Commit 1d7b66a7 authored by Ido Schimmel's avatar Ido Schimmel Committed by Jakub Kicinski

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: default avatarIdo Schimmel <idosch@nvidia.com>
Acked-by: default avatarNikolay Aleksandrov <razor@blackwall.org>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 6afaae6d
...@@ -725,6 +725,7 @@ enum { ...@@ -725,6 +725,7 @@ enum {
MDBE_ATTR_SOURCE, MDBE_ATTR_SOURCE,
MDBE_ATTR_SRC_LIST, MDBE_ATTR_SRC_LIST,
MDBE_ATTR_GROUP_MODE, MDBE_ATTR_GROUP_MODE,
MDBE_ATTR_RTPROT,
__MDBE_ATTR_MAX, __MDBE_ATTR_MAX,
}; };
#define MDBE_ATTR_MAX (__MDBE_ATTR_MAX - 1) #define MDBE_ATTR_MAX (__MDBE_ATTR_MAX - 1)
......
...@@ -682,6 +682,7 @@ static const struct nla_policy br_mdbe_attrs_pol[MDBE_ATTR_MAX + 1] = { ...@@ -682,6 +682,7 @@ static const struct nla_policy br_mdbe_attrs_pol[MDBE_ATTR_MAX + 1] = {
[MDBE_ATTR_GROUP_MODE] = NLA_POLICY_RANGE(NLA_U8, MCAST_EXCLUDE, [MDBE_ATTR_GROUP_MODE] = NLA_POLICY_RANGE(NLA_U8, MCAST_EXCLUDE,
MCAST_INCLUDE), MCAST_INCLUDE),
[MDBE_ATTR_SRC_LIST] = NLA_POLICY_NESTED(br_mdbe_src_list_pol), [MDBE_ATTR_SRC_LIST] = NLA_POLICY_NESTED(br_mdbe_src_list_pol),
[MDBE_ATTR_RTPROT] = NLA_POLICY_MIN(NLA_U8, RTPROT_STATIC),
}; };
static bool is_valid_mdb_entry(struct br_mdb_entry *entry, 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, ...@@ -823,7 +824,7 @@ static int br_mdb_add_group_sg(const struct br_mdb_config *cfg,
} }
p = br_multicast_new_port_group(cfg->p, &cfg->group, *pp, flags, NULL, p = br_multicast_new_port_group(cfg->p, &cfg->group, *pp, flags, NULL,
MCAST_INCLUDE, RTPROT_STATIC); MCAST_INCLUDE, cfg->rt_protocol);
if (unlikely(!p)) { if (unlikely(!p)) {
NL_SET_ERR_MSG_MOD(extack, "Couldn't allocate new (S, G) port group"); NL_SET_ERR_MSG_MOD(extack, "Couldn't allocate new (S, G) port group");
return -ENOMEM; return -ENOMEM;
...@@ -881,6 +882,7 @@ static int br_mdb_add_group_src_fwd(const struct br_mdb_config *cfg, ...@@ -881,6 +882,7 @@ static int br_mdb_add_group_src_fwd(const struct br_mdb_config *cfg,
sg_cfg.group = sg_ip; sg_cfg.group = sg_ip;
sg_cfg.src_entry = true; sg_cfg.src_entry = true;
sg_cfg.filter_mode = MCAST_INCLUDE; sg_cfg.filter_mode = MCAST_INCLUDE;
sg_cfg.rt_protocol = cfg->rt_protocol;
return br_mdb_add_group_sg(&sg_cfg, sgmp, brmctx, flags, extack); return br_mdb_add_group_sg(&sg_cfg, sgmp, brmctx, flags, extack);
} }
...@@ -982,7 +984,7 @@ static int br_mdb_add_group_star_g(const struct br_mdb_config *cfg, ...@@ -982,7 +984,7 @@ static int br_mdb_add_group_star_g(const struct br_mdb_config *cfg,
} }
p = br_multicast_new_port_group(cfg->p, &cfg->group, *pp, flags, NULL, p = br_multicast_new_port_group(cfg->p, &cfg->group, *pp, flags, NULL,
cfg->filter_mode, RTPROT_STATIC); cfg->filter_mode, cfg->rt_protocol);
if (unlikely(!p)) { if (unlikely(!p)) {
NL_SET_ERR_MSG_MOD(extack, "Couldn't allocate new (*, G) port group"); NL_SET_ERR_MSG_MOD(extack, "Couldn't allocate new (*, G) port group");
return -ENOMEM; return -ENOMEM;
...@@ -1193,6 +1195,14 @@ static int br_mdb_config_attrs_init(struct nlattr *set_attrs, ...@@ -1193,6 +1195,14 @@ static int br_mdb_config_attrs_init(struct nlattr *set_attrs,
return -EINVAL; return -EINVAL;
} }
if (mdb_attrs[MDBE_ATTR_RTPROT]) {
if (!cfg->p) {
NL_SET_ERR_MSG_MOD(extack, "Protocol cannot be set for host groups");
return -EINVAL;
}
cfg->rt_protocol = nla_get_u8(mdb_attrs[MDBE_ATTR_RTPROT]);
}
return 0; return 0;
} }
...@@ -1212,6 +1222,7 @@ static int br_mdb_config_init(struct net *net, const struct nlmsghdr *nlh, ...@@ -1212,6 +1222,7 @@ static int br_mdb_config_init(struct net *net, const struct nlmsghdr *nlh,
memset(cfg, 0, sizeof(*cfg)); memset(cfg, 0, sizeof(*cfg));
cfg->filter_mode = MCAST_EXCLUDE; cfg->filter_mode = MCAST_EXCLUDE;
cfg->rt_protocol = RTPROT_STATIC;
bpm = nlmsg_data(nlh); bpm = nlmsg_data(nlh);
if (!bpm->ifindex) { if (!bpm->ifindex) {
......
...@@ -106,6 +106,7 @@ struct br_mdb_config { ...@@ -106,6 +106,7 @@ struct br_mdb_config {
u8 filter_mode; u8 filter_mode;
struct br_mdb_src_entry *src_entries; struct br_mdb_src_entry *src_entries;
int num_src_entries; int num_src_entries;
u8 rt_protocol;
}; };
#endif #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment