8 #include <kea_version.h> 22 #include <boost/lexical_cast.hpp> 42 const char*
const DHCP6_NAME =
"kea-dhcp6";
49 cerr <<
"Kea DHCPv6 server, " 50 <<
"version " << VERSION
51 <<
" (" << PACKAGE_VERSION_TYPE <<
")" 54 cerr <<
"Usage: " << DHCP6_NAME
55 <<
" -[v|V|W] [-d] [-{c|t} cfgfile] [-p number] [-P number]" << endl;
56 cerr <<
" -v: print version number and exit" << endl;
57 cerr <<
" -V: print extended version and exit" << endl;
58 cerr <<
" -W: display the configuration report and exit" << endl;
59 cerr <<
" -d: debug mode with extra verbosity (former -v)" << endl;
60 cerr <<
" -c file: specify configuration file" << endl;
61 cerr <<
" -t file: check the configuration file syntax and exit" << endl;
62 cerr <<
" -p number: specify non-standard server port number 1-65535 " 63 <<
"(useful for testing only)" << endl;
64 cerr <<
" -P number: specify non-standard client port number 1-65535 " 65 <<
"(useful for testing only)" << endl;
71 main(
int argc,
char* argv[]) {
74 int server_port_number = DHCP6_SERVER_PORT;
76 int client_port_number = 0;
77 bool verbose_mode =
false;
78 bool check_mode =
false;
81 std::string config_file(
"");
83 while ((ch = getopt(argc, argv,
"dvVWc:p:P:t:")) != -1) {
90 cout << Dhcpv6Srv::getVersion(
false) << endl;
91 return (EXIT_SUCCESS);
94 cout << Dhcpv6Srv::getVersion(
true) << endl;
95 return (EXIT_SUCCESS);
99 return (EXIT_SUCCESS);
106 config_file = optarg;
111 server_port_number = boost::lexical_cast<
int>(optarg);
112 }
catch (
const boost::bad_lexical_cast &) {
113 cerr <<
"Failed to parse server port number: [" << optarg
114 <<
"], 1-65535 allowed." << endl;
117 if (server_port_number <= 0 || server_port_number > 65535) {
118 cerr <<
"Failed to parse server port number: [" << optarg
119 <<
"], 1-65535 allowed." << endl;
126 client_port_number = boost::lexical_cast<
int>(optarg);
127 }
catch (
const boost::bad_lexical_cast &) {
128 cerr <<
"Failed to parse client port number: [" << optarg
129 <<
"], 1-65535 allowed." << endl;
132 if (client_port_number <= 0 || client_port_number > 65535) {
133 cerr <<
"Failed to parse client port number: [" << optarg
134 <<
"], 1-65535 allowed." << endl;
150 if (config_file.empty()) {
151 cerr <<
"Configuration file not specified." << endl;
156 CfgMgr::instance().setFamily(AF_INET6);
162 setenv(
"KEA_LOCKFILE_DIR",
"none", 0);
169 json = parser.
parseFile(config_file, Parser6Context::PARSER_DHCP6);
171 cerr <<
"No configuration found" << endl;
172 return (EXIT_FAILURE);
175 cerr <<
"Syntax check OK" << endl;
181 cerr <<
"Missing mandatory Dhcp6 element" << endl;
182 return (EXIT_FAILURE);
193 if (status_code == 0) {
194 return (EXIT_SUCCESS);
196 cerr <<
"Error encountered: " << answer->stringValue() << endl;
197 return (EXIT_FAILURE);
199 }
catch (
const std::exception& ex) {
200 cerr <<
"Syntax check failed with: " << ex.what() << endl;
202 return (EXIT_FAILURE);
205 int ret = EXIT_SUCCESS;
216 .arg(server_port_number)
217 .arg(client_port_number)
218 .arg(verbose_mode ?
"yes" :
"no");
222 .arg(PACKAGE_VERSION_TYPE);
224 if (
string(PACKAGE_VERSION_TYPE) ==
"development") {
241 server.
init(config_file);
242 }
catch (
const std::exception& ex) {
260 cerr <<
"Failed to initialize server: " << ex.what() << endl;
263 return (EXIT_FAILURE);
276 cerr << DHCP6_NAME <<
" already running? " << ex.
what()
284 .arg(DHCP6_NAME).arg(ex.
what());
289 }
catch (
const std::exception& ex) {
291 cerr << DHCP6_NAME <<
": Fatal error during start up: " << ex.what()
304 cerr << DHCP6_NAME <<
": Fatal error during start up" #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[])
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
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
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
bool hasAppender(OutputOption::Destination const destination)
Check if this logger has an appender of the given type.
#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.