8#include <kea_version.h>
20#include <boost/lexical_cast.hpp>
37const char*
const DHCP4_NAME =
"kea-dhcp4";
44 cerr <<
"Kea DHCPv4 server, version " << VERSION << endl;
46 cerr <<
"Usage: " << DHCP4_NAME
47 <<
" -[v|V|W] [-d] [-{c|t} cfgfile] [-p number]" << endl;
48 cerr <<
" -v: print version number and exit" << endl;
49 cerr <<
" -V: print extended version and exit" << endl;
50 cerr <<
" -W: display the configuration report and exit" << endl;
51 cerr <<
" -d: debug mode with extra verbosity (former -v)" << endl;
52 cerr <<
" -c file: specify configuration file" << endl;
53 cerr <<
" -t file: check the configuration file syntax and exit" << endl;
54 cerr <<
" -p number: specify non-standard port number 1-65535 "
55 <<
"(useful for testing only)" << endl;
61main(
int argc,
char* argv[]) {
63 int port_number = DHCP4_SERVER_PORT;
65 bool verbose_mode =
false;
66 bool check_mode =
false;
69 std::string config_file(
"");
71 while ((ch = getopt(argc, argv,
"dvVWc:p:t:")) != -1) {
79 return (EXIT_SUCCESS);
83 return (EXIT_SUCCESS);
87 return (EXIT_SUCCESS);
99 port_number = boost::lexical_cast<int>(optarg);
100 }
catch (
const boost::bad_lexical_cast &) {
101 cerr <<
"Failed to parse port number: [" << optarg
102 <<
"], 1-65535 allowed." << endl;
105 if (port_number <= 0 || port_number > 65535) {
106 cerr <<
"Failed to parse port number: [" << optarg
107 <<
"], 1-65535 allowed." << endl;
124 if (config_file.empty()) {
125 cerr <<
"Configuration file not specified." << endl;
137 setenv(
"KEA_LOCKFILE_DIR",
"none", 0);
146 cerr <<
"No configuration found" << endl;
147 return (EXIT_FAILURE);
150 cerr <<
"Syntax check OK" << endl;
156 cerr <<
"Missing mandatory Dhcp4 element" << endl;
157 return (EXIT_FAILURE);
168 if (status_code == 0) {
169 return (EXIT_SUCCESS);
171 cerr <<
"Error encountered: " << answer->stringValue() << endl;
172 return (EXIT_FAILURE);
174 }
catch (
const std::exception& ex) {
175 cerr <<
"Syntax check failed with: " << ex.what() << endl;
177 return (EXIT_FAILURE);
180 int ret = EXIT_SUCCESS;
190 .arg(getpid()).arg(port_number).arg(verbose_mode ?
"yes" :
"no");
207 server.
init(config_file);
208 }
catch (
const std::exception& ex) {
219 cerr <<
"Failed to initialize server: " << ex.what() << endl;
222 return (EXIT_FAILURE);
235 cerr << DHCP4_NAME <<
" already running? " << ex.
what()
243 .arg(DHCP4_NAME).arg(ex.
what());
248 }
catch (
const std::exception& ex) {
250 cerr << DHCP4_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 DHCPv4 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_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.
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.
This file contains several functions and constants that are used for handling commands and responses ...
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_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.
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.
const int DBG_DHCP4_START
Debug level used to log information during server startup.