net: bridge: FDB management
Subsystems (4)
cover net: bridge: FDB management
This series is a follow up to the previous thread here:
http://lists.openwall.net/netdev/2012/02/29/31
There are some significant changes in this series. First I add two NTF_XXX bits to signal if the PF_BRIDGE netlink command should be parsed by the embedded bridge or the SW bridge. The insight here is the SW bridge is always the master device (NTF_MASTER) and the embedded bridge is the lower device (NTF_LOWERDEV). Without either flag set the command is parsed by the SW bridge to support existing tooling.
To make this work correctly I added three new ndo ops
ndo_fdb_add
ndo_fdb_del
ndo_fdb_dump
to add, delete, and dump FDB entries. These operations can be used by drivers to program embedded nics or by software bridges. We have at least three SW bridge now net/bridge, openvswitch, and macvlan. And three variants of embedded bridges SR-IOV devices, multi-function devices and Distributed Switch Architecture (DSA).
I think at least in this case adding netdevice ops is the cleanest way to implement this. I thought about notifier hooks and other methods but for now at least this seems to be the simplest.
I'm going to drop this into my testbed and let it run for a few days. But I think (hope?) this series is close to being ready for a non-RFC submission. I'll probably audit the patches once more as well.
Thanks to Stephen, Ben, and Jamal for bearing with me and the feedback on the last round of patches.
As always any comments/feedback is appreciated!
---
John Fastabend (4):
ixgbe: enable FDB netdevice ops
net: add fdb generic dump routine
net: addr_list: add exclusive dev_uc_add
net: add generic PF_BRIDGE:RTM_XXX FDB hooks
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 59 ++++++++ include/linux/neighbour.h | 3 include/linux/netdevice.h | 27 +++ include/linux/rtnetlink.h | 4 + net/bridge/br_device.c | 3 net/bridge/br_fdb.c | 128 ++++------------ net/bridge/br_netlink.c | 12 -- net/bridge/br_private.h | 15 ++ net/core/dev_addr_lists.c | 19 ++ net/core/rtnetlink.c | 194 +++++++++++++++++++++++++ 10 files changed, 352 insertions(+), 112 deletions(-)
Signature · 1 line
Signature
RFC PATCH 2/4 net: addr_list: add exclusive dev_uc_add
This adds a dev_uc_add_excl() call similar to the original dev_uc_add() except it sets the global bit. With this change the reference count will not be bumped and -EEXIST will be returned if a duplicate address exists.
This is useful for drivers that support SR-IOV and want to manage the unicast lists.
---
include/linux/netdevice.h | 1 + net/core/dev_addr_lists.c | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 0 deletions(-)
include/linux/netdevice.h +1 -0
@@ -2553,6 +2553,7 @@ extern int dev_addr_init(struct net_device *dev);/* Functions used for unicast addresses handling */ extern int dev_uc_add (struct net_device *dev,unsigned char *addr); +extern int dev_uc_add_excl (struct net_device *dev,unsigned char *addr);extern int dev_uc_del (struct net_device *dev,unsigned char *addr);extern int dev_uc_sync (struct net_device *to,struct net_device *from);extern void dev_uc_unsync (struct net_device *to,struct net_device *from);
net/core/dev_addr_lists.c +19 -0
@@ -377,6 +377,25 @@ EXPORT_SYMBOL(dev_addr_del_multiple);*/ /** +* dev_uc_add_excl - Add a global secondary unicast address +* @dev: device +* @addr: address to add +*/ +int dev_uc_add_excl (struct net_device *dev,unsigned char *addr) +{ +int err; + +netif_addr_lock_bh (dev); + err =__hw_addr_add_ex (&dev->uc, addr, dev->addr_len, +NETDEV_HW_ADDR_T_UNICAST , true); +if (!err) +__dev_set_rx_mode (dev); +netif_addr_unlock_bh (dev); +return err; +} +EXPORT_SYMBOL (dev_uc_add_excl); + +/** * dev_uc_add - Add a secondary unicast address * @dev: device * @addr: address to add
RFC PATCH 3/4 net: add fdb generic dump routine
In reply to John FastabendThis adds a generic dump routine drivers can call. It should be sufficient to handle any bridging model that uses the unicast address list. This should be most SR-IOV enabled NICs.
---
net/core/rtnetlink.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 56 insertions(+), 0 deletions(-)
net/core/rtnetlink.c +56 -0
@@ -2082,6 +2082,62 @@ static int rtnl_fdb_del(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)return err; } +/** +* ndo_dflt_fdb_dump: default netdevice operation to dump an FDB table. +* @nlh: netlink message header +* @dev: netdevice +* +* Default netdevice operation to dump the existing unicast address list. +* Returns zero on success. +*/ +int ndo_dflt_fdb_dump (struct sk_buff *skb, +struct netlink_callback *cb, +struct net_device *dev, +int idx) +{ +struct netdev_hw_addr *ha; +struct nlmsghdr *nlh; +struct ndmsg *ndm; +u32 pid, seq; + + pid =NETLINK_CB (cb->skb).pid; + seq = cb->nlh->nlmsg_seq; + +netif_addr_lock_bh (dev); +list_for_each_entry (ha, &dev->uc.list, list) { +if (idx < cb->args[0 ]) + goto skip; + + nlh =nlmsg_put (skb, pid, seq, +RTM_NEWNEIGH ,sizeof (*ndm),NLM_F_MULTI ); +if (!nlh) +break ; + + ndm =nlmsg_data (nlh); + ndm->ndm_family =AF_BRIDGE ; + ndm->ndm_pad1 =0 ; + ndm->ndm_pad2 =0 ; + ndm->ndm_flags =NTF_LOWERDEV ; + ndm->ndm_type =0 ; + ndm->ndm_ifindex = dev->ifindex; + ndm->ndm_state =NUD_PERMANENT ; + +NLA_PUT (skb,NDA_LLADDR ,ETH_ALEN , ha->addr); + +nlmsg_end (skb, nlh); +skip: + ++idx; + } +netif_addr_unlock_bh (dev); + +return idx; +nla_put_failure: +netif_addr_unlock_bh (dev); +nlmsg_cancel (skb, nlh); +return idx; +} +EXPORT_SYMBOL (ndo_dflt_fdb_dump); +static int rtnl_fdb_dump (struct sk_buff *skb,struct netlink_callback *cb) {int idx =0 ;
RFC PATCH 4/4 ixgbe: enable FDB netdevice ops
In reply to John FastabendEnable FDB ops on ixgbe when in SR-IOV mode.
---
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 59 +++++++++++++++++++++++++ 1 files changed, 59 insertions(+), 0 deletions(-)
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +59 -0
@@ -7484,6 +7484,62 @@ static int ixgbe_set_features(struct net_device *netdev, } +static int ixgbe_ndo_fdb_add (struct ndmsg *ndm, +struct net_device *dev, +unsigned char *addr, +u16 flags) +{ +struct ixgbe_adapter *adapter =netdev_priv (dev); +int err = -EOPNOTSUPP ; + +if (ndm->ndm_state &NUD_PERMANENT ) { +pr_info ("%s: FDB only supports static addresses\n" , + ixgbe_driver_name); +return -EINVAL ; + } + +if (adapter->flags &IXGBE_FLAG_SRIOV_ENABLED ) + err =dev_uc_add_excl (dev, addr); + +/* Only return duplicate errors if NLM_F_EXCL is set */ +if (err == -EEXIST && !(flags &NLM_F_EXCL )) + err =0 ; + +return err; +} + +static int ixgbe_ndo_fdb_del (struct ndmsg *ndm, +struct net_device *dev, +unsigned char *addr) +{ +struct ixgbe_adapter *adapter =netdev_priv (dev); +int err = -EOPNOTSUPP ; + +if (ndm->ndm_state &NUD_PERMANENT ) { +pr_info ("%s: FDB only supports static addresses\n" , + ixgbe_driver_name); +return -EINVAL ; + } + +if (adapter->flags &IXGBE_FLAG_SRIOV_ENABLED ) + err =dev_uc_del (dev, addr); + +return err; +} + +static int ixgbe_ndo_fdb_dump (struct sk_buff *skb, +struct netlink_callback *cb, +struct net_device *dev, +int idx) +{ +struct ixgbe_adapter *adapter =netdev_priv (dev); + +if (adapter->flags &IXGBE_FLAG_SRIOV_ENABLED ) + idx =ndo_dflt_fdb_dump (skb, cb, dev, idx); + +return idx; +} +static const struct net_device_ops ixgbe_netdev_ops = { .ndo_open = ixgbe_open, .ndo_stop = ixgbe_close,
@@ -7518,6 +7574,9 @@ static const struct net_device_ops ixgbe_netdev_ops = {#endif /* IXGBE_FCOE */ .ndo_set_features = ixgbe_set_features, .ndo_fix_features = ixgbe_fix_features, + .ndo_fdb_add = ixgbe_ndo_fdb_add, + .ndo_fdb_del = ixgbe_ndo_fdb_del, + .ndo_fdb_dump = ixgbe_ndo_fdb_dump, }; static void __devinit ixgbe_probe_vf(struct ixgbe_adapter *adapter,
Re: [RFC PATCH v1 4/4] ixgbe: enable FDB netdevice ops
Quoted 4 lines
Enable FDB ops on ixgbe when in SR-IOV mode.
Signed-off-by John Fastabend <[email protected]>
Will all this break anything on the vf client? What if the vf is running a bridge.
Re: [RFC PATCH v1 4/4] ixgbe: enable FDB netdevice ops
Quoted 7 lines · Stephen Hemminger
Quoted 4 lines
Enable FDB ops on ixgbe when in SR-IOV mode.
Signed-off-by John Fastabend <[email protected]>Will all this break anything on the vf client? What if the vf is running a bridge.
No shouldn't break anything.
Actually, implementing these ops in the VF driver (ixgbevf in this case) will allow bridging to work on the VF. Because at least on the intel 82599 devices the VF can't be put in promiscuous mode so bridging doesn't work as expected. With the ops implemented we could at least get traffic forwarded correctly for addresses that were known above the VF.