On Sun, Oct 09, 2022 at 07:40:45PM +0200, Hans J. Schultz wrote:
@@ -1018,8 +1020,9 @@ static bool fdb_handle_notify(struct net_bridge_fdb_entry *fdb, u8 notify) /* Update (create or replace) forwarding database entry */ static int fdb_add_entry(struct net_bridge *br, struct net_bridge_port *source, const u8 *addr, struct ndmsg *ndm, u16 flags, u16 vid,
struct nlattr *nfea_tb[])
u32 ext_flags, struct nlattr *nfea_tb[])
{
- bool blackhole = !!(ext_flags & NTF_EXT_BLACKHOLE); bool is_sticky = !!(ndm->ndm_flags & NTF_STICKY); bool refresh = !nfea_tb[NFEA_DONT_REFRESH]; struct net_bridge_fdb_entry *fdb;
@@ -1092,6 +1095,14 @@ static int fdb_add_entry(struct net_bridge *br, struct net_bridge_port *source, modified = true; }
- if (blackhole != test_bit(BR_FDB_BLACKHOLE, &fdb->flags)) {
change_bit(BR_FDB_BLACKHOLE, &fdb->flags);
modified = true;
- }
- if (blackhole)
set_bit(BR_FDB_LOCAL, &fdb->flags);
We should instead validate earlier that NTF_EXT_BLACKHOLE is only specified with NUD_PERMANENT. See more below.
- if (test_and_clear_bit(BR_FDB_LOCKED, &fdb->flags)) modified = true;
@@ -1113,7 +1124,7 @@ static int fdb_add_entry(struct net_bridge *br, struct net_bridge_port *source, static int __br_fdb_add(struct ndmsg *ndm, struct net_bridge *br, struct net_bridge_port *p, const unsigned char *addr, u16 nlh_flags, u16 vid, struct nlattr *nfea_tb[],
struct netlink_ext_ack *extack)
u32 ext_flags, struct netlink_ext_ack *extack)
{ int err = 0; @@ -1138,9 +1149,12 @@ static int __br_fdb_add(struct ndmsg *ndm, struct net_bridge *br, return -EINVAL; } err = br_fdb_external_learn_add(br, p, addr, vid, true);
- } else if ((ext_flags & NTF_EXT_BLACKHOLE) && p) {
NL_SET_ERR_MSG_MOD(extack, "Blackhole FDB entry cannot be applied on a port");
return -EINVAL;
This is too late. I can do:
# bridge fdb add 00:aa:bb:cc:dd:ee dev dummy1 master extern_learn blackhole # bridge fdb get 00:aa:bb:cc:dd:ee br br0 00:aa:bb:cc:dd:ee dev dummy1 extern_learn master br0
Nothing will explode, but it's not ideal either.
Since we force blackhole entries to be permanent they cannot be aged by the kernel. I'm not sure what is the use case for user space adding externally learned blackhole entries.
How about:
diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c index d6f22e2e018a..9257a46544dd 100644 --- a/net/bridge/br_fdb.c +++ b/net/bridge/br_fdb.c @@ -1100,9 +1100,6 @@ static int fdb_add_entry(struct net_bridge *br, struct net_bridge_port *source, modified = true; }
- if (blackhole) - set_bit(BR_FDB_LOCAL, &fdb->flags); - if (test_and_clear_bit(BR_FDB_LOCKED, &fdb->flags)) modified = true;
@@ -1149,9 +1146,6 @@ static int __br_fdb_add(struct ndmsg *ndm, struct net_bridge *br, return -EINVAL; } err = br_fdb_external_learn_add(br, p, addr, vid, false, false, false, true); - } else if ((ext_flags & NTF_EXT_BLACKHOLE) && p) { - NL_SET_ERR_MSG_MOD(extack, "Blackhole FDB entry cannot be applied on a port"); - return -EINVAL; } else { spin_lock_bh(&br->hash_lock); err = fdb_add_entry(br, p, addr, ndm, nlh_flags, vid, ext_flags, nfea_tb); @@ -1214,6 +1208,21 @@ int br_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], return -EINVAL; }
+ if (ext_flags & NTF_EXT_BLACKHOLE) { + if (!(ndm->ndm_state & NUD_PERMANENT)) { + NL_SET_ERR_MSG_MOD(extack, "Blackhole FDB entry must be permanent"); + return -EINVAL; + } + if (p) { + NL_SET_ERR_MSG_MOD(extack, "Blackhole FDB entry cannot be applied on a port"); + return -EINVAL; + } + if (ndm->ndm_flags & NTF_EXT_LEARNED) { + NL_SET_ERR_MSG_MOD(extack, "Blackhole FDB entry cannot be added as externally learned"); + return -EINVAL; + } + } + if (tb[NDA_FDB_EXT_ATTRS]) { attr = tb[NDA_FDB_EXT_ATTRS]; err = nla_parse_nested(nfea_tb, NFEA_MAX, attr,
With which I get:
# bridge fdb add 00:aa:bb:cc:dd:ee dev dummy1 master extern_learn blackhole Error: bridge: Blackhole FDB entry cannot be applied on a port.
# bridge fdb add 00:aa:bb:cc:dd:ee dev br0 self extern_learn blackhole Error: bridge: Blackhole FDB entry cannot be added as externally learned.
} else { spin_lock_bh(&br->hash_lock);
err = fdb_add_entry(br, p, addr, ndm, nlh_flags, vid, nfea_tb);
spin_unlock_bh(&br->hash_lock); }err = fdb_add_entry(br, p, addr, ndm, nlh_flags, vid, ext_flags, nfea_tb);
@@ -1219,10 +1233,10 @@ int br_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], /* VID was specified, so use it. */ err = __br_fdb_add(ndm, br, p, addr, nlh_flags, vid, nfea_tb,
extack);
} else { err = __br_fdb_add(ndm, br, p, addr, nlh_flags, 0, nfea_tb,ext_flags, extack);
extack);
if (err || !vg || !vg->num_vlans) goto out;ext_flags, extack);
@@ -1234,7 +1248,7 @@ int br_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], if (!br_vlan_should_use(v)) continue; err = __br_fdb_add(ndm, br, p, addr, nlh_flags, v->vid,
nfea_tb, extack);
}nfea_tb, ext_flags, extack); if (err) goto out;
diff --git a/net/bridge/br_input.c b/net/bridge/br_input.c index 068fced7693c..665d1d6bdc75 100644 --- a/net/bridge/br_input.c +++ b/net/bridge/br_input.c @@ -193,8 +193,11 @@ int br_handle_frame_finish(struct net *net, struct sock *sk, struct sk_buff *skb if (dst) { unsigned long now = jiffies;
if (test_bit(BR_FDB_LOCAL, &dst->flags))
if (test_bit(BR_FDB_LOCAL, &dst->flags)) {
if (unlikely(test_bit(BR_FDB_BLACKHOLE, &dst->flags)))
goto drop; return br_pass_frame_up(skb);
}
if (now != dst->used) dst->used = now; diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h index 4ce8b8e5ae0b..e7a08657c7ed 100644 --- a/net/bridge/br_private.h +++ b/net/bridge/br_private.h @@ -253,6 +253,7 @@ enum { BR_FDB_NOTIFY, BR_FDB_NOTIFY_INACTIVE, BR_FDB_LOCKED,
- BR_FDB_BLACKHOLE,
}; struct net_bridge_fdb_key { diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 8008ceb45605..ae641dfea5f2 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -4054,7 +4054,7 @@ int ndo_dflt_fdb_add(struct ndmsg *ndm, if (tb[NDA_FLAGS_EXT]) ext_flags = nla_get_u32(tb[NDA_FLAGS_EXT]);
- if (ext_flags & NTF_EXT_LOCKED) {
- if (ext_flags & (NTF_EXT_LOCKED | NTF_EXT_BLACKHOLE)) { netdev_info(dev, "invalid flags given to default FDB implementation\n"); return err; }
-- 2.34.1