From ba93041afcff95bac397dc137e3a44fff92176aa Mon Sep 17 00:00:00 2001 From: John Crispin Date: Thu, 2 May 2024 13:50:34 +0200 Subject: [PATCH] spotfilter: use ARP as fallback for IP discovery Signed-off-by: John Crispin --- feeds/ucentral/spotfilter/src/client.c | 10 +++++++--- feeds/ucentral/spotfilter/src/client.h | 2 +- feeds/ucentral/spotfilter/src/dhcpv4.c | 2 +- feeds/ucentral/spotfilter/src/icmpv6.c | 2 +- feeds/ucentral/spotfilter/src/snoop.c | 1 + 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/feeds/ucentral/spotfilter/src/client.c b/feeds/ucentral/spotfilter/src/client.c index 591afc86b..09e893dc0 100644 --- a/feeds/ucentral/spotfilter/src/client.c +++ b/feeds/ucentral/spotfilter/src/client.c @@ -13,6 +13,7 @@ struct cache_entry { struct avl_node node; uint8_t macaddr[ETH_ALEN]; uint32_t arp_ip4addr; + bool arp; uint32_t ip4addr; uint32_t ip6addr[4]; uint32_t time; @@ -214,16 +215,19 @@ out: return c; } -void client_set_ipaddr(const void *mac, const void *addr, bool ipv6) +void client_set_ipaddr(const void *mac, const void *addr, bool ipv6, bool arp) { struct interface *iface; struct cache_entry *c; struct client *cl; c = client_get_cache_entry(mac); - if (!ipv6 && !c->ip4addr) + if (!ipv6 && arp && c->arp) + return; + if (!ipv6 && (!c->ip4addr || c->arp)) { memcpy(&c->ip4addr, addr, sizeof(c->ip4addr)); - else if (ipv6 && !c->ip6addr[0]) + c->arp = arp; + } else if (ipv6 && !c->ip6addr[0]) memcpy(&c->ip6addr, addr, sizeof(c->ip6addr)); else return; diff --git a/feeds/ucentral/spotfilter/src/client.h b/feeds/ucentral/spotfilter/src/client.h index c22acff5c..4857c32ad 100644 --- a/feeds/ucentral/spotfilter/src/client.h +++ b/feeds/ucentral/spotfilter/src/client.h @@ -25,7 +25,7 @@ int client_set(struct interface *iface, const void *addr, const char *id, int state, int dns_state, int accounting, struct blob_attr *data, const char *device, bool flush); void client_free(struct interface *iface, struct client *cl); -void client_set_ipaddr(const void *mac, const void *addr, bool ipv6); +void client_set_ipaddr(const void *mac, const void *addr, bool ipv6, bool arp); void client_set_arp_ipaddr(const void *mac, const void *addr); void client_init_interface(struct interface *iface); diff --git a/feeds/ucentral/spotfilter/src/dhcpv4.c b/feeds/ucentral/spotfilter/src/dhcpv4.c index 661ff9745..fd883e1d5 100644 --- a/feeds/ucentral/spotfilter/src/dhcpv4.c +++ b/feeds/ucentral/spotfilter/src/dhcpv4.c @@ -106,6 +106,6 @@ void spotfilter_recv_dhcpv4(const void *msgdata, int len, const void *eth_addr) if (op != DHCPV4_MSG_ACK) return; - client_set_ipaddr(msg->chaddr, (uint32_t *)&msg->yiaddr, false); + client_set_ipaddr(msg->chaddr, (uint32_t *)&msg->yiaddr, false, false); } diff --git a/feeds/ucentral/spotfilter/src/icmpv6.c b/feeds/ucentral/spotfilter/src/icmpv6.c index 922d3d931..ba85f7c4a 100644 --- a/feeds/ucentral/spotfilter/src/icmpv6.c +++ b/feeds/ucentral/spotfilter/src/icmpv6.c @@ -42,5 +42,5 @@ void spotfilter_recv_icmpv6(const void *data, int len, const uint8_t *src, const if (opt != (const struct icmpv6_opt *)(data + len)) return; - client_set_ipaddr(src, &nd->nd_na_target, true); + client_set_ipaddr(src, &nd->nd_na_target, true, false); } diff --git a/feeds/ucentral/spotfilter/src/snoop.c b/feeds/ucentral/spotfilter/src/snoop.c index c378aecd1..3f1f217fc 100644 --- a/feeds/ucentral/spotfilter/src/snoop.c +++ b/feeds/ucentral/spotfilter/src/snoop.c @@ -441,6 +441,7 @@ spotfilter_packet_cb(struct packet *pkt) break; client_set_arp_ipaddr(eth->h_source, &arp->src_ip); + client_set_ipaddr(eth->h_source, &arp->src_ip, false, true); break; case ETH_P_IP: ip = pkt_peek(pkt, sizeof(struct ip));