8 #include <kea_version.h>
21 #include <boost/lexical_cast.hpp>
41 const char*
const DHCP4_NAME =
"kea-dhcp4";
48 cerr <<
"Kea DHCPv4 server, "
49 <<
"version " << VERSION
50 <<
" (" << PACKAGE_VERSION_TYPE <<
")"
53 cerr <<
"Usage: " << DHCP4_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 = DHCP4_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 << Dhcpv4Srv::getVersion(
false) << endl;
90 return (EXIT_SUCCESS);
93 cout << Dhcpv4Srv::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_INET);
161 setenv(
"KEA_LOCKFILE_DIR",
"none", 0);
168 json = parser.
parseFile(config_file, Parser4Context::PARSER_DHCP4);
170 cerr <<
"No configuration found" << endl;
171 return (EXIT_FAILURE);
174 cerr <<
"Syntax check OK" << endl;
180 cerr <<
"Missing mandatory Dhcp4 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 << DHCP4_NAME <<
" already running? " << ex.
what()
276 .arg(DHCP4_NAME).arg(ex.
what());
281 }
catch (
const std::exception& ex) {
283 cerr << DHCP4_NAME <<
": Fatal error during start up: " << ex.what()
void init(const std::string &config_file)
Initializes the server.
#define LOG_WARN(LOGGER, MESSAGE)
Macro to conveniently test warn output and log it.
isc::data::ElementPtr parseFile(const std::string &filename, ParserType parser_type)
Run the parser on the file specified.
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
const isc::log::MessageID DHCP4_STARTING
const isc::log::MessageID DHCP4_START_INFO
Evaluation context, an interface to the expression evaluation.
void process(T start, T finish)
Process Specifications.
#define LOG_ERROR(LOGGER, MESSAGE)
Macro to conveniently test error output and log it.
const isc::log::MessageID DHCP4_SHUTDOWN
const int DBG_DHCP4_START
Debug level used to log information during server startup.
isc::data::ConstElementPtr configureDhcp4Server(Dhcpv4Srv &server, isc::data::ConstElementPtr config_set, bool check_only)
Configure DHCPv4 server (Dhcpv4Srv) with a set of configuration values.
isc::log::Logger dhcp4_logger(DHCP4_APP_LOGGER_NAME)
Base logger for DHCPv4 server.
int main(int argc, char *argv[])
static void setProcName(const std::string &proc_name)
Sets the process name.
const isc::log::MessageID DHCP4_DEVELOPMENT_VERSION
const isc::log::MessageID DHCP4_SERVER_FAILED
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.
const isc::log::MessageID DHCP4_ALREADY_RUNNING
static void setVerbose(const bool verbose)
Sets or clears verbose mode.
ConstElementPtr parseAnswer(int &rcode, const ConstElementPtr &msg)
Logging initialization functions.
const isc::log::MessageID DHCP4_STARTED
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
int run()
Main server processing loop.
Controlled version of the DHCPv4 server.
std::string getConfigReport()
#define LOG_FATAL(LOGGER, MESSAGE)
Macro to conveniently test fatal output and log it.
Exception thrown when the PID file points to a live PID.
void createPIDFile(int pid=0)
Creates the PID file.
Contains declarations for loggers used by the DHCPv4 server component.
const char * DHCP4_ROOT_LOGGER_NAME
Defines the name of the root level (default) logger.
const isc::log::MessageID DHCP4_INIT_FAIL