8#include <kea_version.h>
21#include <boost/lexical_cast.hpp>
40const char*
const DHCP6_NAME =
"kea-dhcp6";
42const 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;
66main(
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) {
84 return (EXIT_SUCCESS);
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;
140 setenv(
"KEA_LOCKFILE_DIR",
"none", 0);
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;
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()
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.
static std::string getVersion(bool extended)
returns Kea version on stdout and exit.
bool run()
Main server processing loop.
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 a the PID file points to a live PID.
static void setVerbose(const bool verbose)
Sets or clears verbose mode.
static void loggerInit(const char *log_name, bool verbose)
Initializes logger.
static void setDefaultLoggerName(const std::string &logger)
Sets the default logger name.
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.
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_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)
boost::shared_ptr< const Element > ConstElementPtr
std::string getConfigReport()
isc::data::ConstElementPtr configureDhcp6Server(Dhcpv6Srv &server, isc::data::ConstElementPtr config_set, bool check_only)
Configures DHCPv6 server.
const int DBG_DHCP6_START
Debug level used to log information during server startup.
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.