Skip to contentSkip to conversation

bridge: notify user space of fdb port change

PATCH In review Jon Maxwell 5 participants 8 messages May 13, 2014 – May 24, 2014

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bridge: notify user space of fdb port change

From: Jon Maxwell <[email protected]>

There has been a number incidents recently where customers running KVM have reported that VM hosts on different Hypervisors are unreachable. Based on pcap traces we found that the bridge was broadcasting the ARP request out onto the network. However some NICs have an inbuilt switch which on occasions were broadcasting the VMs ARP request back through the physical NIC on the Hypervisor. This resulted in the bridge changing ports and incorrectly learning that the VMs mac address was external. As a result the ARP reply was directed back onto the external network and VM never updated it's ARP cache. This patch will notify the bridge command to identify such port toggling.

---
 net/bridge/br_fdb.c | 2 ++
 1 file changed, 2 insertions(+)
net/bridge/br_fdb.c +2 -0
index 9203d5a..37742e2 100644
@@ -507,6 +507,8 @@ void br_fdb_update(struct net_bridge *br, struct net_bridge_port *source,
 					source->dev->name);
 		} else {
 			/* fastpath: update of existing entry */
+			if (source->port_no != fdb->dst->port_no)
+				fdb_notify(br, fdb, RTM_NEWNEIGH);
 			fdb->dst = source;
 			fdb->updated = jiffies;
 			if (unlikely(added_by_user))
Signature · 1 line
1.8.3.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 32 lines · Tue, May 13, 2014 at 09:55:08AM CEST, [email protected] wrote:

From: Jon Maxwell <[email protected]>

There has been a number incidents recently where customers running KVM have reported that VM hosts on different Hypervisors are unreachable. Based on pcap traces we found that the bridge was broadcasting the ARP request out onto the network. However some NICs have an inbuilt switch which on occasions were broadcasting the VMs ARP request back through the physical NIC on the Hypervisor. This resulted in the bridge changing ports and incorrectly learning that the VMs mac address was external. As a result the ARP reply was directed back onto the external network and VM never updated it's ARP cache. This patch will notify the bridge command to identify such port toggling.

---
net/bridge/br_fdb.c | 2 ++

1 file changed, 2 insertions(+)
net/bridge/br_fdb.c +2 -0
index 9203d5a..37742e2 100644
@@ -507,6 +507,8 @@ void br_fdb_update(struct net_bridge *br, struct net_bridge_port *source,
 					source->dev->name);
 		} else {
 			/* fastpath: update of existing entry */
+			if (source->port_no != fdb->dst->port_no)
+				fdb_notify(br, fdb, RTM_NEWNEIGH);
 			fdb->dst = source;
 			fdb->updated = jiffies;
 			if (unlikely(added_by_user))
Signature · 1 line
1.8.3.1
#2 lore raw
Quoted 28 lines · On Tue, 13 May 2014 17:16:11 +0200 Jiri Pirko <[email protected]> wrote:
Quoted 27 lines · Tue, May 13, 2014 at 09:55:08AM CEST, [email protected] wrote:

From: Jon Maxwell <[email protected]>

There has been a number incidents recently where customers running KVM have reported that VM hosts on different Hypervisors are unreachable. Based on pcap traces we found that the bridge was broadcasting the ARP request out onto the network. However some NICs have an inbuilt switch which on occasions were broadcasting the VMs ARP request back through the physical NIC on the Hypervisor. This resulted in the bridge changing ports and incorrectly learning that the VMs mac address was external. As a result the ARP reply was directed back onto the external network and VM never updated it's ARP cache. This patch will notify the bridge command to identify such port toggling.

---
net/bridge/br_fdb.c | 2 ++

1 file changed, 2 insertions(+)
net/bridge/br_fdb.c +2 -0
index 9203d5a..37742e2 100644
@@ -507,6 +507,8 @@ void br_fdb_update(struct net_bridge *br, struct net_bridge_port *source,
 					source->dev->name);
 		} else {
 			/* fastpath: update of existing entry */
+			if (source->port_no != fdb->dst->port_no)
+				fdb_notify(br, fdb, RTM_NEWNEIGH);
Quoted 8 lines
Quoted 5 lines
net/bridge/br_fdb.c +0 -0
 			fdb->dst = source;
 			fdb->updated = jiffies;
 			if (unlikely(added_by_user))
Signature · 1 line
1.8.3.1

I like the patch, but please add unlikely() to this conditional. This is in the fast path code for bridge learning.

#3 lore raw
In reply to Jon Maxwell
Quoted 22 lines · Jon Maxwell

From: Jon Maxwell <[email protected]>

There has been a number incidents recently where customers running KVM have reported that VM hosts on different Hypervisors are unreachable. Based on pcap traces we found that the bridge was broadcasting the ARP request out onto the network. However some NICs have an inbuilt switch which on occasions were broadcasting the VMs ARP request back through the physical NIC on the Hypervisor. This resulted in the bridge changing ports and incorrectly learning that the VMs mac address was external. As a result the ARP reply was directed back onto the external network and VM never updated it's ARP cache. This patch will notify the bridge command to identify such port toggling.

---
 net/bridge/br_fdb.c | 2 ++
 1 file changed, 2 insertions(+)
net/bridge/br_fdb.c +0 -0
index 9203d5a..37742e2 100644

net/bridge/br_fdb.c void br_fdb_update(struct net_bridge *br, struct net_bridge_port *source, · line 510

Quoted 4 lines
net/bridge/br_fdb.c +1 -0
@@ -507,6 +507,8 @@ void br_fdb_update(struct net_bridge *br, struct net_bridge_port *source,
 					source->dev->name);
 		} else {
 			/* fastpath: update of existing entry */
+			if (source->port_no != fdb->dst->port_no)

It seems that we don't need to fetch port_no and it is enough to compare source and fdb->dst.

net/bridge/br_fdb.c void br_fdb_update(struct net_bridge *br, struct net_bridge_port *source, · line 514

Quoted 5 lines
net/bridge/br_fdb.c +1 -0
+				fdb_notify(br, fdb, RTM_NEWNEIGH);
 			fdb->dst = source;
 			fdb->updated = jiffies;
 			if (unlikely(added_by_user))

This notifies fdb entry before updating existing entry. Is this on purpose? I think we should notify the updated fdb entry.
Similar code fdb_add_entry() does after updating it.

Also, isn't it better to move update of dst into "if" block?

	if (source != fdb->dst) {
		fdb->dst = source;
		modified = true;
	}
	...
	if (modified) ...

Thanks,
Toshiaki Makita

#4 lore raw

----- Original Message -----

Quoted 29 lines

From: "Toshiaki Makita" <[email protected]>
To: "Jon Maxwell" <[email protected]>, [email protected]
Cc: [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]
Sent: Wednesday, May 14, 2014 10:34:38 AM
Subject: Re: [PATCH net] bridge: notify user space of fdb port change

Quoted 21 lines · Jon Maxwell

From: Jon Maxwell <[email protected]>

There has been a number incidents recently where customers running KVM have reported that VM hosts on different Hypervisors are unreachable. Based on pcap traces we found that the bridge was broadcasting the ARP request out onto the network. However some NICs have an inbuilt switch which on occasions
were broadcasting the VMs ARP request back through the physical NIC on the Hypervisor. This resulted in the bridge changing ports and incorrectly learning
that the VMs mac address was external. As a result the ARP reply was directed
back onto the external network and VM never updated it's ARP cache. This patch
will notify the bridge command to identify such port toggling.

---
 net/bridge/br_fdb.c | 2 ++
 1 file changed, 2 insertions(+)
Quoted 13 lines

net/bridge/br_fdb.c void br_fdb_update(struct net_bridge *br, struct · line 511

Quoted 10 lines
net/bridge/br_fdb.c +1 -0
index 9203d5a..37742e2 100644
@@ -507,6 +507,8 @@ void br_fdb_update(struct net_bridge *br, struct
 net_bridge_port *source,
 					source->dev->name);
 		} else {
 			/* fastpath: update of existing entry */
+			if (source->port_no != fdb->dst->port_no)

It seems that we don't need to fetch port_no and it is enough to compare source and fdb->dst.

It may save a few instructions but I have not tested it.

Quoted 10 lines
Quoted 6 lines
net/bridge/br_fdb.c +1 -0
+				fdb_notify(br, fdb, RTM_NEWNEIGH);
 			fdb->dst = source;
 			fdb->updated = jiffies;

if (unlikely(added_by_user))

This notifies fdb entry before updating existing entry. Is this on purpose? I think we should notify the updated fdb entry.
Similar code fdb_add_entry() does after updating it.

It was not on purpose but for this particular case there will be burst of notifies so it probably does not matter. However I agree it should be after the update. I will do that along with adding the unlikely() conditional and resubmit.

Quoted 2 lines

Also, isn't it better to move update of dst into "if" block?

I would prefer to leave this portion as alone and only use the if statement for the notify.

Quoted 11 lines
	if (source != fdb->dst) {
		fdb->dst = source;
		modified = true;
	}
	...
	if (modified) ...

Thanks,
Toshiaki Makita

#5 lore raw
Quoted 69 lines

----- Original Message -----

Quoted 32 lines

From: "Toshiaki Makita" <[email protected]>
To: "Jon Maxwell" <[email protected]>, [email protected]
Cc: [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]
Sent: Wednesday, May 14, 2014 10:34:38 AM
Subject: Re: [PATCH net] bridge: notify user space of fdb port change

Quoted 23 lines · Jon Maxwell

From: Jon Maxwell <[email protected]>

There has been a number incidents recently where customers running KVM have
reported that VM hosts on different Hypervisors are unreachable. Based on pcap traces we found that the bridge was broadcasting the ARP request out onto the network. However some NICs have an inbuilt switch which on occasions
were broadcasting the VMs ARP request back through the physical NIC on the
Hypervisor. This resulted in the bridge changing ports and incorrectly learning
that the VMs mac address was external. As a result the ARP reply was directed
back onto the external network and VM never updated it's ARP cache. This patch
will notify the bridge command to identify such port toggling.

---
 net/bridge/br_fdb.c | 2 ++
 1 file changed, 2 insertions(+)
Quoted 13 lines

net/bridge/br_fdb.c void br_fdb_update(struct net_bridge *br, struct · line 511

Quoted 10 lines
net/bridge/br_fdb.c +1 -0
index 9203d5a..37742e2 100644
@@ -507,6 +507,8 @@ void br_fdb_update(struct net_bridge *br, struct
 net_bridge_port *source,
 					source->dev->name);
 		} else {
 			/* fastpath: update of existing entry */
+			if (source->port_no != fdb->dst->port_no)

It seems that we don't need to fetch port_no and it is enough to compare source and fdb->dst.

It may save a few instructions but I have not tested it.

Quoted 10 lines
Quoted 6 lines
net/bridge/br_fdb.c +1 -0
+				fdb_notify(br, fdb, RTM_NEWNEIGH);
 			fdb->dst = source;
 			fdb->updated = jiffies;

if (unlikely(added_by_user))

This notifies fdb entry before updating existing entry. Is this on purpose? I think we should notify the updated fdb entry.
Similar code fdb_add_entry() does after updating it.

It was not on purpose but for this particular case there will be burst of notifies
so it probably does not matter. However I agree it should be after the update.
I will do that along with adding the unlikely() conditional and resubmit.

Quoted 1 line
Quoted 13 lines
Quoted 1 line

Also, isn't it better to move update of dst into "if" block?

I would prefer to leave this portion as alone and only use the if statement for the notify.

Quoted 8 lines
	if (source != fdb->dst) {
		fdb->dst = source;
		modified = true;
	}
	...
	if (modified) ...

Makita-san,

I recoded this using your idea and ran it through a reproducer. It work fine. After some more consideration I agree that setting fdb->dst = source is only required when source != fdb->dst.

Thanks for your suggestions. This is the revised patch. It should retain the original behaviour except for the notify after the fdb update.

Please let me know if you have any further input?

$ diff -Naur br_fdb.c br_fdb.c.patch
--- br_fdb.c        2014-05-17 12:43:23.346319609 +1000
+++ br_fdb.c.patch        2014-05-17 16:54:46.280235728 +1000
@@ -487,6 +487,7 @@
 {
         struct hlist_head *head = &br->hash[br_mac_hash(addr, vid)];
         struct net_bridge_fdb_entry *fdb;
+        bool fdb_modified = 0;
         /* some users want to always flood. */
         if (hold_time(br) == 0)
@@ -507,10 +508,16 @@
                                         source->dev->name);
                 } else {
                         /* fastpath: update of existing entry */
-                        fdb->dst = source;
+                        if (unlikely(source != fdb->dst))
+                                {
+                                fdb->dst = source;
+                                fdb_modified = 1;
+                                }
                         fdb->updated = jiffies;
                         if (unlikely(added_by_user))
                                 fdb->added_by_user = 1;
+                        if (unlikely(fdb_modified))
+                                fdb_notify(br, fdb, RTM_NEWNEIGH);
                 }
         } else {
                 spin_lock(&br->hash_lock);
Quoted 4 lines
Quoted 3 lines

Thanks,
Toshiaki Makita

#6 lore raw

(2014/05/23 13:59), Jon Maxwell wrote:
...

Quoted 10 lines

Makita-san,

I recoded this using your idea and ran it through a reproducer. It work fine. After some more consideration I agree that setting fdb->dst = source is only required when source != fdb->dst.

Thanks for your suggestions. This is the revised patch. It should retain the original behaviour except for the notify after the fdb update.

Please let me know if you have any further input?

I have no more comments except for style problems (bracket position, indentation, type mismatch).
thank you for rewriting :)

Thanks,
Toshiaki Makita

Quoted 32 lines
$ diff -Naur br_fdb.c br_fdb.c.patch
br_fdb.c.patch 2014-05-17 16:54:46.280235728 +1000 renamed from br_fdb.c 2014-05-17 12:43:23.346319609 +1000 +8 -1
@@ -487,6 +487,7 @@
 {
         struct hlist_head *head = &br->hash[br_mac_hash(addr, vid)];
         struct net_bridge_fdb_entry *fdb;
+        bool fdb_modified = 0;
 
         /* some users want to always flood. */
         if (hold_time(br) == 0)
@@ -507,10 +508,16 @@
                                         source->dev->name);
                 } else {
                         /* fastpath: update of existing entry */
-                        fdb->dst = source;
+                        if (unlikely(source != fdb->dst))
+                                {
+                                fdb->dst = source;
+                                fdb_modified = 1;
+                                }
                         fdb->updated = jiffies;
                         if (unlikely(added_by_user))
                                 fdb->added_by_user = 1;
+                        if (unlikely(fdb_modified))
+                                fdb_notify(br, fdb, RTM_NEWNEIGH);
                 }
         } else {
                 spin_lock(&br->hash_lock);
#7 lore raw
Quoted 4 lines

I have no more comments except for style problems (bracket position, indentation, type mismatch).
thank you for rewriting :)

np, yes this is a draft but I will make sure complies with checkpatch.pl before submitting it.

Regards

Jon

Quoted 37 lines

Thanks,
Toshiaki Makita

Quoted 32 lines
$ diff -Naur br_fdb.c br_fdb.c.patch
br_fdb.c.patch 2014-05-17 16:54:46.280235728 +1000 renamed from br_fdb.c 2014-05-17 12:43:23.346319609 +1000 +8 -1
@@ -487,6 +487,7 @@
 {
         struct hlist_head *head = &br->hash[br_mac_hash(addr, vid)];
         struct net_bridge_fdb_entry *fdb;
+        bool fdb_modified = 0;
 
         /* some users want to always flood. */
         if (hold_time(br) == 0)
@@ -507,10 +508,16 @@
                                         source->dev->name);
                 } else {
                         /* fastpath: update of existing entry */
-                        fdb->dst = source;
+                        if (unlikely(source != fdb->dst))
+                                {
+                                fdb->dst = source;
+                                fdb_modified = 1;
+                                }
                         fdb->updated = jiffies;
                         if (unlikely(added_by_user))
                                 fdb->added_by_user = 1;
+                        if (unlikely(fdb_modified))
+                                fdb_notify(br, fdb, RTM_NEWNEIGH);
                 }
         } else {
                 spin_lock(&br->hash_lock);