summaryrefslogtreecommitdiff
path: root/subsys
diff options
context:
space:
mode:
authorjune li <junelizh@foxmail.com>2017-04-22 14:13:23 +0800
committerJukka Rissanen <jukka.rissanen@linux.intel.com>2017-04-28 15:01:08 +0300
commit3e4faffedebe1a3ee786e9f73e5f6487d679594f (patch)
tree5f07d973ff84b08bb4a037274fcb893e46fea7bb /subsys
parentacedb70a943036c87d6c0373a74a094abdef5ee3 (diff)
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>
Diffstat (limited to 'subsys')
-rw-r--r--subsys/net/ip/l2/arp.c15
-rw-r--r--subsys/net/ip/l2/ethernet.c14
2 files changed, 27 insertions, 2 deletions
diff --git a/subsys/net/ip/l2/arp.c b/subsys/net/ip/l2/arp.c
index 940501d6c..7e78fd5ad 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 b255349e5..304220da4 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);