arp: Remove reply_offset, and keep previous ARP packet after epoll.
ARP packets aren't split across multiple receive events, so reply_offset is pointless, and we implicitly assume that the previous ARP packet data is still available after a forced sleep.
This commit is contained in:
parent
bdad082a62
commit
7af3e64a99
15
src/arp.c
15
src/arp.c
@ -70,7 +70,6 @@ static struct arp_data garp = {
|
|||||||
.arp_check_start_ts = 0,
|
.arp_check_start_ts = 0,
|
||||||
.total_conflicts = 0,
|
.total_conflicts = 0,
|
||||||
.probe_wait_time = 0,
|
.probe_wait_time = 0,
|
||||||
.reply_offset = 0,
|
|
||||||
.using_bpf = false,
|
.using_bpf = false,
|
||||||
.relentless_def = false,
|
.relentless_def = false,
|
||||||
.router_replied = 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 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);
|
memset(&garp.reply, 0, sizeof garp.reply);
|
||||||
garp.reply_offset = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void arp_min_close_fd(struct client_state_t cs[static 1])
|
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])
|
bool arp_packet_get(struct client_state_t cs[static 1])
|
||||||
{
|
{
|
||||||
ssize_t r = 0;
|
ssize_t r = 0;
|
||||||
if (garp.reply_offset < sizeof garp.reply) {
|
size_t bytes_read = 0;
|
||||||
r = safe_read(cs->arpFd, (char *)&garp.reply + garp.reply_offset,
|
if (bytes_read < sizeof garp.reply) {
|
||||||
sizeof garp.reply - garp.reply_offset);
|
r = safe_read(cs->arpFd, (char *)&garp.reply + bytes_read,
|
||||||
|
sizeof garp.reply - bytes_read);
|
||||||
if (r == 0)
|
if (r == 0)
|
||||||
return false;
|
return false;
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
@ -760,10 +759,10 @@ bool arp_packet_get(struct client_state_t cs[static 1])
|
|||||||
client_config.interface, __func__, strerror(errno));
|
client_config.interface, __func__, strerror(errno));
|
||||||
return false;
|
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;
|
return false;
|
||||||
|
|
||||||
// Emulate the BPF filters if they are not in use.
|
// Emulate the BPF filters if they are not in use.
|
||||||
|
@ -91,7 +91,6 @@ struct arp_data {
|
|||||||
long long last_conflict_ts; // TS of the last conflicting ARP seen.
|
long long last_conflict_ts; // TS of the last conflicting ARP seen.
|
||||||
long long arp_check_start_ts; // TS of when we started the
|
long long arp_check_start_ts; // TS of when we started the
|
||||||
// AS_COLLISION_CHECK state.
|
// AS_COLLISION_CHECK state.
|
||||||
size_t reply_offset;
|
|
||||||
unsigned int total_conflicts; // Total number of address conflicts on
|
unsigned int total_conflicts; // Total number of address conflicts on
|
||||||
// the interface. Never decreases.
|
// the interface. Never decreases.
|
||||||
int gw_check_initpings; // Initial count of ASEND_GW_PING when
|
int gw_check_initpings; // Initial count of ASEND_GW_PING when
|
||||||
@ -104,7 +103,6 @@ struct arp_data {
|
|||||||
bool server_replied:1;
|
bool server_replied:1;
|
||||||
};
|
};
|
||||||
|
|
||||||
void arp_reply_clear(void);
|
|
||||||
void arp_reset_state(struct client_state_t cs[static 1]);
|
void arp_reset_state(struct client_state_t cs[static 1]);
|
||||||
|
|
||||||
bool arp_packet_get(struct client_state_t cs[static 1]);
|
bool arp_packet_get(struct client_state_t cs[static 1]);
|
||||||
|
@ -368,8 +368,6 @@ static void do_ndhc_work(void)
|
|||||||
sev_arp, force_fingerprint,
|
sev_arp, force_fingerprint,
|
||||||
cs.dhcp_wake_ts <= nowts,
|
cs.dhcp_wake_ts <= nowts,
|
||||||
arp_wake_ts <= nowts, sev_signal);
|
arp_wake_ts <= nowts, sev_signal);
|
||||||
if (sev_arp)
|
|
||||||
arp_reply_clear();
|
|
||||||
|
|
||||||
if (dhcp_ok == COR_ERROR) {
|
if (dhcp_ok == COR_ERROR) {
|
||||||
timeout = 2000 + nk_random_u32(&cs.rnd32_state) % 3000;
|
timeout = 2000 + nk_random_u32(&cs.rnd32_state) % 3000;
|
||||||
|
Loading…
Reference in New Issue
Block a user