Skip to content

Commit e709d44

Browse files
committed
Merge branch 'net-ndo_fdb_add-del-have-drivers-report-whether-they-notified'
Petr Machata says: ==================== net: ndo_fdb_add/del: Have drivers report whether they notified Currently when FDB entries are added to or deleted from a VXLAN netdevice, the VXLAN driver emits one notification, including the VXLAN-specific attributes. The core however always sends a notification as well, a generic one. Thus two notifications are unnecessarily sent for these operations. A similar situation comes up with bridge driver, which also emits notifications on its own. # ip link add name vx type vxlan id 1000 dstport 4789 # bridge monitor fdb & [1] 1981693 # bridge fdb add de:ad:be:ef:13:37 dev vx self dst 192.0.2.1 de:ad:be:ef:13:37 dev vx dst 192.0.2.1 self permanent de:ad:be:ef:13:37 dev vx self permanent In order to prevent this duplicity, add a parameter, bool *notified, to ndo_fdb_add and ndo_fdb_del. The flag is primed to false, and if the callee sends a notification on its own, it sets the flag to true, thus informing the core that it should not generate another notification. Patches #1 to #2 are concerned with the above. In the remaining patches, #3 to #7, add a selftest. This takes place across several patches. Many of the helpers we would like to use for the test are in forwarding/lib.sh, whereas net/ is a more suitable place for the test, so the libraries need to be massaged a bit first. ==================== Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 2a8ce47 + 15880be commit e709d44

29 files changed

+419
-267
lines changed

drivers/net/ethernet/intel/i40e/i40e_main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13095,12 +13095,13 @@ static int i40e_get_phys_port_id(struct net_device *netdev,
1309513095
* @addr: the MAC address entry being added
1309613096
* @vid: VLAN ID
1309713097
* @flags: instructions from stack about fdb operation
13098+
* @notified: whether notification was emitted
1309813099
* @extack: netlink extended ack, unused currently
1309913100
*/
1310013101
static int i40e_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
1310113102
struct net_device *dev,
1310213103
const unsigned char *addr, u16 vid,
13103-
u16 flags,
13104+
u16 flags, bool *notified,
1310413105
struct netlink_ext_ack *extack)
1310513106
{
1310613107
struct i40e_netdev_priv *np = netdev_priv(dev);

drivers/net/ethernet/intel/ice/ice_main.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6125,12 +6125,14 @@ ice_set_tx_maxrate(struct net_device *netdev, int queue_index, u32 maxrate)
61256125
* @addr: the MAC address entry being added
61266126
* @vid: VLAN ID
61276127
* @flags: instructions from stack about fdb operation
6128+
* @notified: whether notification was emitted
61286129
* @extack: netlink extended ack
61296130
*/
61306131
static int
61316132
ice_fdb_add(struct ndmsg *ndm, struct nlattr __always_unused *tb[],
61326133
struct net_device *dev, const unsigned char *addr, u16 vid,
6133-
u16 flags, struct netlink_ext_ack __always_unused *extack)
6134+
u16 flags, bool *notified,
6135+
struct netlink_ext_ack __always_unused *extack)
61346136
{
61356137
int err;
61366138

@@ -6164,12 +6166,14 @@ ice_fdb_add(struct ndmsg *ndm, struct nlattr __always_unused *tb[],
61646166
* @dev: the net device pointer
61656167
* @addr: the MAC address entry being added
61666168
* @vid: VLAN ID
6169+
* @notified: whether notification was emitted
61676170
* @extack: netlink extended ack
61686171
*/
61696172
static int
61706173
ice_fdb_del(struct ndmsg *ndm, __always_unused struct nlattr *tb[],
61716174
struct net_device *dev, const unsigned char *addr,
6172-
__always_unused u16 vid, struct netlink_ext_ack *extack)
6175+
__always_unused u16 vid, bool *notified,
6176+
struct netlink_ext_ack *extack)
61736177
{
61746178
int err;
61756179

drivers/net/ethernet/intel/igb/igb_main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2486,7 +2486,7 @@ static int igb_set_features(struct net_device *netdev,
24862486
static int igb_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
24872487
struct net_device *dev,
24882488
const unsigned char *addr, u16 vid,
2489-
u16 flags,
2489+
u16 flags, bool *notified,
24902490
struct netlink_ext_ack *extack)
24912491
{
24922492
/* guarantee we can provide a unique filter for the unicast address */

drivers/net/ethernet/intel/ixgbe/ixgbe_main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9954,7 +9954,7 @@ static int ixgbe_set_features(struct net_device *netdev,
99549954
static int ixgbe_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
99559955
struct net_device *dev,
99569956
const unsigned char *addr, u16 vid,
9957-
u16 flags,
9957+
u16 flags, bool *notified,
99589958
struct netlink_ext_ack *extack)
99599959
{
99609960
/* guarantee we can provide a unique filter for the unicast address */

drivers/net/ethernet/mscc/ocelot_net.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ static void ocelot_get_stats64(struct net_device *dev,
730730
static int ocelot_port_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
731731
struct net_device *dev,
732732
const unsigned char *addr,
733-
u16 vid, u16 flags,
733+
u16 vid, u16 flags, bool *notified,
734734
struct netlink_ext_ack *extack)
735735
{
736736
struct ocelot_port_private *priv = netdev_priv(dev);
@@ -744,7 +744,7 @@ static int ocelot_port_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
744744
static int ocelot_port_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
745745
struct net_device *dev,
746746
const unsigned char *addr, u16 vid,
747-
struct netlink_ext_ack *extack)
747+
bool *notified, struct netlink_ext_ack *extack)
748748
{
749749
struct ocelot_port_private *priv = netdev_priv(dev);
750750
struct ocelot_port *ocelot_port = &priv->port;

drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ static int qlcnic_set_mac(struct net_device *netdev, void *p)
367367

368368
static int qlcnic_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
369369
struct net_device *netdev,
370-
const unsigned char *addr, u16 vid,
370+
const unsigned char *addr, u16 vid, bool *notified,
371371
struct netlink_ext_ack *extack)
372372
{
373373
struct qlcnic_adapter *adapter = netdev_priv(netdev);
@@ -394,7 +394,7 @@ static int qlcnic_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
394394
static int qlcnic_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
395395
struct net_device *netdev,
396396
const unsigned char *addr, u16 vid, u16 flags,
397-
struct netlink_ext_ack *extack)
397+
bool *notified, struct netlink_ext_ack *extack)
398398
{
399399
struct qlcnic_adapter *adapter = netdev_priv(netdev);
400400
int err = 0;

drivers/net/macvlan.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ static int macvlan_vlan_rx_kill_vid(struct net_device *dev,
10241024
static int macvlan_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
10251025
struct net_device *dev,
10261026
const unsigned char *addr, u16 vid,
1027-
u16 flags,
1027+
u16 flags, bool *notified,
10281028
struct netlink_ext_ack *extack)
10291029
{
10301030
struct macvlan_dev *vlan = netdev_priv(dev);
@@ -1049,7 +1049,7 @@ static int macvlan_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
10491049

10501050
static int macvlan_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
10511051
struct net_device *dev,
1052-
const unsigned char *addr, u16 vid,
1052+
const unsigned char *addr, u16 vid, bool *notified,
10531053
struct netlink_ext_ack *extack)
10541054
{
10551055
struct macvlan_dev *vlan = netdev_priv(dev);

drivers/net/vxlan/vxlan_core.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,7 +1241,7 @@ static int vxlan_fdb_parse(struct nlattr *tb[], struct vxlan_dev *vxlan,
12411241
static int vxlan_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
12421242
struct net_device *dev,
12431243
const unsigned char *addr, u16 vid, u16 flags,
1244-
struct netlink_ext_ack *extack)
1244+
bool *notified, struct netlink_ext_ack *extack)
12451245
{
12461246
struct vxlan_dev *vxlan = netdev_priv(dev);
12471247
/* struct net *net = dev_net(vxlan->dev); */
@@ -1277,6 +1277,9 @@ static int vxlan_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
12771277
nhid, true, extack);
12781278
spin_unlock_bh(&vxlan->hash_lock[hash_index]);
12791279

1280+
if (!err)
1281+
*notified = true;
1282+
12801283
return err;
12811284
}
12821285

@@ -1316,7 +1319,7 @@ int __vxlan_fdb_delete(struct vxlan_dev *vxlan,
13161319
/* Delete entry (via netlink) */
13171320
static int vxlan_fdb_delete(struct ndmsg *ndm, struct nlattr *tb[],
13181321
struct net_device *dev,
1319-
const unsigned char *addr, u16 vid,
1322+
const unsigned char *addr, u16 vid, bool *notified,
13201323
struct netlink_ext_ack *extack)
13211324
{
13221325
struct vxlan_dev *vxlan = netdev_priv(dev);
@@ -1338,6 +1341,9 @@ static int vxlan_fdb_delete(struct ndmsg *ndm, struct nlattr *tb[],
13381341
true);
13391342
spin_unlock_bh(&vxlan->hash_lock[hash_index]);
13401343

1344+
if (!err)
1345+
*notified = true;
1346+
13411347
return err;
13421348
}
13431349

include/linux/netdevice.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,12 +1248,17 @@ struct netdev_net_notifier {
12481248
* int (*ndo_fdb_add)(struct ndmsg *ndm, struct nlattr *tb[],
12491249
* struct net_device *dev,
12501250
* const unsigned char *addr, u16 vid, u16 flags,
1251-
* struct netlink_ext_ack *extack);
1251+
* bool *notified, struct netlink_ext_ack *extack);
12521252
* Adds an FDB entry to dev for addr.
1253+
* Callee shall set *notified to true if it sent any appropriate
1254+
* notification(s). Otherwise core will send a generic one.
12531255
* int (*ndo_fdb_del)(struct ndmsg *ndm, struct nlattr *tb[],
12541256
* struct net_device *dev,
1255-
* const unsigned char *addr, u16 vid)
1257+
* const unsigned char *addr, u16 vid
1258+
* bool *notified, struct netlink_ext_ack *extack);
12561259
* Deletes the FDB entry from dev corresponding to addr.
1260+
* Callee shall set *notified to true if it sent any appropriate
1261+
* notification(s). Otherwise core will send a generic one.
12571262
* int (*ndo_fdb_del_bulk)(struct nlmsghdr *nlh, struct net_device *dev,
12581263
* struct netlink_ext_ack *extack);
12591264
* int (*ndo_fdb_dump)(struct sk_buff *skb, struct netlink_callback *cb,
@@ -1525,12 +1530,15 @@ struct net_device_ops {
15251530
const unsigned char *addr,
15261531
u16 vid,
15271532
u16 flags,
1533+
bool *notified,
15281534
struct netlink_ext_ack *extack);
15291535
int (*ndo_fdb_del)(struct ndmsg *ndm,
15301536
struct nlattr *tb[],
15311537
struct net_device *dev,
15321538
const unsigned char *addr,
1533-
u16 vid, struct netlink_ext_ack *extack);
1539+
u16 vid,
1540+
bool *notified,
1541+
struct netlink_ext_ack *extack);
15341542
int (*ndo_fdb_del_bulk)(struct nlmsghdr *nlh,
15351543
struct net_device *dev,
15361544
struct netlink_ext_ack *extack);

net/bridge/br_fdb.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,7 +1152,7 @@ static int fdb_add_entry(struct net_bridge *br, struct net_bridge_port *source,
11521152
static int __br_fdb_add(struct ndmsg *ndm, struct net_bridge *br,
11531153
struct net_bridge_port *p, const unsigned char *addr,
11541154
u16 nlh_flags, u16 vid, struct nlattr *nfea_tb[],
1155-
struct netlink_ext_ack *extack)
1155+
bool *notified, struct netlink_ext_ack *extack)
11561156
{
11571157
int err = 0;
11581158

@@ -1183,6 +1183,8 @@ static int __br_fdb_add(struct ndmsg *ndm, struct net_bridge *br,
11831183
spin_unlock_bh(&br->hash_lock);
11841184
}
11851185

1186+
if (!err)
1187+
*notified = true;
11861188
return err;
11871189
}
11881190

@@ -1195,7 +1197,7 @@ static const struct nla_policy br_nda_fdb_pol[NFEA_MAX + 1] = {
11951197
int br_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
11961198
struct net_device *dev,
11971199
const unsigned char *addr, u16 vid, u16 nlh_flags,
1198-
struct netlink_ext_ack *extack)
1200+
bool *notified, struct netlink_ext_ack *extack)
11991201
{
12001202
struct nlattr *nfea_tb[NFEA_MAX + 1], *attr;
12011203
struct net_bridge_vlan_group *vg;
@@ -1258,10 +1260,10 @@ int br_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
12581260

12591261
/* VID was specified, so use it. */
12601262
err = __br_fdb_add(ndm, br, p, addr, nlh_flags, vid, nfea_tb,
1261-
extack);
1263+
notified, extack);
12621264
} else {
12631265
err = __br_fdb_add(ndm, br, p, addr, nlh_flags, 0, nfea_tb,
1264-
extack);
1266+
notified, extack);
12651267
if (err || !vg || !vg->num_vlans)
12661268
goto out;
12671269

@@ -1273,7 +1275,7 @@ int br_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
12731275
if (!br_vlan_should_use(v))
12741276
continue;
12751277
err = __br_fdb_add(ndm, br, p, addr, nlh_flags, v->vid,
1276-
nfea_tb, extack);
1278+
nfea_tb, notified, extack);
12771279
if (err)
12781280
goto out;
12791281
}
@@ -1285,7 +1287,7 @@ int br_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
12851287

12861288
static int fdb_delete_by_addr_and_port(struct net_bridge *br,
12871289
const struct net_bridge_port *p,
1288-
const u8 *addr, u16 vlan)
1290+
const u8 *addr, u16 vlan, bool *notified)
12891291
{
12901292
struct net_bridge_fdb_entry *fdb;
12911293

@@ -1294,18 +1296,19 @@ static int fdb_delete_by_addr_and_port(struct net_bridge *br,
12941296
return -ENOENT;
12951297

12961298
fdb_delete(br, fdb, true);
1299+
*notified = true;
12971300

12981301
return 0;
12991302
}
13001303

13011304
static int __br_fdb_delete(struct net_bridge *br,
13021305
const struct net_bridge_port *p,
1303-
const unsigned char *addr, u16 vid)
1306+
const unsigned char *addr, u16 vid, bool *notified)
13041307
{
13051308
int err;
13061309

13071310
spin_lock_bh(&br->hash_lock);
1308-
err = fdb_delete_by_addr_and_port(br, p, addr, vid);
1311+
err = fdb_delete_by_addr_and_port(br, p, addr, vid, notified);
13091312
spin_unlock_bh(&br->hash_lock);
13101313

13111314
return err;
@@ -1314,7 +1317,7 @@ static int __br_fdb_delete(struct net_bridge *br,
13141317
/* Remove neighbor entry with RTM_DELNEIGH */
13151318
int br_fdb_delete(struct ndmsg *ndm, struct nlattr *tb[],
13161319
struct net_device *dev,
1317-
const unsigned char *addr, u16 vid,
1320+
const unsigned char *addr, u16 vid, bool *notified,
13181321
struct netlink_ext_ack *extack)
13191322
{
13201323
struct net_bridge_vlan_group *vg;
@@ -1337,19 +1340,19 @@ int br_fdb_delete(struct ndmsg *ndm, struct nlattr *tb[],
13371340
}
13381341

13391342
if (vid) {
1340-
err = __br_fdb_delete(br, p, addr, vid);
1343+
err = __br_fdb_delete(br, p, addr, vid, notified);
13411344
} else {
13421345
struct net_bridge_vlan *v;
13431346

13441347
err = -ENOENT;
1345-
err &= __br_fdb_delete(br, p, addr, 0);
1348+
err &= __br_fdb_delete(br, p, addr, 0, notified);
13461349
if (!vg || !vg->num_vlans)
13471350
return err;
13481351

13491352
list_for_each_entry(v, &vg->vlan_list, vlist) {
13501353
if (!br_vlan_should_use(v))
13511354
continue;
1352-
err &= __br_fdb_delete(br, p, addr, v->vid);
1355+
err &= __br_fdb_delete(br, p, addr, v->vid, notified);
13531356
}
13541357
}
13551358

net/bridge/br_private.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -853,12 +853,12 @@ void br_fdb_update(struct net_bridge *br, struct net_bridge_port *source,
853853

854854
int br_fdb_delete(struct ndmsg *ndm, struct nlattr *tb[],
855855
struct net_device *dev, const unsigned char *addr, u16 vid,
856-
struct netlink_ext_ack *extack);
856+
bool *notified, struct netlink_ext_ack *extack);
857857
int br_fdb_delete_bulk(struct nlmsghdr *nlh, struct net_device *dev,
858858
struct netlink_ext_ack *extack);
859859
int br_fdb_add(struct ndmsg *nlh, struct nlattr *tb[], struct net_device *dev,
860860
const unsigned char *addr, u16 vid, u16 nlh_flags,
861-
struct netlink_ext_ack *extack);
861+
bool *notified, struct netlink_ext_ack *extack);
862862
int br_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb,
863863
struct net_device *dev, struct net_device *fdev, int *idx);
864864
int br_fdb_get(struct sk_buff *skb, struct nlattr *tb[], struct net_device *dev,

net/core/rtnetlink.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4578,9 +4578,10 @@ static int rtnl_fdb_add(struct sk_buff *skb, struct nlmsghdr *nlh,
45784578
netif_is_bridge_port(dev)) {
45794579
struct net_device *br_dev = netdev_master_upper_dev_get(dev);
45804580
const struct net_device_ops *ops = br_dev->netdev_ops;
4581+
bool notified = false;
45814582

45824583
err = ops->ndo_fdb_add(ndm, tb, dev, addr, vid,
4583-
nlh->nlmsg_flags, extack);
4584+
nlh->nlmsg_flags, &notified, extack);
45844585
if (err)
45854586
goto out;
45864587
else
@@ -4589,16 +4590,18 @@ static int rtnl_fdb_add(struct sk_buff *skb, struct nlmsghdr *nlh,
45894590

45904591
/* Embedded bridge, macvlan, and any other device support */
45914592
if ((ndm->ndm_flags & NTF_SELF)) {
4593+
bool notified = false;
4594+
45924595
if (dev->netdev_ops->ndo_fdb_add)
45934596
err = dev->netdev_ops->ndo_fdb_add(ndm, tb, dev, addr,
45944597
vid,
45954598
nlh->nlmsg_flags,
4596-
extack);
4599+
&notified, extack);
45974600
else
45984601
err = ndo_dflt_fdb_add(ndm, tb, dev, addr, vid,
45994602
nlh->nlmsg_flags);
46004603

4601-
if (!err) {
4604+
if (!err && !notified) {
46024605
rtnl_fdb_notify(dev, addr, vid, RTM_NEWNEIGH,
46034606
ndm->ndm_state);
46044607
ndm->ndm_flags &= ~NTF_SELF;
@@ -4698,11 +4701,13 @@ static int rtnl_fdb_del(struct sk_buff *skb, struct nlmsghdr *nlh,
46984701
if ((!ndm->ndm_flags || ndm->ndm_flags & NTF_MASTER) &&
46994702
netif_is_bridge_port(dev)) {
47004703
struct net_device *br_dev = netdev_master_upper_dev_get(dev);
4704+
bool notified = false;
47014705

47024706
ops = br_dev->netdev_ops;
47034707
if (!del_bulk) {
47044708
if (ops->ndo_fdb_del)
4705-
err = ops->ndo_fdb_del(ndm, tb, dev, addr, vid, extack);
4709+
err = ops->ndo_fdb_del(ndm, tb, dev, addr, vid,
4710+
&notified, extack);
47064711
} else {
47074712
if (ops->ndo_fdb_del_bulk)
47084713
err = ops->ndo_fdb_del_bulk(nlh, dev, extack);
@@ -4716,10 +4721,13 @@ static int rtnl_fdb_del(struct sk_buff *skb, struct nlmsghdr *nlh,
47164721

47174722
/* Embedded bridge, macvlan, and any other device support */
47184723
if (ndm->ndm_flags & NTF_SELF) {
4724+
bool notified = false;
4725+
47194726
ops = dev->netdev_ops;
47204727
if (!del_bulk) {
47214728
if (ops->ndo_fdb_del)
4722-
err = ops->ndo_fdb_del(ndm, tb, dev, addr, vid, extack);
4729+
err = ops->ndo_fdb_del(ndm, tb, dev, addr, vid,
4730+
&notified, extack);
47234731
else
47244732
err = ndo_dflt_fdb_del(ndm, tb, dev, addr, vid);
47254733
} else {
@@ -4730,7 +4738,7 @@ static int rtnl_fdb_del(struct sk_buff *skb, struct nlmsghdr *nlh,
47304738
}
47314739

47324740
if (!err) {
4733-
if (!del_bulk)
4741+
if (!del_bulk && !notified)
47344742
rtnl_fdb_notify(dev, addr, vid, RTM_DELNEIGH,
47354743
ndm->ndm_state);
47364744
ndm->ndm_flags &= ~NTF_SELF;

0 commit comments

Comments
 (0)