📄 dhcpd.c
字号:
oc = lookup_option (&server_universe, options, SV_LOG_FACILITY); if (oc) { if (evaluate_option_cache (&db, (struct packet *)0, (struct lease *)0, (struct client_state *)0, options, (struct option_state *)0, &global_scope, oc, MDL)) { if (db.len == 1) { closelog ();#ifdef SYSLOG_4_2 openlog ("dhcpd", LOG_NDELAY); log_priority = db.data [0];#else openlog ("dhcpd", LOG_NDELAY, db.data [0]);#endif /* Log the startup banner into the new log file. */ if (!quiet) { /* Don't log to stderr twice. */ tmp = log_perror; log_perror = 0; log_info ("%s %s", message, DHCP_VERSION); log_info (copyright); log_info (arr); log_info (url); log_perror = tmp; } } else log_fatal ("invalid log facility"); data_string_forget (&db, MDL); } } /* Don't need the options anymore. */ option_state_dereference (&options, MDL); #if defined (NSUPDATE) /* If old-style ddns updates have been requested, parse the old-style ddns updater. */ if (ddns_update_style == 1) { struct executable_statement **e, *s; if (root_group -> statements) { s = (struct executable_statement *)0; if (!executable_statement_allocate (&s, MDL)) log_fatal ("no memory for ddns updater"); executable_statement_reference (&s -> next, root_group -> statements, MDL); executable_statement_dereference (&root_group -> statements, MDL); executable_statement_reference (&root_group -> statements, s, MDL); s -> op = statements_statement; e = &s -> data.statements; executable_statement_dereference (&s, MDL); } else { e = &root_group -> statements; } /* Set up the standard name service updater routine. */ parse = (struct parse *)0; result = new_parse (&parse, -1, old_nsupdate, (sizeof old_nsupdate) - 1, "old name service update routine", 0); if (result != ISC_R_SUCCESS) log_fatal ("can't begin parsing old ddns updater!"); tmp = 0; if (!(parse_executable_statements (e, parse, &tmp, context_any))) { end_parse (&parse); log_fatal ("can't parse standard ddns updater!"); } end_parse (&parse); }#endif}void postdb_startup (void){ /* Initialize the omapi listener state. */ if (omapi_port != -1) { omapi_listener_start (0); }#if defined (FAILOVER_PROTOCOL) /* Initialize the failover listener state. */ dhcp_failover_startup ();#endif}/* Print usage message. */static void usage (){ log_info ("%s %s", message, DHCP_VERSION); log_info (copyright); log_info (arr); log_fatal ("Usage: dhcpd [-p <UDP port #>] [-d] [-f]%s%s%s%s", "\n [-cf config-file] [-lf lease-file]",#if defined (TRACING) "\n [-tf trace-output-file]", "\n [-play trace-input-file]",#else "", "",#endif /* TRACING */ "\n [-t] [-T] [-s server] [if0 [...ifN]]");}void lease_pinged (from, packet, length) struct iaddr from; u_int8_t *packet; int length;{ struct lease *lp; /* Don't try to look up a pinged lease if we aren't trying to ping one - otherwise somebody could easily make us churn by just forging repeated ICMP EchoReply packets for us to look up. */ if (!outstanding_pings) return; lp = (struct lease *)0; if (!find_lease_by_ip_addr (&lp, from, MDL)) { log_debug ("unexpected ICMP Echo Reply from %s", piaddr (from)); return; } if (!lp -> state) {#if defined (FAILOVER_PROTOCOL) if (!lp -> pool || !lp -> pool -> failover_peer)#endif log_debug ("ICMP Echo Reply for %s late or spurious.", piaddr (from)); goto out; } if (lp -> ends > cur_time) { log_debug ("ICMP Echo reply while lease %s valid.", piaddr (from)); } /* At this point it looks like we pinged a lease and got a response, which shouldn't have happened. */ data_string_forget (&lp -> state -> parameter_request_list, MDL); free_lease_state (lp -> state, MDL); lp -> state = (struct lease_state *)0; abandon_lease (lp, "pinged before offer"); cancel_timeout (lease_ping_timeout, lp); --outstanding_pings; out: lease_dereference (&lp, MDL);}void lease_ping_timeout (vlp) void *vlp;{ struct lease *lp = vlp;#if defined (DEBUG_MEMORY_LEAKAGE) unsigned long previous_outstanding = dmalloc_outstanding;#endif --outstanding_pings; dhcp_reply (lp);#if defined (DEBUG_MEMORY_LEAKAGE) log_info ("generation %ld: %ld new, %ld outstanding, %ld long-term", dmalloc_generation, dmalloc_outstanding - previous_outstanding, dmalloc_outstanding, dmalloc_longterm);#endif#if defined (DEBUG_MEMORY_LEAKAGE) dmalloc_dump_outstanding ();#endif}int dhcpd_interface_setup_hook (struct interface_info *ip, struct iaddr *ia){ struct subnet *subnet; struct shared_network *share; isc_result_t status; /* Special case for fallback network - not sure why this is necessary. */ if (!ia) { const char *fnn = "fallback-net"; char *s; status = shared_network_allocate (&ip -> shared_network, MDL); if (status != ISC_R_SUCCESS) log_fatal ("No memory for shared subnet: %s", isc_result_totext (status)); ip -> shared_network -> name = dmalloc (strlen (fnn) + 1, MDL); strcpy (ip -> shared_network -> name, fnn); return 1; } /* If there's a registered subnet for this address, connect it together... */ subnet = (struct subnet *)0; if (find_subnet (&subnet, *ia, MDL)) { /* If this interface has multiple aliases on the same subnet, ignore all but the first we encounter. */ if (!subnet -> interface) { interface_reference (&subnet -> interface, ip, MDL); subnet -> interface_address = *ia; } else if (subnet -> interface != ip) { log_error ("Multiple interfaces match the %s: %s %s", "same subnet", subnet -> interface -> name, ip -> name); } share = subnet -> shared_network; if (ip -> shared_network && ip -> shared_network != share) { log_fatal ("Interface %s matches multiple shared %s", ip -> name, "networks"); } else { if (!ip -> shared_network) shared_network_reference (&ip -> shared_network, share, MDL); } if (!share -> interface) { interface_reference (&share -> interface, ip, MDL); } else if (share -> interface != ip) { log_error ("Multiple interfaces match the %s: %s %s", "same shared network", share -> interface -> name, ip -> name); } subnet_dereference (&subnet, MDL); } return 1;}static TIME shutdown_time;static int omapi_connection_count;enum dhcp_shutdown_state shutdown_state;isc_result_t dhcp_io_shutdown (omapi_object_t *obj, void *foo){ /* Shut down all listeners. */ if (shutdown_state == shutdown_listeners && obj -> type == omapi_type_listener && obj -> inner && obj -> inner -> type == omapi_type_protocol_listener) { omapi_listener_destroy (obj, MDL); return ISC_R_SUCCESS; } /* Shut down all existing omapi connections. */ if (obj -> type == omapi_type_connection && obj -> inner && obj -> inner -> type == omapi_type_protocol) { if (shutdown_state == shutdown_drop_omapi_connections) { omapi_disconnect (obj, 1); } omapi_connection_count++; if (shutdown_state == shutdown_omapi_connections) { omapi_disconnect (obj, 0); return ISC_R_SUCCESS; } } /* Shutdown all DHCP interfaces. */ if (obj -> type == dhcp_type_interface && shutdown_state == shutdown_dhcp) { dhcp_interface_remove (obj, (omapi_object_t *)0); return ISC_R_SUCCESS; } return ISC_R_SUCCESS;}static isc_result_t dhcp_io_shutdown_countdown (void *vlp){ dhcp_failover_state_t *state;#if defined (FAILOVER_PROTOCOL) int failover_connection_count = 0;#endif oncemore: if (shutdown_state == shutdown_listeners || shutdown_state == shutdown_omapi_connections || shutdown_state == shutdown_drop_omapi_connections || shutdown_state == shutdown_dhcp) { omapi_connection_count = 0; omapi_io_state_foreach (dhcp_io_shutdown, 0); } if ((shutdown_state == shutdown_listeners || shutdown_state == shutdown_omapi_connections || shutdown_state == shutdown_drop_omapi_connections) && omapi_connection_count == 0) { shutdown_state = shutdown_dhcp; shutdown_time = cur_time; goto oncemore; } else if (shutdown_state == shutdown_listeners && cur_time - shutdown_time > 4) { shutdown_state = shutdown_omapi_connections; shutdown_time = cur_time; } else if (shutdown_state == shutdown_omapi_connections && cur_time - shutdown_time > 4) { shutdown_state = shutdown_drop_omapi_connections; shutdown_time = cur_time; } else if (shutdown_state == shutdown_drop_omapi_connections && cur_time - shutdown_time > 4) { shutdown_state = shutdown_dhcp; shutdown_time = cur_time; goto oncemore; } else if (shutdown_state == shutdown_dhcp && cur_time - shutdown_time > 4) { shutdown_state = shutdown_done; shutdown_time = cur_time; }#if defined (FAILOVER_PROTOCOL) /* Set all failover peers into the shutdown state. */ if (shutdown_state == shutdown_dhcp) { for (state = failover_states; state; state = state -> next) { if (state -> me.state == normal) { dhcp_failover_set_state (state, shut_down); failover_connection_count++; } if (state -> me.state == shut_down && state -> partner.state != partner_down) failover_connection_count++; } } if (shutdown_state == shutdown_done) { for (state = failover_states; state; state = state -> next) { if (state -> me.state == shut_down) { if (state -> link_to_peer) dhcp_failover_link_dereference (&state -> link_to_peer, MDL); dhcp_failover_set_state (state, recover); } }#if defined (DEBUG_MEMORY_LEAKAGE) && \ defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT) free_everything (); omapi_print_dmalloc_usage_by_caller ();#endif exit (0); } #else if (shutdown_state == shutdown_done) {#if defined (DEBUG_MEMORY_LEAKAGE) && \ defined (DEBUG_MEMORY_LEAKAGE_ON_EXIT) free_everything (); omapi_print_dmalloc_usage_by_caller (); #endif exit (0); }#endif if (shutdown_state == shutdown_dhcp && !failover_connection_count) { shutdown_state = shutdown_done; shutdown_time = cur_time; goto oncemore; } add_timeout (cur_time + 1, (void (*)(void *))dhcp_io_shutdown_countdown, 0, 0, 0); return ISC_R_SUCCESS;}isc_result_t dhcp_set_control_state (control_object_state_t oldstate, control_object_state_t newstate){ if (newstate == server_shutdown) { shutdown_time = cur_time; shutdown_state = shutdown_listeners; dhcp_io_shutdown_countdown (0); return ISC_R_SUCCESS; } return ISC_R_INVALIDARG;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -