net: l2: Clear arp cache when disable interface.
When connect to diffrent router with the same gateway ip address, need to clear arp cache when disable interface, or it will use the wrong gateway mac address. Call net_arp_clear_cache function replace to set arp_table 0. Change-Id: Ib403a0c0030832ba48824db4d2d3fcb8add63d16 Signed-off-by: june li <junelizh@foxmail.com>
This commit is contained in:
parent
acedb70a94
commit
3e4faffede
3 changed files with 29 additions and 2 deletions
|
@ -39,10 +39,12 @@ struct net_arp_hdr {
|
||||||
struct net_pkt *net_arp_prepare(struct net_pkt *pkt);
|
struct net_pkt *net_arp_prepare(struct net_pkt *pkt);
|
||||||
enum net_verdict net_arp_input(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);
|
void net_arp_init(void);
|
||||||
|
|
||||||
#else /* CONFIG_NET_ARP */
|
#else /* CONFIG_NET_ARP */
|
||||||
|
|
||||||
|
#define net_arp_clear_cache(...)
|
||||||
#define net_arp_init(...)
|
#define net_arp_init(...)
|
||||||
|
|
||||||
#endif /* CONFIG_NET_ARP */
|
#endif /* CONFIG_NET_ARP */
|
||||||
|
|
|
@ -483,7 +483,20 @@ enum net_verdict net_arp_input(struct net_pkt *pkt)
|
||||||
return NET_OK;
|
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));
|
memset(&arp_table, 0, sizeof(arp_table));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void net_arp_init(void)
|
||||||
|
{
|
||||||
|
net_arp_clear_cache();
|
||||||
|
}
|
||||||
|
|
|
@ -310,4 +310,16 @@ static inline u16_t ethernet_reserve(struct net_if *iface, void *unused)
|
||||||
return sizeof(struct net_eth_hdr);
|
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);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue