 |
Kea
1.5.0
|
Go to the documentation of this file.
8 #include <kea_version.h>
20 #include <boost/lexical_cast.hpp>
37 const 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;
61 main(
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) {
78 cout << Dhcpv4Srv::getVersion(
false) << endl;
79 return (EXIT_SUCCESS);
82 cout << Dhcpv4Srv::getVersion(
true) << endl;
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;
130 CfgMgr::instance().setFamily(AF_INET);
137 setenv(
"KEA_LOCKFILE_DIR",
"none", 0);
144 json = parser.
parseFile(config_file, Parser4Context::PARSER_DHCP4);
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()
#define LOG_ERROR(LOGGER, MESSAGE)
Macro to conveniently test error output and log it.
Evaluation context, an interface to the expression evaluation.
isc::data::ConstElementPtr configureDhcp4Server(Dhcpv4Srv &server, isc::data::ConstElementPtr config_set, bool check_only)
Configure DHCPv4 server (Dhcpv4Srv) with a set of configuration values.
const char * DHCP4_ROOT_LOGGER_NAME
Defines the name of the root level (default) logger.
const int DBG_DHCP4_START
Debug level used to log information during server startup.
isc::data::ElementPtr parseFile(const std::string &filename, ParserType parser_type)
Run the parser on the file specified.
void createPIDFile(int pid=0)
Creates the PID file.
void init(const std::string &config_file)
Initializes the server.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
bool run()
Main server processing loop.
#define LOG_FATAL(LOGGER, MESSAGE)
Macro to conveniently test fatal output and log it.
void setProcName(const std::string &proc_name)
Sets the process name.
Controlled version of the DHCPv4 server.
Exception thrown when a the PID file points to a live PID.
static void setVerbose(const bool verbose)
Sets or clears verbose mode.
void process(T start, T finish)
Process Specifications.
ConstElementPtr parseAnswer(int &rcode, const ConstElementPtr &msg)
void setConfigFile(const std::string &config_file)
Sets the configuration file name.
std::string getConfigReport()
isc::log::Logger dhcp4_logger(DHCP4_APP_LOGGER_NAME)
Base logger for DHCPv4 server.
int main(int argc, char *argv[])
boost::shared_ptr< const Element > ConstElementPtr
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
Logging initialization functions.