[dhcp-agent-commits] dhcp-agent/src dhcp-align.h,NONE,1.1 dhcp-cache-entry.h,NONE,1.1 dhcp-client-ca
Status: Alpha
Brought to you by:
actmodern
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory usw-pr-cvs1:/tmp/cvs-serv30373 Modified Files: Makefile.am dhcp-agent.h dhcp-align.c dhcp-arp-discovery.c dhcp-arp.c dhcp-cache-entry.c dhcp-client-cache.c dhcp-client-conf.c dhcp-client-control.c dhcp-client-states.c dhcp-client.c dhcp-client.h dhcp-com.c dhcp-convert.c dhcp-daemon.c dhcp-eth.c dhcp-globconf.c dhcp-icmp-discovery.c dhcp-icmp.c dhcp-interface.c dhcp-ip.c dhcp-librawnet.h dhcp-libutil.h dhcp-local.h dhcp-options-strings.c dhcp-packet-build.c dhcp-print.c dhcp-print.h dhcp-rawnet.c dhcp-route.c dhcp-rtt.c dhcp-rtt.h dhcp-sniff.c dhcp-sniffer-ohandlers.c dhcp-sysconf.c dhcp-timer.c dhcp-timer.h dhcp-udp.c Added Files: dhcp-align.h dhcp-cache-entry.h dhcp-client-cache.h dhcp-client-conf.h dhcp-daemon.h dhcp-interface.h dhcp-limits.h dhcp-options-strings.h Removed Files: dhcp-files.h dhcp-net.h Log Message: completed code split --- NEW FILE: dhcp-align.h --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-align.h,v 1.1 2002/11/10 15:46:40 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. * */ #ifndef DHCP_ALIGN_H #define DHCP_ALIGN_H /* alignment routines. */ extern void align_ip(const unsigned char *data, struct ip_hdr *iphdr); extern void align_udp(const unsigned char *data, struct udp_hdr *udp); extern void align_dhcphdr(const unsigned char *data, dhcphdr *dhcp); extern void align_eth(const unsigned char *data, struct eth_hdr *header); extern void align_icmp(const unsigned char *data, struct icmp_hdr *header); extern void align_icmp_mask(const unsigned char *data, struct icmp_msg_mask *header); extern void align_icmp_echo(const unsigned char *data, struct icmp_msg_echo *header); extern void align_arp_header(const unsigned char *data, struct arp_hdr *header); extern void align_arp_data(const unsigned char *data, struct arp_ethip *arp_data); #endif /* DHCP_ALIGN_H */ --- NEW FILE: dhcp-cache-entry.h --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-cache-entry.h,v 1.1 2002/11/10 15:46:40 actmodern Exp $ * * Copyright 2002 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_CACHE_ENTRY_H #define DHCP_CACHE_ENTRY_H typedef struct { char *name; char *value; } cache_entry_t; extern cache_entry_t *create_cache_entry(const char *name, const char *value); extern void destroy_cache_entry(cache_entry_t *cache); extern void cache_entry_purge_list(list_t *cache_list); #endif /* DHCP_CACHE_ENTRY_H */ --- NEW FILE: dhcp-client-cache.h --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-cache.h,v 1.1 2002/11/10 15:46:40 actmodern Exp $ * * Copyright 2002 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_CACHE_H #define DHCP_CLIENT_CACHE_H /* data structures. */ typedef struct { const char *interface; /* points to dhcp_client_control->interface */ list_t *vars; } client_cache_t; /* prototypes. */ extern client_cache_t *create_client_cache(const char *interface); extern void purge_cache(client_cache_t *cc); extern void client_cache_destroy(client_cache_t *cc); extern int load_client_cache(client_cache_t *cc, unsigned char use_tmp); 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 void client_cache_update(client_cache_t *cc); extern void client_cache_delete_tmp_cache(client_cache_t *cc); extern void client_cache_delete_cache(client_cache_t *cc); #endif /* DHCP_CLIENT_CACHE_H */ --- NEW FILE: dhcp-client-conf.h --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-conf.h,v 1.1 2002/11/10 15:46:40 actmodern Exp $ * * Copyright 2002 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_CONF_H #define DHCP_CLIENT_CONF_H /* data structures. */ typedef struct { char *conf_file; const char *interface; /* points to dhcp_client_control->interface */ /* specific configurations */ unsigned char options[MAX_OPTIONS_HANDLED]; /* which options should we handle. */ } client_conf_t; extern client_conf_t *create_client_conf(const char *interface); extern void client_conf_destroy(client_conf_t *cc); extern int load_client_conf(client_conf_t *cc); #endif /* DHCP_CLIENT_CONF_H */ --- NEW FILE: dhcp-daemon.h --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-daemon.h,v 1.1 2002/11/10 15:46:40 actmodern Exp $ * * Copyright 2002 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_DAEMON_H #define DHCP_DAEMON_H /* global vars. */ #ifdef HAVE_SIG_ATOMIC_T extern sig_atomic_t want_shutdown; extern sig_atomic_t want_hup; #else /* HAVE_SIG_ATOMIC_T */ extern volatile int want_shutdown; extern volatile int want_hup; #endif /* HAVE_SIG_ATOMIC_T */ /* prototypes. */ extern void go_background(char *dir); extern void setup_interrupt_handlers(void); #endif /* DHCP_DAEMON_H */ --- NEW FILE: dhcp-interface.h --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-interface.h,v 1.1 2002/11/10 15:46:40 actmodern Exp $ * * Copyright 2002 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_INTERFACE_H #define DHCP_INTERFACE_H extern interface_control_t *create_interface_control(char *name); extern void destroy_interface_control(interface_control_t *ic); extern int interface_up(interface_control_t *ic, uint32_t addr, uint32_t netmask, int mtu); extern int interface_down(interface_control_t *ic); extern int interface_get_ip_addr(interface_control_t *ic, uint32_t *addr); extern list_t *interface_get_active_interfaces(void); extern list_t *interface_get_inactive_interfaces(void); extern int interface_is_up(interface_control_t *ic); #endif /* DHCP_INTERFACE_H */ --- NEW FILE: dhcp-limits.h --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-limits.h,v 1.1 2002/11/10 15:46:40 actmodern Exp $ * * Copyright 2002 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_LIMITS_H #define DHCP_LIMITS_H /* sensible default for max descriptors -- we use this if we can't find it through other means (sysconf/getrusage) */ #define SENSIBLE_DESCRIPTOR_MAX 128 /* Generic size for buffers we use. * XXX -- fix generic buffers into sensible sizes. */ #define GENERIC_BUFFSIZE 256 /* mtu -- this is a broken guessing game right now.*/ #define DEFAULT_MTU 1500 #define SNAPLEN DEFAULT_MTU /* XXX -- should be called DEFAULT_SNAPLEN. * rawnet makes an assumption on incoming * packets this is broken. fixme. * */ /* Max message size option default. */ #define MAX_MESSAGE_SIZE 576 /* max options handled. */ #define MAX_OPTIONS_HANDLED 62 #endif /* DHCP_LIMITS_H */ --- NEW FILE: dhcp-options-strings.h --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-options-strings.h,v 1.1 2002/11/10 15:46:40 actmodern Exp $ * * Copyright 2002 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_OPTION_STRINGS_H #define DHCP_OPTION_STRINGS_H extern char *dhcp_options_strings[]; #endif /* DHCP_OPTION_STRINGS_H */ Index: Makefile.am =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/Makefile.am,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Makefile.am 9 Nov 2002 16:59:15 -0000 1.4 --- Makefile.am 10 Nov 2002 15:46:40 -0000 1.5 *************** *** 3,7 **** # Main source Makefile.am ! CFLAGS = -Wall -Werror INCLUDES = @PCAP_INC@ @DNET_INC@ DEFS = @DEFS@ --- 3,7 ---- # Main source Makefile.am ! CFLAGS = -Wall -Werror -g INCLUDES = @PCAP_INC@ @DNET_INC@ DEFS = @DEFS@ *************** *** 9,13 **** # Programs we are compiling. ! #bin_PROGRAMS = dhcp-sniff dhcp-client lib_LTLIBRARIES = libdhcputil.la --- 9,13 ---- # Programs we are compiling. ! bin_PROGRAMS = dhcp-sniff dhcp-client lib_LTLIBRARIES = libdhcputil.la *************** *** 21,67 **** dhcp-varfile.c \ dhcp-parser.c \ ! dhcp-files.c ! # dhcp-rawnet.c ! # dhcp-align.c ! # dhcp-com.c \ ! # dhcp-eth.c \ ! # dhcp-ip.c \ ! # dhcp-udp.c \ ! # dhcp-arp.c \ ! # dhcp-icmp.c \ ! # dhcp-interface.c \ dhcp-libutil.h \ ! # dhcp-librawnet.h \ ! # dhcp-packet-build.c \ ! # dhcp-icmp-discovery.c \ ! # dhcp-arp-discovery.c \ ! dhcp-local.h ! # dhcp_sniff_SOURCES = \ ! # $(COMMON_SOURCES) \ ! # $(RAWNET_SOURCES) \ ! # dhcp-sniff.c \ ! # dhcp-print.c \ ! # dhcp-sniffer-ohandlers.c ! # dhcp_client_SOURCES = \ ! # $(COMMON_SOURCES) \ ! # $(RAWNET_SOURCES) \ ! # dhcp-client.c \ ! # dhcp-daemon.c \ ! # dhcp-client-cache.c \ ! # dhcp-cache-entry.c \ ! # dhcp-client-control.c \ ! # dhcp-client-conf.c \ ! # dhcp-client-states.c \ ! # dhcp-options-strings.c \ ! # dhcp-convert.c \ ! # dhcp-sysconf.c \ ! # dhcp-route.c \ ! # dhcp-globconf.c ! # dhcp_client_LDADD = @PCAP_LIB@ @DNET_LIB@ ! # dhcp_sniff_LDADD = @PCAP_LIB@ @DNET_LIB@ noinst_HEADERS = dhcp-agent.h ../config.h --- 21,62 ---- dhcp-varfile.c \ dhcp-parser.c \ ! dhcp-files.c \ ! dhcp-rawnet.c \ ! dhcp-interface.c \ ! dhcp-local.h \ dhcp-libutil.h \ ! dhcp-librawnet.h \ ! dhcp-align.c \ ! dhcp-packet-build.c \ ! dhcp-icmp-discovery.c \ ! dhcp-arp-discovery.c \ ! dhcp-com.c \ ! dhcp-eth.c \ ! dhcp-ip.c \ ! dhcp-udp.c \ ! dhcp-arp.c \ ! dhcp-icmp.c \ ! dhcp-route.c ! dhcp_sniff_SOURCES = dhcp-sniff.c \ ! dhcp-print.c \ ! dhcp-sniffer-ohandlers.c ! dhcp_client_SOURCES = dhcp-client.c \ ! dhcp-daemon.c \ ! dhcp-client-cache.c \ ! dhcp-cache-entry.c \ ! dhcp-client-control.c \ ! dhcp-client-conf.c \ ! dhcp-client-states.c \ ! dhcp-options-strings.c \ ! dhcp-convert.c \ ! dhcp-sysconf.c \ ! dhcp-globconf.c ! dhcp_client_LDADD = -ldhcputil ! dhcp_sniff_LDADD = -ldhcputil ! libdhcputil_la_LIBADD = @PCAP_LIB@ @DNET_LIB@ noinst_HEADERS = dhcp-agent.h ../config.h Index: dhcp-agent.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-agent.h,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** dhcp-agent.h 29 Oct 2002 17:11:33 -0000 1.1.1.1 --- dhcp-agent.h 10 Nov 2002 15:46:40 -0000 1.2 *************** *** 61,89 **** extern const char *__progname; - #if defined(HAVE_GETOPT_H) - - # include <getopt.h> - - #endif /* HAVE_GETOPT_H */ - - #ifdef HAVE_PRIMACROS_H - - #include <primacros.h> - - #endif /* HAVE_PRIMACROS_H */ - - #if defined(HAVE_STDARG_H) - - # include <stdarg.h> - - # else - - # if defined(HAVE_SYS_VARARGS_H) - - # include <varargs.h> - - # endif /* HAVE_VARARGS_H */ - - #endif /* HAVE_STDARG_H */ # if defined(HAVE_SYS_UTSNAME_H) --- 61,64 ---- *************** *** 98,105 **** * * * * * * * * * * */ - /* Limit on size of strings we'd be willing to handle. */ - - # define MAX_STRING_LEN 256 - /* Generic size for buffers we use. * XXX -- fix generic buffers into sensible sizes. --- 73,76 ---- *************** *** 115,133 **** */ - # define DEFAULT_MTU 1500 - # define SNAPLEN DEFAULT_MTU /* XXX -- should be called DEFAULT_SNAPLEN. - * rawnet makes an assumption on incoming - * packets this is broken. fixme. - * - */ - - /* Max message size option default. */ - - # define MAX_MESSAGE_SIZE 576 - - /* max options handled. */ - - # define MAX_OPTIONS_HANDLED 62 - /* sensible default for max descriptors -- we use this if we can't find it through other means (sysconf/getrusage) */ --- 86,89 ---- *************** *** 135,163 **** #define SENSIBLE_DESCRIPTOR_MAX 128 - /* Reasonable defaults in case services db isn't up to date. */ - - #define BOOTP_CLIENT 68 - #define BOOTP_SERVER 67 - - /* Solaris doesn't have INADDR_NONE */ - - #ifndef INADDR_NONE - #define INADDR_NONE (uint32_t) -1 - #endif - - /* Verbosity levels. */ - - enum verbosity { QUIET_VERBOSITY_LEVEL = 0, ERROR_VERBOSITY_LEVEL, NORMAL_VERBOSITY_LEVEL, - WARNING_VERBOSITY_LEVEL, DEBUG_VERBOSITY_LEVEL, MAX_VERBOSITY_LEVEL }; - - /* Line length for messages before breaking into a new line. */ - - #define MESSAGE_LINE_LENGTH 60 - - /* as mentioned in rfc2131, 64 seconds is the recommended upper - * limit of waiting time for ethernet. */ - - #define RECOMMENDED_MAX_SECS_WAIT 10 - /* * * * * * * * * * * * Data structures. * --- 91,94 ---- *************** *** 172,830 **** } list_t; - /* DHCP fixed header -- before dhcp options. */ - - /* Size of header independant of any padding - * sizeof() the structure may return. */ - - #define DHCP_FIXEDHDR_LEN 236 - - typedef struct { - uint8_t op; - uint8_t htype; - uint8_t hlen; - uint8_t hops; - uint32_t xid; - uint16_t secs; - uint16_t flags; - uint32_t ciaddr; - uint32_t yiaddr; - uint32_t siaddr; - uint32_t giaddr; - - #define DHCP_CHADDR_SIZE 16 - unsigned char chaddr[DHCP_CHADDR_SIZE]; - #define DHCP_SNAME_SIZE 64 - unsigned char sname[DHCP_SNAME_SIZE]; - #define DHCP_FILE_SIZE 128 - unsigned char file[DHCP_FILE_SIZE]; - - /* options go here. */ - } 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 * - * for packet assembly/disassembly. */ - - typedef struct { - dhcphdr fixedheader; /* DHCP fixed header. */ - uint32_t magic_cookie; /* Magic cookie. */ - list_t *options; /* Option list. */ - list_t *options_seek; /* Seek pointer to option list. */ - } dhcp_obj; - - /* - * Other packet objects. - * - * We use these to create a single interface - * for creating custom packeting. - * - */ - - typedef struct { - struct eth_hdr header; - } eth_obj; - - typedef struct { - struct ip_hdr header; - } ip_obj; - - typedef struct { - struct arp_hdr header; - struct arp_ethip arp_data; - } arp_obj; - - typedef struct { - struct icmp_hdr icmp_header; - union icmp_msg icmp_msg; - } icmp_obj; - - typedef struct { - struct udp_hdr header; - } udp_obj; - - /* interface control object: - * we store dnet's interface handle, - * and interface_entry structure. - * We need the entry structure - */ - - typedef struct { - intf_t *interface_handle; - struct intf_entry *interface_entry; - } interface_control_t; - - /* - * DHCP raw network object. - * - * We do all our network transmission - * through this data structure. - * - */ - - typedef struct { - - /* we should not interface directly with any of these members - * above the rawnet layer: FIXME -- unfortunately we do. */ - - pcap_t *pcap; /* packet capturing device (pcap). */ - int pcap_fd; /* file descriptor we can select on for pcap. */ - eth_t *eth; /* ethernet device handler (libdnet). */ - - uint16_t src_port, dst_port; /* udp ports for writing packets. */ - char *device; /* device name. */ - - char *packet_data; /* packet data. */ - int packet_len; /* total length of packet. */ - - struct timeval tstamp; /* timestamp. */ - - eth_addr_t chw_addr; /* our hardware address. */ - ip_addr_t cip_addr; /* our ip address. */ - - eth_addr_t *fake_hw_addr; /* our fake hardware address. */ - - int promiscuous; /* run in promiscuous mode flag. */ - interface_control_t - *intf_handle; /* interface control handle. */ - - /* - * Data objects - * - * After reception of packets on the wire - * they're aligned and placed into these - * objects. - * - */ - - unsigned char type; /* Type of data: - * ARP, ICMP DHCP */ - char *pcap_filter; /* low level pcap filter. */ - - /* Packet data. */ - - eth_obj *ether_p; - ip_obj *ip_p; - arp_obj *arp_p; - icmp_obj *icmp_p; - udp_obj *udp_p; - dhcp_obj *dhcp_p; - - } rawnet_t; - - typedef struct { - char *conf_file; - char *interface; /* points to dhcp_client_control->interface */ - - /* specific configurations */ - - unsigned char options[MAX_OPTIONS_HANDLED]; /* which options should we handle. */ - } client_conf_t; - - /* Cache data types. */ - - typedef struct { - char *name; - char *value; - } cache_entry_t; - - typedef struct { - char *interface; /* points to dhcp_client_control->interface */ - list_t *vars; - } client_cache_t; - - /* Client data object. */ - - typedef struct { - - rawnet_t *rawnet; /* raw network handle */ - - client_cache_t *cache; /* cache */ - client_conf_t *conf; /* configuration. */ - - uint32_t xid; /* unique xid */ - time_t started; /* the amount of milliseconds since we started. */ - time_t secs; /* secs -- used to save secs value. */ - uint32_t renewal_time; /* when to renew lease (secs). */ - - char *interface; /* interface name. */ - unsigned char *class_id, *client_id; /* client_id, class_id */ - int state; /* our current state. */ - int discover_offer_retries; /* counter for retries on discover_offer */ - - ip_addr_t sip_addr; /* server's ip address. */ - eth_addr_t shw_addr; /* server's hardware address. */ - - } dhcp_client_control_t; - - /* Option print handler structure. */ - - typedef struct { - char *prefix; - void (*handle_option)(const unsigned char *data, - int len, int print_val); - } option_handler; - /* * * * * * * * Constants * * * * * * * */ - /* Syslog options. */ - - #define LOG_OPT LOG_PID|LOG_NDELAY /* Options */ - #define LOG_FACILITY LOG_DAEMON /* Facility */ - #define ERROR_LEVEL LOG_ERR /* Error level */ - #define INFO_LEVEL LOG_INFO /* Normal level */ - - /* DHCP Type messages */ - - # define DHCP_DISCOVER_TM 1 - # define DHCP_OFFER_TM 2 - # define DHCP_REQUEST_TM 3 - # define DHCP_DECLINE_TM 4 - # define DHCP_DHCPACK_TM 5 - # define DHCP_DHCPNAK_TM 6 - # define DHCP_RELEASE_TM 7 - - /* BOOTP Types */ - - #define DHCP_BOOTP_REQUEST 1 - #define DHCP_BOOTP_REPLY 2 - - /* Flags */ - - #define DHCP_BROADCAST_FLAG 0x8000 - - /* Option tags. */ - - /* (this is me trying to make constant names out of long option - * names. let the comedy ensue!) - */ - - # define TAG_DHCP_PAD 0 - # define TAG_DHCP_SUBNET_MASK 1 - # define TAG_DHCP_TIME_OFFSET 2 - # define TAG_DHCP_ROUTER 3 - # define TAG_DHCP_TIME_SERVER 4 - # define TAG_DHCP_NAME_SERVER 5 - # define TAG_DHCP_DOMAIN_NAME_SERVER 6 - # define TAG_DHCP_LOG_SERVER 7 - # define TAG_DHCP_COOKIE_SERVER 8 - # define TAG_DHCP_LPR_SERVER 9 - # define TAG_DHCP_IMPRESS_SERVER 10 - # define TAG_DHCP_RESOURCE_LOCATION_SERVER 11 - # define TAG_DHCP_HOST_NAME 12 - # define TAG_DHCP_BOOT_FILE_SIZE 13 - # define TAG_DHCP_MERIT_DUMP_FILE 14 - # define TAG_DHCP_DOMAIN_NAME 15 - # define TAG_DHCP_SWAP_SERVER 16 - # define TAG_DHCP_ROOT_PATH 17 - # define TAG_DHCP_EXTENSIONS_PATH 18 - # define TAG_DHCP_IP_FORWARDING 19 - # define TAG_DHCP_NON_LOCAL_SOURCE_ROUTING 20 - # define TAG_DHCP_POLICY_FILTER 21 - # define TAG_DHCP_MAX_DGRAM_REASSUMBLY_SIZE 22 - # define TAG_DHCP_IP_TIME_TO_LIVE 23 - # define TAG_DHCP_MTU_AGING_TIMEOUT 24 - # define TAG_DHCP_MTU_PLATEAU_TABLE 25 - # define TAG_DHCP_INTERFACE_MTU 26 - # define TAG_DHCP_SUBNETS_ARE_LOCAL 27 - # define TAG_DHCP_BROADCAST_ADDRESS 28 - # define TAG_DHCP_MASK_DISCOVERY 29 - # define TAG_DHCP_MASK_SUPPLIER 30 - # define TAG_DHCP_ROUTER_DISCOVERY 31 - # define TAG_DHCP_ROUTER_SOLICITATION 32 - # define TAG_DHCP_STATIC_ROUTE 33 - # define TAG_DHCP_TRAILER_ENCAPSULATION 34 - # define TAG_DHCP_ARP_CACHE_TIMEOUT 35 - # define TAG_DHCP_ETHERNET_ENCAPSULATION 36 - # define TAG_DHCP_TCP_DEFAULT_TTL 37 - # define TAG_DHCP_TCP_KEEPALIVE_INTERVAL 38 - # define TAG_DHCP_TCP_KEEPALIVE_GARBAGE 39 - # define TAG_DHCP_NIS_DOMAIN_NAME 40 - # define TAG_DHCP_NIS_SERVERS 41 - # define TAG_DHCP_NTP_SERVERS 42 - # define TAG_DHCP_VENDOR_SPECIFIC 43 - # define TAG_DHCP_NETBIOSOTCP_NAME_SERVER 44 - # define TAG_DHCP_NETBIOSOTCP_DATAGRAM_SERVER 45 - # define TAG_DHCP_NETBIOSOTCP_NODE_TYPE 46 - # define TAG_DHCP_NETBIOSOTCP_SCOPE 47 - # define TAG_DHCP_XWIN_FONT_SERVER 48 - # define TAG_DHCP_XWIN_DISP_MANAGER_SERVER 49 - # define TAG_DHCP_REQUESTED_IP_ADDRESS 50 - # define TAG_DHCP_IP_ADDRESS_LEASE_TIME 51 - # define TAG_DHCP_OVERLOAD 52 - # define TAG_DHCP_MESSAGE_TYPE 53 - # define TAG_DHCP_SERVER_IDENTIFIER 54 - # define TAG_DHCP_PARAMETERS 55 - # define TAG_DHCP_MESSAGE 56 - # define TAG_DHCP_MAX_DHCP_SIZE 57 - # define TAG_DHCP_RENEWAL_TIME 58 - # define TAG_DHCP_REBINDING_TIME 59 - # define TAG_DHCP_VENDOR_CLASS_ID 60 - # define TAG_DHCP_CLIENT_ID 61 - # define TAG_DHCP_NISPLUS_DOMAIN 64 - # define TAG_DHCP_NISPLUS_SERVERS 65 - # define TAG_DHCP_TFTP_SERVER 66 - # define TAG_DHCP_BOOT_FILE_NAME 67 - # define TAG_DHCP_IP_HOME_AGENT 68 - # define TAG_DHCP_SMTP_SERVER 69 - # define TAG_DHCP_POP_SERVER 70 - # define TAG_DHCP_NNTP_SERVER 71 - # define TAG_DHCP_DEFAULT_WWW_SERVER 72 - # define TAG_DHCP_DEFAULT_FINGER_SERVER 73 - # define TAG_DHCP_DEFAULT_IRC_SERVER 74 - # define TAG_DHCP_DEFAULT_ST_SERVER 75 - # define TAG_DHCP_DEFAULT_STDA_SERVER 76 - # define TAG_DHCP_END 255 - - /* DHCP overload option values. */ - - #define DHCP_OVERLOAD_FILE 1 - #define DHCP_OVERLOAD_SNAME 2 - #define DHCP_OVERLOAD_BOTH 3 - - /* NetBIOS Scope Node Types */ - - # define NETBIOS_B_NODE 0x01 - # define NETBIOS_P_NODE 0x02 - # define NETBIOS_M_NODE 0x04 - # define NETBIOS_H_NODE 0x06 - - /* Parse types. */ - - #define PARSE_SINGLE_STRING 1 - #define PARSE_DOUBLE_STRINGS 2 - /* * * * * * * * * * * * * Function prototypes * * * * * * * * * * * * */ - /* cache manipulation. */ - - extern client_cache_t *create_client_cache(dhcp_client_control_t *dc); - extern void client_cache_destroy(client_cache_t *cc); - extern int load_client_cache(client_cache_t *dc, unsigned char use_tmp); - extern int client_cache_is_empty(client_cache_t *cc); - extern void purge_cache(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_temp); - extern list_t *client_cache_load_option_string_list(client_cache_t *cc, - unsigned char use_tmp); - - extern void client_cache_update(client_cache_t *cc); - extern void client_cache_delete_cache(client_cache_t *cc); - extern void client_cache_delete_tmp_cache(client_cache_t *cc); - - /* cache object manipulation. */ - - extern cache_entry_t *make_cache_entry(const char *name, const char *value); - extern void destroy_cache_entry(cache_entry_t *cache); - extern void cache_entry_purge_list(list_t *cache_list); - - /* packet building routines. */ - - /* dhcp packet routines. */ - extern void build_dhcp_discover(rawnet_t *net, uint32_t xid, time_t secs, list_t *options); - extern void build_dhcp_request_unicast(rawnet_t *net, uint32_t xid, time_t secs, list_t *options, - ip_addr_t sip_addr, eth_addr_t shw_addr); - extern void build_dhcp_request_broadcast(rawnet_t *net, uint32_t xid, time_t secs, list_t *options); - extern void build_dhcp_release(rawnet_t *net, uint32_t xid, list_t *options, ip_addr_t sip_addr, eth_addr_t shw_addr); - - /* arp packet routines. */ - extern void build_arp_reply_broadcast(rawnet_t *net, uint32_t source_addr, - eth_addr_t source_hw_addr); - - extern void build_arp_reply(rawnet_t *net, - uint32_t source_addr, - uint32_t dest_addr, - eth_addr_t source_hw_addr, - eth_addr_t dest_hw_addr); - - extern void build_arp_request(rawnet_t *net, - uint32_t source_addr, - uint32_t dest_addr, - eth_addr_t source_hw_addr); - - extern void build_unarp(rawnet_t *net, uint32_t source_addr, - eth_addr_t source_hw_addr); - - /* icmp packet routines. */ - extern void build_icmp_mask_request(rawnet_t *net, uint32_t id, uint32_t seq); - extern void build_icmp_mask_reply(rawnet_t *net, uint32_t id, uint32_t seq, uint32_t subnet_mask); - extern void build_icmp_echo_request(rawnet_t *net, ip_addr_t source_addr, ip_addr_t dest_addr, - eth_addr_t source_mac, eth_addr_t dest_mac, uint16_t id, - uint16_t seq); - - /* ICMP discovery routines. */ - extern int icmp_subnet_mask_discovery(rawnet_t *net, int retries, uint32_t *subnet_mask); - extern list_t *icmp_rtt_discovery(rawnet_t *net, list_t *addresses); - - /* ARP discovery routines. */ - extern int arp_discover_hardware_address(rawnet_t *net, int retries, uint32_t address, eth_addr_t *mac_addr); - - /* routing table routines. */ - - extern int route_find(rawnet_t *net, ip_addr_t addr, eth_addr_t *dest_mac); - - /* Daemon routines. */ - - extern void go_background(char *dir); - extern void setup_interrupt_handlers(void); - - /* Replacement vsnprintf, snprintf that work the way we want them to. */ - - extern int snprintf (char *str, size_t count, const char *fmt, ...); - extern int vsnprintf (char *str, size_t count, const char *fmt, va_list arg); - - /* DHCP obj routines. */ - - 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); - extern uint16_t dhcp_get_flags(dhcp_obj *dhcp); - extern uint32_t dhcp_get_ciaddr(dhcp_obj *dhcp); - extern uint32_t dhcp_get_yiaddr(dhcp_obj *dhcp); - 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); - extern void dhcp_set_flag_broadcast(dhcp_obj *dhcp); - extern void dhcp_unset_flag_broadcast(dhcp_obj *dhcp); - extern void dhcp_set_ciaddr(dhcp_obj *dhcp, uint32_t ciaddr); - extern void dhcp_set_yiaddr(dhcp_obj *dhcp, uint32_t yiaddr); - 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_atleast_requested_options(dhcp_obj *dhcp, unsigned char *option); - extern int dhcp_have_exact_requested_options(dhcp_obj *dhcp, unsigned char *options); - 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(unsigned char *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(char *hostname); - - - /* Ether obj routines. */ - - extern eth_obj *eth_create(void); - extern void eth_destroy(eth_obj *eth); - extern int eth_read_packet_image(eth_obj *eth, const unsigned char *packet, int len); - extern void eth_write_packet_image(eth_obj *eth, unsigned char *packet); - - extern eth_addr_t eth_get_src_address(eth_obj *eth); - extern eth_addr_t eth_get_dst_address(eth_obj *eth); - extern uint16_t eth_get_type(eth_obj *eth); - - extern void eth_set_src_address(eth_obj *eth, eth_addr_t addr); - extern void eth_set_dst_address(eth_obj *eth, eth_addr_t addr); - extern void eth_set_type(eth_obj *eth, uint16_t type); - - /* IP obj routines. */ - - extern ip_obj *ip_create(void); - extern void ip_destroy(ip_obj *ip); - extern int ip_read_packet_image(ip_obj *ip, const unsigned char *packet, int len); - extern void ip_write_packet_image(ip_obj *ip, unsigned char *packet); - - extern uint32_t ip_get_source_addr(ip_obj *ip); - extern uint32_t ip_get_dest_addr(ip_obj *ip); - extern unsigned char ip_get_hl(ip_obj *ip); - extern uint8_t ip_get_proto(ip_obj *ip); - - extern void ip_set_hl(ip_obj *ip, uint16_t header_len); - extern void ip_set_tos(ip_obj *ip, unsigned char ip_tos); - extern void ip_set_len(ip_obj *ip, uint16_t ip_len); - extern void ip_set_id(ip_obj *ip, uint16_t ip_id); - extern void ip_set_off(ip_obj *ip, uint16_t ip_off); - extern void ip_set_ttl(ip_obj *ip, uint8_t ip_ttl); - extern void ip_set_proto(ip_obj *ip, unsigned char ip_proto); - extern void ip_set_source_addr(ip_obj *ip, uint32_t ip_src); - extern void ip_set_dest_addr(ip_obj *ip, uint32_t ip_src); - - /* ARP obj routines. */ - - extern arp_obj *arp_create(void); - extern void arp_destroy(arp_obj *arp); - extern void arp_write_packet_image(arp_obj *arp, unsigned char *packet); - - extern void arp_set_hardware_type(arp_obj *arp, uint16_t hdr_addr); - extern void arp_set_protocol_type(arp_obj *arp, uint16_t pro); - extern void arp_set_hardware_len(arp_obj *arp, uint8_t len); - extern void arp_set_protocol_len(arp_obj *arp, uint8_t len); - extern void arp_set_op(arp_obj *arp, uint16_t op); - extern void arp_set_sender_hardware_address(arp_obj *arp, eth_addr_t addr); - extern void arp_set_sender_protocol_address(arp_obj *arp, uint32_t addr); - extern void arp_set_target_hardware_address(arp_obj *arp, eth_addr_t addr); - extern void arp_set_target_protocol_address(arp_obj *arp, uint32_t addr); - - extern uint16_t arp_get_op(arp_obj *arp); - extern uint16_t arp_get_hardware_type(arp_obj *arp); - extern uint16_t arp_get_protocol_type(arp_obj *arp); - extern uint8_t arp_get_hardware_len(arp_obj *arp); - extern uint8_t arp_get_protocol_len(arp_obj *arp); - extern unsigned char *arp_get_sender_hardware_address(arp_obj *arp); - extern unsigned char *arp_get_sender_protocol_address(arp_obj *arp); - - extern int arp_read_packet_image(arp_obj *arp, const unsigned char *packet, int len); - - /* UDP obj routines. */ - - extern udp_obj *udp_create(void); - extern void udp_destroy(udp_obj *udp); - extern int udp_read_packet_image(udp_obj *udp, const unsigned char *packet, int len); - extern void udp_write_packet_image(udp_obj *udp, unsigned char *packet); - - extern uint16_t udp_get_src_port(udp_obj *udp); - extern uint16_t udp_get_dst_port(udp_obj *udp); - extern uint16_t udp_get_len(udp_obj *udp); - - extern void udp_set_src_port(udp_obj *udp, uint16_t src_port); - extern void udp_set_dst_port(udp_obj *udp, uint16_t dst_port); - extern void udp_set_len(udp_obj *udp, uint16_t len); - extern void udp_set_cksum(udp_obj *udp, uint16_t cksum); - - /* ICMP obj routines. */ - - extern icmp_obj *icmp_create(void); - extern void icmp_destroy(icmp_obj *icmp); - - extern void icmp_set_type(icmp_obj *icmp, uint8_t type); - extern void icmp_set_code(icmp_obj *icmp, uint8_t code); - extern void icmp_clear_cksum(icmp_obj *icmp); - extern void icmp_mask_set_id(icmp_obj *icmp, uint32_t id); - extern void icmp_mask_set_seq(icmp_obj *icmp, uint32_t seq); - extern void icmp_mask_set_mask(icmp_obj *icmp, uint32_t mask); - extern void icmp_echo_set_id(icmp_obj *icmp, uint16_t id); - extern void icmp_echo_set_seq(icmp_obj *icmp, uint16_t seq); - - extern uint8_t icmp_get_type(icmp_obj *icmp); - extern uint32_t icmp_mask_get_mask(icmp_obj *icmp_p); - extern void icmp_write_packet_image(icmp_obj *icmp, unsigned char *packet); - extern int icmp_read_packet_image(icmp_obj *icmp, const unsigned char *packet, int len); - - /* Alignment functions. */ - - extern void align_eth(const unsigned char *data, struct eth_hdr *eth); - extern void align_ip(const unsigned char *data, struct ip_hdr *iphdr); - extern void align_udp(const unsigned char *data, struct udp_hdr *udp); - extern void align_dhcphdr(const unsigned char *data, dhcphdr *dhcp); - extern void align_icmp(const unsigned char *data, struct icmp_hdr *header); - extern void align_icmp_mask(const unsigned char *data, struct icmp_msg_mask *header); - extern void align_icmp_echo(const unsigned char *data, struct icmp_msg_echo *header); - extern void align_arp_header(const unsigned char *data, struct arp_hdr *header); - extern void align_arp_data(const unsigned char *data, struct arp_ethip *arp_data); - - /* Linked List routines. */ - - extern list_t *add_to_list(list_t *head, void *datum); - extern list_t *add_to_end_of_list(list_t *head, void *datum); - extern list_t *remove_from_list(list_t *head, void *datum); - extern void purge_list(list_t *head, void (*purge_func)(void *d)); - extern void purge_list_internal(void *head); - extern list_t *join_lists(list_t *first_list, list_t *second_list); - extern list_t *list_find_datum_by(list_t *list, int (*find_func)(void *, void *), void *arg); - extern list_t *sort_list(list_t *list, int (*compare)(void *, void *)); - - /* Logging functions. */ - - extern void init_log(const char *s); - extern void close_log(void); - extern void error_log(const char *msg); - extern void info_log(const char *msg); - - /* dhcp client control */ - - extern dhcp_client_control_t *create_dhcp_client_control(char *interface, int promiscuous); - extern void destroy_dhcp_client_control(dhcp_client_control_t *dc); - extern void dhcp_client_update_secs(dhcp_client_control_t *dc); - extern void dhcp_client_reset_secs(dhcp_client_control_t *dc); - extern void dhcp_control_use_fake_hw_addr(dhcp_client_control_t *dc, - char *fake_hw_addr); - extern dhcp_client_control_t *create_dhcp_client_control_dummy(char *interface); - extern void dhcp_client_interface_down(dhcp_client_control_t *dc); - extern void dhcp_client_update_xid(dhcp_client_control_t *dc); - - extern void dhcp_client_set_server_hw_address(dhcp_client_control_t *dc, eth_addr_t eth_addr); - extern void dhcp_client_set_server_ip_address(dhcp_client_control_t *dc, ip_addr_t ip_addr); - - /* dhcp client conf */ - - extern client_conf_t *create_client_conf(dhcp_client_control_t *dc); - extern void client_conf_destroy(client_conf_t *cc); - extern int load_client_conf(client_conf_t *cc); - - /* interface control */ - - extern interface_control_t *create_interface_control(char *name); - extern int interface_is_up(interface_control_t *ic); - extern int interface_up(interface_control_t *ic, uint32_t addr, uint32_t netmask, int mtu); - extern int interface_down(interface_control_t *ic); - extern void destroy_interface_control(interface_control_t *ic); - extern int interface_get_ip_addr(interface_control_t *ic, uint32_t *addr); - extern list_t *interface_get_active_interfaces(void); - extern list_t *interface_get_inactive_interfaces(void); - - /* client states */ - - extern int client_discover_offer(dhcp_client_control_t *dc); - extern int client_request_ack(dhcp_client_control_t *dc); - extern int client_wait(dhcp_client_control_t *dc); - extern int client_release(dhcp_client_control_t *dc); - extern int client_setup(dhcp_client_control_t *dc); - /* Global vars. */ --- 103,114 ---- *************** *** 833,837 **** extern int want_shutdown, want_hup; extern char *dhcp_conf_options_strings[]; - extern option_handler option_handlers[]; extern char *dhcp_options_strings[]; --- 117,120 ---- Index: dhcp-align.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-align.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** dhcp-align.c 29 Oct 2002 17:11:18 -0000 1.1.1.1 --- dhcp-align.c 10 Nov 2002 15:46:40 -0000 1.2 *************** *** 33,37 **** #define MODULE_NAME "dhcp-align" ! #include <dhcp-agent.h> void align_ip(const unsigned char *data, struct ip_hdr *iphdr) --- 33,39 ---- #define MODULE_NAME "dhcp-align" ! #include "dhcp-local.h" ! #include "dhcp-libutil.h" ! #include "dhcp-librawnet.h" void align_ip(const unsigned char *data, struct ip_hdr *iphdr) Index: dhcp-arp-discovery.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-arp-discovery.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** dhcp-arp-discovery.c 29 Oct 2002 17:11:18 -0000 1.1.1.1 --- dhcp-arp-discovery.c 10 Nov 2002 15:46:40 -0000 1.2 *************** *** 23,29 **** */ ! #include <dhcp-agent.h> ! #include <dhcp-util.h> ! #include <dhcp-net.h> #define MODULE_NAME "dhcp-arp-discovery" --- 23,29 ---- */ ! #include "dhcp-local.h" ! #include "dhcp-libutil.h" ! #include "dhcp-librawnet.h" #define MODULE_NAME "dhcp-arp-discovery" Index: dhcp-arp.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-arp.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** dhcp-arp.c 29 Oct 2002 17:11:18 -0000 1.1.1.1 --- dhcp-arp.c 10 Nov 2002 15:46:40 -0000 1.2 *************** *** 25,30 **** #define MODULE_NAME "dhcp-arp" ! #include <dhcp-agent.h> ! #include <dhcp-util.h> /* constructor */ --- 25,33 ---- #define MODULE_NAME "dhcp-arp" ! #include "dhcp-local.h" ! #include "dhcp-libutil.h" ! #include "dhcp-librawnet.h" ! ! #include "dhcp-align.h" /* constructor */ Index: dhcp-cache-entry.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-cache-entry.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** dhcp-cache-entry.c 29 Oct 2002 17:11:18 -0000 1.1.1.1 --- dhcp-cache-entry.c 10 Nov 2002 15:46:40 -0000 1.2 *************** *** 29,37 **** #define MODULE_NAME "dhcp-cache-entry" ! #include <dhcp-agent.h> ! #include <dhcp-util.h> /* constructors. */ ! cache_entry_t *make_cache_entry(const char *name, const char *value) { cache_entry_t *cache; --- 29,39 ---- #define MODULE_NAME "dhcp-cache-entry" ! #include "dhcp-local.h" ! #include "dhcp-libutil.h" ! ! #include "dhcp-cache-entry.h" /* constructors. */ ! cache_entry_t *create_cache_entry(const char *name, const char *value) { cache_entry_t *cache; Index: dhcp-client-cache.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-cache.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** dhcp-client-cache.c 29 Oct 2002 17:11:19 -0000 1.1.1.1 --- dhcp-client-cache.c 10 Nov 2002 15:46:40 -0000 1.2 *************** *** 26,43 **** #define MODULE_NAME "dhcp-client-cache" ! #include <dhcp-agent.h> ! #include <dhcp-util.h> ! #include <dhcp-files.h> ! #include <dhcp-parser.h> ! #include <dhcp-varfile.h> ! #include <dhcp-convert.h> /* constructor. */ ! client_cache_t *create_client_cache(dhcp_client_control_t *dc) { client_cache_t *cc; cc = xmalloc(sizeof(client_cache_t)); ! cc->interface = dc->interface; /* don't copy just point. */ cc->vars = NULL; --- 26,46 ---- #define MODULE_NAME "dhcp-client-cache" ! #include "dhcp-local.h" ! #include "dhcp-limits.h" ! #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" /* constructor. */ ! client_cache_t *create_client_cache(const char *interface) { client_cache_t *cc; cc = xmalloc(sizeof(client_cache_t)); ! cc->interface = interface; /* don't copy just point. */ cc->vars = NULL; *************** *** 93,97 **** case VARFILE_SUCCESS: ! cache_entry = make_cache_entry(varfile_get_name(varfile), varfile_get_val(varfile)); return cache_entry; --- 96,100 ---- case VARFILE_SUCCESS: ! cache_entry = create_cache_entry(varfile_get_name(varfile), varfile_get_val(varfile)); return cache_entry; *************** *** 244,248 **** break; } else { ! copy = make_cache_entry(ce->name, ce->value); options = add_to_list(options, copy); break; --- 247,251 ---- break; } else { ! copy = create_cache_entry(ce->name, ce->value); options = add_to_list(options, copy); break; Index: dhcp-client-conf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-conf.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** dhcp-client-conf.c 29 Oct 2002 17:11:19 -0000 1.1.1.1 --- dhcp-client-conf.c 10 Nov 2002 15:46:40 -0000 1.2 *************** *** 25,33 **** #define MODULE_NAME "dhcp-client-conf" ! #include <dhcp-agent.h> ! #include <dhcp-util.h> ! #include <dhcp-files.h> ! #include <dhcp-parser.h> ! #include <dhcp-varfile.h> #define DEFAULT_CONFIG_OPTIONS_LEN 8 --- 25,37 ---- #define MODULE_NAME "dhcp-client-conf" ! #include "dhcp-local.h" ! #include "dhcp-limits.h" ! #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-options-strings.h" #define DEFAULT_CONFIG_OPTIONS_LEN 8 *************** *** 54,58 **** } ! client_conf_t *create_client_conf(dhcp_client_control_t *dc) { client_conf_t *cc; --- 58,62 ---- } ! client_conf_t *create_client_conf(const char *interface) { client_conf_t *cc; *************** *** 60,64 **** cc = xmalloc(sizeof(client_conf_t)); client_conf_reset_options(cc); ! cc->interface = dc->interface; return cc; } --- 64,68 ---- cc = xmalloc(sizeof(client_conf_t)); client_conf_reset_options(cc); ! cc->interface = interface; return cc; } Index: dhcp-client-control.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-control.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** dhcp-client-control.c 29 Oct 2002 17:11:19 -0000 1.1.1.1 --- dhcp-client-control.c 10 Nov 2002 15:46:40 -0000 1.2 *************** *** 24,31 **** #define MODULE_NAME "dhcp-client-control" ! #include <dhcp-agent.h> ! #include <dhcp-util.h> ! #include <dhcp-globconf.h> ! #include <dhcp-net.h> /* Utility routines to update counters and time stamps. */ --- 24,38 ---- #define MODULE_NAME "dhcp-client-control" ! #include "dhcp-local.h" ! #include "dhcp-limits.h" ! #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-client-conf.h" ! #include "dhcp-globconf.h" /* Utility routines to update counters and time stamps. */ *************** *** 131,136 **** dc->state = 0; dc->interface = xstrdup(interface); ! dc->conf = create_client_conf(dc); ! dc->cache = create_client_cache(dc); if(load_client_conf(dc->conf) < 0) { --- 138,143 ---- dc->state = 0; dc->interface = xstrdup(interface); ! dc->conf = create_client_conf(dc->interface); ! dc->cache = create_client_cache(dc->interface); if(load_client_conf(dc->conf) < 0) { *************** *** 148,153 **** /* Get port numbers from services db. */ ! dport = port_for_service("bootps", "udp"); ! sport = port_for_service("bootpc", "udp"); dport = ntohs(dport); --- 155,160 ---- /* Get port numbers from services db. */ ! dport = rawnet_port_for_service("bootps", "udp"); ! sport = rawnet_port_for_service("bootpc", "udp"); dport = ntohs(dport); Index: dhcp-client-states.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client-states.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** dhcp-client-states.c 29 Oct 2002 17:11:20 -0000 1.1.1.1 --- dhcp-client-states.c 10 Nov 2002 15:46:40 -0000 1.2 *************** *** 28,37 **** #define MODULE_NAME "dhcp-client-states" ! #include <dhcp-agent.h> ! #include <dhcp-client.h> ! #include <dhcp-util.h> ! #include <dhcp-sysconf.h> ! #include <dhcp-globconf.h> ! #include <dhcp-net.h> /*************************** --- 28,42 ---- #define MODULE_NAME "dhcp-client-states" ! #include "dhcp-local.h" ! #include "dhcp-limits.h" ! #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-globconf.h" ! #include "dhcp-sysconf.h" /*************************** *************** *** 421,425 **** dhcp_client_interface_down(dc); ! return 0; /* called from do_shutdown() so no real state returned */ } --- 426,433 ---- dhcp_client_interface_down(dc); ! /* called from do_shutdown() so no real state returned. ! * however if we do take the return value into consideration ! * we should handle it as an error. */ ! return STATE_FATAL_ERROR; } *************** *** 493,494 **** --- 501,526 ---- } + /* do a graceful shutdown. */ + int client_do_shutdown(dhcp_client_control_t *dc) + { + list_t *cached_options; + + INFO_MESSAGE("shutting down."); + + if(dc) { /* only do clean up if we can. */ + + /* load what we can from the cache. */ + + cached_options = client_cache_load_option_string_list(dc->cache, 0); + if(cached_options != NULL) + do_sysconf_cleanup(cached_options, dc); + + cache_entry_purge_list(cached_options); + + client_release(dc); + delete_pid_file(dc->interface); + destroy_dhcp_client_control(dc); + } + + exit(0); + } Index: dhcp-client.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-client.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** dhcp-client.c 29 Oct 2002 17:11:21 -0000 1.1.1.1 --- dhcp-client.c 10 Nov 2002 15:46:40 -0000 1.2 *************** *** 25,34 **** #define MODULE_NAME "dhcp-client" ! #include <dhcp-agent.h> ! #include <dhcp-util.h> ! #include <dhcp-sysconf.h> ! #include <dhcp-globconf.h> ! #include <dhcp-files.h> ! #include <dhcp-client.h> /* forward declarations of do_ routines. */ --- 25,39 ---- #define MODULE_NAME "dhcp-client" ! #include "dhcp-local.h" ! #include "dhcp-limits.h" ! #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-globconf.h" ! #include "dhcp-daemon.h" /* forward declarations of do_ routines. */ *************** *** 79,82 **** --- 84,88 ---- client_release, client_fatal_error, + client_do_shutdown, }; *************** *** 138,166 **** } - /* do a graceful shutdown. */ - static void do_shutdown(dhcp_client_control_t *dc) - { - list_t *cached_options; - - INFO_MESSAGE("shutting down."); - - if(dc) { /* only do clean up if we can. */ - - /* load what we can from the cache. */ - - cached_options = client_cache_load_option_string_list(dc->cache, 0); - if(cached_options != NULL) - do_sysconf_cleanup(cached_options, dc); - - cache_entry_purge_list(cached_options); - - client_release(dc); - delete_pid_file(dc->interface); - destroy_dhcp_client_control(dc); - } - - exit(0); - } - /* check for existing client. */ static int client_process_exists(char *interface) --- 144,147 ---- *************** *** 198,204 **** if(active) ! interface_list = interface_get_active_interfaces(); else ! interface_list = interface_get_inactive_interfaces(); if(interface_list == NULL) --- 179,185 ---- if(active) ! interface_list = rawnet_list_active_interfaces(); else ! interface_list = rawnet_list_inactive_interfaces(); if(interface_list == NULL) *************** *** 242,246 **** if(want_shutdown) ! do_shutdown(dc); /* if we're only running to be setup, --- 223,227 ---- if(want_shutdown) ! client_states[STATE_DO_SHUTDOWN](dc); /* if we're only running to be setup, *************** *** 322,326 **** /* begin hack. */ dc = create_dhcp_client_control_dummy(interface); ! cc = create_client_cache(dc); /* now delete. */ --- 303,307 ---- /* begin hack. */ dc = create_dhcp_client_control_dummy(interface); ! cc = create_client_cache(dc->interface); /* now delete. */ *************** *** 404,408 **** if((dc = create_dhcp_client_control(interface, promiscuous)) == NULL) { ERROR_MESSAGE("encountered a fatal error. I'm exiting."); ! do_shutdown(NULL); } --- 385,389 ---- if((dc = create_dhcp_client_control(interface, promiscuous)) == ... [truncated message content] |