8 #include <kea_version.h>
21 #include <boost/lexical_cast.hpp>
41 const char*
const DHCP6_NAME =
"kea-dhcp6";
48 cerr <<
"Kea DHCPv6 server, "
49 <<
"version " << VERSION
50 <<
" (" << PACKAGE_VERSION_TYPE <<
")"
53 cerr <<
"Usage: " << DHCP6_NAME
54 <<
" -[v|V|W] [-d] [-{c|t} cfgfile] [-p number] [-P number]" << endl;
55 cerr <<
" -v: print version number and exit." << endl;
56 cerr <<
" -V: print extended version and exit" << endl;
57 cerr <<
" -W: display the configuration report and exit" << endl;
58 cerr <<
" -d: debug mode with extra verbosity (former -v)" << endl;
59 cerr <<
" -c file: specify configuration file" << endl;
60 cerr <<
" -t file: check the configuration file syntax and exit" << endl;
61 cerr <<
" -p number: specify non-standard server port number 1-65535 "
62 <<
"(useful for testing only)" << endl;
63 cerr <<
" -P number: specify non-standard client port number 1-65535 "
64 <<
"(useful for testing only)" << endl;
70 main(
int argc,
char* argv[]) {
73 int server_port_number = DHCP6_SERVER_PORT;
75 int client_port_number = 0;
76 bool verbose_mode =
false;
77 bool check_mode =
false;
80 std::string config_file(
"");
82 while ((ch = getopt(argc, argv,
"dvVWc:p:P:t:")) != -1) {
89 cout << Dhcpv6Srv::getVersion(
false) << endl;
90 return (EXIT_SUCCESS);
93 cout << Dhcpv6Srv::getVersion(
true) << endl;
94 return (EXIT_SUCCESS);
98 return (EXIT_SUCCESS);
105 config_file = optarg;
110 server_port_number = boost::lexical_cast<
int>(optarg);
111 }
catch (
const boost::bad_lexical_cast &) {
112 cerr <<
"Failed to parse server port number: [" << optarg
113 <<
"], 1-65535 allowed." << endl;
116 if (server_port_number <= 0 || server_port_number > 65535) {
117 cerr <<
"Failed to parse server port number: [" << optarg
118 <<
"], 1-65535 allowed." << endl;
125 client_port_number = boost::lexical_cast<
int>(optarg);
126 }
catch (
const boost::bad_lexical_cast &) {
127 cerr <<
"Failed to parse client port number: [" << optarg
128 <<
"], 1-65535 allowed." << endl;
131 if (client_port_number <= 0 || client_port_number > 65535) {
132 cerr <<
"Failed to parse client port number: [" << optarg
133 <<
"], 1-65535 allowed." << endl;
149 if (config_file.empty()) {
150 cerr <<
"Configuration file not specified." << endl;
155 CfgMgr::instance().setFamily(AF_INET6);
161 setenv(
"KEA_LOCKFILE_DIR",
"none", 0);
168 json = parser.
parseFile(config_file, Parser6Context::PARSER_DHCP6);
170 cerr <<
"No configuration found" << endl;
171 return (EXIT_FAILURE);
174 cerr <<
"Syntax check OK" << endl;
180 cerr <<
"Missing mandatory Dhcp6 element" << endl;
181 return (EXIT_FAILURE);
192 if (status_code == 0) {
193 return (EXIT_SUCCESS);
195 cerr <<
"Error encountered: " << answer->stringValue() << endl;
196 return (EXIT_FAILURE);
198 }
catch (
const std::exception& ex) {
199 cerr <<
"Syntax check failed with: " << ex.what() << endl;
201 return (EXIT_FAILURE);
204 int ret = EXIT_SUCCESS;
215 .arg(server_port_number)
216 .arg(client_port_number)
217 .arg(verbose_mode ?
"yes" :
"no");
221 .arg(PACKAGE_VERSION_TYPE);
223 if (
string(PACKAGE_VERSION_TYPE) ==
"development") {
240 server.
init(config_file);
241 }
catch (
const std::exception& ex) {
252 cerr <<
"Failed to initialize server: " << ex.what() << endl;
255 return (EXIT_FAILURE);
268 cerr << DHCP6_NAME <<
" already running? " << ex.
what()
276 .arg(DHCP6_NAME).arg(ex.
what());
281 }
catch (
const std::exception& ex) {
283 cerr << DHCP6_NAME <<
"Fatal error during start up: " << ex.what()
#define LOG_WARN(LOGGER, MESSAGE)
Macro to conveniently test warn output and log it.
const isc::log::MessageID DHCP6_DEVELOPMENT_VERSION
int run()
Main server processing loop.
isc::data::ConstElementPtr configureDhcp6Server(Dhcpv6Srv &server, isc::data::ConstElementPtr config_set, bool check_only)
Configures DHCPv6 server.
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
isc::data::ElementPtr parseFile(const std::string &filename, ParserType parser_type)
Run the parser on the file specified.
const isc::log::MessageID DHCP6_STARTED
void process(T start, T finish)
Process Specifications.
#define LOG_ERROR(LOGGER, MESSAGE)
Macro to conveniently test error output and log it.
void init(const std::string &config_file)
Initializes the server.
Evaluation context, an interface to the expression evaluation.
const char * DHCP6_ROOT_LOGGER_NAME
Defines the name of the root level (default) logger.
const isc::log::MessageID DHCP6_ALREADY_RUNNING
int main(int argc, char *argv[])
const isc::log::MessageID DHCP6_INIT_FAIL
const isc::log::MessageID DHCP6_SERVER_FAILED
const int DBG_DHCP6_START
Debug level used to log information during server startup.
static void setProcName(const std::string &proc_name)
Sets the process name.
const isc::log::MessageID DHCP6_STARTING
void setConfigFile(const std::string &config_file)
Sets the configuration file name.
boost::shared_ptr< const Element > ConstElementPtr
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
static void setVerbose(const bool verbose)
Sets or clears verbose mode.
const isc::log::MessageID DHCP6_SHUTDOWN
ConstElementPtr parseAnswer(int &rcode, const ConstElementPtr &msg)
Logging initialization functions.
const isc::log::MessageID DHCP6_START_INFO
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
std::string getConfigReport()
#define LOG_FATAL(LOGGER, MESSAGE)
Macro to conveniently test fatal output and log it.
Controlled version of the DHCPv6 server.
Exception thrown when the PID file points to a live PID.
void createPIDFile(int pid=0)
Creates the PID file.
isc::log::Logger dhcp6_logger(DHCP6_APP_LOGGER_NAME)
Base logger for DHCPv6 server.