From 348e975f2db79f436e428e298e4bab6f5322eac2 Mon Sep 17 00:00:00 2001 From: "Nicholas J. Kain" Date: Mon, 27 Feb 2017 11:30:35 -0500 Subject: [PATCH] reinit_shared_deconfig() was not fully resetting arp state. --- src/arp.c | 45 +++++++++++++++++++++++++++------------------ src/arp.h | 3 +-- src/state.c | 3 +-- 3 files changed, 29 insertions(+), 22 deletions(-) diff --git a/src/arp.c b/src/arp.c index 6d9b35e..7c9fa8c 100644 --- a/src/arp.c +++ b/src/arp.c @@ -85,8 +85,34 @@ void arp_reply_clear(void) garp.reply_offset = 0; } -void arp_reset_send_stats(void) +static void arp_min_close_fd(struct client_state_t cs[static 1]) { + if (cs->arpFd < 0) + return; + epoll_del(cs->epollFd, cs->arpFd); + close(cs->arpFd); + cs->arpFd = -1; + cs->arp_is_defense = false; +} + +static void arp_close_fd(struct client_state_t cs[static 1]) +{ + arp_min_close_fd(cs); + for (int i = 0; i < AS_MAX; ++i) + garp.wake_ts[i] = -1; +} + +void arp_reset_state(struct client_state_t cs[static 1]) +{ + arp_close_fd(cs); + arp_reply_clear(); + garp.last_conflict_ts = 0; + garp.gw_check_initpings = 0; + garp.arp_check_start_ts = 0; + garp.total_conflicts = 0; + garp.probe_wait_time = 0; + garp.server_replied = false; + garp.router_replied = false; for (int i = 0; i < ASEND_MAX; ++i) { garp.send_stats[i].ts = 0; garp.send_stats[i].count = 0; @@ -129,23 +155,6 @@ static int get_arp_defense_socket(struct client_state_t cs[static 1]) return fd; } -static void arp_min_close_fd(struct client_state_t cs[static 1]) -{ - if (cs->arpFd < 0) - return; - epoll_del(cs->epollFd, cs->arpFd); - close(cs->arpFd); - cs->arpFd = -1; - cs->arp_is_defense = false; -} - -void arp_close_fd(struct client_state_t cs[static 1]) -{ - arp_min_close_fd(cs); - for (int i = 0; i < AS_MAX; ++i) - garp.wake_ts[i] = -1; -} - static int arp_open_fd(struct client_state_t cs[static 1], bool defense) { if (cs->arpFd >= 0 && defense == cs->arp_is_defense) diff --git a/src/arp.h b/src/arp.h index 409c3dc..6a41ca6 100644 --- a/src/arp.h +++ b/src/arp.h @@ -105,12 +105,11 @@ struct arp_data { }; void arp_reply_clear(void); +void arp_reset_state(struct client_state_t cs[static 1]); bool arp_packet_get(struct client_state_t cs[static 1]); void set_arp_relentless_def(bool v); -void arp_reset_send_stats(void); -void arp_close_fd(struct client_state_t cs[static 1]); int arp_check(struct client_state_t cs[static 1], struct dhcpmsg packet[static 1]); int arp_gw_check(struct client_state_t cs[static 1]); diff --git a/src/state.c b/src/state.c index c73b72e..7d4ec66 100644 --- a/src/state.c +++ b/src/state.c @@ -75,7 +75,6 @@ static int delay_timeout(struct client_state_t cs[static 1], size_t numpackets) static void reinit_shared_deconfig(struct client_state_t cs[static 1]) { - arp_close_fd(cs); cs->clientAddr = 0; cs->num_dhcp_requests = 0; cs->got_router_arp = false; @@ -86,7 +85,7 @@ static void reinit_shared_deconfig(struct client_state_t cs[static 1]) cs->sent_second_announce = false; memset(&cs->routerArp, 0, sizeof cs->routerArp); memset(&cs->serverArp, 0, sizeof cs->serverArp); - arp_reset_send_stats(); + arp_reset_state(cs); } static void reinit_selecting(struct client_state_t cs[static 1], int timeout)