Skip to contentSkip to conversation

Issue NETDEV_CHANGE notification when bridge changes state

PATCH In review Adam Majer 7 participants 18 messages Mar 6, 2011 – Mar 14, 2011

Subsystems (4)
lore
Share & tools
lore

Adam Majer

author
#0 lore raw

PATCH 1/2 Issue NETDEV_CHANGE notification when bridge changes state

IPv6 address autoconfiguration relies on an UP interface to processes traffic normally. A bridge that is UP enters LEARNING state and this state "eats" any Router Advertising packets sent to the bridge. Issuing a NETDEV_CHANGE notification on the bridge interface when it changes state allows autoconfiguration code to retry querying router information.

---
 net/bridge/br_if.c      |   20 ++++++++++++++++++++
 net/bridge/br_private.h |    2 ++
 net/bridge/br_stp.c     |    2 ++
 3 files changed, 24 insertions(+), 0 deletions(-)
net/bridge/br_if.c +20 -0
index d9d1e2b..9604d52 100644
@@ -25,6 +25,22 @@
 
 #include "br_private.h"
 
+
+/*
+ * Notifies that the bridge has changed state
+ */
+static void br_port_change_notifier_handler(struct work_struct *work)
+{
+	struct net_bridge *br = container_of(work,
+					     struct net_bridge,
+					     change_notification_worker);
+
+	rtnl_lock();
+	netdev_state_change(br->dev);
+	rtnl_unlock();
+}
+
+
 /*
  * Determine initial path cost based on speed.
  * using recommendations from 802.1d standard
@@ -163,6 +179,7 @@ static void del_br(struct net_bridge *br, struct list_head *head)
 {
 	struct net_bridge_port *p, *n;
 
+	flush_work(&br->change_notification_worker);
 	list_for_each_entry_safe(p, n, &br->port_list, list) {
 		del_nbp(p);
 	}
@@ -203,6 +220,9 @@ static struct net_device *new_bridge_dev(struct net *net, const char *name)
 
 	memcpy(br->group_addr, br_group_address, ETH_ALEN);
 
+	INIT_WORK(&br->change_notification_worker,
+		  &br_port_change_notifier_handler);
+
 	br->feature_mask = dev->features;
 	br->stp_enabled = BR_NO_STP;
 	br->designated_root = br->bridge_id;
net/bridge/br_private.h +2 -0
index 4e1b620..7f8ef41 100644
@@ -179,6 +179,8 @@ struct net_bridge
 	struct list_head		port_list;
 	struct net_device		*dev;
 
+	struct work_struct		change_notification_worker;
+
 	struct br_cpu_netstats __percpu *stats;
 	spinlock_t			hash_lock;
 	struct hlist_head		hash[BR_HASH_SIZE];
net/bridge/br_stp.c +2 -0
index 57186d8..b5be3e3 100644
@@ -296,6 +296,8 @@ void br_topology_change_detection(struct net_bridge *br)
 {
 	int isroot = br_is_root_bridge(br);
 
+	queue_work(system_long_wq, &br->change_notification_worker);
+
 	if (br->stp_enabled != BR_KERNEL_STP)
 		return;
 
Signature · 1 line
1.7.2.3
author
#1 lore raw

PATCH 2/2 Retry autoconfiguration on interface after NETDEV_CHANGE notification

A bridged interface will timeout trying to receive Router Advert as these packets are not forwarded when bridge is UP but not in the FORWARDING state (eg. LEARNING state). Bridge code issues NETDEV_CHANGE when bridge's internal state is changed. It is then possible to retry Router Solicitation.

---
 net/ipv6/addrconf.c |   74 +++++++++++++++++++++++++++++++++-----------------
 1 files changed, 49 insertions(+), 25 deletions(-)
net/ipv6/addrconf.c +49 -25
index fd6782e..f8018b3 100644
@@ -152,6 +152,7 @@ static void addrconf_dad_start(struct inet6_ifaddr *ifp, u32 flags);
 static void addrconf_dad_timer(unsigned long data);
 static void addrconf_dad_completed(struct inet6_ifaddr *ifp);
 static void addrconf_dad_run(struct inet6_dev *idev);
+static void addrconf_rs_start(struct inet6_ifaddr *ifp);
 static void addrconf_rs_timer(unsigned long data);
 static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifa);
 static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifa);
@@ -2368,6 +2369,18 @@ static void addrconf_add_linklocal(struct inet6_dev *idev, struct in6_addr *addr
 		addrconf_prefix_route(&ifp->addr, ifp->prefix_len, idev->dev, 0, 0);
 		addrconf_dad_start(ifp, 0);
 		in6_ifa_put(ifp);
+	} else if (PTR_ERR(ifp) == -EEXIST &&
+		list_is_singular(&idev->addr_list)) {
+		/*
+		 * first address must be link local, but no router - re-solicit.
+		 * This code path is called when bridge exits LEARNING state
+		 */
+
+		ifp = list_first_entry(&idev->addr_list,
+				       struct inet6_ifaddr,
+				       if_list);
+
+		addrconf_rs_start(ifp);
 	}
 }
 
@@ -2532,8 +2545,11 @@ static int addrconf_notify(struct notifier_block *this, unsigned long event,
 			}
 
 			if (idev) {
-				if (idev->if_flags & IF_READY)
-					/* device is already configured. */
+				if (idev->if_flags & IF_READY &&
+				    idev->if_flags & IF_RA_RCVD)
+					/* device is already configured and
+					 * RA was received.
+					 */
 					break;
 				idev->if_flags |= IF_READY;
 			}
@@ -2775,6 +2791,35 @@ static int addrconf_ifdown(struct net_device *dev, int how)
 	return 0;
 }
 
+static void addrconf_rs_start(struct inet6_ifaddr *ifp)
+{
+	/* If added prefix is link local and forwarding is off,
+	   start sending router solicitations.
+	 */
+	struct net_device *dev = ifp->idev->dev;
+
+	if ((ifp->idev->cnf.forwarding == 0 ||
+	     ifp->idev->cnf.forwarding == 2) &&
+	    ifp->idev->cnf.rtr_solicits > 0 &&
+	    (dev->flags&IFF_LOOPBACK) == 0 &&
+	    (ipv6_addr_type(&ifp->addr) & IPV6_ADDR_LINKLOCAL)) {
+		/*
+		 *	If a host as already performed a random delay
+		 *	[...] as part of DAD [...] there is no need
+		 *	to delay again before sending the first RS
+		 */
+		ndisc_send_rs(ifp->idev->dev, &ifp->addr,
+			      &in6addr_linklocal_allrouters);
+
+		spin_lock_bh(&ifp->lock);
+		ifp->probes = 1;
+		ifp->idev->if_flags |= IF_RS_SENT;
+		addrconf_mod_timer(ifp, AC_RS,
+				   ifp->idev->cnf.rtr_solicit_interval);
+		spin_unlock_bh(&ifp->lock);
+	}
+}
+
 static void addrconf_rs_timer(unsigned long data)
 {
 	struct inet6_ifaddr *ifp = (struct inet6_ifaddr *) data;
@@ -2935,36 +2980,15 @@ out:
 
 static void addrconf_dad_completed(struct inet6_ifaddr *ifp)
 {
-	struct net_device *dev = ifp->idev->dev;
-
 	/*
 	 *	Configure the address for reception. Now it is valid.
 	 */
 
 	ipv6_ifa_notify(RTM_NEWADDR, ifp);
 
-	/* If added prefix is link local and forwarding is off,
-	   start sending router solicitations.
-	 */
+	/* start sending router solicitations. */
 
-	if ((ifp->idev->cnf.forwarding == 0 ||
-	     ifp->idev->cnf.forwarding == 2) &&
-	    ifp->idev->cnf.rtr_solicits > 0 &&
-	    (dev->flags&IFF_LOOPBACK) == 0 &&
-	    (ipv6_addr_type(&ifp->addr) & IPV6_ADDR_LINKLOCAL)) {
-		/*
-		 *	If a host as already performed a random delay
-		 *	[...] as part of DAD [...] there is no need
-		 *	to delay again before sending the first RS
-		 */
-		ndisc_send_rs(ifp->idev->dev, &ifp->addr, &in6addr_linklocal_allrouters);
-
-		spin_lock_bh(&ifp->lock);
-		ifp->probes = 1;
-		ifp->idev->if_flags |= IF_RS_SENT;
-		addrconf_mod_timer(ifp, AC_RS, ifp->idev->cnf.rtr_solicit_interval);
-		spin_unlock_bh(&ifp->lock);
-	}
+	addrconf_rs_start(ifp);
 }
 
 static void addrconf_dad_run(struct inet6_dev *idev)
Signature · 1 line
1.7.2.3
author
#2 lore raw
In reply to Adam Majer

Hello,

As background for these 2 patches, the current bridge code does not play very nicely with IPv6 autoconfiguration. What happens is,

[   35.117030] device eth0 entered promiscuous mode
[   35.120898] br0: port 1(eth0) entering learning state
[   35.120901] br0: port 1(eth0) entering learning state

Here bridge is setup and both interface eth0 and br0 are indicated as up via NETDEV_UP notification. The IPv6 autoconfiguration code configures linklocal address and start to issue RS packets. These timeout because bridge is in learning state, not forwarding state.

[   45.168007] br0: no IPv6 routers present
[   45.312020] eth0: no IPv6 routers present

RS timeouts and IPv6 is abandoned at this point.

[   50.144011] br0: port 1(eth0) entering forwarding state

Now bridge entered forwarding state. Userland sets up IPv4 via DHCP or otherwise.

[   50.144487] ADDRCONF(NETDEV_CHANGE): br0: link becomes ready

With the patches, NETDEV_CHANGE is issued by the bridge once it changes state. The autoconfiguration code then checks that no RA packets are received and only linklocal interface is setup. It then retries soliciting router information.

This is my first attempt at a kernel patch so please be gentle :) Part of the autoconf patch splits out the addrconf_rs_start() code from the addrconf_dad_completed() function.

Cheers,
Adam

Signature · 2 lines
Adam Majer
[email protected]
#3 lore raw
In reply to Adam Majer

Why not set forwarding delay to zero? I don't think you are using STP?

P.s: removing linux-kernel mailing list, since there is no point in copying the whole world on this thread.

author
#4 lore raw
Quoted 4 lines · Stephen Hemminger

Why not set forwarding delay to zero? I don't think you are using STP?

P.s: removing linux-kernel mailing list, since there is no point in copying the whole world on this thread.

I just sent patches where MAINTAINERS file told me to send it. ;)

No, I'm not relying on STP. I think setting learning->forwarding delay to 0 could cause problems with STP like loops until the loop is detected.

There may be a better spot where to insert the notification that the bridge is forwarding data, though I'm not exactly certain where. The patch will cause bridge to issue NETDEV_CHANGE notification for all topology changes. This may or may not be useful but shouldn't be harmful (I can't imagine these occur very often?) The IPv6 autoconf patch will only act on this if it doesn't have IPv6 address configured manually or via autoconf.

Signature · 2 lines
Adam Majer
[email protected]
#5 lore raw
Quoted 12 lines · On Sun, 6 Mar 2011 02:03:28 -0600 Adam Majer <[email protected]> wrote:
Quoted 4 lines · Stephen Hemminger

Why not set forwarding delay to zero? I don't think you are using STP?

P.s: removing linux-kernel mailing list, since there is no point in copying the whole world on this thread.

I just sent patches where MAINTAINERS file told me to send it. ;)

No, I'm not relying on STP. I think setting learning->forwarding delay to 0 could cause problems with STP like loops until the loop is detected.

Quoted 8 lines

There may be a better spot where to insert the notification that the bridge is forwarding data, though I'm not exactly certain where. The patch will cause bridge to issue NETDEV_CHANGE notification for all topology changes. This may or may not be useful but shouldn't be harmful (I can't imagine these occur very often?) The IPv6 autoconf patch will only act on this if it doesn't have IPv6 address configured manually or via autoconf.

Since this a generic problem, it needs a better solution. Sending NETDEV_CHANGE impacts lots of other pieces, and even user space has similar problems.

author
#6 lore raw
Quoted 3 lines · Stephen Hemminger

Since this a generic problem, it needs a better solution. Sending NETDEV_CHANGE impacts lots of other pieces, and even user space has similar problems.

It does seem a little broad notification type. I've checked over all the currently defined NETDEV notifiers, and it seems that NETDEV_NOTIFY_PEERS may be a better option to use when bridge has a potential topology change.

Currently it is only used in ipv4/devinet.c: where it is used to issue a gratuitous ARP.

Signature · 2 lines
Adam Majer
[email protected]
#7 lore raw
Quoted 6 lines · Stephen Hemminger
Quoted 3 lines

Since this a generic problem, it needs a better solution. Sending NETDEV_CHANGE impacts lots of other pieces, and even user space has similar problems.

Quoted 7 lines

It does seem a little broad notification type. I've checked over all the currently defined NETDEV notifiers, and it seems that NETDEV_NOTIFY_PEERS may be a better option to use when bridge has a potential topology change.

Currently it is only used in ipv4/devinet.c: where it is used to issue a gratuitous ARP.

I was thinking of fixing bridge to not actually bring the link up until in forwarding mode. Other applications (DHCP, etc) see the link up and really don't like being in half duplex during that period.

#8 lore raw
Quoted 11 lines · Stephen Hemminger
Quoted 11 lines · Stephen Hemminger
Quoted 3 lines

Since this a generic problem, it needs a better solution. Sending NETDEV_CHANGE impacts lots of other pieces, and even user space has similar problems.

It does seem a little broad notification type. I've checked over all the currently defined NETDEV notifiers, and it seems that NETDEV_NOTIFY_PEERS may be a better option to use when bridge has a potential topology change.

Quoted 7 lines
Quoted 2 lines

Currently it is only used in ipv4/devinet.c: where it is used to issue a gratuitous ARP.

I was thinking of fixing bridge to not actually bring the link up until in forwarding mode. Other applications (DHCP, etc) see the link up and really don't like being in half duplex during that period.

I think it is the right way to manage this situation. And bonding should behave the same, if not already true.

Nicolas.

#9 lore raw

PATCH 1/1 bridge: control carrier based on ports online

This makes the bridge device behave like a physical device. In earlier releases the bridge always asserted carrier. This changes the behavior so that bridge device carrier is on only if one or more ports are in the forwarding state. This should help IPv6 autoconfiguration, DHCP, and routing daemons.

I did brief testing with Network and Virt manager and they seem fine, but since this changes behavior of bridge, it should wait until net-next (2.6.39).

---
 net/bridge/br_device.c    |    4 ++++
 net/bridge/br_stp.c       |   35 ++++++++++++++++++++++-------------
 net/bridge/br_stp_timer.c |    1 +
 3 files changed, 27 insertions(+), 13 deletions(-)
net/bridge/br_device.c +4 -0
@@ -78,6 +78,8 @@ static int br_dev_open(struct net_device
 {
 	struct net_bridge *br = netdev_priv(dev);
 
+	netif_carrier_off(dev);
+
 	br_features_recompute(br);
 	netif_start_queue(dev);
 	br_stp_enable_bridge(br);
@@ -94,6 +96,8 @@ static int br_dev_stop(struct net_device
 {
 	struct net_bridge *br = netdev_priv(dev);
 
+	netif_carrier_off(dev);
+
 	br_stp_disable_bridge(br);
 	br_multicast_stop(br);
 
net/bridge/br_stp.c +22 -13
@@ -397,28 +397,37 @@ static void br_make_forwarding(struct ne
 void br_port_state_selection(struct net_bridge *br)
 {
 	struct net_bridge_port *p;
+	unsigned int liveports = 0;
 
 	/* Don't change port states if userspace is handling STP */
 	if (br->stp_enabled == BR_USER_STP)
 		return;
 
 	list_for_each_entry(p, &br->port_list, list) {
-		if (p->state != BR_STATE_DISABLED) {
-			if (p->port_no == br->root_port) {
-				p->config_pending = 0;
-				p->topology_change_ack = 0;
-				br_make_forwarding(p);
-			} else if (br_is_designated_port(p)) {
-				del_timer(&p->message_age_timer);
-				br_make_forwarding(p);
-			} else {
-				p->config_pending = 0;
-				p->topology_change_ack = 0;
-				br_make_blocking(p);
-			}
+		if (p->state == BR_STATE_DISABLED)
+			continue;
+
+		if (p->port_no == br->root_port) {
+			p->config_pending = 0;
+			p->topology_change_ack = 0;
+			br_make_forwarding(p);
+		} else if (br_is_designated_port(p)) {
+			del_timer(&p->message_age_timer);
+			br_make_forwarding(p);
+		} else {
+			p->config_pending = 0;
+			p->topology_change_ack = 0;
+			br_make_blocking(p);
 		}
 
+		if (p->state == BR_STATE_FORWARDING)
+			++liveports;
 	}
+
+	if (liveports == 0)
+		netif_carrier_off(br->dev);
+	else
+		netif_carrier_on(br->dev);
 }
 
 /* called under bridge lock */
net/bridge/br_stp_timer.c +1 -0
@@ -94,6 +94,7 @@ static void br_forward_delay_timer_expir
 		p->state = BR_STATE_FORWARDING;
 		if (br_is_designated_for_some_port(br))
 			br_topology_change_detection(br);
+		netif_carrier_on(br->dev);
 	}
 	br_log_state(p);
 	spin_unlock(&br->lock);
Reviewed-by on v1 1/1
#10 lore raw

Re: [PATCH] bridge: control carrier based on ports online

Quoted 68 lines · Stephen Hemminger

This makes the bridge device behave like a physical device. In earlier releases the bridge always asserted carrier. This changes the behavior so that bridge device carrier is on only if one or more ports are in the forwarding state. This should help IPv6 autoconfiguration, DHCP, and routing daemons.

I did brief testing with Network and Virt manager and they seem fine, but since this changes behavior of bridge, it should wait until net-next (2.6.39).

---
  net/bridge/br_device.c    |    4 ++++
  net/bridge/br_stp.c       |   35 ++++++++++++++++++++++-------------
  net/bridge/br_stp_timer.c |    1 +
  3 files changed, 27 insertions(+), 13 deletions(-)
net/bridge/br_device.c +4 -0
@@ -78,6 +78,8 @@ static int br_dev_open(struct net_device
  {
  	struct net_bridge *br = netdev_priv(dev);
 
+	netif_carrier_off(dev);
+
  	br_features_recompute(br);
  	netif_start_queue(dev);
  	br_stp_enable_bridge(br);
@@ -94,6 +96,8 @@ static int br_dev_stop(struct net_device
  {
  	struct net_bridge *br = netdev_priv(dev);
 
+	netif_carrier_off(dev);
+
  	br_stp_disable_bridge(br);
  	br_multicast_stop(br);
 
net/bridge/br_stp.c +5 -13
@@ -397,28 +397,37 @@ static void br_make_forwarding(struct ne
  void br_port_state_selection(struct net_bridge *br)
  {
  	struct net_bridge_port *p;
+	unsigned int liveports = 0;
 
  	/* Don't change port states if userspace is handling STP */
  	if (br->stp_enabled == BR_USER_STP)
  		return;
 
  	list_for_each_entry(p,&br->port_list, list) {
-		if (p->state != BR_STATE_DISABLED) {
-			if (p->port_no == br->root_port) {
-				p->config_pending = 0;
-				p->topology_change_ack = 0;
-				br_make_forwarding(p);
-			} else if (br_is_designated_port(p)) {
-				del_timer(&p->message_age_timer);
-				br_make_forwarding(p);
-			} else {
-				p->config_pending = 0;
-				p->topology_change_ack = 0;
-				br_make_blocking(p);
-			}
+		if (p->state == BR_STATE_DISABLED)
+			continue;
+
+		if (p->port_no == br->root_port) {

net/bridge/br_stp.c static void br_make_forwarding(struct ne · line 420

Quoted 10 lines
net/bridge/br_stp.c +10 -0
+			p->config_pending = 0;
+			p->topology_change_ack = 0;
+			br_make_forwarding(p);
+		} else if (br_is_designated_port(p)) {
+			del_timer(&p->message_age_timer);
+			br_make_forwarding(p);
+		} else {
+			p->config_pending = 0;
+			p->topology_change_ack = 0;
+			br_make_blocking(p);

Is the above part really related to the purpose of this patch? It looks like (good) cleanup, but should be in a different patch.

Except from this comment,

Quoted 24 lines
net/bridge/br_stp.c +7 -0
  		}
 
+		if (p->state == BR_STATE_FORWARDING)
+			++liveports;
  	}
+
+	if (liveports == 0)
+		netif_carrier_off(br->dev);
+	else
+		netif_carrier_on(br->dev);
  }
 
  /* called under bridge lock */
net/bridge/br_stp_timer.c +1 -0
@@ -94,6 +94,7 @@ static void br_forward_delay_timer_expir
  		p->state = BR_STATE_FORWARDING;
  		if (br_is_designated_for_some_port(br))
  			br_topology_change_detection(br);
+		netif_carrier_on(br->dev);
  	}
  	br_log_state(p);
  	spin_unlock(&br->lock);
#11 lore raw

Re: [PATCH] bridge: control carrier based on ports online

Quoted 83 lines · On Mon, 07 Mar 2011 21:48:16 +0100 Nicolas de Pesloüan…
Quoted 68 lines · Stephen Hemminger

This makes the bridge device behave like a physical device. In earlier releases the bridge always asserted carrier. This changes the behavior so that bridge device carrier is on only if one or more ports are in the forwarding state. This should help IPv6 autoconfiguration, DHCP, and routing daemons.

I did brief testing with Network and Virt manager and they seem fine, but since this changes behavior of bridge, it should wait until net-next (2.6.39).

---
  net/bridge/br_device.c    |    4 ++++
  net/bridge/br_stp.c       |   35 ++++++++++++++++++++++-------------
  net/bridge/br_stp_timer.c |    1 +
  3 files changed, 27 insertions(+), 13 deletions(-)
net/bridge/br_device.c +4 -0
@@ -78,6 +78,8 @@ static int br_dev_open(struct net_device
  {
  	struct net_bridge *br = netdev_priv(dev);
 
+	netif_carrier_off(dev);
+
  	br_features_recompute(br);
  	netif_start_queue(dev);
  	br_stp_enable_bridge(br);
@@ -94,6 +96,8 @@ static int br_dev_stop(struct net_device
  {
  	struct net_bridge *br = netdev_priv(dev);
 
+	netif_carrier_off(dev);
+
  	br_stp_disable_bridge(br);
  	br_multicast_stop(br);
 
net/bridge/br_stp.c +5 -13
@@ -397,28 +397,37 @@ static void br_make_forwarding(struct ne
  void br_port_state_selection(struct net_bridge *br)
  {
  	struct net_bridge_port *p;
+	unsigned int liveports = 0;
 
  	/* Don't change port states if userspace is handling STP */
  	if (br->stp_enabled == BR_USER_STP)
  		return;
 
  	list_for_each_entry(p,&br->port_list, list) {
-		if (p->state != BR_STATE_DISABLED) {
-			if (p->port_no == br->root_port) {
-				p->config_pending = 0;
-				p->topology_change_ack = 0;
-				br_make_forwarding(p);
-			} else if (br_is_designated_port(p)) {
-				del_timer(&p->message_age_timer);
-				br_make_forwarding(p);
-			} else {
-				p->config_pending = 0;
-				p->topology_change_ack = 0;
-				br_make_blocking(p);
-			}
+		if (p->state == BR_STATE_DISABLED)
+			continue;
+
+		if (p->port_no == br->root_port) {

net/bridge/br_stp.c static void br_make_forwarding(struct ne · line 420

Quoted 10 lines
net/bridge/br_stp.c +10 -0
+			p->config_pending = 0;
+			p->topology_change_ack = 0;
+			br_make_forwarding(p);
+		} else if (br_is_designated_port(p)) {
+			del_timer(&p->message_age_timer);
+			br_make_forwarding(p);
+		} else {
+			p->config_pending = 0;
+			p->topology_change_ack = 0;
+			br_make_blocking(p);

Is the above part really related to the purpose of this patch? It looks like (good) cleanup, but should be in a different patch.

Quoted 3 lines

Except from this comment,

The loop is going over the state of ports.
Since the new code at the end of loop has to check for STATE_FORWARDING it is clearer with continue statement. When adding code it is always better to clarify the logic in the process rather than making it more complex.

#12 lore raw

Re: [PATCH] bridge: control carrier based on ports online

Quoted 4 lines · Stephen Hemminger
Quoted 1 line · On Mon, 07 Mar 2011 21:48:16 +0100 Nicolas de…

Le 07/03/2011 19:34, Stephen Hemminger a écrit :

[snip]

Quoted 34 lines
Quoted 34 lines
Quoted 18 lines
   	list_for_each_entry(p,&br->port_list, list) {
net/bridge/br_stp.c +4 -13
-		if (p->state != BR_STATE_DISABLED) {
-			if (p->port_no == br->root_port) {
-				p->config_pending = 0;
-				p->topology_change_ack = 0;
-				br_make_forwarding(p);
-			} else if (br_is_designated_port(p)) {
-				del_timer(&p->message_age_timer);
-				br_make_forwarding(p);
-			} else {
-				p->config_pending = 0;
-				p->topology_change_ack = 0;
-				br_make_blocking(p);
-			}
+		if (p->state == BR_STATE_DISABLED)
+			continue;
+
+		if (p->port_no == br->root_port) {

net/bridge/br_stp.c static void br_make_forwarding(struct ne · line 420

Quoted 10 lines
net/bridge/br_stp.c +10 -0
+			p->config_pending = 0;
+			p->topology_change_ack = 0;
+			br_make_forwarding(p);
+		} else if (br_is_designated_port(p)) {
+			del_timer(&p->message_age_timer);
+			br_make_forwarding(p);
+		} else {
+			p->config_pending = 0;
+			p->topology_change_ack = 0;
+			br_make_blocking(p);

Is the above part really related to the purpose of this patch? It looks like (good) cleanup, but should be in a different patch.

Except from this comment,

Quoted 7 lines
Quoted 1 line

The loop is going over the state of ports.
Since the new code at the end of loop has to check for STATE_FORWARDING it is clearer with continue statement. When adding code it is always better to clarify the logic in the process rather than making it more complex.

Sound's good to me. Thanks for clarifying.

Nicolas.

author Tested-by on v1 1/1
#13 lore raw

Re: [PATCH] bridge: control carrier based on ports online

In reply to Stephen Hemminger
Quoted 5 lines · Stephen Hemminger

This makes the bridge device behave like a physical device. In earlier releases the bridge always asserted carrier. This changes the behavior so that bridge device carrier is on only if one or more ports are in the forwarding state. This should help IPv6 autoconfiguration, DHCP, and routing daemons.

Yes, your patch does fix issues with IPv6 autoconfiguration in bridged networks completely. I've just tested it with and without STP. IPv4 DHCP continues to function correctly. It is definitely much cleaner solution than my hack.

IPv6 autoconfiguration code already checks if NETDEV_CHANGE or NETDEV_UP represent a device that is ready to transmit data before attempting to configure the interface. No additional changes required there. This patch should also fix duplicate address detection of linklocal address on bridged interfaces that I believe was also broken prior to this patch.

If you want, you can add

Cheers,
- Adam

maintainer Applied
#14 lore raw

Re: [PATCH] bridge: control carrier based on ports online

In reply to Stephen Hemminger

From: Stephen Hemminger <[email protected]>
Date: Mon, 7 Mar 2011 10:34:06 -0800

Quoted 11 lines

This makes the bridge device behave like a physical device. In earlier releases the bridge always asserted carrier. This changes the behavior so that bridge device carrier is on only if one or more ports are in the forwarding state. This should help IPv6 autoconfiguration, DHCP, and routing daemons.

I did brief testing with Network and Virt manager and they seem fine, but since this changes behavior of bridge, it should wait until net-next (2.6.39).

Applied to net-next-2.6, thanks Stephen.

#15 lore raw
In reply to Adam Majer
Quoted 6 lines · Adam Majer
Quoted 1 line · Stephen Hemminger

Why not set forwarding delay to zero? I don't think you are using STP?

No, I'm not relying on STP. I think setting learning->forwarding delay to 0 could cause problems with STP like loops until the loop is detected.

I don't think that Stephen is saying that you should hard-code the forwarding delay as zero (i.e. to remove the delay from the kernel completely), but rather use brctl to set the forwarding delay to zero on bridge instances in which you're not using STP.

HTH, Jan

#16 lore raw
In reply to Adam Majer
Quoted 8 lines · Adam Majer

IPv6 address autoconfiguration relies on an UP interface to processes traffic normally. A bridge that is UP enters LEARNING state and this state "eats" any Router Advertising packets sent to the bridge. Issuing a NETDEV_CHANGE notification on the bridge interface when it changes state allows autoconfiguration code to retry querying router information.

...

net/bridge/br_if.c line 42

Quoted 11 lines
net/bridge/br_if.c +11 -0
+static void br_port_change_notifier_handler(struct work_struct *work)
+{
+	struct net_bridge *br = container_of(work,
+					     struct net_bridge,
+					     change_notification_worker);
+
+	rtnl_lock();
+	netdev_state_change(br->dev);
+	rtnl_unlock();
+}
+

Do you really want user-space to get this notification too? Why do you put it into a workqueue? Maybe it has to be called in process-context?

Thanks.

author
#17 lore raw
Quoted 11 lines · Américo Wang
Quoted 8 lines · Adam Majer

IPv6 address autoconfiguration relies on an UP interface to processes traffic normally. A bridge that is UP enters LEARNING state and this state "eats" any Router Advertising packets sent to the bridge. Issuing a NETDEV_CHANGE notification on the bridge interface when it changes state allows autoconfiguration code to retry querying router information.

...

Quoted 15 lines

net/bridge/br_if.c line 42

Quoted 11 lines
net/bridge/br_if.c +11 -0
+static void br_port_change_notifier_handler(struct work_struct *work)
+{
+	struct net_bridge *br = container_of(work,
+					     struct net_bridge,
+					     change_notification_worker);
+
+	rtnl_lock();
+	netdev_state_change(br->dev);
+	rtnl_unlock();
+}
+

Do you really want user-space to get this notification too? Why do you put it into a workqueue? Maybe it has to be called in process-context?

Stephen Hemminger's patch (posted as a reply in this thread but only on the netdev mailing list) is much better as it only brings the link up on the bridge interface when the bridge enters forwarding mode.

Effectively it does similar thing via NETDEV_CHANGE but requires no other hacks in other code. It should make userland much happier too.

As for my patch, I've put that in the workqueue because the notification cannot be called in interrupt context. Is there a better way of calling code that can sleep from interrupt context?

- Adam

Signature · 2 lines
Adam Majer
[email protected]