[Dhcp-agent-commits] CVS: dhcp-agent COST,1.6,1.7 Makefile.am,1.13,1.14 Makefile.in,1.13,1.14 TODO,1
Status: Alpha
Brought to you by:
actmodern
|
From: Thamer Al-H. <act...@us...> - 2002-05-18 18:10:12
|
Update of /cvsroot/dhcp-agent/dhcp-agent
In directory usw-pr-cvs1:/tmp/cvs-serv12618
Modified Files:
COST Makefile.am Makefile.in TODO dhcp-agent.h
dhcp-client-control.c dhcp-client-states.c dhcp-convert.c
dhcp-interface.c dhcp-net.c dhcp-sysconf.c dhcp-util.c
Log Message:
various updates; bug fixes;
Index: COST
===================================================================
RCS file: /cvsroot/dhcp-agent/dhcp-agent/COST,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** COST 25 Feb 2002 01:39:29 -0000 1.6
--- COST 18 May 2002 18:10:09 -0000 1.7
***************
*** 1,11 ****
In writing dhcp-agent I suffered the following:
-
- Feb - March 2001 (Current values as of the Feb 24)
! 83 pots of coffee; 211 camel filter cigarettes; 35 diet cokes
! (cutting down); 845 mp3s (thanks stephanie); 18 historical trips
! to the wash room; 16 showers; lost one pretty geekette; got one
! job offer; got one pretty geekette; startin' to feel some justice
! in this world;
Jan - Feb 2001
--- 1,21 ----
In writing dhcp-agent I suffered the following:
! May - June 2001
!
! 3 pots of coffee; 42 camel filter cigarretes; one sorry poser;
! cleaned up apartment 0 times;
!
! April - May 2001
!
! lost one geek girl; haven't kept track -- will soon
!
! March - April 2001
!
! -- didn't write much code so no costs involved; earned new place
!
! Feb - March 2001
!
! -- gained one geek girl: as you can imagine little was done;
! earned job
Jan - Feb 2001
Index: Makefile.am
===================================================================
RCS file: /cvsroot/dhcp-agent/dhcp-agent/Makefile.am,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** Makefile.am 25 Feb 2002 01:39:29 -0000 1.13
--- Makefile.am 18 May 2002 18:10:09 -0000 1.14
***************
*** 10,14 ****
dhcp-align.c dhcp-net.c dhcp-list.c dhcp-com.c dhcp-eth.c dhcp-ip.c \
dhcp-udp.c dhcp-arp.c dhcp-icmp.c dhcp-log.c @DHCP_SNPRINTF@ \
! dhcp-sniffer-ohandlers.c dhcp-rtt.c
dhcpsniff_LDADD = @PCAP_LIB@ @DNET_LIB@
--- 10,14 ----
dhcp-align.c dhcp-net.c dhcp-list.c dhcp-com.c dhcp-eth.c dhcp-ip.c \
dhcp-udp.c dhcp-arp.c dhcp-icmp.c dhcp-log.c @DHCP_SNPRINTF@ \
! dhcp-sniffer-ohandlers.c dhcp-rtt.c dhcp-interface.c
dhcpsniff_LDADD = @PCAP_LIB@ @DNET_LIB@
Index: Makefile.in
===================================================================
RCS file: /cvsroot/dhcp-agent/dhcp-agent/Makefile.in,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** Makefile.in 25 Feb 2002 01:39:29 -0000 1.13
--- Makefile.in 18 May 2002 18:10:09 -0000 1.14
***************
*** 78,82 ****
bin_PROGRAMS = dhcpsniff dhcpclient
! dhcpsniff_SOURCES = dhcp-sniff.c dhcp-print.c dhcp-util.c dhcp-align.c dhcp-net.c dhcp-list.c dhcp-com.c dhcp-eth.c dhcp-ip.c dhcp-udp.c dhcp-arp.c dhcp-icmp.c dhcp-log.c @DHCP_SNPRINTF@ dhcp-sniffer-ohandlers.c dhcp-rtt.c
--- 78,82 ----
bin_PROGRAMS = dhcpsniff dhcpclient
! dhcpsniff_SOURCES = dhcp-sniff.c dhcp-print.c dhcp-util.c dhcp-align.c dhcp-net.c dhcp-list.c dhcp-com.c dhcp-eth.c dhcp-ip.c dhcp-udp.c dhcp-arp.c dhcp-icmp.c dhcp-log.c @DHCP_SNPRINTF@ dhcp-sniffer-ohandlers.c dhcp-rtt.c dhcp-interface.c
***************
*** 106,110 ****
dhcpsniff_OBJECTS = dhcp-sniff.o dhcp-print.o dhcp-util.o dhcp-align.o \
dhcp-net.o dhcp-list.o dhcp-com.o dhcp-eth.o dhcp-ip.o dhcp-udp.o \
! dhcp-arp.o dhcp-icmp.o dhcp-log.o dhcp-sniffer-ohandlers.o dhcp-rtt.o
dhcpsniff_DEPENDENCIES =
dhcpsniff_LDFLAGS =
--- 106,111 ----
dhcpsniff_OBJECTS = dhcp-sniff.o dhcp-print.o dhcp-util.o dhcp-align.o \
dhcp-net.o dhcp-list.o dhcp-com.o dhcp-eth.o dhcp-ip.o dhcp-udp.o \
! dhcp-arp.o dhcp-icmp.o dhcp-log.o dhcp-sniffer-ohandlers.o dhcp-rtt.o \
! dhcp-interface.o
dhcpsniff_DEPENDENCIES =
dhcpsniff_LDFLAGS =
Index: TODO
===================================================================
RCS file: /cvsroot/dhcp-agent/dhcp-agent/TODO,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** TODO 25 Feb 2002 01:39:29 -0000 1.11
--- TODO 18 May 2002 18:10:09 -0000 1.12
***************
*** 65,66 ****
--- 65,70 ----
by using devices like /dev/urandom explicitly if available.
-- fix overflow issue in dhcp-icmp-discovery (icmp_do_echo)
+ -- check if pcap prefixes its error messages if so remove pcap prefixes.
+ -- we need a proper error passing scheme for error strings so
+ that we wind up with a single string in the end.
+
Index: dhcp-agent.h
===================================================================
RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-agent.h,v
retrieving revision 1.31
retrieving revision 1.32
diff -C2 -d -r1.31 -r1.32
*** dhcp-agent.h 25 Feb 2002 01:39:29 -0000 1.31
--- dhcp-agent.h 18 May 2002 18:10:09 -0000 1.32
***************
*** 257,260 ****
--- 257,272 ----
} udp_obj;
+ /* interface control object:
+ * we store dnet's interface handle,
+ * and interface_entry structure.
+ * We need the entry structure
+ */
+
+ typedef struct {
+ intf_t *interface_handle;
+ struct intf_entry interface_entry;
+ } interface_control_t;
+
+
/*
* DHCP raw network object.
***************
*** 268,272 ****
/* we should not interface directly with any of these members
! * above the rawnet layer. */
pcap_t *pcap; /* packet capturing device (pcap). */
--- 280,284 ----
/* 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). */
***************
*** 283,289 ****
eth_addr_t hw_addr; /* our hardware address. */
ip_addr_t ip_addr; /* our ip address. */
int promiscious; /* run in promiscious mode flag. */
!
/*
* Data objects
--- 295,304 ----
eth_addr_t hw_addr; /* our hardware address. */
+ eth_addr_t *fake_hw_addr; /* our fake hardware address. */
ip_addr_t ip_addr; /* our ip address. */
int promiscious; /* run in promiscious mode flag. */
! interface_control_t
! *intf_handle; /* interface control handle. */
!
/*
* Data objects
***************
*** 335,349 ****
} client_conf_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;
-
/* Client data object. */
--- 350,353 ----
***************
*** 360,367 ****
uint32_t renewal_time; /* when to renew lease (secs). */
- interface_control_t *interface_control; /* interface handler. */
char *interface; /* interface name. */
unsigned char *class_id, *client_id; /* client_id, class_id */
- unsigned char *client_hw_addr; /* our hardware address. */
int state; /* our current state. */
int discover_offer_retries; /* how many times we should discover/offer before giving up. */
--- 364,369 ----
***************
*** 496,503 ****
extern void rawnet_destroy(rawnet_t *net);
extern int rawnet_get_packet(rawnet_t *net);
! extern int rawnet_get_interface_hw_addr(rawnet_t *net, eth_addr_t *addr);
extern char *rawnet_strerror(rawnet_t *net);
extern int rawnet_send_packet(rawnet_t *net);
extern void rawnet_use_fake_hw_addr(rawnet_t *raw, char *mac_string);
extern void build_dhcp_discover(rawnet_t *net, uint32_t xid, time_t secs, list_t *options);
--- 498,508 ----
extern void rawnet_destroy(rawnet_t *net);
extern int rawnet_get_packet(rawnet_t *net);
! extern int rawnet_get_hw_addr(rawnet_t *net, eth_addr_t *addr);
! extern int rawnet_get_real_hw_addr(rawnet_t *net, eth_addr_t *addr);
! extern int rawnet_get_ip_addr(rawnet_t *net, ip_addr_t *addr);
extern char *rawnet_strerror(rawnet_t *net);
extern int rawnet_send_packet(rawnet_t *net);
extern void rawnet_use_fake_hw_addr(rawnet_t *raw, char *mac_string);
+ extern void reinitialize_rawnet(rawnet_t *net, int promiscious);
extern void build_dhcp_discover(rawnet_t *net, uint32_t xid, time_t secs, list_t *options);
***************
*** 538,543 ****
int (*check)(void *arg));
! /* droppage in rawnet is probably wrong -- but we'll clean up later (FIXME) */
! extern char *network_address_to_string_static(uint32_t addr);
/* ICMP discovery routines. */
--- 543,548 ----
int (*check)(void *arg));
! extern int rawnet_interface_up(rawnet_t *net, ip_addr_t addr, ip_addr_t netmask, int mtu);
! extern int rawnet_interface_down(rawnet_t *net);
/* ICMP discovery routines. */
***************
*** 898,901 ****
--- 903,909 ----
extern int rtt_can_retry(rtt_t *rtt);
extern void rtt_destroy(rtt_t *rtt);
+
+ /* global conversion routines. */
+ extern char *network_address_to_string_static(uint32_t addr);
/* Global vars. */
Index: dhcp-client-control.c
===================================================================
RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client-control.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** dhcp-client-control.c 16 Feb 2002 17:54:33 -0000 1.14
--- dhcp-client-control.c 18 May 2002 18:10:09 -0000 1.15
***************
*** 59,63 ****
{
unsigned char *s;
! unsigned char mac_add[6];
s = xmalloc(1 + ETH_ADDR_LEN);
--- 59,63 ----
{
unsigned char *s;
! unsigned char mac_add[ETH_ADDR_LEN];
s = xmalloc(1 + ETH_ADDR_LEN);
***************
*** 122,126 ****
dc->state = 0;
dc->interface = strdup(interface);
- dc->interface_control = create_interface_control(interface);
dc->conf = create_client_conf(dc);
dc->cache = create_client_cache(dc);
--- 122,125 ----
***************
*** 131,145 ****
}
- /* We need to bring the interface up,
- * even if its not initialized properly. */
-
- if(interface_up(dc->interface_control, 0, 0xffffffff, -1)) {
-
- error_message("could not bring up interface: %s: %s", dc->interface, strerror(errno));
- destroy_dhcp_client_control(dc);
- return NULL;
-
- }
-
/* Get port numbers from services db. */
--- 130,133 ----
***************
*** 189,193 ****
#endif /* HAVE_UNAME */
! if(rawnet_get_interface_hw_addr(dc->rawnet, &interface_addr)) {
error_message("could not acquire interface address");
destroy_dhcp_client_control(dc);
--- 177,181 ----
#endif /* HAVE_UNAME */
! if(rawnet_get_hw_addr(dc->rawnet, &interface_addr)) {
error_message("could not acquire interface address");
destroy_dhcp_client_control(dc);
***************
*** 201,210 ****
/* use fake address in 0x:0x:0x:0x:0x we need to notify rawnet about this.
! * achtung: arp packets still have proper address so we don't fudge arp caches up. */
void dhcp_control_use_fake_hw_addr(dhcp_client_control_t *dc, char *fake_hw_addr)
{
char *new_client_id = create_fake_client_id(fake_hw_addr);
!
! xfree(dc->client_id);
dc->client_id = new_client_id;
--- 189,199 ----
/* use fake address in 0x:0x:0x:0x:0x we need to notify rawnet about this.
! * achtung: all packets _except_ dhcp packets will still use the real hardware address. */
void dhcp_control_use_fake_hw_addr(dhcp_client_control_t *dc, char *fake_hw_addr)
{
char *new_client_id = create_fake_client_id(fake_hw_addr);
!
! if(dc->client_id != NULL)
! xfree(dc->client_id);
dc->client_id = new_client_id;
***************
*** 228,234 ****
xfree(dc->interface);
- if(dc->interface_control)
- destroy_interface_control(dc->interface_control);
-
if(dc->class_id)
xfree(dc->class_id);
--- 217,220 ----
***************
*** 236,242 ****
if(dc->client_id)
xfree(dc->client_id);
-
- if(dc->client_hw_addr)
- xfree(dc->client_hw_addr);
xfree(dc);
--- 222,225 ----
Index: dhcp-client-states.c
===================================================================
RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client-states.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -d -r1.18 -r1.19
*** dhcp-client-states.c 16 Feb 2002 17:54:33 -0000 1.18
--- dhcp-client-states.c 18 May 2002 18:10:09 -0000 1.19
***************
*** 28,39 ****
#include <dhcp-agent.h>
! static uint32_t client_ip_addr;
! static eth_addr_t client_hw_addr;
static sig_atomic_t have_alarm = 0;
static RETSIGTYPE handle_alarm(int i)
{
! have_alarm= 1;
return (RETSIGTYPE) 0;
}
--- 28,48 ----
#include <dhcp-agent.h>
! /* alarm handling routine and variable. */
!
! /* wrap for volatine integers, or proper sig_atomic_t types. */
!
! #ifdef HAVE_SIG_ATOMIC_T
static sig_atomic_t have_alarm = 0;
+ #else /* HAVE_SIG_ATOMIC_T */
+
+ static int have_alarm = 0;
+
+ #endif
+
static RETSIGTYPE handle_alarm(int i)
{
! have_alarm = 1;
return (RETSIGTYPE) 0;
}
***************
*** 83,88 ****
* matching xid. */
! if(dc->rawnet->type != RAWNET_DHCP ||
! (!rawnet_is_valid(dc->rawnet)) ||
(dhcp_get_xid(dc->rawnet->dhcp_p) != dc->xid))
return 0;
--- 92,97 ----
* matching xid. */
! if((!rawnet_is_valid(dc->rawnet)) ||
! dc->rawnet->type != RAWNET_DHCP ||
(dhcp_get_xid(dc->rawnet->dhcp_p) != dc->xid))
return 0;
***************
*** 119,139 ****
}
- /* Called after initialization.
- * This lets us do things like arp and unarp
- * without having to sift through the cache.
- */
-
- static int client_update_addresses(dhcp_client_control_t *dc)
- {
-
- if(rawnet_get_interface_hw_addr(dc->rawnet, &client_hw_addr) ||
- interface_get_ip_addr(dc->interface_control, &client_ip_addr)) {
- error_message("could get get hardware and ip addresses after initialization.");
- return -1;
- }
-
- return 0;
- }
-
/*
* Use this to send out a broadcast reply claiming that we own the
--- 128,131 ----
***************
*** 145,148 ****
--- 137,145 ----
static void client_broadcast_arp_reply(dhcp_client_control_t *dc)
{
+ ip_addr_t client_ip_addr;
+ eth_addr_t client_hw_addr;
+
+ rawnet_get_ip_addr(dc->rawnet, &client_ip_addr);
+ rawnet_get_real_hw_addr(dc->rawnet, &client_hw_addr);
build_arp_reply_broadcast(dc->rawnet, client_ip_addr, client_hw_addr);
***************
*** 155,158 ****
--- 152,161 ----
static void client_broadcast_unarp(dhcp_client_control_t *dc)
{
+ ip_addr_t client_ip_addr;
+ eth_addr_t client_hw_addr;
+
+ rawnet_get_ip_addr(dc->rawnet, &client_ip_addr);
+ rawnet_get_real_hw_addr(dc->rawnet, &client_hw_addr);
+
build_unarp(dc->rawnet, client_ip_addr, client_hw_addr);
rawnet_send_packet(dc->rawnet);
***************
*** 276,282 ****
do_sysconf(options, dc);
cache_entry_purge_list(options);
-
- if(client_update_addresses(dc))
- return -1;
client_broadcast_arp_reply(dc);
--- 279,282 ----
Index: dhcp-convert.c
===================================================================
RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-convert.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** dhcp-convert.c 9 Feb 2002 16:22:35 -0000 1.7
--- dhcp-convert.c 18 May 2002 18:10:09 -0000 1.8
***************
*** 772,774 ****
--- 772,787 ----
}
+ /* variation on network_addr_to_string in dhcp-convert.c we use
+ * this when we don't want to run around freeing results up, and
+ * know that it will be statically stored. Useful for insertion
+ * in message log routines. */
+
+ char *network_address_to_string_static(uint32_t addr)
+ {
+ struct in_addr in;
+ in.s_addr = addr;
+
+ return(inet_ntoa(in));
+ }
+
/* Gee, lots of workhorses in this source file. */
Index: dhcp-interface.c
===================================================================
RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-interface.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** dhcp-interface.c 25 Feb 2002 01:39:29 -0000 1.13
--- dhcp-interface.c 18 May 2002 18:10:09 -0000 1.14
***************
*** 33,37 ****
if(intf_get(ic->interface_handle, &ic->interface_entry) < 0) {
! error_message("could not lookup interface %s : %d", ic->interface_entry.intf_name, strerror(errno));
return -1;
}
--- 33,38 ----
if(intf_get(ic->interface_handle, &ic->interface_entry) < 0) {
! error_message("interface_control: could not lookup interface %s : %d", ic->interface_entry.intf_name,
! strerror(errno));
return -1;
}
***************
*** 43,47 ****
{
if(intf_set(ic->interface_handle, &ic->interface_entry) < 0) {
! error_message("could not lookup interface %s : %d", ic->interface_entry.intf_name, strerror(errno));
return -1;
}
--- 44,49 ----
{
if(intf_set(ic->interface_handle, &ic->interface_entry) < 0) {
! error_message("interface_control: could not lookup interface %s : %d", ic->interface_entry.intf_name,
! strerror(errno));
return -1;
}
***************
*** 59,63 ****
ic->interface_handle = intf_open();
if(ic->interface_handle == NULL) /* XXX -- update to dnet's error strings when dnet has some */
! fatal_error("could not acquire interface handler");
strncpy(ic->interface_entry.intf_name, name, sizeof(ic->interface_entry.intf_name) -1);
--- 61,65 ----
ic->interface_handle = intf_open();
if(ic->interface_handle == NULL) /* XXX -- update to dnet's error strings when dnet has some */
! fatal_error("interface_control: could not acquire interface handler");
strncpy(ic->interface_entry.intf_name, name, sizeof(ic->interface_entry.intf_name) -1);
Index: dhcp-net.c
===================================================================
RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-net.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** dhcp-net.c 25 Feb 2002 01:39:30 -0000 1.16
--- dhcp-net.c 18 May 2002 18:10:09 -0000 1.17
***************
*** 63,79 ****
#include <dhcp-agent.h>
- /* variation on network_addr_to_string in dhcp-convert.c we use
- * this when we don't want to run around freeing results up, and
- * know that it will be statically stored. Useful for insertion
- * in message log routines. */
-
- char *network_address_to_string_static(uint32_t addr)
- {
- struct in_addr in;
- in.s_addr = addr;
-
- return(inet_ntoa(in));
- }
-
/* Get port number for named service. */
--- 63,66 ----
***************
*** 85,89 ****
if((sv = getservbyname(serv, proto)) == NULL) {
! error_message("could not get service listing: %d", strerror(errno));
return -1;
}
--- 72,76 ----
if((sv = getservbyname(serv, proto)) == NULL) {
! error_message("rawnet: could not get service listing: %d", strerror(errno));
return -1;
}
***************
*** 108,116 ****
if(host == NULL) {
! error_message("unable to resolv host: %s", hstrerror(h_errno));
return -1;
}
! memcpy((int *) * &host->h_addr, &addr, sizeof(addr));
}
--- 95,103 ----
if(host == NULL) {
! error_message("rawnet: unable to resolv host: %s", hstrerror(h_errno));
return -1;
}
! memcpy(&addr, (int *) * &host->h_addr, sizeof(addr));
}
***************
*** 118,124 ****
}
! int rawnet_get_interface_hw_addr(rawnet_t *net, eth_addr_t *addr)
{
return(eth_get(net->eth, addr));
}
--- 105,132 ----
}
! /* 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) {
+ return(eth_get(net->eth, addr));
+ } else {
+ memcpy(addr, net->fake_hw_addr->data, ETH_ADDR_LEN);
+ return 0;
+ }
+ }
+
+ /* get real interface address skipping fake if its available. */
+ int rawnet_get_real_hw_addr(rawnet_t *net, eth_addr_t *addr)
+ {
+ /* are we using a fake address? */
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));
}
***************
*** 144,148 ****
if(interface_name == NULL) {
! error_message("pcap_lookupdev: %s", errbuf);
return NULL;
}
--- 152,156 ----
if(interface_name == NULL) {
! error_message("rawnet: pcap_lookupdev: %s", errbuf);
return NULL;
}
***************
*** 152,156 ****
pcap = pcap_open_live(interface_name, SNAPLEN, promiscious, 0, errbuf);
if(pcap == NULL) {
! error_message("pcap_openlive: %s", errbuf);
return NULL;
}
--- 160,164 ----
pcap = pcap_open_live(interface_name, SNAPLEN, promiscious, 0, errbuf);
if(pcap == NULL) {
! error_message("rawnet: pcap_openlive: %s", errbuf);
return NULL;
}
***************
*** 158,162 ****
if(pcap_compile(pcap, &filter, filter_string, 1, mask) == -1) {
pcap_close(pcap);
! error_message("pcap_compile: %s",pcap_geterr(pcap));
return NULL;
}
--- 166,170 ----
if(pcap_compile(pcap, &filter, filter_string, 1, mask) == -1) {
pcap_close(pcap);
! error_message("rawnet: pcap_compile: %s",pcap_geterr(pcap));
return NULL;
}
***************
*** 164,168 ****
if(pcap_setfilter(pcap, &filter) == -1) {
pcap_close(pcap);
! error_message("pcap_setfilter: %s", pcap_geterr(pcap));
return NULL;
}
--- 172,176 ----
if(pcap_setfilter(pcap, &filter) == -1) {
pcap_close(pcap);
! error_message("rawnet: pcap_setfilter: %s", pcap_geterr(pcap));
return NULL;
}
***************
*** 175,178 ****
--- 183,215 ----
}
+ /* 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("rawnet: could not bring up interface: %s: %s", net->device, strerror(errno));
+ rawnet_destroy(net);
+ return 1;
+ }
+
+ memcpy(&net->ip_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("rawnet: could not bring down interface: %s: %s", net->device, strerror(errno));
+ rawnet_destroy(net);
+ return 1;
+ }
+
+ memset(&net->ip_addr, 0, IP_ADDR_LEN); /* clear our IP address -- this isn't very useful though. */
+ return 0;
+ }
+
/* Create the workhorse network module. */
***************
*** 196,204 ****
net->eth = eth_open(device);
if(net->eth == NULL) {
! error_message("device not supported or unavailable: %s", device);
rawnet_destroy(net);
return NULL;
}
/* get pcap handler */
--- 233,253 ----
net->eth = eth_open(device);
if(net->eth == NULL) {
! error_message("rawnet: device not supported or unavailable: %s", device);
rawnet_destroy(net);
return NULL;
}
+ /* 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) {
+ rawnet_destroy(net);
+ return NULL;
+ }
+
+ /* We need to bring the interface up,
+ * even if its not initialized properly. */
+
+ rawnet_interface_up(net, 0, 0xffffff, -1);
+
/* get pcap handler */
***************
*** 211,219 ****
net->pcap_fd = pcap_fileno(net->pcap);
if(net->pcap_fd < 0) {
! error_message("cannot get descriptor for %s, this system may not be supported.", device);
rawnet_destroy(net);
return NULL;
}
/* Build packet handler objects.
*
--- 260,275 ----
net->pcap_fd = pcap_fileno(net->pcap);
if(net->pcap_fd < 0) {
! error_message("rawnet: cannot get descriptor for %s, this system may not be supported.", device);
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->hw_addr);
+ rawnet_get_ip_addr(net, &net->ip_addr);
+
/* Build packet handler objects.
*
***************
*** 229,256 ****
net->dhcp_p = dhcp_create();
- /* For now we use the real hardware address in hw_addr.
- * rawnet_use_fake_hw_addr can always be called to change
- * this. */
-
- rawnet_get_interface_hw_addr(net, &net->hw_addr);
-
return net;
}
/* Use a fake hardware address (diagnostic purposes). We need to
! * reinitialize our rawnet to use promiscious packet
! * capturing. */
void rawnet_use_fake_hw_addr(rawnet_t *net, char *mac_string)
{
! unsigned char *mac_addr;
!
!
! mac_addr = xmalloc(ETH_ADDR_LEN);
if(hex_string_to_value(mac_string, mac_addr))
fatal_error("malformed mac_string for fake client hw addr. please check mac address.");
memcpy(net->hw_addr.data, mac_addr, ETH_ADDR_LEN);
! xfree(mac_addr);
return;
--- 285,307 ----
net->dhcp_p = dhcp_create();
return net;
}
/* Use a fake hardware address (diagnostic purposes). We need to
! * reinitialize our rawnet to use promiscious packet capturing
! * since we do want to accept packets for this hardware
! * address. */
void 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))
fatal_error("malformed mac_string for fake client hw addr. please check mac address.");
memcpy(net->hw_addr.data, mac_addr, ETH_ADDR_LEN);
!
! /* now reinitialize in promiscious mode */
! reinitialize_rawnet(net, 1);
return;
***************
*** 261,264 ****
--- 312,319 ----
if(net->eth != NULL)
eth_close(net->eth);
+
+ if(net->intf_handle) {
+ destroy_interface_control(net->intf_handle);
+ }
if(net->pcap != NULL)
***************
*** 273,277 ****
if(net->pcap_filter)
xfree(net->pcap_filter);
!
if(net->ether_p)
eth_destroy(net->ether_p);
--- 328,332 ----
if(net->pcap_filter)
xfree(net->pcap_filter);
!
if(net->ether_p)
eth_destroy(net->ether_p);
***************
*** 287,295 ****
dhcp_destroy(net->dhcp_p);
! xfree(net);
return;
}
/* Bring pcap/dnet up and down.
* Useful for wait states when
--- 342,354 ----
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
***************
*** 323,326 ****
--- 382,394 ----
}
+ void reinitialize_rawnet(rawnet_t *net, int promiscious)
+ {
+ net->promiscious = promiscious;
+ rawnet_down(net);
+ rawnet_up(net);
+
+ return;
+ }
+
/*
* rawnet get packet:
***************
*** 523,527 ****
if(rawnet_send_packet(net) < 0) {
! error_message("could not send packet: %s", strerror(errno));
rtt_destroy(rtt);
return -1;
--- 591,595 ----
if(rawnet_send_packet(net) < 0) {
! error_message("rawnet: could not send packet: %s", strerror(errno));
rtt_destroy(rtt);
return -1;
***************
*** 535,539 ****
case RAWNET_PCAP_ERROR:
! error_message("couldn't wait for packets: %s : %s", net->device,
strerror(errno));
rtt_destroy(rtt);
--- 603,607 ----
case RAWNET_PCAP_ERROR:
! error_message("rawnet: couldn't wait for packets: %s : %s", net->device,
strerror(errno));
rtt_destroy(rtt);
***************
*** 572,576 ****
default:
! error_message("invalid return from rawnet_send_packet() -- this is a bug report it please");
break;
}
--- 640,644 ----
default:
! error_message("rawnet: invalid return from rawnet_send_packet() -- this is a bug report it please");
break;
}
Index: dhcp-sysconf.c
===================================================================
RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-sysconf.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** dhcp-sysconf.c 15 Feb 2002 09:19:52 -0000 1.8
--- dhcp-sysconf.c 18 May 2002 18:10:09 -0000 1.9
***************
*** 227,231 ****
fatal_error("do not have enough settings for interface configuration!");
! if(interface_up(dc->interface_control, addr, netmask, mtu))
fatal_error("could not bring up interface: %s", dc->interface);
--- 227,231 ----
fatal_error("do not have enough settings for interface configuration!");
! if(rawnet_interface_up(dc->rawnet, addr, netmask, mtu))
fatal_error("could not bring up interface: %s", dc->interface);
***************
*** 268,275 ****
info_message("configuring for option %s", dhcp_options_strings[i]);
!
!
data = option_convert_handlers[i].serialize_to_internal(ce->value);
! sysconf_handlers[i].sysconf_handler(data, dc);
option_convert_handlers[i].free_internal(data);
}
--- 268,278 ----
info_message("configuring for option %s", dhcp_options_strings[i]);
!
data = option_convert_handlers[i].serialize_to_internal(ce->value);
!
! if(sysconf_handlers[i].sysconf_handler(data, dc))
! error_message("error configuring for option %s: %s", dhcp_options_strings[i],
! strerror(errno));
!
option_convert_handlers[i].free_internal(data);
}
Index: dhcp-util.c
===================================================================
RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-util.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** dhcp-util.c 25 Feb 2002 01:39:30 -0000 1.9
--- dhcp-util.c 18 May 2002 18:10:09 -0000 1.10
***************
*** 291,296 ****
}
! /* interface to splice_string. */
!
char *splice_many_strings(int num, char *string, ...)
{
--- 291,295 ----
}
! /* splice many strings lets us pass a variable amount of strings to be spliced. */
char *splice_many_strings(int num, char *string, ...)
{
|