From 028e0b20563cbe5a7adb350e670181c77f4c9050 Mon Sep 17 00:00:00 2001 From: Tom Gundersen Date: Wed, 19 Aug 2015 19:42:38 +0200 Subject: [PATCH] sd-ipv4ll: remove duplicate packet verification Most packets are filtered out by the BPF, so only check for the parts that may actually differ. --- src/libsystemd-network/sd-ipv4ll.c | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/src/libsystemd-network/sd-ipv4ll.c b/src/libsystemd-network/sd-ipv4ll.c index 9736e4d12aa..b6aad2888da 100644 --- a/src/libsystemd-network/sd-ipv4ll.c +++ b/src/libsystemd-network/sd-ipv4ll.c @@ -172,26 +172,15 @@ static void ipv4ll_set_next_wakeup(sd_ipv4ll *ll, int sec, int random_sec) { ll->next_wakeup_valid = 1; } -static bool ipv4ll_arp_conflict (sd_ipv4ll *ll, struct ether_arp *arp) { +static bool ipv4ll_arp_conflict(sd_ipv4ll *ll, struct ether_arp *arp) { assert(ll); assert(arp); + /* see the BPF */ if (memcmp(arp->arp_spa, &ll->address, sizeof(ll->address)) == 0) return true; - return false; -} - -static bool ipv4ll_arp_probe_conflict (sd_ipv4ll *ll, struct ether_arp *arp) { - assert(ll); - assert(arp); - - if (ipv4ll_arp_conflict(ll, arp)) - return true; - - if (memcmp(arp->arp_tpa, &ll->address, sizeof(ll->address)) == 0) - return true; - + /* the TPA matched instead of the SPA, this is not a conflict */ return false; } @@ -368,11 +357,10 @@ static int ipv4ll_on_packet(sd_event_source *s, int fd, case IPV4LL_STATE_WAITING_PROBE: case IPV4LL_STATE_PROBING: case IPV4LL_STATE_WAITING_ANNOUNCE: - if (ipv4ll_arp_probe_conflict(ll, &packet)) { - r = ipv4ll_on_conflict(ll); - if (r < 0) - goto out; - } + /* BPF ensures this packet indicates a conflict */ + r = ipv4ll_on_conflict(ll); + if (r < 0) + goto out; break; default: