8#include <kea_version.h>
22#include <boost/lexical_cast.hpp>
42const char*
const DHCP4_NAME =
"kea-dhcp4";
49 cerr <<
"Kea DHCPv4 server, "
50 <<
"version " << VERSION
51 <<
" (" << PACKAGE_VERSION_TYPE <<
")"
54 cerr <<
"Usage: " << DHCP4_NAME
55 <<
" -[v|V|W] [-d] [-{c|t|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 <<
" -T file: check the configuration file doing hooks load and extra "
63 <<
"checks and exit" << endl;
64 cerr <<
" -p number: specify non-standard server port number 1-65535 "
65 <<
"(useful for testing only)" << endl;
66 cerr <<
" -P number: specify non-standard client port number 1-65535 "
67 <<
"(useful for testing only)" << endl;
73main(
int argc,
char* argv[]) {
76 int server_port_number = DHCP4_SERVER_PORT;
78 int client_port_number = 0;
79 bool verbose_mode =
false;
80 bool check_mode =
false;
81 bool load_hooks =
false;
84 std::string config_file(
"");
89 while ((ch = getopt(argc, argv,
"dvVWc:p:P:t:T:")) != -1) {
97 return (EXIT_SUCCESS);
101 return (EXIT_SUCCESS);
105 return (EXIT_SUCCESS);
110 config_file = optarg;
115 config_file = optarg;
119 config_file = optarg;
124 server_port_number = boost::lexical_cast<int>(optarg);
125 }
catch (
const boost::bad_lexical_cast &) {
126 cerr <<
"Failed to parse server port number: [" << optarg
127 <<
"], 1-65535 allowed." << endl;
130 if (server_port_number <= 0 || server_port_number > 65535) {
131 cerr <<
"Failed to parse server port number: [" << optarg
132 <<
"], 1-65535 allowed." << endl;
139 client_port_number = boost::lexical_cast<int>(optarg);
140 }
catch (
const boost::bad_lexical_cast &) {
141 cerr <<
"Failed to parse client port number: [" << optarg
142 <<
"], 1-65535 allowed." << endl;
145 if (client_port_number <= 0 || client_port_number > 65535) {
146 cerr <<
"Failed to parse client port number: [" << optarg
147 <<
"], 1-65535 allowed." << endl;
163 if (config_file.empty()) {
164 cerr <<
"Configuration file not specified." << endl;
172 setenv(
"KEA_LOCKFILE_DIR",
"none", 0);
181 cerr <<
"No configuration found" << endl;
182 return (EXIT_FAILURE);
185 cerr <<
"Syntax check OK" << endl;
191 cerr <<
"Missing mandatory Dhcp4 element" << endl;
192 return (EXIT_FAILURE);
197 server.setProcName(DHCP4_NAME);
205 if (status_code == 0) {
206 return (EXIT_SUCCESS);
208 cerr <<
"Error encountered: " << answer->stringValue() << endl;
209 return (EXIT_FAILURE);
211 }
catch (
const std::exception& ex) {
212 cerr <<
"Syntax check failed with: " << ex.what() << endl;
214 return (EXIT_FAILURE);
217 int ret = EXIT_SUCCESS;
228 .arg(server_port_number)
229 .arg(client_port_number)
230 .arg(verbose_mode ?
"yes" :
"no");
234 .arg(PACKAGE_VERSION_TYPE);
236 if (
string(PACKAGE_VERSION_TYPE) ==
"development") {
244 server.setVerbose(verbose_mode);
247 server.setProcName(DHCP4_NAME);
248 server.setConfigFile(config_file);
249 server.createPIDFile();
253 server.init(config_file);
254 }
catch (
const std::exception& ex) {
272 cerr <<
"Failed to initialize server: " << ex.what() << endl;
275 return (EXIT_FAILURE);
288 cerr << DHCP4_NAME <<
" already running? " << ex.what()
296 .arg(DHCP4_NAME).arg(ex.what());
301 }
catch (
const std::exception& ex) {
303 cerr << DHCP4_NAME <<
": Fatal error during start up: " << ex.what()
316 cerr << DHCP4_NAME <<
": Fatal error during start up"
static CfgMgr & instance()
returns a single instance of Configuration Manager
Controlled version of the DHCPv4 server.
static std::string getVersion(bool extended)
returns Kea version on stdout and exit.
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_DHCP4
This parser will parse the content as Dhcp4 config wrapped in a map (that's the regular config file)
void process(T start, T finish)
Process Specifications.
bool hasAppender(OutputOption::Destination const destination)
Check if this logger has an appender of the given type.
Exception thrown when the PID file points to a live PID.
static void loggerInit(const char *log_name, bool verbose)
Initializes logger.
static void setDefaultLoggerName(const std::string &logger)
Sets the default logger name.
int main(int argc, char *argv[])
Contains declarations for loggers used by the DHCPv4 server component.
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)
boost::shared_ptr< const Element > ConstElementPtr
std::string getConfigReport()
const char * DHCP4_ROOT_LOGGER_NAME
Defines the name of the root level (default) logger.
const isc::log::MessageID DHCP4_ALREADY_RUNNING
const isc::log::MessageID DHCP4_STARTED
const isc::log::MessageID DHCP4_START_INFO
const isc::log::MessageID DHCP4_SERVER_FAILED
const isc::log::MessageID DHCP4_INIT_FAIL
isc::data::ConstElementPtr configureDhcp4Server(Dhcpv4Srv &server, isc::data::ConstElementPtr config_set, bool check_only, bool extra_checks)
Configure DHCPv4 server (Dhcpv4Srv) with a set of configuration values.
const isc::log::MessageID DHCP4_SHUTDOWN
const isc::log::MessageID DHCP4_STARTING
isc::log::Logger dhcp4_logger(DHCP4_APP_LOGGER_NAME)
Base logger for DHCPv4 server.
const isc::log::MessageID DHCP4_DEVELOPMENT_VERSION
const int DBG_DHCP4_START
Debug level used to log information during server startup.