dhcp-agent-commits Mailing List for dhcp-agent (Page 25)
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
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory usw-pr-cvs1:/tmp/cvs-serv5669 Modified Files: Makefile.am dhcp-files.c dhcp-local.h dhcp-log.c dhcp-parser.c dhcp-parser.h dhcp-util.c dhcp-varfile.c Added Files: dhcp-log.h Log Message: linked in file/parser routines to utility library --- NEW FILE: dhcp-log.h --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-log.h,v 1.1 2002/11/09 16:59:15 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. * * System logging functions. * */ #ifndef DHCP_LOG_H #define DHCP_LOG_H 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); #endif /* DHCP_LOG_H */ Index: Makefile.am =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/Makefile.am,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Makefile.am 3 Nov 2002 16:34:55 -0000 1.3 --- Makefile.am 9 Nov 2002 16:59:15 -0000 1.4 *************** *** 3,6 **** --- 3,7 ---- # Main source Makefile.am + CFLAGS = -Wall -Werror INCLUDES = @PCAP_INC@ @DNET_INC@ DEFS = @DEFS@ *************** *** 12,22 **** libdhcputil_la_SOURCES = dhcp-util.c \ - dhcp-util.h \ dhcp-stringbuffer.c \ dhcp-list.c \ dhcp-log.c \ ! dhcp-snprintf.c ! # dhcp-rawnet.c \ ! # dhcp-align.c \ # dhcp-com.c \ # dhcp-eth.c \ --- 13,27 ---- libdhcputil_la_SOURCES = dhcp-util.c \ dhcp-stringbuffer.c \ dhcp-list.c \ dhcp-log.c \ ! dhcp-snprintf.c \ ! dhcp-rtt.c \ ! dhcp-timer.c \ ! dhcp-varfile.c \ ! dhcp-parser.c \ ! dhcp-files.c ! # dhcp-rawnet.c ! # dhcp-align.c # dhcp-com.c \ # dhcp-eth.c \ *************** *** 25,30 **** # dhcp-arp.c \ # dhcp-icmp.c \ ! # dhcp-rtt.c \ ! # dhcp-interface.c # dhcp_sniff_SOURCES = \ --- 30,40 ---- # 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 = \ *************** *** 44,60 **** # dhcp-client-control.c \ # dhcp-client-conf.c \ - # dhcp-files.c \ # dhcp-client-states.c \ # dhcp-options-strings.c \ # dhcp-convert.c \ # dhcp-sysconf.c \ - # dhcp-packet-build.c \ - # dhcp-icmp-discovery.c \ - # dhcp-arp-discovery.c \ # dhcp-route.c \ ! # dhcp-globconf.c \ ! # dhcp-parser.c \ ! # dhcp-varfile.c \ ! # dhcp-timer.c # dhcp_client_LDADD = @PCAP_LIB@ @DNET_LIB@ --- 54,64 ---- # 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@ Index: dhcp-files.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-files.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** dhcp-files.c 29 Oct 2002 17:11:23 -0000 1.1.1.1 --- dhcp-files.c 9 Nov 2002 16:59:15 -0000 1.2 *************** *** 26,32 **** #define MODULE_NAME "dhcp-files" ! #include <dhcp-agent.h> ! #include <dhcp-util.h> ! #include <dhcp-files.h> static FILE *file_open_proc(const char *filename, char *cmode, int flags, mode_t mode) --- 26,31 ---- #define MODULE_NAME "dhcp-files" ! #include "dhcp-local.h" ! #include "dhcp-libutil.h" static FILE *file_open_proc(const char *filename, char *cmode, int flags, mode_t mode) Index: dhcp-local.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-local.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** dhcp-local.h 3 Nov 2002 16:34:55 -0000 1.1 --- dhcp-local.h 9 Nov 2002 16:59:15 -0000 1.2 *************** *** 37,51 **** #include <stdlib.h> #include <stdio.h> #include <sys/types.h> #include <sys/time.h> #include <string.h> #include <unistd.h> #include <syslog.h> #include <signal.h> ! #include <stdarg.h> ! #include <inttypes.h> #include <dnet.h> #include <pcap.h> --- 37,59 ---- #include <stdlib.h> #include <stdio.h> + #include <stdarg.h> #include <sys/types.h> + #include <sys/stat.h> #include <sys/time.h> + #include <sys/ioctl.h> + #include <sys/fcntl.h> + #include <sys/uio.h> + #include <inttypes.h> + #include <errno.h> #include <string.h> #include <unistd.h> #include <syslog.h> #include <signal.h> ! #include <time.h> ! #include <ctype.h> + #include <net/bpf.h> #include <dnet.h> #include <pcap.h> Index: dhcp-log.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-log.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-log.c 3 Nov 2002 16:34:55 -0000 1.3 --- dhcp-log.c 9 Nov 2002 16:59:15 -0000 1.4 *************** *** 46,50 **** } ! void info_log(const char *msg) { syslog(INFO_LEVEL, "%s", msg); --- 46,50 ---- } ! void info_log(const char *msg) { syslog(INFO_LEVEL, "%s", msg); Index: dhcp-parser.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-parser.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** dhcp-parser.c 29 Oct 2002 17:11:27 -0000 1.1.1.1 --- dhcp-parser.c 9 Nov 2002 16:59:15 -0000 1.2 *************** *** 20,34 **** * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. - * - * Parser driver. Here we can build custom parsers by plugging in - * the applicable functions for each single character token. A - * default parser with a 0 for a character is used as a fallback - * (and to mark the end of the parser driver) - * - * This parser will b0rk on something that's not printable and not even - * call the parse function. - * - * We build from the parser utility routines or we can pass our - * own. * */ --- 20,23 ---- *************** *** 36,45 **** #define MODULE_NAME "dhcp-parser" ! #include <dhcp-agent.h> ! #include <dhcp-util.h> ! #include <dhcp-stringbuffer.h> ! #include <dhcp-files.h> ! #include <dhcp-parser.h> static int is_valid_string_char(int c) { --- 25,34 ---- #define MODULE_NAME "dhcp-parser" ! #include "dhcp-local.h" ! #include "dhcp-libutil.h" ! ! #include "dhcp-parser.h" + /* is a valid string character. */ static int is_valid_string_char(int c) { *************** *** 53,56 **** --- 42,46 ---- } + /* the stream is EOF or an error occured. */ static token_t check_eof(parser_t *input) { *************** *** 84,87 **** --- 74,78 ---- } + /* read a quoted string. */ static token_t parse_get_quoted_string(parser_t *input) { *************** *** 130,133 **** --- 121,125 ---- } + /* read a string. */ static token_t parse_get_string(parser_t *input) { *************** *** 167,170 **** --- 159,163 ---- } + /* get the next atom. */ atom_t get_next_atom(parser_t *input) { *************** *** 246,249 **** --- 239,243 ---- } + /* create a parser instance. */ parser_t *create_parser(const char *filename) { Index: dhcp-parser.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-parser.h,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** dhcp-parser.h 29 Oct 2002 17:11:33 -0000 1.1.1.1 --- dhcp-parser.h 9 Nov 2002 16:59:15 -0000 1.2 *************** *** 28,31 **** --- 28,41 ---- #define DHCP_PARSER_H + typedef uint8_t token_t; + typedef uint8_t atom_t; + + extern void destroy_parser(parser_t *parser); + extern parser_t *create_parser(const char *filename); + extern atom_t get_next_atom(parser_t *input); + extern const char *parser_get_data(parser_t *input); + extern int parser_get_line_no(parser_t *parser); + + /* parser return values. */ #define PARSER_TOKEN_ERROR 0 #define PARSER_TOKEN_NEWLINE 1 *************** *** 41,58 **** #define PARSER_ATOM_EOF 4 ! typedef uint8_t token_t; ! typedef uint8_t atom_t; ! ! typedef struct { ! FILE *fp; ! int line_no; ! stringbuffer *data_buff; ! } parser_t; ! ! extern void destroy_parser(parser_t *parser); ! extern parser_t *create_parser(const char *filename); ! extern atom_t get_next_atom(parser_t *input); ! extern const char *parser_get_data(parser_t *input); ! extern int parser_get_line_no(parser_t *parser); #endif /* DHCP_PARSER_H */ --- 51,57 ---- #define PARSER_ATOM_EOF 4 ! /* Parse types. */ ! #define PARSE_SINGLE_STRING 1 ! #define PARSE_DOUBLE_STRINGS 2 #endif /* DHCP_PARSER_H */ Index: dhcp-util.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-util.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcp-util.c 3 Nov 2002 16:34:55 -0000 1.4 --- dhcp-util.c 9 Nov 2002 16:59:15 -0000 1.5 *************** *** 30,33 **** --- 30,35 ---- #include "dhcp-libutil.h" + #include "dhcp-log.h" + static uint8_t interactive = 1; static int verbosity_level = DEBUG_VERBOSITY_LEVEL; Index: dhcp-varfile.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-varfile.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** dhcp-varfile.c 29 Oct 2002 17:11:31 -0000 1.1.1.1 --- dhcp-varfile.c 9 Nov 2002 16:59:15 -0000 1.2 *************** *** 26,34 **** #define MODULE_NAME "dhcp-varfile" ! #include <dhcp-agent.h> ! #include <dhcp-util.h> ! #include <dhcp-files.h> ! #include <dhcp-parser.h> ! #include <dhcp-varfile.h> const char *varfile_get_name(varfile_t *varfile) --- 26,33 ---- #define MODULE_NAME "dhcp-varfile" ! #include "dhcp-local.h" ! #include "dhcp-libutil.h" ! ! #include "dhcp-parser.h" const char *varfile_get_name(varfile_t *varfile) |
From: <act...@us...> - 2002-11-04 00:44:23
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory usw-pr-cvs1:/tmp/cvs-serv27769 Removed Files: dhcp-varfile.h Log Message: varfile.h no longer needed --- dhcp-varfile.h DELETED --- |
From: <act...@us...> - 2002-11-03 16:39:25
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory usw-pr-cvs1:/tmp/cvs-serv32071 Added Files: dhcp-rawnet.c dhcp-librawnet.h Log Message: new rawnet code --- NEW FILE: dhcp-rawnet.c --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-rawnet.c,v 1.1 2002/11/03 16:39:22 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. * * Raw network module. * */ #define MODULE_NAME "dhcp-rawnet" #include <dhcp-rawnet.h> #include <dhcp-libutil.h> #include <dhcp-librawnet.h> #include <sys/ioctl.h> #include <sys/uio.h> #include <net/bpf.h> /************************ * Address Manipulation.* ************************/ /* get interface address. */ int rawnet_get_hw_addr(rawnet_t *net, eth_addr_t *addr) { /* are we using a fake address? */ if(net->fake_hw_addr != NULL) { memcpy(addr, net->fake_hw_addr->data, ETH_ADDR_LEN); return 0; } else { return(eth_get(net->eth, addr)); } } /* get real interface address skipping fake even if its available. */ int rawnet_get_real_hw_addr(rawnet_t *net, eth_addr_t *addr) { return(eth_get(net->eth, addr)); } /* get IP address. */ int rawnet_get_ip_addr(rawnet_t *net, ip_addr_t *addr) { return(interface_get_ip_addr(net->intf_handle, addr)); } /* get port number for named service. */ int rawnet_port_for_service(const char *serv, const char *proto) { struct servent *sv; setservent(0); if((sv = getservbyname(serv, proto)) == NULL) { ERROR_MESSAGE("rawnet: could not get service listing: %d", strerror(errno)); return -1; } return(sv->s_port); } /* * Initialization of packet capturing device. * */ static pcap_t *initialize_pcap_device(char *interface_name, char *filter_string, int promiscuous) { pcap_t *pcap; struct bpf_program filter; char errbuf[PCAP_ERRBUF_SIZE]; uint32_t mask = 0xffffffff; #if defined(HAVE_BPF_IMMEDIATE) int fd; u_int on = 1; #endif /* HAVE_BPF_IMMEDIATE */ /* Open packet capturing device. */ pcap = pcap_open_live(interface_name, SNAPLEN, promiscuous, 0, errbuf); if(pcap == NULL) { ERROR_MESSAGE("could not open pcap device: %s", pcap_geterr(pcap)); return NULL; } if(pcap_compile(pcap, &filter, filter_string, 1, mask) == -1) { ERROR_MESSAGE("could not compile pcap filter: %s", pcap_geterr(pcap)); pcap_close(pcap); return NULL; } if(pcap_setfilter(pcap, &filter) == -1) { ERROR_MESSAGE("could not compile pcap filter: %s", pcap_geterr(pcap)); pcap_close(pcap); return NULL; } pcap_freecode(&filter); #if defined(HAVE_BPF_IMMEDIATE) /* FreeBSD, and possibly other flavors with BPF need us to * set the descriptor non blocking with BIOCIMMEDIATE. */ if((fd = pcap_fileno(pcap)) < 0) { ERROR_MESSAGE("could not obtain pcap descriptor: %s", pcap_geterr(pcap)); pcap_close(pcap); return NULL; } if(ioctl(fd, BIOCIMMEDIATE, &on) < 0) { ERROR_MESSAGE("initialize_pcap_device", "could not set BIOCIMMEDIATE: %s", strerror(errno)); pcap_close(pcap); return NULL; } #endif /* HAVE_BPF_IMMEDIATE */ return pcap; } /* wrapper around interface handler routines. */ /* bring up interface, and assign ourselves the address passed. */ int rawnet_interface_up(rawnet_t *net, ip_addr_t addr, ip_addr_t netmask, int mtu) { if(interface_up(net->intf_handle, addr, netmask, mtu)) { ERROR_MESSAGE("could not bring interface up."); return -1; } memcpy(&net->cip_addr, &addr, IP_ADDR_LEN); /* set our IP address. */ return 0; } /* bring down interface. */ int rawnet_interface_down(rawnet_t *net) { if(interface_down(net->intf_handle)) { ERROR_MESSAGE("could not bring interface down."); return -1; } memset(&net->cip_addr, 0, IP_ADDR_LEN); /* clear our IP address -- this isn't very useful though. */ return 0; } /* Create the workhorse network module. */ rawnet_t *rawnet_create(const char *device, const char *filter, int dhcp_src_port, int dhcp_dst_port, int promiscuous) { rawnet_t *net; int retval; net = xcalloc(sizeof(rawnet_t)); net->src_port = dhcp_src_port; net->dst_port = dhcp_dst_port; net->device = xstrdup(device); net->pcap_filter = xstrdup(filter); net->packet_data = xcalloc(DEFAULT_MTU); /* XXX -- fixme make mtu configurable. */ net->promiscuous = promiscuous; /* get the interface handle for bringing it up or down and querying it. */ net->intf_handle = create_interface_control(net->device); if(net->intf_handle == NULL) { ERROR_MESSAGE("could not acquire interface handle"); rawnet_destroy(net); return NULL; } /* Is the interface up? */ retval = interface_is_up(net->intf_handle); if(retval == -1) { /* error on interface detection */ ERROR_MESSAGE("error on interface detection for device: %s", device); rawnet_destroy(net); return NULL; } if(retval == 0) { /* interface down */ /* bring it up with dum values. */ if(rawnet_interface_up(net, 0, 0xffffff, -1)) { ERROR_MESSAGE("error trying to bring device up: %s", device); rawnet_destroy(net); return NULL; } } /* any other value of retval and the interface is already up. */ /* Get the interface and make sure its an ethernet interface or * else we're hosed. */ net->eth = eth_open(device); if(net->eth == NULL) { ERROR_MESSAGE("device not available or supported: %s : %s", device, strerror(errno)); rawnet_destroy(net); return NULL; } /* get pcap handler */ net->pcap = initialize_pcap_device(net->device, net->pcap_filter, promiscuous); if(net->pcap == NULL) { ERROR_MESSAGE("could not initialize pcap device for: %s", device); return NULL; } net->pcap_fd = pcap_fileno(net->pcap); if(net->pcap_fd < 0) { ERROR_MESSAGE("could not get pcap descriptor for: %s: %s", device, pcap_geterr(net->pcap)); rawnet_destroy(net); return NULL; } /* When we first initialize we use a real hardware * address. This can be changed later to a fake hardware * address if the system supports it. */ rawnet_get_hw_addr(net, &net->chw_addr); rawnet_get_ip_addr(net, &net->cip_addr); /* Packet handler objects. * * These exit on failure. * */ net->ether_p = eth_create(); net->ip_p = ip_create(); net->arp_p = arp_create(); net->icmp_p = icmp_create(); net->udp_p = udp_create(); net->dhcp_p = dhcp_create(); return net; } /* Use a fake hardware address (diagnostic purposes). We need to * reinitialize our rawnet to use promiscuous packet capturing * since we do want to accept packets for this hardware * address. */ int rawnet_use_fake_hw_addr(rawnet_t *net, char *mac_string) { unsigned char mac_addr[ETH_ADDR_LEN]; net->fake_hw_addr = xmalloc(sizeof(eth_addr_t)); if(hex_string_to_value(mac_string, mac_addr)) { ERROR_MESSAGE("malformed mac address: %s", mac_string); xfree(net->fake_hw_addr); net->fake_hw_addr = NULL; return -1; } memcpy(net->chw_addr.data, mac_addr, ETH_ADDR_LEN); /* now reinitialize in promiscuous mode */ reinitialize_rawnet(net, 1); return 0; } void rawnet_destroy(rawnet_t *net) { if(net->eth != NULL) eth_close(net->eth); if(net->intf_handle) destroy_interface_control(net->intf_handle); if(net->pcap != NULL) pcap_close(net->pcap); if(net->device) xfree(net->device); if(net->packet_data) xfree(net->packet_data); if(net->pcap_filter) xfree(net->pcap_filter); if(net->ether_p) eth_destroy(net->ether_p); if(net->ip_p) ip_destroy(net->ip_p); if(net->arp_p) arp_destroy(net->arp_p); if(net->icmp_p) icmp_destroy(net->icmp_p); if(net->udp_p) udp_destroy(net->udp_p); if(net->dhcp_p) dhcp_destroy(net->dhcp_p); xfree(net); return; } /* The rawnet up and down routines don't mess with the interface * intentionally. They're meant only to close our packet capturing * and sending devices so as to free up system resources. */ /* Bring pcap/dnet up and down. * Useful for wait states when * we don't want our packet buffers * to fill up. */ void rawnet_down(rawnet_t *net) { if(net->pcap != NULL) { pcap_close(net->pcap); net->pcap = NULL; } if(net->eth != NULL) { eth_close(net->eth); net->eth = NULL; } return; } int rawnet_up(rawnet_t *net) { net->pcap = initialize_pcap_device(net->device, net->pcap_filter, net->promiscuous); if(net->pcap == NULL) { ERROR_MESSAGE("could not initialize pcap on device: %s", net->device); return -1; } if((net->pcap_fd = pcap_fileno(net->pcap)) < 0) { ERROR_MESSAGE("could not get pcap descriptor for: %s: %s", net->device, pcap_geterr(net->pcap)); rawnet_down(net); return -1; } net->eth = eth_open(net->device); if(net->eth == NULL) { ERROR_MESSAGE("could not get ethernet handler on device: %s", net->device); rawnet_down(net); return -1; } return 0; } void reinitialize_rawnet(rawnet_t *net, int promiscuous) { net->promiscuous = promiscuous; rawnet_down(net); rawnet_up(net); return; } /* * rawnet get packet: * we already expect a filter to only allow * the following types of packets: * ARP, UDP, and ICMP. * * Anything else is considered malformed. * */ int rawnet_get_packet(rawnet_t *net, struct timeval *tm) { const unsigned char *packet; struct pcap_pkthdr pkthdr; int len; fd_set read_set; int retval; net->type = RAWNET_UNKNOWN; while(1) { FD_ZERO(&read_set); FD_SET(net->pcap_fd, &read_set); retval = select((net->pcap_fd + 1), &read_set, NULL, NULL, tm); if(retval == 0) return RAWNET_TIMEOUT; if(retval < 0) return RAWNET_PCAP_ERROR; packet = pcap_next(net->pcap, &pkthdr); if(packet == NULL) continue; /* BPF may return 1 when there really isn't any packet for us. * is this because we're notified prior to filtering? * pcap only returns NULL on EWOULDBLOCK for bpf -- even though * in debugging I *never* get that errno value :| */ else break; } /* Set timestamp. */ #if defined(HAVE_BPF_TIMEVAL) /* This is an ugly hack -- why oh why did OpenBSD insist on * creating its own bpf_timeval struct with unsigned values * as opposed to the common UNIX timeval which has signed values. * * * *sigh* * * There really isn't any clean way around this apart from grabbing * our own timestamp instead of using the bpf one. This is inaccurate * but until OpenBSD fixes their braindamage they'll just have to * deal with the inaccuracy. Anything else would be too damaging * to the other UNIX flavors. */ gettimeofday(&net->tstamp, NULL); #else /* HAVE_BPF_TIMEVAL */ net->tstamp = pkthdr.ts; #endif /* HAVE_BPF_TIMEVAL */ /* Read ethernet header and switch on type. * * Fails if malformed or insufficient length. */ if(eth_read_packet_image(net->ether_p, packet, pkthdr.caplen) < 0) return RAWNET_MALFORMED_PACKET; packet += ETH_HDR_LEN; pkthdr.caplen -= ETH_HDR_LEN; switch(eth_get_type(net->ether_p)) { case ETH_TYPE_ARP: if(arp_read_packet_image(net->arp_p, packet, pkthdr.caplen) < 0) return RAWNET_MALFORMED_PACKET; net->type = RAWNET_ARP; return RAWNET_OK; case ETH_TYPE_IP: if(ip_read_packet_image(net->ip_p, packet, pkthdr.caplen) < 0) return RAWNET_MALFORMED_PACKET; len = ip_get_hl(net->ip_p); packet += len; pkthdr.caplen -= len; switch(ip_get_proto(net->ip_p)) { case IP_PROTO_UDP: if(udp_read_packet_image(net->udp_p, packet, pkthdr.caplen) < 0) return RAWNET_MALFORMED_PACKET; /* We assume any UDP packet does contain a DHCP packet. * So try and grab it here. */ packet += UDP_HDR_LEN; pkthdr.caplen -= UDP_HDR_LEN; /* purge dhcp so we get rid of old options. */ dhcp_purge(net->dhcp_p); if(dhcp_read_packet_image(net->dhcp_p, packet, pkthdr.caplen) < 0) return RAWNET_MALFORMED_PACKET; net->type = RAWNET_DHCP; return RAWNET_OK; case IP_PROTO_ICMP: if(icmp_read_packet_image(net->icmp_p, packet, pkthdr.caplen) < 0) return RAWNET_MALFORMED_PACKET; net->type = RAWNET_ICMP; return RAWNET_OK; default: break; } default: break; } return RAWNET_UNHANDLED; } int rawnet_send_packet(rawnet_t *net) { if(eth_send(net->eth, net->packet_data, net->packet_len) != net->packet_len) { ERROR_MESSAGE("could not write to device: %s : %s", net->device, strerror(errno)); return -1; } return 0; } /* Just update the seconds field. * * FIXME: mod this so that it hooks * into the rest of the framework. * right now it's error prone. */ void rawnet_dhcp_update(rawnet_t *net, time_t seconds) { unsigned char *packet; uint16_t secs = htons(seconds); /* FIX ME: we're assuming the ip packet header * has no options. */ packet = (net->packet_data + ETH_HDR_LEN + IP_HDR_LEN + UDP_HDR_LEN); packet += 8; /* to seconds field. */ memcpy(packet, &secs, 2); ip_checksum((net->packet_data + ETH_HDR_LEN), (net->packet_len - ETH_HDR_LEN)); return; } /* * We can ask rawnet to validate for us. * Insert checks here to make sure * the packet is as kosher as christmas * (chicken soup). * */ int rawnet_is_valid(rawnet_t *net) { switch(net->type) { case RAWNET_DHCP: if(!dhcp_valid_magic_cookie(net->dhcp_p)) break; else return 1; default: /* todo: we need more validation on other packets. */ break; } return 0; } /* Generic send and wait for reply: * * Calls update() after timeout. * Calls check() on every packet coming in. * */ int rawnet_packet_transact(rawnet_t *net, void *arg, void (*update)(void *arg), int (*check)(void *arg), time_t max_timeout) { rtt_t *rtt; int retval; unsigned char send_packet = 1; struct timeval timeout; /* create rtt mechanism. */ rtt = rtt_create(max_timeout); /* We loop here and re-send packets if we timeout, or fail a * check on an incoming packets. */ while(1) { if(send_packet) { send_packet = 0; if(rawnet_send_packet(net) < 0) { rtt_destroy(rtt); ERROR_MESSAGE("could not dispatch packet"); return RAWNET_ERROR; } } timeout = rtt_get_timeout(rtt); retval = rawnet_get_packet(net, &timeout); switch(retval) { case RAWNET_PCAP_ERROR: rtt_destroy(rtt); ERROR_MESSAGE("could not wait for packets on: %s", net->device); return RAWNET_ERROR; case RAWNET_TIMEOUT: rtt_timeout(rtt); if(!rtt_can_retry(rtt)) { rtt_destroy(rtt); return RAWNET_TIMEOUT; } if(update) /* update if needed. only called after timeout. */ update(arg); send_packet = 1; break; case RAWNET_OK: if(!check) /* no check? return 0 anyway (we want * any packet it seems). */ return 0; if(check(arg)) { /* if we have a check * then check packet. */ rtt_destroy(rtt); return RAWNET_OK; /* it's good. let's return. */ } /* otherwise we should just continue. */ break; case RAWNET_UNHANDLED: case RAWNET_MALFORMED_PACKET: break; default: FATAL_MESSAGE("rawnet: invalid return from rawnet_get_packet() -- this is a bug report it please"); } } } const char *rawnet_get_device_name(rawnet_t *net) { return net->device; } --- NEW FILE: dhcp-librawnet.h --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-librawnet.h,v 1.1 2002/11/03 16:39:22 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_LIBRAWNET_H #define DHCP_LIBRAWNET_H /* data structures. */ /* rtt struct. */ typedef struct rtt { struct timeval timeout; time_t max_timeout; time_t start_time; time_t elapsed_time; } rtt_t; /* 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 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; /* * 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. * */ uint8_t 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; /* constants. */ /* 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 /* Reasonable defaults in case services db isn't up to date. */ #define BOOTP_CLIENT 68 #define BOOTP_SERVER 67 /* timeout as per rfc2131 */ #define MILLISECOND_TIMEOUT 4000 #define MILLISECOND_RAND_TIMEOUT 1000 /* macros. */ /* time macros. */ #define SECS_TO_MSECS(x) (x * 1000) #define MSECS_TO_SECS(x) (x/1000) #define MSECS_TO_SECS_REM(x) (x%1000) /* prototypes. */ /* 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); /* 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); extern int port_for_service(const char *serv, const char *proto); /* RTT mechanism. */ extern rtt_t *rtt_create(time_t max_timeout); extern struct timeval rtt_get_timeout(rtt_t *rtt); extern void rtt_timeout(rtt_t *rtt); extern int rtt_can_retry(rtt_t *rtt); extern void rtt_destroy(rtt_t *rtt); #endif /* DHCP_LIBRAWNET_H */ |
From: <act...@us...> - 2002-11-03 16:36:14
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory usw-pr-cvs1:/tmp/cvs-serv31295 Removed Files: dhcp-net.c Log Message: no need for dhcp-net.c --- dhcp-net.c DELETED --- |
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory usw-pr-cvs1:/tmp/cvs-serv30990 Modified Files: Makefile.am dhcp-util.c dhcp-stringbuffer.c dhcp-snprintf.c dhcp-log.c dhcp-list.c dhcp-libutil.h Added Files: dhcp-local.h Removed Files: dhcp-util.h Log Message: redid utility library layout and some additional minor changes --- NEW FILE: dhcp-local.h --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-local.h,v 1.1 2002/11/03 16:34:55 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. * * Local header file. Here we set all local settings and include * system headers. * */ #ifndef DHCP_LOCAL_H #define DHCP_LOCAL_H #define __STDC_FORMAT_MACROS /* we need the C99 type macros. */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <stdlib.h> #include <stdio.h> #include <sys/types.h> #include <sys/time.h> #include <string.h> #include <unistd.h> #include <syslog.h> #include <signal.h> #include <stdarg.h> #include <inttypes.h> #include <dnet.h> #include <pcap.h> /* XXX -- ??? -- what's the deal with this? must remember. */ /* must be placed in main source of each binary. * if not available. */ extern const char *__progname; #endif /* DHCP_LOCAL_H */ Index: Makefile.am =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/Makefile.am,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Makefile.am 30 Oct 2002 05:00:46 -0000 1.2 --- Makefile.am 3 Nov 2002 16:34:55 -0000 1.3 *************** *** 9,33 **** # Programs we are compiling. #bin_PROGRAMS = dhcp-sniff dhcp-client ! lib_LTLIBRARIES = libutil.la ! ! libutil_la_SOURCES = dhcp-util.c dhcp-util.h \ ! dhcp-stringbuffer.c \ ! dhcp-list.c \ ! dhcp-log.c \ ! dhcp-snprintf.c \ ! dhcp-libutil.h ! # Main network code. ! # RAWNET_SOURCES = \ ! # dhcp-net.c \ ! # dhcp-align.c \ ! # dhcp-com.c \ ! # dhcp-eth.c \ ! # dhcp-ip.c \ ! # dhcp-udp.c \ ! # dhcp-arp.c \ ! # dhcp-icmp.c \ ! # dhcp-rtt.c \ ! dhcp-interface.c # dhcp_sniff_SOURCES = \ --- 9,30 ---- # Programs we are compiling. #bin_PROGRAMS = dhcp-sniff dhcp-client ! lib_LTLIBRARIES = libdhcputil.la ! libdhcputil_la_SOURCES = dhcp-util.c \ ! dhcp-util.h \ ! dhcp-stringbuffer.c \ ! dhcp-list.c \ ! dhcp-log.c \ ! dhcp-snprintf.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-rtt.c \ ! # dhcp-interface.c # dhcp_sniff_SOURCES = \ Index: dhcp-util.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-util.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-util.c 30 Oct 2002 05:11:17 -0000 1.3 --- dhcp-util.c 3 Nov 2002 16:34:55 -0000 1.4 *************** *** 27,32 **** #define MODULE_NAME "dhcp-util" ! #include <dhcp-util.h> ! #include <dhcp-libutil.h> static uint8_t interactive = 1; --- 27,32 ---- #define MODULE_NAME "dhcp-util" ! #include "dhcp-local.h" ! #include "dhcp-libutil.h" static uint8_t interactive = 1; *************** *** 455,458 **** --- 455,462 ---- } + /* Random number generation. * + * We're interfacing into dnet's code * + * here. */ + static rand_t *ran_gen = NULL; *************** *** 479,482 **** --- 483,487 ---- } + /* timeval difference. */ struct timeval timeval_diff(struct timeval begin, struct timeval end) { *************** *** 588,606 **** return 1; - } - - /* get port number for named service. */ - int port_for_service(const char *serv, const char *proto) - { - struct servent *sv; - - setservent(0); - - if((sv = getservbyname(serv, proto)) == NULL) { - ERROR_MESSAGE("rawnet: could not get service listing: %d", strerror(errno)); - return -1; - } - - return(sv->s_port); } --- 593,596 ---- Index: dhcp-stringbuffer.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-stringbuffer.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-stringbuffer.c 30 Oct 2002 05:00:46 -0000 1.2 --- dhcp-stringbuffer.c 3 Nov 2002 16:34:55 -0000 1.3 *************** *** 33,38 **** #define MODULE_NAME "dhcp-stringbuffer" ! #include <dhcp-util.h> ! #include <dhcp-libutil.h> /* * * * * * * * * * * * * --- 33,38 ---- #define MODULE_NAME "dhcp-stringbuffer" ! #include "dhcp-local.h" ! #include "dhcp-libutil.h" /* * * * * * * * * * * * * *************** *** 127,132 **** void destroy_stringbuffer(stringbuffer *sb) { ! free(sb->buf); ! free(sb); } --- 127,132 ---- void destroy_stringbuffer(stringbuffer *sb) { ! xfree(sb->buf); ! xfree(sb); } Index: dhcp-snprintf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-snprintf.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** dhcp-snprintf.c 29 Oct 2002 17:11:29 -0000 1.1.1.1 --- dhcp-snprintf.c 3 Nov 2002 16:34:55 -0000 1.2 *************** *** 56,60 **** --- 56,62 ---- **************************************************************/ + #ifdef HAVE_CONFIG_H #include "config.h" + #endif /* HAVE_CONFIG_H */ #if !defined(HAVE_SNPRINTF) || !defined(HAVE_VSNPRINTF) Index: dhcp-log.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-log.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-log.c 30 Oct 2002 05:00:46 -0000 1.2 --- dhcp-log.c 3 Nov 2002 16:34:55 -0000 1.3 *************** *** 25,30 **** */ ! #include <dhcp-util.h> ! #include <dhcp-libutil.h> void init_log(const char *s) --- 25,30 ---- */ ! #include "dhcp-local.h" ! #include "dhcp-libutil.h" void init_log(const char *s) Index: dhcp-list.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-list.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-list.c 30 Oct 2002 05:00:46 -0000 1.2 --- dhcp-list.c 3 Nov 2002 16:34:55 -0000 1.3 *************** *** 24,29 **** #define MODULE_NAME "dhcp-list" ! #include <dhcp-util.h> ! #include <dhcp-libutil.h> list_t *add_to_list(list_t *head, void *datum) --- 24,29 ---- #define MODULE_NAME "dhcp-list" ! #include "dhcp-local.h" ! #include "dhcp-libutil.h" list_t *add_to_list(list_t *head, void *datum) Index: dhcp-libutil.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-libutil.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-libutil.h 30 Oct 2002 05:11:16 -0000 1.2 --- dhcp-libutil.h 3 Nov 2002 16:34:55 -0000 1.3 *************** *** 101,105 **** extern const char *getprogname(void); extern int resolv(char *address, uint32_t *addr); - extern int port_for_service(const char *serv, const char *proto); extern int is_seven_bit_clean(const char *data, int len); --- 101,104 ---- --- dhcp-util.h DELETED --- |
From: <act...@us...> - 2002-10-30 05:11:19
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory usw-pr-cvs1:/tmp/cvs-serv9609/src Modified Files: dhcp-libutil.h dhcp-util.c Log Message: interactive mode setter and update to some type definitions Index: dhcp-libutil.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-libutil.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** dhcp-libutil.h 30 Oct 2002 05:00:46 -0000 1.1 --- dhcp-libutil.h 30 Oct 2002 05:11:16 -0000 1.2 *************** *** 41,46 **** /* string buffer object. */ typedef struct { ! int len; ! int capacity; char *buf; } stringbuffer; --- 41,46 ---- /* string buffer object. */ typedef struct { ! size_t len; ! size_t capacity; char *buf; } stringbuffer; *************** *** 136,139 **** --- 136,142 ---- extern void stringbuffer_align(stringbuffer *sb, int begin, int end); extern int stringbuffer_getlen(stringbuffer *sb); + + /* interactive mode switch. */ + void set_interactive(uint8_t interactive_arg); /* constants. */ Index: dhcp-util.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-util.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-util.c 30 Oct 2002 05:00:46 -0000 1.2 --- dhcp-util.c 30 Oct 2002 05:11:17 -0000 1.3 *************** *** 30,34 **** #include <dhcp-libutil.h> ! static int interactive = 1; static int verbosity_level = DEBUG_VERBOSITY_LEVEL; --- 30,34 ---- #include <dhcp-libutil.h> ! static uint8_t interactive = 1; static int verbosity_level = DEBUG_VERBOSITY_LEVEL; *************** *** 560,563 **** --- 560,564 ---- } + /* remove alarm. */ void remove_alarm(void) { *************** *** 575,578 **** --- 576,580 ---- } + /* check for seven bit cleanliness. */ int is_seven_bit_clean(const char *data, int len) { *************** *** 588,593 **** } ! /* Get port number for named service. */ ! int port_for_service(const char *serv, const char *proto) { --- 590,594 ---- } ! /* get port number for named service. */ int port_for_service(const char *serv, const char *proto) { *************** *** 628,630 **** --- 629,638 ---- return 0; + } + + void set_interactive(uint8_t interactive_arg) + { + /* set to 1 or 0. */ + interactive = interactive_arg; + return; } |
From: <act...@us...> - 2002-10-30 05:02:28
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv7096 Modified Files: README Log Message: textual fixes for new binary names Index: README =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/README,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** README 29 Oct 2002 17:11:02 -0000 1.1.1.1 --- README 30 Oct 2002 05:02:26 -0000 1.2 *************** *** 66,88 **** To uninstall dhcp-agent just type "make uninstall" ! Using dhcpsniff to sniff for packets. ------------------------------------- ! Read the man page for dhcpsniff for command line options. ! Simply run dhcpsniff with no arguments to have it sniff the first ethernet interface it finds. You need to run this as root since it needs access to a packet capturing device. ! Using dhcpclient ---------------- ! Read the man page for dhcpclient for command line options. ! dhcpclient currently only sets up the interface, routing, and domain name system if the appropriate DHCP options are received. More options will be added later. ! dhcpclient is still a bit finnicky about which interface it picks. Use the -i option to force it to choose an interface. Or down the ethernet interface you wish to use and it will --- 66,88 ---- To uninstall dhcp-agent just type "make uninstall" ! Using dhcp-sniff to sniff for packets. ------------------------------------- ! Read the man page for dhcp-sniff for command line options. ! Simply run dhcp-sniff with no arguments to have it sniff the first ethernet interface it finds. You need to run this as root since it needs access to a packet capturing device. ! Using dhcp-client ---------------- ! Read the man page for dhcp-client for command line options. ! dhcp-client currently only sets up the interface, routing, and domain name system if the appropriate DHCP options are received. More options will be added later. ! dhcp-client is still a bit finnicky about which interface it picks. Use the -i option to force it to choose an interface. Or down the ethernet interface you wish to use and it will |
From: <act...@us...> - 2002-10-30 05:02:13
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv7024 Modified Files: LICENSE Log Message: license updated for 2002 Index: LICENSE =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/LICENSE,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** LICENSE 29 Oct 2002 17:11:02 -0000 1.1.1.1 --- LICENSE 30 Oct 2002 05:02:11 -0000 1.2 *************** *** 1,3 **** ! Copyright 2001 Thamer Alharbash <tm...@wh...> Redistribution and use in source and binary forms, with or without --- 1,3 ---- ! Copyright 2002 Thamer Alharbash <tm...@wh...> Redistribution and use in source and binary forms, with or without |
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory usw-pr-cvs1:/tmp/cvs-serv6635/src Modified Files: Makefile.am dhcp-list.c dhcp-log.c dhcp-stringbuffer.c dhcp-util.c dhcp-util.h Added Files: dhcp-libutil.h Removed Files: dhcp-stringbuffer.h Log Message: setup for making a utility library -- zorched makefile.am temporarily until this conversion is over --- NEW FILE: dhcp-libutil.h --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-libutil.h,v 1.1 2002/10/30 05:00:46 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. * * External interface header file: include this to use the * utility library. * */ #ifndef DHCP_LIBUTIL_H #define DHCP_LIBUTIL_H /* * * * * * * * * * * * Data structures. * * * * * * * * * * * */ /* list object. */ typedef struct list { struct list *next; void *data; } list_t; /* string buffer object. */ typedef struct { int len; int capacity; char *buf; } stringbuffer; /* prototypes. */ /* in case strdup is not available. */ # ifndef HAVE_STRDUP extern char *strdup(char *s); # endif /* HAVE_STRDUP */ /* messaging. */ extern void error_message(const char *func_name, const char *fmt, ...); extern void fatal_message(const char *func_name, const char *fmt, ...); extern void info_message(const char *fmt, ...); extern void warn_message(char *fmt, ...); extern void debug_message(const char *module_name, const char *func, const char *file, const char *fmt, ...); /* verbosity levels. */ extern int get_verbosity_level(void); extern int set_verbosity_level(int verbosity_level_to_set); /* dynamic allocation wrappers. */ extern void *xmalloc(size_t size); extern void *xcalloc(size_t size); extern void xfree(void *p); extern void *xrealloc(void *p, size_t size); /* signal/interrupt handlers. */ extern int check_for_interrupts(void); extern void suspend_for_interrupts(void); extern void block_interrupts(void); extern void add_interrupt_handler(int sigtype, void (*sighandler)(int)); extern void remove_interrupt(int sig); /* alarm handlers. */ extern int had_alarm(void); extern void set_alarm(struct timeval alarm_time); extern void remove_alarm(void); /* string routines -- XXX FIXME: we eventually want everything in * stringbuffer */ extern char *splice_string(const char *s1, const char *s2); extern char *splice_many_strings(int num, char *s, ...); extern int string_matches(const char *s1, const char *s2); extern int hex_string_to_value(char *string, unsigned char *dst); extern int is_string(const char *string, int len); extern char *xstrdup(const char *string); /* random number gen. */ extern uint16_t get_random_uint16(void); extern uint32_t get_random_uint32(void); /* misc. */ extern struct timeval timeval_diff(struct timeval begin, struct timeval end); extern const char *getprogname(void); extern int resolv(char *address, uint32_t *addr); extern int port_for_service(const char *serv, const char *proto); extern int is_seven_bit_clean(const char *data, int len); /* 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); /* 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 *)); /* stringbuffer. */ extern stringbuffer *create_stringbuffer(void); extern void destroy_stringbuffer(stringbuffer *sb); extern void stringbuffer_append(stringbuffer *sb, const char *s); extern stringbuffer *stringbuffer_trim_whitespace(stringbuffer *sb); extern char *stringbuffer_get_last_occurance(stringbuffer *sb, char c); extern void stringbuffer_trim_newline(stringbuffer *sb); extern const char *stringbuffer_getstring(stringbuffer *sb); extern void stringbuffer_aprintf(stringbuffer *sb, const char *fmt, ...); extern void stringbuffer_aprintf_align(stringbuffer *sb, int begin, int end, const char *fmt, ...); extern void stringbuffer_avprintf(stringbuffer *sb, const char *fmt, va_list ap); extern void stringbuffer_append_c(stringbuffer *sb, char c); extern void stringbuffer_clear(stringbuffer *sb); extern const char *stringbuffer_getnextline(stringbuffer *sb, const char *cptr); extern void stringbuffer_marknewlines(stringbuffer *sb); extern void stringbuffer_set(stringbuffer *dest, const char *s); extern void stringbuffer_align(stringbuffer *sb, int begin, int end); extern int stringbuffer_getlen(stringbuffer *sb); /* constants. */ /* stringbuffer chunk allocation size. */ #define STRINGBUFFER_CHUNKSIZE 16 /* Line length for messages before breaking into a new line. */ #define MESSAGE_LINE_LENGTH 60 /* macros. */ /* log message macros. */ #define INFO_MESSAGE(...) { info_message(__VA_ARGS__); } #define ERROR_MESSAGE(...) { error_message(__func__, __VA_ARGS__); } #define WARN_MESSAGE(...) { warn_message(__VA_ARGS__); } #define FATAL_MESSAGE(...) { fatal_message(__func__, __VA_ARGS__); } #define DEBUG_MESSAGE(...) { debug_message(MODULE_NAME, __func__, __FILE__, __VA_ARGS__); } /* Verbosity levels. */ enum verbosity { QUIET_VERBOSITY_LEVEL = 0, ERROR_VERBOSITY_LEVEL, NORMAL_VERBOSITY_LEVEL, WARNING_VERBOSITY_LEVEL, DEBUG_VERBOSITY_LEVEL, MAX_VERBOSITY_LEVEL }; /* 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 */ #endif /* DHCP_LIBUTIL_H */ Index: Makefile.am =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/Makefile.am,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** Makefile.am 29 Oct 2002 17:11:32 -0000 1.1.1.1 --- Makefile.am 30 Oct 2002 05:00:46 -0000 1.2 *************** *** 8,66 **** # Programs we are compiling. ! bin_PROGRAMS = dhcp-sniff dhcp-client ! # Common sources. ! COMMON_SOURCES = \ ! dhcp-util.c dhcp-util.h \ ! dhcp-stringbuffer.c \ ! dhcp-list.c \ ! dhcp-log.c \ ! dhcp-snprintf.c # Main network code. ! RAWNET_SOURCES = \ ! dhcp-net.c \ ! dhcp-align.c \ ! dhcp-com.c \ ! dhcp-eth.c \ ! dhcp-ip.c \ ! dhcp-udp.c \ ! dhcp-arp.c \ ! dhcp-icmp.c \ ! dhcp-rtt.c \ dhcp-interface.c ! 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-files.c \ ! dhcp-client-states.c \ ! dhcp-options-strings.c \ ! dhcp-convert.c \ ! dhcp-sysconf.c \ ! dhcp-packet-build.c \ ! dhcp-icmp-discovery.c \ ! dhcp-arp-discovery.c \ ! dhcp-route.c \ ! dhcp-globconf.c \ ! dhcp-parser.c \ ! dhcp-varfile.c \ ! dhcp-timer.c ! dhcp_client_LDADD = @PCAP_LIB@ @DNET_LIB@ ! dhcp_sniff_LDADD = @PCAP_LIB@ @DNET_LIB@ noinst_HEADERS = dhcp-agent.h ../config.h --- 8,66 ---- # Programs we are compiling. ! #bin_PROGRAMS = dhcp-sniff dhcp-client ! lib_LTLIBRARIES = libutil.la ! libutil_la_SOURCES = dhcp-util.c dhcp-util.h \ ! dhcp-stringbuffer.c \ ! dhcp-list.c \ ! dhcp-log.c \ ! dhcp-snprintf.c \ ! dhcp-libutil.h # Main network code. ! # RAWNET_SOURCES = \ ! # dhcp-net.c \ ! # dhcp-align.c \ ! # dhcp-com.c \ ! # dhcp-eth.c \ ! # dhcp-ip.c \ ! # dhcp-udp.c \ ! # dhcp-arp.c \ ! # dhcp-icmp.c \ ! # dhcp-rtt.c \ dhcp-interface.c ! # 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-files.c \ ! # dhcp-client-states.c \ ! # dhcp-options-strings.c \ ! # dhcp-convert.c \ ! # dhcp-sysconf.c \ ! # dhcp-packet-build.c \ ! # dhcp-icmp-discovery.c \ ! # dhcp-arp-discovery.c \ ! # dhcp-route.c \ ! # dhcp-globconf.c \ ! # dhcp-parser.c \ ! # dhcp-varfile.c \ ! # dhcp-timer.c ! # dhcp_client_LDADD = @PCAP_LIB@ @DNET_LIB@ ! # dhcp_sniff_LDADD = @PCAP_LIB@ @DNET_LIB@ noinst_HEADERS = dhcp-agent.h ../config.h Index: dhcp-list.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-list.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** dhcp-list.c 29 Oct 2002 17:11:25 -0000 1.1.1.1 --- dhcp-list.c 30 Oct 2002 05:00:46 -0000 1.2 *************** *** 24,29 **** #define MODULE_NAME "dhcp-list" - #include <dhcp-agent.h> #include <dhcp-util.h> list_t *add_to_list(list_t *head, void *datum) --- 24,29 ---- #define MODULE_NAME "dhcp-list" #include <dhcp-util.h> + #include <dhcp-libutil.h> list_t *add_to_list(list_t *head, void *datum) Index: dhcp-log.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-log.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** dhcp-log.c 29 Oct 2002 17:11:25 -0000 1.1.1.1 --- dhcp-log.c 30 Oct 2002 05:00:46 -0000 1.2 *************** *** 25,29 **** */ ! #include <dhcp-agent.h> void init_log(const char *s) --- 25,30 ---- */ ! #include <dhcp-util.h> ! #include <dhcp-libutil.h> void init_log(const char *s) Index: dhcp-stringbuffer.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-stringbuffer.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** dhcp-stringbuffer.c 29 Oct 2002 17:11:30 -0000 1.1.1.1 --- dhcp-stringbuffer.c 30 Oct 2002 05:00:46 -0000 1.2 *************** *** 33,38 **** #define MODULE_NAME "dhcp-stringbuffer" - #include <dhcp-agent.h> #include <dhcp-util.h> /* * * * * * * * * * * * * --- 33,38 ---- #define MODULE_NAME "dhcp-stringbuffer" #include <dhcp-util.h> + #include <dhcp-libutil.h> /* * * * * * * * * * * * * Index: dhcp-util.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-util.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** dhcp-util.c 29 Oct 2002 17:11:31 -0000 1.1.1.1 --- dhcp-util.c 30 Oct 2002 05:00:46 -0000 1.2 *************** *** 27,33 **** #define MODULE_NAME "dhcp-util" - #include <dhcp-agent.h> #include <dhcp-util.h> static int verbosity_level = DEBUG_VERBOSITY_LEVEL; --- 27,34 ---- #define MODULE_NAME "dhcp-util" #include <dhcp-util.h> + #include <dhcp-libutil.h> + static int interactive = 1; static int verbosity_level = DEBUG_VERBOSITY_LEVEL; Index: dhcp-util.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-util.h,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** dhcp-util.h 29 Oct 2002 17:11:34 -0000 1.1.1.1 --- dhcp-util.h 30 Oct 2002 05:00:46 -0000 1.2 *************** *** 21,24 **** --- 21,27 ---- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * + * Internal libutil header. We include what we need from the + * system here. + * */ *************** *** 26,102 **** #define DHCP_UTIL_H ! #include <dhcp-stringbuffer.h> ! ! /* Utility functions. */ ! ! /* in case strdup is not available. */ ! ! # ifndef HAVE_STRDUP ! extern char *strdup(char *s); ! # endif /* HAVE_STRDUP */ ! ! /* messaging. */ ! extern void error_message(const char *func_name, const char *fmt, ...); ! extern void fatal_message(const char *func_name, const char *fmt, ...); ! extern void info_message(const char *fmt, ...); ! extern void warn_message(char *fmt, ...); ! extern void debug_message(const char *module_name, const char *func, const char *file, const char *fmt, ...); ! ! /* verbosity levels. */ ! extern int get_verbosity_level(void); ! extern int set_verbosity_level(int verbosity_level_to_set); ! ! /* dynamic allocation wrappers. */ ! extern void *xmalloc(size_t size); ! extern void *xcalloc(size_t size); ! extern void xfree(void *p); ! extern void *xrealloc(void *p, size_t size); ! /* signal/interrupt handlers. */ ! extern int check_for_interrupts(void); ! extern void suspend_for_interrupts(void); ! extern void block_interrupts(void); ! extern void add_interrupt_handler(int sigtype, void (*sighandler)(int)); ! extern void remove_interrupt(int sig); ! ! /* alarm handlers. */ ! extern int had_alarm(void); ! extern void set_alarm(struct timeval alarm_time); ! extern void remove_alarm(void); ! ! /* sigio handlers -- FIXME: we don't want these anymore really. */ ! extern void track_sigio(void); ! extern int had_io(void); ! ! /* string routines -- XXX FIXME: we eventually want everything in ! * stringbuffer */ ! ! extern char *splice_string(const char *s1, const char *s2); ! extern char *splice_many_strings(int num, char *s, ...); ! extern int string_matches(const char *s1, const char *s2); ! extern int hex_string_to_value(char *string, unsigned char *dst); ! extern int is_string(const char *string, int len); ! extern char *xstrdup(const char *string); ! /* random number gen. */ ! extern uint16_t get_random_uint16(void); ! extern uint32_t get_random_uint32(void); ! /* misc. */ ! extern struct timeval timeval_diff(struct timeval begin, struct timeval end); ! extern const char *getprogname(void); ! extern int resolv(char *address, uint32_t *addr); ! extern int port_for_service(const char *serv, const char *proto); ! extern int is_seven_bit_clean(const char *data, int len); ! /* macros. */ ! /* log message macros. */ ! #define INFO_MESSAGE(...) { info_message(__VA_ARGS__); } ! #define ERROR_MESSAGE(...) { error_message(__func__, __VA_ARGS__); } ! #define WARN_MESSAGE(...) { warn_message(__VA_ARGS__); } ! #define FATAL_MESSAGE(...) { fatal_message(__func__, __VA_ARGS__); } ! #define DEBUG_MESSAGE(...) { debug_message(MODULE_NAME, __func__, __FILE__, __VA_ARGS__); } #endif /* DHCP_UTIL_H */ --- 29,60 ---- #define DHCP_UTIL_H ! #define __STDC_FORMAT_MACROS /* we need the C99 type macros. */ ! #ifdef HAVE_CONFIG_H ! #include "config.h" ! #endif ! #include <stdlib.h> ! #include <stdio.h> + #include <sys/types.h> + #include <sys/time.h> + #include <sys/stat.h> ! #include <string.h> ! #include <errno.h> ! #include <ctype.h> ! #include <unistd.h> ! #include <syslog.h> ! #include <signal.h> ! #include <stdarg.h> ! #include <inttypes.h> ! #include <dnet.h> ! /* XXX -- ??? -- what's the deal with this? must remember. */ ! /* must be placed in main source of each binary. ! * if not available. */ ! extern const char *__progname; #endif /* DHCP_UTIL_H */ --- dhcp-stringbuffer.h DELETED --- |
From: <act...@us...> - 2002-10-30 05:00:48
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv6635 Modified Files: config.h.in configure.in Log Message: setup for making a utility library -- zorched makefile.am temporarily until this conversion is over Index: config.h.in =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/config.h.in,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** config.h.in 29 Oct 2002 17:11:03 -0000 1.1.1.1 --- config.h.in 30 Oct 2002 05:00:46 -0000 1.2 *************** *** 16,19 **** --- 16,22 ---- #undef HAVE_DAEMON + /* Define to 1 if you have the <dlfcn.h> header file. */ + #undef HAVE_DLFCN_H + /* Define to 1 if you have the <getopt.h> header file. */ #undef HAVE_GETOPT_H Index: configure.in =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/configure.in,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** configure.in 29 Oct 2002 17:11:03 -0000 1.1.1.1 --- configure.in 30 Oct 2002 05:00:46 -0000 1.2 *************** *** 34,37 **** --- 34,38 ---- AC_PROG_INSTALL AC_PROG_MAKE_SET + AC_PROG_LIBTOOL dnl check header files we should have |
From: <act...@us...> - 2002-10-30 04:56:08
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory usw-pr-cvs1:/tmp/cvs-serv5649/src Modified Files: .cvsignore Log Message: more ignoring Index: .cvsignore =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/.cvsignore,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** .cvsignore 29 Oct 2002 17:19:49 -0000 1.3 --- .cvsignore 30 Oct 2002 04:56:05 -0000 1.4 *************** *** 4,5 **** --- 4,7 ---- dhcp-client dhcp-sniff + .libs + *.la *.lo |
From: <act...@us...> - 2002-10-30 04:56:08
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv5649 Modified Files: .cvsignore Log Message: more ignoring Index: .cvsignore =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/.cvsignore,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** .cvsignore 29 Oct 2002 17:19:49 -0000 1.2 --- .cvsignore 30 Oct 2002 04:56:04 -0000 1.3 *************** *** 7,8 **** --- 7,9 ---- config.h stamp-h1 + config.guess config.sub ltmain.sh |
From: <act...@us...> - 2002-10-29 17:19:52
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory usw-pr-cvs1:/tmp/cvs-serv9477/src Modified Files: .cvsignore Log Message: update to ignore -- again Index: .cvsignore =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/.cvsignore,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** .cvsignore 29 Oct 2002 17:14:23 -0000 1.2 --- .cvsignore 29 Oct 2002 17:19:49 -0000 1.3 *************** *** 2,3 **** --- 2,5 ---- .deps stamp-h1 + dhcp-client + dhcp-sniff |
From: <act...@us...> - 2002-10-29 17:19:52
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv9477 Modified Files: .cvsignore Log Message: update to ignore -- again Index: .cvsignore =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/.cvsignore,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** .cvsignore 29 Oct 2002 17:11:03 -0000 1.1.1.1 --- .cvsignore 29 Oct 2002 17:19:49 -0000 1.2 *************** *** 5,6 **** --- 5,8 ---- config.log config.status configure depcomp install-sh libtool missing mkinstalldirs + config.h + stamp-h1 |
From: <act...@us...> - 2002-10-29 17:17:40
|
Update of /cvsroot/dhcp-agent/dhcp-agent/man In directory usw-pr-cvs1:/tmp/cvs-serv8403/man Removed Files: Makefile.in Log Message: more cleanup. no need for Makefile.in in man dir --- Makefile.in DELETED --- |
From: <act...@us...> - 2002-10-29 17:16:49
|
Update of /cvsroot/dhcp-agent/dhcp-agent/man In directory usw-pr-cvs1:/tmp/cvs-serv7985/man Added Files: .cvsignore Log Message: added cvsignore for man dir --- NEW FILE: .cvsignore --- Makefile.in Makefile stamp-h1 |
From: <act...@us...> - 2002-10-29 17:14:26
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory usw-pr-cvs1:/tmp/cvs-serv6531/src Modified Files: .cvsignore Log Message: update to cvsignore Index: .cvsignore =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/.cvsignore,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** .cvsignore 29 Oct 2002 17:11:34 -0000 1.1.1.1 --- .cvsignore 29 Oct 2002 17:14:23 -0000 1.2 *************** *** 1,3 **** Makefile Makefile.in .deps ! --- 1,3 ---- Makefile Makefile.in .deps ! stamp-h1 |
From: <act...@us...> - 2002-10-29 17:13:58
|
Update of /cvsroot/dhcp-agent/dhcp-agent/src In directory usw-pr-cvs1:/tmp/cvs-serv6286/src Removed Files: stamp-h1 Log Message: no need for stamp file --- stamp-h1 DELETED --- |
From: Thamer Al-H. <tm...@wh...> - 2002-10-29 15:47:40
|
CVS backed up and zapped. Will be commiting code soon with new structure. -- Thamer Al-Harbash http://www.whitefang.com/ team dresch made me do it |
From: <act...@us...> - 2002-10-26 22:47:20
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv29078 Modified Files: dhcp-client.c dhcp-client.h Log Message: fix to bugged dispatchingg :) Index: dhcp-client.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client.c,v retrieving revision 1.48 retrieving revision 1.49 diff -C2 -d -r1.48 -r1.49 *** dhcp-client.c 26 Oct 2002 22:39:32 -0000 1.48 --- dhcp-client.c 26 Oct 2002 22:47:17 -0000 1.49 *************** *** 251,255 **** } ! state = client_states[state]; } --- 251,255 ---- } ! state = client_states[state](dc); } Index: dhcp-client.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcp-client.h 26 Oct 2002 22:39:32 -0000 1.4 --- dhcp-client.h 26 Oct 2002 22:47:17 -0000 1.5 *************** *** 41,48 **** #define STATE_DISCOVER_OFFER 0 #define STATE_REQUEST_ACK 1 ! #define STATE_SETUP 3 ! #define STATE_WAIT 4 ! #define STATE_RELEASE 5 ! #define STATE_FATAL_ERROR 6 extern int client_discover_offer(dhcp_client_control_t *dc); --- 41,48 ---- #define STATE_DISCOVER_OFFER 0 #define STATE_REQUEST_ACK 1 ! #define STATE_SETUP 2 ! #define STATE_WAIT 3 ! #define STATE_RELEASE 4 ! #define STATE_FATAL_ERROR 5 extern int client_discover_offer(dhcp_client_control_t *dc); |
From: <act...@us...> - 2002-10-26 22:39:35
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv16708 Modified Files: dhcp-agent.h dhcp-client-states.c dhcp-client.c dhcp-client.h Log Message: client states now in dispatch array Index: dhcp-agent.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-agent.h,v retrieving revision 1.76 retrieving revision 1.77 diff -C2 -d -r1.76 -r1.77 *** dhcp-agent.h 26 Oct 2002 18:13:21 -0000 1.76 --- dhcp-agent.h 26 Oct 2002 22:39:32 -0000 1.77 *************** *** 499,513 **** # define NETBIOS_H_NODE 0x06 - /* DHCP states - * We use these internally - * for the state machine. */ - - #define STATE_FATAL_ERROR -1 - #define STATE_DISCOVER_OFFER 0 - #define STATE_REQUEST_ACK 1 - #define STATE_SETUP 3 - #define STATE_WAIT 4 - #define STATE_RELEASE 5 - /* Parse types. */ --- 499,502 ---- Index: dhcp-client-states.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client-states.c,v retrieving revision 1.42 retrieving revision 1.43 diff -C2 -d -r1.42 -r1.43 *** dhcp-client-states.c 23 Oct 2002 23:43:34 -0000 1.42 --- dhcp-client-states.c 26 Oct 2002 22:39:32 -0000 1.43 *************** *** 29,32 **** --- 29,33 ---- #include <dhcp-agent.h> + #include <dhcp-client.h> #include <dhcp-util.h> #include <dhcp-sysconf.h> *************** *** 485,486 **** --- 486,494 ---- * return STATE_REQUEST_ACK here. */ } + + int client_fatal_error(dhcp_client_control_t *dc) + { + FATAL_MESSAGE("encountered a fatal error. i'm giving up."); + exit(1); /* to get rid of compiler warning. */ + } + Index: dhcp-client.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client.c,v retrieving revision 1.47 retrieving revision 1.48 diff -C2 -d -r1.47 -r1.48 *** dhcp-client.c 22 Oct 2002 00:59:41 -0000 1.47 --- dhcp-client.c 26 Oct 2002 22:39:32 -0000 1.48 *************** *** 71,74 **** --- 71,85 ---- }; + /* client state dispatch: index constants in dhcp-client.h */ + client_state client_states[] = { + client_discover_offer, + client_request_ack, + client_setup, + client_wait, + client_release, + client_fatal_error, + }; + + /* global vars affecting other code. */ int interactive = 1; /* by default we begin interactive (messages on stdout/stderr). */ *************** *** 239,275 **** return state; } - - switch(state) { - - case STATE_FATAL_ERROR: - FATAL_MESSAGE("encountered fatal error. I'm giving up."); - - case STATE_DISCOVER_OFFER: - state = client_discover_offer(dc); - break; - - case STATE_REQUEST_ACK: - state = client_request_ack(dc); - break; ! case STATE_SETUP: ! state = client_setup(dc); ! have_setup = 1; ! break; ! ! case STATE_WAIT: ! state = client_wait(dc); ! break; ! ! case STATE_RELEASE: ! state = client_release(dc); ! break; - default: - break; - } } ! return STATE_FATAL_ERROR; /* we should never get here, but if we do... */ } --- 250,259 ---- return state; } ! state = client_states[state]; } ! return STATE_FATAL_ERROR; /* we should never get here, but if we do it's bad :) */ } Index: dhcp-client.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** dhcp-client.h 17 Jun 2002 13:23:07 -0000 1.3 --- dhcp-client.h 26 Oct 2002 22:39:32 -0000 1.4 *************** *** 28,32 **** --- 28,34 ---- typedef void (*client_command)(char *interface); typedef char *(*interface_lister)(void); + typedef int (*client_state)(dhcp_client_control_t *); + /* client commands. */ #define DO_VERSION 0 #define DO_KILL 1 *************** *** 35,38 **** #define DO_CLIENT 4 ! #endif --- 37,55 ---- #define DO_CLIENT 4 ! /* DHCP client states. */ + #define STATE_DISCOVER_OFFER 0 + #define STATE_REQUEST_ACK 1 + #define STATE_SETUP 3 + #define STATE_WAIT 4 + #define STATE_RELEASE 5 + #define STATE_FATAL_ERROR 6 + + 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); + extern int client_fatal_error(dhcp_client_control_t *dc); + + #endif |
From: <act...@us...> - 2002-10-26 18:13:50
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv23040 Modified Files: dhcp-timer.c dhcp-timer.h Log Message: culled timer routines to be better Index: dhcp-timer.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-timer.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** dhcp-timer.c 26 Oct 2002 14:26:41 -0000 1.1 --- dhcp-timer.c 26 Oct 2002 18:13:48 -0000 1.2 *************** *** 26,29 **** --- 26,30 ---- * * All timers have an unsigned 32-bit integer ID assigned to them. + * */ *************** *** 34,81 **** #include <dhcp-timer.h> ! /* create a new trigger. */ ! static trigger_t *create_trigger(uint32_t id, uint32_t trigger_time) ! { ! trigger_t *trigger; ! ! trigger = xmalloc(sizeof(trigger_t)); ! trigger->trigger_id = id; ! trigger->trigger_timer = trigger_time; ! ! return trigger; ! } ! ! /* destroy a trigger. */ ! static void destroy_trigger(trigger_t *trigger) ! { ! xfree(trigger); ! return; ! } ! ! /* utility routine to get trigger by its id -- pass this to ! * list_find_datum_by */ ! static uint32_t get_trigger_id(trigger_t *trigger) ! { ! return trigger->trigger_id; ! } ! ! /* utility to pass to purge_list. */ ! static void destroy_trigger_l(void *p) { ! trigger_t *trigger = p; ! ! destroy_trigger(trigger); ! return; ! } ! /* utility list find routine. */ ! int find_trigger_by_id(void *trigger_p, void *id_p) ! { ! uint32_t *id = id_p; ! trigger_t *trigger = trigger_p; ! if(get_trigger_id(trigger) == *id) return 1; return 0; } --- 35,52 ---- #include <dhcp-timer.h> ! /* compare triggers by returning shortest time as highest. */ ! static int compare_triggers_shortest(void *trigger1_p, void *trigger2_p) { ! uint32_t *trigger1, *trigger2; ! trigger1 = trigger1_p; ! trigger2 = trigger2_p; ! if(trigger1 > trigger2) return 1; + if(trigger1 < trigger2) + return -1; + return 0; } *************** *** 88,92 **** timer = xmalloc(sizeof(timer_keeper_t)); timer->triggers = NULL; - timer->active = 0; return timer; --- 59,62 ---- *************** *** 96,100 **** void destroy_timer(timer_keeper_t *timer) { ! purge_list(timer->triggers, destroy_trigger_l); xfree(timer); --- 66,70 ---- void destroy_timer(timer_keeper_t *timer) { ! purge_list(timer->triggers, NULL); xfree(timer); *************** *** 103,109 **** /* add a new trigger. */ ! void timer_add_trigger(timer_keeper_t *timer, uint32_t id, uint32_t time) { ! trigger_t *trigger = create_trigger(id, time); timer->triggers = add_to_list(timer->triggers, trigger); --- 73,80 ---- /* add a new trigger. */ ! void timer_add_trigger(timer_keeper_t *timer, uint32_t trigger_time) { ! uint32_t *trigger = xmalloc(sizeof(uint32_t)); ! *trigger = trigger_time; timer->triggers = add_to_list(timer->triggers, trigger); *************** *** 112,129 **** } ! /* delete a trigger by its id. */ ! int timer_delete_trigger(timer_keeper_t *timer, uint32_t id) { ! list_t *trigger_l; ! trigger_t *trigger; ! trigger_l = list_find_datum_by(timer->triggers, find_trigger_by_id, &id); ! if(trigger_l == NULL) ! return 1; ! trigger = trigger_l->data; ! timer->triggers = remove_from_list(timer->triggers, trigger); ! return 0; } --- 83,100 ---- } ! /* timer setup next trigger. */ ! void timer_set_next(timer_keeper_t *timer) { ! uint32_t *trigger; ! if(timer->triggers == NULL) ! return; ! timer->triggers = sort_list(timer->triggers, compare_triggers_shortest); ! trigger = timer->triggers->data; ! alarm(*trigger); ! timer->triggers = remove_from_list(timer->triggers, timer->triggers->data); ! xfree(trigger); } Index: dhcp-timer.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-timer.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** dhcp-timer.h 26 Oct 2002 14:26:41 -0000 1.1 --- dhcp-timer.h 26 Oct 2002 18:13:48 -0000 1.2 *************** *** 33,48 **** typedef struct { list_t *triggers; - uint8_t active; } timer_keeper_t; - typedef struct { - uint32_t trigger_id; - uint32_t trigger_timer; - } trigger_t; - extern timer_keeper_t *create_timer(void); extern void destroy_timer(timer_keeper_t *timer); ! extern void timer_add_trigger(timer_keeper_t *timer, uint32_t id, uint32_t time); ! extern int timer_delete_trigger(timer_keeper_t *timer, uint32_t id); #endif /* DHCP_TIMER_H */ --- 33,43 ---- typedef struct { list_t *triggers; } timer_keeper_t; extern timer_keeper_t *create_timer(void); extern void destroy_timer(timer_keeper_t *timer); ! extern void timer_set_next(timer_keeper_t *timer); ! extern void timer_add_trigger(timer_keeper_t *timer, uint32_t time); ! extern int timer_purge(timer_keeper_t); #endif /* DHCP_TIMER_H */ |
From: <act...@us...> - 2002-10-26 18:13:25
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv22743 Modified Files: dhcp-agent.h dhcp-list.c Log Message: updated list routines Index: dhcp-agent.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-agent.h,v retrieving revision 1.75 retrieving revision 1.76 diff -C2 -d -r1.75 -r1.76 *** dhcp-agent.h 25 Oct 2002 13:20:08 -0000 1.75 --- dhcp-agent.h 26 Oct 2002 18:13:21 -0000 1.76 *************** *** 789,792 **** --- 789,793 ---- 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. */ Index: dhcp-list.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-list.c,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** dhcp-list.c 26 Oct 2002 14:26:41 -0000 1.9 --- dhcp-list.c 26 Oct 2002 18:13:21 -0000 1.10 *************** *** 138,139 **** --- 138,169 ---- return NULL; } + + /* we use a fairly dumb sorting algorithm. optimize later. the + * real problem is we're using a list which sucks for these kinds + * of things :-) */ + list_t *sort_list(list_t *list, int (*compare)(void *, void *)) + { + list_t *new_list = NULL; + list_t *highest, *ptr; + + while(1) { + /* keep looping until list is NULL. */ + highest = list; + + if(list == NULL) + break; + + /* otherwise move down list and compare values. */ + for(ptr = list->next;ptr;ptr = ptr->next) { + if(compare(highest->data, ptr->data) == -1) { + highest = ptr; + } + } + + new_list = add_to_list(new_list, highest->data); + list = remove_from_list(list, highest->data); + + } + + return new_list; + } |
From: <act...@us...> - 2002-10-26 14:26:44
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv23167 Modified Files: Makefile.am Makefile.in dhcp-list.c Added Files: dhcp-timer.c dhcp-timer.h Log Message: new dhcp-timer object; not tested yet --- NEW FILE: dhcp-timer.c --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/dhcp-timer.c,v 1.1 2002/10/26 14:26:41 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. * * Timer keeper object to keep track of an infinite number of timers. * We can add new timers to it, activate it when we want to, * deactivate it, and remove timers. * * All timers have an unsigned 32-bit integer ID assigned to them. */ #define MODULE_NAME "dhcp-timer" #include <dhcp-agent.h> #include <dhcp-util.h> #include <dhcp-timer.h> /* create a new trigger. */ static trigger_t *create_trigger(uint32_t id, uint32_t trigger_time) { trigger_t *trigger; trigger = xmalloc(sizeof(trigger_t)); trigger->trigger_id = id; trigger->trigger_timer = trigger_time; return trigger; } /* destroy a trigger. */ static void destroy_trigger(trigger_t *trigger) { xfree(trigger); return; } /* utility routine to get trigger by its id -- pass this to * list_find_datum_by */ static uint32_t get_trigger_id(trigger_t *trigger) { return trigger->trigger_id; } /* utility to pass to purge_list. */ static void destroy_trigger_l(void *p) { trigger_t *trigger = p; destroy_trigger(trigger); return; } /* utility list find routine. */ int find_trigger_by_id(void *trigger_p, void *id_p) { uint32_t *id = id_p; trigger_t *trigger = trigger_p; if(get_trigger_id(trigger) == *id) return 1; return 0; } /* create a new timer keeper. */ timer_keeper_t *create_timer(void) { timer_keeper_t *timer; timer = xmalloc(sizeof(timer_keeper_t)); timer->triggers = NULL; timer->active = 0; return timer; } /* destroy a timer keeper. */ void destroy_timer(timer_keeper_t *timer) { purge_list(timer->triggers, destroy_trigger_l); xfree(timer); return; } /* add a new trigger. */ void timer_add_trigger(timer_keeper_t *timer, uint32_t id, uint32_t time) { trigger_t *trigger = create_trigger(id, time); timer->triggers = add_to_list(timer->triggers, trigger); return; } /* delete a trigger by its id. */ int timer_delete_trigger(timer_keeper_t *timer, uint32_t id) { list_t *trigger_l; trigger_t *trigger; trigger_l = list_find_datum_by(timer->triggers, find_trigger_by_id, &id); if(trigger_l == NULL) return 1; trigger = trigger_l->data; timer->triggers = remove_from_list(timer->triggers, trigger); return 0; } --- NEW FILE: dhcp-timer.h --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/dhcp-timer.h,v 1.1 2002/10/26 14:26:41 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. * * Timer keeper object to keep track of an infinite number of * time triggers. We can add new time trigger to it, activate it * when we want to, deactivate it, and remove triggers. * * All timers have an unsigned 32-bit integer ID assigned to them. */ #ifndef DHCP_TIMER_H #define DHCP_TIMER_H typedef struct { list_t *triggers; uint8_t active; } timer_keeper_t; typedef struct { uint32_t trigger_id; uint32_t trigger_timer; } trigger_t; extern timer_keeper_t *create_timer(void); extern void destroy_timer(timer_keeper_t *timer); extern void timer_add_trigger(timer_keeper_t *timer, uint32_t id, uint32_t time); extern int timer_delete_trigger(timer_keeper_t *timer, uint32_t id); #endif /* DHCP_TIMER_H */ Index: Makefile.am =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/Makefile.am,v retrieving revision 1.31 retrieving revision 1.32 diff -C2 -d -r1.31 -r1.32 *** Makefile.am 21 Oct 2002 01:02:48 -0000 1.31 --- Makefile.am 26 Oct 2002 14:26:41 -0000 1.32 *************** *** 21,25 **** dhcp-sysconf.c dhcp-rtt.c dhcp-packet-build.c dhcp-icmp-discovery.c \ dhcp-arp-discovery.c dhcp-route.c dhcp-globconf.c dhcp-stringbuffer.c \ ! dhcp-parser.c dhcp-varfile.c dhcpclient_LDADD = @PCAP_LIB@ @DNET_LIB@ --- 21,25 ---- dhcp-sysconf.c dhcp-rtt.c dhcp-packet-build.c dhcp-icmp-discovery.c \ dhcp-arp-discovery.c dhcp-route.c dhcp-globconf.c dhcp-stringbuffer.c \ ! dhcp-parser.c dhcp-varfile.c dhcp-timer.c dhcpclient_LDADD = @PCAP_LIB@ @DNET_LIB@ Index: Makefile.in =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/Makefile.in,v retrieving revision 1.33 retrieving revision 1.34 diff -C2 -d -r1.33 -r1.34 *** Makefile.in 21 Oct 2002 01:02:48 -0000 1.33 --- Makefile.in 26 Oct 2002 14:26:41 -0000 1.34 *************** *** 103,107 **** dhcp-sysconf.c dhcp-rtt.c dhcp-packet-build.c dhcp-icmp-discovery.c \ dhcp-arp-discovery.c dhcp-route.c dhcp-globconf.c dhcp-stringbuffer.c \ ! dhcp-parser.c dhcp-varfile.c --- 103,107 ---- dhcp-sysconf.c dhcp-rtt.c dhcp-packet-build.c dhcp-icmp-discovery.c \ dhcp-arp-discovery.c dhcp-route.c dhcp-globconf.c dhcp-stringbuffer.c \ ! dhcp-parser.c dhcp-varfile.c dhcp-timer.c *************** *** 142,146 **** dhcp-arp-discovery.$(OBJEXT) dhcp-route.$(OBJEXT) \ dhcp-globconf.$(OBJEXT) dhcp-stringbuffer.$(OBJEXT) \ ! dhcp-parser.$(OBJEXT) dhcp-varfile.$(OBJEXT) dhcpclient_OBJECTS = $(am_dhcpclient_OBJECTS) dhcpclient_DEPENDENCIES = --- 142,147 ---- dhcp-arp-discovery.$(OBJEXT) dhcp-route.$(OBJEXT) \ dhcp-globconf.$(OBJEXT) dhcp-stringbuffer.$(OBJEXT) \ ! dhcp-parser.$(OBJEXT) dhcp-varfile.$(OBJEXT) \ ! dhcp-timer.$(OBJEXT) dhcpclient_OBJECTS = $(am_dhcpclient_OBJECTS) dhcpclient_DEPENDENCIES = *************** *** 188,192 **** @AMDEP_TRUE@ ./$(DEPDIR)/dhcp-snprintf.Po \ @AMDEP_TRUE@ ./$(DEPDIR)/dhcp-stringbuffer.Po \ ! @AMDEP_TRUE@ ./$(DEPDIR)/dhcp-sysconf.Po ./$(DEPDIR)/dhcp-udp.Po \ @AMDEP_TRUE@ ./$(DEPDIR)/dhcp-util.Po \ @AMDEP_TRUE@ ./$(DEPDIR)/dhcp-varfile.Po --- 189,194 ---- @AMDEP_TRUE@ ./$(DEPDIR)/dhcp-snprintf.Po \ @AMDEP_TRUE@ ./$(DEPDIR)/dhcp-stringbuffer.Po \ ! @AMDEP_TRUE@ ./$(DEPDIR)/dhcp-sysconf.Po \ ! @AMDEP_TRUE@ ./$(DEPDIR)/dhcp-timer.Po ./$(DEPDIR)/dhcp-udp.Po \ @AMDEP_TRUE@ ./$(DEPDIR)/dhcp-util.Po \ @AMDEP_TRUE@ ./$(DEPDIR)/dhcp-varfile.Po *************** *** 314,317 **** --- 316,320 ---- @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dhcp-stringbuffer.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dhcp-sysconf.Po@am__quote@ + @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dhcp-timer.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dhcp-udp.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dhcp-util.Po@am__quote@ Index: dhcp-list.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-list.c,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** dhcp-list.c 25 Oct 2002 13:20:08 -0000 1.8 --- dhcp-list.c 26 Oct 2002 14:26:41 -0000 1.9 *************** *** 138,141 **** return NULL; } - - --- 138,139 ---- |
From: <act...@us...> - 2002-10-25 17:35:37
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv12503a Modified Files: dhcp-agent.h dhcp-list.c Log Message: i need more coffee Index: dhcp-agent.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-agent.h,v retrieving revision 1.74 retrieving revision 1.75 diff -C2 -d -r1.74 -r1.75 *** dhcp-agent.h 25 Oct 2002 12:58:20 -0000 1.74 --- dhcp-agent.h 25 Oct 2002 13:20:08 -0000 1.75 *************** *** 788,792 **** extern void purge_list_internal(void *head); extern list_t *join_lists(list_t *first_list, list_t *second_list); ! extern list_t *find_datum_by(list_t *first, int (*find_func(void *, void *)), void *arg); /* Logging functions. */ --- 788,792 ---- 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); /* Logging functions. */ Index: dhcp-list.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-list.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** dhcp-list.c 25 Oct 2002 12:58:20 -0000 1.7 --- dhcp-list.c 25 Oct 2002 13:20:08 -0000 1.8 *************** *** 127,131 **** } ! list_t *find_datum_by(list_t *list, int (*find_func(void *, void *)), void *arg) { list_t *ptr; --- 127,131 ---- } ! list_t *list_find_datum_by(list_t *list, int (*find_func)(void *, void *), void *arg) { list_t *ptr; |