From: Petr Machata <petrm@nvidia.com>
To: "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>, <netdev@vger.kernel.org>
Cc: Andrew Lunn <andrew+netdev@lunn.ch>,
Nikolay Aleksandrov <razor@blackwall.org>,
<bridge@lists.linux.dev>, Ido Schimmel <idosch@nvidia.com>,
Petr Machata <petrm@nvidia.com>, Andy Roulin <aroulin@nvidia.com>,
<mlxsw@nvidia.com>
Subject: [PATCH net-next v2 04/13] net: bridge: Pass struct ndo_fdb_parms a bit further
Date: Mon, 30 Nov 2026 14:03:20 +0100 [thread overview]
Message-ID: <c26b6db3da84e1209dfeb4b29bace485f744aa2a.1796041491.git.petrm@nvidia.com> (raw)
In-Reply-To: <cover.1796041491.git.petrm@nvidia.com>
__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.
Signed-off-by: Petr Machata <petrm@nvidia.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Reviewed-by: Nikolay Aleksandrov <razor@blackwall.org>
---
net/bridge/br_fdb.c | 48 +++++++++++++++++++++++----------------------
1 file changed, 25 insertions(+), 23 deletions(-)
diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c
index 9e2fdcc5ca9b..45b844a9a1f6 100644
--- a/net/bridge/br_fdb.c
+++ b/net/bridge/br_fdb.c
@@ -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;
}
--
2.56.1
next prev parent reply other threads:[~2026-11-30 13:05 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 13:03 [PATCH net-next v2 00/13] net: Report requester's port ID in FDB notifications Petr Machata
2026-11-30 13:03 ` [PATCH net-next v2 01/13] net: Introduce struct ndo_fdb_parms Petr Machata
2026-11-30 13:03 ` [PATCH net-next v2 02/13] net: Pass struct ndo_fdb_parms to ndo_dflt_fdb_{add, del}() Petr Machata
2026-11-30 13:03 ` [PATCH net-next v2 03/13] net: Pass portid to ndo_fdb_get through the structure Petr Machata
2026-11-30 13:03 ` Petr Machata [this message]
2026-11-30 13:03 ` [PATCH net-next v2 05/13] net: bridge: Pass portid through FDB notifications Petr Machata
2026-11-30 13:03 ` [PATCH net-next v2 06/13] net: vxlan: " Petr Machata
2026-11-30 13:03 ` [PATCH net-next v2 07/13] net: rtnetlink: Report port ID in bridge and VXLAN " Petr Machata
2026-11-30 13:03 ` [PATCH net-next v2 08/13] net: rtnetlink: Report port ID in bulk FDB delete notifications Petr Machata
2026-11-30 13:03 ` [PATCH net-next v2 09/13] net: rtnetlink: Report port ID in fallback FDB notifications Petr Machata
2026-11-30 13:03 ` [PATCH net-next v2 10/13] netlink: specs: rt-neigh: Extend the delneigh request attributes Petr Machata
2026-11-30 13:03 ` [PATCH net-next v2 11/13] tools: ynl: Add NLM_F_BULK Petr Machata
2026-11-30 13:03 ` [PATCH net-next v2 12/13] selftests: net: lib: py: Add RtnlNeighFamily Petr Machata
2026-11-30 13:03 ` [PATCH net-next v2 13/13] selftests: net: Add a test for port ID in FDB notifications Petr Machata
2026-11-30 13:24 ` [PATCH net-next v2 00/13] net: Report requester's " Przemek Kitszel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c26b6db3da84e1209dfeb4b29bace485f744aa2a.1796041491.git.petrm@nvidia.com \
--to=petrm@nvidia.com \
--cc=andrew+netdev@lunn.ch \
--cc=aroulin@nvidia.com \
--cc=bridge@lists.linux.dev \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=idosch@nvidia.com \
--cc=kuba@kernel.org \
--cc=mlxsw@nvidia.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=razor@blackwall.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox