net: bridge: fdb: factor out configured entry destination updates

Share the destination update logic used by user configured and ext learned
entries. Report a modification only when the port changes.

Signed-off-by: Nikolay Aleksandrov <razor@blackwall.org>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Link: https://patch.msgid.link/20261005143937.877466-6-razor@blackwall.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Nikolay Aleksandrov 2026-10-05 17:39:36 +03:00 committed by Jakub Kicinski
parent 1fbe2d9d37
commit d65082c8bf

View File

@ -1193,6 +1193,22 @@ static bool fdb_handle_notify(struct net_bridge_fdb_entry *fdb, u8 notify)
return modified;
}
static bool fdb_update_dst(struct net_bridge_fdb_entry *fdb,
struct net_bridge_dst old_dst,
struct net_bridge_dst dst)
{
if (br_dst_equal(old_dst, dst))
return false;
if (br_dst_port(old_dst) == br_dst_port(dst)) {
br_fdb_dst_replace(fdb, old_dst, dst);
return false;
}
br_fdb_dst_write(fdb, dst);
return true;
}
/* 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,
@ -1246,14 +1262,7 @@ static int fdb_add_entry(struct net_bridge *br, struct net_bridge_dst dst,
return -EEXIST;
old_dst = br_fdb_dst_read(fdb);
if (!br_dst_equal(old_dst, dst)) {
if (br_dst_port(old_dst) != source) {
modified = true;
br_fdb_dst_write(fdb, dst);
} else {
br_fdb_dst_replace(fdb, old_dst, dst);
}
}
modified = fdb_update_dst(fdb, old_dst, dst);
set_bit(BR_FDB_ADDED_BY_USER, &fdb->flags);
if (test_and_clear_bit(BR_FDB_DYNAMIC_LEARNED, &fdb->flags))
@ -1634,14 +1643,7 @@ int br_fdb_external_learn_add(struct net_bridge *br, struct net_bridge_port *p,
WRITE_ONCE(fdb->updated, jiffies);
if (!br_dst_equal(old_dst, dst)) {
if (br_dst_port(old_dst) != p) {
modified = true;
br_fdb_dst_write(fdb, dst);
} else {
br_fdb_dst_replace(fdb, old_dst, dst);
}
}
modified = fdb_update_dst(fdb, old_dst, dst);
if (test_and_set_bit(BR_FDB_ADDED_BY_EXT_LEARN, &fdb->flags)) {
/* Refresh entry */