dhcp-agent-commits Mailing List for dhcp-agent (Page 20)
Status: Alpha
Brought to you by:
actmodern
You can subscribe to this list here.
2002 |
Jan
|
Feb
(33) |
Mar
|
Apr
|
May
(19) |
Jun
(61) |
Jul
(12) |
Aug
|
Sep
(5) |
Oct
(31) |
Nov
(24) |
Dec
(56) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2003 |
Jan
(9) |
Feb
|
Mar
(16) |
Apr
(4) |
May
(68) |
Jun
(70) |
Jul
(100) |
Aug
(54) |
Sep
|
Oct
|
Nov
|
Dec
|
2004 |
Jan
|
Feb
(1) |
Mar
|
Apr
|
May
(7) |
Jun
(12) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2007 |
Jan
(1) |
Feb
|
Mar
(1) |
Apr
(4) |
May
(1) |
Jun
|
Jul
(1) |
Aug
(1) |
Sep
(8) |
Oct
(5) |
Nov
(6) |
Dec
(4) |
2008 |
Jan
(9) |
Feb
(20) |
Mar
(32) |
Apr
(18) |
May
(19) |
Jun
(12) |
Jul
(23) |
Aug
(7) |
Sep
(15) |
Oct
(22) |
Nov
(50) |
Dec
(68) |
2009 |
Jan
(63) |
Feb
(23) |
Mar
(43) |
Apr
(50) |
May
(110) |
Jun
(103) |
Jul
(71) |
Aug
(26) |
Sep
(16) |
Oct
(31) |
Nov
(8) |
Dec
(13) |
2010 |
Jan
(6) |
Feb
(6) |
Mar
(36) |
Apr
(57) |
May
(67) |
Jun
(70) |
Jul
(44) |
Aug
(46) |
Sep
(27) |
Oct
(2) |
Nov
|
Dec
|
2011 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
|
2013 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(2) |
Nov
|
Dec
|
From: <act...@us...> - 2003-05-11 07:49:09
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv5918 Modified Files: dhcp-client-states.c dhcp-sysconf.c dhcp-sysconf.h Log Message: sysconf is mostly gone now Index: dhcp-client-states.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-states.c,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** dhcp-client-states.c 4 May 2003 18:51:54 -0000 1.27 --- dhcp-client-states.c 11 May 2003 07:49:05 -0000 1.28 *************** *** 373,378 **** } ! reinitialize_timer(dc->context->timer); ! do_sysconf(timer_options, dc, 0); dhcp_opt_destroy_option_list(timer_options); --- 373,377 ---- } ! do_sysconf_setup_timers(timer_options, dc); dhcp_opt_destroy_option_list(timer_options); *************** *** 660,664 **** */ ! do_sysconf(options, dc, 1); dhcp_opt_destroy_option_list(options); --- 659,664 ---- */ ! do_sysconf_setup_timers(options, dc); ! do_sysconf(options, dc); dhcp_opt_destroy_option_list(options); Index: dhcp-sysconf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-sysconf.c,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** dhcp-sysconf.c 4 May 2003 18:53:28 -0000 1.16 --- dhcp-sysconf.c 11 May 2003 07:49:05 -0000 1.17 *************** *** 39,364 **** #include "dhcp-client.h" #include "dhcp-sysconf.h" ! static int sysconf_setup_routers(void *value, dhcp_client_control_t *dc); ! static int sysconf_cleanup_routers(void *value, dhcp_client_control_t *dc); ! static int sysconf_setup_domain_name_servers(void *value, dhcp_client_control_t *dc); ! static int sysconf_setup_domain_name(void *value, dhcp_client_control_t *dc); ! static int client_setup_lease_time(void *value, dhcp_client_control_t *dc); ! static int client_setup_rebind_time(void *value, dhcp_client_control_t *dc); ! static int client_setup_renew_time(void *value, dhcp_client_control_t *dc); ! ! /* Only use handlers here which can be done in any order. ! * Some special handlers are done in a particular order ! * before we run these routines. ! */ ! ! sysconf_handler sysconf_handlers[] = { ! {NULL, NULL, SYSCONF_UNSET,} ! , /* 0 Pad -- not handled here. */ ! {NULL, NULL, SYSCONF_UNSET,} ! , /* 1 Subnet mask -- not handled here. */ ! {NULL, NULL, SYSCONF_UNSET,} ! , /* 2 Time offset. */ ! {sysconf_setup_routers, ! sysconf_cleanup_routers, ! SYSCONF_UNSET,} ! , /* 3 Routers. */ ! {NULL, NULL, SYSCONF_UNSET,} ! , /* 4 Time server. */ ! {NULL, NULL, SYSCONF_UNSET,} ! , /* 5 Name servers (old -- IEN 116). */ ! {sysconf_setup_domain_name_servers, ! NULL, ! SYSCONF_UNSET,} ! , /* 6 Domain name servers. */ ! {NULL, 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. */ ! {sysconf_setup_domain_name, NULL, ! SYSCONF_UNSET,} ! , /* 15 Domain name. */ ! {NULL, 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 Requested IP Address. */ ! {client_setup_lease_time, NULL, SYSCONF_UNSET,} ! , /* 51 IP Address Lease Time. */ ! {NULL, SYSCONF_UNSET,} ! , /* 52 */ ! {NULL, SYSCONF_UNSET,} ! , /* 53 */ ! {NULL, NULL, SYSCONF_UNSET,} ! , /* 54 */ ! {NULL, NULL, SYSCONF_UNSET,} ! , /* 55 */ ! {NULL, NULL, SYSCONF_UNSET,} ! , /* 56 */ ! {NULL, NULL, SYSCONF_UNSET,} ! , /* 57 */ ! {client_setup_renew_time, NULL, SYSCONF_UNSET,} ! , /* 58 Renewal Time (T1). */ ! {client_setup_rebind_time, NULL, SYSCONF_UNSET,} ! , /* 59 Rebind Time (T2). */ ! {NULL, NULL, SYSCONF_UNSET,} ! , /* 60 Class ID */ ! {NULL, NULL, SYSCONF_UNSET,} ! , /* 61 Client ID */ ! {NULL, NULL, SYSCONF_UNSET,} ! , /* 62 NIS+ Domain */ ! {NULL, NULL, SYSCONF_UNSET,} ! , /* 63 NIS+ Servers */ ! {NULL, NULL, SYSCONF_UNSET,} ! , /* 64 TFTP Servers */ ! {NULL, NULL, SYSCONF_UNSET,} ! , /* 65 Boot File Name */ ! {NULL, NULL, SYSCONF_UNSET,} ! , /* 66 IP Home Agent */ ! {NULL, NULL, SYSCONF_UNSET,} ! , /* 67 SMTP Server */ ! {NULL, NULL, SYSCONF_UNSET,} ! , /* 69 POP Server */ ! {NULL, NULL, SYSCONF_UNSET,} ! , /* 69 NNTP Server */ ! {NULL, NULL, SYSCONF_UNSET,} ! , /* 70 Default WWW Server */ ! {NULL, NULL, SYSCONF_UNSET,} ! , /* 71 Default Finger Server */ ! {NULL, NULL, SYSCONF_UNSET,} ! , /* 72 Default IRC Server */ ! {NULL, NULL, SYSCONF_UNSET,} ! , /* 73 Default ST Server */ ! {NULL, NULL, SYSCONF_UNSET,} ! , /* 74 Default STDA Server */ ! }; ! ! /* * * * * * * * * * * * * * * * * * * * ! * Sysconf functions. These do setup. * ! * * * * * * * * * * * * * * * * * * * */ ! ! static int client_setup_lease_time(void *value, dhcp_client_control_t *dc) ! { ! uint32_t *secs = value; ! ! timer_add_trigger(dc->context->timer, *secs, TIMER_IP_LEASE); ! return 0; ! } ! ! static int client_setup_rebind_time(void *value, dhcp_client_control_t *dc) ! { ! uint32_t *secs = value; ! ! timer_add_trigger(dc->context->timer, *secs, TIMER_REBIND); ! return 0; ! } ! ! static int client_setup_renew_time(void *value, dhcp_client_control_t *dc) ! { ! uint32_t *secs = value; ! ! timer_add_trigger(dc->context->timer, *secs, TIMER_RENEW); ! return 0; ! } ! ! int sysconf_setup_routers(void *value, dhcp_client_control_t *dc) ! { ! struct route_entry r_entry; ! uint32_t *addr_val; ! route_t *rt; ! list_t *routers; ! ! memset(&r_entry, 0, sizeof(struct route_entry)); ! ! routers = value; ! ! addr_val = list_first(routers); ! ! r_entry.route_dst.addr_type = ADDR_TYPE_IP; ! r_entry.route_dst.addr_bits = 0; ! r_entry.route_dst.addr_ip = 0; ! ! r_entry.route_gw.addr_type = ADDR_TYPE_IP; ! r_entry.route_gw.addr_bits = 0; ! memcpy(&r_entry.route_gw.addr_ip, addr_val, IP_ADDR_LEN); ! ! rt = route_open(); ! if(rt == NULL) { ! ERROR_MESSAGE("unable to open routing table: %s", strerror(errno)); ! return -1; ! } ! ! if(route_add(rt, &r_entry) < 0) { ! ERROR_MESSAGE("unable to add route: %s", strerror(errno)); ! route_close(rt); ! return -1; ! } ! ! route_close(rt); ! return 0; ! } ! ! 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; ! list_t *servers = value; ! struct in_addr addr; ! void *data; ! ! fp = file_open_or_create_safe("resolv.conf", "a"); ! if(fp == NULL) ! return -1; ! ! list_rewind(servers); ! while((data = list_next(servers)) != NULL) { ! memcpy(&addr.s_addr, data, IP_ADDR_LEN); ! fprintf(fp, "nameserver %s\n", inet_ntoa(addr)); ! } ! ! fclose(fp); ! return 0; ! } ! int sysconf_setup_domain_name(void *value, dhcp_client_control_t *dc) { ! FILE *fp; ! char *dm; ! ! fp = file_open_or_create_safe("resolv.conf", "a"); ! if(fp == NULL) ! return -1; ! ! dm = value; ! fprintf(fp, "search %s\n", dm); ! ! fclose(fp); ! return 0; } ! static void sysconf_cleanup_files(void) { ! /* these files are in our work directory, ! * so we won't do anything dangerous to the system yet. */ ! ! file_delete("resolv.conf"); return; } ! static int sysconf_setup_interface(list_t *options, dhcp_client_control_t *dc) { - uint32_t addr, netmask; - uint8_t have_addr = 0; - uint8_t have_netmask = 0; - uint16_t mtu_val = 0; dhcp_opt_t *option; - void *data; - int mtu; dhcp_opt_tag_t tag; ! INFO_MESSAGE("configuring interface: %s", dc->interface); list_rewind(options); --- 39,67 ---- #include "dhcp-client.h" #include "dhcp-sysconf.h" + #include "dhcp-client-guile.h" ! /* * * * * * * * * * * * ! * Sysconf interface. * ! * * * * * * * * * * * */ ! void do_sysconf(list_t *options, dhcp_client_control_t *dc) { ! return dhcp_sysconf_guile(dc, options); } ! void do_sysconf_cleanup(list_t *options, dhcp_client_control_t *dc) { ! /* nada :-) */ return; } ! /* setup timers only. this is done internally after rebinding or renewing. */ ! void do_sysconf_setup_timers(list_t *options, dhcp_client_control_t *dc) { dhcp_opt_t *option; dhcp_opt_tag_t tag; + uint32_t *secs; ! reinitialize_timer(dc->context->timer); list_rewind(options); *************** *** 367,540 **** tag = dhcp_opt_get_tag(option); ! if(tag == TAG_DHCP_REQUESTED_IP_ADDRESS) { ! ! data = dhcp_opt_get_host_data(option); ! memcpy(&addr, data, IP_ADDR_LEN); ! have_addr = 1; continue; - } - - if(tag == TAG_DHCP_SUBNET_MASK) { ! data = dhcp_opt_get_host_data(option); ! memcpy(&netmask, data, IP_ADDR_LEN); ! have_netmask = 1; continue; - } ! if(tag == TAG_DHCP_INTERFACE_MTU) { ! ! data = dhcp_opt_get_host_data(option); ! memcpy(&mtu, data, sizeof(uint16_t)); ! xfree(data); continue; - } - } - - if(!have_addr && !have_netmask) { - ERROR_MESSAGE("do not have enough settings for interface configuration"); - return -1; - } - - if(mtu_val != 0) - mtu = mtu_val; /* we're promoting so it is safe. */ - else - mtu = client_conf_get_default_mtu(dc->conf); - - - if(rawnet_interface_up(dc->rawnet, addr, netmask, mtu, 1)) { - ERROR_MESSAGE("could not bring interface up: %s", rawnet_get_device_name(dc->rawnet)); - return -1; - } - - return 0; - } - - /* * * * * * * * * * * * - * Sysconf interface. * - * * * * * * * * * * * */ - - void do_sysconf(list_t *options, dhcp_client_control_t *dc, uint8_t do_interface) - { - void *data; - dhcp_opt_t *option; - uint8_t *configure_opts = NULL; - dhcp_opt_tag_t tag; - - /* Clean up any config files we have. */ - - sysconf_cleanup_files(); - - /* Setup our interface. Put before the others as it - * is likely required for the others to work. */ - - if(do_interface) - sysconf_setup_interface(options, dc); - - /* ask client conf if we're supposed to configure certain options. - * if so get the bit array. */ - - if(client_conf_get_opt_configure_bit_array(dc->conf, dhcp_client_get_server_ip_address(dc), - dhcp_client_get_server_hw_address(dc))) { - - configure_opts = client_conf_get_opt_configure_bit_array(dc->conf, - dhcp_client_get_server_ip_address(dc), - dhcp_client_get_server_hw_address(dc)); - } - - /* Now walk through the other options, performing setup and - * cleanup operations as necessary. */ - - list_rewind(options); - while((option = list_next(options)) != NULL) { - - tag = dhcp_opt_get_tag(option); - - /* Make sure we know how to setup this option, and we're - * supposed to. */ - - if(configure_opts) { - - if(sysconf_handlers[tag].setup == NULL || - configure_opts[tag] == 0) - continue; - - } else { - - if(sysconf_handlers[tag].setup == NULL) - continue; - - } - - data = dhcp_opt_get_host_data(option); - - /* Cleanup first, if we're supposed to. */ - - if(sysconf_handlers[tag].cleanup != NULL && - (sysconf_handlers[tag].flag & SYSCONF_DO_CLEANUP) == 1) { - - INFO_MESSAGE("cleanup option: %s", dhcp_option_printable_string_get(tag)); - - if(sysconf_handlers[tag].cleanup(data, dc)) - WARN_MESSAGE("sysconf: error cleaning up option: %s", - dhcp_option_conf_string_get(tag)); - } - - /* Now we can try to setup the option, and flag it for - * cleanup. */ - - INFO_MESSAGE("setup option: %s", dhcp_option_printable_string_get(tag)); - - if(sysconf_handlers[tag].setup(data, dc)) { - - sysconf_handlers[tag].flag &= ~SYSCONF_DO_CLEANUP; - WARN_MESSAGE("unable to setup option: %s", dhcp_option_printable_string_get(tag)); - - } else { - - sysconf_handlers[tag].flag |= SYSCONF_DO_CLEANUP; - - } - - } - - /* we don't need to worry about race conditions. - * /etc should NOT be world writable! */ - - /* FIXME: perhaps we should have file handlers in the sysconf array? */ - - if(file_exists("resolv.conf")) { - file_move("resolv.conf", "/etc/resolv.conf"); - file_make_public_read("/etc/resolv.conf"); - } - - return; - } - - void do_sysconf_cleanup(list_t *options, dhcp_client_control_t *dc) - { - void *data; - dhcp_opt_t *option; - dhcp_opt_tag_t tag; - - /* Walk through the sysconf_handlers array. */ - - list_rewind(options); - while((option = list_next(options)) != NULL) { - - tag = dhcp_opt_get_tag(option); - if(sysconf_handlers[tag].flag & SYSCONF_DO_CLEANUP && - sysconf_handlers[tag].cleanup != NULL) { - - data = dhcp_opt_get_host_data(option); - - INFO_MESSAGE("cleanup option: %s", dhcp_option_printable_string_get(tag)); - - if(sysconf_handlers[tag].cleanup(data, dc)) - WARN_MESSAGE("sysconf: error cleaning up option: %s", - dhcp_option_printable_string_get(tag)); } } --- 70,90 ---- tag = dhcp_opt_get_tag(option); ! if(tag == TAG_DHCP_RENEWAL_TIME) { + secs = dhcp_opt_get_host_data(option); + timer_add_trigger(dc->context->timer, *secs, TIMER_RENEW); continue; ! } else if(tag == TAG_DHCP_REBINDING_TIME) { + secs = dhcp_opt_get_host_data(option); + timer_add_trigger(dc->context->timer, *secs, TIMER_REBIND); continue; ! } else if(tag == TAG_DHCP_IP_ADDRESS_LEASE_TIME) { + secs = dhcp_opt_get_host_data(option); + timer_add_trigger(dc->context->timer, *secs, TIMER_IP_LEASE); continue; } } Index: dhcp-sysconf.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-sysconf.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcp-sysconf.h 19 Nov 2002 19:44:44 -0000 1.4 --- dhcp-sysconf.h 11 May 2003 07:49:05 -0000 1.5 *************** *** 40,45 **** /* System configuration routines. */ ! extern void do_sysconf(list_t *options, dhcp_client_control_t *dc, uint8_t do_interface); extern void do_sysconf_cleanup(list_t *options, dhcp_client_control_t *dc); #endif /* SYSCONF_H */ --- 40,46 ---- /* System configuration routines. */ ! extern void do_sysconf(list_t *options, dhcp_client_control_t *dc); extern void do_sysconf_cleanup(list_t *options, dhcp_client_control_t *dc); + extern void do_sysconf_setup_timers(list_t *options, dhcp_client_control_t *dc); #endif /* SYSCONF_H */ |
From: <act...@us...> - 2003-05-11 07:48:33
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv5664 Modified Files: dhcp-client-guile.c Added Files: dhcp-client-guile.h Log Message: more for the guile interface --- NEW FILE: dhcp-client-guile.h --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-guile.h,v 1.1 2003/05/11 07:48:29 actmodern Exp $ * * Copyright 2003 Thamer Alharbash <tm...@wh...> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. The names of the authors may not be used to endorse or promote * products derived from this software without specific prior * written permission. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * */ #ifndef DHCP_CLIENT_GUILE_H #define DHCP_CLIENT_GUILE_H #include <libguile.h> typedef struct client_control_smob { dhcp_client_control_t *dc; } client_control_smob_t; /* guile interface. */ extern void dhcp_sysconf_guile(dhcp_client_control_t *dc, list_t *options); extern void dhcp_guile_init(void); #endif /* DHCP_CLIENT_GUILE_H */ Index: dhcp-client-guile.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-guile.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** dhcp-client-guile.c 6 May 2003 03:48:43 -0000 1.1 --- dhcp-client-guile.c 11 May 2003 07:48:29 -0000 1.2 *************** *** 36,42 **** #include "dhcp-client-cache.h" #include "dhcp-client.h" ! #include <libguile.h> /* define a dhcp option as a list. */ static void def_guile_option_list(dhcp_opt_t *option) --- 36,389 ---- #include "dhcp-client-cache.h" #include "dhcp-client.h" + #include "dhcp-client-guile.h" + #include "dhcp-interface.h" + #include "dhcp-limits.h" ! static scm_t_bits client_control_tag; ! ! /* * * * * * * * * * * * * * * * * * * * * * * * ! * utility routines guile doesn't provide but * ! * really should :| * ! * * * * * * * * * * * * * * * * * * * * * * * */ ! ! static char *x_scm_symbol2newstr(SCM symbol) ! { ! size_t len; ! char *newstr; ! ! len = SCM_SYMBOL_LENGTH(symbol); ! newstr = xmalloc((len + 1) * sizeof(char)); ! memcpy(newstr, SCM_SYMBOL_CHARS(symbol), len); ! newstr[len] = 0; ! ! return newstr; ! } ! ! static char *x_scm_string2newstr(SCM string) ! { ! size_t len; ! char *newstr; ! ! len = SCM_STRING_LENGTH(string); ! newstr = xmalloc((len + 1) * sizeof(char)); ! memcpy(newstr, SCM_STRING_CHARS(string), len); ! newstr[len] = 0; ! ! return newstr; ! } ! ! /* * * * * * * * * * * * * * * * * * * * ! * guile interface to utility routines * ! * * * * * * * * * * * * * * * * * * * */ ! ! /* find out if we should configure an option as per a user's request. */ ! static SCM dhcp_scm_configurep(SCM scm_dc, SCM scm_option) ! { ! client_control_smob_t *client_control_smob; ! dhcp_client_control_t *dc; ! uint8_t *configure_opts; ! char *opt_sym_name; ! char *opt_proper_name; ! dhcp_opt_tag_t tag; ! SCM return_bool = SCM_BOOL_F; ! ! /* do assertions */ ! SCM_ASSERT(SCM_SMOB_PREDICATE(client_control_tag, scm_dc), ! scm_dc, SCM_ARG1, "client-interface-up"); ! ! SCM_ASSERT(SCM_SYMBOLP(scm_option), scm_option, SCM_ARG2, "client-interface-up"); ! ! client_control_smob = (client_control_smob_t *)SCM_SMOB_DATA(scm_dc); ! dc = client_control_smob->dc; ! configure_opts = client_conf_get_opt_configure_bit_array(dc->conf, ! dhcp_client_get_server_ip_address(dc), ! dhcp_client_get_server_hw_address(dc)); ! if(configure_opts == NULL) ! return SCM_BOOL_T; ! ! opt_sym_name = x_scm_symbol2newstr(scm_option); ! if(!strncmp("dhcp-", opt_sym_name, strlen("dhcp-"))) { ! ! opt_proper_name = opt_sym_name + 5; ! ! for(tag = 0; tag < MAX_OPTIONS_HANDLED; tag++) { ! ! if(!strcmp(dhcp_option_conf_string_get(tag), ! opt_proper_name)) { ! return_bool = SCM_BOOL_T; ! break; ! } ! } ! } ! ! xfree(opt_sym_name); ! return return_bool; ! } ! ! /* get the default mtu */ ! static SCM dhcp_scm_get_default_mtu(SCM scm_dc) ! { ! client_control_smob_t *client_control_smob; ! dhcp_client_control_t *dc; ! SCM mtu; ! ! /* do assertions */ ! SCM_ASSERT(SCM_SMOB_PREDICATE(client_control_tag, scm_dc), ! scm_dc, SCM_ARG1, "client-interface-up"); ! ! client_control_smob = (client_control_smob_t *)SCM_SMOB_DATA(scm_dc); ! dc = client_control_smob->dc; ! ! mtu = SCM_MAKINUM(client_conf_get_default_mtu(dc->conf)); ! ! return mtu; ! } ! ! /* get the default subnet mask. FIXME: todo. */ ! static SCM dhcp_scm_get_default_subnet_mask(SCM scm_dc) ! { ! client_control_smob_t *client_control_smob; ! dhcp_client_control_t *dc; ! SCM subnet_mask; ! ! /* do assertions */ ! SCM_ASSERT(SCM_SMOB_PREDICATE(client_control_tag, scm_dc), ! scm_dc, SCM_ARG1, "client-interface-up"); ! ! client_control_smob = (client_control_smob_t *)SCM_SMOB_DATA(scm_dc); ! dc = client_control_smob->dc; ! ! /* fixme: implement default client subnet-mask option in client conf. */ ! subnet_mask = SCM_BOOL_F; ! return subnet_mask; ! } ! ! /* interface-up: bring an interface up. */ ! static SCM dhcp_scm_interface_up(SCM scm_dc, ! SCM scm_ip_address, ! SCM scm_netmask, ! SCM scm_mtu) ! { ! client_control_smob_t *client_control_smob; ! dhcp_client_control_t *dc; ! rawnet_t *rawnet; ! ip_addr_t ip_address, netmask; ! int mtu; ! ! /* do assertions */ ! SCM_ASSERT(SCM_SMOB_PREDICATE(client_control_tag, scm_dc), ! scm_dc, SCM_ARG1, "client-interface-up"); ! ! SCM_ASSERT(SCM_STRINGP(scm_ip_address)|SCM_INUMP(scm_ip_address), scm_ip_address, ! SCM_ARG2, "client-interface-up"); ! ! SCM_ASSERT(SCM_STRINGP(scm_netmask)|SCM_INUMP(scm_netmask), scm_netmask, ! SCM_ARG3, "client-interface-up"); ! ! SCM_ASSERT(SCM_STRINGP(scm_mtu)|SCM_INUM(scm_mtu), scm_mtu, ! SCM_ARG4, "client-interface-up"); ! ! /* convert to C types. */ ! ! /* interface handle. */ ! client_control_smob = (client_control_smob_t *)SCM_SMOB_DATA(scm_dc); ! dc = client_control_smob->dc; ! rawnet = dc->rawnet; ! ! /* if string change to number first. */ ! if(SCM_STRINGP(scm_ip_address)) { ! ip_address = ntohl(scm_num2ulong(scm_inet_aton(scm_ip_address), 1, "client-interface-up")); ! } else { ! ip_address = scm_num2ulong(scm_ip_address, 1, "client-interface-up"); ! } ! ! /* if string change to number first. */ ! if(SCM_STRINGP(scm_netmask)) { ! netmask = ntohl(scm_num2ulong(scm_inet_aton(scm_netmask), 1, "client-interface-up")); ! } else { ! netmask = scm_num2ulong(scm_netmask, 1, "client-interface-up"); ! } ! ! /* if string change to number first. */ ! if(SCM_STRINGP(scm_mtu)) { ! mtu = scm_num2ulong(scm_mtu, 1, "client-interface-up"); ! } else { ! mtu = scm_num2int(scm_mtu, 1, "client-interface-up"); ! } ! ! /* don't throw an exception: return true/false based on return value. */ ! if(rawnet_interface_up(rawnet, ip_address, netmask, mtu, 1)) ! return SCM_BOOL_F; ! else ! return SCM_BOOL_T; ! } ! ! /* add a default route. */ ! static SCM dhcp_scm_client_set_default_route(SCM scm_dc, SCM scm_default_router) ! { ! client_control_smob_t *client_control_smob; ! dhcp_client_control_t *dc; ! rawnet_t *rawnet; ! ip_addr_t default_router; ! struct route_entry r_entry; ! route_t *rt; ! ! /* do assertions */ ! SCM_ASSERT(SCM_SMOB_PREDICATE(client_control_tag, scm_dc), ! scm_dc, SCM_ARG1, "client-set-default-route"); ! ! SCM_ASSERT(SCM_STRINGP(scm_default_router)|SCM_INUMP(scm_default_router), scm_default_router, ! SCM_ARG2, "client-set-default-route"); ! ! /* if string change to number first. */ ! if(SCM_STRINGP(scm_default_router)) { ! default_router = ntohl(scm_num2ulong(scm_inet_aton(scm_default_router), 1, "client-set-default-route")); ! } else { ! default_router = scm_num2ulong(scm_default_router, 1, "client-set-default-route"); ! } ! ! /* interface handle. */ ! client_control_smob = (client_control_smob_t *)SCM_SMOB_DATA(scm_dc); ! dc = client_control_smob->dc; ! rawnet = dc->rawnet; ! ! memset(&r_entry, 0, sizeof(struct route_entry)); ! ! r_entry.route_dst.addr_type = ADDR_TYPE_IP; ! r_entry.route_dst.addr_bits = 0; ! r_entry.route_dst.addr_ip = 0; ! ! r_entry.route_gw.addr_type = ADDR_TYPE_IP; ! r_entry.route_gw.addr_bits = 0; ! memcpy(&r_entry.route_gw.addr_ip, &default_router, IP_ADDR_LEN); ! ! rt = route_open(); ! if(rt == NULL) { ! ERROR_MESSAGE("unable to open routing table: %s", strerror(errno)); ! return SCM_BOOL_F; ! } ! ! if(route_add(rt, &r_entry) < 0) { ! ERROR_MESSAGE("unable to add route: %s", strerror(errno)); ! route_close(rt); ! return SCM_BOOL_F; ! } ! ! route_close(rt); ! return SCM_BOOL_T; ! } ! ! SCM scm_client_shutdown(SCM scm_dc) ! { ! client_control_smob_t *client_control_smob; ! dhcp_client_control_t *dc; ! ! /* do assertions */ ! SCM_ASSERT(SCM_SMOB_PREDICATE(client_control_tag, scm_dc), ! scm_dc, SCM_ARG1, "client-shutdown"); ! ! /* interface handle. */ ! client_control_smob = (client_control_smob_t *)SCM_SMOB_DATA(scm_dc); ! dc = client_control_smob->dc; ! ! client_do_shutdown(dc); + /* never really returns but to avoid compiler warning. */ + return SCM_BOOL_F; + } + + /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * info message, error message, and fatal message wrappers. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + + static SCM scm_client_info_message(SCM string) + { + char *str; + + str = x_scm_string2newstr(string); + INFO_MESSAGE(str); + xfree(str); + + return SCM_BOOL_T; + } + + static SCM scm_client_error_message(SCM string) + { + char *str; + + str = x_scm_string2newstr(string); + ERROR_MESSAGE(str); + xfree(str); + + return SCM_BOOL_T; + } + + static SCM scm_client_fatal_error_message(SCM string) + { + char *str; + + str = x_scm_string2newstr(string); + FATAL_MESSAGE(str); + xfree(str); + + return SCM_BOOL_T; + } + + /* * * * * * * * * * * * * * * * * * * * + * dhcp client control smob * + * * * * * * * * * * * * * * * * * * * */ + + /* mark a dhcp client control scm: we don't need to do any marking. */ + static SCM dhcp_scm_client_control_mark(SCM scm_client_control) + { + return SCM_BOOL_F; + } + + /* free a client control scm. */ + static size_t dhcp_scm_client_control_free(SCM scm_client_control) + { + client_control_smob_t *client_control_smob; + + client_control_smob = (client_control_smob_t *)SCM_SMOB_DATA(scm_client_control); + xfree(client_control_smob); + + return sizeof(client_control_smob_t); + } + + /* print out a client control scm. */ + static int dhcp_scm_client_control_print(SCM scm_client_control, SCM port, scm_print_state *pstate) + { + scm_puts("#<client_control>", port); + return 1; + } + + /* convert a client control handler to SCM. */ + static SCM dhcp_scm_make_client_control(dhcp_client_control_t *dc) + { + client_control_smob_t *client_control_smob; + + client_control_smob = xmalloc(sizeof(client_control_smob_t)); + client_control_smob->dc = dc; + + SCM_RETURN_NEWSMOB(client_control_tag, client_control_smob); + } + + /* initialization routines for client_control SMOB. */ + static void init_client_control_smob(void) + { + client_control_tag = scm_make_smob_type("client_control", sizeof(client_control_smob_t)); + + /* bind mark, free, and print. */ + scm_set_smob_mark(client_control_tag, dhcp_scm_client_control_mark); + scm_set_smob_free(client_control_tag, dhcp_scm_client_control_free); + scm_set_smob_print(client_control_tag, dhcp_scm_client_control_print); + + return; + } + + /* * * * * * * * * * * * * * * * * * * * * * + * guile routines to define dhcp options. * + * * * * * * * * * * * * * * * * * * * * * */ + /* define a dhcp option as a list. */ static void def_guile_option_list(dhcp_opt_t *option) *************** *** 51,59 **** val = dhcp_opt_get_user_string(option); ! stringbuffer_aprintf(val_sb, "'( %s", val); xfree(val); ! stringbuffer_replace_c(val_sb, ',', ' '); ! stringbuffer_aprintf(val_sb, ")"); stringbuffer_aprintf(expr_sb, "(define dhcp-%s %s)", --- 398,406 ---- val = dhcp_opt_get_user_string(option); ! stringbuffer_aprintf(val_sb, "'( \"%s", val); xfree(val); ! stringbuffer_replace(val_sb, ",", "\""); ! stringbuffer_aprintf(val_sb, "\")"); stringbuffer_aprintf(expr_sb, "(define dhcp-%s %s)", *************** *** 139,146 **** /* take a list of options and define them at the top level. */ ! static void dhcp_def_guile_options(list_t *options) { dhcp_opt_t *option; /* walk down list and create each option and bind symbols to dhcp options. */ --- 486,500 ---- /* take a list of options and define them at the top level. */ ! static void dhcp_def_guile_options(dhcp_client_control_t *dc, list_t *options) { + SCM client_control_sym; + SCM client_control_handle; dhcp_opt_t *option; + client_control_sym = scm_str2symbol("client-control"); + client_control_handle = dhcp_scm_make_client_control(dc); + + scm_define(client_control_sym, client_control_handle); + /* walk down list and create each option and bind symbols to dhcp options. */ *************** *** 151,161 **** } - /* that's it. */ - return; } /* undefine options so we don't see stale ones the next time we do a sysconf. */ ! static void dhcp_undef_guile_options(list_t *options) { dhcp_opt_t *option; --- 505,513 ---- } return; } /* undefine options so we don't see stale ones the next time we do a sysconf. */ ! static void dhcp_undef_guile_options(dhcp_client_control_t *dc, list_t *options) { dhcp_opt_t *option; *************** *** 175,178 **** --- 527,533 ---- } + /* undefine the client control handler too. */ + scm_c_eval_string("(undefine client-control)"); + stringbuffer_destroy(expr_sb); *************** *** 180,187 **** --- 535,546 ---- } + /* run the guile dhcp sysconf script. */ static void dhcp_run_guile_sysconf(dhcp_client_control_t *dc) { stringbuffer_t *sb; + if(getenv("DEBUG_CLIENT_SCM")) + scm_shell(0, NULL); + sb = stringbuffer_create(); stringbuffer_aprintf(sb, "%s.sysconf", dc->interface); *************** *** 193,201 **** } void dhcp_sysconf_guile(dhcp_client_control_t *dc, list_t *options) { ! dhcp_def_guile_options(options); dhcp_run_guile_sysconf(dc); ! dhcp_undef_guile_options(options); return; --- 552,583 ---- } + /* * * * * * * * * * * * * * * * + * public interface routines. * + * * * * * * * * * * * * * * * */ + + void dhcp_guile_init(void) + { + init_client_control_smob(); + + /* bind subroutines. */ + + scm_c_define_gsubr("client-interface-up", 4, 0, 0, dhcp_scm_interface_up); + scm_c_define_gsubr("client-set-default-route", 2, 0, 0, dhcp_scm_client_set_default_route); + scm_c_define_gsubr("client-get-default-mtu", 1, 0, 0, dhcp_scm_get_default_mtu); + scm_c_define_gsubr("client-get-default-subnet-mask", 1, 0, 0, dhcp_scm_get_default_subnet_mask); + scm_c_define_gsubr("client-configure?", 2, 0, 0, dhcp_scm_configurep); + scm_c_define_gsubr("client-info-message", 1, 0, 0, scm_client_info_message); + scm_c_define_gsubr("client-error-message", 1, 0, 0, scm_client_error_message); + scm_c_define_gsubr("client-fatal-error-message", 1, 0, 0, scm_client_fatal_error_message); + scm_c_define_gsubr("client-shutdown", 1, 0, 0, scm_client_shutdown); + + return; + } + void dhcp_sysconf_guile(dhcp_client_control_t *dc, list_t *options) { ! dhcp_def_guile_options(dc, options); dhcp_run_guile_sysconf(dc); ! dhcp_undef_guile_options(dc, options); return; |
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv24500 Modified Files: Makefile.am dhcp-client.c dhcp-client.h dhcp-option-convert.c dhcp-option.c dhcp-option.h Log Message: updated for new guile interface Index: Makefile.am =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/Makefile.am,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** Makefile.am 5 May 2003 14:22:05 -0000 1.18 --- Makefile.am 6 May 2003 03:49:16 -0000 1.19 *************** *** 60,66 **** dhcp-client-states.c \ dhcp-options-strings.c \ ! dhcp-sysconf.c ! dhcp_client_LDADD = -ldhcputil @GUILE_LIB@ dhcp_sniff_LDADD = -ldhcputil --- 60,67 ---- dhcp-client-states.c \ dhcp-options-strings.c \ ! dhcp-sysconf.c \ ! dhcp-client-guile.c ! dhcp_client_LDADD = -ldhcputil @GUILE_LIB@ -lefence dhcp_sniff_LDADD = -ldhcputil Index: dhcp-client.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client.c,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** dhcp-client.c 2 Jan 2003 04:23:01 -0000 1.21 --- dhcp-client.c 6 May 2003 03:49:16 -0000 1.22 *************** *** 36,39 **** --- 36,41 ---- #include "dhcp-daemon.h" + #include <libguile.h> + /* forward declarations of do_ routines. */ static void do_version(char *interface); *************** *** 481,485 **** } ! int main(int argc, char *argv[]) { int c, command_code = DO_CLIENT; --- 483,488 ---- } ! /* main function: called from scm_boot_guile */ ! static void real_main(void *closure, int argc, char *argv[]) { int c, command_code = DO_CLIENT; *************** *** 574,576 **** --- 577,588 ---- commands[command_code] (interface); exit(0); + } + + /* actual main: boot guile up so it knows where the bottom of the stack is. */ + int main(int argc, char *argv[]) + { + scm_boot_guile(argc, argv, real_main, NULL); + + /* get rid of compiler warning. */ + exit(1); } Index: dhcp-client.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client.h,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** dhcp-client.h 3 Jan 2003 21:29:22 -0000 1.12 --- dhcp-client.h 6 May 2003 03:49:16 -0000 1.13 *************** *** 133,135 **** --- 133,138 ---- extern void dhcp_client_control_set_context(dhcp_client_control_t *dc, dhcp_client_control_context_t *context); + /* guile interface. */ + extern void dhcp_sysconf_guile(dhcp_client_control_t *dc, list_t *options); + #endif /* DHCP_CLIENT_H */ Index: dhcp-option-convert.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-option-convert.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-option-convert.c 4 May 2003 18:53:11 -0000 1.2 --- dhcp-option-convert.c 6 May 2003 03:49:16 -0000 1.3 *************** *** 1029,1041 **** } ! static char *ip_addr_to_string_proc(void *data) { ip_addr_t *ip_addr; ip_addr = data; ! return ip_addr_to_string(*ip_addr); } ! static char *ip_addr_list_to_string_proc(void *data, const char *separator) { ip_addr_t *ip_addr; --- 1029,1053 ---- } ! static char *ip_addr_to_string_proc(void *data, uint8_t quoted) { + stringbuffer_t *sb; ip_addr_t *ip_addr; + char *ip_addr_str; + ip_addr = data; + ip_addr_str = ip_addr_to_string(*ip_addr); ! if(quoted) { ! sb = stringbuffer_create(); ! stringbuffer_aprintf(sb, "\"%s\"", ip_addr_str); ! ! xfree(ip_addr_str); ! ip_addr_str = xstrdup(stringbuffer_getstring(sb)); ! } ! ! return ip_addr_str; } ! static char *ip_addr_list_to_string_proc(void *data, const char *separator, uint8_t quoted) { ip_addr_t *ip_addr; *************** *** 1109,1118 **** static char *ip_addr_list_to_user_string(void *data) { ! return ip_addr_list_to_string_proc(data, ", "); } static char *ip_addr_to_user_string(void *data) { ! return ip_addr_to_string_proc(data); } --- 1121,1130 ---- static char *ip_addr_list_to_user_string(void *data) { ! return ip_addr_list_to_string_proc(data, ", ", 1); } static char *ip_addr_to_user_string(void *data) { ! return ip_addr_to_string_proc(data, 1); } *************** *** 1156,1165 **** static char *ip_addr_list_to_internal_string(void *data) { ! return ip_addr_list_to_string_proc(data, ";"); } static char *ip_addr_to_internal_string(void *data) { ! return ip_addr_to_string_proc(data); } --- 1168,1177 ---- static char *ip_addr_list_to_internal_string(void *data) { ! return ip_addr_list_to_string_proc(data, ";", 0); } static char *ip_addr_to_internal_string(void *data) { ! return ip_addr_to_string_proc(data, 0); } Index: dhcp-option.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-option.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-option.c 4 May 2003 18:53:11 -0000 1.3 --- dhcp-option.c 6 May 2003 03:49:16 -0000 1.4 *************** *** 1371,1374 **** --- 1371,1379 ---- } + dhcp_opt_type_t dhcp_opt_get_val_type(dhcp_opt_t *opt) + { + return DHCP_OPT_GET_VAL_TYPE(opt); + } + dhcp_opt_tag_t dhcp_opt_get_tag(dhcp_opt_t *opt) { Index: dhcp-option.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-option.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-option.h 4 May 2003 18:53:11 -0000 1.3 --- dhcp-option.h 6 May 2003 03:49:16 -0000 1.4 *************** *** 67,70 **** --- 67,71 ---- #define DHCP_OPT_GET_TYPE(x) (x->opt_attr->type) + #define DHCP_OPT_GET_VAL_TYPE(x) (x->opt_attr->val_type) #define DHCP_OPT_GET_TAG(x) (x->opt_attr->tag) #define DHCP_OPT_GET_TOTAL_LEN(x) (x->opt_attr->len * x->num) |
From: <act...@us...> - 2003-05-06 03:48:46
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv24368 Added Files: dhcp-client-guile.c Log Message: new guile interface code --- NEW FILE: dhcp-client-guile.c --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-guile.c,v 1.1 2003/05/06 03:48:43 actmodern Exp $ * * Copyright 2002 Thamer Alharbash * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. The names of the authors may not be used to endorse or promote * products derived from this software without specific prior * written permission. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * * Glue between dhcp-client and guile. * * Everything to do with guile should go here. * */ #include "dhcp-local.h" #include "dhcp-libutil.h" #include "dhcp-librawnet.h" #include "dhcp-option.h" #include "dhcp-options-strings.h" #include "dhcp-client-conf.h" #include "dhcp-client-cache.h" #include "dhcp-client.h" #include <libguile.h> /* define a dhcp option as a list. */ static void def_guile_option_list(dhcp_opt_t *option) { stringbuffer_t *expr_sb; stringbuffer_t *val_sb; char *val; expr_sb = stringbuffer_create(); val_sb = stringbuffer_create(); val = dhcp_opt_get_user_string(option); stringbuffer_aprintf(val_sb, "'( %s", val); xfree(val); stringbuffer_replace_c(val_sb, ',', ' '); stringbuffer_aprintf(val_sb, ")"); stringbuffer_aprintf(expr_sb, "(define dhcp-%s %s)", dhcp_option_conf_string_get(dhcp_opt_get_tag(option)), stringbuffer_getstring(val_sb)); scm_c_eval_string(stringbuffer_getstring(expr_sb)); stringbuffer_destroy(expr_sb); stringbuffer_destroy(val_sb); return; } /* define a dhcp option as an atom. */ static void def_guile_option_atom(dhcp_opt_t *option) { stringbuffer_t *expr_sb; expr_sb = stringbuffer_create(); stringbuffer_aprintf(expr_sb, "(define dhcp-%s %s)", dhcp_option_conf_string_get(dhcp_opt_get_tag(option)), dhcp_opt_get_user_string(option)); scm_c_eval_string(stringbuffer_getstring(expr_sb)); stringbuffer_destroy(expr_sb); return; } /* define a dhcp option as string -- this means we have to escape any " and \. */ static void def_guile_option_string(dhcp_opt_t *option) { stringbuffer_t *expr_sb; stringbuffer_t *val_sb; expr_sb = stringbuffer_create(); val_sb = stringbuffer_create(); stringbuffer_append(val_sb, dhcp_opt_get_user_string(option)); stringbuffer_replace(val_sb, "\\", "\\\\"); stringbuffer_replace(val_sb, "\"", "\\\""); stringbuffer_aprintf(expr_sb, "(define dhcp-%s \"%s\")", dhcp_option_conf_string_get(dhcp_opt_get_tag(option)), stringbuffer_getstring(val_sb)); scm_c_eval_string(stringbuffer_getstring(expr_sb)); stringbuffer_destroy(expr_sb); stringbuffer_destroy(val_sb); return; } /* define a dhcp option at the top level guile environ. */ static void def_guile_option(dhcp_opt_t *option) { switch(dhcp_opt_get_type(option)) { case DHCP_OPT_LIST: def_guile_option_list(option); break; case DHCP_OPT_ATOM: def_guile_option_atom(option); break; case DHCP_OPT_STRING: def_guile_option_string(option); break; case DHCP_OPT_ARRAY: def_guile_option_list(option); break; default: FATAL_MESSAGE("illegal dhcp option. i should not get here. this is a bug. report it."); exit(1); } return; } /* take a list of options and define them at the top level. */ static void dhcp_def_guile_options(list_t *options) { dhcp_opt_t *option; /* walk down list and create each option and bind symbols to dhcp options. */ list_rewind(options); while((option = list_next(options)) != NULL) { def_guile_option(option); } /* that's it. */ return; } /* undefine options so we don't see stale ones the next time we do a sysconf. */ static void dhcp_undef_guile_options(list_t *options) { dhcp_opt_t *option; stringbuffer_t *expr_sb; /* walk down list and undef each option by name. */ expr_sb = stringbuffer_create(); list_rewind(options); while((option = list_next(options)) != NULL) { stringbuffer_clear(expr_sb); stringbuffer_aprintf(expr_sb, "(undefine dhcp-%s)", dhcp_option_conf_string_get(dhcp_opt_get_tag(option))); scm_c_eval_string(stringbuffer_getstring(expr_sb)); } stringbuffer_destroy(expr_sb); return; } static void dhcp_run_guile_sysconf(dhcp_client_control_t *dc) { stringbuffer_t *sb; sb = stringbuffer_create(); stringbuffer_aprintf(sb, "%s.sysconf", dc->interface); scm_c_primitive_load(stringbuffer_getstring(sb)); stringbuffer_destroy(sb); return; } void dhcp_sysconf_guile(dhcp_client_control_t *dc, list_t *options) { dhcp_def_guile_options(options); dhcp_run_guile_sysconf(dc); dhcp_undef_guile_options(options); return; } |
From: <act...@us...> - 2003-05-05 14:22:09
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv3336 Modified Files: Makefile.am Log Message: added libguile Index: Makefile.am =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/Makefile.am,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** Makefile.am 4 May 2003 18:48:50 -0000 1.17 --- Makefile.am 5 May 2003 14:22:05 -0000 1.18 *************** *** 4,8 **** AM_CFLAGS = -Wall -Werror ! INCLUDES = @PCAP_INC@ @DNET_INC@ DEFS = @DEFS@ AUTOMAKE_OPTIONS = foreign --- 4,8 ---- AM_CFLAGS = -Wall -Werror ! INCLUDES = @PCAP_INC@ @DNET_INC@ @GUILE_INC@ DEFS = @DEFS@ AUTOMAKE_OPTIONS = foreign *************** *** 62,66 **** dhcp-sysconf.c ! dhcp_client_LDADD = -ldhcputil -lefence dhcp_sniff_LDADD = -ldhcputil --- 62,66 ---- dhcp-sysconf.c ! dhcp_client_LDADD = -ldhcputil @GUILE_LIB@ dhcp_sniff_LDADD = -ldhcputil |
From: <act...@us...> - 2003-05-05 14:21:28
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory sc8-pr-cvs1:/tmp/cvs-serv2950 Modified Files: TODO Log Message: update to TODO Index: TODO =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/TODO,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** TODO 30 Mar 2003 04:34:00 -0000 1.8 --- TODO 5 May 2003 14:21:24 -0000 1.9 *************** *** 3,7 **** Things that need to be done for RFC compliance: ! -- allow options to be concontonated together (which extend over 255 octets) --- 3,7 ---- Things that need to be done for RFC compliance: ! -- allow options to be concantonated together (which extend over 255 octets) *************** *** 41,69 **** -- stringbuffer used in almost _all_ string operations except really simple ones. - -- we may need to change the dhcp_build_* routines to use the - dhcp-convert driver to generate the network data. it's not an - issue in the client since our option generation is minimal but - will be in the server where we'll have lots of internal data - to pack into the dhcp responses. right now we have a handful of - routines that do. we need an array of generic routines to call - the applicable dhcp-convert and then build the option wirh - create_dhcp_option(data, len, tag) - -- document output from dhcpsniff -- especially how brief mode is layed out. - -- dhcpsniff shouldn't be using printfs -- wrap that up in one of - the messaging routines or create a new one. - -- change uint32_t to ip_addr_t for ipv4 addresses. (this looks almost done) - -- make it so set/get methods in all packeting routines do - network type conversions and not higher level functions (i - think this is done now) - - -- list_destroy only accepts one destructor. we need a way of destroying a list - with differnet data types. (this looks too complicated to do - and not enough code needs it) - -- check for race condition -- even if it is tiny -- in client_wait --- 41,49 ---- *************** *** 71,78 **** single client_request_ack routine ! -- complete client-conf code. define the prototype for a hook and ! put it in all the right places. ! ! -- write dhcp-sysconf to allow configuration via a small minimalistic interpreter -- check if we handle 0xffffffff timers right. --- 51,55 ---- single client_request_ack routine ! -- write dhcp-sysconf to allow configuration via a guile -- check if we handle 0xffffffff timers right. *************** *** 89,103 **** prudent to capsulate this as an object in its own right. - -- client-conf limitiation. append/prepend options may not - contain semicolons in lists. append/prepend/override can't - tell the difference between a single value and a list. this - causes problem because we cannot cleanly link this into the - soon-to-be-written guile recipes. need a way to represent - options better. - -- subnet mask must be first option if router option is set. ! -- need a whole new way to look at dhcp option. a dhcp_option ! object which does a lot more and is abstracted from a lot of ! the other code. --- 66,74 ---- prudent to capsulate this as an object in its own right. -- subnet mask must be first option if router option is set. ! -- stringbuffer might be more useful it allowed marking of ! arbitrary characters with sentinels. + -- our configure script can handle define our own PRI C99 format + definitions. We need ones for scanning -- SCN. |
From: <act...@us...> - 2003-05-05 01:26:51
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv16855 Modified Files: dhcp-client-control.c Log Message: now using stringbuffer_t for class id construction Index: dhcp-client-control.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-control.c,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** dhcp-client-control.c 4 May 2003 18:51:37 -0000 1.15 --- dhcp-client-control.c 5 May 2003 01:26:49 -0000 1.16 *************** *** 132,135 **** --- 132,136 ---- #ifdef HAVE_UNAME struct utsname utsname; + stringbuffer_t *sb; #endif /* HAVE_UNAME */ *************** *** 197,205 **** #ifdef HAVE_UNAME uname(&utsname); ! /* FIXME use stringbuffer to make sure spacing is correct. */ ! dc->class_id = ! splice_many_strings(4, utsname.sysname, utsname.nodename, utsname.release, utsname.version, ! utsname.machine); #else /* HAVE_UNAME */ dc->class_id = xstrdup("Unknown"); --- 198,212 ---- #ifdef HAVE_UNAME + sb = stringbuffer_create(); + uname(&utsname); ! ! stringbuffer_aprintf(sb, "%s %s %s %s", utsname.sysname, utsname.nodename, utsname.release, utsname.version, ! utsname.machine); ! ! dc->class_id = xstrdup(stringbuffer_getstring(sb)); ! ! stringbuffer_destroy(sb); ! #else /* HAVE_UNAME */ dc->class_id = xstrdup("Unknown"); |
From: <act...@us...> - 2003-05-05 01:23:40
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv16129 Modified Files: dhcp-client-cache.c Log Message: fixed compile error -- moved scope of static function Index: dhcp-client-cache.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-cache.c,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** dhcp-client-cache.c 4 May 2003 18:50:41 -0000 1.15 --- dhcp-client-cache.c 5 May 2003 01:23:37 -0000 1.16 *************** *** 168,209 **** } - /* load cache and optionally run the check routine passed on it. */ - static list_t *client_cache_load_options_proc(client_cache_t *cc, uint8_t use_tmp, - int (*check)(cache_entry_t *ce)) - { - list_t *option_list; - cache_entry_t *ce; - dhcp_opt_t *option; - - if(client_cache_load(cc, use_tmp)) - return NULL; - - /* create the option list. */ - option_list = list_create(); - - /* now convert from cache entry to dhcp option. */ - list_rewind(cc->vars); - while((ce = list_next(cc->vars)) != NULL) { - - /* check if we want it. */ - if((check != NULL && check(ce)) || - (check == NULL)) { - - option = dhcp_opt_create_from_host_string(ce->tag, ce->value); - - if(option == NULL) { - ERROR_MESSAGE("could not convert option %s from cached value: %s", - dhcp_option_printable_string_get(ce->tag), - ce->value); - FATAL_MESSAGE("cache is corrupt! exiting."); - } - - list_add(option_list, option); - } - } - - return option_list; - } - /* * * * * * * * * * * * Cache load/dump * --- 168,171 ---- *************** *** 279,282 **** --- 241,282 ---- return retval; + } + + /* load cache and optionally run the check routine passed on it. */ + static list_t *client_cache_load_options_proc(client_cache_t *cc, uint8_t use_tmp, + int (*check)(cache_entry_t *ce)) + { + list_t *option_list; + cache_entry_t *ce; + dhcp_opt_t *option; + + if(client_cache_load(cc, use_tmp)) + return NULL; + + /* create the option list. */ + option_list = list_create(); + + /* now convert from cache entry to dhcp option. */ + list_rewind(cc->vars); + while((ce = list_next(cc->vars)) != NULL) { + + /* check if we want it. */ + if((check != NULL && check(ce)) || + (check == NULL)) { + + option = dhcp_opt_create_from_host_string(ce->tag, ce->value); + + if(option == NULL) { + ERROR_MESSAGE("could not convert option %s from cached value: %s", + dhcp_option_printable_string_get(ce->tag), + ce->value); + FATAL_MESSAGE("cache is corrupt! exiting."); + } + + list_add(option_list, option); + } + } + + return option_list; } |
From: <act...@us...> - 2003-05-04 18:53:32
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv11120 Modified Files: dhcp-sysconf.c Log Message: sysconf brought in line with new dhcp object Index: dhcp-sysconf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-sysconf.c,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** dhcp-sysconf.c 25 Mar 2003 03:06:42 -0000 1.15 --- dhcp-sysconf.c 4 May 2003 18:53:28 -0000 1.16 *************** *** 31,44 **** #include "dhcp-libutil.h" #include "dhcp-librawnet.h" - #include "dhcp-client-conf.h" #include "dhcp-cache-entry.h" #include "dhcp-client-cache.h" #include "dhcp-client.h" - - #include "dhcp-convert.h" #include "dhcp-sysconf.h" - #include "dhcp-options-strings.h" - static int sysconf_setup_routers(void *value, dhcp_client_control_t *dc); --- 31,42 ---- #include "dhcp-libutil.h" #include "dhcp-librawnet.h" + #include "dhcp-option.h" + #include "dhcp-options-strings.h" #include "dhcp-cache-entry.h" #include "dhcp-client-cache.h" + #include "dhcp-client-conf.h" #include "dhcp-client.h" #include "dhcp-sysconf.h" static int sysconf_setup_routers(void *value, dhcp_client_control_t *dc); *************** *** 244,302 **** { struct route_entry r_entry; ! uint32_t *tmp_addr_val, *addr_val = NULL; route_t *rt; list_t *routers; - list_t *average_latencies; - int *lowest_latency; - int *latency; - int sends; ! memset(&r_entry.route_dst, 0, sizeof(r_entry.route_dst)); ! memset(&r_entry.route_gw, 0, sizeof(r_entry.route_gw)); routers = value; ! if(client_conf_get_do_measure_router_latency_icmp(dc->conf, ! dhcp_client_get_server_ip_address(dc), dhcp_client_get_server_hw_address(dc))) { ! ! /* check router latency with icmp. this is probably broken. */ ! ! sends = client_conf_get_icmp_retries(dc->conf, dhcp_client_get_server_ip_address(dc), dhcp_client_get_server_hw_address(dc)); ! ! /* we're guaranteed at least one router and one returned from icmp_rtt_discovery */ ! average_latencies = icmp_rtt_discovery(dc->rawnet, routers, sends); ! ! /* Even if all routers fail to respond to the ICMP echo query, ! * we still want to use one of them. ! * (See RFC 1812, section 4.3.3.6.) */ ! ! list_rewind(average_latencies); ! addr_val = list_next(average_latencies); ! lowest_latency = list_next(average_latencies); ! ! while(((tmp_addr_val = list_next(average_latencies)) != NULL) ! && ((latency = list_next(average_latencies)) != NULL)) { ! ! if(*latency != -1 && *latency < *lowest_latency) { ! *lowest_latency = *latency; ! addr_val = tmp_addr_val; ! } ! } ! ! r_entry.route_dst.addr_type = ADDR_TYPE_IP; ! r_entry.route_dst.addr_bits = 0; ! r_entry.route_dst.addr_ip = 0; ! ! r_entry.route_gw.addr_type = ADDR_TYPE_IP; ! r_entry.route_gw.addr_bits = 0; ! memcpy(&r_entry.route_gw.addr_ip, addr_val, IP_ADDR_LEN); ! ! list_destroy(average_latencies, xfree); ! } else { ! /* just get the first value. */ ! addr_val = list_first(routers); ! } rt = route_open(); --- 242,262 ---- { struct route_entry r_entry; ! uint32_t *addr_val; route_t *rt; list_t *routers; ! memset(&r_entry, 0, sizeof(struct route_entry)); routers = value; ! addr_val = list_first(routers); ! r_entry.route_dst.addr_type = ADDR_TYPE_IP; ! r_entry.route_dst.addr_bits = 0; ! r_entry.route_dst.addr_ip = 0; ! r_entry.route_gw.addr_type = ADDR_TYPE_IP; ! r_entry.route_gw.addr_bits = 0; ! memcpy(&r_entry.route_gw.addr_ip, addr_val, IP_ADDR_LEN); rt = route_open(); *************** *** 395,414 **** uint8_t have_netmask = 0; uint16_t mtu_val = 0; ! cache_entry_t *ce; void *data; int mtu; INFO_MESSAGE("configuring interface: %s", dc->interface); list_rewind(options); ! while((ce = list_next(options)) != NULL) { ! if(TAG_DHCP_REQUESTED_IP_ADDRESS == ce->tag) { ! data = ! option_convert_handlers[TAG_DHCP_REQUESTED_IP_ADDRESS].serialize_to_internal(ce-> ! value); memcpy(&addr, data, IP_ADDR_LEN); - xfree(data); have_addr = 1; --- 355,374 ---- uint8_t have_netmask = 0; uint16_t mtu_val = 0; ! dhcp_opt_t *option; void *data; int mtu; + dhcp_opt_tag_t tag; INFO_MESSAGE("configuring interface: %s", dc->interface); list_rewind(options); ! while((option = list_next(options)) != NULL) { ! tag = dhcp_opt_get_tag(option); ! if(tag == TAG_DHCP_REQUESTED_IP_ADDRESS) { ! ! data = dhcp_opt_get_host_data(option); memcpy(&addr, data, IP_ADDR_LEN); have_addr = 1; *************** *** 416,424 **** } ! if(TAG_DHCP_SUBNET_MASK == ce->tag) { ! data = option_convert_handlers[TAG_DHCP_SUBNET_MASK].serialize_to_internal(ce->value); memcpy(&netmask, data, IP_ADDR_LEN); - xfree(data); have_netmask = 1; --- 376,383 ---- } ! if(tag == TAG_DHCP_SUBNET_MASK) { ! data = dhcp_opt_get_host_data(option); memcpy(&netmask, data, IP_ADDR_LEN); have_netmask = 1; *************** *** 426,432 **** } ! if(TAG_DHCP_INTERFACE_MTU == ce->tag) { ! data = option_convert_handlers[TAG_DHCP_INTERFACE_MTU].serialize_to_internal(ce->value); memcpy(&mtu, data, sizeof(uint16_t)); xfree(data); --- 385,391 ---- } ! if(tag == TAG_DHCP_INTERFACE_MTU) { ! data = dhcp_opt_get_host_data(option); memcpy(&mtu, data, sizeof(uint16_t)); xfree(data); *************** *** 462,467 **** { void *data; ! cache_entry_t *ce; uint8_t *configure_opts = NULL; /* Clean up any config files we have. */ --- 421,427 ---- { void *data; ! dhcp_opt_t *option; uint8_t *configure_opts = NULL; + dhcp_opt_tag_t tag; /* Clean up any config files we have. */ *************** *** 490,494 **** list_rewind(options); ! while((ce = list_next(options)) != NULL) { /* Make sure we know how to setup this option, and we're --- 450,456 ---- list_rewind(options); ! while((option = list_next(options)) != NULL) { ! ! tag = dhcp_opt_get_tag(option); /* Make sure we know how to setup this option, and we're *************** *** 497,525 **** if(configure_opts) { ! if(sysconf_handlers[ce->tag].setup == NULL || ! option_convert_handlers[ce->tag].serialize_to_internal == NULL || ! configure_opts[ce->tag] == 0) continue; } else { ! if(sysconf_handlers[ce->tag].setup == NULL || ! option_convert_handlers[ce->tag].serialize_to_internal == NULL) continue; } ! data = option_convert_handlers[ce->tag].serialize_to_internal(ce->value); /* Cleanup first, if we're supposed to. */ ! if(sysconf_handlers[ce->tag].cleanup != NULL && ! (sysconf_handlers[ce->tag].flag & SYSCONF_DO_CLEANUP) == 1) { ! INFO_MESSAGE("cleanup option: %s", dhcp_option_printable_string_get(ce->tag)); ! if(sysconf_handlers[ce->tag].cleanup(data, dc)) WARN_MESSAGE("sysconf: error cleaning up option: %s", ! dhcp_option_conf_string_get(ce->tag)); } --- 459,485 ---- if(configure_opts) { ! if(sysconf_handlers[tag].setup == NULL || ! configure_opts[tag] == 0) continue; } else { ! if(sysconf_handlers[tag].setup == NULL) continue; } ! data = dhcp_opt_get_host_data(option); /* Cleanup first, if we're supposed to. */ ! if(sysconf_handlers[tag].cleanup != NULL && ! (sysconf_handlers[tag].flag & SYSCONF_DO_CLEANUP) == 1) { ! INFO_MESSAGE("cleanup option: %s", dhcp_option_printable_string_get(tag)); ! if(sysconf_handlers[tag].cleanup(data, dc)) WARN_MESSAGE("sysconf: error cleaning up option: %s", ! dhcp_option_conf_string_get(tag)); } *************** *** 527,548 **** * cleanup. */ ! INFO_MESSAGE("setup option: %s", dhcp_option_printable_string_get(ce->tag)); ! if(sysconf_handlers[ce->tag].setup(data, dc)) { ! sysconf_handlers[ce->tag].flag &= ~SYSCONF_DO_CLEANUP; ! WARN_MESSAGE("unable to setup option: %s", dhcp_option_printable_string_get(ce->tag)); } else { ! sysconf_handlers[ce->tag].flag |= SYSCONF_DO_CLEANUP; } - option_convert_handlers[ce->tag].free_internal(data); - } - /* we don't need to worry about race conditions. * /etc should NOT be world writable! */ --- 487,505 ---- * cleanup. */ ! INFO_MESSAGE("setup option: %s", dhcp_option_printable_string_get(tag)); ! if(sysconf_handlers[tag].setup(data, dc)) { ! sysconf_handlers[tag].flag &= ~SYSCONF_DO_CLEANUP; ! WARN_MESSAGE("unable to setup option: %s", dhcp_option_printable_string_get(tag)); } else { ! sysconf_handlers[tag].flag |= SYSCONF_DO_CLEANUP; } } /* we don't need to worry about race conditions. * /etc should NOT be world writable! */ *************** *** 561,583 **** { void *data; ! cache_entry_t *ce; /* Walk through the sysconf_handlers array. */ list_rewind(options); ! while((ce = list_next(options)) != NULL) { ! if(sysconf_handlers[ce->tag].flag & SYSCONF_DO_CLEANUP && ! sysconf_handlers[ce->tag].cleanup != NULL) { ! data = option_convert_handlers[ce->tag].serialize_to_internal(ce->value); ! INFO_MESSAGE("cleanup option: %s", dhcp_option_printable_string_get(ce->tag)); ! if(sysconf_handlers[ce->tag].cleanup(data, dc)) WARN_MESSAGE("sysconf: error cleaning up option: %s", ! dhcp_option_printable_string_get(ce->tag)); ! ! option_convert_handlers[ce->tag].free_internal(data); } } --- 518,540 ---- { void *data; ! dhcp_opt_t *option; ! dhcp_opt_tag_t tag; /* Walk through the sysconf_handlers array. */ list_rewind(options); ! while((option = list_next(options)) != NULL) { ! tag = dhcp_opt_get_tag(option); ! if(sysconf_handlers[tag].flag & SYSCONF_DO_CLEANUP && ! sysconf_handlers[tag].cleanup != NULL) { ! data = dhcp_opt_get_host_data(option); ! INFO_MESSAGE("cleanup option: %s", dhcp_option_printable_string_get(tag)); ! if(sysconf_handlers[tag].cleanup(data, dc)) WARN_MESSAGE("sysconf: error cleaning up option: %s", ! dhcp_option_printable_string_get(tag)); } } |
From: <act...@us...> - 2003-05-04 18:53:15
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv10987 Modified Files: dhcp-librawnet.h dhcp-option-convert.c dhcp-option.c dhcp-option.h Log Message: new interface additions to dhcp object -- need to put all in librawnet.h though Index: dhcp-librawnet.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-librawnet.h,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** dhcp-librawnet.h 2 May 2003 02:34:19 -0000 1.11 --- dhcp-librawnet.h 4 May 2003 18:53:11 -0000 1.12 *************** *** 475,480 **** extern int dhcp_is_sname_overload(dhcp_obj * dhcp); - extern dhcp_opt_t *dhcp_build_parameter_request_list_option(uint8_t *requested_options); - extern int dhcp_read_packet_image(dhcp_obj * dhcp, const uint8_t *dhcp_packet, int len); extern void dhcp_write_options(dhcp_obj * dhcp, uint8_t *packet); --- 475,478 ---- Index: dhcp-option-convert.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-option-convert.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** dhcp-option-convert.c 28 Apr 2003 22:23:06 -0000 1.1 --- dhcp-option-convert.c 4 May 2003 18:53:11 -0000 1.2 *************** *** 28,32 **** #define MODULE_NAME "dhcp-option-convert" ! #define DHCP_OPTION_MACROS /* get the dhcp-option macros. */ #include "dhcp-local.h" --- 28,32 ---- #define MODULE_NAME "dhcp-option-convert" ! #define DHCP_OPTION_MACROS #include "dhcp-local.h" *************** *** 72,75 **** --- 72,78 ---- } + if(num == 0 && *input != 0) + num++; /* we have at least one. */ + return num; } *************** *** 362,366 **** for(i = 0;i < num;i ++) { ! uint32_copy[i] = ntohs(uint32_data[i]); } --- 365,369 ---- for(i = 0;i < num;i ++) { ! uint32_copy[i] = ntohl(uint32_data[i]); } *************** *** 1053,1057 **** num++; if(num < list_get_len(list)) { ! stringbuffer_aprintf(sb, "%s%s ", ip_addr_str, separator); } else { stringbuffer_aprintf(sb, "%s", ip_addr_str); --- 1056,1060 ---- num++; if(num < list_get_len(list)) { ! stringbuffer_aprintf(sb, "%s%s", ip_addr_str, separator); } else { stringbuffer_aprintf(sb, "%s", ip_addr_str); *************** *** 1490,1494 **** new_string = xmalloc(sizeof(int8_t) * (string_len + 1)); memcpy(new_string, data, string_len); ! new_string[string_len -1] = 0; opt->num = string_len; --- 1493,1497 ---- new_string = xmalloc(sizeof(int8_t) * (string_len + 1)); memcpy(new_string, data, string_len); ! new_string[string_len] = 0; opt->num = string_len; Index: dhcp-option.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-option.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-option.c 28 Apr 2003 22:20:24 -0000 1.2 --- dhcp-option.c 4 May 2003 18:53:11 -0000 1.3 *************** *** 23,28 **** */ - #define DHCP_OPTION_MACROS /* use the macros in dhcp-option.h */ #define MODULE_NAME "dhcp-option" #include "dhcp-local.h" --- 23,28 ---- */ #define MODULE_NAME "dhcp-option" + #define DHCP_OPTION_MACROS #include "dhcp-local.h" *************** *** 755,762 **** DHCP_OPT_VAL_ADDRESS, dhcp_opt_to_network_ip_addr, ! dhcp_opt_to_user_string_list_ip_addr, ! dhcp_opt_to_internal_string_list_ip_addr, dhcp_opt_from_network_ip_addr, ! dhcp_opt_from_user_string_list_ip_addr, dhcp_opt_from_internal_string_ip_addr, dhcp_opt_destroy_atom, --- 755,762 ---- DHCP_OPT_VAL_ADDRESS, dhcp_opt_to_network_ip_addr, ! dhcp_opt_to_user_string_ip_addr, ! dhcp_opt_to_internal_string_ip_addr, dhcp_opt_from_network_ip_addr, ! dhcp_opt_from_user_string_ip_addr, dhcp_opt_from_internal_string_ip_addr, dhcp_opt_destroy_atom, *************** *** 890,907 **** }, - /* Another one we aren't - * implementing at all. */ - /* Vendor class identifier */ { TAG_DHCP_VENDOR_CLASS_ID, sizeof(uint8_t), ! DHCP_OPT_ATOM, DHCP_OPT_VAL_UINT8, ! dhcp_opt_to_network_uint8, ! dhcp_opt_to_user_string_uint8, ! dhcp_opt_to_internal_string_uint8, ! dhcp_opt_from_network_uint8, ! dhcp_opt_from_user_string_uint8, ! dhcp_opt_from_internal_string_uint8, dhcp_opt_destroy_atom, }, --- 890,904 ---- }, /* Vendor class identifier */ { TAG_DHCP_VENDOR_CLASS_ID, sizeof(uint8_t), ! DHCP_OPT_STRING, DHCP_OPT_VAL_UINT8, ! dhcp_opt_to_network_string, ! dhcp_opt_to_user_string_string, ! dhcp_opt_to_internal_string_string, ! dhcp_opt_from_network_string, ! dhcp_opt_from_user_string_string, ! dhcp_opt_from_internal_string_string, dhcp_opt_destroy_atom, }, *************** *** 1205,1209 **** /* create a new dhcp option datum from network data. */ ! dhcp_opt_t *dhcp_opt_create_from_network(const uint8_t *data, size_t len, dhcp_opt_tag_t tag) { dhcp_opt_t *opt; --- 1202,1206 ---- /* create a new dhcp option datum from network data. */ ! dhcp_opt_t *dhcp_opt_create_from_network(const uint8_t *data, dhcp_opt_len_t len, dhcp_opt_tag_t tag) { dhcp_opt_t *opt; *************** *** 1276,1279 **** --- 1273,1277 ---- opt->val = xstrdup(data); opt->num = strlen(data); + break; *************** *** 1357,1361 **** /* get total length. */ ! size_t dhcp_opt_get_total_len(dhcp_opt_t *opt) { return DHCP_OPT_GET_TOTAL_LEN(opt); --- 1355,1359 ---- /* get total length. */ ! dhcp_opt_len_t dhcp_opt_get_total_len(dhcp_opt_t *opt) { return DHCP_OPT_GET_TOTAL_LEN(opt); *************** *** 1367,1368 **** --- 1365,1444 ---- return opt->num; } + + dhcp_opt_type_t dhcp_opt_get_type(dhcp_opt_t *opt) + { + return DHCP_OPT_GET_TYPE(opt); + } + + dhcp_opt_tag_t dhcp_opt_get_tag(dhcp_opt_t *opt) + { + return DHCP_OPT_GET_TAG(opt); + } + + /* convenience routines. */ + + /* create a dhcp message type option. */ + dhcp_opt_t *dhcp_opt_create_message_type(uint8_t message_type) + { + return dhcp_opt_create_from_internal_data(TAG_DHCP_MESSAGE_TYPE, &message_type, sizeof(message_type)); + } + + /* accept bit array telling us which options to build the request option. */ + dhcp_opt_t *dhcp_opt_create_parameter_request_list(uint8_t *requested_options) + { + uint8_t i, j; + uint8_t len = 0; + dhcp_opt_t *option; + uint8_t *opt_request; + + /* Grab length so we can just malloc all at once. */ + for(i = 0; i < MAX_OPTIONS_HANDLED; i++) { + if(requested_options[i]) + len++; + } + + if(len == 0) { + /* no parameter list. return empty list. */ + return NULL; + } + + opt_request = xmalloc(len * sizeof(uint8_t)); + + j = 0; + for(i = 0; i < MAX_OPTIONS_HANDLED; i++) { + if(requested_options[i]) { + opt_request[j] = i; + j++; + } + } + + option = dhcp_opt_create_from_internal_data(TAG_DHCP_PARAMETERS, opt_request, len); + xfree(opt_request); + + return option; + } + + /* destroy a list of options by calling their destruction routine. */ + void dhcp_opt_destroy_option_list(list_t *list) + { + dhcp_opt_t *option; + + list_rewind(list); + while((option = list_next(list)) != NULL) { + + list_remove_by_datum(list, option); + dhcp_opt_destroy(option); + } + + list_destroy(list, NULL); + + return; + } + + dhcp_opt_t *dhcp_option_copy(dhcp_opt_t *option) + { + return dhcp_opt_create_from_internal_data(dhcp_opt_get_tag(option), + dhcp_opt_get_host_data(option), + dhcp_opt_get_total_len(option)); + } + Index: dhcp-option.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-option.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-option.h 28 Apr 2003 22:20:24 -0000 1.2 --- dhcp-option.h 4 May 2003 18:53:11 -0000 1.3 *************** *** 26,86 **** #define DHCP_OPTION_H ! /* type definitions. */ ! ! typedef uint8_t dhcp_opt_tag_t; ! typedef uint8_t dhcp_opt_len_t; ! typedef uint16_t dhcp_opt_type_t; ! typedef uint16_t dhcp_opt_val_type_t; ! ! /* forward declare dhcp_opt to typedef function pointers below. */ ! struct dhcp_opt; ! ! /* typedef of dhcp option function pointers. */ ! ! /* converters from external data to internal */ ! typedef int (*dhcp_opt_from_string)(struct dhcp_opt *opt, const char *input); ! typedef int (*dhcp_opt_from_user_string)(struct dhcp_opt *opt, list_t *input_list); ! typedef int (*dhcp_opt_from_network)(struct dhcp_opt *opt, const uint8_t *data, size_t len); ! ! /* converts from internal data to other data formats. */ ! typedef void *(*dhcp_opt_to_network_data)(struct dhcp_opt *opt); ! typedef void *(*dhcp_opt_to_host_data)(struct dhcp_opt *opt); ! typedef char *(*dhcp_opt_to_user_string)(struct dhcp_opt *opt); ! typedef char *(*dhcp_opt_to_string)(struct dhcp_opt *opt); ! ! /* the data destructor. */ ! typedef void (*dhcp_opt_data_destroy)(struct dhcp_opt *opt); ! ! typedef struct dhcp_opt_attr { ! ! dhcp_opt_tag_t tag; /* tag */ ! dhcp_opt_len_t len; /* member length in octets */ ! dhcp_opt_val_type_t type; /* type of opt */ ! dhcp_opt_val_type_t val_type; /* type of val */ ! ! /* data extraction routines. */ ! dhcp_opt_to_network_data to_network_data; /* to network data representation. */ ! dhcp_opt_to_user_string to_user_string; /* to user string representation. */ ! dhcp_opt_to_string to_internal_string; /* to internal string representation. */ ! ! /* data creation routines. */ ! dhcp_opt_from_network from_network; /* network data to internal. */ ! dhcp_opt_from_user_string from_user_string; /* user string to internal. */ ! dhcp_opt_from_string from_internal_string; /* string to internal. */ ! ! dhcp_opt_data_destroy destroy; /* destroy option datum. */ ! ! } dhcp_opt_attr_t; ! ! /* the dhcp_opt object. */ ! ! typedef struct dhcp_opt { ! void *val; /* value */ ! size_t num; /* num */ ! dhcp_opt_attr_t *opt_attr; /* attributes */ ! } dhcp_opt_t; /* constants. */ --- 26,51 ---- #define DHCP_OPTION_H ! /* prototypes. */ ! extern dhcp_opt_t *dhcp_opt_create_from_network(const uint8_t *data, dhcp_opt_len_t len, dhcp_opt_tag_t tag); ! extern dhcp_opt_t *dhcp_opt_create_from_internal_data(uint8_t tag, void *data, size_t len); ! extern dhcp_opt_t *dhcp_opt_create_from_user_string(uint8_t tag, void *string_data); ! extern dhcp_opt_t *dhcp_opt_create_from_host_string(uint8_t tag, char *input); ! extern void *dhcp_opt_get_network_data(dhcp_opt_t *opt); ! extern void *dhcp_opt_get_host_data(dhcp_opt_t *opt); ! extern char *dhcp_opt_get_user_string(dhcp_opt_t *opt); ! extern char *dhcp_opt_get_internal_string(dhcp_opt_t *opt); ! extern size_t dhcp_opt_get_mem_len(dhcp_opt_t *opt); ! extern size_t dhcp_opt_get_num(dhcp_opt_t *opt); ! extern dhcp_opt_len_t dhcp_opt_get_total_len(dhcp_opt_t *opt); ! extern dhcp_opt_tag_t dhcp_opt_get_tag(dhcp_opt_t *opt); ! extern dhcp_opt_type_t dhcp_opt_get_type(dhcp_opt_t *opt); ! extern void dhcp_opt_destroy(dhcp_opt_t *opt); ! extern void dhcp_opt_destroy_option_list(list_t *list); ! extern dhcp_opt_t *dhcp_option_copy(dhcp_opt_t *option); ! extern dhcp_opt_t *dhcp_opt_create_message_type(uint8_t message_type); ! extern dhcp_opt_t *dhcp_opt_create_parameter_request_list(uint8_t *requested_options); /* constants. */ *************** *** 102,105 **** --- 67,71 ---- #define DHCP_OPT_GET_TYPE(x) (x->opt_attr->type) + #define DHCP_OPT_GET_TAG(x) (x->opt_attr->tag) #define DHCP_OPT_GET_TOTAL_LEN(x) (x->opt_attr->len * x->num) #define DHCP_OPT_GET_MEM_LEN(x) (x->opt_attr->len) *************** *** 117,121 **** #endif /* DHCP_OPTION_MACROS */ - #endif /* DHCP_OPTION_H */ --- 83,86 ---- |
From: <act...@us...> - 2003-05-04 18:52:22
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv10718 Modified Files: dhcp-com.c Log Message: dhcp-com brought in line with new dhcp object Index: dhcp-com.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-com.c,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** dhcp-com.c 2 May 2003 02:34:19 -0000 1.10 --- dhcp-com.c 4 May 2003 18:52:19 -0000 1.11 *************** *** 47,60 **** } ! /* clean out options. */ ! static void dhcp_purge_option_list(list_t *options) { ! dhcp_opt_t *opt; ! list_rewind(options); ! while((opt = list_next(options)) != NULL) { ! list_remove_by_datum(options, opt); ! dhcp_opt_destroy(opt); } --- 47,60 ---- } ! /* clean out dhcp object so it can be reused again. */ ! void dhcp_purge(dhcp_obj * dhcp) { ! dhcp_opt_t *option; ! list_rewind(dhcp->options); ! while((option = list_next(dhcp->options)) != NULL) { ! list_remove_by_datum(dhcp->options, option); ! dhcp_opt_destroy(option); } *************** *** 62,74 **** } - /* clean out dhcp object so it can be reused again. */ - void dhcp_purge(dhcp_obj * dhcp) - { - dhcp_purge_option_list(dhcp->options); - dhcp->options = list_create(); - - return; - } - /* purge and free up dhcp object. */ void dhcp_destroy(dhcp_obj * dhcp) --- 62,65 ---- *************** *** 97,103 **** * dhcp option object. */ option = dhcp_opt_create_from_network(&opt_data[2], opt_data[1], opt_data[0]); - *optlen = opt_data[1]; return option; } --- 88,94 ---- * dhcp option object. */ + *optlen = opt_data[1]; option = dhcp_opt_create_from_network(&opt_data[2], opt_data[1], opt_data[0]); return option; } *************** *** 575,613 **** return len; - } - - /* accept bit array telling us which options to build the request option. */ - dhcp_opt_t *dhcp_build_parameter_request_list_option(uint8_t *requested_options) - { - uint8_t i, j; - uint8_t len = 0; - dhcp_opt_t *option; - uint8_t *opt_request; - - /* Grab length so we can just malloc all at once. */ - for(i = 0; i < MAX_OPTIONS_HANDLED; i++) { - if(requested_options[i]) - len++; - } - - if(len == 0) { - /* no parameter list. return empty list. */ - return NULL; - } - - opt_request = xmalloc(len * sizeof(uint8_t)); - - j = 0; - for(i = 0; i < MAX_OPTIONS_HANDLED; i++) { - if(requested_options[i]) { - opt_request[j] = i; - j++; - } - } - - option = dhcp_opt_create_from_internal_data(TAG_DHCP_PARAMETERS, opt_request, len); - xfree(opt_request); - - return option; } --- 566,569 ---- |
From: <act...@us...> - 2003-05-04 18:51:57
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv10555 Modified Files: dhcp-client-states.c Log Message: client-states brought in line with new dhcp object Index: dhcp-client-states.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-states.c,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** dhcp-client-states.c 25 Mar 2003 20:29:16 -0000 1.26 --- dhcp-client-states.c 4 May 2003 18:51:54 -0000 1.27 *************** *** 32,39 **** #include "dhcp-libutil.h" #include "dhcp-librawnet.h" #include "dhcp-options-strings.h" #include "dhcp-client-conf.h" - #include "dhcp-cache-entry.h" #include "dhcp-client-cache.h" #include "dhcp-client.h" --- 32,39 ---- #include "dhcp-libutil.h" #include "dhcp-librawnet.h" + #include "dhcp-option.h" #include "dhcp-options-strings.h" #include "dhcp-client-conf.h" #include "dhcp-client-cache.h" #include "dhcp-client.h" *************** *** 48,61 **** { list_t *options; ! dhcp_option_t *option; options = list_create(); /* client_id: RFC2131 says we MAY */ ! option = dhcp_build_client_id(dc->client_id, (ETH_ADDR_LEN + 1)); list_add(options, option); /* dhcp message type. */ ! option = dhcp_build_message_type(DHCP_RELEASE_TM); list_add(options, option); --- 48,61 ---- { list_t *options; ! dhcp_opt_t *option; options = list_create(); /* client_id: RFC2131 says we MAY */ ! option = dhcp_opt_create_from_internal_data(TAG_DHCP_CLIENT_ID, dc->client_id, (ETH_ADDR_LEN + 1)); list_add(options, option); /* dhcp message type. */ ! option = dhcp_opt_create_message_type(DHCP_RELEASE_TM); list_add(options, option); *************** *** 68,86 **** { list_t *options; ! dhcp_option_t *option; const char *hostname; options = list_create(); ! /* dhcp max DHCP message size: ! * should go into globconf. */ ! option = dhcp_build_max_message_size_option(MAX_MESSAGE_SIZE); list_add(options, option); /* client_id */ ! option = dhcp_build_client_id(dc->client_id, (ETH_ADDR_LEN + 1)); list_add(options, option); /* class_id */ ! option = dhcp_build_class_id(dc->class_id); list_add(options, option); --- 68,88 ---- { list_t *options; ! dhcp_opt_t *option; ! char *hostname_tmp; const char *hostname; + uint16_t max_message_opt_data = MAX_MESSAGE_SIZE; options = list_create(); ! ! option = dhcp_opt_create_from_internal_data(TAG_DHCP_MAX_DHCP_SIZE, &max_message_opt_data, ! sizeof(max_message_opt_data)); list_add(options, option); /* client_id */ ! option = dhcp_opt_create_from_internal_data(TAG_DHCP_CLIENT_ID, dc->client_id, (ETH_ADDR_LEN + 1)); list_add(options, option); /* class_id */ ! option = dhcp_opt_create_from_internal_data(TAG_DHCP_VENDOR_CLASS_ID, dc->class_id, (strlen(dc->class_id) + 1)); list_add(options, option); *************** *** 89,93 **** if(hostname != NULL) { /* if we have one set it. */ ! option = dhcp_build_hostname(hostname); list_add(options, option); } --- 91,103 ---- if(hostname != NULL) { /* if we have one set it. */ ! ! /* can't pass const char pointer so copy to char pointer. ! * FIXME: audit types and fix any const propogation ! * problems like these properly. */ ! ! hostname_tmp = xstrdup(hostname); ! option = dhcp_opt_create_from_internal_data(TAG_DHCP_HOST_NAME, hostname_tmp, (strlen(hostname_tmp) + 1)); ! xfree(hostname_tmp); ! list_add(options, option); } *************** *** 101,110 **** list_t *options; list_t *requested_options; ! dhcp_option_t *option; options = list_create(); ! option = dhcp_build_parameter_request_list_option(client_conf_get_request_opt_bit_array(dc->conf)); if(option == NULL) { ! WARN_MESSAGE("sending with empty parameter request list"); } else { list_add(options, option); --- 111,121 ---- list_t *options; list_t *requested_options; ! dhcp_opt_t *option; options = list_create(); ! option = dhcp_opt_create_parameter_request_list(client_conf_get_request_opt_bit_array(dc->conf)); ! if(option == NULL) { ! WARN_MESSAGE("sending without parameter request list"); } else { list_add(options, option); *************** *** 112,116 **** /* dhcp message type. */ ! option = dhcp_build_message_type(DHCP_DISCOVER_TM); list_add(options, option); --- 123,127 ---- /* dhcp message type. */ ! option = dhcp_opt_create_message_type(DHCP_DISCOVER_TM); list_add(options, option); *************** *** 126,134 **** list_t *options; list_t *requested_options; ! dhcp_option_t *option; options = list_create(); /* dhcp message type. */ ! option = dhcp_build_message_type(DHCP_REQUEST_TM); list_add(options, option); --- 137,146 ---- list_t *options; list_t *requested_options; ! dhcp_opt_t *option; options = list_create(); + /* dhcp message type. */ ! option = dhcp_opt_create_message_type(DHCP_REQUEST_TM); list_add(options, option); *************** *** 143,155 **** { list_t *options; ! dhcp_option_t *option; options = list_create(); /* dhcp message type. */ ! option = dhcp_build_message_type(DHCP_REQUEST_TM); list_add(options, option); /* client_id */ ! option = dhcp_build_client_id(dc->client_id, (ETH_ADDR_LEN + 1)); list_add(options, option); --- 155,168 ---- { list_t *options; ! dhcp_opt_t *option; options = list_create(); + /* dhcp message type. */ ! option = dhcp_opt_create_message_type(DHCP_REQUEST_TM); list_add(options, option); /* client_id */ ! option = dhcp_opt_create_from_internal_data(TAG_DHCP_CLIENT_ID, dc->client_id, (ETH_ADDR_LEN + 1)); list_add(options, option); *************** *** 164,167 **** --- 177,208 ---- } + /* make a new copy with options which are meant for protocol purposes only. */ + static list_t *client_remove_protocol_only_options(list_t *options) + { + dhcp_opt_t *option, *option_copy; + list_t *non_protocol_opts; + + non_protocol_opts = list_create(); + list_rewind(options); + while((option = list_next(options)) != NULL) { + + switch(dhcp_opt_get_tag(option)) { + + case TAG_DHCP_MAX_DHCP_SIZE: + case TAG_DHCP_MESSAGE_TYPE: + case TAG_DHCP_OVERLOAD: + break; + + default: + option_copy = dhcp_option_copy(option); + list_add(non_protocol_opts, option_copy); + break; + } + } + + return non_protocol_opts; + } + + /****************** * check routines * *************** *** 177,181 **** uint8_t *required_options; uint8_t received_options[MAX_OPTIONS_HANDLED_NUM]; ! dhcp_option_t *dhcp_option; int i; --- 218,222 ---- uint8_t *required_options; uint8_t received_options[MAX_OPTIONS_HANDLED_NUM]; ! dhcp_opt_t *dhcp_option; int i; *************** *** 201,210 **** /* if it's in our range fill it in or ignore it and give a warning. */ ! if(dhcp_option->tag > MAX_OPTIONS_HANDLED) { ! WARN_MESSAGE("ignoring received option tag which is out of our range: %d", dhcp_option->tag); continue; } ! received_options[dhcp_option->tag] = 1; } --- 242,251 ---- /* if it's in our range fill it in or ignore it and give a warning. */ ! if(dhcp_opt_get_tag(dhcp_option) > MAX_OPTIONS_HANDLED) { ! WARN_MESSAGE("ignoring received option tag which is out of our range: %d", dhcp_opt_get_tag(dhcp_option)); continue; } ! received_options[dhcp_opt_get_tag(dhcp_option)] = 1; } *************** *** 325,329 **** list_t *timer_options; ! timer_options = client_cache_load_option_timer_string_list(dc->cache, 0); if(list_get_len(timer_options) == 0) { --- 366,370 ---- list_t *timer_options; ! timer_options = client_cache_load_timer_options(dc->cache, 0); if(list_get_len(timer_options) == 0) { *************** *** 334,338 **** reinitialize_timer(dc->context->timer); do_sysconf(timer_options, dc, 0); ! cache_entry_purge_list(timer_options); return; --- 375,379 ---- reinitialize_timer(dc->context->timer); do_sysconf(timer_options, dc, 0); ! dhcp_opt_destroy_option_list(timer_options); return; *************** *** 416,421 **** int client_discover_offer(dhcp_client_control_t *dc) { ! list_t *options; int retval; INFO_MESSAGE("attempting DHCP DISCOVER"); --- 457,463 ---- int client_discover_offer(dhcp_client_control_t *dc) { ! list_t *options, *dump_options; int retval; + ip_addr_t yiaddr, siaddr; INFO_MESSAGE("attempting DHCP DISCOVER"); *************** *** 470,487 **** * The server may have decided to be nice to us. */ if(!dhcp_have_option(dc->rawnet->dhcp_p, TAG_DHCP_REQUESTED_IP_ADDRESS)) list_add(dc->rawnet->dhcp_p->options, ! dhcp_build_requested_ip_address(dhcp_get_yiaddr(dc->rawnet->dhcp_p))); if(!dhcp_have_option(dc->rawnet->dhcp_p, TAG_DHCP_SERVER_IDENTIFIER)) ! list_add(dc->rawnet->dhcp_p->options, ! dhcp_build_server_identifier(dhcp_get_siaddr(dc->rawnet->dhcp_p))); /* dump cache file. */ ! if(client_cache_dump_options(dc->cache, dc->rawnet->dhcp_p->options)) { ERROR_MESSAGE("could not create temporary cache."); return STATE_FATAL_ERROR; } client_cache_update(dc->cache); --- 512,541 ---- * The server may have decided to be nice to us. */ + yiaddr = dhcp_get_yiaddr(dc->rawnet->dhcp_p); + siaddr = dhcp_get_siaddr(dc->rawnet->dhcp_p); + if(!dhcp_have_option(dc->rawnet->dhcp_p, TAG_DHCP_REQUESTED_IP_ADDRESS)) list_add(dc->rawnet->dhcp_p->options, ! dhcp_opt_create_from_internal_data(TAG_DHCP_REQUESTED_IP_ADDRESS, ! &yiaddr, ! IP_ADDR_LEN)); if(!dhcp_have_option(dc->rawnet->dhcp_p, TAG_DHCP_SERVER_IDENTIFIER)) ! list_add(dc->rawnet->dhcp_p->options, ! dhcp_opt_create_from_internal_data(TAG_DHCP_SERVER_IDENTIFIER, ! &siaddr, ! IP_ADDR_LEN)); ! ! /* before dumping options strip options we never want to dump */ ! ! dump_options = client_remove_protocol_only_options(dc->rawnet->dhcp_p->options); /* dump cache file. */ ! if(client_cache_dump_options(dc->cache, dump_options)) { ERROR_MESSAGE("could not create temporary cache."); return STATE_FATAL_ERROR; } + dhcp_opt_destroy_option_list(dump_options); client_cache_update(dc->cache); *************** *** 500,504 **** options = client_build_request_option_list(dc); ! cache_options = client_cache_load_option_network_list(dc->cache, 0); if(list_get_len(cache_options) == 0) { --- 554,558 ---- options = client_build_request_option_list(dc); ! cache_options = client_cache_load_options(dc->cache, 0); if(list_get_len(cache_options) == 0) { *************** *** 593,597 **** INFO_MESSAGE("performing system configuration"); ! options = client_cache_load_option_string_list(dc->cache, 0); if(list_get_len(options) == 0) { ERROR_MESSAGE("received empty configuration cache! cannot configure host"); --- 647,651 ---- INFO_MESSAGE("performing system configuration"); ! options = client_cache_load_options(dc->cache, 0); if(list_get_len(options) == 0) { ERROR_MESSAGE("received empty configuration cache! cannot configure host"); *************** *** 607,611 **** do_sysconf(options, dc, 1); ! cache_entry_purge_list(options); if(client_broadcast_arp_reply(dc) < 0) { --- 661,665 ---- do_sysconf(options, dc, 1); ! dhcp_opt_destroy_option_list(options); if(client_broadcast_arp_reply(dc) < 0) { *************** *** 706,713 **** /* load what we can from the cache. */ ! cached_options = client_cache_load_option_string_list(dc->cache, 0); do_sysconf_cleanup(cached_options, dc); ! cache_entry_purge_list(cached_options); client_release(dc); --- 760,767 ---- /* load what we can from the cache. */ ! cached_options = client_cache_load_options(dc->cache, 0); do_sysconf_cleanup(cached_options, dc); ! dhcp_opt_destroy_option_list(cached_options); client_release(dc); |
From: <act...@us...> - 2003-05-04 18:51:41
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv10499 Modified Files: dhcp-client-control.c Log Message: client control brought in line with new dhcp object Index: dhcp-client-control.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-control.c,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** dhcp-client-control.c 3 Jan 2003 21:29:22 -0000 1.14 --- dhcp-client-control.c 4 May 2003 18:51:37 -0000 1.15 *************** *** 198,201 **** --- 198,202 ---- #ifdef HAVE_UNAME uname(&utsname); + /* FIXME use stringbuffer to make sure spacing is correct. */ dc->class_id = splice_many_strings(4, utsname.sysname, utsname.nodename, utsname.release, utsname.version, |
From: <act...@us...> - 2003-05-04 18:51:30
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv10429 Modified Files: dhcp-client-conf.c Log Message: client conf brought in line with new dhcp object Index: dhcp-client-conf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-conf.c,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** dhcp-client-conf.c 27 Mar 2003 01:39:16 -0000 1.22 --- dhcp-client-conf.c 4 May 2003 18:51:23 -0000 1.23 *************** *** 29,32 **** --- 29,33 ---- #include "dhcp-libutil.h" #include "dhcp-librawnet.h" + #include "dhcp-option.h" #include "dhcp-conf.h" *************** *** 36,40 **** #include "dhcp-client-cache.h" #include "dhcp-options-strings.h" - #include "dhcp-convert.h" #include "dhcp-client-defaults.h" --- 37,40 ---- *************** *** 478,482 **** case CLIENT_VAR_INTERFACE_MTU: ! uint16_val = string_to_uint16(var_value); if(uint16_val != NULL) { var = dhcp_conf_var_create(var_symbol, uint16_val); --- 478,485 ---- case CLIENT_VAR_INTERFACE_MTU: ! ! uint16_val = xmalloc(sizeof(uint16_t)); ! sscanf(var_value, "%"SCNu16, uint16_val); ! if(uint16_val != NULL) { var = dhcp_conf_var_create(var_symbol, uint16_val); *************** *** 649,655 **** list_destroy(params->variables, dhcp_conf_var_destroy_l); list_destroy(params->lower_params, params_destroy_l); ! list_destroy(params->append_options, cache_entry_destroy_l); ! list_destroy(params->prepend_options, cache_entry_destroy_l); ! list_destroy(params->override_options, cache_entry_destroy_l); xfree(params); --- 652,659 ---- list_destroy(params->variables, dhcp_conf_var_destroy_l); list_destroy(params->lower_params, params_destroy_l); ! ! dhcp_opt_destroy_option_list(params->append_options); ! dhcp_opt_destroy_option_list(params->prepend_options); ! dhcp_opt_destroy_option_list(params->override_options); xfree(params); *************** *** 831,842 **** } ! static int directive_static_cache_entry_handler_proc(client_conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data, ! int var_type) { char *option_name; list_t *option_data_list; ! char *data; ! stringbuffer_t *sb; ! cache_entry_t *ce = NULL; directive_t *directive = directive_data; uint8_t i; --- 835,898 ---- } ! static int directive_user_defined_override(client_conf_params_t *params, const char *option_name, dhcp_opt_t *option) ! { ! if(option == NULL) { ! ERROR_MESSAGE("unknown option %s to override", option_name); ! return 1; ! } ! ! list_add(params->override_options, option); ! return 0; ! } ! ! static int directive_user_defined_append(client_conf_params_t *params, const char *option_name, dhcp_opt_t *option) ! { ! if(option == NULL) { ! ERROR_MESSAGE("unknown option %s to append", option_name); ! return 1; ! } ! ! /* cannot append unless it's a list type. */ ! ! if(dhcp_opt_get_type(option) != DHCP_OPT_LIST) { ! ERROR_MESSAGE("user config attempted to append to: %s", option_name); ! ERROR_MESSAGE("cannot append option which is not a list type"); ! ERROR_MESSAGE("you can only override options which are not lists."); ! ! dhcp_opt_destroy(option); ! return 1; ! } ! ! list_add(params->append_options, option); ! return 0; ! } ! ! static int directive_user_defined_prepend(client_conf_params_t *params, const char *option_name, dhcp_opt_t *option) ! { ! if(option == NULL) { ! ERROR_MESSAGE("unknown option %s to prepend", option_name); ! return 1; ! } ! /* cannot append unless it's a list type. */ ! ! if(dhcp_opt_get_type(option) != DHCP_OPT_LIST) { ! ERROR_MESSAGE("user config attempted to prepend to: %s", option_name); ! ERROR_MESSAGE("cannot prepend option which is not a list type"); ! ERROR_MESSAGE("you can only override options which are not lists."); ! ! dhcp_opt_destroy(option); ! return 1; ! } ! ! list_add(params->prepend_options, option); ! return 0; ! } ! ! static int directive_user_defined_option_handler_proc(client_conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data, ! int var_type) { char *option_name; list_t *option_data_list; ! dhcp_opt_t *option = NULL; directive_t *directive = directive_data; uint8_t i; *************** *** 847,896 **** option_data_list = list_get_by_index(directive->arguments, 2); - for(i = 0; i < MAX_OPTIONS_HANDLED; i++) { if(!strcmp(option_strings[i], option_name)) { ! /* found a match. create cache entry and break out.*/ ! ! /* FIXME: a ";" will wreck havoc on conversion list routines by causing them to split a datum. ! * this a limitation because dhcp-convert.c was never written to take in string form. it was always ! * assumed that this data came in from the network in network form. */ ! ! /* more hackery. there are two versions of ! * options. those with lists and those without. we ! * actually can't tell the difference from here ! * (FIXME: we should) so we check the list length. if ! * it's more than one we append with a semicolon, and ! * loop. otherwise we just pass. */ ! ! if(list_get_len(option_data_list) == 1) { ! ! /* just pass data . */ ! data = list_first(option_data_list); ! ce = create_cache_entry(i, dhcp_option_printable_string_get(i), data); ! break; /* done. */ ! ! } else { ! ! /* create a list out of it just dhcp-convert would. ! * this is too much hackery and needs to go soon. */ ! ! sb = stringbuffer_create(); ! ! while((data = list_next(option_data_list)) != NULL) { ! stringbuffer_aprintf(sb, "%s;", data); ! } ! ! ce = create_cache_entry(i, dhcp_option_printable_string_get(i), xstrdup(stringbuffer_getstring(sb))); ! stringbuffer_destroy(sb); ! ! break; /* done. */ ! } } } ! if(ce == NULL) { ! ERROR_MESSAGE("unknown option %s to append/prepend", option_name); return 1; } --- 903,917 ---- option_data_list = list_get_by_index(directive->arguments, 2); for(i = 0; i < MAX_OPTIONS_HANDLED; i++) { if(!strcmp(option_strings[i], option_name)) { ! option = dhcp_opt_create_from_user_string(i, option_data_list); ! break; } } ! if(i == MAX_OPTIONS_HANDLED) { ! ERROR_MESSAGE("unrecognized dhcp option specified by user config: %s", option_name); return 1; } *************** *** 901,917 **** case CLIENT_VAR_APPEND_OPTIONS: ! list_add(params->append_options, ce); break; ! case CLIENT_VAR_PREPEND_OPTIONS: ! list_add(params->prepend_options, ce); break; ! case CLIENT_VAR_OVERRIDE_OPTIONS: ! list_add(params->override_options, ce); break; default: ! FATAL_MESSAGE("i have encountered a bug. i shouldn't be here."); } --- 922,938 ---- case CLIENT_VAR_APPEND_OPTIONS: ! directive_user_defined_append(params, option_name, option); break; ! case CLIENT_VAR_PREPEND_OPTIONS: ! directive_user_defined_prepend(params, option_name, option); break; ! case CLIENT_VAR_OVERRIDE_OPTIONS: ! directive_user_defined_override(params, option_name, option); break; default: ! FATAL_MESSAGE("illegal append/prepend/override specified. i have encountered a bug. i shouldn't be here."); } *************** *** 921,935 **** static int directive_append_handler(client_conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data) { ! return directive_static_cache_entry_handler_proc(params, directive_data, group_type, group_data, CLIENT_VAR_APPEND_OPTIONS); } static int directive_prepend_handler(client_conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data) { ! return directive_static_cache_entry_handler_proc(params, directive_data, group_type, group_data, CLIENT_VAR_PREPEND_OPTIONS); } static int directive_override_handler(client_conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data) { ! return directive_static_cache_entry_handler_proc(params, directive_data, group_type, group_data, CLIENT_VAR_OVERRIDE_OPTIONS); } --- 942,956 ---- static int directive_append_handler(client_conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data) { ! return directive_user_defined_option_handler_proc(params, directive_data, group_type, group_data, CLIENT_VAR_APPEND_OPTIONS); } static int directive_prepend_handler(client_conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data) { ! return directive_user_defined_option_handler_proc(params, directive_data, group_type, group_data, CLIENT_VAR_PREPEND_OPTIONS); } static int directive_override_handler(client_conf_params_t *params, void *directive_data, directive_group_t group_type, void *group_data) { ! return directive_user_defined_option_handler_proc(params, directive_data, group_type, group_data, CLIENT_VAR_OVERRIDE_OPTIONS); } |
From: <act...@us...> - 2003-05-04 18:50:45
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv10232 Modified Files: dhcp-client-cache.c dhcp-client-cache.h Log Message: new cache code brought in line with new dhcp object Index: dhcp-client-cache.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-cache.c,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** dhcp-client-cache.c 2 May 2003 02:46:59 -0000 1.14 --- dhcp-client-cache.c 4 May 2003 18:50:41 -0000 1.15 *************** *** 157,160 **** --- 157,209 ---- } + /* check if a cache entry is for a timer option. */ + static int is_timer_option(cache_entry_t *ce) + { + if(ce->tag == TAG_DHCP_IP_ADDRESS_LEASE_TIME || + ce->tag == TAG_DHCP_RENEWAL_TIME || + ce->tag == TAG_DHCP_REBINDING_TIME) + return 1; + else + return 0; + } + + /* load cache and optionally run the check routine passed on it. */ + static list_t *client_cache_load_options_proc(client_cache_t *cc, uint8_t use_tmp, + int (*check)(cache_entry_t *ce)) + { + list_t *option_list; + cache_entry_t *ce; + dhcp_opt_t *option; + + if(client_cache_load(cc, use_tmp)) + return NULL; + + /* create the option list. */ + option_list = list_create(); + + /* now convert from cache entry to dhcp option. */ + list_rewind(cc->vars); + while((ce = list_next(cc->vars)) != NULL) { + + /* check if we want it. */ + if((check != NULL && check(ce)) || + (check == NULL)) { + + option = dhcp_opt_create_from_host_string(ce->tag, ce->value); + + if(option == NULL) { + ERROR_MESSAGE("could not convert option %s from cached value: %s", + dhcp_option_printable_string_get(ce->tag), + ce->value); + FATAL_MESSAGE("cache is corrupt! exiting."); + } + + list_add(option_list, option); + } + } + + return option_list; + } + /* * * * * * * * * * * * Cache load/dump * *************** *** 232,239 **** } ! /* dump options into file. here we take data in network form and ! * dump them in serialized form. we always do this to the temp ! * file. the list should contain pointers to dhcp_option_t datums ! * in network byte order. */ int client_cache_dump_options(client_cache_t *cc, list_t *options) --- 281,287 ---- } ! /* dump options into file. here we take data and write it into ! * serialized form. we always do this to the temp file. the list ! * should contain pointers to dhcp_opt_t. */ int client_cache_dump_options(client_cache_t *cc, list_t *options) *************** *** 277,305 **** list_t *client_cache_load_options(client_cache_t *cc, uint8_t use_tmp) { ! list_t *option_list; ! cache_entry_t *ce; ! dhcp_opt_t *option; ! ! if(client_cache_load(cc, use_tmp)) ! return NULL; ! ! /* create the option list. */ ! option_list = list_create(); ! ! /* now convert from cache entry to dhcp option. */ ! list_rewind(cc->vars); ! while((ce = list_next(cc->vars)) != NULL) { ! ! option = dhcp_opt_create_from_host_string(ce->tag, ce->value); ! if(option == NULL) { ! ERROR_MESSAGE("could not convert option %s from cached value: %s", ! dhcp_option_printable_string_get(ce->tag), ! ce->value); ! FATAL_MESSAGE("cache is corrupt! exiting."); ! } ! ! list_add(option_list, option); ! } ! return option_list; } --- 325,333 ---- list_t *client_cache_load_options(client_cache_t *cc, uint8_t use_tmp) { ! return client_cache_load_options_proc(cc, use_tmp, NULL); ! } ! list_t *client_cache_load_timer_options(client_cache_t *cc, uint8_t use_tmp) ! { ! return client_cache_load_options_proc(cc, use_tmp, is_timer_option); } Index: dhcp-client-cache.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-cache.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** dhcp-client-cache.h 2 May 2003 02:46:59 -0000 1.5 --- dhcp-client-cache.h 4 May 2003 18:50:41 -0000 1.6 *************** *** 43,46 **** --- 43,47 ---- extern int client_cache_dump_options(client_cache_t *cc, list_t *options); extern list_t *client_cache_load_options(client_cache_t *cc, uint8_t use_tmp); + extern list_t *client_cache_load_timer_options(client_cache_t *cc, uint8_t use_tmp); #endif /* DHCP_CLIENT_CACHE_H */ |
From: <act...@us...> - 2003-05-04 18:48:53
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv9533 Modified Files: Makefile.am Log Message: new Makefile incorporating new dhcp object changes Index: Makefile.am =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/Makefile.am,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** Makefile.am 28 Apr 2003 22:22:31 -0000 1.16 --- Makefile.am 4 May 2003 18:48:50 -0000 1.17 *************** *** 15,20 **** noinst_HEADERS = dhcp-align.h dhcp-client-cache.h dhcp-client.h dhcp-daemon.h dhcp-interface.h \ dhcp-libutil.h dhcp-local.h dhcp-options-strings.h dhcp-print.h dhcp-cache-entry.h \ ! dhcp-client-conf.h dhcp-convert.h dhcp-librawnet.h dhcp-limits.h dhcp-log.h \ ! dhcp-tokenizer.h dhcp-sysconf.h dhcp-conf.h dhcp-conf-var.h dhcp-option.h dhcp-option-convert.h --- 15,20 ---- noinst_HEADERS = dhcp-align.h dhcp-client-cache.h dhcp-client.h dhcp-daemon.h dhcp-interface.h \ dhcp-libutil.h dhcp-local.h dhcp-options-strings.h dhcp-print.h dhcp-cache-entry.h \ ! dhcp-client-conf.h dhcp-librawnet.h dhcp-limits.h dhcp-log.h dhcp-tokenizer.h \ ! dhcp-sysconf.h dhcp-conf.h dhcp-conf-var.h dhcp-option.h dhcp-option-convert.h *************** *** 46,52 **** dhcp-conf-var.c \ dhcp-option.c \ ! dhcp-option-convert.c \ ! dhcp-convert.c ! dhcp_sniff_SOURCES = dhcp-sniff.c \ --- 46,50 ---- dhcp-conf-var.c \ dhcp-option.c \ ! dhcp-option-convert.c dhcp_sniff_SOURCES = dhcp-sniff.c \ *************** *** 64,68 **** dhcp-sysconf.c ! dhcp_client_LDADD = -ldhcputil dhcp_sniff_LDADD = -ldhcputil --- 62,66 ---- dhcp-sysconf.c ! dhcp_client_LDADD = -ldhcputil -lefence dhcp_sniff_LDADD = -ldhcputil |
From: <act...@us...> - 2003-05-04 18:48:31
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv9406 Removed Files: dhcp-convert.c dhcp-convert.h Log Message: no longer need old conversion routines --- dhcp-convert.c DELETED --- --- dhcp-convert.h DELETED --- |
From: <act...@us...> - 2003-05-02 02:47:04
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv7319 Modified Files: dhcp-client-cache.c dhcp-client-cache.h Log Message: dhcp-client-cache brought in line with new dhcp-option Index: dhcp-client-cache.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-cache.c,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** dhcp-client-cache.c 2 Jan 2003 04:23:01 -0000 1.13 --- dhcp-client-cache.c 2 May 2003 02:46:59 -0000 1.14 *************** *** 1,4 **** /* $Header$ ! * * Copyright 2002 Thamer Alharbash <tm...@wh...> * --- 1,4 ---- /* $Header$ ! * * Copyright 2002 Thamer Alharbash <tm...@wh...> * *************** *** 19,24 **** * Client cache object: * ! * We use this to load cached DHCP options, save them, and conversion with ! * dhcp-convert are done here to network or serialized state. * */ --- 19,23 ---- * Client cache object: * ! * We use this to load cached DHCP options, and save them. * */ *************** *** 30,37 **** #include "dhcp-libutil.h" #include "dhcp-librawnet.h" #include "dhcp-cache-entry.h" #include "dhcp-client-cache.h" - #include "dhcp-convert.h" #include "dhcp-options-strings.h" --- 29,36 ---- #include "dhcp-libutil.h" #include "dhcp-librawnet.h" + #include "dhcp-option.h" #include "dhcp-cache-entry.h" #include "dhcp-client-cache.h" #include "dhcp-options-strings.h" *************** *** 215,219 **** /* load cache */ ! static int client_cache_load(client_cache_t *cc, unsigned char use_tmp) { char *fname; --- 214,218 ---- /* load cache */ ! static int client_cache_load(client_cache_t *cc, uint8_t use_tmp) { char *fname; *************** *** 233,314 **** } - /* * * * * * * * * * * * * * - * Conversion work horses: * - * * * * * * * * * * * * * */ - - /* convert to network. */ - static void *convert_to_network(unsigned char tag, char *string) - { - void *data; - dhcp_option_t *opt; - unsigned char len; - - if(option_convert_handlers[tag].serialize_to_network == NULL) - return NULL; - - data = option_convert_handlers[tag].serialize_to_network(string, &len); - - if(data == NULL) { - WARN_MESSAGE("option: %s may be malformed. I'll ignore and carry on.", - dhcp_option_printable_string_get(tag)); - return NULL; - } - - opt = create_dhcp_option(data, len, tag); - xfree(data); - return opt; - } - - /* convert only timer options to serialized form. */ - static void *convert_timers_to_string(unsigned char tag, char *string) - { - cache_entry_t *ce; - - /* we have three timers we care about */ - if(tag == TAG_DHCP_IP_ADDRESS_LEASE_TIME || - tag == TAG_DHCP_RENEWAL_TIME || tag == TAG_DHCP_REBINDING_TIME) { - - ce = create_cache_entry(tag, dhcp_option_printable_string_get(tag), string); - return ce; - } - - return NULL; - } - - static void *convert_to_cache_entry(unsigned char tag, char *string) - { - cache_entry_t *ce; - - ce = create_cache_entry(tag, dhcp_option_printable_string_get(tag), string); - return ce; - } - - /* - * Convert options from cache serialized form to whatever form convert_func, returns. - * If convert_func is NULL then just return in serialized form (sysconf needs it that way). - * - */ - static list_t *get_cache_options_list_proc(client_cache_t *cc, - void *(*convert_func) (unsigned char tag, char *string)) - { - list_t *options; - cache_entry_t *ce; - void *data; - - options = list_create(); - - list_rewind(cc->vars); - while((ce = list_next(cc->vars)) != NULL) { - - data = convert_func(atoi(ce->name), ce->value); - if(data != NULL) { /* we need to silently ignore nulls here so that the timer only converter works. */ - list_add(options, data); - } - - } - - return options; - } - /* dump options into file. here we take data in network form and * dump them in serialized form. we always do this to the temp --- 232,235 ---- *************** *** 321,326 **** char *name; char *val; ! dhcp_option_t *opt; stringbuffer_t *sb; sb = stringbuffer_create(); --- 242,248 ---- char *name; char *val; ! dhcp_opt_t *opt; stringbuffer_t *sb; + uint8_t tag; sb = stringbuffer_create(); *************** *** 335,356 **** while((opt = list_next(options)) != NULL) { ! /* Run coversion routines to store internally in ! * serialized (string) state. */ ! ! if(option_convert_handlers[opt->tag].serialize == NULL) ! continue; ! ! val = option_convert_handlers[opt->tag].serialize(opt->data, opt->len); ! ! /* ! * the dhcp data object cannot validate ! * at the level we can, so check for a NULL value. ! * ! */ ! ! if(val == NULL) { ! WARN_MESSAGE("option %s appear malformed. skipping.."); ! continue; ! } stringbuffer_clear(sb); --- 257,262 ---- while((opt = list_next(options)) != NULL) { ! tag = dhcp_opt_get_tag(opt); ! val = dhcp_opt_get_internal_string(opt); stringbuffer_clear(sb); *************** *** 359,363 **** stringbuffer_replace(sb, "\"", "\\\""); ! fprintf(fp, "%d=\"%s\" # %s\n", opt->tag, stringbuffer_getstring(sb), dhcp_option_printable_string_get(opt->tag)); xfree(val); } --- 265,270 ---- stringbuffer_replace(sb, "\"", "\\\""); ! fprintf(fp, "%"PRIu8"=\"%s\" # %s\n", tag, ! stringbuffer_getstring(sb), dhcp_option_printable_string_get(tag)); xfree(val); } *************** *** 368,407 **** } ! /* work horse load options and convert routine. */ ! static list_t *client_cache_load_options_list_proc(client_cache_t *cc, unsigned char use_tmp, ! void *(*convert_func) (unsigned char tag, ! char *string)) { ! list_t *options; ! if(client_cache_load(cc, use_tmp) < 0) return NULL; ! options = get_cache_options_list_proc(cc, convert_func); ! client_cache_purge(cc); ! ! return options; ! } ! /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ! * Main conversion interface. These routines will load, convert, * ! * and return the options in whichever format we want. * ! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ ! /* load options and return network list. */ ! list_t *client_cache_load_option_network_list(client_cache_t *cc, unsigned char use_tmp) ! { ! return (client_cache_load_options_list_proc(cc, use_tmp, convert_to_network)); ! } ! /* load options and return serialized list. */ ! list_t *client_cache_load_option_string_list(client_cache_t *cc, unsigned char use_tmp) ! { ! return (client_cache_load_options_list_proc(cc, use_tmp, convert_to_cache_entry)); ! } ! /* load timer options and return them in internal list. */ ! list_t *client_cache_load_option_timer_string_list(client_cache_t *cc, unsigned char use_tmp) ! { ! return (client_cache_load_options_list_proc(cc, use_tmp, convert_timers_to_string)); } --- 275,305 ---- } ! list_t *client_cache_load_options(client_cache_t *cc, uint8_t use_tmp) { ! list_t *option_list; ! cache_entry_t *ce; ! dhcp_opt_t *option; ! if(client_cache_load(cc, use_tmp)) return NULL; ! /* create the option list. */ ! option_list = list_create(); ! /* now convert from cache entry to dhcp option. */ ! list_rewind(cc->vars); ! while((ce = list_next(cc->vars)) != NULL) { ! option = dhcp_opt_create_from_host_string(ce->tag, ce->value); ! if(option == NULL) { ! ERROR_MESSAGE("could not convert option %s from cached value: %s", ! dhcp_option_printable_string_get(ce->tag), ! ce->value); ! FATAL_MESSAGE("cache is corrupt! exiting."); ! } ! list_add(option_list, option); ! } ! return option_list; } Index: dhcp-client-cache.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-cache.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcp-client-cache.h 22 Nov 2002 15:33:26 -0000 1.4 --- dhcp-client-cache.h 2 May 2003 02:46:59 -0000 1.5 *************** *** 42,49 **** extern int client_cache_is_empty(client_cache_t *cc); extern int client_cache_dump_options(client_cache_t *cc, list_t *options); ! extern list_t *client_cache_load_option_network_list(client_cache_t *cc, unsigned char use_tmp); ! extern list_t *client_cache_load_option_string_list(client_cache_t *cc, unsigned char use_tmp); ! extern list_t *client_cache_load_option_timer_string_list(client_cache_t *cc, ! unsigned char use_tmp); #endif /* DHCP_CLIENT_CACHE_H */ --- 42,46 ---- extern int client_cache_is_empty(client_cache_t *cc); extern int client_cache_dump_options(client_cache_t *cc, list_t *options); ! extern list_t *client_cache_load_options(client_cache_t *cc, uint8_t use_tmp); #endif /* DHCP_CLIENT_CACHE_H */ |
From: <act...@us...> - 2003-05-02 02:44:59
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv6648 Modified Files: dhcp-print.h Log Message: fixed up prototyping (was b0rken) Index: dhcp-print.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-print.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcp-print.h 2 May 2003 02:34:42 -0000 1.4 --- dhcp-print.h 2 May 2003 02:44:52 -0000 1.5 *************** *** 37,42 **** /* main printers */ ! extern void print_dhcphdr_brief(dhcp_obj * dhcp); ! extern void print_dhcphdr_verbose(dhcp_obj * dhcp); /* Printing functions. */ --- 37,42 ---- /* main printers */ ! extern void print_dhcp_packet_verbose(rawnet_t *net); ! extern void print_dhcp_packet_brief(rawnet_t *net); /* Printing functions. */ |
From: <act...@us...> - 2003-05-02 02:34:45
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv3575 Modified Files: dhcp-print.c dhcp-print.h Log Message: dhcp-print.c brought inline with new dhcp-option Index: dhcp-print.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-print.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** dhcp-print.c 27 Dec 2002 02:53:45 -0000 1.5 --- dhcp-print.c 2 May 2003 02:34:42 -0000 1.6 *************** *** 31,34 **** --- 31,35 ---- #include "dhcp-libutil.h" #include "dhcp-librawnet.h" + #include "dhcp-option.h" #include "dhcp-print.h" *************** *** 37,43 **** void print_dhcphdr_brief(dhcp_obj * dhcp) { ! unsigned char op; struct in_addr in; ! unsigned char *hw_ptr; int i; --- 38,44 ---- void print_dhcphdr_brief(dhcp_obj * dhcp) { ! uint8_t op; struct in_addr in; ! uint8_t *hw_ptr; int i; *************** *** 153,159 **** { struct in_addr in; ! unsigned char *hw_ptr; int i; ! unsigned char op; printf("----------------------------------DHCP Info--------------------------\n"); --- 154,160 ---- { struct in_addr in; ! uint8_t *hw_ptr; int i; ! uint8_t op; printf("----------------------------------DHCP Info--------------------------\n"); *************** *** 270,274 **** } ! void print_request_options(const unsigned char *data, int len, int printval) { int i; --- 271,275 ---- } ! void print_request_options(const uint8_t *data, int len, int printval) { int i; *************** *** 299,305 **** } ! void print_dhcp_type_message(const unsigned char *data, int len, int printval) { ! unsigned char dhcp_type = *data; if(len != 1) { --- 300,306 ---- } ! void print_dhcp_type_message(const uint8_t *data, int len, int printval) { ! uint8_t dhcp_type = *data; if(len != 1) { *************** *** 347,351 **** /* Just print a 32bit inet address. */ ! static int print_address(const unsigned char *data) { struct in_addr in; --- 348,352 ---- /* Just print a 32bit inet address. */ ! static int print_address(const uint8_t *data) { struct in_addr in; *************** *** 358,362 **** * addresses too. */ ! void print_address_list(const unsigned char *data, int len, int ini_val) { int i, j, line_val; --- 359,363 ---- * addresses too. */ ! void print_address_list(const uint8_t *data, int len, int ini_val) { int i, j, line_val; *************** *** 393,397 **** /* Same as print_address_list only we add a netmask in between. */ ! void print_address_mask_list(const unsigned char *data, int len, int ini_val) { int i, j, line_val; --- 394,398 ---- /* Same as print_address_list only we add a netmask in between. */ ! void print_address_mask_list(const uint8_t *data, int len, int ini_val) { int i, j, line_val; *************** *** 434,438 **** /* Same as print_address_list only we add a route with "->" in between. */ ! void print_address_route_list(const unsigned char *data, int len, int ini_val) { int i, j, line_val; --- 435,439 ---- /* Same as print_address_list only we add a route with "->" in between. */ ! void print_address_route_list(const uint8_t *data, int len, int ini_val) { int i, j, line_val; *************** *** 475,479 **** /* Print a string. */ ! void print_string(const unsigned char *data, int len, int print_val) { char *new_string; --- 476,480 ---- /* Print a string. */ ! void print_string(const uint8_t *data, int len, int print_val) { char *new_string; *************** *** 497,501 **** /* Print a signed 32bit integer. */ ! void print_int32(const unsigned char *data, int len, int print_val) { bpf_int32 val; --- 498,502 ---- /* Print a signed 32bit integer. */ ! void print_int32(const uint8_t *data, int len, int print_val) { bpf_int32 val; *************** *** 515,519 **** /* Print unsigned 32-bit integer. */ ! void print_uint32(const unsigned char *data, int len, int print_val) { uint32_t val; --- 516,520 ---- /* Print unsigned 32-bit integer. */ ! void print_uint32(const uint8_t *data, int len, int print_val) { uint32_t val; *************** *** 533,537 **** /* Print unsigned 16-bit integer. */ ! void print_uint16(const unsigned char *data, int len, int print_val) { uint16_t val; --- 534,538 ---- /* Print unsigned 16-bit integer. */ ! void print_uint16(const uint8_t *data, int len, int print_val) { uint16_t val; *************** *** 551,555 **** /* Print unsigned byte. */ ! void print_ubyte(const unsigned char *data, int len, int print_val) { if(len != 1) { --- 552,556 ---- /* Print unsigned byte. */ ! void print_ubyte(const uint8_t *data, int len, int print_val) { if(len != 1) { *************** *** 562,566 **** } ! void print_uint16_list(const unsigned char *data, int len, int ini_val) { int i, j, line_val; --- 563,567 ---- } ! void print_uint16_list(const uint8_t *data, int len, int ini_val) { int i, j, line_val; *************** *** 598,602 **** /* Print a boolean value as enabled or disabled. */ ! void print_en_bool(const unsigned char *data, int len, int print_val) { --- 599,603 ---- /* Print a boolean value as enabled or disabled. */ ! void print_en_bool(const uint8_t *data, int len, int print_val) { *************** *** 616,620 **** /* Print boolean: "Yes" "No" */ ! void print_yn_bool(const unsigned char *data, int len, int print_val) { --- 617,621 ---- /* Print boolean: "Yes" "No" */ ! void print_yn_bool(const uint8_t *data, int len, int print_val) { *************** *** 634,638 **** /* Print netbios node type. */ ! void print_netbios_node_type(const unsigned char *data, int len, int print_val) { if(len != 1) { --- 635,639 ---- /* Print netbios node type. */ ! void print_netbios_node_type(const uint8_t *data, int len, int print_val) { if(len != 1) { *************** *** 655,659 **** /* Don't handle handler -- the irony... */ ! void dont_handle(const unsigned char *data, int len, int print_val) { printf("<Not handled>"); --- 656,660 ---- /* Don't handle handler -- the irony... */ ! void dont_handle(const uint8_t *data, int len, int print_val) { printf("<Not handled>"); *************** *** 672,677 **** void print_options_verbose(dhcp_obj * dhcp) { ! dhcp_option_t *option; ! unsigned char tag; int print_val; --- 673,678 ---- void print_options_verbose(dhcp_obj * dhcp) { ! dhcp_opt_t *option; ! uint8_t tag; int print_val; *************** *** 683,690 **** * we can assume that the code will always be valid. */ ! tag = option->tag; print_val = printf("%s", option_handlers[tag].prefix); print_val += printf(": "); ! option_handlers[tag].handle_option(option->data, option->len, print_val); printf("\n"); } --- 684,693 ---- * we can assume that the code will always be valid. */ ! tag = dhcp_opt_get_tag(option); print_val = printf("%s", option_handlers[tag].prefix); print_val += printf(": "); ! option_handlers[tag].handle_option(dhcp_opt_get_host_data(option), ! dhcp_opt_get_mem_len(option), ! print_val); printf("\n"); } Index: dhcp-print.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-print.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-print.h 16 Nov 2002 00:23:44 -0000 1.3 --- dhcp-print.h 2 May 2003 02:34:42 -0000 1.4 *************** *** 30,34 **** typedef struct { char *prefix; ! void (*handle_option) (const unsigned char *data, int len, int print_val); } option_handler; --- 30,34 ---- typedef struct { char *prefix; ! void (*handle_option) (const uint8_t *data, int len, int print_val); } option_handler; *************** *** 37,42 **** /* main printers */ ! extern void print_dhcp_packet_verbose(rawnet_t *net); ! extern void print_dhcp_packet_brief(rawnet_t *net); /* Printing functions. */ --- 37,42 ---- /* main printers */ ! extern void print_dhcphdr_brief(dhcp_obj * dhcp); ! extern void print_dhcphdr_verbose(dhcp_obj * dhcp); /* Printing functions. */ *************** *** 56,74 **** /* Print utility functions. */ ! extern void print_dhcp_type_message(const unsigned char *data, int len, int printval); ! extern void print_address_list(const unsigned char *data, int len, int print_val); ! extern void print_int32(const unsigned char *data, int len, int print_val); ! extern void print_string(const unsigned char *data, int len, int print_val); ! extern void print_uint16(const unsigned char *data, int len, int print_val); ! extern void print_en_bool(const unsigned char *data, int len, int print_val); ! extern void print_yn_bool(const unsigned char *data, int len, int print_val); ! extern void print_address_mask_list(const unsigned char *data, int len, int ini_val); ! extern void print_ubyte(const unsigned char *data, int len, int print_val); ! extern void print_uint16_list(const unsigned char *data, int len, int print_val); ! extern void print_uint32(const unsigned char *data, int len, int print_val); ! extern void print_netbios_node_type(const unsigned char *data, int len, int print_val); ! extern void print_address_route_list(const unsigned char *data, int len, int ini_val); ! extern void print_request_options(const unsigned char *data, int len, int printval); ! extern void dont_handle(const unsigned char *data, int len, int print_val); /* in dhcp-sniffer-ohandlers.c */ --- 56,74 ---- /* Print utility functions. */ ! extern void print_dhcp_type_message(const uint8_t *data, int len, int printval); ! extern void print_address_list(const uint8_t *data, int len, int print_val); ! extern void print_int32(const uint8_t *data, int len, int print_val); ! extern void print_string(const uint8_t *data, int len, int print_val); ! extern void print_uint16(const uint8_t *data, int len, int print_val); ! extern void print_en_bool(const uint8_t *data, int len, int print_val); ! extern void print_yn_bool(const uint8_t *data, int len, int print_val); ! extern void print_address_mask_list(const uint8_t *data, int len, int ini_val); ! extern void print_ubyte(const uint8_t *data, int len, int print_val); ! extern void print_uint16_list(const uint8_t *data, int len, int print_val); ! extern void print_uint32(const uint8_t *data, int len, int print_val); ! extern void print_netbios_node_type(const uint8_t *data, int len, int print_val); ! extern void print_address_route_list(const uint8_t *data, int len, int ini_val); ! extern void print_request_options(const uint8_t *data, int len, int printval); ! extern void dont_handle(const uint8_t *data, int len, int print_val); /* in dhcp-sniffer-ohandlers.c */ *************** *** 76,78 **** extern option_handler option_handlers[]; ! #endif --- 76,79 ---- extern option_handler option_handlers[]; ! #endif /* DHCP_PRINT_H */ ! |
From: <act...@us...> - 2003-05-02 02:34:23
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv3469 Modified Files: dhcp-com.c dhcp-librawnet.h Log Message: dhcp-com.c brought inline with new dhcp-option Index: dhcp-com.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-com.c,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** dhcp-com.c 25 Mar 2003 20:27:46 -0000 1.9 --- dhcp-com.c 2 May 2003 02:34:19 -0000 1.10 *************** *** 30,45 **** #include "dhcp-libutil.h" #include "dhcp-librawnet.h" #include "dhcp-align.h" ! static const unsigned char dhcp_magic_cookie[4] = { 99, 130, 83, 99 }; /* create new dhcp object. */ - dhcp_obj *dhcp_create(void) { dhcp_obj *dhcp; ! dhcp = xmalloc(sizeof(dhcp_obj)); dhcp->options = list_create(); --- 30,45 ---- #include "dhcp-libutil.h" #include "dhcp-librawnet.h" + #include "dhcp-option.h" #include "dhcp-align.h" ! static const uint8_t dhcp_magic_cookie[4] = { 99, 130, 83, 99 }; /* create new dhcp object. */ dhcp_obj *dhcp_create(void) { dhcp_obj *dhcp; ! dhcp = xcalloc(sizeof(dhcp_obj)); dhcp->options = list_create(); *************** *** 48,62 **** /* clean out options. */ ! ! void dhcp_purge_option_list(list_t *options) { ! /* Free up options. */ - list_destroy(options, xfree); return; } ! /* Clean out dhcp object so it can be reused again. */ ! void dhcp_purge(dhcp_obj * dhcp) { --- 48,66 ---- /* clean out options. */ ! static void dhcp_purge_option_list(list_t *options) { ! dhcp_opt_t *opt; ! ! list_rewind(options); ! while((opt = list_next(options)) != NULL) { ! ! list_remove_by_datum(options, opt); ! dhcp_opt_destroy(opt); ! } return; } ! /* clean out dhcp object so it can be reused again. */ void dhcp_purge(dhcp_obj * dhcp) { *************** *** 67,100 **** } ! /* Purge and free up dhcp object. */ ! void dhcp_destroy(dhcp_obj * dhcp) { dhcp_purge(dhcp); xfree(dhcp); - return; - } - - /* create option. */ - dhcp_option_t *create_dhcp_option(const unsigned char *opt_data, unsigned char len, - unsigned char tag) - { - dhcp_option_t *option; - - option = xmalloc(sizeof(dhcp_option_t)); - option->tag = tag; - option->len = len; - - option->data = xmalloc(option->len); - memcpy(option->data, opt_data, option->len); - - return option; - } - - /* destroy dhcp option. */ - void destroy_dhcp_option(dhcp_option_t *option) - { - xfree(option->data); - xfree(option); return; --- 71,80 ---- } ! /* purge and free up dhcp object. */ void dhcp_destroy(dhcp_obj * dhcp) { dhcp_purge(dhcp); + list_destroy(dhcp->options, NULL); xfree(dhcp); return; *************** *** 102,112 **** /* copy DHCP option safely. */ ! static dhcp_option_t *process_next_dhcp_option(const unsigned char *opt_data, ! int len, unsigned char *optlen) { ! dhcp_option_t *option; /* Check for malformed option. */ ! if(len < 2 || !dhcp_option_is_valid(opt_data[0], opt_data[1])) return NULL; --- 82,95 ---- /* copy DHCP option safely. */ ! static dhcp_opt_t *process_next_dhcp_option(const uint8_t *opt_data, ! int len, uint8_t *optlen) { ! dhcp_opt_t *option; /* Check for malformed option. */ ! ! if(len < 2 || /* is len smaller than 2? (it can never be) */ ! !dhcp_option_is_valid(opt_data[0], opt_data[1]) /* is the tag and len valid? */ ! || len < opt_data[1]) /* finally is there as much space as is claimed? */ return NULL; *************** *** 114,126 **** * dhcp option object. */ ! option = create_dhcp_option(&opt_data[2], opt_data[1], opt_data[0]); ! *(optlen) = option->len; return option; } ! static void dhcp_read_options_image(dhcp_obj * dhcp, const unsigned char *dhcp_packet, int len) { ! unsigned char optlen; ! dhcp_option_t *option; /* Try and copy all the options. --- 97,110 ---- * dhcp option object. */ ! option = dhcp_opt_create_from_network(&opt_data[2], opt_data[1], opt_data[0]); ! ! *optlen = opt_data[1]; return option; } ! static void dhcp_read_options_image(dhcp_obj * dhcp, const uint8_t *dhcp_packet, int len) { ! uint8_t optlen; ! dhcp_opt_t *option; /* Try and copy all the options. *************** *** 167,171 **** /* read packet image. */ ! int dhcp_read_packet_image(dhcp_obj * dhcp, const unsigned char *dhcp_packet, int len) { /* Get the fixedheader or if not --- 151,155 ---- /* read packet image. */ ! int dhcp_read_packet_image(dhcp_obj * dhcp, const uint8_t *dhcp_packet, int len) { /* Get the fixedheader or if not *************** *** 199,206 **** --- 183,192 ---- /* Now check if we have options overload in file field * and read options as necesssary. */ + if(dhcp_is_file_overload(dhcp)) dhcp_read_options_image(dhcp, dhcp->fixedheader.file, DHCP_FILE_SIZE); /* Ditto on the sname field. */ + if(dhcp_is_sname_overload(dhcp)) dhcp_read_options_image(dhcp, dhcp->fixedheader.sname, DHCP_SNAME_SIZE); *************** *** 218,222 **** /* dhcp op */ ! unsigned char dhcp_get_op(dhcp_obj * dhcp) { return (dhcp->fixedheader.op); --- 204,208 ---- /* dhcp op */ ! uint8_t dhcp_get_op(dhcp_obj * dhcp) { return (dhcp->fixedheader.op); *************** *** 224,228 **** /* dhcp hardware type */ ! unsigned char dhcp_get_htype(dhcp_obj * dhcp) { return (dhcp->fixedheader.htype); --- 210,214 ---- /* dhcp hardware type */ ! uint8_t dhcp_get_htype(dhcp_obj * dhcp) { return (dhcp->fixedheader.htype); *************** *** 230,234 **** /* dhcp hlen type */ ! unsigned char dhcp_get_hlen(dhcp_obj * dhcp) { return (dhcp->fixedheader.hlen); --- 216,220 ---- /* dhcp hlen type */ ! uint8_t dhcp_get_hlen(dhcp_obj * dhcp) { return (dhcp->fixedheader.hlen); *************** *** 236,240 **** /* dhcp hops */ ! unsigned char dhcp_get_hops(dhcp_obj * dhcp) { return (dhcp->fixedheader.hops); --- 222,226 ---- /* dhcp hops */ ! uint8_t dhcp_get_hops(dhcp_obj * dhcp) { return (dhcp->fixedheader.hops); *************** *** 284,288 **** /* dhcp chaddr */ ! unsigned char *dhcp_get_chaddr(dhcp_obj * dhcp) { return (dhcp->fixedheader.chaddr); --- 270,274 ---- /* dhcp chaddr */ ! uint8_t *dhcp_get_chaddr(dhcp_obj * dhcp) { return (dhcp->fixedheader.chaddr); *************** *** 290,294 **** /* dhcp giaddr */ ! unsigned char *dhcp_get_sname(dhcp_obj * dhcp) { return (dhcp->fixedheader.sname); --- 276,280 ---- /* dhcp giaddr */ ! uint8_t *dhcp_get_sname(dhcp_obj * dhcp) { return (dhcp->fixedheader.sname); *************** *** 296,300 **** /* dhcp file */ ! unsigned char *dhcp_get_filename(dhcp_obj * dhcp) { return (dhcp->fixedheader.file); --- 282,286 ---- /* dhcp file */ ! uint8_t *dhcp_get_filename(dhcp_obj * dhcp) { return (dhcp->fixedheader.file); *************** *** 307,310 **** --- 293,435 ---- } + /* DHCP set methods. */ + + /* dhcp op */ + void dhcp_set_op(dhcp_obj * dhcp, uint8_t op) + { + memcpy(&dhcp->fixedheader.op, &op, 1); + } + + /* dhcp hardware type */ + void dhcp_set_htype(dhcp_obj * dhcp, uint8_t htype) + { + memcpy(&dhcp->fixedheader.htype, &htype, 1); + } + + /* dhcp hlen type */ + void dhcp_set_hlen(dhcp_obj * dhcp, uint8_t hlen) + { + memcpy(&dhcp->fixedheader.hlen, &hlen, 1); + } + + /* dhcp hops */ + void dhcp_set_hops(dhcp_obj * dhcp, uint8_t hops) + { + memcpy(&dhcp->fixedheader.hops, &hops, 1); + } + + /* dhcp xid: do conversion */ + void dhcp_set_xid(dhcp_obj * dhcp, uint32_t xid) + { + xid = htonl(xid); + memcpy(&dhcp->fixedheader.xid, &xid, 4); + } + + /* dhcp secs: do conversion. */ + void dhcp_set_secs(dhcp_obj * dhcp, uint16_t secs) + { + secs = ntohs(secs); + memcpy(&dhcp->fixedheader.secs, &secs, 2); + } + + /* dhcp flags: do conversion */ + void dhcp_set_flag_broadcast(dhcp_obj * dhcp) + { + dhcp->fixedheader.flags = htons(DHCP_BROADCAST_FLAG); + return; + } + + /* dhcp flags: do conversion */ + void dhcp_unset_flag_broadcast(dhcp_obj * dhcp) + { + dhcp->fixedheader.flags = 0; + return; + } + + /* dhcp ciaddr: no conversion necessary */ + void dhcp_set_ciaddr(dhcp_obj * dhcp, uint32_t ciaddr) + { + memcpy(&dhcp->fixedheader.ciaddr, &ciaddr, 4); + return; + } + + /* dhcp yiaddr: no conversion necessary */ + void dhcp_set_yiaddr(dhcp_obj * dhcp, uint32_t yiaddr) + { + memcpy(&dhcp->fixedheader.yiaddr, &yiaddr, 4); + return; + } + + /* dhcp siaddr: no conversion necessary */ + void dhcp_set_siaddr(dhcp_obj * dhcp, uint32_t siaddr) + { + memcpy(&dhcp->fixedheader.siaddr, &siaddr, 4); + return; + } + + /* dhcp giaddr: no conversion necessary */ + void dhcp_set_giaddr(dhcp_obj * dhcp, uint32_t giaddr) + { + memcpy(&dhcp->fixedheader.giaddr, &giaddr, 4); + return; + } + + /* dhcp chaddr */ + void dhcp_set_chaddr(dhcp_obj * dhcp, uint8_t *chaddr, int len) + { + memcpy(&dhcp->fixedheader.chaddr, chaddr, len); + } + + /* dhcp chaddr */ + void dhcp_clear_chaddr(dhcp_obj * dhcp) + { + memset(dhcp->fixedheader.chaddr, 0, DHCP_CHADDR_SIZE); + return; + } + + /* dhcp sname */ + void dhcp_set_sname(dhcp_obj * dhcp, uint8_t *sname) + { + memcpy(&dhcp->fixedheader.sname, sname, DHCP_SNAME_SIZE); + return; + } + + /* dhcp file */ + void dhcp_set_filename(dhcp_obj * dhcp, uint8_t *file) + { + memcpy(&dhcp->fixedheader.file, file, DHCP_FILE_SIZE); + return; + } + + /* dhcp sname */ + void dhcp_clear_sname(dhcp_obj * dhcp) + { + memset(&dhcp->fixedheader.sname, 0, DHCP_SNAME_SIZE); + return; + } + + /* dhcp file */ + void dhcp_clear_filename(dhcp_obj * dhcp) + { + memset(&dhcp->fixedheader.file, 0, DHCP_FILE_SIZE); + return; + } + + /* cookie. */ + void dhcp_set_magic_cookie(dhcp_obj * dhcp) + { + memcpy(&dhcp->magic_cookie, dhcp_magic_cookie, 4); + return; + } + + /* dhcp set options, add options. */ + + /* replace options with list passed (convenience). */ + void dhcp_set_options(dhcp_obj * dhcp, list_t *options) + { + dhcp->options = options; + return; + } + /* Options routines. */ *************** *** 318,322 **** /* Return the next option or NULL if at the end. */ ! dhcp_option_t *dhcp_get_next_option(dhcp_obj * dhcp) { return(list_next(dhcp->options)); --- 443,447 ---- /* Return the next option or NULL if at the end. */ ! dhcp_opt_t *dhcp_get_next_option(dhcp_obj * dhcp) { return(list_next(dhcp->options)); *************** *** 337,343 **** /* test for type. */ ! int dhcp_is_type(dhcp_obj * dhcp, unsigned char type) { ! dhcp_option_t *opt; dhcp_reset_option_seek(dhcp); --- 462,469 ---- /* test for type. */ ! int dhcp_is_type(dhcp_obj * dhcp, uint8_t type) { ! dhcp_opt_t *opt; ! uint8_t *message_type; dhcp_reset_option_seek(dhcp); *************** *** 345,356 **** while((opt = dhcp_get_next_option(dhcp)) != NULL) { ! if(opt->tag == TAG_DHCP_MESSAGE_TYPE) { ! if(opt->len != 1) /* let's not get hosed shall we? */ ! continue; ! if(*(opt->data) == type) return 1; ! else ! break; } } --- 471,483 ---- while((opt = dhcp_get_next_option(dhcp)) != NULL) { ! if(dhcp_opt_get_tag(opt) == TAG_DHCP_MESSAGE_TYPE) { ! message_type = dhcp_opt_get_host_data(opt); ! ! if(*message_type == type) { return 1; ! } else { ! return 0; ! } } } *************** *** 360,364 **** /* test for option validity. */ ! int dhcp_option_is_valid(unsigned char tag, unsigned char tag_len) { if(tag_len < 1 || tag > MAX_OPTIONS_HANDLED) --- 487,491 ---- /* test for option validity. */ ! int dhcp_option_is_valid(uint8_t tag, uint8_t tag_len) { if(tag_len < 1 || tag > MAX_OPTIONS_HANDLED) *************** *** 369,375 **** /* test for existance of option. */ ! int dhcp_have_option(dhcp_obj * dhcp, unsigned char tag) { ! dhcp_option_t *option; /* Check for a option by tag. */ --- 496,502 ---- /* test for existance of option. */ ! int dhcp_have_option(dhcp_obj *dhcp, uint8_t tag) { ! dhcp_opt_t *option; /* Check for a option by tag. */ *************** *** 377,381 **** while((option = dhcp_get_next_option(dhcp)) != NULL) { ! if(option->tag == tag) return 1; } --- 504,509 ---- while((option = dhcp_get_next_option(dhcp)) != NULL) { ! ! if(dhcp_opt_get_tag(option) == tag) return 1; } *************** *** 385,397 **** /* get the overload which may be for file, sname, or both. */ ! static unsigned char dhcp_get_overload_option(dhcp_obj * dhcp) { ! dhcp_option_t *option; dhcp_reset_option_seek(dhcp); while((option = dhcp_get_next_option(dhcp)) != NULL) { ! if(option->tag == TAG_DHCP_OVERLOAD) { ! return *(option->data); } } --- 513,526 ---- /* get the overload which may be for file, sname, or both. */ ! static uint8_t dhcp_get_overload_option(dhcp_obj * dhcp) { ! dhcp_opt_t *option; dhcp_reset_option_seek(dhcp); while((option = dhcp_get_next_option(dhcp)) != NULL) { ! ! if(dhcp_opt_get_tag(option) == TAG_DHCP_OVERLOAD) { ! return *(uint8_t *)(dhcp_opt_get_host_data(option)); } } *************** *** 403,407 **** int dhcp_is_file_overload(dhcp_obj * dhcp) { ! unsigned char overload_val = dhcp_get_overload_option(dhcp); if(overload_val == DHCP_OVERLOAD_FILE || overload_val == DHCP_OVERLOAD_BOTH) --- 532,536 ---- int dhcp_is_file_overload(dhcp_obj * dhcp) { ! uint8_t overload_val = dhcp_get_overload_option(dhcp); if(overload_val == DHCP_OVERLOAD_FILE || overload_val == DHCP_OVERLOAD_BOTH) *************** *** 414,418 **** int dhcp_is_sname_overload(dhcp_obj * dhcp) { ! unsigned char overload_val = dhcp_get_overload_option(dhcp); if(overload_val == DHCP_OVERLOAD_SNAME || overload_val == DHCP_OVERLOAD_BOTH) --- 543,547 ---- int dhcp_is_sname_overload(dhcp_obj * dhcp) { ! uint8_t overload_val = dhcp_get_overload_option(dhcp); if(overload_val == DHCP_OVERLOAD_SNAME || overload_val == DHCP_OVERLOAD_BOTH) *************** *** 430,434 **** { uint16_t len = 0; ! dhcp_option_t *opt; int padding; --- 559,563 ---- { uint16_t len = 0; ! dhcp_opt_t *opt; int padding; *************** *** 437,441 **** len += 2; /* for tag and len bytes. */ ! len += opt->len; } --- 566,570 ---- len += 2; /* for tag and len bytes. */ ! len += dhcp_opt_get_total_len(opt); } *************** *** 449,457 **** /* accept bit array telling us which options to build the request option. */ ! dhcp_option_t *dhcp_build_parameter_request_list_option(uint8_t *requested_options) { ! unsigned char i, j; ! unsigned char len = 0; ! dhcp_option_t *option; /* Grab length so we can just malloc all at once. */ --- 578,587 ---- /* accept bit array telling us which options to build the request option. */ ! dhcp_opt_t *dhcp_build_parameter_request_list_option(uint8_t *requested_options) { ! uint8_t i, j; ! uint8_t len = 0; ! dhcp_opt_t *option; ! uint8_t *opt_request; /* Grab length so we can just malloc all at once. */ *************** *** 466,669 **** } ! option = xmalloc(sizeof(dhcp_option_t)); ! option->len = len; ! option->tag = TAG_DHCP_PARAMETERS; ! option->data = xmalloc(len); j = 0; for(i = 0; i < MAX_OPTIONS_HANDLED; i++) { if(requested_options[i]) { ! option->data[j] = i; j++; } } ! return option; ! } ! ! dhcp_option_t *dhcp_build_max_message_size_option(uint16_t max) ! { ! max = htons(max); ! return (create_dhcp_option((unsigned char *)&max, sizeof(uint16_t), TAG_DHCP_MAX_DHCP_SIZE)); ! } ! ! dhcp_option_t *dhcp_build_message_type(unsigned char type) ! { ! return (create_dhcp_option ! ((unsigned char *)&type, sizeof(unsigned char), TAG_DHCP_MESSAGE_TYPE)); ! } ! ! dhcp_option_t *dhcp_build_class_id(unsigned char *class_id) ! { ! unsigned char len = strlen(class_id); ! return (create_dhcp_option(class_id, len, TAG_DHCP_VENDOR_CLASS_ID)); ! } ! ! dhcp_option_t *dhcp_build_client_id(unsigned char *client_id, unsigned char len) ! { ! return (create_dhcp_option(client_id, len, TAG_DHCP_CLIENT_ID)); ! } ! ! dhcp_option_t *dhcp_build_requested_ip_address(uint32_t address) ! { ! return (create_dhcp_option ! ((unsigned char *)&address, IP_ADDR_LEN, TAG_DHCP_REQUESTED_IP_ADDRESS)); ! } ! ! dhcp_option_t *dhcp_build_server_identifier(uint32_t address) ! { ! return (create_dhcp_option((unsigned char *)&address, IP_ADDR_LEN, TAG_DHCP_SERVER_IDENTIFIER)); ! } ! ! dhcp_option_t *dhcp_build_hostname(const char *hostname) ! { ! return (create_dhcp_option ! ((unsigned char *)hostname, (strlen(hostname) + 1), TAG_DHCP_HOST_NAME)); ! } ! ! /* DHCP set methods. */ ! ! /* dhcp op */ ! void dhcp_set_op(dhcp_obj * dhcp, unsigned char op) ! { ! memcpy(&dhcp->fixedheader.op, &op, 1); ! } ! ! /* dhcp hardware type */ ! void dhcp_set_htype(dhcp_obj * dhcp, unsigned char htype) ! { ! memcpy(&dhcp->fixedheader.htype, &htype, 1); ! } ! ! /* dhcp hlen type */ ! void dhcp_set_hlen(dhcp_obj * dhcp, unsigned char hlen) ! { ! memcpy(&dhcp->fixedheader.hlen, &hlen, 1); ! } ! ! /* dhcp hops */ ! void dhcp_set_hops(dhcp_obj * dhcp, unsigned char hops) ! { ! memcpy(&dhcp->fixedheader.hops, &hops, 1); ! } ! ! /* dhcp xid: do conversion */ ! void dhcp_set_xid(dhcp_obj * dhcp, uint32_t xid) ! { ! xid = htonl(xid); ! memcpy(&dhcp->fixedheader.xid, &xid, 4); ! } ! ! /* dhcp secs: do conversion. */ ! void dhcp_set_secs(dhcp_obj * dhcp, uint16_t secs) ! { ! secs = ntohs(secs); ! memcpy(&dhcp->fixedheader.secs, &secs, 2); ! } ! ! /* dhcp flags: do conversion */ ! void dhcp_set_flag_broadcast(dhcp_obj * dhcp) ! { ! dhcp->fixedheader.flags = htons(DHCP_BROADCAST_FLAG); ! return; ! } ! ! /* dhcp flags: do conversion */ ! void dhcp_unset_flag_broadcast(dhcp_obj * dhcp) ! { ! dhcp->fixedheader.flags = 0; ! return; ! } ! ! /* dhcp ciaddr: no conversion necessary */ ! void dhcp_set_ciaddr(dhcp_obj * dhcp, uint32_t ciaddr) ! { ! memcpy(&dhcp->fixedheader.ciaddr, &ciaddr, 4); ! return; ! } ! ! /* dhcp yiaddr: no conversion necessary */ ! void dhcp_set_yiaddr(dhcp_obj * dhcp, uint32_t yiaddr) ! { ! memcpy(&dhcp->fixedheader.yiaddr, &yiaddr, 4); ! return; ! } ! ! /* dhcp siaddr: no conversion necessary */ ! void dhcp_set_siaddr(dhcp_obj * dhcp, uint32_t siaddr) ! { ! memcpy(&dhcp->fixedheader.siaddr, &siaddr, 4); ! return; ! } ! ! /* dhcp giaddr: no conversion necessary */ ! void dhcp_set_giaddr(dhcp_obj * dhcp, uint32_t giaddr) ! { ! memcpy(&dhcp->fixedheader.giaddr, &giaddr, 4); ! return; ! } ! ! /* dhcp chaddr */ ! void dhcp_set_chaddr(dhcp_obj * dhcp, unsigned char *chaddr, int len) ! { ! memcpy(&dhcp->fixedheader.chaddr, chaddr, len); ! } ! ! /* dhcp chaddr */ ! void dhcp_clear_chaddr(dhcp_obj * dhcp) ! { ! memset(dhcp->fixedheader.chaddr, 0, DHCP_CHADDR_SIZE); ! return; ! } ! ! /* dhcp sname */ ! void dhcp_set_sname(dhcp_obj * dhcp, unsigned char *sname) ! { ! memcpy(&dhcp->fixedheader.sname, sname, DHCP_SNAME_SIZE); ! return; ! } ! ! /* dhcp file */ ! void dhcp_set_filename(dhcp_obj * dhcp, unsigned char *file) ! { ! memcpy(&dhcp->fixedheader.file, file, DHCP_FILE_SIZE); ! return; ! } ! ! /* dhcp sname */ ! void dhcp_clear_sname(dhcp_obj * dhcp) ! { ! memset(&dhcp->fixedheader.sname, 0, DHCP_SNAME_SIZE); ! return; ! } ! ! /* dhcp file */ ! void dhcp_clear_filename(dhcp_obj * dhcp) ! { ! memset(&dhcp->fixedheader.file, 0, DHCP_FILE_SIZE); ! return; ! } ! ! /* cookie. */ ! void dhcp_set_magic_cookie(dhcp_obj * dhcp) ! { ! memcpy(&dhcp->magic_cookie, dhcp_magic_cookie, 4); ! return; ! } ! ! /* dhcp set options, add options. */ ! /* replace options with list passed (convenience). */ ! void dhcp_set_options(dhcp_obj * dhcp, list_t *options) ! { ! dhcp->options = options; ! return; } /* write options to packet pointer. */ ! void dhcp_write_options(dhcp_obj * dhcp, unsigned char *packet) { ! dhcp_option_t *option; ! int padding, len = 0; dhcp_reset_option_seek(dhcp); --- 596,622 ---- } ! opt_request = xmalloc(len * sizeof(uint8_t)); j = 0; for(i = 0; i < MAX_OPTIONS_HANDLED; i++) { if(requested_options[i]) { ! opt_request[j] = i; j++; } } ! option = dhcp_opt_create_from_internal_data(TAG_DHCP_PARAMETERS, opt_request, len); ! xfree(opt_request); ! return option; } /* write options to packet pointer. */ ! void dhcp_write_options(dhcp_obj * dhcp, uint8_t *packet) { ! dhcp_opt_t *option; ! size_t len = 0; ! size_t padding; ! uint8_t *network_data; dhcp_reset_option_seek(dhcp); *************** *** 671,686 **** while((option = dhcp_get_next_option(dhcp)) != NULL) { ! *packet = option->tag; packet += 1; len++; ! *packet = option->len; packet += 1; len++; ! memcpy(packet, option->data, option->len); ! packet += option->len; ! len += option->len; } --- 624,641 ---- while((option = dhcp_get_next_option(dhcp)) != NULL) { ! *packet = dhcp_opt_get_tag(option); packet += 1; len++; ! *packet = dhcp_opt_get_total_len(option); packet += 1; len++; ! network_data = dhcp_opt_get_network_data(option); ! memcpy(packet, network_data, dhcp_opt_get_total_len(option)); ! xfree(network_data); + packet += dhcp_opt_get_total_len(option); + len += dhcp_opt_get_total_len(option); } *************** *** 702,706 **** /* write dhcp image out to packet. */ ! void dhcp_write_packet_image(dhcp_obj * dhcp, unsigned char *packet) { /* Dump fixed header first. */ --- 657,661 ---- /* write dhcp image out to packet. */ ! void dhcp_write_packet_image(dhcp_obj * dhcp, uint8_t *packet) { /* Dump fixed header first. */ Index: dhcp-librawnet.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-librawnet.h,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** dhcp-librawnet.h 3 Jan 2003 21:29:22 -0000 1.10 --- dhcp-librawnet.h 2 May 2003 02:34:19 -0000 1.11 *************** *** 26,29 **** --- 26,52 ---- #define DHCP_LIBRAWNET_H + /* type definitions. */ + + typedef uint8_t dhcp_opt_tag_t; + typedef uint8_t dhcp_opt_len_t; + typedef uint16_t dhcp_opt_type_t; + typedef uint16_t dhcp_opt_val_type_t; + + /* forward declare dhcp_opt to typedef function pointers below. */ + struct dhcp_opt; + + /* typedef of dhcp option function pointers. */ + + /* converters from external data to internal */ + typedef int (*dhcp_opt_from_string)(struct dhcp_opt *opt, const char *input); + typedef int (*dhcp_opt_from_user_string)(struct dhcp_opt *opt, list_t *input_list); + typedef int (*dhcp_opt_from_network)(struct dhcp_opt *opt, const uint8_t *data, size_t len); + + /* converts from internal data to other data formats. */ + typedef void *(*dhcp_opt_to_network_data)(struct dhcp_opt *opt); + typedef void *(*dhcp_opt_to_host_data)(struct dhcp_opt *opt); + typedef char *(*dhcp_opt_to_user_string)(struct dhcp_opt *opt); + typedef char *(*dhcp_opt_to_string)(struct dhcp_opt *opt); + /* data structures. */ *************** *** 68,78 **** } dhcphdr; ! /* dhcp option structure for internal ! * dhcp object representation. */ ! typedef struct { ! unsigned char tag; ! unsigned char len; ! unsigned char *data; ! } dhcp_option_t; /* DHCP object * --- 91,126 ---- } dhcphdr; ! /* the data destructor. */ ! typedef void (*dhcp_opt_data_destroy)(struct dhcp_opt *opt); ! ! typedef struct dhcp_opt_attr { ! ! dhcp_opt_tag_t tag; /* tag */ ! dhcp_opt_len_t len; /* member length in octets */ ! dhcp_opt_val_type_t type; /* type of opt */ ! dhcp_opt_val_type_t val_type; /* type of val */ ! ! /* data extraction routines. */ ! dhcp_opt_to_network_data to_network_data; /* to network data representation. */ ! dhcp_opt_to_user_string to_user_string; /* to user string representation. */ ! dhcp_opt_to_string to_internal_string; /* to internal string representation. */ ! ! /* data creation routines. */ ! dhcp_opt_from_network from_network; /* network data to internal. */ ! dhcp_opt_from_user_string from_user_string; /* user string to internal. */ ! dhcp_opt_from_string from_internal_string; /* string to internal. */ ! ! dhcp_opt_data_destroy destroy; /* destroy option datum. */ ! ! } dhcp_opt_attr_t; ! ! /* the dhcp option object. */ ! ! typedef struct dhcp_opt { ! void *val; /* value */ ! size_t num; /* num */ ! dhcp_opt_attr_t *opt_attr; /* attributes */ ! } dhcp_opt_t; ! /* DHCP object * *************** *** 376,388 **** extern dhcp_obj *dhcp_create(void); extern void dhcp_purge(dhcp_obj * dhcp); - extern void dhcp_purge_option_list(list_t *options); /* only use on network list. */ extern void dhcp_destroy(dhcp_obj * dhcp); - extern int dhcp_read_packet_image(dhcp_obj * dhcp, const unsigned char *dhcp_packet, int len); - extern void dhcp_write_packet_image(dhcp_obj * dhcp, unsigned char *packet); ! extern unsigned char dhcp_get_op(dhcp_obj * dhcp); ! extern unsigned char dhcp_get_hlen(dhcp_obj * dhcp); ! extern unsigned char dhcp_get_htype(dhcp_obj * dhcp); ! extern unsigned char dhcp_get_hops(dhcp_obj * dhcp); extern uint32_t dhcp_get_xid(dhcp_obj * dhcp); extern uint16_t dhcp_get_secs(dhcp_obj * dhcp); --- 424,433 ---- extern dhcp_obj *dhcp_create(void); extern void dhcp_purge(dhcp_obj * dhcp); extern void dhcp_destroy(dhcp_obj * dhcp); ! extern uint8_t dhcp_get_op(dhcp_obj * dhcp); ! extern uint8_t dhcp_get_htype(dhcp_obj * dhcp); ! extern uint8_t dhcp_get_hlen(dhcp_obj * dhcp); ! extern uint8_t dhcp_get_hops(dhcp_obj * dhcp); extern uint32_t dhcp_get_xid(dhcp_obj * dhcp); extern uint16_t dhcp_get_secs(dhcp_obj * dhcp); *************** *** 392,404 **** extern uint32_t dhcp_get_siaddr(dhcp_obj * dhcp); extern uint32_t dhcp_get_giaddr(dhcp_obj * dhcp); ! extern unsigned char *dhcp_get_chaddr(dhcp_obj * dhcp); ! extern unsigned char *dhcp_get_sname(dhcp_obj * dhcp); ! extern unsigned char *dhcp_get_filename(dhcp_obj * dhcp); extern uint32_t dhcp_get_magic_cookie(dhcp_obj * dhcp); ! extern void dhcp_set_op(dhcp_obj * dhcp, unsigned char op); ! extern void dhcp_set_htype(dhcp_obj * dhcp, unsigned char htype); ! extern void dhcp_set_hlen(dhcp_obj * dhcp, unsigned char hlen); ! extern void dhcp_set_hops(dhcp_obj * dhcp, unsigned char hops); extern void dhcp_set_xid(dhcp_obj * dhcp, uint32_t xid); extern void dhcp_set_secs(dhcp_obj * dhcp, uint16_t secs); --- 437,449 ---- extern uint32_t dhcp_get_siaddr(dhcp_obj * dhcp); extern uint32_t dhcp_get_giaddr(dhcp_obj * dhcp); ! extern uint8_t *dhcp_get_chaddr(dhcp_obj * dhcp); ! extern uint8_t *dhcp_get_sname(dhcp_obj * dhcp); ! extern uint8_t *dhcp_get_filename(dhcp_obj * dhcp); extern uint32_t dhcp_get_magic_cookie(dhcp_obj * dhcp); ! extern void dhcp_set_op(dhcp_obj * dhcp, uint8_t op); ! extern void dhcp_set_htype(dhcp_obj * dhcp, uint8_t htype); ! extern void dhcp_set_hlen(dhcp_obj * dhcp, uint8_t hlen); ! extern void dhcp_set_hops(dhcp_obj * dhcp, uint8_t hops); extern void dhcp_set_xid(dhcp_obj * dhcp, uint32_t xid); extern void dhcp_set_secs(dhcp_obj * dhcp, uint16_t secs); *************** *** 409,444 **** extern void dhcp_set_siaddr(dhcp_obj * dhcp, uint32_t siaddr); extern void dhcp_set_giaddr(dhcp_obj * dhcp, uint32_t giaddr); ! extern void dhcp_set_sname(dhcp_obj * dhcp, unsigned char *sname); ! extern void dhcp_set_filename(dhcp_obj * dhcp, unsigned char *file); ! extern void dhcp_set_magic_cookie(dhcp_obj * dhcp); ! extern void dhcp_set_options(dhcp_obj * dhcp, list_t *options); ! extern void dhcp_set_chaddr(dhcp_obj * dhcp, unsigned char *chaddr, int len); ! extern void dhcp_clear_sname(dhcp_obj * dhcp); extern void dhcp_clear_filename(dhcp_obj * dhcp); ! extern void dhcp_clear_chaddr(dhcp_obj * dhcp); extern void dhcp_reset_option_seek(dhcp_obj * dhcp); ! extern dhcp_option_t *dhcp_get_next_option(dhcp_obj * dhcp); ! extern dhcp_option_t *create_dhcp_option(const unsigned char *opt_data, ! unsigned char len, unsigned char tag); ! extern void destroy_dhcp_option(dhcp_option_t *option); extern uint16_t dhcp_get_options_len(list_t *options); extern int dhcp_valid_magic_cookie(dhcp_obj * dhcp); ! extern int dhcp_is_type(dhcp_obj * dhcp, unsigned char type); ! extern int dhcp_option_is_valid(unsigned char tag, unsigned char tag_len); ! extern int dhcp_have_option(dhcp_obj * dhcp, unsigned char tag); extern int dhcp_is_file_overload(dhcp_obj * dhcp); extern int dhcp_is_sname_overload(dhcp_obj * dhcp); - extern uint32_t dhcp_gen_xid(void); ! extern dhcp_option_t *dhcp_build_parameter_request_list_option(uint8_t *requested_options); ! extern dhcp_option_t *dhcp_build_max_message_size_option(uint16_t max); ! extern dhcp_option_t *dhcp_build_message_type(unsigned char type); ! extern dhcp_option_t *dhcp_build_class_id(unsigned char *class_id); ! extern dhcp_option_t *dhcp_build_client_id(unsigned char *client_id, unsigned char len); ! extern dhcp_option_t *dhcp_build_requested_ip_address(uint32_t address); ! extern dhcp_option_t *dhcp_build_server_identifier(uint32_t address); ! extern dhcp_option_t *dhcp_build_hostname(const char *hostname); /* Ether obj routines. */ --- 454,485 ---- extern void dhcp_set_siaddr(dhcp_obj * dhcp, uint32_t siaddr); extern void dhcp_set_giaddr(dhcp_obj * dhcp, uint32_t giaddr); ! extern void dhcp_set_chaddr(dhcp_obj * dhcp, uint8_t *chaddr, int len); ! extern void dhcp_clear_chaddr(dhcp_obj * dhcp); ! extern void dhcp_set_sname(dhcp_obj * dhcp, uint8_t *sname); ! extern void dhcp_set_filename(dhcp_obj * dhcp, uint8_t *file); extern void dhcp_clear_sname(dhcp_obj * dhcp); extern void dhcp_clear_filename(dhcp_obj * dhcp); ! extern void dhcp_set_magic_cookie(dhcp_obj * dhcp); ! extern void dhcp_set_options(dhcp_obj * dhcp, list_t *options); extern void dhcp_reset_option_seek(dhcp_obj * dhcp); ! extern dhcp_opt_t *dhcp_get_next_option(dhcp_obj * dhcp); ! extern uint16_t dhcp_get_options_len(list_t *options); + extern int dhcp_valid_magic_cookie(dhcp_obj * dhcp); ! extern int dhcp_is_type(dhcp_obj * dhcp, uint8_t type); ! extern int dhcp_option_is_valid(uint8_t tag, uint8_t tag_len); ! extern int dhcp_have_option(dhcp_obj *dhcp, uint8_t tag); extern int dhcp_is_file_overload(dhcp_obj * dhcp); extern int dhcp_is_sname_overload(dhcp_obj * dhcp); ! extern dhcp_opt_t *dhcp_build_parameter_request_list_option(uint8_t *requested_options); ! ! extern int dhcp_read_packet_image(dhcp_obj * dhcp, const uint8_t *dhcp_packet, int len); ! extern void dhcp_write_options(dhcp_obj * dhcp, uint8_t *packet); ! extern void dhcp_write_packet_image(dhcp_obj * dhcp, uint8_t *packet); ! ! extern uint32_t dhcp_gen_xid(void); /* Ether obj routines. */ |
From: <act...@us...> - 2003-04-28 22:23:09
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv19881 Added Files: dhcp-option-convert.c dhcp-option-convert.h Log Message: new conversion routines for new dhcp option object --- NEW FILE: dhcp-option-convert.c --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-option-convert.c,v 1.1 2003/04/28 22:23:06 actmodern Exp $ * * Copyright 2002, 2003 Thamer Alharbash <tm...@wh...> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. The names of the authors may not be used to endorse or promote * products derived from this software without specific prior * written permission. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR [...2239 lines suppressed...] char *dhcp_opt_to_internal_string_list_ip_addr(dhcp_opt_t *opt) { return ip_addr_list_to_internal_string(opt->val); } char *dhcp_opt_to_internal_string_list_ip_addr_pair(dhcp_opt_t *opt) { return ip_addr_list_to_internal_string(opt->val); } char *dhcp_opt_to_internal_string_nvt_string(dhcp_opt_t *opt) { return xstrdup((char *)opt->val); } char *dhcp_opt_to_internal_string_string(dhcp_opt_t *opt) { return xstrdup((char *)opt->val); } --- NEW FILE: dhcp-option-convert.h --- #ifndef DHCP_OPTION_CONVERT_H #define DHCP_OPTION_CONVERT_H /* dhcp option conversion routines. */ /* from network data host data. */ extern int dhcp_opt_from_network_uint8(dhcp_opt_t *opt, const uint8_t *data, size_t len); extern int dhcp_opt_from_network_uint16(dhcp_opt_t *opt, const uint8_t *data, size_t len); extern int dhcp_opt_from_network_uint32(dhcp_opt_t *opt, const uint8_t *data, size_t len); extern int dhcp_opt_from_network_int8(dhcp_opt_t *opt, const uint8_t *data, size_t len); extern int dhcp_opt_from_network_int16(dhcp_opt_t *opt, const uint8_t *data, size_t len); extern int dhcp_opt_from_network_int32(dhcp_opt_t *opt, const uint8_t *data, size_t len); extern int dhcp_opt_from_network_list_uint8(dhcp_opt_t *opt, const uint8_t *data, size_t len); extern int dhcp_opt_from_network_list_uint16(dhcp_opt_t *opt, const uint8_t *data, size_t len); extern int dhcp_opt_from_network_list_uint32(dhcp_opt_t *opt, const uint8_t *data, size_t len); extern int dhcp_opt_from_network_list_int8(dhcp_opt_t *opt, const uint8_t *data, size_t len); extern int dhcp_opt_from_network_list_int16(dhcp_opt_t *opt, const uint8_t *data, size_t len); extern int dhcp_opt_from_network_list_int32(dhcp_opt_t *opt, const uint8_t *data, size_t len); extern int dhcp_opt_from_network_array_uint8(dhcp_opt_t *opt, const uint8_t *data, size_t len); extern int dhcp_opt_from_network_array_uint16(dhcp_opt_t *opt, const uint8_t *data, size_t len); extern int dhcp_opt_from_network_array_uint32(dhcp_opt_t *opt, const uint8_t *data, size_t len); extern int dhcp_opt_from_network_array_int8(dhcp_opt_t *opt, const uint8_t *data, size_t len); extern int dhcp_opt_from_network_array_int16(dhcp_opt_t *opt, const uint8_t *data, size_t len); extern int dhcp_opt_from_network_array_int32(dhcp_opt_t *opt, const uint8_t *data, size_t len); extern int dhcp_opt_from_network_ip_addr(dhcp_opt_t *opt, const uint8_t *data, size_t len); extern int dhcp_opt_from_network_ip_addr_pair(dhcp_opt_t *opt, const uint8_t *data, size_t len); extern int dhcp_opt_from_network_list_ip_addr(dhcp_opt_t *opt, const uint8_t *data, size_t len); extern int dhcp_opt_from_network_list_ip_addr_pair(dhcp_opt_t *opt, const uint8_t *data, size_t len); extern int dhcp_opt_from_network_nvt_string(dhcp_opt_t *opt, const uint8_t *data, size_t len); extern int dhcp_opt_from_network_string(dhcp_opt_t *opt, const uint8_t *data, size_t len); /* from internal string to host data. */ extern int dhcp_opt_from_internal_string_uint8(dhcp_opt_t *opt, const char *input); extern int dhcp_opt_from_internal_string_uint16(dhcp_opt_t *opt, const char *input); extern int dhcp_opt_from_internal_string_uint32(dhcp_opt_t *opt, const char *input); extern int dhcp_opt_from_internal_string_int8(dhcp_opt_t *opt, const char *input); extern int dhcp_opt_from_internal_string_int16(dhcp_opt_t *opt, const char *input); extern int dhcp_opt_from_internal_string_int32(dhcp_opt_t *opt, const char *input); extern int dhcp_opt_from_internal_string_list_uint8(dhcp_opt_t *opt, const char *input); extern int dhcp_opt_from_internal_string_list_uint16(dhcp_opt_t *opt, const char *input); extern int dhcp_opt_from_internal_string_list_uint32(dhcp_opt_t *opt, const char *input); extern int dhcp_opt_from_internal_string_list_int8(dhcp_opt_t *opt, const char *input); extern int dhcp_opt_from_internal_string_list_int16(dhcp_opt_t *opt, const char *input); extern int dhcp_opt_from_internal_string_list_int32(dhcp_opt_t *opt, const char *input); extern int dhcp_opt_from_internal_string_array_uint8(dhcp_opt_t *opt, const char *input); extern int dhcp_opt_from_internal_string_array_uint16(dhcp_opt_t *opt, const char *input); extern int dhcp_opt_from_internal_string_array_uint32(dhcp_opt_t *opt, const char *input); extern int dhcp_opt_from_internal_string_array_int8(dhcp_opt_t *opt, const char *input); extern int dhcp_opt_from_internal_string_array_int16(dhcp_opt_t *opt, const char *input); extern int dhcp_opt_from_internal_string_array_int32(dhcp_opt_t *opt, const char *input); extern int dhcp_opt_from_internal_string_ip_addr(dhcp_opt_t *opt, const char *input); extern int dhcp_opt_from_internal_string_ip_addr_pair(dhcp_opt_t *opt, const char *input); extern int dhcp_opt_from_internal_string_list_ip_addr(dhcp_opt_t *opt, const char *input); extern int dhcp_opt_from_internal_string_list_ip_addr_pair(dhcp_opt_t *opt, const char *input); extern int dhcp_opt_from_internal_string_nvt_string(dhcp_opt_t *opt, const char *input); extern int dhcp_opt_from_internal_string_string(dhcp_opt_t *opt, const char *input); /* from user string to host data */ extern int dhcp_opt_from_user_string_uint8(dhcp_opt_t *opt, list_t *input_list); extern int dhcp_opt_from_user_string_uint16(dhcp_opt_t *opt, list_t *input_list); extern int dhcp_opt_from_user_string_uint32(dhcp_opt_t *opt, list_t *input_list); extern int dhcp_opt_from_user_string_int8(dhcp_opt_t *opt, list_t *input_list); extern int dhcp_opt_from_user_string_int16(dhcp_opt_t *opt, list_t *input_list); extern int dhcp_opt_from_user_string_int32(dhcp_opt_t *opt, list_t *input_list); extern int dhcp_opt_from_user_string_list_uint8(dhcp_opt_t *opt, list_t *input_list); extern int dhcp_opt_from_user_string_list_uint16(dhcp_opt_t *opt, list_t *input_list); extern int dhcp_opt_from_user_string_list_uint32(dhcp_opt_t *opt, list_t *input_list); extern int dhcp_opt_from_user_string_list_int8(dhcp_opt_t *opt, list_t *input_list); extern int dhcp_opt_from_user_string_list_int16(dhcp_opt_t *opt, list_t *input_list); extern int dhcp_opt_from_user_string_list_int32(dhcp_opt_t *opt, list_t *input_list); extern int dhcp_opt_from_user_string_array_uint8(dhcp_opt_t *opt, list_t *input_list); extern int dhcp_opt_from_user_string_array_uint16(dhcp_opt_t *opt, list_t *input_list); extern int dhcp_opt_from_user_string_array_uint32(dhcp_opt_t *opt, list_t *input_list); extern int dhcp_opt_from_user_string_array_int8(dhcp_opt_t *opt, list_t *input_list); extern int dhcp_opt_from_user_string_array_int16(dhcp_opt_t *opt, list_t *input_list); extern int dhcp_opt_from_user_string_array_int32(dhcp_opt_t *opt, list_t *input_list); extern int dhcp_opt_from_user_string_ip_addr(dhcp_opt_t *opt, list_t *input_list); extern int dhcp_opt_from_user_string_ip_addr_pair(dhcp_opt_t *opt, list_t *input_list); extern int dhcp_opt_from_user_string_list_ip_addr(dhcp_opt_t *opt, list_t *input_list); extern int dhcp_opt_from_user_string_list_ip_addr_pair(dhcp_opt_t *opt, list_t *input_list); extern int dhcp_opt_from_user_string_nvt_string(dhcp_opt_t *opt, list_t *input_list); extern int dhcp_opt_from_user_string_string(dhcp_opt_t *opt, list_t *input_list); /* to network data. */ extern void *dhcp_opt_to_network_uint8(dhcp_opt_t *opt); extern void *dhcp_opt_to_network_uint16(dhcp_opt_t *opt); extern void *dhcp_opt_to_network_uint32(dhcp_opt_t *opt); extern void *dhcp_opt_to_network_int8(dhcp_opt_t *opt); extern void *dhcp_opt_to_network_int16(dhcp_opt_t *opt); extern void *dhcp_opt_to_network_int32(dhcp_opt_t *opt); extern void *dhcp_opt_to_network_list_uint8(dhcp_opt_t *opt); extern void *dhcp_opt_to_network_list_uint16(dhcp_opt_t *opt); extern void *dhcp_opt_to_network_list_uint32(dhcp_opt_t *opt); extern void *dhcp_opt_to_network_list_int8(dhcp_opt_t *opt); extern void *dhcp_opt_to_network_list_int16(dhcp_opt_t *opt); extern void *dhcp_opt_to_network_list_int32(dhcp_opt_t *opt); extern void *dhcp_opt_to_network_array_uint8(dhcp_opt_t *opt); extern void *dhcp_opt_to_network_array_uint16(dhcp_opt_t *opt); extern void *dhcp_opt_to_network_array_uint32(dhcp_opt_t *opt); extern void *dhcp_opt_to_network_array_int8(dhcp_opt_t *opt); extern void *dhcp_opt_to_network_array_int16(dhcp_opt_t *opt); extern void *dhcp_opt_to_network_array_int32(dhcp_opt_t *opt); extern void *dhcp_opt_to_network_ip_addr(dhcp_opt_t *opt); extern void *dhcp_opt_to_network_ip_addr_pair(dhcp_opt_t *opt); extern void *dhcp_opt_to_network_list_ip_addr(dhcp_opt_t *opt); extern void *dhcp_opt_to_network_list_ip_addr_pair(dhcp_opt_t *opt); extern void *dhcp_opt_to_network_nvt_string(dhcp_opt_t *opt); extern void *dhcp_opt_to_network_string(dhcp_opt_t *opt); /* to user string. */ extern char *dhcp_opt_to_user_string_uint8(dhcp_opt_t *opt); extern char *dhcp_opt_to_user_string_uint16(dhcp_opt_t *opt); extern char *dhcp_opt_to_user_string_uint32(dhcp_opt_t *opt); extern char *dhcp_opt_to_user_string_int8(dhcp_opt_t *opt); extern char *dhcp_opt_to_user_string_int16(dhcp_opt_t *opt); extern char *dhcp_opt_to_user_string_int32(dhcp_opt_t *opt); extern char *dhcp_opt_to_user_string_list_uint8(dhcp_opt_t *opt); extern char *dhcp_opt_to_user_string_list_uint16(dhcp_opt_t *opt); extern char *dhcp_opt_to_user_string_list_uint32(dhcp_opt_t *opt); extern char *dhcp_opt_to_user_string_list_int8(dhcp_opt_t *opt); extern char *dhcp_opt_to_user_string_list_int16(dhcp_opt_t *opt); extern char *dhcp_opt_to_user_string_list_int32(dhcp_opt_t *opt); extern char *dhcp_opt_to_user_string_array_uint8(dhcp_opt_t *opt); extern char *dhcp_opt_to_user_string_array_uint16(dhcp_opt_t *opt); extern char *dhcp_opt_to_user_string_array_uint32(dhcp_opt_t *opt); extern char *dhcp_opt_to_user_string_array_int8(dhcp_opt_t *opt); extern char *dhcp_opt_to_user_string_array_int16(dhcp_opt_t *opt); extern char *dhcp_opt_to_user_string_array_int32(dhcp_opt_t *opt); extern char *dhcp_opt_to_user_string_ip_addr(dhcp_opt_t *opt); extern char *dhcp_opt_to_user_string_ip_addr_pair(dhcp_opt_t *opt); extern char *dhcp_opt_to_user_string_list_ip_addr(dhcp_opt_t *opt); extern char *dhcp_opt_to_user_string_list_ip_addr_pair(dhcp_opt_t *opt); extern char *dhcp_opt_to_user_string_nvt_string(dhcp_opt_t *opt); extern char *dhcp_opt_to_user_string_string(dhcp_opt_t *opt); /* to internal string. */ extern char *dhcp_opt_to_internal_string_uint8(dhcp_opt_t *opt); extern char *dhcp_opt_to_internal_string_uint16(dhcp_opt_t *opt); extern char *dhcp_opt_to_internal_string_uint32(dhcp_opt_t *opt); extern char *dhcp_opt_to_internal_string_int8(dhcp_opt_t *opt); extern char *dhcp_opt_to_internal_string_int16(dhcp_opt_t *opt); extern char *dhcp_opt_to_internal_string_int32(dhcp_opt_t *opt); extern char *dhcp_opt_to_internal_string_list_uint8(dhcp_opt_t *opt); extern char *dhcp_opt_to_internal_string_list_uint16(dhcp_opt_t *opt); extern char *dhcp_opt_to_internal_string_list_uint32(dhcp_opt_t *opt); extern char *dhcp_opt_to_internal_string_list_int8(dhcp_opt_t *opt); extern char *dhcp_opt_to_internal_string_list_int16(dhcp_opt_t *opt); extern char *dhcp_opt_to_internal_string_list_int32(dhcp_opt_t *opt); extern char *dhcp_opt_to_internal_string_array_uint8(dhcp_opt_t *opt); extern char *dhcp_opt_to_internal_string_array_uint16(dhcp_opt_t *opt); extern char *dhcp_opt_to_internal_string_array_uint32(dhcp_opt_t *opt); extern char *dhcp_opt_to_internal_string_array_int8(dhcp_opt_t *opt); extern char *dhcp_opt_to_internal_string_array_int16(dhcp_opt_t *opt); extern char *dhcp_opt_to_internal_string_array_int32(dhcp_opt_t *opt); extern char *dhcp_opt_to_internal_string_ip_addr(dhcp_opt_t *opt); extern char *dhcp_opt_to_internal_string_ip_addr_pair(dhcp_opt_t *opt); extern char *dhcp_opt_to_internal_string_list_ip_addr(dhcp_opt_t *opt); extern char *dhcp_opt_to_internal_string_list_ip_addr_pair(dhcp_opt_t *opt); extern char *dhcp_opt_to_internal_string_nvt_string(dhcp_opt_t *opt); extern char *dhcp_opt_to_internal_string_string(dhcp_opt_t *opt); #endif /* DHCP_OPTION_CONVERT_H */ |
From: <act...@us...> - 2003-04-28 22:22:35
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv19655 Modified Files: Makefile.am Log Message: added new dhcp object to libdhcputil Index: Makefile.am =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/Makefile.am,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** Makefile.am 25 Mar 2003 03:07:28 -0000 1.15 --- Makefile.am 28 Apr 2003 22:22:31 -0000 1.16 *************** *** 16,20 **** dhcp-libutil.h dhcp-local.h dhcp-options-strings.h dhcp-print.h dhcp-cache-entry.h \ dhcp-client-conf.h dhcp-convert.h dhcp-librawnet.h dhcp-limits.h dhcp-log.h \ ! dhcp-tokenizer.h dhcp-sysconf.h dhcp-conf.h dhcp-conf-var.h --- 16,20 ---- dhcp-libutil.h dhcp-local.h dhcp-options-strings.h dhcp-print.h dhcp-cache-entry.h \ dhcp-client-conf.h dhcp-convert.h dhcp-librawnet.h dhcp-limits.h dhcp-log.h \ ! dhcp-tokenizer.h dhcp-sysconf.h dhcp-conf.h dhcp-conf-var.h dhcp-option.h dhcp-option-convert.h *************** *** 44,48 **** dhcp-interrupt.c \ dhcp-conf.c \ ! dhcp-conf-var.c dhcp_sniff_SOURCES = dhcp-sniff.c \ --- 44,52 ---- dhcp-interrupt.c \ dhcp-conf.c \ ! dhcp-conf-var.c \ ! dhcp-option.c \ ! dhcp-option-convert.c \ ! dhcp-convert.c ! dhcp_sniff_SOURCES = dhcp-sniff.c \ *************** *** 58,62 **** dhcp-client-states.c \ dhcp-options-strings.c \ - dhcp-convert.c \ dhcp-sysconf.c --- 62,65 ---- |
From: <act...@us...> - 2003-04-28 22:21:55
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv19315 Modified Files: dhcp-list.c dhcp-libutil.h Log Message: added list_copy -- routine to copy datums if the size is known. Index: dhcp-list.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-list.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** dhcp-list.c 2 Jan 2003 04:23:01 -0000 1.5 --- dhcp-list.c 28 Apr 2003 22:21:52 -0000 1.6 *************** *** 304,305 **** --- 304,326 ---- return list->len; } + + list_t *list_copy(list_t *list, size_t data_size) + { + uint8_t *src_data; + uint8_t *new_data; + list_t *new_list; + + new_list = list_create(); + + list_rewind(list); + while((src_data = list_next(list)) != NULL) { + + new_data = xmalloc(data_size); + memcpy(new_data, src_data, data_size); + + list_add(new_list, new_data); + } + + return new_list; + } + Index: dhcp-libutil.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-libutil.h,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** dhcp-libutil.h 25 Mar 2003 03:03:56 -0000 1.24 --- dhcp-libutil.h 28 Apr 2003 22:21:52 -0000 1.25 *************** *** 218,221 **** --- 218,222 ---- extern void *list_next(list_t *list); extern int list_get_len(list_t *list); + extern list_t *list_copy(list_t *list, size_t data_size); /* stringbuffer. */ |
From: <act...@us...> - 2003-04-28 22:20:31
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory sc8-pr-cvs1:/tmp/cvs-serv18492 Modified Files: dhcp-convert.c dhcp-convert.h dhcp-option.c dhcp-option.h Log Message: new dhcp option object Index: dhcp-convert.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-convert.c,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** dhcp-convert.c 26 Mar 2003 03:45:35 -0000 1.9 --- dhcp-convert.c 28 Apr 2003 22:20:23 -0000 1.10 *************** *** 964,965 **** --- 964,1014 ---- return (string_int_to_network(s, ret_len, 0, sizeof(uint16_t))); } + + /** -- NEW replacement code. */ + + /* We've redone our handlers. The old handlers are still here + * until the dhcp_opt_t object becomes mature. + * + * We now have six handlers which do the following: + * + * (*) Network to internal: take raw data and convert it to host order. + * (*) User string to internal: input from the user to internal host order. + * (*) Internal string to internal: input from our own string data to + * internal host order. + * + * (*) Internal to string internal: host order to internal string. + * (*) Internal to string user: host order to user string. + * (*) Internal to network: host order to network byte order. + * + * Also we've replaced our byte routines to handle unsigned and + * signed as opposed to just a plain byte. We've kept them + * seperate to ensure proper handling by the hardware of both + * signed and unsigned. + * + */ + + /* utility routines. */ + + static uint8_t *make_byte_copy(const uint8_t *data) + { + uint8_t *new_data; + + new_data = xmalloc(sizeof(1)); + memcpy(new_data, data, 1); + + return new_data; + } + + /* uint8_t from network to host. just check length and copy. */ + void *network_uint8_to_host(const unsigned char *data, int len) + { + uint8_t *host_data; + + if(len != 1) { + return NULL; + } + + host_data = make_byte_copy(data); + + return host_data; + } Index: dhcp-convert.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-convert.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-convert.h 16 Nov 2002 00:23:43 -0000 1.2 --- dhcp-convert.h 28 Apr 2003 22:20:24 -0000 1.3 *************** *** 26,36 **** #define DHCP_CONVERT_H /* conversion handler. */ typedef struct option_convert_handler { ! char *(*serialize) (const unsigned char *data, int len); ! void *(*serialize_to_internal) (const char *string); ! void *(*serialize_to_network) (const char *string, unsigned char *retlen); ! void (*free_internal) (void *ptr); } option_convert_handler; --- 26,41 ---- #define DHCP_CONVERT_H + typedef char *(*serialize_from_network)(const unsigned char *data, int len); + typedef void *(*serialize_to_internal)(const char *string); + typedef void *(*serialize_to_network)(const char *string, unsigned char *retlen); + typedef void (*free_internal)(void *ptr); + /* conversion handler. */ typedef struct option_convert_handler { ! serialize_from_network serialize; ! serialize_to_internal serialize_to_internal; ! serialize_to_network serialize_to_network; ! free_internal free_internal; } option_convert_handler; *************** *** 97,100 **** --- 102,130 ---- extern char *network_address_to_string_static(uint32_t addr); + + /* new routines. */ + + /* new byte routines. */ + + /* unsigned octet. */ + extern void *network_uint8_to_host(const unsigned char *data, int len); + extern void *user_string_uint8_to_host(const char *data, int len); + extern void *internal_string_uint8_to_host(const char *data, int len); + + extern char *uint8_to_internal_string(uint8_t *data, int len); + extern char *uint8_to_user_string(uint8_t *data, int len); + extern void *uint8_to_network(uint8_t *data, int *retlen); + + /* unsigned octet. */ + extern void *network_int8_to_host(const unsigned char *data, int len); + extern void *user_string_int8_to_host(const char *data, int len); + extern void *internal_string_int8_to_host(const char *data, int len); + + extern char *int8_to_internal_string(uint8_t *data, int len); + extern char *int8_to_user_string(uint8_t *data, int len); + extern void *int8_to_network(uint8_t *data, int *retlen); + + + #endif /* DHCP_CONVERT_H */ Index: dhcp-option.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-option.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** dhcp-option.c 4 Apr 2003 05:31:39 -0000 1.1 --- dhcp-option.c 28 Apr 2003 22:20:24 -0000 1.2 *************** *** 23,32 **** */ #include "dhcp-local.h" #include "dhcp-libutil.h" #include "dhcp-librawnet.h" - #include "dhcp-convert.h" #include "dhcp-option.h" #include "dhcp-limits.h" [...2174 lines suppressed...] + return DHCP_OPT_TO_INTERNAL_STRING(opt); + } + + /* get member length. */ + size_t dhcp_opt_get_mem_len(dhcp_opt_t *opt) + { + return DHCP_OPT_GET_MEM_LEN(opt); + } + + /* get total length. */ + size_t dhcp_opt_get_total_len(dhcp_opt_t *opt) + { + return DHCP_OPT_GET_TOTAL_LEN(opt); + } + + /* get num. */ + size_t dhcp_opt_get_num(dhcp_opt_t *opt) + { + return opt->num; + } Index: dhcp-option.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-option.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** dhcp-option.h 4 Apr 2003 05:31:39 -0000 1.1 --- dhcp-option.h 28 Apr 2003 22:20:24 -0000 1.2 *************** *** 36,69 **** struct dhcp_opt; ! typedef char *(*dhcp_opt_to_string_internal)(struct dhcp_opt *opt); ! typedef char *(*dhcp_opt_to_string_user)(struct dhcp_opt *opt); typedef void *(*dhcp_opt_to_network_data)(struct dhcp_opt *opt); typedef void *(*dhcp_opt_to_host_data)(struct dhcp_opt *opt); ! typedef char *(*dhcp_opt_network_to_internal)(uint8_t *data, size_t len, struct dhcp_opt *opt); ! typedef char *(*dhcp_opt_string_user_to_internal)(list_t *input, struct dhcp_opt *opt); ! typedef void *(*dhcp_opt_string_to_internal)(char *input, struct dhcp_opt *opt); ! ! typedef void (*dhcp_opt_destroy)(struct dhcp_opt *opt); typedef struct dhcp_opt_attr { ! dhcp_opt_tag_t tag; /* tag */ ! dhcp_opt_len_t len; /* member length in octets */ dhcp_opt_val_type_t type; /* type of opt */ dhcp_opt_val_type_t val_type; /* type of val */ ! /* extraction routines. */ ! dhcp_opt_to_string_internal to_internal_string; /* to internal string representation. */ ! dhcp_opt_to_string_user to_string_user; /* to user string representation. */ dhcp_opt_to_network_data to_network_data; /* to network data representation. */ ! dhcp_opt_to_host_data to_host_data; /* to host data representation. */ ! /* creation routines. */ ! dhcp_opt_network_to_internal network_to_internal; /* network data to internal. */ ! dhcp_opt_string_user_to_internal string_user_to_internal; /* user string to internal. */ ! dhcp_opt_string_to_internal string_to_internal; /* string to internal. */ ! dhcp_opt_destroy destroy; /* destroy option datum. */ } dhcp_opt_attr_t; --- 36,73 ---- struct dhcp_opt; ! /* typedef of dhcp option function pointers. */ ! ! /* converters from external data to internal */ ! typedef int (*dhcp_opt_from_string)(struct dhcp_opt *opt, const char *input); ! typedef int (*dhcp_opt_from_user_string)(struct dhcp_opt *opt, list_t *input_list); ! typedef int (*dhcp_opt_from_network)(struct dhcp_opt *opt, const uint8_t *data, size_t len); ! ! /* converts from internal data to other data formats. */ typedef void *(*dhcp_opt_to_network_data)(struct dhcp_opt *opt); typedef void *(*dhcp_opt_to_host_data)(struct dhcp_opt *opt); + typedef char *(*dhcp_opt_to_user_string)(struct dhcp_opt *opt); + typedef char *(*dhcp_opt_to_string)(struct dhcp_opt *opt); ! /* the data destructor. */ ! typedef void (*dhcp_opt_data_destroy)(struct dhcp_opt *opt); typedef struct dhcp_opt_attr { ! dhcp_opt_tag_t tag; /* tag */ ! dhcp_opt_len_t len; /* member length in octets */ dhcp_opt_val_type_t type; /* type of opt */ dhcp_opt_val_type_t val_type; /* type of val */ ! /* data extraction routines. */ dhcp_opt_to_network_data to_network_data; /* to network data representation. */ ! dhcp_opt_to_user_string to_user_string; /* to user string representation. */ ! dhcp_opt_to_string to_internal_string; /* to internal string representation. */ ! /* data creation routines. */ ! dhcp_opt_from_network from_network; /* network data to internal. */ ! dhcp_opt_from_user_string from_user_string; /* user string to internal. */ ! dhcp_opt_from_string from_internal_string; /* string to internal. */ ! dhcp_opt_data_destroy destroy; /* destroy option datum. */ } dhcp_opt_attr_t; *************** *** 72,79 **** --- 76,85 ---- typedef struct dhcp_opt { + void *val; /* value */ size_t num; /* num */ dhcp_opt_attr_t *opt_attr; /* attributes */ + } dhcp_opt_t; *************** *** 91,93 **** --- 97,121 ---- DHCP_OPT_VAL_ADDRESS_PAIR }; + /* convenience macros. this makes accessing what's under the attr structure easier. */ + + #ifdef DHCP_OPTION_MACROS + + #define DHCP_OPT_GET_TYPE(x) (x->opt_attr->type) + #define DHCP_OPT_GET_TOTAL_LEN(x) (x->opt_attr->len * x->num) + #define DHCP_OPT_GET_MEM_LEN(x) (x->opt_attr->len) + + #define DHCP_OPT_FROM_NETWORK_DATA(x, data, len) (x->opt_attr->from_network(x, data, len)) + #define DHCP_OPT_FROM_USER_STRING(x, string_data) (x->opt_attr->from_user_string(x, string_data)) + #define DHCP_OPT_FROM_INTERNAL_STRING(x, string_data) (x->opt_attr->from_internal_string(x, string_data)) + + #define DHCP_OPT_TO_INTERNAL_STRING(x) (x->opt_attr->to_internal_string(x)) + #define DHCP_OPT_TO_USER_STRING(x) (x->opt_attr->to_user_string(x)) + #define DHCP_OPT_TO_NETWORK_DATA(x) (x->opt_attr->to_network_data(x)) + #define DHCP_OPT_TO_INTERNAL_DATA(x) (x->opt_attr->to_host_data(x, retlen)) + + #define DHCP_OPT_DESTROY(x) (x->opt_attr->destroy(x)) + + #endif /* DHCP_OPTION_MACROS */ + #endif /* DHCP_OPTION_H */ + |