29static const char copyright[] =
30"Copyright 2004-2022 Internet Systems Consortium.";
31static const char arr [] =
"All rights reserved.";
32static const char message [] =
"Internet Systems Consortium DHCP Server";
33static const char url [] =
34"For info, please visit https://www.isc.org/software/dhcp/";
47# include <sys/types.h>
51# define group real_group
64#include <systemd/sd-daemon.h>
75option server.ddns-hostname = \n\
76 pick (option fqdn.hostname, option host-name, config-option host-name); \n\
77option server.ddns-domainname = config-option domain-name; \n\
78option server.ddns-rev-domainname = \"in-addr.arpa.\";";
128static void omapi_listener_start (
void *foo)
137 log_fatal (
"Can't allocate new generic object: %s",
143 (listener, verify_addr, verify_auth);
145 log_error (
"Can't start OMAPI protocol: %s",
156#define DHCPD_USAGE0 \
157"[-p <UDP port #>] [-f] [-d] [-q] [-t|-T]\n"
161#define DHCPD_USAGE1 \
162" [-4|-6] [-4o6 <port>]\n" \
163" [-cf config-file] [-lf lease-file]\n"
165#define DHCPD_USAGE1 \
166" [-4|-6] [-cf config-file] [-lf lease-file]\n"
169#define DHCPD_USAGE1 \
170" [-cf config-file] [-lf lease-file]\n"
173#if defined (PARANOIA)
174#define DHCPD_USAGEP \
175" [-user user] [-group group] [-chroot dir]\n"
177#define DHCPD_USAGEP ""
181#define DHCPD_USAGET \
182" [-tf trace-output-file]\n" \
183" [-play trace-input-file]\n"
185#define DHCPD_USAGET ""
188#define DHCPD_USAGEC \
189" [-pf pid-file] [--no-pid] [-s server]\n" \
192#define DHCPD_USAGEH "{--version|--help|-h}"
209static char use_noarg[] =
"No argument for command: %s ";
212usage(
const char *
sfmt,
const char *
sarg) {
219#ifdef PRINT_SPECIFIC_CL_ERRORS
224 log_fatal(
"Usage: %s %s%s%s%s%s\n %s %s",
239#if defined (PARANOIA)
243 log_fatal (
"you must be root to use chroot");
267 int dfd[2] = { -1, -1 };
274#if defined (NSUPDATE)
292#if defined (PARANOIA)
318 for (
i = 1;
i < argc;
i++) {
336 const char vstring[] =
"isc-dhcpd-";
354#if defined (PARANOIA)
411 log_fatal(
"Can't initialize context: %s",
433 for (
i = 1;
i < argc;
i++) {
436 usage(use_noarg,
argv[
i-1]);
438 log_debug (
"binding to user-specified port %d",
451 usage(use_noarg,
argv[
i-1]);
453#if defined (PARANOIA)
456 usage(use_noarg,
argv[
i-1]);
460 usage(use_noarg,
argv[
i-1]);
464 usage(use_noarg,
argv[
i-1]);
469 usage(use_noarg,
argv[
i-1]);
474 usage(use_noarg,
argv[
i-1]);
479 usage(use_noarg,
argv[
i-1]);
505 log_fatal(
"Server cannot run in both IPv4 and "
506 "IPv6 mode at the same time.");
512 log_fatal(
"Server cannot run in both IPv4 and "
513 "IPv6 mode at the same time.");
520 usage(use_noarg,
argv[
i-1]);
523 log_debug(
"DHCPv4 over DHCPv6 over ::1 port %d and %d",
532 usage(use_noarg,
argv[
i-1]);
536 usage(use_noarg,
argv[
i-1]);
540 }
else if (
argv [
i][0] ==
'-') {
541 usage(
"Unknown command %s",
argv[
i]);
551 log_fatal (
"Insufficient memory to %s %s: %s",
552 "record interface",
argv [
i],
565#if defined(DHCPv6) && defined(DHCP4o6)
568 log_error(
"please specify the address family "
569 "with DHPv4 over DHCPv6 [-4|-6].");
571 log_fatal(
"DHCPv4 server in DHPv4 over DHCPv6 "
572 "mode with command line specified "
585 if ((
s =
getenv (
"PATH_DHCPD6_DB")))
591 if ((
s =
getenv (
"PATH_DHCPD6_PID")))
639#if defined (NSUPDATE)
644#if defined (PARANOIA)
650 log_fatal (
"you must be root to set user");
664#define group real_group
668 log_fatal (
"you must be root to set group");
677# if defined (EARLY_CHROOT)
685 if ((
s =
getenv (
"DHCPD_PORT"))) {
687 log_debug (
"binding to environment-specified port %d",
726 log_fatal(
"You can only specify address to send "
727 "replies to when running an IPv4 server.");
753#if defined (LDAP_CONFIGURATION)
755#if defined (LDAP_USE_SSL)
763 log_fatal (
"Can't allocate root group!");
774#if defined (NSUPDATE)
778 "standard name service update routine", 0);
780 log_fatal (
"can't begin parsing name service updater!");
787 log_fatal(
"can't parse standard name service updater!");
801 log_error (
"** You must specify a lease file with -lf.");
802 log_error (
" Dhcpd will not overwrite your default");
803 log_fatal (
" lease file when playing back a trace. **");
807#if defined (DEBUG_MEMORY_LEAKAGE) && \
808 defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
820 log_fatal(
"Out of memory creating hash for active IA_NA.");
823 log_fatal(
"Out of memory creating hash for active IA_TA.");
826 log_fatal(
"Out of memory creating hash for active IA_PD.");
832 log_fatal (
"Configuration file errors encountered -- exiting");
836#if defined (FAILOVER_PROTOCOL)
840#if defined(DHCPv6) && defined(DHCP4o6)
843 log_fatal(
"DHCPv4 server in DHPv4 over DHCPv6 "
844 "mode with config file specified "
849#if defined (PARANOIA) && !defined (EARLY_CHROOT)
886 "DHCP server running.");
900#if defined(DHCPv6) && defined(DHCP4o6)
942 &
ip -> hw_address.hbuf [
ip -> hw_address.hlen -
966 log_fatal(
"Unable to set server identifier.");
988 log_error(
"Can't create PID file %s: %m.",
993#if defined (PARANOIA)
1017 if (
dfd[0] != -1 &&
dfd[1] != -1) {
1044#if defined (DEBUG_MEMORY_LEAKAGE) || defined (DEBUG_MALLOC_POOL) || \
1045 defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
1054#if defined(ENABLE_GENTLE_SHUTDOWN)
1062 log_info(
"Server starting service.");
1064#ifdef HAVE_LIBSYSTEMD
1067 "STATUS=Dispatching packets...\n"
1069 (
unsigned long)
getpid());
1091#if defined (NSUPDATE)
1109 log_fatal(
"no memory for lease db filename.");
1122 log_fatal(
"no memory for pid filename.");
1142 log_fatal(
"no memory for lease db filename.");
1156 log_fatal(
"no memory for pid filename.");
1196 log_fatal(
"invalid omapi port data length");
1206 log_fatal(
"no memory for OMAPI key filename.");
1224 log_fatal(
"invalid local port data length");
1235 log_fatal(
"invalid remote port data length");
1247 log_fatal(
"invalid broadcast address data length");
1258 log_fatal(
"invalid local address data length");
1275#if defined (NSUPDATE)
1278 log_fatal(
"ddns-update-style ad_hoc no longer supported");
1312 log_fatal(
"Unable to complete ddns initialization");
1324 log_fatal(
"Support for ddns-update-style not compiled in");
1358#if defined(DELAYED_ACK)
1366 log_fatal(
"invalid max delayed ACK count ");
1375 "setting delayed-ack to zero (incompatible)");
1389 log_fatal(
"invalid max ack delay configuration");
1404 log_error(
"Not using fsync() to flush lease writes");
1411 log_info(
"Setting server-id-check true");
1438 log_fatal(
"invalid abandon-lease-time");
1444#if defined (FAILOVER_PROTOCOL)
1464 log_info(
"EUI64 leases will not be written to lease file");
1478#if defined (BINARY_LEASES)
1480 log_info(
"Source compiled to use binary-leases");
1492 omapi_listener_start (0);
1495#if defined (FAILOVER_PROTOCOL)
1522 log_debug (
"unexpected ICMP Echo Reply from %s",
1528#if defined (FAILOVER_PROTOCOL)
1530 !
lp ->
pool -> failover_peer)
1532 log_debug (
"ICMP Echo Reply for %s late or spurious.",
1538 log_debug (
"ICMP Echo reply while lease %s valid.",
1560#if defined (DEBUG_MEMORY_LEAKAGE)
1567#if defined (DEBUG_MEMORY_LEAKAGE)
1568 log_info (
"generation %ld: %ld new, %ld outstanding, %ld long-term",
1573#if defined (DEBUG_MEMORY_LEAKAGE)
1587 const char *
fnn =
"fallback-net";
1590 log_fatal (
"No memory for shared subnet: %s",
1594 log_fatal(
"no memory for shared network");
1609 log_error (
"Multiple interfaces match the %s: %s %s",
1616 log_fatal (
"Interface %s matches multiple shared %s",
1617 ip -> name,
"networks");
1627 log_error (
"Multiple interfaces match the %s: %s %s",
1628 "same shared network",
1636static TIME shutdown_time;
1637static int omapi_connection_count;
1658 omapi_connection_count++;
1676#if defined (FAILOVER_PROTOCOL)
1687 omapi_connection_count = 0;
1694 omapi_connection_count == 0) {
1717#if defined (FAILOVER_PROTOCOL)
1740#if defined (DEBUG_MEMORY_LEAKAGE) && \
1741 defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
1751#if defined (DEBUG_MEMORY_LEAKAGE) && \
1752 defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT)
1773 (
void (*)(
void *))dhcp_io_shutdown_countdown, 0, 0, 0);
1783 log_error (
"System time has been changed. Leases information unreliable!");
1798 dhcp_io_shutdown_countdown (0);
1812 (
void (*)(
void *))dhcp_io_shutdown_countdown, 0, 0, 0);
int group_allocate(struct group **ptr, const char *file, int line)
void data_string_forget(struct data_string *data, const char *file, int line)
int option_state_allocate(struct option_state **ptr, const char *file, int line)
int option_state_dereference(struct option_state **ptr, const char *file, int line)
isc_result_t end_parse(struct parse **cfile)
isc_result_t new_parse(struct parse **cfile, int file, char *inbuf, unsigned buflen, const char *name, int eolp)
void add_timeout(struct timeval *when, void *where, void *what, tvref_t ref, tvunref_t unref)
void cancel_timeout(void *where, void *what)
struct option_cache * lookup_option(struct universe *universe, struct option_state *options, unsigned code)
void do_packet(struct interface_info *interface, struct dhcp_packet *packet, unsigned len, unsigned int from_port, struct iaddr from, struct hardware *hfrom)
void add_enumeration(struct enumeration *enumeration)
int parse_executable_statements(struct executable_statement **statements, struct parse *cfile, int *lose, enum expression_context case_context)
char * absolute_path(const char *orgpath)
#define FAILOVER_PROTOCOL
u_int32_t getUShort(const unsigned char *)
u_int32_t getULong(const unsigned char *)
void trace_seed_input(trace_type_t *, unsigned, char *)
void trace_seed_stop(trace_type_t *)
void trace_seed_stash(trace_type_t *, unsigned)
int find_subnet(struct subnet **sp, struct iaddr addr, const char *file, int line)
void db_startup(int testp)
void lease_ping_timeout(void *vlp)
isc_boolean_t no_pid_file
int server_identifier_matched
int main(int argc, char **argv)
isc_result_t dhcp_io_shutdown(omapi_object_t *obj, void *foo)
u_int32_t abandon_lease_time
int dhcp_max_agent_option_packet_length
void postconf_initialization(int quiet)
const char * path_dhcpd_db
void lease_pinged(struct iaddr from, u_int8_t *packet, int length)
int dhcpd_interface_setup_hook(struct interface_info *ip, struct iaddr *ia)
const char * path_dhcpd_conf
enum dhcp_shutdown_state shutdown_state
isc_result_t dhcp_set_control_state(control_object_state_t oldstate, control_object_state_t newstate)
void postdb_startup(void)
const char * path_dhcpd_pid
struct class unknown_class
struct iaddr server_identifier
void mark_hosts_unavailable(void)
dhcp_failover_state_t * failover_states
int write_server_duid(void)
void do_packet6(struct interface_info *, const char *, int, int, const struct iaddr *, isc_boolean_t)
#define SV_ABANDON_LEASE_TIME
#define SV_CHECK_SECS_BYTE_ORDER
struct enumeration prefix_length_modes
#define INTERFACE_REQUESTED
void interface_trace_setup(void)
#define SV_SERVER_ID_CHECK
struct enumeration ddns_styles
void dhcp_failover_sanity_check(void)
#define SV_DDNS_LOCAL_ADDRESS4
#define SV_RELEASE_ON_ROAM
void classification_setup(void)
#define SV_DONT_USE_FSYNC
#define DISCOVER_SERVER46
void dhcp_failover_startup(void)
isc_result_t generate_new_server_duid(void)
void free_lease_state(struct lease_state *, const char *, int)
void parse_trace_setup(void)
#define DDNS_UPDATE_STYLE_NONE
dhcp_control_object_t * dhcp_control_object
void dhcp_common_objects_setup(void)
void abandon_lease(struct lease *, const char *)
#define SV_BIND_LOCAL_ADDRESS6
#define SV_DHCPV6_PID_FILE_NAME
#define SV_LIMITED_BROADCAST_ADDRESS
@ shutdown_drop_omapi_connections
@ shutdown_omapi_connections
void mark_phosts_unavailable(void)
#define DHCPD_LOG_FACILITY
u_int16_t get_conflict_mask(struct option_state *input_options)
void schedule_all_ipv6_lease_timeouts()
void dhcp_db_objects_setup(void)
struct universe server_universe
isc_result_t set_server_duid_from_option(void)
int group_writer(struct group_object *)
void(* dhcpv6_packet_handler)(struct interface_info *, const char *, int, int, const struct iaddr *, isc_boolean_t)
struct in6_addr local_address6
#define SV_DDNS_LOCAL_ADDRESS6
void trace_ddns_init(void)
#define SV_LEASE_FILE_NAME
#define DEFAULT_ABANDON_LEASE_TIME
#define SV_DHCPV6_LEASE_FILE_NAME
isc_result_t dhcp_failover_set_state(dhcp_failover_state_t *, enum failover_state)
struct enumeration syslog_enum
void report_jumbo_ranges()
#define SV_LOCAL_ADDRESS6
void dhcp_reply(struct lease *)
int find_lease_by_ip_addr(struct lease **, struct iaddr, const char *, int)
void initialize_server_option_spaces(void)
#define DDNS_UPDATE_STYLE_AD_HOC
isc_boolean_t server_duid_isset(void)
isc_result_t readconf(void)
#define SV_PREFIX_LEN_MODE
void mark_interfaces_unavailable(void)
#define SV_DDNS_UPDATE_STYLE
u_int16_t ddns_conflict_mask
struct interface_info * interfaces
struct in_addr limited_broadcast
void discover_interfaces(int state)
int quiet_interface_discovery
int(* dhcp_interface_setup_hook)(struct interface_info *, struct iaddr *)
void(* bootp_packet_handler)(struct interface_info *, struct dhcp_packet *, unsigned, unsigned int, struct iaddr, struct hardware *)
struct in_addr local_address
omapi_object_type_t * dhcp_type_interface
isc_result_t dhcp_interface_remove(omapi_object_t *lp, omapi_object_t *id)
void execute_statements_in_scope(struct binding_value **result, struct packet *packet, struct lease *lease, struct client_state *client_state, struct option_state *in_options, struct option_state *out_options, struct binding_scope **scope, struct group *group, struct group *limiting_group, struct on_star *on_star)
#define DEFAULT_HASH_SIZE
void icmp_startup(int routep, void *handler)
u_int16_t validate_port(char *port)
const char * piaddr(const struct iaddr addr)
u_int16_t validate_port_pair(char *port)
isc_result_t dhcp_context_create(int flags, struct in_addr *local4, struct in6_addr *local6)
void dhcp_signal_handler(int signal)
#define DHCP_CONTEXT_PRE_DB
#define DHCP_CONTEXT_POST_DB
struct group * root_group
int(* group_write_hook)(struct group_object *)
void omapi_print_dmalloc_usage_by_caller(void)
isc_result_t omapi_generic_new(omapi_object_t **, const char *, int)
isc_result_t omapi_object_dereference(omapi_object_t **, const char *, int)
isc_result_t omapi_protocol_listen(omapi_object_t *, unsigned, int)
isc_result_t omapi_disconnect(omapi_object_t *, int)
isc_result_t omapi_init(void)
isc_result_t omapi_auth_key_lookup_name(omapi_auth_key_t **, const char *)
omapi_object_type_t * omapi_type_protocol
isc_result_t omapi_io_state_foreach(isc_result_t(*func)(omapi_object_t *, void *), void *p)
calls a given function on every object
omapi_object_type_t * omapi_type_connection
void * dmalloc(size_t, const char *, int)
omapi_object_type_t * omapi_type_listener
void dfree(void *, const char *, int)
omapi_object_type_t * omapi_type_protocol_listener
isc_result_t omapi_protocol_configure_security(omapi_object_t *, isc_result_t(*)(omapi_object_t *, omapi_addr_t *), isc_result_t(*)(omapi_object_t *, omapi_auth_key_t *))
isc_result_t omapi_listener_destroy(omapi_object_t *, const char *, int)
isc_result_t omapi_set_int_value(omapi_object_t *, omapi_object_t *, const char *, int)
int log_error(const char *,...) __attribute__((__format__(__printf__
int int int log_debug(const char *,...) __attribute__((__format__(__printf__
void log_fatal(const char *,...) __attribute__((__format__(__printf__
int int log_info(const char *,...) __attribute__((__format__(__printf__
#define DHCP_R_INVALIDARG
#define DHCP_R_INVALIDKEY
struct executable_statement * statements
struct interface_info * next
struct lease_state * state
struct interface_info * interface
struct shared_network * shared_network
struct iaddr interface_address
void initialize_common_option_spaces()
trace_type_t * trace_type_register(const char *, void *, void(*)(trace_type_t *, unsigned, char *), void(*)(trace_type_t *), const char *, int)
isc_result_t trace_begin(const char *, const char *, int)
void trace_file_replay(const char *)
void trace_replay_init(void)
isc_result_t trace_init(void(*set_time)(time_t), const char *, int)
int evaluate_option_cache(struct data_string *result, struct packet *packet, struct lease *lease, struct client_state *client_state, struct option_state *in_options, struct option_state *cfg_options, struct binding_scope **scope, struct option_cache *oc, const char *file, int line)
int evaluate_boolean_option_cache(int *ignorep, struct packet *packet, struct lease *lease, struct client_state *client_state, struct option_state *in_options, struct option_state *cfg_options, struct binding_scope **scope, struct option_cache *oc, const char *file, int line)
struct binding_scope * global_scope