Re: [PATCH 3/3] bridge: fix bridge root block on designated port

2014-03-14 Thread Luis R. Rodriguez
On Thu, Mar 13, 2014 at 03:16:23PM -0700, Stephen Hemminger wrote:
 On Wed, 12 Mar 2014 20:15:27 -0700
 Luis R. Rodriguez mcg...@do-not-panic.com wrote:
 
  --- a/net/bridge/br_private.h
  +++ b/net/bridge/br_private.h
  @@ -150,6 +150,7 @@ struct net_bridge_port
  u8  priority;
  u8  state;
  u16 port_no;
  +   boolroot_block_enabled;
  unsigned char   topology_change_ack;
 
 It seems a bit confusing to have both a ROOT_BLOCK flag in the
 data structure and and additional root_block_enabled flag.
 If nothing else it is a waste of space.

Indeed, however there is a use for it. Consider the case where we loop
over each port and check to see if its root blocked and need to tickle it
or the bridge. In the case that root port block was enabled before and
someone is lifting it the flag would be removed and therefore not on
but it was root blocked though and we need a way to keep track of that.

The flag then is a toggle for userspace, while the bool tells us about
the current state.

 Looks like you are changing the meaning slightly. 

Let me know in what way. I can't see it.

 is possible to have BR_ROOT_BLOCK set but !root_block_enabled? 

Yeah in the case a new request to set it to root block then
BR_ROOT_BLOCK would be set but root_block_enabled would not be set.

 and what about the inverse?

BR_ROOT_BLOCK would not be set when userspace wants to disable root
port block and root_block_enabled would be enabled in this case if
it used to be enabled. So yes, both are possible.

  Luis


pgpTcha59LBd8.pgp
Description: PGP signature


Re: [PATCH 3/3] bridge: fix bridge root block on designated port

2014-03-13 Thread Stephen Hemminger
On Wed, 12 Mar 2014 20:15:27 -0700
Luis R. Rodriguez mcg...@do-not-panic.com wrote:

 --- a/net/bridge/br_private.h
 +++ b/net/bridge/br_private.h
 @@ -150,6 +150,7 @@ struct net_bridge_port
   u8  priority;
   u8  state;
   u16 port_no;
 + boolroot_block_enabled;
   unsigned char   topology_change_ack;

It seems a bit confusing to have both a ROOT_BLOCK flag in the
data structure and and additional root_block_enabled flag.
If nothing else it is a waste of space.

Looks like you are changing the meaning slightly. is possible
to have BR_ROOT_BLOCK set but !root_block_enabled? and what about
the inverse?
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 3/3] bridge: fix bridge root block on designated port

2014-03-12 Thread Luis R. Rodriguez
From: Luis R. Rodriguez mcg...@suse.com

Root port blocking was designed so that a bridge port can opt
out of becoming the designated root port for a bridge. If a port
however first becomes the designated root port and we then toggle
the root port block on it we currently don't kick that port out of
the designated root port. This fixes that. This is particularly
important for net_devices that would wish to never become a root
port from the start, currently toggling that off will enable root
port flag but it won't really kick the bridge and do what you'd
expect, the MAC address is kept on the bridge of the toggled port
for root_block if it was the designated port.

In order to catch if a port with root port block preference is set
we need to move our check for root block prior to the root selection
so check for root blocked ports upon eveyr br_configuration_update().
We also simply just prevent the root-blocked ports from consideration
as root port candidates on br_should_become_root_port() and
br_stp_recalculate_bridge_id().

The issue that this patch is trying to address and fix can be tested
easily before and after this patch is applied using 2 TAP net_devices
and then toggling at will with the root_block knob.

ip tuntap add dev tap0 mode tap
ip tuntap add dev tap1 mode tap
ip link add dev br0 type bridge
ip link show br0
echo ---
ip link set dev tap0 master br0
ip link
echo ---
ip link set dev tap1 master br0
ip link
echo ---

Upon review at the above results you can toggle root_block
on each port to see if you see the results you expect.

bridge link set dev tap0 root_block on
ip link
bridge link set dev tap1 root_block on
ip link

Toggling off root_block on any port should will bring back the
port to be a candidate for designated root port:

bridge link set dev tap1 root_block off
ip link
bridge link set dev tap0 root_block off
ip link

To nuke:

ip tuntap del tap0 mode tap
ip tuntap del tap0 mode tap

Cc: Stephen Hemminger step...@networkplumber.org
Cc: bri...@lists.linux-foundation.org
Cc: net...@vger.kernel.org
Cc: linux-ker...@vger.kernel.org
Cc: xen-de...@lists.xenproject.org
Cc: kvm@vger.kernel.org
Signed-off-by: Luis R. Rodriguez mcg...@suse.com
---
 net/bridge/br_netlink.c | 18 
 net/bridge/br_private.h |  1 +
 net/bridge/br_stp.c | 73 +
 net/bridge/br_stp_if.c  |  3 +-
 4 files changed, 88 insertions(+), 7 deletions(-)

diff --git a/net/bridge/br_netlink.c b/net/bridge/br_netlink.c
index 6f1b26d..fbec354 100644
--- a/net/bridge/br_netlink.c
+++ b/net/bridge/br_netlink.c
@@ -324,6 +324,21 @@ static void br_set_port_flag(struct net_bridge_port *p, 
struct nlattr *tb[],
}
 }
 
+static void br_kick_bridge_port(struct net_bridge_port *p)
+{
+   struct net_bridge *br = p-br;
+   bool wasroot;
+
+   wasroot = br_is_root_bridge(br);
+   br_become_designated_port(p);
+
+   br_configuration_update(br);
+   br_port_state_selection(br);
+
+   if (br_is_root_bridge(br)  !wasroot)
+   br_become_root_bridge(br);
+}
+
 /* Process bridge protocol info on port */
 static int br_setport(struct net_bridge_port *p, struct nlattr *tb[])
 {
@@ -353,6 +368,9 @@ static int br_setport(struct net_bridge_port *p, struct 
nlattr *tb[])
if (err)
return err;
}
+
+   br_kick_bridge_port(p);
+
return 0;
 }
 
diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h
index 32a06da..45d7917 100644
--- a/net/bridge/br_private.h
+++ b/net/bridge/br_private.h
@@ -150,6 +150,7 @@ struct net_bridge_port
u8  priority;
u8  state;
u16 port_no;
+   boolroot_block_enabled;
unsigned char   topology_change_ack;
unsigned char   config_pending;
port_id port_id;
diff --git a/net/bridge/br_stp.c b/net/bridge/br_stp.c
index 3c86f05..f5741f3 100644
--- a/net/bridge/br_stp.c
+++ b/net/bridge/br_stp.c
@@ -59,6 +59,7 @@ static int br_should_become_root_port(const struct 
net_bridge_port *p,
 
br = p-br;
if (p-state == BR_STATE_DISABLED ||
+  (p-flags  BR_ROOT_BLOCK) ||
br_is_designated_port(p))
return 0;
 
@@ -104,7 +105,7 @@ static void br_root_port_block(const struct net_bridge *br,
   struct net_bridge_port *p)
 {
 
-   br_notice(br, port %u(%s) tried to become root port (blocked),
+   br_notice(br, port %u (%s) is now root blocked,
  (unsigned int) p-port_no, p-dev-name);
 
p-state = BR_STATE_LISTENING;
@@ -124,11 +125,7 @@ static void br_root_selection(struct net_bridge *br)
list_for_each_entry(p, br-port_list, list)