[Dhcp-agent-commits] dhcp-agent dhcp-client.c,1.33,1.34 dhcp-sysconf.c,1.20,1.21 dhcp-sysconf.h,1.2,
Status: Alpha
Brought to you by:
actmodern
From: <bk...@us...> - 2002-06-24 02:04:59
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv22556 Modified Files: dhcp-client.c dhcp-sysconf.c dhcp-sysconf.h Log Message: Implement framework for sysconf_*_cleanup functions. A default route cleanup is here too. And the client calls do_sysconf_cleanup() when shutting down. Index: dhcp-client.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client.c,v retrieving revision 1.33 retrieving revision 1.34 diff -C2 -d -r1.33 -r1.34 *** dhcp-client.c 23 Jun 2002 22:50:19 -0000 1.33 --- dhcp-client.c 24 Jun 2002 02:04:56 -0000 1.34 *************** *** 25,28 **** --- 25,29 ---- #include <dhcp-agent.h> #include <dhcp-util.h> + #include <dhcp-sysconf.h> #include <dhcp-globconf.h> #include <dhcp-files.h> *************** *** 125,128 **** --- 126,130 ---- if(dc) { /* only do clean up if we can. */ + do_sysconf_cleanup(dc); client_release(dc); delete_pid_file(dc->interface); Index: dhcp-sysconf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-sysconf.c,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** dhcp-sysconf.c 22 Jun 2002 01:47:57 -0000 1.20 --- dhcp-sysconf.c 24 Jun 2002 02:04:56 -0000 1.21 *************** *** 38,105 **** sysconf_handler sysconf_handlers[] = { ! { NULL, }, /* 0 */ /* Pad -- don't handle here. */ ! { NULL, }, /* 1 */ /* Subnet mask -- don't handle here.*/ ! { NULL, }, /* 2 */ /* time offset. */ ! { sysconf_routers, }, /* 3 */ /* routers. */ ! { NULL, }, /* 4 */ /* time server. */ ! { NULL, }, /* 5 */ /* name server (old). */ ! { sysconf_domain_name_servers, }, /* 6 */ /* domain name servers. */ ! { NULL, }, /* 7 */ /* mit-lcs log server. */ ! { NULL, }, /* 8 */ /* cookie servers. */ ! { NULL, }, /* 9 */ /* lpr servers. */ ! { NULL, }, /* 10 */ /* impress server. */ ! { NULL, }, /* 11 */ /* resource location server. */ ! { NULL, }, /* 12 */ /* host name option. */ ! { NULL, }, /* 13 */ /* boot file size option. */ ! { NULL, }, /* 14 */ /* merit dump file. */ ! { sysconf_domain_name, }, /* 15 */ /* domain name. */ ! { NULL, }, /* 16 */ /* swap server. */ ! { NULL, }, /* 17 */ /* root path. */ ! { NULL, }, /* 18 */ /* extension path */ ! { NULL, }, /* 19 */ /* ip forwarding. */ ! { NULL, }, /* 20 */ /* non local source routing. */ ! { NULL, }, /* 21 */ /* policy filter option. */ ! { NULL, }, /* 23 */ /* maximum dgram reassembly. */ ! { NULL, }, /* 24 */ /* mtu aging timeout. */ ! { NULL, }, /* 25 */ /* mtu plateau table. */ ! { NULL, }, /* 26 */ /* interface mtu */ ! { NULL, }, /* 27 */ /* subnets are local. */ ! { NULL, }, /* 28 */ /* broadcast address. */ ! { NULL, }, /* 29 */ /* perform mask discovery. */ ! { NULL, }, /* 30 */ /* mask supplier. */ ! { NULL, }, /* 31 */ /* perform router discovery. */ ! { NULL, }, /* 32 */ /* router soliciation address. */ ! { NULL, }, /* 33 */ /* static route. */ ! { NULL, }, /* 34 */ /* trailer encapsulation. */ ! { NULL, }, /* 35 */ /* arp cache timeout. */ ! { NULL, }, /* 36 */ /* ethernet encapsulation. */ ! { NULL, }, /* 37 */ /* tcp default ttl. */ ! { NULL, }, /* 38 */ /* tcp keepalive garbage option. */ ! { NULL, }, /* 39 */ /* network information service domain. */ ! { NULL, }, /* 40 */ /* network time protocol servers. */ ! { NULL, }, /* 41 */ /* vendor specific. */ ! { NULL, }, /* 42 */ /* netbios over TCP/IP name server. */ ! { NULL, }, /* 43 */ /* netbios over tcp/ip */ ! { NULL, }, /* 44 */ ! { NULL, }, /* 45 */ ! { NULL, }, /* 46 */ ! { NULL, }, /* 47 */ ! { NULL, }, /* 48 */ ! { NULL, }, /* 49 */ ! { NULL, }, /* 50 */ ! { NULL, }, /* 51 */ ! { NULL, }, /* 52 */ ! { NULL, }, /* 53 */ ! { NULL, }, /* 54 */ ! { NULL, }, /* 55 */ ! { NULL, }, /* 56 */ ! { NULL, }, /* 57 */ ! { NULL, }, /* 58 */ ! { NULL, }, /* 59 */ ! { NULL, }, /* 60 */ ! { NULL, }, /* 61 */ }; ! int sysconf_routers(void *value, dhcp_client_control_t *dc) { struct route_entry r_entry; --- 38,168 ---- sysconf_handler sysconf_handlers[] = { ! /* 0 Pad -- not handled here. */ ! { NULL, NULL, SYSCONF_UNSET, }, ! /* 1 Subnet mask -- not handled here. */ ! { NULL, NULL, SYSCONF_UNSET, }, ! /* 2 Time offset. */ ! { NULL, NULL, SYSCONF_UNSET, }, ! /* 3 Routers. */ ! { sysconf_setup_routers, sysconf_cleanup_routers, SYSCONF_UNSET, }, ! /* 4 Time server. */ ! { NULL, NULL, SYSCONF_UNSET, }, ! /* 5 Name servers. */ ! { NULL, NULL, SYSCONF_UNSET, }, ! /* 6 Domain name servers. */ ! { sysconf_setup_domain_name_servers, NULL, SYSCONF_UNSET, }, ! /* 7 MIT LCS log servers. */ ! { NULL, NULL, SYSCONF_UNSET, }, ! /* 8 Cookie servers. */ ! { NULL, NULL, SYSCONF_UNSET, }, ! /* 9 LPR servers. */ ! { NULL, NULL, SYSCONF_UNSET, }, ! /* 10 Impress server. */ ! { NULL, NULL, SYSCONF_UNSET, }, ! /* 11 Resource location servers. */ ! { NULL, NULL, SYSCONF_UNSET, }, ! /* 12 Hostname. */ ! { NULL, NULL, SYSCONF_UNSET, }, ! /* 13 Boot file size. */ ! { NULL, NULL, SYSCONF_UNSET, }, ! /* 14 Merit dump file. */ ! { NULL, NULL, SYSCONF_UNSET, }, ! /* 15 Domain name. */ ! { sysconf_setup_domain_name, NULL, SYSCONF_UNSET, }, ! /* 16 Swap server. */ ! { NULL, NULL, SYSCONF_UNSET, }, ! /* 17 Root path. */ ! { NULL, NULL, SYSCONF_UNSET, }, ! /* 18 Extensions path. */ ! { NULL, NULL, SYSCONF_UNSET, }, ! /* 19 IP forwarding. */ ! { NULL, NULL, SYSCONF_UNSET, }, ! /* 20 Source routing. */ ! { NULL, NULL, SYSCONF_UNSET, }, ! /* 21 Policy filter. */ ! { NULL, NULL, SYSCONF_UNSET, }, ! /* 22 Maximum DGRAM reassembly. */ ! { NULL, NULL, SYSCONF_UNSET, }, ! /* 23 Default IP time-to-live. */ ! { NULL, NULL, SYSCONF_UNSET, }, ! /* 24 Path MTU aging timeout. */ ! { NULL, NULL, SYSCONF_UNSET, }, ! /* 25 Path MTU plateau table. */ ! { NULL, NULL, SYSCONF_UNSET, }, ! /* 26 Interface MTU. */ ! { NULL, NULL, SYSCONF_UNSET, }, ! /* 27 All subnets. */ ! { NULL, NULL, SYSCONF_UNSET, }, ! /* 28 Broadcast address. */ ! { NULL, NULL, SYSCONF_UNSET, }, ! /* 29 Perform mask discovery. */ ! { NULL, NULL, SYSCONF_UNSET, }, ! /* 30 Mask supplier. */ ! { NULL, NULL, SYSCONF_UNSET, }, ! /* 31 Perform router discovery. */ ! { NULL, NULL, SYSCONF_UNSET, }, ! /* 32 Router solicitation address. */ ! { NULL, NULL, SYSCONF_UNSET, }, ! /* 33 Static route. */ ! { NULL, NULL, SYSCONF_UNSET, }, ! /* 34 Trailer encapsulation. */ ! { NULL, NULL, SYSCONF_UNSET, }, ! /* 35 ARP cache timeout. */ ! { NULL, NULL, SYSCONF_UNSET, }, ! /* 36 Ethernet encapsulation. */ ! { NULL, NULL, SYSCONF_UNSET, }, ! /* 37 TCP default TTL. */ ! { NULL, NULL, SYSCONF_UNSET, }, ! /* 38 TCP keepalive interval. */ ! { NULL, NULL, SYSCONF_UNSET, }, ! /* 39 TCP keepalive garbage. */ ! { NULL, NULL, SYSCONF_UNSET, }, ! /* 40 Network Information Service domain. */ ! { NULL, NULL, SYSCONF_UNSET, }, ! /* 41 Network Information servers. */ ! { NULL, NULL, SYSCONF_UNSET, }, ! /* 42 Network Time Protocol servers. */ ! { NULL, NULL, SYSCONF_UNSET, }, ! /* 43 Vendor Specific information. */ ! { NULL, NULL, SYSCONF_UNSET, }, ! /* 44 NetBIOS over TCP/IP name servers. */ ! { NULL, NULL, SYSCONF_UNSET, }, ! /* 45 NetBIOS over TCP/IP datagram distribution servers. */ ! { NULL, NULL, SYSCONF_UNSET, }, ! /* 46 NetBIOS over TCP/IP node type. */ ! { NULL, NULL, SYSCONF_UNSET, }, ! /* 47 NetBIOS over TCP/IP scope. */ ! { NULL, NULL, SYSCONF_UNSET, }, ! /* 48 X-Windows font servers. */ ! { NULL, NULL, SYSCONF_UNSET, }, ! /* 49 X-Windows system display manager. */ ! { NULL, NULL, SYSCONF_UNSET, }, ! /* 50 */ ! { NULL, NULL, SYSCONF_UNSET, }, ! /* 51 */ ! { NULL, NULL, SYSCONF_UNSET, }, ! /* 52 */ ! { NULL, NULL, SYSCONF_UNSET, }, ! /* 53 */ ! { NULL, NULL, SYSCONF_UNSET, }, ! /* 54 */ ! { NULL, NULL, SYSCONF_UNSET, }, ! /* 55 */ ! { NULL, NULL, SYSCONF_UNSET, }, ! /* 56 */ ! { NULL, NULL, SYSCONF_UNSET, }, ! /* 57 */ ! { NULL, NULL, SYSCONF_UNSET, }, ! /* 58 */ ! { NULL, NULL, SYSCONF_UNSET, }, ! /* 59 */ ! { NULL, NULL, SYSCONF_UNSET, }, ! /* 60 */ ! { NULL, NULL, SYSCONF_UNSET, }, ! /* 61 */ ! { NULL, NULL, SYSCONF_UNSET, }, }; ! int sysconf_setup_routers(void *value, dhcp_client_control_t *dc) { struct route_entry r_entry; *************** *** 159,163 **** } ! int sysconf_domain_name_servers(void *value, dhcp_client_control_t *dc) { FILE *fp; --- 222,253 ---- } ! int sysconf_cleanup_routers(void *value, dhcp_client_control_t *dc) ! { ! struct route_entry r_entry; ! route_t *rt; ! ! memset(&r_entry.route_dst, 0, sizeof(r_entry.route_dst)); ! memset(&r_entry.route_gw, 0, sizeof(r_entry.route_gw)); ! ! rt = route_open(); ! if(rt == NULL) { ! return -1; ! } ! ! r_entry.route_dst.addr_type = ADDR_TYPE_IP; ! r_entry.route_dst.addr_bits = 0; ! r_entry.route_dst.addr_ip = 0; ! ! if(route_delete(rt, &r_entry) < 0) { ! warn_message("couldn't delete default route entry"); ! route_close(rt); ! return -1; ! } ! ! route_close(rt); ! return 0; ! } ! ! int sysconf_setup_domain_name_servers(void *value, dhcp_client_control_t *dc) { FILE *fp; *************** *** 178,182 **** } ! int sysconf_domain_name(void *value, dhcp_client_control_t *dc) { FILE *fp; --- 268,272 ---- } ! int sysconf_setup_domain_name(void *value, dhcp_client_control_t *dc) { FILE *fp; *************** *** 267,276 **** sysconf_cleanup_files(); ! /* Setup our interface it. */ sysconf_setup_interface(options, dc); ! /* we need to setup the interface ourselves before ! * anything (route won't work otherwise.) */ for(list_ptr = options;list_ptr;list_ptr = list_ptr->next) { --- 357,367 ---- sysconf_cleanup_files(); ! /* Setup our interface. Put before the others as it ! * is likely required for the others to work. */ sysconf_setup_interface(options, dc); ! /* Now walk through the other options, performing setup and ! * cleanup operations as necessary. */ for(list_ptr = options;list_ptr;list_ptr = list_ptr->next) { *************** *** 282,300 **** if(string_matches(dhcp_options_strings[i], ce->name)) { ! /* We have a match now check for sysconf and serialize_to_internal ! * handler. */ ! if(sysconf_handlers[i].sysconf_handler == NULL || option_convert_handlers[i].serialize_to_internal == NULL) break; - info_message("configuring for option %s", dhcp_options_strings[i]); - data = option_convert_handlers[i].serialize_to_internal(ce->value); ! if(sysconf_handlers[i].sysconf_handler(data, dc)) ! error_message("error configuring for option %s: %s", dhcp_options_strings[i], strerror(errno)); option_convert_handlers[i].free_internal(data); } --- 373,415 ---- if(string_matches(dhcp_options_strings[i], ce->name)) { ! /* Make sure we know how to setup this option. */ ! if(sysconf_handlers[i].setup == NULL || option_convert_handlers[i].serialize_to_internal == NULL) break; data = option_convert_handlers[i].serialize_to_internal(ce->value); ! /* Cleanup first, if we're supposed to. */ ! ! if(sysconf_handlers[i].cleanup != NULL && ! (sysconf_handlers[i].flag & SYSCONF_DO_CLEANUP) == 1) { ! ! info_message("cleanup option: %s", ! dhcp_options_strings[i]); ! ! if(sysconf_handlers[i].cleanup(data, dc)) ! error_message("cleanup option: %s: %s", ! dhcp_options_strings[i], strerror(errno)); ! } ! ! /* Now we can try to setup the option, and flag it for ! * cleanup. */ ! ! info_message("setup option: %s", dhcp_options_strings[i]); ! ! if(sysconf_handlers[i].setup(data, dc)) { ! ! sysconf_handlers[i].flag &= ~SYSCONF_DO_CLEANUP; ! error_message("setup option: %s: %s", dhcp_options_strings[i], strerror(errno)); + } else { + + sysconf_handlers[i].flag |= SYSCONF_DO_CLEANUP; + + } + + option_convert_handlers[i].free_internal(data); } *************** *** 313,315 **** --- 428,461 ---- return; + } + + void do_sysconf_cleanup(dhcp_client_control_t *dc) + { + int i; + void *data; + + /* Walk through the sysconf_handlers array. */ + + for(i = 0;i < MAX_OPTIONS_HANDLED;i++) { + + /* Perform cleanup only if we're supposed to, and if there's a + * cleanup function for the option. */ + + if(sysconf_handlers[i].flag & SYSCONF_DO_CLEANUP && + sysconf_handlers[i].cleanup != NULL) { + + data = option_convert_handlers[i].serialize_to_internal(dhcp_options_strings[i]); + + info_message("cleanup option: %s", dhcp_options_strings[i]); + + if(sysconf_handlers[i].cleanup(data, dc)) + error_message("cleanup option: %s: %s", dhcp_options_strings[i], + strerror(errno)); + + option_convert_handlers[i].free_internal(data); + + } + + } + } Index: dhcp-sysconf.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-sysconf.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-sysconf.h 17 Jun 2002 13:23:08 -0000 1.2 --- dhcp-sysconf.h 24 Jun 2002 02:04:56 -0000 1.3 *************** *** 29,42 **** typedef struct { ! int (*sysconf_handler)(void *value, dhcp_client_control_t *dc); } sysconf_handler; /* System configuration routines. */ ! extern int sysconf_routers(void *value, dhcp_client_control_t *dc); ! extern int sysconf_domain_name_servers(void *value, dhcp_client_control_t *dc); ! extern int sysconf_domain_name(void *value, dhcp_client_control_t *dc); extern void do_sysconf(list_t *options, dhcp_client_control_t *dc); #endif /* SYSCONF_H */ --- 29,49 ---- typedef struct { ! int (*setup)(void *value, dhcp_client_control_t *dc); ! int (*cleanup)(void *value, dhcp_client_control_t *dc); ! uint8_t flag; } sysconf_handler; + /* Hex macros for sysconf flags. */ + #define SYSCONF_UNSET 0x00 + #define SYSCONF_DO_CLEANUP 0x01 /* System configuration routines. */ ! extern int sysconf_setup_routers(void *value, dhcp_client_control_t *dc); ! extern int sysconf_cleanup_routers(void *value, dhcp_client_control_t *dc); ! extern int sysconf_setup_domain_name_servers(void *value, dhcp_client_control_t *dc); ! extern int sysconf_setup_domain_name(void *value, dhcp_client_control_t *dc); extern void do_sysconf(list_t *options, dhcp_client_control_t *dc); + extern void do_sysconf_cleanup(dhcp_client_control_t *dc); #endif /* SYSCONF_H */ |