8#include <kea_version.h>
23#include <boost/lexical_cast.hpp>
45const char*
const DHCP6_NAME =
"kea-dhcp6";
52 cerr <<
"Kea DHCPv6 server, "
53 <<
"version " << VERSION
54 <<
" (" << PACKAGE_VERSION_TYPE <<
")"
57 cerr <<
"Usage: " << DHCP6_NAME
58 <<
" -[v|V|W] [-d|F|R|X] [-{c|t|T} cfgfile] [-p number] [-P number]" << endl;
59 cerr <<
" -v: print version number and exit" << endl;
60 cerr <<
" -V: print extended version and exit" << endl;
61 cerr <<
" -W: display the configuration report and exit" << endl;
62 cerr <<
" -d: debug mode with extra verbosity (former -v)" << endl;
63 cerr <<
" -F: exit on critical error" << endl;
64 cerr <<
" -R: config back end repair mode" << endl;
65 cerr <<
" -X: disables security restrictions" << endl;
66 cerr <<
" -c file: specify configuration file" << endl;
67 cerr <<
" -t file: check the configuration file syntax and exit" << endl;
68 cerr <<
" -T file: check the configuration file doing hooks load and extra "
69 <<
"checks and exit" << endl;
70 cerr <<
" -p number: specify non-standard server port number 1-65535 "
71 <<
"(useful for testing only)" << endl;
72 cerr <<
" -P number: specify non-standard client port number 1-65535 "
73 <<
"(useful for testing only)" << endl;
79main(
int argc,
char* argv[]) {
84 int server_port_number = DHCP6_SERVER_PORT;
86 int client_port_number = 0;
87 bool verbose_mode =
false;
88 bool check_mode =
false;
89 bool load_hooks =
false;
92 std::string config_file(
"");
106 while ((ch = getopt(argc, argv,
"vVWdFRXc:t:T:p:P:")) != -1) {
110 return (EXIT_SUCCESS);
114 return (EXIT_SUCCESS);
118 return (EXIT_SUCCESS);
137 config_file = optarg;
142 config_file = optarg;
148 config_file = optarg;
153 server_port_number = boost::lexical_cast<int>(optarg);
154 }
catch (
const boost::bad_lexical_cast &) {
155 cerr <<
"Failed to parse server port number: [" << optarg
156 <<
"], 1-65535 allowed." << endl;
159 if (server_port_number <= 0 || server_port_number > 65535) {
160 cerr <<
"Failed to parse server port number: [" << optarg
161 <<
"], 1-65535 allowed." << endl;
168 client_port_number = boost::lexical_cast<int>(optarg);
169 }
catch (
const boost::bad_lexical_cast &) {
170 cerr <<
"Failed to parse client port number: [" << optarg
171 <<
"], 1-65535 allowed." << endl;
174 if (client_port_number <= 0 || client_port_number > 65535) {
175 cerr <<
"Failed to parse client port number: [" << optarg
176 <<
"], 1-65535 allowed." << endl;
192 if (config_file.empty()) {
193 cerr <<
"Configuration file not specified." << endl;
201 setenv(
"KEA_LOCKFILE_DIR",
"none", 0);
210 cerr <<
"No configuration found" << endl;
211 return (EXIT_FAILURE);
214 cerr <<
"Syntax check OK" << endl;
220 cerr <<
"Missing mandatory Dhcp6 element" << endl;
221 return (EXIT_FAILURE);
234 if (status_code == 0) {
235 return (EXIT_SUCCESS);
237 cerr <<
"Error encountered: " << answer->stringValue() << endl;
238 return (EXIT_FAILURE);
240 }
catch (
const std::exception& ex) {
241 cerr <<
"Syntax check failed with: " << ex.what() << endl;
243 return (EXIT_FAILURE);
246 int ret = EXIT_SUCCESS;
257 .arg(server_port_number)
258 .arg(client_port_number)
259 .arg(verbose_mode ?
"yes" :
"no");
263 .arg(PACKAGE_VERSION_TYPE);
265 if (
string(PACKAGE_VERSION_TYPE) ==
"development") {
294 server.
init(config_file);
295 }
catch (
const std::exception& ex) {
313 cerr <<
"Failed to initialize server: " << ex.what() << endl;
316 return (EXIT_FAILURE);
329 cerr << DHCP6_NAME <<
" already running? " << ex.
what()
337 .arg(DHCP6_NAME).arg(ex.
what());
342 }
catch (
const std::exception& ex) {
344 cerr << DHCP6_NAME <<
": Fatal error during start up: " << ex.
what()
357 cerr << DHCP6_NAME <<
": Fatal error during start up"
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
void setFamily(uint16_t family)
Sets address family (AF_INET or AF_INET6).
static CfgMgr & instance()
returns a single instance of Configuration Manager
Controlled version of the DHCPv6 server.
void init(const std::string &config_file)
Initializes the server.
int run()
Main server processing loop.
static std::string getVersion(bool extended)
returns Kea version on stdout and exit.
void setFamily(uint16_t family)
Sets address family (AF_INET or AF_INET6).
static IfaceMgr & instance()
IfaceMgr is a singleton class.
Evaluation context, an interface to the expression evaluation.
isc::data::ElementPtr parseFile(const std::string &filename, ParserType parser_type)
Run the parser on the file specified.
@ PARSER_DHCP6
This parser will parse the content as Dhcp6 config wrapped in a map (that's the regular config file).
void process(T start, T finish)
Process Specifications.
Exception thrown when the PID file points to a live PID.
static void setShutdownOnFailure(bool shutdown)
Set the shutdown on critical failure flag.
static bool getCBRepairMode()
Get the CB repair mode flag.
static void setVerbose(const bool verbose)
Sets or clears verbose mode.
static void setCBRepairMode(bool cb_repair_mode)
Set the CB repair mode flag.
static void loggerInit(const char *log_name, bool verbose)
Initializes logger.
static void setDefaultLoggerName(const std::string &logger)
Sets the default logger name.
static void setProcName(const std::string &proc_name)
Sets the process name.
void createPIDFile(int pid=0)
Creates the PID file.
void setConfigFile(const std::string &config_file)
Sets the configuration file name.
static bool shouldEnforceSecurity()
Indicates security checks should be enforced.
static void enableEnforcement(bool enable)
Enables or disables security enforcement checks.
int main(int argc, char *argv[])
Logging initialization functions.
#define LOG_ERROR(LOGGER, MESSAGE)
Macro to conveniently test error output and log it.
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
#define LOG_WARN(LOGGER, MESSAGE)
Macro to conveniently test warn output and log it.
#define LOG_FATAL(LOGGER, MESSAGE)
Macro to conveniently test fatal output and log it.
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
ConstElementPtr parseAnswer(int &rcode, const ConstElementPtr &msg)
Parses a standard config/command level answer and returns arguments or text status code.
boost::shared_ptr< const Element > ConstElementPtr
std::string getConfigReport()
const isc::log::MessageID DHCP6_CB_REPAIR_MODE_ENABLED
isc::data::ConstElementPtr configureDhcp6Server(Dhcpv6Srv &server, isc::data::ConstElementPtr config_set, bool check_only, bool extra_checks)
Configure DHCPv6 server (Dhcpv6Srv) with a set of configuration values.
const isc::log::MessageID DHCP6_INIT_FAIL
const int DBG_DHCP6_START
Debug level used to log information during server startup.
const isc::log::MessageID DHCP6_SERVER_FAILED
const isc::log::MessageID DHCP6_DEVELOPMENT_VERSION
const isc::log::MessageID DHCP6_SHUTDOWN
const isc::log::MessageID DHCP6_STARTED
const isc::log::MessageID DHCP6_STARTING
const isc::log::MessageID DHCP6_START_INFO
const isc::log::MessageID DHCP6_SECURITY_CHECKS_DISABLED
const isc::log::MessageID DHCP6_ALREADY_RUNNING
const isc::log::MessageID DHCP6_ROOT_USER_SECURITY_WARNING
const char * DHCP6_ROOT_LOGGER_NAME
Defines the name of the root level (default) logger.
isc::log::Logger dhcp6_logger(DHCP6_APP_LOGGER_NAME)
Base logger for DHCPv6 server.
bool amRunningAsRoot()
Indicates if current user is root.
void setUmask()
Set umask (at least 0027 i.e. no group write and no other access).