8#include <kea_version.h> 
   23#include <boost/lexical_cast.hpp> 
   44const char* 
const DHCP4_NAME = 
"kea-dhcp4";
 
   51    cerr << 
"Kea DHCPv4 server, " 
   52         << 
"version " << VERSION
 
   53         << 
" (" << PACKAGE_VERSION_TYPE << 
")" 
   56    cerr << 
"Usage: " << DHCP4_NAME
 
   57         << 
" -[v|V|W|X] [-d] [-{c|t|T} cfgfile] [-p number] [-P number]" << endl;
 
   58    cerr << 
"  -v: print version number and exit" << endl;
 
   59    cerr << 
"  -V: print extended version and exit" << endl;
 
   60    cerr << 
"  -W: display the configuration report and exit" << endl;
 
   61    cerr << 
"  -d: debug mode with extra verbosity (former -v)" << endl;
 
   62    cerr << 
"  -c file: specify configuration file" << endl;
 
   63    cerr << 
"  -t file: check the configuration file syntax and exit" << endl;
 
   64    cerr << 
"  -T file: check the configuration file doing hooks load and extra " 
   65         << 
"checks and exit" << endl;
 
   66    cerr << 
"  -p number: specify non-standard server port number 1-65535 " 
   67         << 
"(useful for testing only)" << endl;
 
   68    cerr << 
"  -P number: specify non-standard client port number 1-65535 " 
   69         << 
"(useful for testing only)" << endl;
 
   70    cerr << 
"  -X: disables security restrictions" << endl;
 
   76main(
int argc, 
char* argv[]) {
 
   81    int server_port_number = DHCP4_SERVER_PORT;
 
   83    int client_port_number = 0;
 
   84    bool verbose_mode = 
false; 
 
   85    bool check_mode = 
false;   
 
   86    bool load_hooks = 
false;   
 
   89    std::string config_file(
"");
 
   94    while ((ch = getopt(argc, argv, 
"dvVWc:p:P:t:T:X")) != -1) {
 
  102            return (EXIT_SUCCESS);
 
  106            return (EXIT_SUCCESS);
 
  110            return (EXIT_SUCCESS);
 
  115            config_file = optarg;
 
  120            config_file = optarg;
 
  124            config_file = optarg;
 
  129                server_port_number = boost::lexical_cast<int>(optarg);
 
  130            } 
catch (
const boost::bad_lexical_cast &) {
 
  131                cerr << 
"Failed to parse server port number: [" << optarg
 
  132                     << 
"], 1-65535 allowed." << endl;
 
  135            if (server_port_number <= 0 || server_port_number > 65535) {
 
  136                cerr << 
"Failed to parse server port number: [" << optarg
 
  137                     << 
"], 1-65535 allowed." << endl;
 
  144                client_port_number = boost::lexical_cast<int>(optarg);
 
  145            } 
catch (
const boost::bad_lexical_cast &) {
 
  146                cerr << 
"Failed to parse client port number: [" << optarg
 
  147                     << 
"], 1-65535 allowed." << endl;
 
  150            if (client_port_number <= 0 || client_port_number > 65535) {
 
  151                cerr << 
"Failed to parse client port number: [" << optarg
 
  152                     << 
"], 1-65535 allowed." << endl;
 
  172    if (config_file.empty()) {
 
  173        cerr << 
"Configuration file not specified." << endl;
 
  181            setenv(
"KEA_LOCKFILE_DIR", 
"none", 0);
 
  190                cerr << 
"No configuration found" << endl;
 
  191                return (EXIT_FAILURE);
 
  194                cerr << 
"Syntax check OK" << endl;
 
  200                cerr << 
"Missing mandatory Dhcp4 element" << endl;
 
  201                return (EXIT_FAILURE);
 
  214            if (status_code == 0) {
 
  215                return (EXIT_SUCCESS);
 
  217                cerr << 
"Error encountered: " << answer->stringValue() << endl;
 
  218                return (EXIT_FAILURE);
 
  220        } 
catch (
const std::exception& ex) {
 
  221            cerr << 
"Syntax check failed with: " << ex.what() << endl;
 
  223        return (EXIT_FAILURE);
 
  226    int ret = EXIT_SUCCESS;
 
  237            .arg(server_port_number)
 
  238            .arg(client_port_number)
 
  239            .arg(verbose_mode ? 
"yes" : 
"no");
 
  243            .arg(PACKAGE_VERSION_TYPE);
 
  245        if (
string(PACKAGE_VERSION_TYPE) == 
"development") {
 
  270            server.
init(config_file);
 
  271        } 
catch (
const std::exception& ex) {
 
  289                cerr << 
"Failed to initialize server: " << ex.what() << endl;
 
  292            return (EXIT_FAILURE);
 
  305        cerr << DHCP4_NAME << 
" already running? " << ex.
what()
 
  313                .arg(DHCP4_NAME).arg(ex.
what());
 
  318    } 
catch (
const std::exception& ex) {
 
  320        cerr << DHCP4_NAME << 
": Fatal error during start up: " << ex.
what()
 
  333        cerr << DHCP4_NAME << 
": Fatal error during start up" 
 
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.
int run()
Main server processing loop.
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.
Exception thrown when 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.
static 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.
static bool shouldEnforceSecurity()
Indicates security checks should be enforced.
static void enableEnforcement(bool enable)
Enables or disables security enforcment checks.
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)
Parses a standard config/command level answer and returns arguments or text status code.
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_SECURITY_CHECKS_DISABLED
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_ROOT_USER_SECURITY_WARNING
const isc::log::MessageID DHCP4_DEVELOPMENT_VERSION
const int DBG_DHCP4_START
Debug level used to log information during server startup.
bool amRunningAsRoot()
Indicates if current user is root.
void setUmask()
Set umask (at least 0027 i.e. no group write and no other access).