Skip to contentSkip to conversation

net: Report requester's port ID in FDB notifications

PATCH New Petr Machata 1 participant 14 messages Nov 23

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

cover net: Report requester's port ID in FDB notifications

Every netlink message carries a port ID in the nlmsg_pid header field. The port ID identifies a netlink socket. In a request it is the port ID of the socket that sent it. When a change that results from a request is announced to the multicast listeners, the kernel puts the port ID of the requester in nlmsg_pid of the notification. For changes that the kernel initiates by itself, such as aging, nlmsg_pid is zero.

This is used by applications that both configure the kernel and listen to notifications from it. By comparing nlmsg_pid to the port ID of their own socket, they can tell their own changes apart from those made by someone else, and ignore the former. Commit 7b8f7a402d4c ("neighbour: fix nlmsg_pid in notifications") fixed this for IP neighbours, citing quagga as one such application. Routes and nexthops report the port ID as well.

For FDB entries, the notifications (RTM_NEWNEIGH and RTM_DELNEIGH with the AF_BRIDGE family) always carry zero, whoever caused them, so applications that manage FDB cannot do this sort of filtering. Hence this patchset.

The patchset goes through the following steps:

- FDB notifications are generated in two places. The bridge and VXLAN drivers send their own from ndo_fdb_add, _del and _del_bulk, but these NDOs are not given the port ID of the requester. For other drivers that implement ndo_fdb_add / _del, the rtnetlink core sends a default notification on their behalf. It has the port ID at hand, but does not pass it on.

The obvious way to get the port ID to the bridge and VXLAN is to add it to the NDO prototypes. But ndo_fdb_add and _del already carry many arguments, and one more would further complicate the already unwieldy prototypes, as well as require adjustments in every driver. Instead, in patch #1, convert the prototypes of ndo_fdb_add, _del and _get to take a new struct ndo_fdb_parms. ndo_fdb_get already has the port ID, but it shares most of its arguments with the other two, so it makes sense to treat them alike.

A dedicated structure has the advantage that both callers and callees can refer to individual arguments by name instead of by position. Any future additions boil down to a new field in the structure.

In patch #2, have ndo_dflt_fdb_add and ndo_dflt_fdb_del take the structure as well. That simplifies the drivers that use the helper, which can now just pass the structure pointer right through.

In patch #3, move the port ID of ndo_fdb_get from an argument into the structure and adjust drivers.

- Now that the structure argument is available to the bridge driver, make use of the fact in patch #4. Instead of unpacking the structure fields and passing them on one by one, propagate the structure itself further into the driver.

Then in patch #5, propagate the port ID all the way to where bridge notifications are generated.

It is tempting to somehow use the parms structure more extensively in VXLAN as well, but VXLAN has its own large set of protocol-specific parameters. Passing the structure as such is not going to help that much. It looks like VXLAN would ideally need its own VXLAN-specific parms structure. But since the complexity damage here is limited to VXLAN, leave the status quo and in patch #6, just add the new parameter. The patchset is large enough as it is.

- Patch #7 is where the port ID in struct ndo_fdb_parms is initialized from the request. With that, notifications that the bridge and VXLAN send as a result of adding, replacing and deleting an entry carry the port ID. Notifications that are not a result of a request still carry zero.

Patch #8 then adds the port ID argument to ndo_fdb_del_bulk, which does not use the newly-introduced parms structure, and has the bridge and VXLAN drivers use the now-available port ID for notifications.

Finally, patch #9 converts the rtnetlink fallback helper, so that the notifications it sends on behalf of drivers that do not emit their own carry the port ID as well.

- Patches #10 to #13 add a selftest. Patches #10 to #12 extend the rt-neigh spec with attributes needed to build FDB delete requests, add the NLM_F_BULK flag to the YNL Python library and add an RtnlNeighFamily wrapper to the selftest library. Patch #13 then adds the test itself. The test is written in Python with YNL, because the usual shell tools cannot show nlmsg_pid.

Petr Machata (13):
net: Introduce struct ndo_fdb_parms
net: Pass struct ndo_fdb_parms to ndo_dflt_fdb_{add, del}()
net: Pass portid to ndo_fdb_get through the structure
net: bridge: Pass struct ndo_fdb_parms a bit further
net: bridge: Pass portid through FDB notifications
net: vxlan: Pass portid through FDB notifications
net: rtnetlink: Report port ID in bridge and VXLAN FDB notifications
net: rtnetlink: Report port ID in bulk FDB delete notifications
net: rtnetlink: Report port ID in fallback FDB notifications
netlink: specs: rt-neigh: Extend the delneigh request attributes
tools: ynl: Add NLM_F_BULK
selftests: net: lib: py: Add RtnlNeighFamily
selftests: net: Add a test for port ID in FDB notifications

 Documentation/netlink/specs/rt-neigh.yaml     |   4 +
 drivers/net/ethernet/intel/i40e/i40e_main.c   |  29 +-
 drivers/net/ethernet/intel/ice/ice_main.c     |  43 ++-
 drivers/net/ethernet/intel/igb/igb_main.c     |  14 +-
 drivers/net/ethernet/intel/ixgbe/ixgbe_main.c |  14 +-
 drivers/net/ethernet/mscc/ocelot_net.c        |  19 +-
 .../net/ethernet/qlogic/qlcnic/qlcnic_main.c  |  38 ++-
 drivers/net/macvlan.c                         |  33 +-
 drivers/net/vxlan/vxlan_core.c                | 118 +++----
 drivers/net/vxlan/vxlan_private.h             |   5 +-
 drivers/net/vxlan/vxlan_vnifilter.c           |   6 +-
 include/linux/netdevice.h                     |  43 ++-
 include/linux/rtnetlink.h                     |   9 +-
 net/bridge/br.c                               |   2 +-
 net/bridge/br_fdb.c                           | 177 ++++++-----
 net/bridge/br_netlink.c                       |   4 +-
 net/bridge/br_private.h                       |  20 +-
 net/bridge/br_sysfs_br.c                      |   2 +-
 net/core/rtnetlink.c                          |  98 +++---
 tools/net/ynl/pyynl/lib/ynl.py                |   2 +
 tools/testing/selftests/net/Makefile          |   1 +
 tools/testing/selftests/net/config            |   1 +
 .../selftests/net/fdb_notify_portid.py        | 297 ++++++++++++++++++
 .../testing/selftests/net/lib/py/__init__.py  |   6 +-
 tools/testing/selftests/net/lib/py/ynl.py     |  10 +-
 25 files changed, 669 insertions(+), 326 deletions(-)
 create mode 100755 tools/testing/selftests/net/fdb_notify_portid.py
Signature · 1 line
2.56.1
#1 lore raw

PATCH 1/13 net: Introduce struct ndo_fdb_parms

The ndo_fdb_add, ndo_fdb_del and ndo_fdb_get callbacks share a growing list of arguments: device, address, VLAN ID and, for add, the netlink message flags. A following patch will add another argument to that list: a port ID. With that addition, the prototypes get unwieldy. Any such change also prompts updates of the corresponding NDO callbacks in several drivers.

Collect the common arguments in a new struct ndo_fdb_parms, similarly to how struct neigh_parms is used for ndo_neigh_setup, and pass a pointer to it instead of these arguments. The ndmsg, nlattr array, the "notified" flag, extack, and for ndo_fdb_get also the port ID and sequence number, stay separate arguments.

In rtnl_fdb_del(), the structure is only initialized for non-bulk requests, which is where the VLAN ID and address are parsed, and the only place where the callbacks consume it.

With this change, addition of a new parameter then consists of adding a new field to this struct and a proper initialization, and avoids the NDO update dance.

No functional change intended.

---
CC: Tony Nguyen <[email protected]>
CC: Przemek Kitszel <[email protected]>
CC: [email protected]
CC: Vladimir Oltean <[email protected]>
CC: [email protected]
CC: Shahed Shaikh <[email protected]>
CC: Manish Chopra <[email protected]>
CC: [email protected]

---
 drivers/net/ethernet/intel/i40e/i40e_main.c   | 29 ++++----
 drivers/net/ethernet/intel/ice/ice_main.c     | 43 ++++++------
 drivers/net/ethernet/intel/igb/igb_main.c     | 15 +++--
 drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 15 +++--
 drivers/net/ethernet/mscc/ocelot_net.c        | 19 +++---
 .../net/ethernet/qlogic/qlcnic/qlcnic_main.c  | 40 +++++------
 drivers/net/macvlan.c                         | 33 +++++----
 drivers/net/vxlan/vxlan_core.c                | 27 ++++----
 include/linux/netdevice.h                     | 38 ++++++-----
 net/bridge/br_fdb.c                           | 67 ++++++++++---------
 net/bridge/br_private.h                       | 14 ++--
 net/core/rtnetlink.c                          | 37 +++++++---
 12 files changed, 195 insertions(+), 182 deletions(-)
drivers/net/ethernet/intel/i40e/i40e_main.c +13 -16
index abbc71e815ae..c8337bef5dbf 100644
@@ -13022,28 +13022,24 @@ static int i40e_get_phys_port_id(struct net_device *netdev,
  * i40e_ndo_fdb_add - add an entry to the hardware database
  * @ndm: the input from the stack
  * @tb: pointer to array of nladdr (unused)
- * @dev: the net device pointer
- * @addr: the MAC address entry being added
- * @vid: VLAN ID
- * @flags: instructions from stack about fdb operation
+ * @parms: common FDB parameters
  * @notified: whether notification was emitted
  * @extack: netlink extended ack, unused currently
  */
 static int i40e_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
-			    struct net_device *dev,
-			    const unsigned char *addr, u16 vid,
-			    u16 flags, bool *notified,
+			    const struct ndo_fdb_parms *parms, bool *notified,
 			    struct netlink_ext_ack *extack)
 {
-	struct i40e_netdev_priv *np = netdev_priv(dev);
+	struct i40e_netdev_priv *np = netdev_priv(parms->dev);
 	struct i40e_pf *pf = np->vsi->back;
 	int err = 0;
 
 	if (!test_bit(I40E_FLAG_SRIOV_ENA, pf->flags))
 		return -EOPNOTSUPP;
 
-	if (vid) {
-		pr_info("%s: vlans aren't supported yet for dev_uc|mc_add()\n", dev->name);
+	if (parms->vid) {
+		pr_info("%s: vlans aren't supported yet for dev_uc|mc_add()\n",
+			parms->dev->name);
 		return -EINVAL;
 	}
 
@@ -13051,19 +13047,20 @@ static int i40e_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
 	 * ndm_state is given only allow permanent addresses
 	 */
 	if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) {
-		netdev_info(dev, "FDB only supports static addresses\n");
+		netdev_info(parms->dev, "FDB only supports static addresses\n");
 		return -EINVAL;
 	}
 
-	if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr))
-		err = dev_uc_add_excl(dev, addr);
-	else if (is_multicast_ether_addr(addr))
-		err = dev_mc_add_excl(dev, addr);
+	if (is_unicast_ether_addr(parms->addr) ||
+	    is_link_local_ether_addr(parms->addr))
+		err = dev_uc_add_excl(parms->dev, parms->addr);
+	else if (is_multicast_ether_addr(parms->addr))
+		err = dev_mc_add_excl(parms->dev, parms->addr);
 	else
 		err = -EINVAL;
 
 	/* Only return duplicate errors if NLM_F_EXCL is set */
-	if (err == -EEXIST && !(flags & NLM_F_EXCL))
+	if (err == -EEXIST && !(parms->flags & NLM_F_EXCL))
 		err = 0;
 
 	return err;
drivers/net/ethernet/intel/ice/ice_main.c +19 -24

87 lines not on this page · raw message

drivers/net/ethernet/intel/igb/igb_main.c +8 -7
index c75d78badf71..42b2fd3ed95c 100644
@@ -2517,21 +2517,22 @@ static int igb_set_features(struct net_device *netdev,
 }
 
 static int igb_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
-			   struct net_device *dev,
-			   const unsigned char *addr, u16 vid,
-			   u16 flags, bool *notified,
+			   const struct ndo_fdb_parms *parms, bool *notified,
 			   struct netlink_ext_ack *extack)
 {
 	/* guarantee we can provide a unique filter for the unicast address */
-	if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) {
-		struct igb_adapter *adapter = netdev_priv(dev);
+	if (is_unicast_ether_addr(parms->addr) ||
+	    is_link_local_ether_addr(parms->addr)) {
+		struct igb_adapter *adapter = netdev_priv(parms->dev);
 		int vfn = adapter->vfs_allocated_count;
 
-		if (netdev_uc_count(dev) >= igb_available_rars(adapter, vfn))
+		if (netdev_uc_count(parms->dev) >=
+		    igb_available_rars(adapter, vfn))
 			return -ENOMEM;
 	}
 
-	return ndo_dflt_fdb_add(ndm, tb, dev, addr, vid, flags);
+	return ndo_dflt_fdb_add(ndm, tb, parms->dev, parms->addr,
+				parms->vid, parms->flags);
 }
 
 #define IGB_MAX_MAC_HDR_LEN	127
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +8 -7
index 6458cb2e511e..26d1a7253cf3 100644
@@ -10603,21 +10603,22 @@ static int ixgbe_set_features(struct net_device *netdev,
 }
 
 static int ixgbe_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
-			     struct net_device *dev,
-			     const unsigned char *addr, u16 vid,
-			     u16 flags, bool *notified,
+			     const struct ndo_fdb_parms *parms, bool *notified,
 			     struct netlink_ext_ack *extack)
 {
 	/* guarantee we can provide a unique filter for the unicast address */
-	if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) {
-		struct ixgbe_adapter *adapter = ixgbe_from_netdev(dev);
+	if (is_unicast_ether_addr(parms->addr) ||
+	    is_link_local_ether_addr(parms->addr)) {
+		struct ixgbe_adapter *adapter = ixgbe_from_netdev(parms->dev);
 		u16 pool = VMDQ_P(0);
 
-		if (netdev_uc_count(dev) >= ixgbe_available_rars(adapter, pool))
+		if (netdev_uc_count(parms->dev) >=
+		    ixgbe_available_rars(adapter, pool))
 			return -ENOMEM;
 	}
 
-	return ndo_dflt_fdb_add(ndm, tb, dev, addr, vid, flags);
+	return ndo_dflt_fdb_add(ndm, tb, parms->dev, parms->addr,
+				parms->vid, parms->flags);
 }
 
 /**
drivers/net/ethernet/mscc/ocelot_net.c +9 -10
index 4d45e136f08f..65f9dee62dc5 100644
@@ -765,30 +765,29 @@ static void ocelot_get_stats64(struct net_device *dev,
 }
 
 static int ocelot_port_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
-			       struct net_device *dev,
-			       const unsigned char *addr,
-			       u16 vid, u16 flags, bool *notified,
-			       struct netlink_ext_ack *extack)
+			       const struct ndo_fdb_parms *parms,
+			       bool *notified, struct netlink_ext_ack *extack)
 {
-	struct ocelot_port_private *priv = netdev_priv(dev);
+	struct ocelot_port_private *priv = netdev_priv(parms->dev);
 	struct ocelot_port *ocelot_port = &priv->port;
 	struct ocelot *ocelot = ocelot_port->ocelot;
 	int port = priv->port.index;
 
-	return ocelot_fdb_add(ocelot, port, addr, vid, ocelot_port->bridge);
+	return ocelot_fdb_add(ocelot, port, parms->addr, parms->vid,
+			      ocelot_port->bridge);
 }
 
 static int ocelot_port_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
-			       struct net_device *dev,
-			       const unsigned char *addr, u16 vid,
+			       const struct ndo_fdb_parms *parms,
 			       bool *notified, struct netlink_ext_ack *extack)
 {
-	struct ocelot_port_private *priv = netdev_priv(dev);
+	struct ocelot_port_private *priv = netdev_priv(parms->dev);
 	struct ocelot_port *ocelot_port = &priv->port;
 	struct ocelot *ocelot = ocelot_port->ocelot;
 	int port = priv->port.index;
 
-	return ocelot_fdb_del(ocelot, port, addr, vid, ocelot_port->bridge);
+	return ocelot_fdb_del(ocelot, port, parms->addr, parms->vid,
+			      ocelot_port->bridge);
 }
 
 static int ocelot_port_fdb_do_dump(const unsigned char *addr, u16 vid,
drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c +20 -20
index 23ae76ca81db..85017de2161b 100644
@@ -366,24 +366,24 @@ static int qlcnic_set_mac(struct net_device *netdev, void *p)
 }
 
 static int qlcnic_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
-			struct net_device *netdev,
-			const unsigned char *addr, u16 vid, bool *notified,
+			const struct ndo_fdb_parms *parms, bool *notified,
 			struct netlink_ext_ack *extack)
 {
-	struct qlcnic_adapter *adapter = netdev_priv(netdev);
+	struct qlcnic_adapter *adapter = netdev_priv(parms->dev);
 	int err = -EOPNOTSUPP;
 
 	if (!adapter->fdb_mac_learn)
-		return ndo_dflt_fdb_del(ndm, tb, netdev, addr, vid);
+		return ndo_dflt_fdb_del(ndm, tb, parms->dev, parms->addr,
+					parms->vid);
 
 	if ((adapter->flags & QLCNIC_ESWITCH_ENABLED) ||
 	    qlcnic_sriov_check(adapter)) {
-		if (is_unicast_ether_addr(addr)) {
-			err = dev_uc_del(netdev, addr);
+		if (is_unicast_ether_addr(parms->addr)) {
+			err = dev_uc_del(parms->dev, parms->addr);
 			if (!err)
-				err = qlcnic_nic_del_mac(adapter, addr);
-		} else if (is_multicast_ether_addr(addr)) {
-			err = dev_mc_del(netdev, addr);
+				err = qlcnic_nic_del_mac(adapter, parms->addr);
+		} else if (is_multicast_ether_addr(parms->addr)) {
+			err = dev_mc_del(parms->dev, parms->addr);
 		} else {
 			err =  -EINVAL;
 		}
@@ -392,15 +392,15 @@ static int qlcnic_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
 }
 
 static int qlcnic_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
-			struct net_device *netdev,
-			const unsigned char *addr, u16 vid, u16 flags,
-			bool *notified, struct netlink_ext_ack *extack)
+			const struct ndo_fdb_parms *parms, bool *notified,
+			struct netlink_ext_ack *extack)
 {
-	struct qlcnic_adapter *adapter = netdev_priv(netdev);
+	struct qlcnic_adapter *adapter = netdev_priv(parms->dev);
 	int err = 0;
 
 	if (!adapter->fdb_mac_learn)
-		return ndo_dflt_fdb_add(ndm, tb, netdev, addr, vid, flags);
+		return ndo_dflt_fdb_add(ndm, tb, parms->dev, parms->addr,
+					parms->vid, parms->flags);
 
 	if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED) &&
 	    !qlcnic_sriov_check(adapter)) {
@@ -408,16 +408,16 @@ static int qlcnic_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
 		return -EOPNOTSUPP;
 	}
 
-	if (ether_addr_equal(addr, adapter->mac_addr))
+	if (ether_addr_equal(parms->addr, adapter->mac_addr))
 		return err;
 
-	if (is_unicast_ether_addr(addr)) {
-		if (netdev_uc_count(netdev) < adapter->ahw->max_uc_count)
-			err = dev_uc_add_excl(netdev, addr);
+	if (is_unicast_ether_addr(parms->addr)) {
+		if (netdev_uc_count(parms->dev) < adapter->ahw->max_uc_count)
+			err = dev_uc_add_excl(parms->dev, parms->addr);
 		else
 			err = -ENOMEM;
-	} else if (is_multicast_ether_addr(addr)) {
-		err = dev_mc_add_excl(netdev, addr);
+	} else if (is_multicast_ether_addr(parms->addr)) {
+		err = dev_mc_add_excl(parms->dev, parms->addr);
 	} else {
 		err = -EINVAL;
 	}
drivers/net/macvlan.c +15 -18
index c7afa736c472..06079c697772 100644
@@ -1054,49 +1054,46 @@ static int macvlan_vlan_rx_kill_vid(struct net_device *dev,
 }
 
 static int macvlan_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
-			   struct net_device *dev,
-			   const unsigned char *addr, u16 vid,
-			   u16 flags, bool *notified,
+			   const struct ndo_fdb_parms *parms, bool *notified,
 			   struct netlink_ext_ack *extack)
 {
-	struct macvlan_dev *vlan = netdev_priv(dev);
+	struct macvlan_dev *vlan = netdev_priv(parms->dev);
 	int err = -EINVAL;
 
 	/* Support unicast filter only on passthru devices.
 	 * Multicast filter should be allowed on all devices.
 	 */
-	if (!macvlan_passthru(vlan->port) && is_unicast_ether_addr(addr))
+	if (!macvlan_passthru(vlan->port) && is_unicast_ether_addr(parms->addr))
 		return -EOPNOTSUPP;
 
-	if (flags & NLM_F_REPLACE)
+	if (parms->flags & NLM_F_REPLACE)
 		return -EOPNOTSUPP;
 
-	if (is_unicast_ether_addr(addr))
-		err = dev_uc_add_excl(dev, addr);
-	else if (is_multicast_ether_addr(addr))
-		err = dev_mc_add_excl(dev, addr);
+	if (is_unicast_ether_addr(parms->addr))
+		err = dev_uc_add_excl(parms->dev, parms->addr);
+	else if (is_multicast_ether_addr(parms->addr))
+		err = dev_mc_add_excl(parms->dev, parms->addr);
 
 	return err;
 }
 
 static int macvlan_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
-			   struct net_device *dev,
-			   const unsigned char *addr, u16 vid, bool *notified,
+			   const struct ndo_fdb_parms *parms, bool *notified,
 			   struct netlink_ext_ack *extack)
 {
-	struct macvlan_dev *vlan = netdev_priv(dev);
+	struct macvlan_dev *vlan = netdev_priv(parms->dev);
 	int err = -EINVAL;
 
 	/* Support unicast filter only on passthru devices.
 	 * Multicast filter should be allowed on all devices.
 	 */
-	if (!macvlan_passthru(vlan->port) && is_unicast_ether_addr(addr))
+	if (!macvlan_passthru(vlan->port) && is_unicast_ether_addr(parms->addr))
 		return -EOPNOTSUPP;
 
-	if (is_unicast_ether_addr(addr))
-		err = dev_uc_del(dev, addr);
-	else if (is_multicast_ether_addr(addr))
-		err = dev_mc_del(dev, addr);
+	if (is_unicast_ether_addr(parms->addr))
+		err = dev_uc_del(parms->dev, parms->addr);
+	else if (is_multicast_ether_addr(parms->addr))
+		err = dev_mc_del(parms->dev, parms->addr);
 
 	return err;
 }
drivers/net/vxlan/vxlan_core.c +12 -15
index d11028b37472..a9f6bdd52c12 100644
@@ -1241,12 +1241,11 @@ static int vxlan_fdb_parse(struct nlattr *tb[], struct vxlan_dev *vxlan,
 
 /* Add static entry (via netlink) */
 static int vxlan_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
-			 struct net_device *dev,
-			 const unsigned char *addr, u16 vid, u16 flags,
-			 bool *notified, struct netlink_ext_ack *extack)
+			 const struct ndo_fdb_parms *parms, bool *notified,
+			 struct netlink_ext_ack *extack)
 {
 	const struct vxlan_config *cfg;
-	struct vxlan_dev *vxlan = netdev_priv(dev);
+	struct vxlan_dev *vxlan = netdev_priv(parms->dev);
 	/* struct net *net = dev_net(vxlan->dev); */
 	union vxlan_addr ip;
 	__be16 port;
@@ -1273,7 +1272,8 @@ static int vxlan_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
 		return -EAFNOSUPPORT;
 
 	spin_lock_bh(&vxlan->hash_lock);
-	err = vxlan_fdb_update(vxlan, addr, &ip, ndm->ndm_state, flags,
+	err = vxlan_fdb_update(vxlan, parms->addr, &ip, ndm->ndm_state,
+			       parms->flags,
 			       port, src_vni, vni, ifindex,
 			       ndm->ndm_flags | NTF_VXLAN_ADDED_BY_USER,
 			       nhid, true, extack);
@@ -1320,11 +1320,10 @@ int __vxlan_fdb_delete(struct vxlan_dev *vxlan,
 
 /* Delete entry (via netlink) */
 static int vxlan_fdb_delete(struct ndmsg *ndm, struct nlattr *tb[],
-			    struct net_device *dev,
-			    const unsigned char *addr, u16 vid, bool *notified,
+			    const struct ndo_fdb_parms *parms, bool *notified,
 			    struct netlink_ext_ack *extack)
 {
-	struct vxlan_dev *vxlan = netdev_priv(dev);
+	struct vxlan_dev *vxlan = netdev_priv(parms->dev);
 	union vxlan_addr ip;
 	__be32 src_vni, vni;
 	u32 ifindex, nhid;
@@ -1337,8 +1336,8 @@ static int vxlan_fdb_delete(struct ndmsg *ndm, struct nlattr *tb[],
 		return err;
 
 	spin_lock_bh(&vxlan->hash_lock);
-	err = __vxlan_fdb_delete(vxlan, addr, ip, port, src_vni, vni, ifindex,
-				 true);
+	err = __vxlan_fdb_delete(vxlan, parms->addr, ip, port, src_vni, vni,
+				 ifindex, true);
 	spin_unlock_bh(&vxlan->hash_lock);
 
 	if (!err)
@@ -1400,12 +1399,10 @@ static int vxlan_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb,
 
 static int vxlan_fdb_get(struct sk_buff *skb,
 			 struct nlattr *tb[],
-			 struct net_device *dev,
-			 const unsigned char *addr,
-			 u16 vid, u32 portid, u32 seq,
+			 const struct ndo_fdb_parms *parms, u32 portid, u32 seq,
 			 struct netlink_ext_ack *extack)
 {
-	struct vxlan_dev *vxlan = netdev_priv(dev);
+	struct vxlan_dev *vxlan = netdev_priv(parms->dev);
 	const struct vxlan_config *cfg;
 	struct vxlan_fdb *f;
 	__be32 vni;
@@ -1420,7 +1417,7 @@ static int vxlan_fdb_get(struct sk_buff *skb,
 
 	rcu_read_lock();
 
-	f = vxlan_find_mac_rcu(vxlan, cfg, addr, vni);
+	f = vxlan_find_mac_rcu(vxlan, cfg, parms->addr, vni);
 	if (!f) {
 		NL_SET_ERR_MSG(extack, "Fdb entry not found");
 		err = -ENOENT;
include/linux/netdevice.h +22 -16
index 694b6d29f680..0bfd36057d3a 100644
@@ -1087,6 +1087,20 @@ struct netdev_net_notifier {
 	struct notifier_block *nb;
 };
 
+/**
+ * struct ndo_fdb_parms - parameters for ndo_fdb_{add,del,get}
+ * @dev: device the FDB entry is added to, deleted from or looked up on
+ * @addr: MAC address of the FDB entry
+ * @vid: VLAN ID of the FDB entry, 0 if none
+ * @flags: netlink message flags (NLM_F_*) of the request
+ */
+struct ndo_fdb_parms {
+	struct net_device	*dev;
+	const unsigned char	*addr;
+	u16			vid;
+	u16			flags;
+};
+
 /*
  * This structure defines the management hooks for network devices.
  * The following hooks can be defined; unless noted otherwise, they are
@@ -1330,17 +1344,15 @@ struct netdev_net_notifier {
  *	Must return >0 or -errno if it changed dev->features itself.
  *
  * int (*ndo_fdb_add)(struct ndmsg *ndm, struct nlattr *tb[],
- *		      struct net_device *dev,
- *		      const unsigned char *addr, u16 vid, u16 flags,
+ *		      const struct ndo_fdb_parms *parms,
  *		      bool *notified, struct netlink_ext_ack *extack);
- *	Adds an FDB entry to dev for addr.
+ *	Adds an FDB entry to parms->dev for parms->addr.
  *	Callee shall set *notified to true if it sent any appropriate
  *	notification(s). Otherwise core will send a generic one.
  * int (*ndo_fdb_del)(struct ndmsg *ndm, struct nlattr *tb[],
- *		      struct net_device *dev,
- *		      const unsigned char *addr, u16 vid
+ *		      const struct ndo_fdb_parms *parms,
  *		      bool *notified, struct netlink_ext_ack *extack);
- *	Deletes the FDB entry from dev corresponding to addr.
+ *	Deletes the FDB entry from parms->dev corresponding to parms->addr.
  *	Callee shall set *notified to true if it sent any appropriate
  *	notification(s). Otherwise core will send a generic one.
  * int (*ndo_fdb_del_bulk)(struct nlmsghdr *nlh, struct net_device *dev,
@@ -1614,17 +1626,12 @@ struct net_device_ops {
 
 	int			(*ndo_fdb_add)(struct ndmsg *ndm,
 					       struct nlattr *tb[],
-					       struct net_device *dev,
-					       const unsigned char *addr,
-					       u16 vid,
-					       u16 flags,
+					       const struct ndo_fdb_parms *parms,
 					       bool *notified,
 					       struct netlink_ext_ack *extack);
 	int			(*ndo_fdb_del)(struct ndmsg *ndm,
 					       struct nlattr *tb[],
-					       struct net_device *dev,
-					       const unsigned char *addr,
-					       u16 vid,
+					       const struct ndo_fdb_parms *parms,
 					       bool *notified,
 					       struct netlink_ext_ack *extack);
 	int			(*ndo_fdb_del_bulk)(struct nlmsghdr *nlh,
@@ -1637,9 +1644,8 @@ struct net_device_ops {
 						int *idx);
 	int			(*ndo_fdb_get)(struct sk_buff *skb,
 					       struct nlattr *tb[],
-					       struct net_device *dev,
-					       const unsigned char *addr,
-					       u16 vid, u32 portid, u32 seq,
+					       const struct ndo_fdb_parms *parms,
+					       u32 portid, u32 seq,
 					       struct netlink_ext_ack *extack);
 	int			(*ndo_mdb_add)(struct net_device *dev,
 					       struct nlattr *tb[],
net/bridge/br_fdb.c +34 -33

155 lines not on this page · raw message

net/bridge/br_private.h +7 -7
index 014d0b8db8c7..0062bbe94d1c 100644
@@ -1015,17 +1015,17 @@ void br_fdb_update(struct net_bridge *br, struct net_bridge_port *source,
 		   unsigned long flags);
 
 int br_fdb_delete(struct ndmsg *ndm, struct nlattr *tb[],
-		  struct net_device *dev, const unsigned char *addr, u16 vid,
-		  bool *notified, struct netlink_ext_ack *extack);
+		  const struct ndo_fdb_parms *parms, bool *notified,
+		  struct netlink_ext_ack *extack);
 int br_fdb_delete_bulk(struct nlmsghdr *nlh, struct net_device *dev,
 		       struct netlink_ext_ack *extack);
-int br_fdb_add(struct ndmsg *nlh, struct nlattr *tb[], struct net_device *dev,
-	       const unsigned char *addr, u16 vid, u16 nlh_flags,
-	       bool *notified, struct netlink_ext_ack *extack);
+int br_fdb_add(struct ndmsg *nlh, struct nlattr *tb[],
+	       const struct ndo_fdb_parms *parms, bool *notified,
+	       struct netlink_ext_ack *extack);
 int br_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb,
 		struct net_device *dev, struct net_device *fdev, int *idx);
-int br_fdb_get(struct sk_buff *skb, struct nlattr *tb[], struct net_device *dev,
-	       const unsigned char *addr, u16 vid, u32 portid, u32 seq,
+int br_fdb_get(struct sk_buff *skb, struct nlattr *tb[],
+	       const struct ndo_fdb_parms *parms, u32 portid, u32 seq,
 	       struct netlink_ext_ack *extack);
 int br_fdb_sync_static(struct net_bridge *br, struct net_bridge_port *p);
 void br_fdb_unsync_static(struct net_bridge *br, struct net_bridge_port *p);
net/core/rtnetlink.c +28 -9
index e141340172ce..b1649f1cb33a 100644
@@ -4814,6 +4814,7 @@ static int rtnl_fdb_add(struct sk_buff *skb, struct nlmsghdr *nlh,
 	struct net *net = sock_net(skb->sk);
 	struct ndmsg *ndm;
 	struct nlattr *tb[NDA_MAX+1];
+	struct ndo_fdb_parms parms;
 	struct net_device *dev;
 	u8 *addr;
 	u16 vid;
@@ -4852,6 +4853,13 @@ static int rtnl_fdb_add(struct sk_buff *skb, struct nlmsghdr *nlh,
 	if (err)
 		return err;
 
+	parms = (struct ndo_fdb_parms) {
+		.dev = dev,
+		.addr = addr,
+		.vid = vid,
+		.flags = nlh->nlmsg_flags,
+	};
+
 	err = -EOPNOTSUPP;
 
 	/* Support fdb on master device the net/bridge default case */
@@ -4861,8 +4869,7 @@ static int rtnl_fdb_add(struct sk_buff *skb, struct nlmsghdr *nlh,
 		const struct net_device_ops *ops = br_dev->netdev_ops;
 		bool notified = false;
 
-		err = ops->ndo_fdb_add(ndm, tb, dev, addr, vid,
-				       nlh->nlmsg_flags, &notified, extack);
+		err = ops->ndo_fdb_add(ndm, tb, &parms, &notified, extack);
 		if (err)
 			goto out;
 		else
@@ -4874,9 +4881,7 @@ static int rtnl_fdb_add(struct sk_buff *skb, struct nlmsghdr *nlh,
 		bool notified = false;
 
 		if (dev->netdev_ops->ndo_fdb_add)
-			err = dev->netdev_ops->ndo_fdb_add(ndm, tb, dev, addr,
-							   vid,
-							   nlh->nlmsg_flags,
+			err = dev->netdev_ops->ndo_fdb_add(ndm, tb, &parms,
 							   &notified, extack);
 		else
 			err = ndo_dflt_fdb_add(ndm, tb, dev, addr, vid,
@@ -4927,6 +4932,7 @@ static int rtnl_fdb_del(struct sk_buff *skb, struct nlmsghdr *nlh,
 	const struct net_device_ops *ops;
 	struct ndmsg *ndm;
 	struct nlattr *tb[NDA_MAX+1];
+	struct ndo_fdb_parms parms;
 	struct net_device *dev;
 	__u8 *addr = NULL;
 	int err;
@@ -4966,6 +4972,12 @@ static int rtnl_fdb_del(struct sk_buff *skb, struct nlmsghdr *nlh,
 		err = fdb_vid_parse(tb[NDA_VLAN], &vid, extack);
 		if (err)
 			return err;
+
+		parms = (struct ndo_fdb_parms) {
+			.dev = dev,
+			.addr = addr,
+			.vid = vid,
+		};
 	}
 
 	if (dev->type != ARPHRD_ETHER) {
@@ -4984,7 +4996,7 @@ static int rtnl_fdb_del(struct sk_buff *skb, struct nlmsghdr *nlh,
 		ops = br_dev->netdev_ops;
 		if (!del_bulk) {
 			if (ops->ndo_fdb_del)
-				err = ops->ndo_fdb_del(ndm, tb, dev, addr, vid,
+				err = ops->ndo_fdb_del(ndm, tb, &parms,
 						       &notified, extack);
 		} else {
 			if (ops->ndo_fdb_del_bulk)
@@ -5004,7 +5016,7 @@ static int rtnl_fdb_del(struct sk_buff *skb, struct nlmsghdr *nlh,
 		ops = dev->netdev_ops;
 		if (!del_bulk) {
 			if (ops->ndo_fdb_del)
-				err = ops->ndo_fdb_del(ndm, tb, dev, addr, vid,
+				err = ops->ndo_fdb_del(ndm, tb, &parms,
 						       &notified, extack);
 			else
 				err = ndo_dflt_fdb_del(ndm, tb, dev, addr, vid);
@@ -5327,6 +5339,7 @@ static int rtnl_fdb_get(struct sk_buff *in_skb, struct nlmsghdr *nlh,
 	const struct net_device_ops *ops = NULL;
 	struct net *net = sock_net(in_skb->sk);
 	struct nlattr *tb[NDA_MAX + 1];
+	struct ndo_fdb_parms parms;
 	struct sk_buff *skb;
 	int brport_idx = 0;
 	u8 ndm_flags = 0;
@@ -5404,8 +5417,14 @@ static int rtnl_fdb_get(struct sk_buff *in_skb, struct nlmsghdr *nlh,
 
 	if (br_dev)
 		dev = br_dev;
-	err = ops->ndo_fdb_get(skb, tb, dev, addr, vid,
-			       NETLINK_CB(in_skb).portid,
+
+	parms = (struct ndo_fdb_parms) {
+		.dev = dev,
+		.addr = addr,
+		.vid = vid,
+	};
+
+	err = ops->ndo_fdb_get(skb, tb, &parms, NETLINK_CB(in_skb).portid,
 			       nlh->nlmsg_seq, extack);
 	if (err)
 		goto out;
Signature · 1 line
2.56.1
#3 lore raw

PATCH 3/13 net: Pass portid to ndo_fdb_get through the structure

In reply to Petr Machata

So far, portid was passed as a separate argument to ndo_fdb_get. In order to get the portid parameter to ndo_fdb_add and _del, we'll be adding it to struct ndo_fdb_parms. That will make portid as an explicit argument redundant.

Make the move from argument to structure member for ndo_fdb_get now as a self-contained change. Proper support for ndo_fdb_add and _del will be done next.

---
 drivers/net/vxlan/vxlan_core.c | 4 ++--
 include/linux/netdevice.h      | 4 +++-
 net/bridge/br_fdb.c            | 5 ++---
 net/bridge/br_private.h        | 2 +-
 net/core/rtnetlink.c           | 4 ++--
 5 files changed, 10 insertions(+), 9 deletions(-)
drivers/net/vxlan/vxlan_core.c +2 -2
index a9f6bdd52c12..725c6216d56c 100644
@@ -1399,7 +1399,7 @@ static int vxlan_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb,
 
 static int vxlan_fdb_get(struct sk_buff *skb,
 			 struct nlattr *tb[],
-			 const struct ndo_fdb_parms *parms, u32 portid, u32 seq,
+			 const struct ndo_fdb_parms *parms, u32 seq,
 			 struct netlink_ext_ack *extack)
 {
 	struct vxlan_dev *vxlan = netdev_priv(parms->dev);
@@ -1424,7 +1424,7 @@ static int vxlan_fdb_get(struct sk_buff *skb,
 		goto errout;
 	}
 
-	err = vxlan_fdb_info(skb, vxlan, f, portid, seq,
+	err = vxlan_fdb_info(skb, vxlan, f, parms->portid, seq,
 			     RTM_NEWNEIGH, 0, first_remote_rcu(f));
 errout:
 	rcu_read_unlock();
include/linux/netdevice.h +3 -1
index 0bfd36057d3a..233584013fc9 100644
@@ -1093,12 +1093,14 @@ struct netdev_net_notifier {
  * @addr: MAC address of the FDB entry
  * @vid: VLAN ID of the FDB entry, 0 if none
  * @flags: netlink message flags (NLM_F_*) of the request
+ * @portid: netlink port ID of the requester
  */
 struct ndo_fdb_parms {
 	struct net_device	*dev;
 	const unsigned char	*addr;
 	u16			vid;
 	u16			flags;
+	u32			portid;
 };
 
 /*
@@ -1645,7 +1647,7 @@ struct net_device_ops {
 	int			(*ndo_fdb_get)(struct sk_buff *skb,
 					       struct nlattr *tb[],
 					       const struct ndo_fdb_parms *parms,
-					       u32 portid, u32 seq,
+					       u32 seq,
 					       struct netlink_ext_ack *extack);
 	int			(*ndo_mdb_add)(struct net_device *dev,
 					       struct nlattr *tb[],
net/bridge/br_fdb.c +2 -3
index 8ed7af3e410d..9e2fdcc5ca9b 100644
@@ -1146,7 +1146,7 @@ int br_fdb_dump(struct sk_buff *skb,
 
 int br_fdb_get(struct sk_buff *skb,
 	       struct nlattr *tb[],
-	       const struct ndo_fdb_parms *parms, u32 portid, u32 seq,
+	       const struct ndo_fdb_parms *parms, u32 seq,
 	       struct netlink_ext_ack *extack)
 {
 	struct net_bridge *br = netdev_priv(parms->dev);
@@ -1161,8 +1161,7 @@ int br_fdb_get(struct sk_buff *skb,
 		goto errout;
 	}
 
-	err = fdb_fill_info(skb, br, f, portid, seq,
-			    RTM_NEWNEIGH, 0);
+	err = fdb_fill_info(skb, br, f, parms->portid, seq, RTM_NEWNEIGH, 0);
 errout:
 	rcu_read_unlock();
 	return err;
net/bridge/br_private.h +1 -1
index 0062bbe94d1c..f4eaaff816b7 100644
@@ -1025,7 +1025,7 @@ int br_fdb_add(struct ndmsg *nlh, struct nlattr *tb[],
 int br_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb,
 		struct net_device *dev, struct net_device *fdev, int *idx);
 int br_fdb_get(struct sk_buff *skb, struct nlattr *tb[],
-	       const struct ndo_fdb_parms *parms, u32 portid, u32 seq,
+	       const struct ndo_fdb_parms *parms, u32 seq,
 	       struct netlink_ext_ack *extack);
 int br_fdb_sync_static(struct net_bridge *br, struct net_bridge_port *p);
 void br_fdb_unsync_static(struct net_bridge *br, struct net_bridge_port *p);
net/core/rtnetlink.c +2 -2
index e7d683952838..f31549923848 100644
@@ -5420,10 +5420,10 @@ static int rtnl_fdb_get(struct sk_buff *in_skb, struct nlmsghdr *nlh,
 		.dev = dev,
 		.addr = addr,
 		.vid = vid,
+		.portid = NETLINK_CB(in_skb).portid,
 	};
 
-	err = ops->ndo_fdb_get(skb, tb, &parms, NETLINK_CB(in_skb).portid,
-			       nlh->nlmsg_seq, extack);
+	err = ops->ndo_fdb_get(skb, tb, &parms, nlh->nlmsg_seq, extack);
 	if (err)
 		goto out;
 
Signature · 1 line
2.56.1
#2 lore raw

PATCH 2/13 net: Pass struct ndo_fdb_parms to ndo_dflt_fdb_{add, del}()

In reply to Petr Machata

The previous patch converted the ndo_fdb_add, ndo_fdb_del and ndo_fdb_get callbacks to take their common arguments through struct ndo_fdb_parms. The default implementations, ndo_dflt_fdb_add() and ndo_dflt_fdb_del(), are called from those callbacks in several drivers (igb, ixgbe, qlcnic) and from rtnl_fdb_add() and rtnl_fdb_del() as a fallback. These default implementations have not been converted, and callers must unpack individual arguments.

Convert the fallback functions to take the structure as well.

No functional change intended.

---
CC: Tony Nguyen <[email protected]>
CC: Przemek Kitszel <[email protected]>
CC: [email protected]
CC: Shahed Shaikh <[email protected]>
CC: Manish Chopra <[email protected]>
CC: [email protected]

---
 drivers/net/ethernet/intel/igb/igb_main.c     |  3 +-
 drivers/net/ethernet/intel/ixgbe/ixgbe_main.c |  3 +-
 .../net/ethernet/qlogic/qlcnic/qlcnic_main.c  |  6 +--
 include/linux/rtnetlink.h                     |  9 +---
 net/core/rtnetlink.c                          | 42 +++++++++----------
 5 files changed, 26 insertions(+), 37 deletions(-)
drivers/net/ethernet/intel/igb/igb_main.c +1 -2
index 42b2fd3ed95c..b2efa0a1fa07 100644
@@ -2531,8 +2531,7 @@ static int igb_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
 			return -ENOMEM;
 	}
 
-	return ndo_dflt_fdb_add(ndm, tb, parms->dev, parms->addr,
-				parms->vid, parms->flags);
+	return ndo_dflt_fdb_add(ndm, tb, parms);
 }
 
 #define IGB_MAX_MAC_HDR_LEN	127
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +1 -2
index 26d1a7253cf3..e444ebfe77fa 100644
@@ -10617,8 +10617,7 @@ static int ixgbe_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
 			return -ENOMEM;
 	}
 
-	return ndo_dflt_fdb_add(ndm, tb, parms->dev, parms->addr,
-				parms->vid, parms->flags);
+	return ndo_dflt_fdb_add(ndm, tb, parms);
 }
 
 /**
drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c +2 -4
index 85017de2161b..6c48cdaf25c0 100644
@@ -373,8 +373,7 @@ static int qlcnic_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
 	int err = -EOPNOTSUPP;
 
 	if (!adapter->fdb_mac_learn)
-		return ndo_dflt_fdb_del(ndm, tb, parms->dev, parms->addr,
-					parms->vid);
+		return ndo_dflt_fdb_del(ndm, tb, parms);
 
 	if ((adapter->flags & QLCNIC_ESWITCH_ENABLED) ||
 	    qlcnic_sriov_check(adapter)) {
@@ -399,8 +398,7 @@ static int qlcnic_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
 	int err = 0;
 
 	if (!adapter->fdb_mac_learn)
-		return ndo_dflt_fdb_add(ndm, tb, parms->dev, parms->addr,
-					parms->vid, parms->flags);
+		return ndo_dflt_fdb_add(ndm, tb, parms);
 
 	if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED) &&
 	    !qlcnic_sriov_check(adapter)) {
include/linux/rtnetlink.h +2 -7
index a54ec40d095c..e963b43bce76 100644
@@ -211,15 +211,10 @@ extern int ndo_dflt_fdb_dump(struct sk_buff *skb,
 			     int *idx);
 extern int ndo_dflt_fdb_add(struct ndmsg *ndm,
 			    struct nlattr *tb[],
-			    struct net_device *dev,
-			    const unsigned char *addr,
-			    u16 vid,
-			    u16 flags);
+			    const struct ndo_fdb_parms *parms);
 extern int ndo_dflt_fdb_del(struct ndmsg *ndm,
 			    struct nlattr *tb[],
-			    struct net_device *dev,
-			    const unsigned char *addr,
-			    u16 vid);
+			    const struct ndo_fdb_parms *parms);
 
 extern int ndo_dflt_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
 				   struct net_device *dev, u16 mode,
net/core/rtnetlink.c +20 -22

93 lines not on this page · raw message

Signature · 1 line
2.56.1
#4 lore raw

PATCH 4/13 net: bridge: Pass struct ndo_fdb_parms a bit further

In reply to Petr Machata

__br_fdb_add() and fdb_add_entry() take the FDB address, the netlink message flags and the VLAN ID as separate arguments. All of these are already available in struct ndo_fdb_parms, which br_fdb_add() receives from its caller. Just pass the structure instead.

__br_fdb_add() uses the passed-in vlan parameter to decode VID and passes that on to fdb_add_entry(). Instead, in br_fdb_add(), prime parms->vid to the right value, so that when __br_fdb_add() passes the parms structure through to fdb_add_entry(), the latter can just take the VID from there. This obeys the principle of least surprise: an add-like function that gets a parms structure has all add-like parameters properly initialized.

It would also be possible to pass struct ndo_fdb_parms to br_fdb_external_learn_add(), which would replace addr and vid now and portid later. But that function is also called from switchdev, where the appropriate structure would have to be created from scratch, which makes the benefit less clear. In the end, I left it out.

No functional change intended.

---
 net/bridge/br_fdb.c | 48 +++++++++++++++++++++++----------------------
 1 file changed, 25 insertions(+), 23 deletions(-)
net/bridge/br_fdb.c +25 -23
index 9e2fdcc5ca9b..45b844a9a1f6 100644
@@ -1209,7 +1209,7 @@ static bool fdb_update_dst(struct net_bridge_fdb_entry *fdb,
 
 /* Update (create or replace) forwarding database entry */
 static int fdb_add_entry(struct net_bridge *br, struct net_bridge_dst dst,
-			 const u8 *addr, struct ndmsg *ndm, u16 flags, u16 vid,
+			 struct ndmsg *ndm, const struct ndo_fdb_parms *parms,
 			 struct nlattr *nfea_tb[])
 {
 	struct net_bridge_port *source = br_dst_port(dst);
@@ -1242,12 +1242,12 @@ static int fdb_add_entry(struct net_bridge *br, struct net_bridge_dst dst,
 			return -EINVAL;
 	}
 
-	fdb = br_fdb_find(br, addr, vid);
+	fdb = br_fdb_find(br, parms->addr, parms->vid);
 	if (fdb == NULL) {
-		if (!(flags & NLM_F_CREATE))
+		if (!(parms->flags & NLM_F_CREATE))
 			return -ENOENT;
 
-		fdb = fdb_create(br, dst, addr, vid,
+		fdb = fdb_create(br, dst, parms->addr, parms->vid,
 				 BIT(BR_FDB_ADDED_BY_USER));
 		if (!fdb)
 			return -ENOMEM;
@@ -1256,7 +1256,7 @@ static int fdb_add_entry(struct net_bridge *br, struct net_bridge_dst dst,
 	} else {
 		struct net_bridge_dst old_dst;
 
-		if (flags & NLM_F_EXCL)
+		if (parms->flags & NLM_F_EXCL)
 			return -EEXIST;
 
 		old_dst = br_fdb_dst_read(fdb);
@@ -1271,15 +1271,15 @@ static int fdb_add_entry(struct net_bridge *br, struct net_bridge_dst dst,
 		if (state & NUD_PERMANENT) {
 			set_bit(BR_FDB_LOCAL, &fdb->flags);
 			if (!test_and_set_bit(BR_FDB_STATIC, &fdb->flags))
-				fdb_add_hw_addr(br, addr);
+				fdb_add_hw_addr(br, parms->addr);
 		} else if (state & NUD_NOARP) {
 			clear_bit(BR_FDB_LOCAL, &fdb->flags);
 			if (!test_and_set_bit(BR_FDB_STATIC, &fdb->flags))
-				fdb_add_hw_addr(br, addr);
+				fdb_add_hw_addr(br, parms->addr);
 		} else {
 			clear_bit(BR_FDB_LOCAL, &fdb->flags);
 			if (test_and_clear_bit(BR_FDB_STATIC, &fdb->flags))
-				fdb_del_hw_addr(br, addr);
+				fdb_del_hw_addr(br, parms->addr);
 		}
 
 		modified = true;
@@ -1307,12 +1307,11 @@ static int fdb_add_entry(struct net_bridge *br, struct net_bridge_dst dst,
 }
 
 static int __br_fdb_add(struct ndmsg *ndm, struct net_bridge *br,
-			struct net_bridge_port *p, const unsigned char *addr,
-			u16 nlh_flags, struct net_bridge_vlan *vlan,
-			struct nlattr *nfea_tb[],
+			struct net_bridge_port *p,
+			const struct ndo_fdb_parms *parms,
+			struct net_bridge_vlan *vlan, struct nlattr *nfea_tb[],
 			bool *notified, struct netlink_ext_ack *extack)
 {
-	u16 vid = vlan ? vlan->vid : 0;
 	struct net_bridge_dst dst;
 	int err = 0;
 
@@ -1327,7 +1326,8 @@ static int __br_fdb_add(struct ndmsg *ndm, struct net_bridge *br,
 
 		local_bh_disable();
 		rcu_read_lock();
-		br_fdb_update(br, p, vlan, addr, BIT(BR_FDB_ADDED_BY_USER));
+		br_fdb_update(br, p, vlan, parms->addr,
+			      BIT(BR_FDB_ADDED_BY_USER));
 		rcu_read_unlock();
 		local_bh_enable();
 	} else if (ndm->ndm_flags & NTF_EXT_LEARNED) {
@@ -1336,12 +1336,12 @@ static int __br_fdb_add(struct ndmsg *ndm, struct net_bridge *br,
 					   "FDB entry towards bridge must be permanent");
 			return -EINVAL;
 		}
-		err = br_fdb_external_learn_add(br, p, addr, vid, false, true);
+		err = br_fdb_external_learn_add(br, p, parms->addr, parms->vid,
+						false, true);
 	} else {
 		dst = p && vlan ? br_vlan_to_dst(vlan) : br_port_to_dst(p);
 		spin_lock_bh(&br->hash_lock);
-		err = fdb_add_entry(br, dst, addr, ndm, nlh_flags, vid,
-				    nfea_tb);
+		err = fdb_add_entry(br, dst, ndm, parms, nfea_tb);
 		spin_unlock_bh(&br->hash_lock);
 	}
 
@@ -1422,11 +1422,11 @@ int br_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
 		}
 
 		/* VID was specified, so use it. */
-		err = __br_fdb_add(ndm, br, p, parms->addr, parms->flags, v,
-				   nfea_tb, notified, extack);
+		err = __br_fdb_add(ndm, br, p, parms, v, nfea_tb, notified,
+				   extack);
 	} else {
-		err = __br_fdb_add(ndm, br, p, parms->addr, parms->flags,
-				   NULL, nfea_tb, notified, extack);
+		err = __br_fdb_add(ndm, br, p, parms, NULL, nfea_tb, notified,
+				   extack);
 		if (err || !vg || !vg->num_vlans)
 			goto out;
 
@@ -1435,11 +1435,13 @@ int br_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
 		 * vlan on this port.
 		 */
 		list_for_each_entry(v, &vg->vlan_list, vlist) {
+			struct ndo_fdb_parms vparms = *parms;
+
 			if (!br_vlan_should_use(v))
 				continue;
-			err = __br_fdb_add(ndm, br, p, parms->addr,
-					   parms->flags, v, nfea_tb, notified,
-					   extack);
+			vparms.vid = v->vid;
+			err = __br_fdb_add(ndm, br, p, &vparms, v, nfea_tb,
+					   notified, extack);
 			if (err)
 				goto out;
 		}
Signature · 1 line
2.56.1
#7 lore raw

PATCH 7/13 net: rtnetlink: Report port ID in bridge and VXLAN FDB notifications

In reply to Petr Machata

Commit 7b8f7a402d4c ("neighbour: fix nlmsg_pid in notifications") made neighbour notifications carry the netlink port ID of the process that triggered them in nlmsg_pid. Similarly route and nexthop update notifications carry the port ID. This allows applications to tell their own changes apart from those made by someone else. For notifications related to FDB entries, port ID is currently always zero, which makes this sort of notification filtering impossible.

After the preceding patches, port ID is available for bridge and VXLAN to use by way of the struct ndo_fdb_parms' portid field, and the two drivers pass the value through to the notifications. The field itself however has so far been not initialized by rtnl_fdb_add() and rtnl_fdb_del().

In this patch do that. With that, the RTM_NEWNEIGH and RTM_DELNEIGH notifications that bridge and VXLAN FDB send carry the port ID. Notifications that are not a result of a netlink request, such as those for learning, aging, or switchdev events, still carry zero.

Bulk deletion (flush) goes through ndo_fdb_del_bulk instead, and is converted in a separate patch.

Drivers other than bridge and VXLAN, which implement ndo_fdb_add and ndo_fdb_del but fall back to the default implementations, still report zero as well. That also is converted in a later patch.

---
 net/core/rtnetlink.c | 3 +++
 1 file changed, 3 insertions(+)
net/core/rtnetlink.c +3 -0
index f31549923848..e0d411c251aa 100644
@@ -4857,6 +4857,7 @@ static int rtnl_fdb_add(struct sk_buff *skb, struct nlmsghdr *nlh,
 		.addr = addr,
 		.vid = vid,
 		.flags = nlh->nlmsg_flags,
+		.portid = NETLINK_CB(skb).portid,
 	};
 
 	err = -EOPNOTSUPP;
@@ -4927,6 +4928,7 @@ static int rtnl_fdb_del(struct sk_buff *skb, struct nlmsghdr *nlh,
 {
 	bool del_bulk = !!(nlh->nlmsg_flags & NLM_F_BULK);
 	struct net *net = sock_net(skb->sk);
+	u32 portid = NETLINK_CB(skb).portid;
 	const struct net_device_ops *ops;
 	struct ndmsg *ndm;
 	struct nlattr *tb[NDA_MAX+1];
@@ -4975,6 +4977,7 @@ static int rtnl_fdb_del(struct sk_buff *skb, struct nlmsghdr *nlh,
 			.dev = dev,
 			.addr = addr,
 			.vid = vid,
+			.portid = portid,
 		};
 	}
 
Signature · 1 line
2.56.1
#8 lore raw

PATCH 8/13 net: rtnetlink: Report port ID in bulk FDB delete notifications

In reply to Petr Machata

The previous patch made the notifications resulting from adding, replacing and deleting bridge and VXLAN FDB entries carry the port ID of the requester in nlmsg_pid. Bulk deletion (flush) does not go through ndo_fdb_del, and thus does not take struct ndo_fdb_parms, but goes through ndo_fdb_del_bulk instead, and still reports zero.

Add a port ID argument to ndo_fdb_del_bulk, and pass the port ID of the requester from rtnl_fdb_del(). The bridge and VXLAN implementations pass it on to the flush helpers, which already know how to use it.

---
 drivers/net/vxlan/vxlan_core.c | 4 ++--
 include/linux/netdevice.h      | 3 ++-
 net/bridge/br_fdb.c            | 4 ++--
 net/bridge/br_private.h        | 2 +-
 net/core/rtnetlink.c           | 6 ++++--
 5 files changed, 11 insertions(+), 8 deletions(-)
drivers/net/vxlan/vxlan_core.c +2 -2
index a010eb8f7f28..c300e0bd9b57 100644
@@ -3208,7 +3208,7 @@ static const struct nla_policy vxlan_del_bulk_policy[NDA_MAX + 1] = {
 					   NTF_ROUTER)
 
 static int vxlan_fdb_delete_bulk(struct nlmsghdr *nlh, struct net_device *dev,
-				 struct netlink_ext_ack *extack)
+				 u32 portid, struct netlink_ext_ack *extack)
 {
 	struct vxlan_dev *vxlan = netdev_priv(dev);
 	struct vxlan_fdb_flush_desc desc = {};
@@ -3266,7 +3266,7 @@ static int vxlan_fdb_delete_bulk(struct nlmsghdr *nlh, struct net_device *dev,
 		desc.dst_ip = ip;
 	}
 
-	vxlan_flush(vxlan, &desc, 0);
+	vxlan_flush(vxlan, &desc, portid);
 
 	return 0;
 }
include/linux/netdevice.h +2 -1
index 233584013fc9..b2846b586a7f 100644
@@ -1358,7 +1358,7 @@ struct ndo_fdb_parms {
  *	Callee shall set *notified to true if it sent any appropriate
  *	notification(s). Otherwise core will send a generic one.
  * int (*ndo_fdb_del_bulk)(struct nlmsghdr *nlh, struct net_device *dev,
- *			   struct netlink_ext_ack *extack);
+ *			   u32 portid, struct netlink_ext_ack *extack);
  * int (*ndo_fdb_dump)(struct sk_buff *skb, struct netlink_callback *cb,
  *		       struct net_device *dev, struct net_device *filter_dev,
  *		       int *idx)
@@ -1638,6 +1638,7 @@ struct net_device_ops {
 					       struct netlink_ext_ack *extack);
 	int			(*ndo_fdb_del_bulk)(struct nlmsghdr *nlh,
 						    struct net_device *dev,
+						    u32 portid,
 						    struct netlink_ext_ack *extack);
 	int			(*ndo_fdb_dump)(struct sk_buff *skb,
 						struct netlink_callback *cb,
net/bridge/br_fdb.c +2 -2
index 3712e6db90f0..6b1c067974ff 100644
@@ -797,7 +797,7 @@ static const struct nla_policy br_fdb_del_bulk_policy[NDA_MAX + 1] = {
 };
 
 int br_fdb_delete_bulk(struct nlmsghdr *nlh, struct net_device *dev,
-		       struct netlink_ext_ack *extack)
+		       u32 portid, struct netlink_ext_ack *extack)
 {
 	struct net_bridge_fdb_flush_desc desc = {};
 	struct ndmsg *ndm = nlmsg_data(nlh);
@@ -864,7 +864,7 @@ int br_fdb_delete_bulk(struct nlmsghdr *nlh, struct net_device *dev,
 	br_debug(br, "flushing port ifindex: %d vlan id: %u flags: 0x%lx flags mask: 0x%lx\n",
 		 desc.port_ifindex, desc.vlan_id, desc.flags, desc.flags_mask);
 
-	br_fdb_flush(br, &desc, 0);
+	br_fdb_flush(br, &desc, portid);
 
 	return 0;
 }
net/bridge/br_private.h +1 -1
index 67e3288b1e40..83f2b7728947 100644
@@ -1018,7 +1018,7 @@ int br_fdb_delete(struct ndmsg *ndm, struct nlattr *tb[],
 		  const struct ndo_fdb_parms *parms, bool *notified,
 		  struct netlink_ext_ack *extack);
 int br_fdb_delete_bulk(struct nlmsghdr *nlh, struct net_device *dev,
-		       struct netlink_ext_ack *extack);
+		       u32 portid, struct netlink_ext_ack *extack);
 int br_fdb_add(struct ndmsg *nlh, struct nlattr *tb[],
 	       const struct ndo_fdb_parms *parms, bool *notified,
 	       struct netlink_ext_ack *extack);
net/core/rtnetlink.c +4 -2
index e0d411c251aa..e1607a3232c7 100644
@@ -5001,7 +5001,8 @@ static int rtnl_fdb_del(struct sk_buff *skb, struct nlmsghdr *nlh,
 						       &notified, extack);
 		} else {
 			if (ops->ndo_fdb_del_bulk)
-				err = ops->ndo_fdb_del_bulk(nlh, dev, extack);
+				err = ops->ndo_fdb_del_bulk(nlh, dev, portid,
+							    extack);
 		}
 
 		if (err)
@@ -5025,7 +5026,8 @@ static int rtnl_fdb_del(struct sk_buff *skb, struct nlmsghdr *nlh,
 			/* in case err was cleared by NTF_MASTER call */
 			err = -EOPNOTSUPP;
 			if (ops->ndo_fdb_del_bulk)
-				err = ops->ndo_fdb_del_bulk(nlh, dev, extack);
+				err = ops->ndo_fdb_del_bulk(nlh, dev, portid,
+							    extack);
 		}
 
 		if (!err) {
Signature · 1 line
2.56.1
#5 lore raw

PATCH 5/13 net: bridge: Pass portid through FDB notifications

In reply to Petr Machata

Add a portid argument to fdb_notify(), fdb_delete(), br_fdb_flush(), fdb_delete_by_addr_and_port(), __br_fdb_delete() and br_fdb_external_learn_add(), and use it for the issued RTM_NEWNEIGH / RTM_DELNEIGH notifications.

Rename br_fdb_update() to __br_fdb_update() and add the portid argument to that, converting internal callers. br_fdb_update() then becomes a thin wrapper that just passes zero for portid and retains the prototype for external callers.

br_fdb_add() and br_fdb_delete() pass on the port ID of the requester. All other callers (learning, aging, switchdev events, sysfs and IFLA_BR_FDB_FLUSH handling, as well as br_fdb_delete_bulk()) pass zero, as before.

As rtnl_fdb_add() and rtnl_fdb_del() do not yet fill in the port ID in struct ndo_fdb_parms, all notifications are still sent with zero. No functional change intended.

---
 net/bridge/br.c          |  2 +-
 net/bridge/br_fdb.c      | 83 +++++++++++++++++++++++-----------------
 net/bridge/br_netlink.c  |  4 +-
 net/bridge/br_private.h  |  4 +-
 net/bridge/br_sysfs_br.c |  2 +-
 5 files changed, 54 insertions(+), 41 deletions(-)
net/bridge/br.c +1 -1
index d9a39ff98868..76feb286acab 100644
@@ -177,7 +177,7 @@ static int br_switchdev_event(struct notifier_block *unused,
 		fdb_info = ptr;
 		err = br_fdb_external_learn_add(br, p, fdb_info->addr,
 						fdb_info->vid,
-						fdb_info->locked, false);
+						fdb_info->locked, 0, false);
 		if (err) {
 			err = notifier_from_errno(err);
 			break;
net/bridge/br_fdb.c +48 -35

272 lines not on this page · raw message

net/bridge/br_netlink.c +2 -2
index 79c4a54990e2..0a1dd507bbff 100644
@@ -1001,7 +1001,7 @@ static int br_setport(struct net_bridge_port *p, struct nlattr *tb[],
 			.port_ifindex = p->dev->ifindex,
 		};
 
-		br_fdb_flush(p->br, &desc);
+		br_fdb_flush(p->br, &desc, 0);
 	}
 
 	changed_mask = old_flags ^ flags;
@@ -1431,7 +1431,7 @@ static int br_changelink(struct net_device *brdev, struct nlattr *tb[],
 			.flags_mask = BIT(BR_FDB_STATIC)
 		};
 
-		br_fdb_flush(br, &desc);
+		br_fdb_flush(br, &desc, 0);
 	}
 
 #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
net/bridge/br_private.h +2 -2
index f4eaaff816b7..67e3288b1e40 100644
@@ -992,7 +992,7 @@ void br_fdb_fini(void);
 int br_fdb_hash_init(struct net_bridge *br);
 void br_fdb_hash_fini(struct net_bridge *br);
 void br_fdb_flush(struct net_bridge *br,
-		  const struct net_bridge_fdb_flush_desc *desc);
+		  const struct net_bridge_fdb_flush_desc *desc, u32 portid);
 void br_fdb_find_delete_local(struct net_bridge *br,
 			      const struct net_bridge_port *p,
 			      const unsigned char *addr, u16 vid);
@@ -1031,7 +1031,7 @@ int br_fdb_sync_static(struct net_bridge *br, struct net_bridge_port *p);
 void br_fdb_unsync_static(struct net_bridge *br, struct net_bridge_port *p);
 int br_fdb_external_learn_add(struct net_bridge *br, struct net_bridge_port *p,
 			      const unsigned char *addr, u16 vid,
-			      bool locked, bool swdev_notify);
+			      bool locked, u32 portid, bool swdev_notify);
 int br_fdb_external_learn_del(struct net_bridge *br, struct net_bridge_port *p,
 			      const unsigned char *addr, u16 vid,
 			      bool swdev_notify);
net/bridge/br_sysfs_br.c +1 -1
index d2993f187f57..3a05764e607a 100644
@@ -349,7 +349,7 @@ static int set_flush(struct net_bridge *br, unsigned long val,
 		.flags_mask = BIT(BR_FDB_STATIC)
 	};
 
-	br_fdb_flush(br, &desc);
+	br_fdb_flush(br, &desc, 0);
 	return 0;
 }
 
Signature · 1 line
2.56.1
#6 lore raw

PATCH 6/13 net: vxlan: Pass portid through FDB notifications

In reply to Petr Machata

Add a portid argument to __vxlan_fdb_notify(), vxlan_fdb_notify(), vxlan_fdb_destroy(), vxlan_fdb_dst_destroy(), vxlan_fdb_update() and its _existing() and _create() helpers, __vxlan_fdb_delete(), vxlan_flush() and vxlan_fdb_flush_match_remotes(), and use it as the netlink port ID of the resulting RTM_NEWNEIGH / RTM_DELNEIGH notifications. Where both portid and swdev_notify are passed, portid comes first: it is part of the message metadata, similarly to the message type, whereas swdev_notify merely toggles whether the switchdev notifiers are called.

vxlan_fdb_add() and vxlan_fdb_delete() pass on the port ID of the requester. All other callers (snooping, device stop, changelink, VNI filtering, switchdev events, as well as vxlan_fdb_delete_bulk()) pass zero, as before.

As rtnl_fdb_add() and rtnl_fdb_del() do not yet fill in the port ID in struct ndo_fdb_parms, all notifications are still sent with zero. No functional change intended.

I considered passing struct ndo_fdb_parms down to vxlan_fdb_update() instead of the individual address and flags, but eventually decided against that. Only vxlan_fdb_add() has the structure at hand, whereas the other callers would have to construct a throwaway one just to pass the address and flags. This makes them longer, not shorter, and the callee would still need most of the VXLAN-specific arguments separately.

Packing the VXLAN-specific parameters (remote IP, port, VNI, ifindex, ...) into a dedicated VXLAN-specific structure might benefit the VXLAN driver in a similar way to how it cleaned up the NDO interface. However this was left out for potential future patchset.

---
 drivers/net/vxlan/vxlan_core.c      | 89 +++++++++++++++--------------
 drivers/net/vxlan/vxlan_private.h   |  5 +-
 drivers/net/vxlan/vxlan_vnifilter.c |  6 +-
 3 files changed, 52 insertions(+), 48 deletions(-)
drivers/net/vxlan/vxlan_core.c +46 -43
index 725c6216d56c..a010eb8f7f28 100644
@@ -265,7 +265,7 @@ static inline size_t vxlan_nlmsg_size(void)
 }
 
 static void __vxlan_fdb_notify(struct vxlan_dev *vxlan, struct vxlan_fdb *fdb,
-			       struct vxlan_rdst *rd, int type)
+			       struct vxlan_rdst *rd, int type, u32 portid)
 {
 	struct net *net = dev_net(vxlan->dev);
 	struct sk_buff *skb;
@@ -275,7 +275,7 @@ static void __vxlan_fdb_notify(struct vxlan_dev *vxlan, struct vxlan_fdb *fdb,
 	if (skb == NULL)
 		goto errout;
 
-	err = vxlan_fdb_info(skb, vxlan, fdb, 0, 0, type, 0, rd);
+	err = vxlan_fdb_info(skb, vxlan, fdb, portid, 0, type, 0, rd);
 	if (err < 0) {
 		/* -EMSGSIZE implies BUG in vxlan_nlmsg_size() */
 		WARN_ON(err == -EMSGSIZE);
@@ -329,8 +329,8 @@ static int vxlan_fdb_switchdev_call_notifiers(struct vxlan_dev *vxlan,
 }
 
 static int vxlan_fdb_notify(struct vxlan_dev *vxlan, struct vxlan_fdb *fdb,
-			    struct vxlan_rdst *rd, int type, bool swdev_notify,
-			    struct netlink_ext_ack *extack)
+			    struct vxlan_rdst *rd, int type, u32 portid,
+			    bool swdev_notify, struct netlink_ext_ack *extack)
 {
 	int err;
 
@@ -349,7 +349,7 @@ static int vxlan_fdb_notify(struct vxlan_dev *vxlan, struct vxlan_fdb *fdb,
 		}
 	}
 
-	__vxlan_fdb_notify(vxlan, fdb, rd, type);
+	__vxlan_fdb_notify(vxlan, fdb, rd, type, portid);
 	return 0;
 }
 
@@ -364,7 +364,7 @@ static void vxlan_ip_miss(struct net_device *dev, union vxlan_addr *ipa)
 		.remote_vni = cpu_to_be32(VXLAN_N_VID),
 	};
 
-	vxlan_fdb_notify(vxlan, &f, &remote, RTM_GETNEIGH, true, NULL);
+	vxlan_fdb_notify(vxlan, &f, &remote, RTM_GETNEIGH, 0, true, NULL);
 }
 
 static void vxlan_fdb_miss(struct vxlan_dev *vxlan, const u8 eth_addr[ETH_ALEN])
@@ -376,7 +376,7 @@ static void vxlan_fdb_miss(struct vxlan_dev *vxlan, const u8 eth_addr[ETH_ALEN])
 
 	memcpy(f.key.eth_addr, eth_addr, ETH_ALEN);
 
-	vxlan_fdb_notify(vxlan, &f, &remote, RTM_GETNEIGH, true, NULL);
+	vxlan_fdb_notify(vxlan, &f, &remote, RTM_GETNEIGH, 0, true, NULL);
 }
 
 /* Look up Ethernet address in forwarding table */
@@ -945,7 +945,7 @@ static void vxlan_fdb_free(struct rcu_head *head)
 }
 
 static void vxlan_fdb_destroy(struct vxlan_dev *vxlan, struct vxlan_fdb *f,
-			      bool do_notify, bool swdev_notify)
+			      bool do_notify, u32 portid, bool swdev_notify)
 {
 	struct vxlan_rdst *rd;
 
@@ -955,11 +955,11 @@ static void vxlan_fdb_destroy(struct vxlan_dev *vxlan, struct vxlan_fdb *f,
 	if (do_notify) {
 		if (rcu_access_pointer(f->nh))
 			vxlan_fdb_notify(vxlan, f, NULL, RTM_DELNEIGH,
-					 swdev_notify, NULL);
+					 portid, swdev_notify, NULL);
 		else
 			list_for_each_entry(rd, &f->remotes, list)
 				vxlan_fdb_notify(vxlan, f, rd, RTM_DELNEIGH,
-						 swdev_notify, NULL);
+						 portid, swdev_notify, NULL);
 	}
 
 	hlist_del_init_rcu(&f->fdb_node);
@@ -983,7 +983,7 @@ static int vxlan_fdb_update_existing(struct vxlan_dev *vxlan,
 				     __be16 port, __be32 vni,
 				     __u32 ifindex, __u16 ndm_flags,
 				     struct vxlan_fdb *f, u32 nhid,
-				     bool swdev_notify,
+				     u32 portid, bool swdev_notify,
 				     struct netlink_ext_ack *extack)
 {
 	__u16 fdb_flags = (ndm_flags & ~NTF_USE);
@@ -1057,7 +1057,7 @@ static int vxlan_fdb_update_existing(struct vxlan_dev *vxlan,
 
 		WRITE_ONCE(f->updated, jiffies);
 		err = vxlan_fdb_notify(vxlan, f, rd, RTM_NEWNEIGH,
-				       swdev_notify, extack);
+				       portid, swdev_notify, extack);
 		if (err)
 			goto err_notify;
 	}
@@ -1081,7 +1081,7 @@ static int vxlan_fdb_update_create(struct vxlan_dev *vxlan,
 				   __u16 state, __u16 flags,
 				   __be16 port, __be32 src_vni, __be32 vni,
 				   __u32 ifindex, __u16 ndm_flags, u32 nhid,
-				   bool swdev_notify,
+				   u32 portid, bool swdev_notify,
 				   struct netlink_ext_ack *extack)
 {
 	__u16 fdb_flags = (ndm_flags & ~NTF_USE);
@@ -1100,14 +1100,14 @@ static int vxlan_fdb_update_create(struct vxlan_dev *vxlan,
 		return rc;
 
 	rc = vxlan_fdb_notify(vxlan, f, first_remote_rtnl(f), RTM_NEWNEIGH,
-			      swdev_notify, extack);
+			      portid, swdev_notify, extack);
 	if (rc)
 		goto err_notify;
 
 	return 0;
 
 err_notify:
-	vxlan_fdb_destroy(vxlan, f, false, false);
+	vxlan_fdb_destroy(vxlan, f, false, 0, false);
 	return rc;
 }
 
@@ -1117,7 +1117,7 @@ int vxlan_fdb_update(struct vxlan_dev *vxlan,
 		     __u16 state, __u16 flags,
 		     __be16 port, __be32 src_vni, __be32 vni,
 		     __u32 ifindex, __u16 ndm_flags, u32 nhid,
-		     bool swdev_notify,
+		     u32 portid, bool swdev_notify,
 		     struct netlink_ext_ack *extack)
 {
 	struct vxlan_fdb *f;
@@ -1132,23 +1132,26 @@ int vxlan_fdb_update(struct vxlan_dev *vxlan,
 
 		return vxlan_fdb_update_existing(vxlan, ip, state, flags, port,
 						 vni, ifindex, ndm_flags, f,
-						 nhid, swdev_notify, extack);
+						 nhid, portid, swdev_notify,
+						 extack);
 	} else {
 		if (!(flags & NLM_F_CREATE))
 			return -ENOENT;
 
 		return vxlan_fdb_update_create(vxlan, mac, ip, state, flags,
 					       port, src_vni, vni, ifindex,
-					       ndm_flags, nhid, swdev_notify,
-					       extack);
+					       ndm_flags, nhid, portid,
+					       swdev_notify, extack);
 	}
 }
 
 static void vxlan_fdb_dst_destroy(struct vxlan_dev *vxlan, struct vxlan_fdb *f,
-				  struct vxlan_rdst *rd, bool swdev_notify)
+				  struct vxlan_rdst *rd, u32 portid,
+				  bool swdev_notify)
 {
 	list_del_rcu(&rd->list);
-	vxlan_fdb_notify(vxlan, f, rd, RTM_DELNEIGH, swdev_notify, NULL);
+	vxlan_fdb_notify(vxlan, f, rd, RTM_DELNEIGH, portid, swdev_notify,
+			 NULL);
 	call_rcu(&rd->rcu, vxlan_dst_free);
 }
 
@@ -1276,7 +1279,7 @@ static int vxlan_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
 			       parms->flags,
 			       port, src_vni, vni, ifindex,
 			       ndm->ndm_flags | NTF_VXLAN_ADDED_BY_USER,
-			       nhid, true, extack);
+			       nhid, parms->portid, true, extack);
 	spin_unlock_bh(&vxlan->hash_lock);
 
 	if (!err)
@@ -1288,7 +1291,7 @@ static int vxlan_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
 int __vxlan_fdb_delete(struct vxlan_dev *vxlan,
 		       const unsigned char *addr, union vxlan_addr ip,
 		       __be16 port, __be32 src_vni, __be32 vni,
-		       u32 ifindex, bool swdev_notify)
+		       u32 ifindex, u32 portid, bool swdev_notify)
 {
 	struct vxlan_rdst *rd = NULL;
 	struct vxlan_fdb *f;
@@ -1308,11 +1311,11 @@ int __vxlan_fdb_delete(struct vxlan_dev *vxlan,
 	 * otherwise destroy the fdb entry
 	 */
 	if (rd && !list_is_singular(&f->remotes)) {
-		vxlan_fdb_dst_destroy(vxlan, f, rd, swdev_notify);
+		vxlan_fdb_dst_destroy(vxlan, f, rd, portid, swdev_notify);
 		goto out;
 	}
 
-	vxlan_fdb_destroy(vxlan, f, true, swdev_notify);
+	vxlan_fdb_destroy(vxlan, f, true, portid, swdev_notify);
 
 out:
 	return 0;
@@ -1337,7 +1340,7 @@ static int vxlan_fdb_delete(struct ndmsg *ndm, struct nlattr *tb[],
 
 	spin_lock_bh(&vxlan->hash_lock);
 	err = __vxlan_fdb_delete(vxlan, parms->addr, ip, port, src_vni, vni,
-				 ifindex, true);
+				 ifindex, parms->portid, true);
 	spin_unlock_bh(&vxlan->hash_lock);
 
 	if (!err)
@@ -1480,7 +1483,7 @@ static enum skb_drop_reason vxlan_snoop(struct net_device *dev,
 				    src_mac, &rdst->remote_ip.sa, &src_ip->sa);
 
 		rdst->remote_ip = *src_ip;
-		vxlan_fdb_notify(vxlan, f, rdst, RTM_NEWNEIGH, true, NULL);
+		vxlan_fdb_notify(vxlan, f, rdst, RTM_NEWNEIGH, 0, true, NULL);
 	} else {
 		/* learned new entry */
 		spin_lock(&vxlan->hash_lock);
@@ -1493,7 +1496,7 @@ static enum skb_drop_reason vxlan_snoop(struct net_device *dev,
 					 cfg->dst_port,
 					 vni,
 					 cfg->vni,
-					 ifindex, NTF_SELF, 0, true, NULL);
+					 ifindex, NTF_SELF, 0, 0, true, NULL);
 		spin_unlock(&vxlan->hash_lock);
 	}
 
@@ -2943,7 +2946,7 @@ static void vxlan_cleanup(struct timer_list *t)
 				netdev_dbg(vxlan->dev, "garbage collect %pM\n",
 					   f->key.eth_addr);
 				f->state = NUD_STALE;
-				vxlan_fdb_destroy(vxlan, f, true, true);
+				vxlan_fdb_destroy(vxlan, f, true, 0, true);
 			}
 			spin_unlock(&vxlan->hash_lock);
 		} else if (time_before(timeout, next_timer)) {
@@ -3138,7 +3141,7 @@ vxlan_fdb_flush_remote_matches(const struct vxlan_fdb_flush_desc *desc,
 static void
 vxlan_fdb_flush_match_remotes(struct vxlan_fdb *f, struct vxlan_dev *vxlan,
 			      const struct vxlan_fdb_flush_desc *desc,
-			      bool *p_destroy_fdb)
+			      u32 portid, bool *p_destroy_fdb)
 {
 	struct vxlan_rdst *rd, *tmp;
 
@@ -3151,13 +3154,13 @@ vxlan_fdb_flush_match_remotes(struct vxlan_fdb *f, struct vxlan_dev *vxlan,
 			return;
 		}
 
-		vxlan_fdb_dst_destroy(vxlan, f, rd, true);
+		vxlan_fdb_dst_destroy(vxlan, f, rd, portid, true);
 	}
 }
 
 /* Purge the forwarding table */
 static void vxlan_flush(struct vxlan_dev *vxlan,
-			const struct vxlan_fdb_flush_desc *desc)
+			const struct vxlan_fdb_flush_desc *desc, u32 portid)
 {
 	bool match_remotes = vxlan_fdb_flush_should_match_remotes(desc);
 	struct vxlan_fdb *f;
@@ -3174,14 +3177,14 @@ static void vxlan_flush(struct vxlan_dev *vxlan,
 		if (match_remotes) {
 			bool destroy_fdb = false;
 
-			vxlan_fdb_flush_match_remotes(f, vxlan, desc,
+			vxlan_fdb_flush_match_remotes(f, vxlan, desc, portid,
 						      &destroy_fdb);
 
 			if (!destroy_fdb)
 				goto unlock;
 		}
 
-		vxlan_fdb_destroy(vxlan, f, true, true);
+		vxlan_fdb_destroy(vxlan, f, true, portid, true);
 unlock:
 		spin_unlock_bh(&vxlan->hash_lock);
 	}
@@ -3263,7 +3266,7 @@ static int vxlan_fdb_delete_bulk(struct nlmsghdr *nlh, struct net_device *dev,
 		desc.dst_ip = ip;
 	}
 
-	vxlan_flush(vxlan, &desc);
+	vxlan_flush(vxlan, &desc, 0);
 
 	return 0;
 }
@@ -3283,7 +3286,7 @@ static int vxlan_stop(struct net_device *dev)
 
 	timer_delete_sync(&vxlan->age_timer);
 
-	vxlan_flush(vxlan, &desc);
+	vxlan_flush(vxlan, &desc, 0);
 	vxlan_sock_release(vxlan);
 
 	return 0;
@@ -4143,7 +4146,7 @@ static int vxlan_dev_create(struct net *net, struct net_device *dev,
 				       cfg->vni,
 				       cfg->vni,
 				       cfg->remote_ifindex,
-				       NTF_SELF, 0, true, extack);
+				       NTF_SELF, 0, 0, true, extack);
 		spin_unlock_bh(&vxlan->hash_lock);
 		if (err)
 			goto unlink;
@@ -4606,7 +4609,7 @@ static int vxlan_changelink(struct net_device *dev, struct nlattr *tb[],
 					       cfg->dst_port,
 					       conf.vni, conf.vni,
 					       conf.remote_ifindex,
-					       NTF_SELF, 0, true, extack);
+					       NTF_SELF, 0, 0, true, extack);
 			if (err) {
 				spin_unlock_bh(&vxlan->hash_lock);
 				if (lowerdev_changed)
@@ -4623,7 +4626,7 @@ static int vxlan_changelink(struct net_device *dev, struct nlattr *tb[],
 					   cfg->vni,
 					   cfg->vni,
 					   cfg->remote_ifindex,
-					   true);
+					   0, true);
 		spin_unlock_bh(&vxlan->hash_lock);
 
 		/* If vni filtering device, also update default fdb entries of
@@ -4687,7 +4690,7 @@ static void vxlan_dellink(struct net_device *dev, struct list_head *head)
 	struct vxlan_dev *vxlan = netdev_priv(dev);
 	struct vxlan_fdb_flush_desc desc = {};
 
-	vxlan_flush(vxlan, &desc);
+	vxlan_flush(vxlan, &desc, 0);
 
 	list_del(&vxlan->next);
 	unregister_netdevice_queue(dev, head);
@@ -4961,7 +4964,7 @@ vxlan_fdb_external_learn_add(struct net_device *dev,
 			       fdb_info->remote_vni,
 			       fdb_info->remote_ifindex,
 			       NTF_USE | NTF_SELF | NTF_EXT_LEARNED,
-			       0, false, extack);
+			       0, 0, false, extack);
 	spin_unlock_bh(&vxlan->hash_lock);
 
 	return err;
@@ -4987,7 +4990,7 @@ vxlan_fdb_external_learn_del(struct net_device *dev,
 					 fdb_info->vni,
 					 fdb_info->remote_vni,
 					 fdb_info->remote_ifindex,
-					 false);
+					 0, false);
 
 	spin_unlock_bh(&vxlan->hash_lock);
 
@@ -5045,7 +5048,7 @@ static void vxlan_fdb_nh_flush(struct nexthop *nh)
 		WARN_ON(!vxlan);
 		spin_lock_bh(&vxlan->hash_lock);
 		if (!hlist_unhashed(&fdb->fdb_node))
-			vxlan_fdb_destroy(vxlan, fdb, false, false);
+			vxlan_fdb_destroy(vxlan, fdb, false, 0, false);
 		spin_unlock_bh(&vxlan->hash_lock);
 	}
 	rcu_read_unlock();
drivers/net/vxlan/vxlan_private.h +3 -2
index f0ee85f83732..632e1880c0b9 100644
@@ -196,13 +196,14 @@ int vxlan_fdb_create(struct vxlan_dev *vxlan,
 int __vxlan_fdb_delete(struct vxlan_dev *vxlan,
 		       const unsigned char *addr, union vxlan_addr ip,
 		       __be16 port, __be32 src_vni, __be32 vni,
-		       u32 ifindex, bool swdev_notify);
+		       u32 ifindex, u32 portid, bool swdev_notify);
 int vxlan_fdb_update(struct vxlan_dev *vxlan,
 		     const u8 *mac, union vxlan_addr *ip,
 		     __u16 state, __u16 flags,
 		     __be16 port, __be32 src_vni, __be32 vni,
 		     __u32 ifindex, __u16 ndm_flags, u32 nhid,
-		     bool swdev_notify, struct netlink_ext_ack *extack);
+		     u32 portid, bool swdev_notify,
+		     struct netlink_ext_ack *extack);
 void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
 		    const struct vxlan_config *cfg,
 		    __be32 default_vni, struct vxlan_rdst *rdst, bool did_rsc);
drivers/net/vxlan/vxlan_vnifilter.c +3 -3
index c5cc6cd08545..927b63db3b5b 100644
@@ -550,7 +550,7 @@ int vxlan_update_default_fdb_entry(struct vxlan_dev *vxlan, __be32 vni,
 				       vni,
 				       vni,
 				       new_ifindex,
-				       NTF_SELF, 0, true, extack);
+				       NTF_SELF, 0, 0, true, extack);
 		if (err && extack) {
 			spin_unlock_bh(&vxlan->hash_lock);
 			return err;
@@ -563,7 +563,7 @@ int vxlan_update_default_fdb_entry(struct vxlan_dev *vxlan, __be32 vni,
 				   cfg->dst_port,
 				   vni, vni,
 				   old_ifindex,
-				   true);
+				   0, true);
 	}
 	spin_unlock_bh(&vxlan->hash_lock);
 
@@ -727,7 +727,7 @@ static void vxlan_vni_delete_group(struct vxlan_dev *vxlan,
 				   cfg->dst_port,
 				   vninode->vni, vninode->vni,
 				   cfg->remote_ifindex,
-				   true);
+				   0, true);
 		spin_unlock_bh(&vxlan->hash_lock);
 	}
 
Signature · 1 line
2.56.1
#9 lore raw

PATCH 9/13 net: rtnetlink: Report port ID in fallback FDB notifications

In reply to Petr Machata

The previous patch made the bridge and VXLAN drivers report the port ID of the requester in the FDB notifications that they emit. Other drivers that implement ndo_fdb_add and ndo_fdb_del, as well as the default implementations ndo_dflt_fdb_add() and ndo_dflt_fdb_del(), do not send notifications themselves. Instead rtnl_fdb_add() and rtnl_fdb_del() send one on their behalf through rtnl_fdb_notify(), and that always uses port ID of zero.

Pass the port ID of the requester to rtnl_fdb_notify() as well, so that the notifications sent for these devices carry it in nlmsg_pid just like the ones from bridge and VXLAN.

---
 net/core/rtnetlink.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
net/core/rtnetlink.c +4 -4
index e1607a3232c7..51713666f0e3 100644
@@ -4721,7 +4721,7 @@ static inline size_t rtnl_fdb_nlmsg_size(const struct net_device *dev)
 }
 
 static void rtnl_fdb_notify(struct net_device *dev, u8 *addr, u16 vid, int type,
-			    u16 ndm_state)
+			    u16 ndm_state, u32 portid)
 {
 	struct net *net = dev_net(dev);
 	struct sk_buff *skb;
@@ -4732,7 +4732,7 @@ static void rtnl_fdb_notify(struct net_device *dev, u8 *addr, u16 vid, int type,
 		goto errout;
 
 	err = nlmsg_populate_fdb_fill(skb, dev, addr, vid,
-				      0, 0, type, NTF_SELF, 0, ndm_state);
+				      portid, 0, type, NTF_SELF, 0, ndm_state);
 	if (err < 0) {
 		kfree_skb(skb);
 		goto errout;
@@ -4888,7 +4888,7 @@ static int rtnl_fdb_add(struct sk_buff *skb, struct nlmsghdr *nlh,
 
 		if (!err && !notified) {
 			rtnl_fdb_notify(dev, addr, vid, RTM_NEWNEIGH,
-					ndm->ndm_state);
+					ndm->ndm_state, parms.portid);
 			ndm->ndm_flags &= ~NTF_SELF;
 		}
 	}
@@ -5033,7 +5033,7 @@ static int rtnl_fdb_del(struct sk_buff *skb, struct nlmsghdr *nlh,
 		if (!err) {
 			if (!del_bulk && !notified)
 				rtnl_fdb_notify(dev, addr, vid, RTM_DELNEIGH,
-						ndm->ndm_state);
+						ndm->ndm_state, portid);
 			ndm->ndm_flags &= ~NTF_SELF;
 		}
 	}
Signature · 1 line
2.56.1
#11 lore raw

PATCH 11/13 tools: ynl: Add NLM_F_BULK

In reply to Petr Machata

Add the NLM_F_BULK flag, which marks a delete request as a bulk delete, to the netlink flags known to the YNL Python library. It has the same value as NLM_F_ACK_TLVS, but that one is only used in replies, whereas NLM_F_BULK is only used in requests.

---
CC: Donald Hunter <[email protected]>

---
 tools/net/ynl/pyynl/lib/ynl.py | 2 ++
 1 file changed, 2 insertions(+)
tools/net/ynl/pyynl/lib/ynl.py +2 -0
index fb5acb8acded..0e9bcd0f2599 100644
@@ -61,6 +61,8 @@ class Netlink:
     NLM_F_CREATE = 0x400
     NLM_F_APPEND = 0x800
 
+    NLM_F_BULK = 0x200
+
     NLM_F_CAPPED = 0x100
     NLM_F_ACK_TLVS = 0x200
 
Signature · 1 line
2.56.1
#10 lore raw

PATCH 10/13 netlink: specs: rt-neigh: Extend the delneigh request attributes

In reply to Petr Machata

The kernel accepts more attributes in an RTM_DELNEIGH request than the spec lists. FDB deletion identifies the entry by NDA_LLADDR and NDA_VLAN, and bulk deletion (NLM_F_BULK) filters entries by NDA_NDM_STATE_MASK and NDA_NDM_FLAGS_MASK.

Add lladdr, vlan, ndm-state-mask and ndm-flags-mask to the request attributes of delneigh, so that these requests can be built through YNL.

---
CC: David Ahern <[email protected]>
CC: Donald Hunter <[email protected]>

---
 Documentation/netlink/specs/rt-neigh.yaml | 4 ++++
 1 file changed, 4 insertions(+)
Documentation/netlink/specs/rt-neigh.yaml +4 -0
index 7929e667cc7a..4dd4e3d997f0 100644
@@ -380,7 +380,11 @@ operations:
           value: 29
           attributes:
             - dst
+            - lladdr
+            - vlan
             - ifindex
+            - ndm-state-mask
+            - ndm-flags-mask
     -
       name: delneigh-ntf
       doc: Notify a neighbour deletion
Signature · 1 line
2.56.1
#13 lore raw

PATCH 13/13 selftests: net: Add a test for port ID in FDB notifications

In reply to Petr Machata

Add a test that checks that RTM_NEWNEIGH and RTM_DELNEIGH notifications for FDB entries carry the netlink port ID of the requester in nlmsg_pid.

A listener socket subscribed to the neighbour group receives the notifications, while two separate requester sockets, A and B, make the changes. Entries are added through A, replaced through B and deleted through A, and the port ID seen by the listener is compared to that of the socket that made the particular change. The following cases are covered:

- bridge: a bridge port (NTF_MASTER) and the bridge device itself (NTF_SELF), including a bridge with VLAN filtering, where one request results in several notifications
- VXLAN, including replacing the remote
- macvlan, which does not send notifications by itself and thus exercises the generic fallback in rtnetlink
- bulk delete (flush) of bridge and VXLAN entries
- bridge entries learned from traffic, which are not a result of a request and should carry a port ID of zero

The test needs CONFIG_PACKET to send the frame that is learned.

fdb_notify.sh already covers some of the same device setups (bridge, VXLAN, macvlan), but it checks for duplicate notifications and cannot check the port ID, as the broadly available tools do not show nlmsg_pid. One option would be to capture bridge monitor run with strace and parse out key tells. But that felt like too much of an ugly hack. Another option considered was netlink capture (nlmon plus tshark), which would add further tool dependencies, and then, a capture does not say which socket a message was sent through, which is needed to tell the requester's port ID from someone else's.

Python with YNL, which the selftests already have, can read nlmsg_pid and compare it to the requester's socket directly. So instead of extending / consolidating with fdb_notify.sh, a new test was written.

---
CC: Shuah Khan <[email protected]>
CC: [email protected]

---
 tools/testing/selftests/net/Makefile          |   1 +
 tools/testing/selftests/net/config            |   1 +
 .../selftests/net/fdb_notify_portid.py        | 297 ++++++++++++++++++
 3 files changed, 299 insertions(+)
 create mode 100755 tools/testing/selftests/net/fdb_notify_portid.py
tools/testing/selftests/net/Makefile +1 -0
index fb0a64662053..fafe30367243 100644
@@ -35,6 +35,7 @@ TEST_PROGS := \
 	fcnal-other.sh \
 	fdb_flush.sh \
 	fdb_notify.sh \
+	fdb_notify_portid.py \
 	fib-onlink-tests.sh \
 	fib_nexthop_multiprefix.sh \
 	fib_nexthop_nongw.sh \
tools/testing/selftests/net/config +1 -0
index dab62cdfa27b..18dfb45fb914 100644
@@ -126,6 +126,7 @@ CONFIG_NFT_COMPAT=m
 CONFIG_NFT_NAT=m
 CONFIG_NUMA=y
 CONFIG_OPENVSWITCH=m
+CONFIG_PACKET=y
 CONFIG_PAGE_POOL_STATS=y
 CONFIG_PSAMPLE=m
 CONFIG_RPS=y
tools/testing/selftests/net/fdb_notify_portid.py new file +297 -0

297 lines not on this page · raw message

Signature · 1 line
2.56.1
#12 lore raw

PATCH 12/13 selftests: net: lib: py: Add RtnlNeighFamily

In reply to Petr Machata

Add a YnlFamily wrapper for the rt-neigh spec, next to the ones for rt-link, rt-addr and rt-route, and export it from lib.py.

---
CC: Shuah Khan <[email protected]>
CC: [email protected]

---
 tools/testing/selftests/net/lib/py/__init__.py |  6 ++++--
 tools/testing/selftests/net/lib/py/ynl.py      | 10 +++++++++-
 2 files changed, 13 insertions(+), 3 deletions(-)
tools/testing/selftests/net/lib/py/__init__.py +4 -2
index b1696f432c7c..3f7696d06e6f 100644
@@ -17,7 +17,8 @@ from .utils import CmdExitFailure, fd_read_timeout, cmd, bkg, defer, \
     ctl_file_write, wait_file, tool, tc
 from .bpf import bpf_map_set, bpf_map_dump, bpf_prog_map_ids
 from .ynl import NlError, NlctrlFamily, YnlFamily, \
-    EthtoolFamily, NetdevFamily, RtnlFamily, RtnlAddrFamily, RtnlRouteFamily
+    EthtoolFamily, NetdevFamily, RtnlFamily, RtnlNeighFamily, \
+    RtnlAddrFamily, RtnlRouteFamily
 from .ynl import NetshaperFamily, DevlinkFamily, GtpFamily, PSPFamily, Netlink
 
 __all__ = ["KSRC",
@@ -36,4 +37,5 @@ __all__ = ["KSRC",
            "NetshaperFamily", "DevlinkFamily", "GtpFamily", "PSPFamily",
            "NlError",
            "YnlFamily", "EthtoolFamily", "NetdevFamily", "RtnlFamily",
-           "NlctrlFamily", "RtnlAddrFamily", "RtnlRouteFamily", "Netlink"]
+           "RtnlNeighFamily", "NlctrlFamily", "RtnlAddrFamily",
+           "RtnlRouteFamily", "Netlink"]
tools/testing/selftests/net/lib/py/ynl.py +9 -1
index 69a6e9d9b390..ac13bf1ff23d 100644
@@ -29,7 +29,8 @@ except ModuleNotFoundError as e:
 
 __all__ = [
     "NlError", "NlPolicy", "Netlink", "YnlFamily", "SPEC_PATH",
-    "EthtoolFamily", "RtnlFamily", "RtnlAddrFamily", "RtnlRouteFamily",
+    "EthtoolFamily", "RtnlFamily", "RtnlNeighFamily", "RtnlAddrFamily",
+    "RtnlRouteFamily",
     "NetdevFamily", "NetshaperFamily", "NlctrlFamily", "DevlinkFamily",
     "GtpFamily", "PSPFamily",
 ]
@@ -49,6 +50,13 @@ class RtnlFamily(YnlFamily):
         super().__init__((SPEC_PATH / Path('rt-link.yaml')).as_posix(),
                          schema='', recv_size=recv_size)
 
+class RtnlNeighFamily(YnlFamily):
+    """Netlink interface for neighbour messages."""
+    # pylint: disable=too-few-public-methods
+    def __init__(self, recv_size=0):
+        super().__init__((SPEC_PATH / Path('rt-neigh.yaml')).as_posix(),
+                         schema='', recv_size=recv_size)
+
 class RtnlAddrFamily(YnlFamily):
     def __init__(self, recv_size=0):
         super().__init__((SPEC_PATH / Path('rt-addr.yaml')).as_posix(),
Signature · 1 line
2.56.1