From a92cb1c4c67cc46c1576afff5c917760f35f19a3 Mon Sep 17 00:00:00 2001 From: "Nicholas J. Kain" Date: Wed, 6 Jul 2011 08:46:05 -0400 Subject: [PATCH] Randomize the DHCP timeout by +[0,1000]ms to comply with RFC. --- ndhc/arp.c | 8 ++++---- ndhc/state.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ndhc/arp.c b/ndhc/arp.c index 881c837..e638469 100644 --- a/ndhc/arp.c +++ b/ndhc/arp.c @@ -1,5 +1,5 @@ /* arp.c - arp ping checking - * Time-stamp: <2011-07-05 16:00:42 njk> + * Time-stamp: <2011-07-06 08:41:06 njk> * * Copyright 2010-2011 Nicholas J. Kain * @@ -123,7 +123,7 @@ static void arp_set_bpf_basic(int fd) BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, (ETH_P_IP << 16) | 0x0604, 1, 0), BPF_STMT(BPF_RET + BPF_K, 0), // Sanity tests passed, so send all possible data. - BPF_STMT(BPF_RET + BPF_K, 0x0fffffff), + BPF_STMT(BPF_RET + BPF_K, 0x7fffffff), }; static const struct sock_fprog sfp_arp = { .len = sizeof sf_arp / sizeof sf_arp[0], @@ -164,13 +164,13 @@ static void arp_set_bpf_defense(struct client_state_t *cs, int fd) // be passed along. BPF_STMT(BPF_LD + BPF_W + BPF_ABS, 22), BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, mac4b, 1, 0), - BPF_STMT(BPF_RET + BPF_K, 0x0fffffff), + BPF_STMT(BPF_RET + BPF_K, 0x7fffffff), // If the last two bytes of the ARP packet source hardware address // do not equal our hardware address, then it's a conflict and should // be passed along. BPF_STMT(BPF_LD + BPF_H + BPF_ABS, 26), BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, mac2b, 1, 0), - BPF_STMT(BPF_RET + BPF_K, 0x0fffffff), + BPF_STMT(BPF_RET + BPF_K, 0x7fffffff), // Packet announces our IP address and hardware address, so it requires // no action. BPF_STMT(BPF_RET + BPF_K, 0), diff --git a/ndhc/state.c b/ndhc/state.c index 6caf83d..f074bd9 100644 --- a/ndhc/state.c +++ b/ndhc/state.c @@ -56,7 +56,7 @@ static int delay_timeout(int numpackets) char tot[] = { 4, 8, 16, 32, 64 }; if (numpackets < sizeof tot) to = tot[numpackets]; - return to * 1000; + return to * 1000 + rand() % 1000; } void reinit_selecting(struct client_state_t *cs, int timeout) @@ -192,7 +192,7 @@ static void an_packet(struct client_state_t *cs, struct dhcpmsg *packet, } else { memcpy(&cs->lease, temp, 4); cs->lease = ntohl(cs->lease); - cs->lease &= 0x0fffffff; + cs->lease &= 0x7fffffff; if (cs->lease < 60) { log_warning("Server sent lease of <1m. Forcing lease to 1m."); cs->lease = 60;