Skip to content

Commit 1d7b66a

Browse files
idoschkuba-moo
authored andcommitted
bridge: mcast: Allow user space to specify MDB entry routing protocol
Add the 'MDBE_ATTR_RTPORT' attribute to allow user space to specify the routing protocol of the MDB port group entry. Enforce a minimum value of 'RTPROT_STATIC' to prevent user space from using protocol values that should only be set by the kernel (e.g., 'RTPROT_KERNEL'). Maintain backward compatibility by defaulting to 'RTPROT_STATIC'. The protocol is already visible to user space in RTM_NEWMDB responses and notifications via the 'MDBA_MDB_EATTR_RTPROT' attribute. The routing protocol allows a routing daemon to distinguish between entries configured by it and those configured by the administrator. Once MDB flush is supported, the protocol can be used as a criterion according to which the flush is performed. Examples: # bridge mdb add dev br0 port dummy10 grp 239.1.1.1 permanent proto kernel Error: integer out of range. # bridge mdb add dev br0 port dummy10 grp 239.1.1.1 permanent proto static # bridge mdb add dev br0 port dummy10 grp 239.1.1.1 src 192.0.2.1 permanent proto zebra # bridge mdb add dev br0 port dummy10 grp 239.1.1.2 permanent source_list 198.51.100.1,198.51.100.2 filter_mode include proto 250 # bridge -d mdb show dev br0 port dummy10 grp 239.1.1.2 src 198.51.100.2 permanent filter_mode include proto 250 dev br0 port dummy10 grp 239.1.1.2 src 198.51.100.1 permanent filter_mode include proto 250 dev br0 port dummy10 grp 239.1.1.2 permanent filter_mode include source_list 198.51.100.2/0.00,198.51.100.1/0.00 proto 250 dev br0 port dummy10 grp 239.1.1.1 src 192.0.2.1 permanent filter_mode include proto zebra dev br0 port dummy10 grp 239.1.1.1 permanent filter_mode exclude proto static Signed-off-by: Ido Schimmel <[email protected]> Acked-by: Nikolay Aleksandrov <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 6afaae6 commit 1d7b66a

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

include/uapi/linux/if_bridge.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,7 @@ enum {
725725
MDBE_ATTR_SOURCE,
726726
MDBE_ATTR_SRC_LIST,
727727
MDBE_ATTR_GROUP_MODE,
728+
MDBE_ATTR_RTPROT,
728729
__MDBE_ATTR_MAX,
729730
};
730731
#define MDBE_ATTR_MAX (__MDBE_ATTR_MAX - 1)

net/bridge/br_mdb.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,7 @@ static const struct nla_policy br_mdbe_attrs_pol[MDBE_ATTR_MAX + 1] = {
682682
[MDBE_ATTR_GROUP_MODE] = NLA_POLICY_RANGE(NLA_U8, MCAST_EXCLUDE,
683683
MCAST_INCLUDE),
684684
[MDBE_ATTR_SRC_LIST] = NLA_POLICY_NESTED(br_mdbe_src_list_pol),
685+
[MDBE_ATTR_RTPROT] = NLA_POLICY_MIN(NLA_U8, RTPROT_STATIC),
685686
};
686687

687688
static bool is_valid_mdb_entry(struct br_mdb_entry *entry,
@@ -823,7 +824,7 @@ static int br_mdb_add_group_sg(const struct br_mdb_config *cfg,
823824
}
824825

825826
p = br_multicast_new_port_group(cfg->p, &cfg->group, *pp, flags, NULL,
826-
MCAST_INCLUDE, RTPROT_STATIC);
827+
MCAST_INCLUDE, cfg->rt_protocol);
827828
if (unlikely(!p)) {
828829
NL_SET_ERR_MSG_MOD(extack, "Couldn't allocate new (S, G) port group");
829830
return -ENOMEM;
@@ -881,6 +882,7 @@ static int br_mdb_add_group_src_fwd(const struct br_mdb_config *cfg,
881882
sg_cfg.group = sg_ip;
882883
sg_cfg.src_entry = true;
883884
sg_cfg.filter_mode = MCAST_INCLUDE;
885+
sg_cfg.rt_protocol = cfg->rt_protocol;
884886
return br_mdb_add_group_sg(&sg_cfg, sgmp, brmctx, flags, extack);
885887
}
886888

@@ -982,7 +984,7 @@ static int br_mdb_add_group_star_g(const struct br_mdb_config *cfg,
982984
}
983985

984986
p = br_multicast_new_port_group(cfg->p, &cfg->group, *pp, flags, NULL,
985-
cfg->filter_mode, RTPROT_STATIC);
987+
cfg->filter_mode, cfg->rt_protocol);
986988
if (unlikely(!p)) {
987989
NL_SET_ERR_MSG_MOD(extack, "Couldn't allocate new (*, G) port group");
988990
return -ENOMEM;
@@ -1193,6 +1195,14 @@ static int br_mdb_config_attrs_init(struct nlattr *set_attrs,
11931195
return -EINVAL;
11941196
}
11951197

1198+
if (mdb_attrs[MDBE_ATTR_RTPROT]) {
1199+
if (!cfg->p) {
1200+
NL_SET_ERR_MSG_MOD(extack, "Protocol cannot be set for host groups");
1201+
return -EINVAL;
1202+
}
1203+
cfg->rt_protocol = nla_get_u8(mdb_attrs[MDBE_ATTR_RTPROT]);
1204+
}
1205+
11961206
return 0;
11971207
}
11981208

@@ -1212,6 +1222,7 @@ static int br_mdb_config_init(struct net *net, const struct nlmsghdr *nlh,
12121222

12131223
memset(cfg, 0, sizeof(*cfg));
12141224
cfg->filter_mode = MCAST_EXCLUDE;
1225+
cfg->rt_protocol = RTPROT_STATIC;
12151226

12161227
bpm = nlmsg_data(nlh);
12171228
if (!bpm->ifindex) {

net/bridge/br_private.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ struct br_mdb_config {
106106
u8 filter_mode;
107107
struct br_mdb_src_entry *src_entries;
108108
int num_src_entries;
109+
u8 rt_protocol;
109110
};
110111
#endif
111112

0 commit comments

Comments
 (0)