diff --git a/src/arp.c b/src/arp.c index 7c9fa8c..a858488 100644 --- a/src/arp.c +++ b/src/arp.c @@ -70,7 +70,6 @@ static struct arp_data garp = { .arp_check_start_ts = 0, .total_conflicts = 0, .probe_wait_time = 0, - .reply_offset = 0, .using_bpf = false, .relentless_def = false, .router_replied = false, @@ -79,10 +78,9 @@ static struct arp_data garp = { void set_arp_relentless_def(bool v) { garp.relentless_def = v; } -void arp_reply_clear(void) +static void arp_reply_clear(void) { memset(&garp.reply, 0, sizeof garp.reply); - garp.reply_offset = 0; } static void arp_min_close_fd(struct client_state_t cs[static 1]) @@ -745,9 +743,10 @@ server_is_router: bool arp_packet_get(struct client_state_t cs[static 1]) { ssize_t r = 0; - if (garp.reply_offset < sizeof garp.reply) { - r = safe_read(cs->arpFd, (char *)&garp.reply + garp.reply_offset, - sizeof garp.reply - garp.reply_offset); + size_t bytes_read = 0; + if (bytes_read < sizeof garp.reply) { + r = safe_read(cs->arpFd, (char *)&garp.reply + bytes_read, + sizeof garp.reply - bytes_read); if (r == 0) return false; if (r < 0) { @@ -760,10 +759,10 @@ bool arp_packet_get(struct client_state_t cs[static 1]) client_config.interface, __func__, strerror(errno)); return false; } - garp.reply_offset += (size_t)r; + bytes_read += (size_t)r; } - if (garp.reply_offset < ARP_MSG_SIZE) + if (bytes_read < ARP_MSG_SIZE) return false; // Emulate the BPF filters if they are not in use. diff --git a/src/arp.h b/src/arp.h index 6a41ca6..2b4bc61 100644 --- a/src/arp.h +++ b/src/arp.h @@ -91,7 +91,6 @@ struct arp_data { long long last_conflict_ts; // TS of the last conflicting ARP seen. long long arp_check_start_ts; // TS of when we started the // AS_COLLISION_CHECK state. - size_t reply_offset; unsigned int total_conflicts; // Total number of address conflicts on // the interface. Never decreases. int gw_check_initpings; // Initial count of ASEND_GW_PING when @@ -104,7 +103,6 @@ struct arp_data { bool server_replied:1; }; -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]); diff --git a/src/ndhc.c b/src/ndhc.c index 72b51fe..6f7a7a4 100644 --- a/src/ndhc.c +++ b/src/ndhc.c @@ -368,8 +368,6 @@ static void do_ndhc_work(void) sev_arp, force_fingerprint, cs.dhcp_wake_ts <= nowts, arp_wake_ts <= nowts, sev_signal); - if (sev_arp) - arp_reply_clear(); if (dhcp_ok == COR_ERROR) { timeout = 2000 + nk_random_u32(&cs.rnd32_state) % 3000;