diff mbox series

[net-next] vxlan: remove fdb when out interface is removed

Message ID 20200527162950.9343-1-ap420073@gmail.com
State Deferred
Delegated to: David Miller
Headers show
Series [net-next] vxlan: remove fdb when out interface is removed | expand

Commit Message

Taehee Yoo May 27, 2020, 4:29 p.m. UTC
vxlan fdb can have NDA_IFINDEX, which indicates an out interface.
If the interface is removed, that fdb will not work.
So, when interface is removed, vxlan's fdb can be removed.

Test commands:
    ip link add dummy0 type dummy
    ip link add vxlan0 type vxlan vni 1000
    bridge fdb add 11:22:33:44:55:66 dst 1.1.1.1 dev vxlan0 via dummy0 self
    ip link del dummy0

Before this patch, fdbs will not be removed.
Result:
    bridge fdb show dev vxlan0
11:22:33:44:55:66 dst 1.1.1.1 via if10 self permanent

'if10' indicates 'dummy0' interface index.
But the dummy0 interface was removed so this fdb will not work.

Signed-off-by: Taehee Yoo <ap420073@gmail.com>
---
 drivers/net/vxlan.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

Comments

David Miller May 29, 2020, 11:42 p.m. UTC | #1
From: Taehee Yoo <ap420073@gmail.com>
Date: Wed, 27 May 2020 16:29:50 +0000

> vxlan fdb can have NDA_IFINDEX, which indicates an out interface.
> If the interface is removed, that fdb will not work.
> So, when interface is removed, vxlan's fdb can be removed.
> 
> Test commands:
>     ip link add dummy0 type dummy
>     ip link add vxlan0 type vxlan vni 1000
>     bridge fdb add 11:22:33:44:55:66 dst 1.1.1.1 dev vxlan0 via dummy0 self
>     ip link del dummy0
> 
> Before this patch, fdbs will not be removed.
> Result:
>     bridge fdb show dev vxlan0
> 11:22:33:44:55:66 dst 1.1.1.1 via if10 self permanent
> 
> 'if10' indicates 'dummy0' interface index.
> But the dummy0 interface was removed so this fdb will not work.
> 
> Signed-off-by: Taehee Yoo <ap420073@gmail.com>

But if someone adds an interface afterwards with ifindex 10 that FDB
entry will start using it.

I don't know how desirable that is, but if someone is depending upon
that behavior now this change will break things for them.
Taehee Yoo June 1, 2020, 12:04 p.m. UTC | #2
On Sat, 30 May 2020 at 08:42, David Miller <davem@davemloft.net> wrote:
>

Hi David,
Thanks a lot for your review!

> From: Taehee Yoo <ap420073@gmail.com>
> Date: Wed, 27 May 2020 16:29:50 +0000
>
> > vxlan fdb can have NDA_IFINDEX, which indicates an out interface.
> > If the interface is removed, that fdb will not work.
> > So, when interface is removed, vxlan's fdb can be removed.
> >
> > Test commands:
> >     ip link add dummy0 type dummy
> >     ip link add vxlan0 type vxlan vni 1000
> >     bridge fdb add 11:22:33:44:55:66 dst 1.1.1.1 dev vxlan0 via dummy0 self
> >     ip link del dummy0
> >
> > Before this patch, fdbs will not be removed.
> > Result:
> >     bridge fdb show dev vxlan0
> > 11:22:33:44:55:66 dst 1.1.1.1 via if10 self permanent
> >
> > 'if10' indicates 'dummy0' interface index.
> > But the dummy0 interface was removed so this fdb will not work.
> >
> > Signed-off-by: Taehee Yoo <ap420073@gmail.com>
>
> But if someone adds an interface afterwards with ifindex 10 that FDB
> entry will start using it.
>
> I don't know how desirable that is, but if someone is depending upon
> that behavior now this change will break things for them.

I also don't know whether reusing FDBs is a valid way.
But, as you said, this patch may break existing things.
So, I think this patch should be dropped.

Thanks a lot!
Taehee Yoo
diff mbox series

Patch

diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
index a0015cdedfaf..52ca735bd91a 100644
--- a/drivers/net/vxlan.c
+++ b/drivers/net/vxlan.c
@@ -4440,6 +4440,39 @@  struct net_device *vxlan_dev_create(struct net *net, const char *name,
 }
 EXPORT_SYMBOL_GPL(vxlan_dev_create);
 
+static void vxlan_delete_rdst(struct vxlan_dev *vxlan, unsigned int h,
+			      int ifindex)
+{
+	struct hlist_node *tmp;
+	struct vxlan_fdb *f;
+
+	spin_lock_bh(&vxlan->hash_lock[h]);
+	hlist_for_each_entry_safe(f, tmp, &vxlan->fdb_head[h], hlist) {
+		struct vxlan_rdst *rd, *rd_next;
+
+		list_for_each_entry_safe(rd, rd_next, &f->remotes, list) {
+			if (rd->remote_ifindex != ifindex)
+				continue;
+
+			if (list_is_singular(&f->remotes))
+				vxlan_fdb_destroy(vxlan, f, true, true);
+			else
+				vxlan_fdb_dst_destroy(vxlan, f, rd, true);
+		}
+	}
+	spin_unlock_bh(&vxlan->hash_lock[h]);
+}
+
+static void vxlan_delete_rdsts(struct vxlan_net *vn, struct net_device *dev)
+{
+	struct vxlan_dev *vxlan, *next;
+	unsigned int h;
+
+	list_for_each_entry_safe(vxlan, next, &vn->vxlan_list, next)
+		for (h = 0; h < FDB_HASH_SIZE; ++h)
+			vxlan_delete_rdst(vxlan, h, dev->ifindex);
+}
+
 static void vxlan_handle_lowerdev_unregister(struct vxlan_net *vn,
 					     struct net_device *dev)
 {
@@ -4470,6 +4503,7 @@  static int vxlan_netdevice_event(struct notifier_block *unused,
 
 	if (event == NETDEV_UNREGISTER) {
 		vxlan_offload_rx_ports(dev, false);
+		vxlan_delete_rdsts(vn, dev);
 		vxlan_handle_lowerdev_unregister(vn, dev);
 	} else if (event == NETDEV_REGISTER) {
 		vxlan_offload_rx_ports(dev, true);