diff --git a/include/net/arp.h b/include/net/arp.h index 4e8ebadf1f0..2a2673699c1 100644 --- a/include/net/arp.h +++ b/include/net/arp.h @@ -39,10 +39,12 @@ struct net_arp_hdr { struct net_pkt *net_arp_prepare(struct net_pkt *pkt); enum net_verdict net_arp_input(struct net_pkt *pkt); +void net_arp_clear_cache(void); void net_arp_init(void); #else /* CONFIG_NET_ARP */ +#define net_arp_clear_cache(...) #define net_arp_init(...) #endif /* CONFIG_NET_ARP */ diff --git a/subsys/net/ip/l2/arp.c b/subsys/net/ip/l2/arp.c index 940501d6c67..7e78fd5ad64 100644 --- a/subsys/net/ip/l2/arp.c +++ b/subsys/net/ip/l2/arp.c @@ -483,7 +483,20 @@ enum net_verdict net_arp_input(struct net_pkt *pkt) return NET_OK; } -void net_arp_init(void) +void net_arp_clear_cache(void) { + int i; + + for (i = 0; i < CONFIG_NET_ARP_TABLE_SIZE; i++) { + if (arp_table[i].pending) { + net_pkt_unref(arp_table[i].pending); + } + } + memset(&arp_table, 0, sizeof(arp_table)); } + +void net_arp_init(void) +{ + net_arp_clear_cache(); +} diff --git a/subsys/net/ip/l2/ethernet.c b/subsys/net/ip/l2/ethernet.c index b255349e5d8..304220da43c 100644 --- a/subsys/net/ip/l2/ethernet.c +++ b/subsys/net/ip/l2/ethernet.c @@ -310,4 +310,16 @@ static inline u16_t ethernet_reserve(struct net_if *iface, void *unused) return sizeof(struct net_eth_hdr); } -NET_L2_INIT(ETHERNET_L2, ethernet_recv, ethernet_send, ethernet_reserve, NULL); +static inline int ethernet_enable(struct net_if *iface, bool state) +{ + ARG_UNUSED(iface); + + if (!state) { + net_arp_clear_cache(); + } + + return 0; +} + +NET_L2_INIT(ETHERNET_L2, ethernet_recv, ethernet_send, ethernet_reserve, + ethernet_enable);