 |
Kea
1.5.0
|
Go to the documentation of this file.
8 #include <kea_version.h>
21 #include <boost/lexical_cast.hpp>
40 const char*
const DHCP6_NAME =
"kea-dhcp6";
42 const char*
const DHCP6_LOGGER_NAME =
"kea-dhcp6";
49 cerr <<
"Kea DHCPv6 server, version " << VERSION << endl;
51 cerr <<
"Usage: " << DHCP6_NAME
52 <<
" -[v|V|W] [-d] [-{c|t} cfgfile] [-p port_number]" << endl;
53 cerr <<
" -v: print version number and exit." << endl;
54 cerr <<
" -V: print extended version and exit" << endl;
55 cerr <<
" -W: display the configuration report and exit" << endl;
56 cerr <<
" -d: debug mode with extra verbosity (former -v)" << endl;
57 cerr <<
" -c file: specify configuration file" << endl;
58 cerr <<
" -t file: check the configuration file syntax and exit" << endl;
59 cerr <<
" -p number: specify non-standard port number 1-65535 "
60 <<
"(useful for testing only)" << endl;
66 main(
int argc,
char* argv[]) {
68 int port_number = DHCP6_SERVER_PORT;
70 bool verbose_mode =
false;
71 bool check_mode =
false;
74 std::string config_file(
"");
76 while ((ch = getopt(argc, argv,
"dvVWc:p:t:")) != -1) {
83 cout << Dhcpv6Srv::getVersion(
false) << endl;
84 return (EXIT_SUCCESS);
87 cout << Dhcpv6Srv::getVersion(
true) << endl;
88 return (EXIT_SUCCESS);
92 return (EXIT_SUCCESS);
104 port_number = boost::lexical_cast<int>(optarg);
105 }
catch (
const boost::bad_lexical_cast &) {
106 cerr <<
"Failed to parse port number: [" << optarg
107 <<
"], 1-65535 allowed." << endl;
110 if (port_number <= 0 || port_number > 65535) {
111 cerr <<
"Failed to parse port number: [" << optarg
112 <<
"], 1-65535 allowed." << endl;
128 if (config_file.empty()) {
129 cerr <<
"Configuration file not specified." << endl;
134 CfgMgr::instance().setFamily(AF_INET6);
140 setenv(
"KEA_LOCKFILE_DIR",
"none", 0);
147 json = parser.
parseFile(config_file, Parser6Context::PARSER_DHCP6);
149 cerr <<
"No configuration found" << endl;
150 return (EXIT_FAILURE);
153 cerr <<
"Syntax check OK" << endl;
159 cerr <<
"Missing mandatory Dhcp6 element" << endl;
160 return (EXIT_FAILURE);
171 if (status_code == 0) {
172 return (EXIT_SUCCESS);
174 cerr <<
"Error encountered: " << answer->stringValue() << endl;
175 return (EXIT_FAILURE);
179 return (EXIT_SUCCESS);
180 }
catch (
const std::exception& ex) {
181 cerr <<
"Syntax check failed with " << ex.what() << endl;
183 return (EXIT_FAILURE);
186 int ret = EXIT_SUCCESS;
191 Daemon::setDefaultLoggerName(DHCP6_LOGGER_NAME);
194 Daemon::loggerInit(DHCP6_LOGGER_NAME, verbose_mode);
197 .arg(getpid()).arg(port_number).arg(verbose_mode ?
"yes" :
"no");
215 server.
init(config_file);
217 }
catch (
const std::exception& ex) {
228 cerr <<
"Failed to initialize server: " << ex.what() << endl;
231 return (EXIT_FAILURE);
244 cerr << DHCP6_NAME <<
" already running? " << ex.
what()
252 .arg(DHCP6_NAME).arg(ex.
what());
257 }
catch (
const std::exception& ex) {
260 cerr << DHCP6_NAME <<
"Fatal error during start up: " << ex.what()
#define LOG_ERROR(LOGGER, MESSAGE)
Macro to conveniently test error output and log it.
const char * DHCP6_ROOT_LOGGER_NAME
Defines the name of the root level (default) logger.
Evaluation context, an interface to the expression evaluation.
isc::log::Logger dhcp6_logger(DHCP6_APP_LOGGER_NAME)
Base logger for DHCPv6 server.
void createPIDFile(int pid=0)
Creates the PID file.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
isc::data::ElementPtr parseFile(const std::string &filename, ParserType parser_type)
Run the parser on the file specified.
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
#define LOG_FATAL(LOGGER, MESSAGE)
Macro to conveniently test fatal output and log it.
Controlled version of the DHCPv6 server.
void setProcName(const std::string &proc_name)
Sets the process name.
bool run()
Main server processing loop.
void init(const std::string &config_file)
Initializes the server.
Exception thrown when a the PID file points to a live PID.
static void setVerbose(const bool verbose)
Sets or clears verbose mode.
void process(T start, T finish)
Process Specifications.
const int DBG_DHCP6_START
Debug level used to log information during server startup.
ConstElementPtr parseAnswer(int &rcode, const ConstElementPtr &msg)
void setConfigFile(const std::string &config_file)
Sets the configuration file name.
std::string getConfigReport()
int main(int argc, char *argv[])
boost::shared_ptr< const Element > ConstElementPtr
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
Logging initialization functions.
isc::data::ConstElementPtr configureDhcp6Server(Dhcpv6Srv &server, isc::data::ConstElementPtr config_set, bool check_only)
Configures DHCPv6 server.