Expose switching attributes via PF_BRIDGE
Subsystems (4)
cover Expose switching attributes via PF_BRIDGE
This series decouples the remaining netlink PF_BRIDGE messages from the bridging module and moves them into rtnetlink proper. By doing this we can use these netlink messages to handle any type of bridge and extend the attributes as needed.
I hope this resolves some of the concerns with the DSA patch below and expect the attached series can be extended to support the DSA infrastructure as needed:
http://patchwork.ozlabs.org/patch/16578/
Also this should resolve a patch here that tried to expose the switching modes but did so using a device specific hook:
http://lists.openwall.net/netdev/2012/04/16/10
I've used a hacked version of the 'bridge' tool Stephen Hemminger submitted as an RFC some months back to test this the output looks like this:
[root@jf-dev1-dcblab iproute2]# ./br/br bridge show
eth2: bridge mode: VEB embedded
eth3: bridge mode: VEB embedded
[root@jf-dev1-dcblab iproute2]# ./br/br bridge mode dev eth2 mode vepa [root@jf-dev1-dcblab iproute2]# ./br/br bridge show
eth2: bridge mode: VEPA embedded
eth3: bridge mode: VEB embedded
I could have just added a ndo op and IFLA_XXX message to set the switching mode but IMHO this is not going to scale as more bridging functionality becomes offloaded. The DSA example is a case where we already have a fully offloaded switch. Any solution we come up with should support both embedded switches and SW switches.
Any comments would be appreciated Thanks!
---
John Fastabend (3):
ixgbe: add setlink, getlink support to ixgbe and ixgbevf
net: add VEPA, VEB bridge mode
net: create generic bridge ops
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 100 +++++++++++++++ drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c | 3 drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c | 10 ++ include/linux/if_link.h | 16 ++ include/linux/netdevice.h | 10 ++ net/bridge/br_device.c | 2 net/bridge/br_netlink.c | 75 ++--------- net/bridge/br_private.h | 3 net/core/rtnetlink.c | 137 +++++++++++++++++++++ 9 files changed, 291 insertions(+), 65 deletions(-)
Signature · 1 line
Signature
RFC PATCH 1/3 net: create generic bridge ops
The PF_BRIDGE:RTM_{GET|SET}LINK nlmsg family and type are currently embedded in the ./net/bridge module. This prohibits them from being used by other bridging devices. One example of this being hardware that has embedded bridging components.
In order to use these nlmsg types more generically this patch adds two net_device_ops hooks. One to set link bridge attributes and another to dump the current bride attributes.
ndo_bridge_setlink()
ndo_bridge_getlink()
This avoids adding many ndo_ops to the net_device but does require drivers do more nlmsg handling.
---
include/linux/netdevice.h | 10 ++++++ net/bridge/br_device.c | 2 + net/bridge/br_netlink.c | 73 ++++++++---------------------------------- net/bridge/br_private.h | 3 ++ net/core/rtnetlink.c | 78 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 106 insertions(+), 60 deletions(-)
include/linux/netdevice.h +10 -0
@@ -916,6 +916,10 @@ struct netdev_fcoe_hbainfo {* struct net_device *dev, int idx) * Used to add FDB entries to dump requests. Implementers should add * entries to skb and update idx with the number of entries. +* +* int (*ndo_bridge_setlink)(struct net_device *dev, struct nlmsghdr *nlh) +* int (*ndo_bridge_getlink)(struct sk_buff *skb, u32 pid, u32 seq, +* struct net_device *dev) */ struct net_device_ops {int (*ndo_init)(struct net_device *dev);
@@ -1025,6 +1029,12 @@ struct net_device_ops {struct netlink_callback *cb, struct net_device *dev, int idx); + +int (*ndo_bridge_setlink)(struct net_device *dev, +struct nlmsghdr *nlh); +int (*ndo_bridge_getlink)(struct sk_buff *skb, +u32 pid,u32 seq, +struct net_device *dev); };/*
net/bridge/br_device.c +2 -0
@@ -320,6 +320,8 @@ static const struct net_device_ops br_netdev_ops = { .ndo_fdb_add = br_fdb_add, .ndo_fdb_del = br_fdb_delete, .ndo_fdb_dump = br_fdb_dump, + .ndo_bridge_getlink = br_getlink, + .ndo_bridge_setlink = br_setlink, };static void br_dev_free (struct net_device *dev)
net/bridge/br_netlink.c +13 -60
106 lines not on this page · raw message
net/bridge/br_private.h +3 -0
@@ -552,6 +552,9 @@ extern int (*br_fdb_test_addr_hook)(struct net_device *dev, unsigned char *addr)extern int br_netlink_init (void );extern void br_netlink_fini (void );extern void br_ifinfo_notify (int event,struct net_bridge_port *port); +extern int br_setlink (struct net_device *dev,struct nlmsghdr *nlmsg); +extern int br_getlink (struct sk_buff *skb,u32 pid,u32 seq, +struct net_device *dev);#ifdef CONFIG_SYSFS /* br_sysfs_if.c */
net/core/rtnetlink.c +78 -0
89 lines not on this page · raw message
RFC PATCH 2/3 net: add VEPA, VEB bridge mode
In reply to John FastabendHardware switches may support enabling and disabling the loopback switch which puts the device in a VEPA mode defined in the IEEE 802.1Qbg specification. In this mode frames are not switched in the hardware but sent directly to the switch. SR-IOV capabable NICs will likely support this mode I am aware of at least two such devices.
This patch adds an additional IFLA_BRIDGE_MODE attribute that can be set and dumped via the PF_BRIDGE:{SET|GET}LINK operations. Also anticipating bridge attributes that may be common for both embedded bridges and software bridges this adds a flags attribute IFLA_BRIDGE_FLAGS currently used to determine if the IFLA_BRIDGE command or event is being generated to/from an embedded bridge or software bridge. Finally, the event generation is pulled out of the bridge module and into rtnetlink proper.
For example using the macvlan driver in VEPA mode on top of an embedded switch requires putting the embedded switch into a VEPA mode to get the expected results.
-------- --------
| VEPA | | VEPA | <-- macvlan vepa edge relays
-------- --------
| |
| |
------------------
| VEPA | <-- embedded switch in NIC
------------------
|
|
-------------------
| external switch | <-- shiny new physical
------------------- switch with VEPA supportA packet sent from the macvlan VEPA at the top could be loopbacked on the embedded switch and never seen by the external switch. So in order for this to work the embedded switch needs to be set in the VEPA state via the above described commands.
---
include/linux/if_link.h | 16 ++++++++++ net/bridge/br_netlink.c | 2 - net/core/rtnetlink.c | 73 ++++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 82 insertions(+), 9 deletions(-)
include/linux/if_link.h +16 -0
@@ -139,6 +139,7 @@ enum {IFLA_NET_NS_FD ,IFLA_EXT_MASK ,/* Extended info mask, VFs, etc */ IFLA_PROMISCUITY ,/* Promiscuity count: > 0 means acts PROMISC */ +IFLA_BRIDGE ,/* Bridge attributes */ #define IFLA_PROMISCUITY IFLA_PROMISCUITY __IFLA_MAX };
@@ -396,4 +397,19 @@ struct ifla_port_vsi { __u8 pad[3]; }; +/* Bridge Flags */ +#define BRIDGE_FLAGS_MASTER 0/* Bridge command to/from master */ +#define BRIDGE_FLAGS_SELF 1/* Bridge command to/from lowerdev */ + +#define BRIDGE_MODE_VEB 0/* Default loopback mode */ +#define BRIDGE_MODE_VEPA 1/* 802.1Qbg defined VEPA mode */ + +/* Bridge management nested attributes */ +enum { +IFLA_BRIDGE_FLAGS , +IFLA_BRIDGE_MODE , + __IFLA_BRIDGE_MAX, +}; +#define IFLA_BRIDGE_MAX (__IFLA_BRIDGE_MAX - 1) +#endif /* _LINUX_IF_LINK_H */
net/bridge/br_netlink.c +0 -2
@@ -166,8 +166,6 @@ int br_setlink(struct net_device *dev, struct nlmsghdr *nlh)br_port_state_selection (p->br);spin_unlock_bh (&p->br->lock); -br_ifinfo_notify (RTM_NEWLINK , p); -return 0 ; }
net/core/rtnetlink.c +66 -7
107 lines not on this page · raw message
RFC PATCH 3/3 ixgbe: add setlink, getlink support to ixgbe and ixgbevf
In reply to John FastabendThis adds support for the net device ops to manage the embedded hardware bridge on ixgbe devices. With this patch the bridge mode can be toggled between VEB and VEPA to support stacking macvlan devices or using the embedded switch without any SW component in 802.1Qbg/br environments.
Additionally, this adds source address pruning to the ixgbevf driver to prune any frames sent back from a reflective relay on the switch. This is required because the existing hardware does not support this. Without it frames get pushed into the stack with its own src mac which is invalid per 802.1Qbg VEPA definition.
---
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 100 ++++++++++++++++++++- drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c | 3 + drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c | 10 ++ 3 files changed, 110 insertions(+), 3 deletions(-)
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +97 -3
@@ -3144,7 +3144,6 @@ static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)IXGBE_WRITE_REG (hw,IXGBE_VFRE (reg_offset ^1 ),0 );IXGBE_WRITE_REG (hw,IXGBE_VFTE (reg_offset), (1 << vf_shift));IXGBE_WRITE_REG (hw,IXGBE_VFTE (reg_offset ^1 ),0 ); -IXGBE_WRITE_REG (hw,IXGBE_PFDTXGSWC ,IXGBE_PFDTXGSWC_VT_LBEN );/* Map PF MAC address in RAR Entry 0 to first pool following VFs */ hw->mac.ops.set_vmdq (hw,0 , adapter->num_vfs);
@@ -3158,8 +3157,6 @@ static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter) gcr_ext |=IXGBE_GCR_EXT_VT_MODE_64 ;IXGBE_WRITE_REG (hw,IXGBE_GCR_EXT , gcr_ext); -/* enable Tx loopback for VF/PF communication */ -IXGBE_WRITE_REG (hw,IXGBE_PFDTXGSWC ,IXGBE_PFDTXGSWC_VT_LBEN );/* Enable MAC Anti-Spoofing */ hw->mac.ops.set_mac_anti_spoofing(hw, (adapter->num_vfs != 0),
@@ -6844,6 +6841,101 @@ static int ixgbe_ndo_fdb_dump(struct sk_buff *skb,return idx; } +static int ixgbe_ndo_bridge_setlink (struct net_device *dev, +struct nlmsghdr *nlh) +{ +struct ixgbe_adapter *adapter =netdev_priv (dev); +struct nlattr *attr, *bridge; +int rem; + +if (!(adapter->flags &IXGBE_FLAG_SRIOV_ENABLED )) +return -EOPNOTSUPP ; + + bridge =nlmsg_find_attr (nlh,sizeof (struct ifinfomsg ),IFLA_BRIDGE ); + +nla_for_each_nested (attr, bridge, rem) { +__u16 mode; +u32 reg =0 ; + +if (nla_type (attr) !=IFLA_BRIDGE_MODE ) +continue ; + + mode =nla_get_u16 (attr); +if (mode ==BRIDGE_MODE_VEPA ) + reg =0 ; +else if (mode ==BRIDGE_MODE_VEB ) + reg =IXGBE_PFDTXGSWC_VT_LBEN ; +else +return -EINVAL ; + +IXGBE_WRITE_REG (&adapter->hw,IXGBE_PFDTXGSWC , reg); + +e_info (drv,"enabling bridge mode: %s\n" , + mode ==BRIDGE_MODE_VEPA ?"VEPA" :"VEB" ); + } + +return 0 ; +} + +static int ixgbe_ndo_bridge_getlink (struct sk_buff *skb,u32 pid,u32 seq, +struct net_device *dev) +{ +struct ixgbe_adapter *adapter =netdev_priv (dev); +struct nlmsghdr *nlh; +struct ifinfomsg *ifm; +struct nlattr *bridge; +u8 operstate =netif_running (dev) ? dev->operstate :IF_OPER_DOWN ; +u16 bridge_mode; + +if (!(adapter->flags &IXGBE_FLAG_SRIOV_ENABLED )) +return 0 ; + + nlh =nlmsg_put (skb, pid, seq,RTM_NEWLINK ,sizeof (*ifm),NLM_F_MULTI ); +if (nlh ==NULL ) +return -EMSGSIZE ; + + ifm =nlmsg_data (nlh); + ifm->ifi_family =AF_BRIDGE ; + ifm->__ifi_pad =0 ; + ifm->ifi_type = dev->type; + ifm->ifi_index = dev->ifindex; + ifm->ifi_flags =dev_get_flags (dev); + ifm->ifi_change =0 ; + + +if (nla_put_string (skb,IFLA_IFNAME , dev->name) || +nla_put_u32 (skb,IFLA_MTU , dev->mtu) || +nla_put_u8 (skb,IFLA_OPERSTATE , operstate) || + (dev->master && +nla_put_u32 (skb,IFLA_MASTER , dev->master->ifindex)) || + (dev->addr_len && +nla_put (skb,IFLA_ADDRESS , dev->addr_len, dev->dev_addr)) || + (dev->ifindex != dev->iflink && +nla_put_u32 (skb,IFLA_LINK , dev->iflink))) + goto nla_put_failure; + +if (IXGBE_READ_REG (&adapter->hw,IXGBE_PFDTXGSWC ) &1 ) + bridge_mode =BRIDGE_MODE_VEB ; +else + bridge_mode =BRIDGE_MODE_VEPA ; + + bridge =nla_nest_start (skb,IFLA_BRIDGE ); +if (!bridge) + goto nla_put_failure; + +if (nla_put_u16 (skb,IFLA_BRIDGE_FLAGS ,BRIDGE_FLAGS_SELF ) || +nla_put_u16 (skb,IFLA_BRIDGE_MODE , bridge_mode)) { +nla_nest_cancel (skb, bridge); + goto nla_put_failure; + } +nla_nest_end (skb, bridge); + +return nlmsg_end (skb, nlh); +nla_put_failure: +nlmsg_cancel (skb, nlh); +return -EMSGSIZE ; +} +static const struct net_device_ops ixgbe_netdev_ops = { .ndo_open = ixgbe_open, .ndo_stop = ixgbe_close,
@@ -6883,6 +6975,8 @@ static const struct net_device_ops ixgbe_netdev_ops = { .ndo_fdb_add = ixgbe_ndo_fdb_add, .ndo_fdb_del = ixgbe_ndo_fdb_del, .ndo_fdb_dump = ixgbe_ndo_fdb_dump, + .ndo_bridge_setlink = ixgbe_ndo_bridge_setlink, + .ndo_bridge_getlink = ixgbe_ndo_bridge_getlink, }; static void __devinit ixgbe_probe_vf(struct ixgbe_adapter *adapter,
drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c +3 -0
@@ -135,6 +135,9 @@ void ixgbe_enable_sriov(struct ixgbe_adapter *adapter, } } +/* Initialize default switching mode VEB */ +IXGBE_WRITE_REG (hw,IXGBE_PFDTXGSWC ,IXGBE_PFDTXGSWC_VT_LBEN ); +/* If call to enable VFs succeeded then allocate memory * for per VF control structures. */
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +10 -0
@@ -575,6 +575,16 @@ static bool ixgbevf_clean_rx_irq(struct ixgbevf_q_vector *q_vector, } skb->protocol =eth_type_trans (skb, adapter->netdev); +/* Workaround hardware that can't do proper VEPA multicast +* source pruning. +*/ +if ((skb->pkt_type & (PACKET_BROADCAST |PACKET_MULTICAST )) && + !(compare_ether_addr (adapter->netdev->dev_addr, +eth_hdr (skb)->h_source))) { +dev_kfree_skb_irq (skb); + goto next_desc; + } +ixgbevf_receive_skb (q_vector, skb, staterr, rx_ring, rx_desc); next_desc:
Re: [RFC PATCH v1 2/3] net: add VEPA, VEB bridge mode
In reply to John FastabendJohn Fastabend <[email protected]> wrote on 05/30/2012 08:37:06 AM:
Some comments below:
net/core/rtnetlink.c static int rtnl_bridge_getlink(struct sk_buff *skb, struct netlink_callback *cb)
Quoted 4 lines
net/core/rtnetlink.c +3
-0+static int rtnl_bridge_notify(struct net_device *dev, u16 flags) +{ + if (!flags && master && master->netdev_ops->
ndo_bridge_getlink)
Review
Quoted 1 line
(quoted diff) +1
-0+ err = master->netdev_ops->ndo_bridge_getlink(skb,
0, 0, dev);
Review
Quoted 2 lines
(quoted diff) +2
-0+ else if (dev->netdev_ops->ndo_bridge_getlink) + err = dev->netdev_ops->ndo_bridge_getlink(skb, 0,
0, dev);
I think you should do something like:
if ((flags == BRIDGE_FLAGS_MASTER) && ...)
...Also you could use BRIDGE_FLAGS_MASTER=1, SELF=2, and use "if (flags & BRIDGE_FLAGS_MASTER)" for consistency?
+ if (!err)
+ err = rtnl_bridge_notify(dev, flags);
It is possible to return a reporting error even though the operation succeeded. Maybe something that could be done here to indicate that the operation succeeded, or is that a TODO?
Quoted 1 line
static int rtnl_bridge_setlink(struct
sk_buff*skb, struct nlmsghdr
*nlh,
Quoted 2 lines
void *arg)
{
..
net/core/rtnetlink.c static int rtnl_bridge_setlink(struct sk_buff *skb, struct nlmsghdr *nlh, · line 2367
Quoted 5 lines
net/core/rtnetlink.c +5
-0+if (!flags && dev->master && + dev->master->netdev_ops->ndo_bridge_setlink) + err = dev->master->netdev_ops->ndo_bridge_setlink (dev, nlh); +else if ((flags &BRIDGE_FLAGS_SELF ) && + dev->netdev_ops->ndo_bridge_setlink)
Same usage of MASTER here.
Thanks,
- KK
Re: [RFC PATCH v1 2/3] net: add VEPA, VEB bridge mode
Quoted 16 lines · On 6/4/2012 7:59 AM, Krishna Kumar2 wrote:
John Fastabend <[email protected]> wrote on 05/30/2012 08:37:06 AM:
Some comments below:
net/core/rtnetlink.c static int rtnl_bridge_getlink(struct sk_buff *skb, struct netlink_callback *cb)
Quoted 4 lines
net/core/rtnetlink.c +3
-0+static int rtnl_bridge_notify(struct net_device *dev, u16 flags) +{ + if (!flags && master && master->netdev_ops->
ndo_bridge_getlink)Review
Quoted 1 line
(quoted diff) +1
-0+ err = master->netdev_ops->ndo_bridge_getlink(skb,0, 0, dev);
Review
Quoted 2 lines
(quoted diff) +2
-0+ else if (dev->netdev_ops->ndo_bridge_getlink) + err = dev->netdev_ops->ndo_bridge_getlink(skb, 0,0, dev);
Quoted 7 lines
I think you should do something like:
if ((flags == BRIDGE_FLAGS_MASTER) && ...) ...Also you could use BRIDGE_FLAGS_MASTER=1, SELF=2, and use "if (flags &
BRIDGE_FLAGS_MASTER)" for consistency?
OK this is likely a good thing otherwise user space is a bit tedious when managing FDB and bridge modes. We do still need the !flags case to support existing applications though, (we must maintain existing semantics)
if (!flags || (flags & BRIDGE_FLAGS_MASTER) && ...)
... else (flags & BRIDGE_FLAGS_SELF) ...
Quoted 10 lines
net/core/rtnetlink.c +2
-0+if (!err) + err =rtnl_bridge_notify (dev, flags);It is possible to return a reporting error even though the operation succeeded. Maybe something that could be done here to indicate that the operation succeeded, or is that a TODO?
The problem is if rtnl_bridge_notify fails due to memory constraints or otherwise. In this case the set has already completed successfully as you note so we should not return any error. This should fix it if I understand your concern correctly.
if (!err) rtnl_bridge_notify(dev, flags); return err;
Quoted 4 lines
Quoted 1 line
static int rtnl_bridge_setlink(struct
sk_buff*skb, struct nlmsghdr*nlh,
Quoted 2 lines
void *arg)
{
Quoted 8 lines
..
net/core/rtnetlink.c static int rtnl_bridge_setlink(struct sk_buff *skb, struct nlmsghdr *nlh, · line 2367
Quoted 5 lines
net/core/rtnetlink.c +5
-0+if (!flags && dev->master && + dev->master->netdev_ops->ndo_bridge_setlink) + err = dev->master->netdev_ops->ndo_bridge_setlink (dev, nlh); +else if ((flags &BRIDGE_FLAGS_SELF ) && + dev->netdev_ops->ndo_bridge_setlink)Same usage of MASTER here.
Agreed. Thanks.
Quoted 4 lines
Thanks,
- KK
Re: [RFC PATCH v1 2/3] net: add VEPA, VEB bridge mode
John Fastabend <[email protected]> wrote on 06/04/2012 10:08:04 PM:
Quoted 13 lines
Quoted 7 lines
I think you should do something like:
if ((flags == BRIDGE_FLAGS_MASTER) && ...) ...Also you could use BRIDGE_FLAGS_MASTER=1, SELF=2, and use "if (flags &
BRIDGE_FLAGS_MASTER)" for consistency?OK this is likely a good thing otherwise user space is a bit tedious when managing FDB and bridge modes. We do still need the !flags case to support existing applications though, (we must maintain existing semantics)
Quoted 4 lines
if (!flags || (flags &
BRIDGE_FLAGS_MASTER) && ...)
...
else (flags &BRIDGE_FLAGS_SELF)
...
Yes, looks good.
Quoted 12 lines
Quoted 5 lines
It is possible to return a reporting error even though the operation succeeded. Maybe something that could be done here to indicate that the operation succeeded, or is that a TODO?
The problem is if
rtnl_bridge_notifyfails due to memory constraints or otherwise. In this case the set has already completed successfully as you note so we should not return any error. This should fix it if I understand your concern correctly.
Quoted 3 lines
if (!err)
rtnl_bridge_notify(dev, flags);
return err;Yes. I guess user will not hang waiting for a response as it will pass NLM_F_ACK, which allows netlink_rcv_skb to call netlink_ack.
Thanks,
- KK