[dhcp-agent-commits] dhcp-agent dhcp-agent.h,1.71,1.72 dhcp-arp-discovery.c,1.10,1.11 dhcp-client-st
Status: Alpha
Brought to you by:
actmodern
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv1699 Modified Files: dhcp-agent.h dhcp-arp-discovery.c dhcp-client-states.c dhcp-icmp-discovery.c dhcp-net.c dhcp-net.h dhcp-rtt.c dhcp-rtt.h Log Message: rtt mechanism update: now allows upper cap Index: dhcp-agent.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-agent.h,v retrieving revision 1.71 retrieving revision 1.72 diff -C2 -d -r1.71 -r1.72 *** dhcp-agent.h 22 Oct 2002 00:46:14 -0000 1.71 --- dhcp-agent.h 23 Oct 2002 23:43:34 -0000 1.72 *************** *** 155,158 **** --- 155,163 ---- #define MESSAGE_LINE_LENGTH 60 + /* as mentioned in rfc2131, 64 seconds is the recommended upper + * limit of waiting time for ethernet. */ + + #define RECOMMENDED_MAX_SECS_WAIT 10 + /* * * * * * * * * * * * Data structures. * Index: dhcp-arp-discovery.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-arp-discovery.c,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** dhcp-arp-discovery.c 21 Oct 2002 01:02:48 -0000 1.10 --- dhcp-arp-discovery.c 23 Oct 2002 23:43:34 -0000 1.11 *************** *** 84,88 **** while(retries--) { ! retval = rawnet_packet_transact(net, arg_list, NULL, check_for_arp_reply); switch(retval) { --- 84,88 ---- while(retries--) { ! retval = rawnet_packet_transact(net, arg_list, NULL, check_for_arp_reply, RECOMMENDED_MAX_SECS_WAIT); switch(retval) { Index: dhcp-client-states.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client-states.c,v retrieving revision 1.41 retrieving revision 1.42 diff -C2 -d -r1.41 -r1.42 *** dhcp-client-states.c 21 Oct 2002 01:02:48 -0000 1.41 --- dhcp-client-states.c 23 Oct 2002 23:43:34 -0000 1.42 *************** *** 292,296 **** retval = rawnet_packet_transact(dc->rawnet, dc, client_update_packet, ! client_check_discover); switch(retval) { --- 292,296 ---- retval = rawnet_packet_transact(dc->rawnet, dc, client_update_packet, ! client_check_discover, RECOMMENDED_MAX_SECS_WAIT); switch(retval) { *************** *** 359,363 **** build_dhcp_request_broadcast(dc->rawnet, dc->xid, dc->secs, options); ! retval = rawnet_packet_transact(dc->rawnet, dc, NULL, client_check_request); switch(retval) { --- 359,363 ---- build_dhcp_request_broadcast(dc->rawnet, dc->xid, dc->secs, options); ! retval = rawnet_packet_transact(dc->rawnet, dc, NULL, client_check_request, RECOMMENDED_MAX_SECS_WAIT); switch(retval) { Index: dhcp-icmp-discovery.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-icmp-discovery.c,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** dhcp-icmp-discovery.c 21 Oct 2002 01:02:48 -0000 1.20 --- dhcp-icmp-discovery.c 23 Oct 2002 23:43:34 -0000 1.21 *************** *** 72,76 **** while(retries--) { ! retval = rawnet_packet_transact(net, net, NULL, icmp_check_mask_reply); switch(retval) { --- 72,76 ---- while(retries--) { ! retval = rawnet_packet_transact(net, net, NULL, icmp_check_mask_reply, RECOMMENDED_MAX_SECS_WAIT); switch(retval) { *************** *** 129,133 **** gettimeofday(&before, NULL); ! if(rawnet_packet_transact(net, net, NULL, icmp_check_echo_reply)) { /* on a timeout we set the latency to -1 */ return -1; --- 129,133 ---- gettimeofday(&before, NULL); ! if(rawnet_packet_transact(net, net, NULL, icmp_check_echo_reply, RECOMMENDED_MAX_SECS_WAIT)) { /* on a timeout we set the latency to -1 */ return -1; Index: dhcp-net.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-net.c,v retrieving revision 1.35 retrieving revision 1.36 diff -C2 -d -r1.35 -r1.36 *** dhcp-net.c 21 Oct 2002 01:02:48 -0000 1.35 --- dhcp-net.c 23 Oct 2002 23:43:34 -0000 1.36 *************** *** 68,71 **** --- 68,75 ---- #include <net/bpf.h> + /************************ + * Address Manipulation.* + ************************/ + /* get interface address. */ int rawnet_get_hw_addr(rawnet_t *net, eth_addr_t *addr) *************** *** 367,371 **** } - /* XXX -- if we fail we should rawnet down it. */ int rawnet_up(rawnet_t *net) { --- 371,374 ---- *************** *** 607,614 **** */ - /* FIXME --: this needs to return a fatal error, timeout, or OK status */ - int rawnet_packet_transact(rawnet_t *net, void *arg, void (*update)(void *arg), ! int (*check)(void *arg)) { rtt_t *rtt; --- 610,615 ---- */ int rawnet_packet_transact(rawnet_t *net, void *arg, void (*update)(void *arg), ! int (*check)(void *arg), time_t max_timeout) { rtt_t *rtt; *************** *** 618,622 **** /* create rtt mechanism. */ ! rtt = rtt_create(); /* We loop here and re-send packets if we timeout, or fail a --- 619,623 ---- /* create rtt mechanism. */ ! rtt = rtt_create(max_timeout); /* We loop here and re-send packets if we timeout, or fail a Index: dhcp-net.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-net.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dhcp-net.h 14 Oct 2002 15:52:33 -0000 1.4 --- dhcp-net.h 23 Oct 2002 23:43:34 -0000 1.5 *************** *** 61,65 **** extern int rawnet_packet_transact(rawnet_t *net, void *arg, void (*update)(void *arg), ! int (*check)(void *arg)); extern int rawnet_interface_up(rawnet_t *net, ip_addr_t addr, ip_addr_t netmask, int mtu); --- 61,66 ---- extern int rawnet_packet_transact(rawnet_t *net, void *arg, void (*update)(void *arg), ! int (*check)(void *arg), ! time_t max_timeout); extern int rawnet_interface_up(rawnet_t *net, ip_addr_t addr, ip_addr_t netmask, int mtu); Index: dhcp-rtt.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-rtt.c,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** dhcp-rtt.c 12 Oct 2002 22:54:50 -0000 1.8 --- dhcp-rtt.c 23 Oct 2002 23:43:34 -0000 1.9 *************** *** 33,49 **** tm.tv_sec = MSECS_TO_SECS(milliseconds); ! tm.tv_usec = MSECS_TO_MSECS_REM(milliseconds); return tm; } ! rtt_t *rtt_create(void) { rtt_t *rtt; - time_t milliseconds; rtt = xmalloc(sizeof(rtt_t)); ! milliseconds = MILLISECOND_TIMEOUT + rand()%MILLISECOND_RAND_TIMEOUT; ! rtt->timeout = make_timeval(milliseconds); return rtt; --- 33,58 ---- tm.tv_sec = MSECS_TO_SECS(milliseconds); ! tm.tv_usec = MSECS_TO_SECS_REM(milliseconds); return tm; } ! static struct timeval init_timeout(void) ! { ! struct timeval timeout; ! ! timeout = make_timeval(MILLISECOND_TIMEOUT + rand()%MILLISECOND_RAND_TIMEOUT); ! return timeout; ! } ! ! rtt_t *rtt_create(time_t max_timeout) { rtt_t *rtt; rtt = xmalloc(sizeof(rtt_t)); ! rtt->timeout = init_timeout(); ! rtt->max_timeout = max_timeout; ! rtt->start_time = time(NULL); ! rtt->elapsed_time = 0; /* we hope :-) */ return rtt; *************** *** 71,75 **** else { /* we're not safe subtracting. don't go below 0. */ ! if(rand_value < milliseconds) milliseconds -= rand_value; else --- 80,84 ---- else { /* we're not safe subtracting. don't go below 0. */ ! if(rand_value <= milliseconds) milliseconds -= rand_value; else *************** *** 84,99 **** { time_t milliseconds; - - milliseconds = SECS_TO_MSECS(rtt->timeout.tv_sec); - milliseconds += rtt->timeout.tv_usec; ! if(milliseconds == 0) /* should never happen but let's check here ! * for safe divide. */ return 0; ! if(milliseconds >= (SECS_TO_MSECS(MAX_SECS_WAIT))) ! return 0; ! else ! return 1; } --- 93,120 ---- { time_t milliseconds; ! rtt->elapsed_time = time(NULL) - rtt->start_time; ! ! if(rtt->elapsed_time >= rtt->max_timeout) { return 0; + } + + milliseconds = SECS_TO_MSECS(rtt->timeout.tv_sec); + milliseconds += rtt->timeout.tv_usec; ! if((milliseconds >= (SECS_TO_MSECS(RECOMMENDED_MAX_SECS_WAIT))) || ! (milliseconds >= (rtt->max_timeout - rtt->elapsed_time))) { ! ! /* It's perfectly possible for this to put us over the top ! * of our max_timeout but it's no big deal since our initial ! * timeout is pretty small anyway. */ ! ! rtt->timeout = init_timeout(); ! ! } else { ! rtt->timeout = make_timeval(milliseconds); ! } ! ! return 1; } Index: dhcp-rtt.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-rtt.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dhcp-rtt.h 17 Jun 2002 13:23:08 -0000 1.2 --- dhcp-rtt.h 23 Oct 2002 23:43:34 -0000 1.3 *************** *** 30,35 **** #define MILLISECOND_TIMEOUT 4000 #define MILLISECOND_RAND_TIMEOUT 1000 - #define MAX_SECS_WAIT 64 /* as mentioned in rfc2131, - * 64 seconds is the upper limit of waiting time. */ /* Utility macros. */ --- 30,33 ---- *************** *** 37,41 **** #define SECS_TO_MSECS(x) (x * 1000) #define MSECS_TO_SECS(x) (x/1000) ! #define MSECS_TO_MSECS_REM(x) (x%1000) /* rtt struct. */ --- 35,39 ---- #define SECS_TO_MSECS(x) (x * 1000) #define MSECS_TO_SECS(x) (x/1000) ! #define MSECS_TO_SECS_REM(x) (x%1000) /* rtt struct. */ *************** *** 43,51 **** typedef struct rtt { struct timeval timeout; } rtt_t; /* prototypes. */ ! extern rtt_t *rtt_create(void); extern struct timeval rtt_get_timeout(rtt_t *rtt); extern void rtt_timeout(rtt_t *rtt); --- 41,52 ---- typedef struct rtt { struct timeval timeout; + time_t max_timeout; + time_t start_time; + time_t elapsed_time; } rtt_t; /* prototypes. */ ! 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); |