/* ****************************************************************************** * IPCOM CONFIGURATION SOURCE FILE * * Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: ipdhcps_config.c,v $ $Revision: 1.24.10.8 $ * $Source: /home/interpeak/CVSRoot/ipdhcps/config/ipdhcps_config.c,v $ * $Author: jren $ * $State: Exp $ $Locker: $ * * INTERPEAK_COPYRIGHT_STRING * * Design and implementation by Jonas Rendel ****************************************************************************** */ /* modification history -------------------- 01h,04sep09,h_s Fix defect WIND00184353. 01g,02jun09,spw Add no strict subnet match sysvar 01f,03jan07,kch Updated CVS revision log entry for Jan 03 code drop. 01e,11dec06,kch Modified ipdhcps_start_hook() and ipdhcps_stop_hook() to allow for user configurable callback hooks. Also added DHCPS_NETCONF_SYSVAR to allow preconfigure network configurations. 01d,01dec06,kch Updated CVS revision log entry. 01c,13sep06,kch Refresh with Sept 08, 2006 code drop 01b,04sep06,kch Include only minimum set of header files to workaround symbol redeclaration errors. 01a,28aug06,kch Update based on Aug 22, 2006 code drop. */ /* **************************************************************************** * 1 DESCRIPTION **************************************************************************** */ /* **************************************************************************** * 2 INCLUDE FILES **************************************************************************** */ #include "ipcom_config.h" #include "ipcom_err.h" /* ?? maybe should be IP_PORT_VXWORKS or PRJ_BUILD */ #ifndef IP_WB_BUILD #include "ipcom_clib.h" #include "ipcom_sock.h" #include "ipcom_inet.h" #include "ipcom_type.h" #include "ipcom_tmo.h" #include "ipcom_cstyle.h" #endif #include "ipcom_sysvar.h" #include "ipcom_shell.h" #ifdef IP_WB_BUILD #include "ipdhcps_config.h" #endif #ifndef IP_WB_BUILD #include "ipdhcps.h" #endif /* **************************************************************************** * 3 GENERAL **************************************************************************** */ /* **************************************************************************** * 4 DEFINES **************************************************************************** */ /* **************************************************************************** * 5 TYPES **************************************************************************** */ #ifdef IP_WB_BUILD /* typedef to make compiler happy... */ typedef int (*ipdhcps_start_cb)(void); typedef int (*ipdhcps_stop_cb)(void); #endif /* **************************************************************************** * 6 EXTERN PROTOTYPES **************************************************************************** */ #if defined(IPDHCPS_INCLUDE_CMD) || !defined(IP_WB_BUILD) IP_EXTERN int ipdhcps_cmd_dhcps(int argc, char **argv); #endif IP_EXTERN int ipdhcps_start_hook (void); IP_EXTERN int ipdhcps_stop_hook (void); #ifdef IPDHCPS_USE_EXAMPLE /* *=========================================================================== * example_dump_lease_db(void); *=========================================================================== * Description: Lease DB dump routine used in the configuration example * below. * */ IP_EXTERN Ip_s32 example_lease_dump_tmo_func(struct Ipcom_tmo_struct *tmo, void *cookie); /* *=========================================================================== * example_restore_lease_db(void) *=========================================================================== * Description: Lease DB restore routine used in the configuration example * below. * */ IP_EXTERN int example_restore_lease_db(void); #endif #if defined (IPDHCPS_INCLUDE_CMD) && defined (IPDHCPS_INCLUDE_ISC_EXAMPLE) /* *=========================================================================== * example_isc_config *=========================================================================== * Description: * Parameters: * Returns: * */ IP_GLOBAL Ip_s32 example_isc_config(const char *cfgfile); #endif /* **************************************************************************** * 7 LOCAL PROTOTYPES **************************************************************************** */ /* **************************************************************************** * 8 DATA **************************************************************************** */ #ifdef IPDHCPS_USE_EXAMPLE /* *=========================================================================== * lease_dump_tmo *=========================================================================== * Description: IPCOM timeout handler used in the configuration example * below. * */ IP_STATIC Ipcom_tmo lease_dump_tmo; #endif /* if needed, use VIP control this value */ #define DHCPS_USE_REMOTE_AGENT_CLASS_ID "true" #define DHCPS_STRICT_VENDER_CLASS_ID_MATCH "true" /* *=========================================================================== * ipdhcps_conf_sysvar *=========================================================================== * Description: Initiates mandatory system configuration variables specific * for IPDHCPS. * */ IP_STATIC IP_CONST Ipcom_sysvar ipdhcps_conf_sysvar[] = { /* * server_port * * UDP port used by the IPDHCPS server. * * Default: 67 */ IP_SYSVAR("ipdhcps.server_port", "67", DHCPS_SERVER_PORT), /* * client_port * * UDP port used by the dhcp/bootp clients. * * Default: 68 */ IP_SYSVAR("ipdhcps.client_port", "68", DHCPS_CLIENT_PORT), /* * default_lease_time * * The default time a client can hold a dynamic lease before * it expires. * * Default: 864000 seconds (10 days). */ IP_SYSVAR("ipdhcps.default_lease_time", "864000", DHCPS_DEFAULT_LEASE_TIME), /* * max_lease_time * * The maximum time a client can hold a dynamic lease before * it expires. * * Default: 8640000 seconds (100 days). */ IP_SYSVAR("ipdhcps.max_lease_time", "864000", DHCPS_MAX_LEASE_TIME), /* * min_lease_time * * The minimimum time a client can hold a dynamic lease before * it expires. * * Default: 60 seconds */ IP_SYSVAR("ipdhcps.min_lease_time", "60", DHCPS_MIN_LEASE_TIME), /* * renewal_time * * The time in seconds when the client must start asking to extend * the lease. This is known as T1 or the renewal time. * If this constant is set to zero the server will not give * the client a value for T1. The client then typically * defaults this value to one-half of its lease time. * * Default: disabled * */ IP_SYSVAR("ipdhcps.renewal_time", "disabled", DHCPS_RENEWAL_TIME), /* * rebinding_time * * The time in seconds when the client must start rebinding * the lease if it has failed to renew it. This is known as T2 * or the rebinding time. * If this constant is set to zero the server will not give * the client a value for T2. The client then typically defaults * value for this parameter. * * Default: disabled */ IP_SYSVAR("ipdhcps.rebinding_time", "disabled", DHCPS_REBINDING_TIME), /* * in_abandoned_state_max_time * * The time that must pass before an abandoned lease is allowed * to be released and set to state free. * * Default: 8640000 seconds (100 days) */ IP_SYSVAR("ipdhcps.in_abandoned_state_max_time", "8640000", DHCPS_ABANDONED_STATE_MAX_TIME), /* * in_expired_state_max_time * * The time in seconds that must pass before an expired lease will * be set to state free to be reused. * * Default: "forever" */ IP_SYSVAR("ipdhcps.in_expired_state_max_time", "forever", DHCPS_EXPIRED_STATE_MAX_TIME), /* * in_released_state_max_time * * The time in seconds that must pass before a released lease can * be set to state free to be reused. * * Default: "forever" */ IP_SYSVAR("ipdhcps.in_released_state_max_time", "forever", DHCPS_RELEASED_STATE_MAX_TIME), /* * in_offered_state_max_time * * The time in seconds that must pass before an offered lease can * be set to state free to be reused. * * Default: 10 seconds */ IP_SYSVAR("ipdhcps.in_offered_state_max_time", "10", DHCPS_OFFERED_STATE_MAX_TIME), /* * lease_for_bootp_client_max_time * * The time in seconds that must pass before a lease held by a * bootp client can be set to state free to be reused. * * Default: "forever" */ IP_SYSVAR("ipdhcps.lease_for_bootp_client_max_time", "forever", DHCPS_LEASE_BOOTPC_MAX_TIME), /* * allow_decline * * This boolean tells if IPDHCPS shall ignore DHCP DECLINE messages * or if it shall honor them in an appropriate way. * If set to "true" the IPDHCPS lease database can in worst case be * exhausted by a malfunctioning DHCP client or a denial of service * attack. * * Default: "true" */ IP_SYSVAR("ipdhcps.allow_decline", "true", DHCPS_ALLOW_DECLINE), /* * enable_new_interface_when_found * * This boolean tells if IPDHCPS shall treat newly found interfaces * as 'enabled' directly when they have been found and attached to * the IPDHCPS. * * If this variable is set to 'false' it is necessary to explicitly * instruct the IPDHCPS which interface(s) it shall use. * This can be done from the shell by issuing the command: * 'dhcps interface enable ' * The same command can also be issued from the netconf sysvar list * upon startup. * * Default: "true" */ IP_SYSVAR("ipdhcps.enable_new_interface_when_found", "true", DHCPS_AUTO_ENABLE_INTERFACES), /* * packet_size * * The size in bytes of a DHCP packet rx/tx buffer used by IPDHCPS. It must never * be less than 576 bytes. * * Default: 576 bytes */ IP_SYSVAR("ipdhcps.packet_size", "576", DHCPS_PKT_SIZE), /* * allow_bootp * * This boolean tells if IPDHCPS shall accept requests from bootp * clients or not. * * Default: "true" */ IP_SYSVAR("ipdhcps.allow_bootp", "true", DHCPS_ALLOW_BOOTP), /* * allow_dynamic_bootp * * This boolean tells if IPDHCPS shall accept allocating dynamic leases * to bootp clients or not. * Becasue of limitations in the bootp protocol, this type of clients * can not release allocated addresses. Hence it is not recommended to * allow them to have dynamic leases. * * Default : "false" (do not accept) */ IP_SYSVAR("ipdhcps.allow_dynamic_bootp", "false", DHCPS_ALLOW_DYNAMIC_BOOTP), /* * do_icmp_address_check * * This boolean tells if IPDHCPS shall perfom a icmp ping check on * each address before it is offered to a DHCP client. * * Default : "false" */ IP_SYSVAR("ipdhcps.do_icmp_address_check", "false", DHCPS_DO_ICMP_ADDRESS_CHECK), /* * authorized_agents * * This parameter is either set to "any" or is a list of IP * addresses to dhcp relay agents that are authorized to * access this dhcp server. * * Default : "any" */ IP_SYSVAR("ipdhcps.authorized_agents", "any", DHCPS_AUTHORIZED_AGENTS), /* * no_strict_subnet_match * * This boolean determines whether IPDHCPS should _not_ prefer to issue a lease from * a pool with the same subnet that is present on the enabled dhcps interface. * * Default: "false" */ IP_SYSVAR("ipdhcps.no_strict_subnet_match", "false", DHCPS_NO_STRICT_SUBNET_MATCH), /* * use_remote_agent_class_id * * This boolean determines whether IPDHCPS check class ID or not. * * Default: "true" */ IP_SYSVAR("ipdhcps.use_remote_agent_class_id", "true", DHCPS_USE_REMOTE_AGENT_CLASS_ID), IP_SYSVAR("ipdhcps.strict_vender_class_id_match", "true", DHCPS_STRICT_VENDER_CLASS_ID_MATCH), { IP_NULL, IP_NULL } }; /* *=========================================================================== * ipdhcps_netconf_sysvar *=========================================================================== * Description: Initiates optional network configuration variables used * for IPDHCPS. The intention of this variable set is to initiate * the dhcp server with a preconfigured setup of networks and hosts * to handle. * Each of these system variables must have a name as below: * ipdhcps.netconf. * The value of the system variable must be a IPDHCPS specific * shell command (without the preceding 'dhcps'). * * Below is an example on how to use it. * */ #ifdef IPDHCPS_INCLUDE_CMD IP_STATIC IP_CONST Ipcom_sysvar ipdhcps_netconf_sysvar[] = { #if defined(IPDHCPS_USE_EXAMPLE) || defined(INCLUDE_IPDHCPS_USE_EXAMPLE) /* Add a subnet 10.1.0.0 with subnet mask 255.255.0.0 */ {"ipdhcps.netconf.00", "subnet add 10.1.0.0 255.255.0.0"}, /* Add an address pool to this subnet */ {"ipdhcps.netconf.01", "pool add 10.1.0.0 10.1.0.5 10.1.0.99"}, /* Add another address pool to this subnet */ {"ipdhcps.netconf.02", "pool add 10.1.0.0 10.1.0.199 10.1.0.249"}, /* Add a domain name (dhcp option 15) to this subnet */ {"ipdhcps.netconf.03", "option add 10.1.0.0 15 green.net"}, /* Add a router (dhcp option 3) to this subnet */ {"ipdhcps.netconf.04", "option add 10.1.0.0 3 10.1.0.1"}, /* Add a name server (dhcp option 5) to this subnet */ {"ipdhcps.netconf.05", "option add 10.1.0.0 5 10.1.0.2"}, /* A another subnet 192.168.2.0 with netmask 255.255.255.0 */ {"ipdhcps.netconf.06", "subnet add 192.168.2.0 255.255.255.0"}, /* Add an address pool to this subnet*/ {"ipdhcps.netconf.07", "pool add 192.168.2.0 192.168.2.10 192.168.2.50"}, /* Add a domain name (dhcp option 15) to this subnet */ {"ipdhcps.netconf.08", "option add 192.168.2.0 15 blue.net"}, /* Add two routers (dhcp option 3) to this subnet */ {"ipdhcps.netconf.09", "option add 192.168.2.0 3 192.168.2.1 192.168.2.2"}, /* Add a static route (dhcp option 33) on this subnet (10.1.0.0->192.168.2.2 */ {"ipdhcps.netconf.10", "option add 192.168.2.0 33 10.1.0.0 192.168.2.2"}, /* Set max lease time to 120 seconds on this subnet */ {"ipdhcps.netconf.11", "config set 192.168.2.0 max-lease-time 120"}, /* Set default lease time to 60 seconds on this subnet */ {"ipdhcps.netconf.12", "config set 192.168.2.0 default-lease-time 60"}, /* Add a host with the client identifier 'Jack's lap top' */ {"ipdhcps.netconf.13", "host add 10.1.0.142 -i \"\\0Jack's lap top\""}, /* Add a host name (dhcp option 12) for this host */ {"ipdhcps.netconf.14", "option add 10.1.0.142 12 blue-host"}, /* Add a router (dhcp option 3) to this host */ {"ipdhcps.netconf.15", "option add 10.1.0.142 3 10.1.0.1"}, /* Add a host with a standard ethernet MAC address */ {"ipdhcps.netconf.16", "host add 10.1.0.141 -h BE:60:13:F7:F8:0F"}, /* Add a host name (dhcp option 12) for this host */ {"ipdhcps.netconf.17", "option add 10.1.0.141 12 yellow-host"}, /* Setup a boot file for this host */ {"ipdhcps.netconf.18", "config set 10.1.0.141 boot-file /boot/yellow-host.boot"}, /* Setup a boot server for this host to boot from */ {"ipdhcps.netconf.19", "config set 10.1.0.141 next-server-name black-server"}, /* Setup the default lease time to 600 seconds on the default net */ {"ipdhcps.netconf.20", "config set default default-lease-time 600"}, /* Setup bootp allowance on the default net */ {"ipdhcps.netconf.21", "config set default allow-bootp false"}, /* Enable ICMP ping checking on subnet 10.1.0.0 */ {"ipdhcps.netconf.22", "config set 10.1.0.0 do-icmp-address-check true"}, /* Add vendor class identifer on subnet 10.1.0.0 */ {"ipdhcps.netconf.23", "class add 10.1.0.0 first-class vendor first"}, /* Add vendor class on default */ {"ipdhcps.netconf.24", "class add default second-class vendor second"}, /* Setup ARP cache timeout on subnet 10.1.0.0 */ {"ipdhcps.netconf.25", "option add 10.1.0.0 35 10"}, /* Setup ARP cache timeout for vendor class on subnet 10.1.0.0 */ {"ipdhcps.netconf.26", "option add 10.1.0.0 -c first-class 35 20"}, /* Setup ARP cache on default */ {"ipdhcps.netconf.27", "option add default 35 60"}, /* Setup ARP cache on vendor class on default */ {"ipdhcps.netconf.28", "option add default -c second-class 35 40"}, /* Setup authorized relay agents on subnet 10.1.0.0 */ {"ipdhcps.netconf.29", "config set 10.1.0.0 authorized-agents 10.1.0.2 10.1.0.3"}, #endif /* IPDHCPS_USE_EXAMPLE || INCLUDE_IPDHCPS_USE_EXAMPLE */ { IP_NULL, IP_NULL} }; #endif /* IPDHCPS_INCLUDE_CMD */ /* **************************************************************************** * 10 GLOBAL FUNCTIONS **************************************************************************** */ #ifdef IP_WB_BUILD #if DHCPS_INSTALL_CALLBACK_HOOK == TRUE /* * forward declarations for the user-defined dhcp server callback hooks * to satisfy the compiler. */ #if defined(DHCPS_START_CALLBACK_HOOK)&& defined(DHCPS_STOP_CALLBACK_HOOK) int DHCPS_START_CALLBACK_HOOK (void); int DHCPS_STOP_CALLBACK_HOOK (void); #endif #else /* * DHCPS_START_CALLBACK_HOOK and DHCPS_STOP_CALLBACK_HOOK are applicable * only if DHCPS_INSTALL_CALLBACK_HOOK is set to TRUE. Explicitly re-define * these hooks to NULL so that we don't get compiler errors */ #undef DHCPS_START_CALLBACK_HOOK #define DHCPS_START_CALLBACK_HOOK NULL #undef DHCPS_STOP_CALLBACK_HOOK #define DHCPS_STOP_CALLBACK_HOOK NULL #endif /* DHCPS_INSTALL_CALLBACK_HOOK */ #endif /* IP_WB_BUILD */ /* *=========================================================================== * ipdhcps_start_hook *=========================================================================== * Description: This routine is called by IPDHCPS at start-up. It is * intended to be used for static configuration of IPDHCPS, * for instance to install a lease 'dump to file' routine and/or * to restore a IPDHCPS database from a lease dump. * * * Parameters: - * Returns: 0 - success * -1 - failure * */ IP_GLOBAL int ipdhcps_start_hook (void) { #ifdef IP_WB_BUILD ipdhcps_start_cb dhcps_cb; dhcps_cb = (DHCPS_START_CALLBACK_HOOK != NULL) ? DHCPS_START_CALLBACK_HOOK : NULL; /* * call the user callback routine if provided. Otherwise, simply return 0. */ return (dhcps_cb != NULL) ? dhcps_cb() : 0; #else /* IP_WB_BUILD */ int ret = 0; #ifdef IPDHCPS_USE_EXAMPLE /* Restore lease database */ example_restore_lease_db (); ipcom_tmo_request (&lease_dump_tmo, example_lease_dump_tmo_func, &lease_dump_tmo, 10*60*60*1000); #endif /* IPDHCPS_USE_EXAMPLE */ #if defined (IPDHCPS_INCLUDE_CMD) && defined (IPDHCPS_INCLUDE_ISC_EXAMPLE) { char *cfgfile = ipcom_sysvar_get("ipdhcps.iscfile", IP_NULL, IP_NULL); if (cfgfile) { ret = example_isc_config(cfgfile); ipcom_free(cfgfile); } } #endif return ret; #endif /* IP_WB_BUILD */ } /* *=========================================================================== * ipdhcps_stop_hook *=========================================================================== * Description: Shows how to save the lease database at shutdown. * Parameters: * Returns: * */ IP_GLOBAL int ipdhcps_stop_hook (void) { #ifdef IP_WB_BUILD ipdhcps_stop_cb dhcps_cb; dhcps_cb = (DHCPS_STOP_CALLBACK_HOOK != NULL) ? DHCPS_STOP_CALLBACK_HOOK : NULL; /* * call the user callback routine if provided. Otherwise, simply return 0. */ return (dhcps_cb != NULL) ? dhcps_cb() : 0; #else /* IP_WB_BUILD */ #ifdef IPDHCPS_USE_EXAMPLE (void)ipcom_tmo_cancel (&lease_dump_tmo); example_dump_lease_db (); #endif return 0; #endif /* IP_WB_BUILD */ } /* **************************************************************************** * 11 GLOBAL FUNCTIONS **************************************************************************** */ /* *=========================================================================== * ipdhcps_configure *=========================================================================== * Description: * Parameters: * Returns: * */ IP_PUBLIC Ip_err ipdhcps_configure(void) { Ip_err ret; /* Initialize IPDHCPS system configuration. */ (void)ipcom_sysvar_setv(ipdhcps_conf_sysvar, 0); #if defined (IPDHCPS_INCLUDE_CMD) { #ifdef IP_WB_BUILD Ipcom_sysvar *entries; if ((entries = (Ipcom_sysvar *)DHCPS_NETCONF_SYSVAR) != NULL) { /* Initialize IPDHCPS network preconfiguration */ (void)ipcom_sysvar_setv(entries, 0); } #else /* IP_WB_BUILD */ /* Initialize IPDHCPS network preconfiguration */ (void)ipcom_sysvar_setv(ipdhcps_netconf_sysvar, 0); #endif /* IP_WB_BUILD */ #endif #if defined(IPDHCPS_INCLUDE_CMD) || !defined(IP_WB_BUILD) ret = ipcom_shell_add_cmd("dhcps", "dhcps ...", "DHCP server shell tool", (Ipcom_shell_cmd_type) ipdhcps_cmd_dhcps, IPCOM_SHELL_PRIO_SAME, IPCOM_PROC_STACK_DEFAULT); if(ret != IPCOM_SUCCESS) return ret; } #endif return IPCOM_SUCCESS; } /* **************************************************************************** * END OF FILE **************************************************************************** */