bridge: mcast: Preparations for EVPN extensions
Subsystems (3)
Ido Schimmel
maintainerv2 cover bridge: mcast: Preparations for EVPN extensions
This patchset was split from [1] and includes non-functional changes aimed at making it easier to add additional netlink attributes later on. Future extensions are available here [2].
The idea behind these patches is to create an MDB configuration structure into which netlink messages are parsed into. The structure is then passed in the entry creation / deletion call chain instead of passing the netlink attributes themselves. The same pattern is used by other rtnetlink objects such as routes and nexthops.
I initially tried to extend the current code, but it proved to be too difficult, which is why I decided to refactor it to the extensible and familiar pattern used by other rtnetlink objects.
Tested using existing selftests and using a new selftest that will be submitted together with the planned extensions.
v2:
* Patch #1: Remove 'skb' argument from br_mdb_config_init().
* Patch #1: Mark 'nlh' argument as 'const'.
* Patch #4: Pass 'cfg' as 'const'.
* Patch #5: Pass 'cfg' as 'const'.
* Patch #9: New patch.
[1] https://lore.kernel.org/netdev/[email protected]/
[2] https://github.com/idosch/linux/commits/submit/mdb_v1
Ido Schimmel (9):
bridge: mcast: Centralize netlink attribute parsing
bridge: mcast: Remove redundant checks
bridge: mcast: Use MDB configuration structure where possible
bridge: mcast: Propagate MDB configuration structure further
bridge: mcast: Use MDB group key from configuration structure
bridge: mcast: Remove br_mdb_parse()
bridge: mcast: Move checks out of critical section
bridge: mcast: Remove redundant function arguments
bridge: mcast: Constify 'group' argument in
br_multicast_new_port_group()
net/bridge/br_mdb.c | 312 ++++++++++++++++++-------------------- net/bridge/br_multicast.c | 2 +- net/bridge/br_private.h | 10 +- 3 files changed, 159 insertions(+), 165 deletions(-)
Signature · 1 line
2.37.3
Ido Schimmel
maintainerPATCH v2 1/9 bridge: mcast: Centralize netlink attribute parsing
Netlink attributes are currently passed deep in the MDB creation call chain, making it difficult to add new attributes. In addition, some validity checks are performed under the multicast lock although they can be performed before it is ever acquired.
As a first step towards solving these issues, parse the RTM_{NEW,DEL}MDB messages into a configuration structure, relieving other functions from the need to handle raw netlink attributes.
Subsequent patches will convert the MDB code to use this configuration structure.
This is consistent with how other rtnetlink objects are handled, such as routes and nexthops.
---
Notes:
v2:
* Remove 'skb' argument from br_mdb_config_init()
* Mark 'nlh' argument as 'const'.
net/bridge/br_mdb.c | 120 ++++++++++++++++++++++++++++++++++++++++ net/bridge/br_private.h | 7 +++ 2 files changed, 127 insertions(+)
net/bridge/br_mdb.c +120 -0
@@ -974,6 +974,116 @@ static int __br_mdb_add(struct net *net, struct net_bridge *br,return ret; } +static int br_mdb_config_attrs_init (struct nlattr *set_attrs, +struct br_mdb_config *cfg, +struct netlink_ext_ack *extack) +{ +struct nlattr *mdb_attrs[MDBE_ATTR_MAX +1 ]; +int err; + + err =nla_parse_nested (mdb_attrs,MDBE_ATTR_MAX , set_attrs, + br_mdbe_attrs_pol, extack); +if (err) +return err; + +if (mdb_attrs[MDBE_ATTR_SOURCE ] && + !is_valid_mdb_source (mdb_attrs[MDBE_ATTR_SOURCE ], + cfg->entry->addr.proto, extack)) +return -EINVAL ; + +__mdb_entry_to_br_ip (cfg->entry, &cfg->group, mdb_attrs); + +return 0 ; +} + +static int br_mdb_config_init (struct net *net,const struct nlmsghdr *nlh, +struct br_mdb_config *cfg, +struct netlink_ext_ack *extack) +{ +struct nlattr *tb[MDBA_SET_ENTRY_MAX +1 ]; +struct br_port_msg *bpm; +struct net_device *dev; +int err; + + err =nlmsg_parse_deprecated (nlh,sizeof (*bpm), tb, +MDBA_SET_ENTRY_MAX ,NULL , extack); +if (err) +return err; + +memset (cfg,0 ,sizeof (*cfg)); + + bpm =nlmsg_data (nlh); +if (!bpm->ifindex) { +NL_SET_ERR_MSG_MOD (extack,"Invalid bridge ifindex" ); +return -EINVAL ; + } + + dev =__dev_get_by_index (net, bpm->ifindex); +if (!dev) { +NL_SET_ERR_MSG_MOD (extack,"Bridge device doesn't exist" ); +return -ENODEV ; + } + +if (!netif_is_bridge_master (dev)) { +NL_SET_ERR_MSG_MOD (extack,"Device is not a bridge" ); +return -EOPNOTSUPP ; + } + + cfg->br =netdev_priv (dev); + +if (!netif_running (cfg->br->dev)) { +NL_SET_ERR_MSG_MOD (extack,"Bridge device is not running" ); +return -EINVAL ; + } + +if (!br_opt_get (cfg->br,BROPT_MULTICAST_ENABLED )) { +NL_SET_ERR_MSG_MOD (extack,"Bridge's multicast processing is disabled" ); +return -EINVAL ; + } + +if (NL_REQ_ATTR_CHECK (extack,NULL , tb,MDBA_SET_ENTRY )) { +NL_SET_ERR_MSG_MOD (extack,"Missing MDBA_SET_ENTRY attribute" ); +return -EINVAL ; + } +if (nla_len (tb[MDBA_SET_ENTRY ]) !=sizeof (struct br_mdb_entry )) { +NL_SET_ERR_MSG_MOD (extack,"Invalid MDBA_SET_ENTRY attribute length" ); +return -EINVAL ; + } + + cfg->entry =nla_data (tb[MDBA_SET_ENTRY ]); +if (!is_valid_mdb_entry (cfg->entry, extack)) +return -EINVAL ; + +if (cfg->entry->ifindex != cfg->br->dev->ifindex) { +struct net_device *pdev; + + pdev =__dev_get_by_index (net, cfg->entry->ifindex); +if (!pdev) { +NL_SET_ERR_MSG_MOD (extack,"Port net device doesn't exist" ); +return -ENODEV ; + } + + cfg->p =br_port_get_rtnl (pdev); +if (!cfg->p) { +NL_SET_ERR_MSG_MOD (extack,"Net device is not a bridge port" ); +return -EINVAL ; + } + +if (cfg->p->br != cfg->br) { +NL_SET_ERR_MSG_MOD (extack,"Port belongs to a different bridge device" ); +return -EINVAL ; + } + } + +if (tb[MDBA_SET_ENTRY_ATTRS ]) +return br_mdb_config_attrs_init (tb[MDBA_SET_ENTRY_ATTRS ], cfg, + extack); +else +__mdb_entry_to_br_ip (cfg->entry, &cfg->group,NULL ); + +return 0 ; +} +static int br_mdb_add (struct sk_buff *skb,struct nlmsghdr *nlh,struct netlink_ext_ack *extack) {
@@ -984,9 +1094,14 @@ static int br_mdb_add(struct sk_buff *skb, struct nlmsghdr *nlh,struct net_device *dev, *pdev;struct br_mdb_entry *entry;struct net_bridge_vlan *v; +struct br_mdb_config cfg;struct net_bridge *br;int err; + err =br_mdb_config_init (net, nlh, &cfg, extack); +if (err) +return err; + err =br_mdb_parse (skb, nlh, &dev, &entry, mdb_attrs, extack);if (err <0 )return err;
@@ -1101,9 +1216,14 @@ static int br_mdb_del(struct sk_buff *skb, struct nlmsghdr *nlh,struct net_device *dev, *pdev;struct br_mdb_entry *entry;struct net_bridge_vlan *v; +struct br_mdb_config cfg;struct net_bridge *br;int err; + err =br_mdb_config_init (net, nlh, &cfg, extack); +if (err) +return err; + err =br_mdb_parse (skb, nlh, &dev, &entry, mdb_attrs, extack);if (err <0 )return err;
net/bridge/br_private.h +7 -0
@@ -92,6 +92,13 @@ struct bridge_mcast_stats {struct br_mcast_stats mstats; struct u64_stats_sync syncp; }; + +struct br_mdb_config { +struct net_bridge *br; +struct net_bridge_port *p; +struct br_mdb_entry *entry; +struct br_ip group; +};#endif /* net_bridge_mcast_port must be always defined due to forwarding stubs */
Signature · 1 line
2.37.3
Re: [PATCH net-next v2 1/9] bridge: mcast: Centralize netlink attribute parsing
Quoted 15 lines · Ido Schimmel
Netlink attributes are currently passed deep in the MDB creation call chain, making it difficult to add new attributes. In addition, some validity checks are performed under the multicast lock although they can be performed before it is ever acquired.
As a first step towards solving these issues, parse the RTM_{NEW,DEL}MDB messages into a configuration structure, relieving other functions from the need to handle raw netlink attributes.
Subsequent patches will convert the MDB code to use this configuration structure.
This is consistent with how other rtnetlink objects are handled, such as routes and nexthops.
Quoted 8 lines
Signed-off-by Ido Schimmel <[email protected]>---
Notes:
v2:
* Remove 'skb' argument frombr_mdb_config_init()
* Mark 'nlh' argument as 'const'.
Thanks,
Ido Schimmel
maintainerPATCH v2 2/9 bridge: mcast: Remove redundant checks
In reply to Ido SchimmelThese checks are now redundant as they are performed by br_mdb_config_init() while parsing the RTM_{NEW,DEL}MDB messages.
Remove them.
--- net/bridge/br_mdb.c | 63 +++++++-------------------------------------- 1 file changed, 9 insertions(+), 54 deletions(-)
net/bridge/br_mdb.c +9 -54
@@ -1090,11 +1090,10 @@ static int br_mdb_add(struct sk_buff *skb, struct nlmsghdr *nlh,struct nlattr *mdb_attrs[MDBE_ATTR_MAX +1 ];struct net *net =sock_net (skb->sk);struct net_bridge_vlan_group *vg; -struct net_bridge_port *p =NULL ; -struct net_device *dev, *pdev;struct br_mdb_entry *entry;struct net_bridge_vlan *v;struct br_mdb_config cfg; +struct net_device *dev;struct net_bridge *br;int err;
@@ -1108,38 +1107,12 @@ static int br_mdb_add(struct sk_buff *skb, struct nlmsghdr *nlh, br =netdev_priv (dev); -if (!netif_running (br->dev)) { -NL_SET_ERR_MSG_MOD (extack,"Bridge device is not running" ); -return -EINVAL ; - } - -if (!br_opt_get (br,BROPT_MULTICAST_ENABLED )) { -NL_SET_ERR_MSG_MOD (extack,"Bridge's multicast processing is disabled" ); -return -EINVAL ; - } -if (entry->ifindex != br->dev->ifindex) { - pdev =__dev_get_by_index (net, entry->ifindex); -if (!pdev) { -NL_SET_ERR_MSG_MOD (extack,"Port net device doesn't exist" ); -return -ENODEV ; - } - - p =br_port_get_rtnl (pdev); -if (!p) { -NL_SET_ERR_MSG_MOD (extack,"Net device is not a bridge port" ); -return -EINVAL ; - } - -if (p->br != br) { -NL_SET_ERR_MSG_MOD (extack,"Port belongs to a different bridge device" ); -return -EINVAL ; - } -if (p->state ==BR_STATE_DISABLED && entry->state !=MDB_PERMANENT ) { +if (cfg.p->state ==BR_STATE_DISABLED && entry->state !=MDB_PERMANENT ) {NL_SET_ERR_MSG_MOD (extack,"Port is in disabled state and entry is not permanent" );return -EINVAL ; } - vg =nbp_vlan_group (p); + vg =nbp_vlan_group (cfg.p); }else { vg =br_vlan_group (br); }
@@ -1150,12 +1123,12 @@ static int br_mdb_add(struct sk_buff *skb, struct nlmsghdr *nlh,if (br_vlan_enabled (br->dev) && vg && entry->vid ==0 ) {list_for_each_entry (v, &vg->vlan_list, vlist) { entry->vid = v->vid; - err =__br_mdb_add (net, br, p, entry, mdb_attrs, extack); + err =__br_mdb_add (net, br, cfg.p, entry, mdb_attrs, extack);if (err)break ; } }else { - err =__br_mdb_add (net, br, p, entry, mdb_attrs, extack); + err =__br_mdb_add (net, br, cfg.p, entry, mdb_attrs, extack); }return err;
@@ -1170,9 +1143,6 @@ static int __br_mdb_del(struct net_bridge *br, struct br_mdb_entry *entry,struct br_ip ip;int err = -EINVAL ; -if (!netif_running (br->dev) || !br_opt_get (br,BROPT_MULTICAST_ENABLED )) -return -EINVAL ; -__mdb_entry_to_br_ip (entry, &ip, mdb_attrs);spin_lock_bh (&br->multicast_lock);
@@ -1212,11 +1182,10 @@ static int br_mdb_del(struct sk_buff *skb, struct nlmsghdr *nlh,struct nlattr *mdb_attrs[MDBE_ATTR_MAX +1 ];struct net *net =sock_net (skb->sk);struct net_bridge_vlan_group *vg; -struct net_bridge_port *p =NULL ; -struct net_device *dev, *pdev;struct br_mdb_entry *entry;struct net_bridge_vlan *v;struct br_mdb_config cfg; +struct net_device *dev;struct net_bridge *br;int err;
@@ -1230,24 +1199,10 @@ static int br_mdb_del(struct sk_buff *skb, struct nlmsghdr *nlh, br =netdev_priv (dev); -if (entry->ifindex != br->dev->ifindex) { - pdev =__dev_get_by_index (net, entry->ifindex); -if (!pdev) -return -ENODEV ; - - p =br_port_get_rtnl (pdev); -if (!p) { -NL_SET_ERR_MSG_MOD (extack,"Net device is not a bridge port" ); -return -EINVAL ; - } -if (p->br != br) { -NL_SET_ERR_MSG_MOD (extack,"Port belongs to a different bridge device" ); -return -EINVAL ; - } - vg =nbp_vlan_group (p); - }else { +if (entry->ifindex != br->dev->ifindex) + vg =nbp_vlan_group (cfg.p); +else vg =br_vlan_group (br); - }/* If vlan filtering is enabled and VLAN is not specified * delete mdb entry on all vlans configured on the port.
Signature · 1 line
2.37.3
Ido Schimmel
maintainerPATCH v2 3/9 bridge: mcast: Use MDB configuration structure where possible
In reply to Ido SchimmelThe MDB configuration structure (i.e., struct br_mdb_config) now includes all the necessary information from the parsed RTM_{NEW,DEL}MDB netlink messages, so use it.
This will later allow us to delete the calls to br_mdb_parse() from br_mdb_add() and br_mdb_del().
No functional changes intended.
--- net/bridge/br_mdb.c | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-)
net/bridge/br_mdb.c +15 -19
@@ -1094,7 +1094,6 @@ static int br_mdb_add(struct sk_buff *skb, struct nlmsghdr *nlh,struct net_bridge_vlan *v;struct br_mdb_config cfg;struct net_device *dev; -struct net_bridge *br;int err; err =br_mdb_config_init (net, nlh, &cfg, extack);
@@ -1105,30 +1104,30 @@ static int br_mdb_add(struct sk_buff *skb, struct nlmsghdr *nlh,if (err <0 )return err; - br =netdev_priv (dev); - -if (entry->ifindex != br->dev->ifindex) { -if (cfg.p->state ==BR_STATE_DISABLED && entry->state !=MDB_PERMANENT ) { +if (cfg.p) { +if (cfg.p->state ==BR_STATE_DISABLED && cfg.entry->state !=MDB_PERMANENT ) {NL_SET_ERR_MSG_MOD (extack,"Port is in disabled state and entry is not permanent" );return -EINVAL ; } vg =nbp_vlan_group (cfg.p); }else { - vg =br_vlan_group (br); + vg =br_vlan_group (cfg.br); }/* If vlan filtering is enabled and VLAN is not specified * install mdb entry on all vlans configured on the port. */ -if (br_vlan_enabled (br->dev) && vg && entry->vid ==0 ) { +if (br_vlan_enabled (cfg.br->dev) && vg && cfg.entry->vid ==0 ) {list_for_each_entry (v, &vg->vlan_list, vlist) { - entry->vid = v->vid; - err =__br_mdb_add (net, br, cfg.p, entry, mdb_attrs, extack); + cfg.entry->vid = v->vid; + err =__br_mdb_add (net, cfg.br, cfg.p, cfg.entry, + mdb_attrs, extack);if (err)break ; } }else { - err =__br_mdb_add (net, br, cfg.p, entry, mdb_attrs, extack); + err =__br_mdb_add (net, cfg.br, cfg.p, cfg.entry, mdb_attrs, + extack); }return err;
@@ -1186,7 +1185,6 @@ static int br_mdb_del(struct sk_buff *skb, struct nlmsghdr *nlh,struct net_bridge_vlan *v;struct br_mdb_config cfg;struct net_device *dev; -struct net_bridge *br;int err; err =br_mdb_config_init (net, nlh, &cfg, extack);
@@ -1197,23 +1195,21 @@ static int br_mdb_del(struct sk_buff *skb, struct nlmsghdr *nlh,if (err <0 )return err; - br =netdev_priv (dev); - -if (entry->ifindex != br->dev->ifindex) +if (cfg.p) vg =nbp_vlan_group (cfg.p);else - vg =br_vlan_group (br); + vg =br_vlan_group (cfg.br);/* If vlan filtering is enabled and VLAN is not specified * delete mdb entry on all vlans configured on the port. */ -if (br_vlan_enabled (br->dev) && vg && entry->vid ==0 ) { +if (br_vlan_enabled (cfg.br->dev) && vg && cfg.entry->vid ==0 ) {list_for_each_entry (v, &vg->vlan_list, vlist) { - entry->vid = v->vid; - err =__br_mdb_del (br, entry, mdb_attrs); + cfg.entry->vid = v->vid; + err =__br_mdb_del (cfg.br, cfg.entry, mdb_attrs); } }else { - err =__br_mdb_del (br, entry, mdb_attrs); + err =__br_mdb_del (cfg.br, cfg.entry, mdb_attrs); }return err;
Signature · 1 line
2.37.3
Ido Schimmel
maintainerPATCH v2 4/9 bridge: mcast: Propagate MDB configuration structure further
In reply to Ido SchimmelAs an intermediate step towards only using the new MDB configuration structure, pass it further in the control path instead of passing individual attributes.
No functional changes intended.
---
Notes:
v2:
* Pass 'cfg' as 'const'.
net/bridge/br_mdb.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-)
net/bridge/br_mdb.c +11 -13
@@ -959,17 +959,15 @@ static int br_mdb_add_group(struct net_bridge *br, struct net_bridge_port *port,return 0 ; } -static int __br_mdb_add (struct net *net,struct net_bridge *br, -struct net_bridge_port *p, -struct br_mdb_entry *entry, +static int __br_mdb_add (const struct br_mdb_config *cfg,struct nlattr **mdb_attrs,struct netlink_ext_ack *extack) {int ret; -spin_lock_bh (&br->multicast_lock); - ret =br_mdb_add_group (br, p, entry, mdb_attrs, extack); -spin_unlock_bh (&br->multicast_lock); +spin_lock_bh (&cfg->br->multicast_lock); + ret =br_mdb_add_group (cfg->br, cfg->p, cfg->entry, mdb_attrs, extack); +spin_unlock_bh (&cfg->br->multicast_lock);return ret; }
@@ -1120,22 +1118,22 @@ static int br_mdb_add(struct sk_buff *skb, struct nlmsghdr *nlh,if (br_vlan_enabled (cfg.br->dev) && vg && cfg.entry->vid ==0 ) {list_for_each_entry (v, &vg->vlan_list, vlist) { cfg.entry->vid = v->vid; - err =__br_mdb_add (net, cfg.br, cfg.p, cfg.entry, - mdb_attrs, extack); + err =__br_mdb_add (&cfg, mdb_attrs, extack);if (err)break ; } }else { - err =__br_mdb_add (net, cfg.br, cfg.p, cfg.entry, mdb_attrs, - extack); + err =__br_mdb_add (&cfg, mdb_attrs, extack); }return err; } -static int __br_mdb_del (struct net_bridge *br,struct br_mdb_entry *entry, +static int __br_mdb_del (const struct br_mdb_config *cfg,struct nlattr **mdb_attrs) { +struct br_mdb_entry *entry = cfg->entry; +struct net_bridge *br = cfg->br;struct net_bridge_mdb_entry *mp;struct net_bridge_port_group *p;struct net_bridge_port_group __rcu **pp;
@@ -1206,10 +1204,10 @@ static int br_mdb_del(struct sk_buff *skb, struct nlmsghdr *nlh,if (br_vlan_enabled (cfg.br->dev) && vg && cfg.entry->vid ==0 ) {list_for_each_entry (v, &vg->vlan_list, vlist) { cfg.entry->vid = v->vid; - err =__br_mdb_del (cfg.br, cfg.entry, mdb_attrs); + err =__br_mdb_del (&cfg, mdb_attrs); } }else { - err =__br_mdb_del (cfg.br, cfg.entry, mdb_attrs); + err =__br_mdb_del (&cfg, mdb_attrs); }return err;
Signature · 1 line
2.37.3
Ido Schimmel
maintainerPATCH v2 5/9 bridge: mcast: Use MDB group key from configuration structure
In reply to Ido SchimmelThe MDB group key (i.e., {source, destination, protocol, VID}) is currently determined under the multicast lock from the netlink attributes. Instead, use the group key from the MDB configuration structure that was prepared before acquiring the lock.
No functional changes intended.
---
Notes:
v2:
* Pass 'cfg' as 'const'.
net/bridge/br_mdb.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
net/bridge/br_mdb.c +7 -8
@@ -855,20 +855,19 @@ __br_mdb_choose_context(struct net_bridge *br,static int br_mdb_add_group (struct net_bridge *br,struct net_bridge_port *port,struct br_mdb_entry *entry, -struct nlattr **mdb_attrs, +const struct br_mdb_config *cfg,struct netlink_ext_ack *extack) {struct net_bridge_mdb_entry *mp, *star_mp;struct net_bridge_port_group __rcu **pp;struct net_bridge_port_group *p;struct net_bridge_mcast *brmctx; -struct br_ip group, star_group; +struct br_ip group = cfg->group;unsigned long now = jiffies;unsigned char flags =0 ; +struct br_ip star_group;u8 filter_mode; -__mdb_entry_to_br_ip (entry, &group, mdb_attrs); - brmctx =__br_mdb_choose_context (br, entry, extack);if (!brmctx)return -EINVAL ;
@@ -966,7 +965,7 @@ static int __br_mdb_add(const struct br_mdb_config *cfg,int ret;spin_lock_bh (&cfg->br->multicast_lock); - ret =br_mdb_add_group (cfg->br, cfg->p, cfg->entry, mdb_attrs, extack); + ret =br_mdb_add_group (cfg->br, cfg->p, cfg->entry, cfg, extack);spin_unlock_bh (&cfg->br->multicast_lock);return ret;
@@ -1118,6 +1117,7 @@ static int br_mdb_add(struct sk_buff *skb, struct nlmsghdr *nlh,if (br_vlan_enabled (cfg.br->dev) && vg && cfg.entry->vid ==0 ) {list_for_each_entry (v, &vg->vlan_list, vlist) { cfg.entry->vid = v->vid; + cfg.group.vid = v->vid; err =__br_mdb_add (&cfg, mdb_attrs, extack);if (err)break ;
@@ -1137,11 +1137,9 @@ static int __br_mdb_del(const struct br_mdb_config *cfg,struct net_bridge_mdb_entry *mp;struct net_bridge_port_group *p;struct net_bridge_port_group __rcu **pp; -struct br_ip ip; +struct br_ip ip = cfg->group;int err = -EINVAL ; -__mdb_entry_to_br_ip (entry, &ip, mdb_attrs); -spin_lock_bh (&br->multicast_lock); mp =br_mdb_ip_get (br, &ip);if (!mp)
@@ -1204,6 +1202,7 @@ static int br_mdb_del(struct sk_buff *skb, struct nlmsghdr *nlh,if (br_vlan_enabled (cfg.br->dev) && vg && cfg.entry->vid ==0 ) {list_for_each_entry (v, &vg->vlan_list, vlist) { cfg.entry->vid = v->vid; + cfg.group.vid = v->vid; err =__br_mdb_del (&cfg, mdb_attrs); } }else {
Signature · 1 line
2.37.3
Ido Schimmel
maintainerPATCH v2 6/9 bridge: mcast: Remove br_mdb_parse()
In reply to Ido SchimmelThe parsing of the netlink messages and the validity checks are now performed in br_mdb_config_init() so we can remove br_mdb_parse().
This finally allows us to stop passing netlink attributes deep in the MDB control path and only use the MDB configuration structure.
--- net/bridge/br_mdb.c | 93 +++------------------------------------------ 1 file changed, 5 insertions(+), 88 deletions(-)
net/bridge/br_mdb.c +5 -88
@@ -754,73 +754,6 @@ static const struct nla_policy br_mdbe_attrs_pol[MDBE_ATTR_MAX + 1] = { sizeof(struct in6_addr)), }; -static int br_mdb_parse (struct sk_buff *skb,struct nlmsghdr *nlh, -struct net_device **pdev,struct br_mdb_entry **pentry, -struct nlattr **mdb_attrs,struct netlink_ext_ack *extack) -{ -struct net *net =sock_net (skb->sk); -struct br_mdb_entry *entry; -struct br_port_msg *bpm; -struct nlattr *tb[MDBA_SET_ENTRY_MAX +1 ]; -struct net_device *dev; -int err; - - err =nlmsg_parse_deprecated (nlh,sizeof (*bpm), tb, -MDBA_SET_ENTRY_MAX ,NULL ,NULL ); -if (err <0 ) -return err; - - bpm =nlmsg_data (nlh); -if (bpm->ifindex ==0 ) { -NL_SET_ERR_MSG_MOD (extack,"Invalid bridge ifindex" ); -return -EINVAL ; - } - - dev =__dev_get_by_index (net, bpm->ifindex); -if (dev ==NULL ) { -NL_SET_ERR_MSG_MOD (extack,"Bridge device doesn't exist" ); -return -ENODEV ; - } - -if (!netif_is_bridge_master (dev)) { -NL_SET_ERR_MSG_MOD (extack,"Device is not a bridge" ); -return -EOPNOTSUPP ; - } - - *pdev = dev; - -if (!tb[MDBA_SET_ENTRY ]) { -NL_SET_ERR_MSG_MOD (extack,"Missing MDBA_SET_ENTRY attribute" ); -return -EINVAL ; - } -if (nla_len (tb[MDBA_SET_ENTRY ]) !=sizeof (struct br_mdb_entry )) { -NL_SET_ERR_MSG_MOD (extack,"Invalid MDBA_SET_ENTRY attribute length" ); -return -EINVAL ; - } - - entry =nla_data (tb[MDBA_SET_ENTRY ]); -if (!is_valid_mdb_entry (entry, extack)) -return -EINVAL ; - *pentry = entry; - -if (tb[MDBA_SET_ENTRY_ATTRS ]) { - err =nla_parse_nested (mdb_attrs,MDBE_ATTR_MAX , - tb[MDBA_SET_ENTRY_ATTRS ], - br_mdbe_attrs_pol, extack); -if (err) -return err; -if (mdb_attrs[MDBE_ATTR_SOURCE ] && - !is_valid_mdb_source (mdb_attrs[MDBE_ATTR_SOURCE ], - entry->addr.proto, extack)) -return -EINVAL ; - }else { -memset (mdb_attrs,0 , -sizeof (struct nlattr *) * (MDBE_ATTR_MAX +1 )); - } - -return 0 ; -} -static struct net_bridge_mcast * __br_mdb_choose_context(struct net_bridge *br, const struct br_mdb_entry *entry,
@@ -959,7 +892,6 @@ static int br_mdb_add_group(struct net_bridge *br, struct net_bridge_port *port, }static int __br_mdb_add (const struct br_mdb_config *cfg, -struct nlattr **mdb_attrs,struct netlink_ext_ack *extack) {int ret;
@@ -1084,23 +1016,16 @@ static int br_mdb_config_init(struct net *net, const struct nlmsghdr *nlh,static int br_mdb_add (struct sk_buff *skb,struct nlmsghdr *nlh,struct netlink_ext_ack *extack) { -struct nlattr *mdb_attrs[MDBE_ATTR_MAX +1 ];struct net *net =sock_net (skb->sk);struct net_bridge_vlan_group *vg; -struct br_mdb_entry *entry;struct net_bridge_vlan *v;struct br_mdb_config cfg; -struct net_device *dev;int err; err =br_mdb_config_init (net, nlh, &cfg, extack);if (err)return err; - err =br_mdb_parse (skb, nlh, &dev, &entry, mdb_attrs, extack); -if (err <0 ) -return err; -if (cfg.p) {if (cfg.p->state ==BR_STATE_DISABLED && cfg.entry->state !=MDB_PERMANENT ) {NL_SET_ERR_MSG_MOD (extack,"Port is in disabled state and entry is not permanent" );
@@ -1118,19 +1043,18 @@ static int br_mdb_add(struct sk_buff *skb, struct nlmsghdr *nlh,list_for_each_entry (v, &vg->vlan_list, vlist) { cfg.entry->vid = v->vid; cfg.group.vid = v->vid; - err =__br_mdb_add (&cfg, mdb_attrs, extack); + err =__br_mdb_add (&cfg, extack);if (err)break ; } }else { - err =__br_mdb_add (&cfg, mdb_attrs, extack); + err =__br_mdb_add (&cfg, extack); }return err; } -static int __br_mdb_del (const struct br_mdb_config *cfg, -struct nlattr **mdb_attrs) +static int __br_mdb_del (const struct br_mdb_config *cfg) {struct br_mdb_entry *entry = cfg->entry;struct net_bridge *br = cfg->br;
@@ -1174,23 +1098,16 @@ static int __br_mdb_del(const struct br_mdb_config *cfg,static int br_mdb_del (struct sk_buff *skb,struct nlmsghdr *nlh,struct netlink_ext_ack *extack) { -struct nlattr *mdb_attrs[MDBE_ATTR_MAX +1 ];struct net *net =sock_net (skb->sk);struct net_bridge_vlan_group *vg; -struct br_mdb_entry *entry;struct net_bridge_vlan *v;struct br_mdb_config cfg; -struct net_device *dev;int err; err =br_mdb_config_init (net, nlh, &cfg, extack);if (err)return err; - err =br_mdb_parse (skb, nlh, &dev, &entry, mdb_attrs, extack); -if (err <0 ) -return err; -if (cfg.p) vg =nbp_vlan_group (cfg.p);else
@@ -1203,10 +1120,10 @@ static int br_mdb_del(struct sk_buff *skb, struct nlmsghdr *nlh,list_for_each_entry (v, &vg->vlan_list, vlist) { cfg.entry->vid = v->vid; cfg.group.vid = v->vid; - err =__br_mdb_del (&cfg, mdb_attrs); + err =__br_mdb_del (&cfg); } }else { - err =__br_mdb_del (&cfg, mdb_attrs); + err =__br_mdb_del (&cfg); }return err;
Signature · 1 line
2.37.3
Ido Schimmel
maintainerPATCH v2 7/9 bridge: mcast: Move checks out of critical section
In reply to Ido SchimmelThe checks only require information parsed from the RTM_NEWMDB netlink message and do not rely on any state stored in the bridge driver. Therefore, there is no need to perform the checks in the critical section under the multicast lock.
Move the checks out of the critical section.
--- net/bridge/br_mdb.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-)
net/bridge/br_mdb.c +18 -18
@@ -805,24 +805,6 @@ static int br_mdb_add_group(struct net_bridge *br, struct net_bridge_port *port,if (!brmctx)return -EINVAL ; -/* host join errors which can happen before creating the group */ -if (!port && !br_group_is_l2 (&group)) { -/* don't allow any flags for host-joined IP groups */ -if (entry->state) { -NL_SET_ERR_MSG_MOD (extack,"Flags are not allowed for host groups" ); -return -EINVAL ; - } -if (!br_multicast_is_star_g (&group)) { -NL_SET_ERR_MSG_MOD (extack,"Groups with sources cannot be manually host joined" ); -return -EINVAL ; - } - } - -if (br_group_is_l2 (&group) && entry->state !=MDB_PERMANENT ) { -NL_SET_ERR_MSG_MOD (extack,"Only permanent L2 entries allowed" ); -return -EINVAL ; - } - mp =br_multicast_new_group (br, &group);if (IS_ERR (mp))return PTR_ERR (mp);
@@ -1026,6 +1008,24 @@ static int br_mdb_add(struct sk_buff *skb, struct nlmsghdr *nlh,if (err)return err; +/* host join errors which can happen before creating the group */ +if (!cfg.p && !br_group_is_l2 (&cfg.group)) { +/* don't allow any flags for host-joined IP groups */ +if (cfg.entry->state) { +NL_SET_ERR_MSG_MOD (extack,"Flags are not allowed for host groups" ); +return -EINVAL ; + } +if (!br_multicast_is_star_g (&cfg.group)) { +NL_SET_ERR_MSG_MOD (extack,"Groups with sources cannot be manually host joined" ); +return -EINVAL ; + } + } + +if (br_group_is_l2 (&cfg.group) && cfg.entry->state !=MDB_PERMANENT ) { +NL_SET_ERR_MSG_MOD (extack,"Only permanent L2 entries allowed" ); +return -EINVAL ; + } +if (cfg.p) {if (cfg.p->state ==BR_STATE_DISABLED && cfg.entry->state !=MDB_PERMANENT ) {NL_SET_ERR_MSG_MOD (extack,"Port is in disabled state and entry is not permanent" );
Signature · 1 line
2.37.3
Ido Schimmel
maintainerPATCH v2 8/9 bridge: mcast: Remove redundant function arguments
In reply to Ido SchimmelDrop the first three arguments and instead extract them from the MDB configuration structure.
--- net/bridge/br_mdb.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
net/bridge/br_mdb.c +5 -4
@@ -786,13 +786,14 @@ __br_mdb_choose_context(struct net_bridge *br,return brmctx; } -static int br_mdb_add_group (struct net_bridge *br,struct net_bridge_port *port, -struct br_mdb_entry *entry, -const struct br_mdb_config *cfg, +static int br_mdb_add_group (const struct br_mdb_config *cfg,struct netlink_ext_ack *extack) {struct net_bridge_mdb_entry *mp, *star_mp;struct net_bridge_port_group __rcu **pp; +struct br_mdb_entry *entry = cfg->entry; +struct net_bridge_port *port = cfg->p; +struct net_bridge *br = cfg->br;struct net_bridge_port_group *p;struct net_bridge_mcast *brmctx;struct br_ip group = cfg->group;
@@ -879,7 +880,7 @@ static int __br_mdb_add(const struct br_mdb_config *cfg,int ret;spin_lock_bh (&cfg->br->multicast_lock); - ret =br_mdb_add_group (cfg->br, cfg->p, cfg->entry, cfg, extack); + ret =br_mdb_add_group (cfg, extack);spin_unlock_bh (&cfg->br->multicast_lock);return ret;
Signature · 1 line
2.37.3
Ido Schimmel
maintainerPATCH v2 9/9 bridge: mcast: Constify 'group' argument in br_multicast_new_port_group()
In reply to Ido SchimmelThe 'group' argument is not modified, so mark it as 'const'. It will allow us to constify arguments of the callers of this function in future patches.
---
Notes:
v2:
* New patch.
net/bridge/br_multicast.c | 2 +- net/bridge/br_private.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-)
net/bridge/br_multicast.c +1 -1
@@ -1273,7 +1273,7 @@ br_multicast_new_group_src(struct net_bridge_port_group *pg, struct br_ip *src_i struct net_bridge_port_group *br_multicast_new_port_group( struct net_bridge_port *port, - struct br_ip *group, + const struct br_ip *group, struct net_bridge_port_group __rcu *next, unsigned char flags, const unsigned char *src,
net/bridge/br_private.h +2 -1
@@ -941,7 +941,8 @@ br_mdb_ip_get(struct net_bridge *br, struct br_ip *dst);struct net_bridge_mdb_entry *br_multicast_new_group (struct net_bridge *br,struct br_ip *group);struct net_bridge_port_group * -br_multicast_new_port_group (struct net_bridge_port *port,struct br_ip *group, +br_multicast_new_port_group (struct net_bridge_port *port, +const struct br_ip *group,struct net_bridge_port_group __rcu *next,unsigned char flags,const unsigned char *src,u8 filter_mode,u8 rt_protocol);
Signature · 1 line
2.37.3
Re: [PATCH net-next v2 9/9] bridge: mcast: Constify 'group' argument in br_multicast_new_port_group()
Quoted 7 lines · Ido Schimmel
The 'group' argument is not modified, so mark it as 'const'. It will allow us to constify arguments of the callers of this function in future patches.
Signed-off-by Ido Schimmel <[email protected]>---
Quoted 8 lines
Notes:
v2:
* New patch.net/bridge/br_multicast.c | 2 +- net/bridge/br_private.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-)
Nice, that's even less than I anticipated. :)
This series was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:
Quoted 11 lines · On Tue, 6 Dec 2022 12:58:00 +0200 you wrote:
This patchset was split from [1] and includes non-functional changes aimed at making it easier to add additional netlink attributes later on. Future extensions are available here [2].
The idea behind these patches is to create an MDB configuration structure into which netlink messages are parsed into. The structure is then passed in the entry creation / deletion call chain instead of passing the netlink attributes themselves. The same pattern is used by other rtnetlink objects such as routes and nexthops.
[...]
Here is the summary with links:
- [net-next,v2,1/9] bridge: mcast: Centralize netlink attribute parsing
https://git.kernel.org/netdev/net-next/c/cb453926865e - [net-next,v2,2/9] bridge: mcast: Remove redundant checks https://git.kernel.org/netdev/net-next/c/386611681524 - [net-next,v2,3/9] bridge: mcast: Use MDB configuration structure where possible https://git.kernel.org/netdev/net-next/c/f2b5aac68117 - [net-next,v2,4/9] bridge: mcast: Propagate MDB configuration structure further https://git.kernel.org/netdev/net-next/c/8bd9c08e3241 - [net-next,v2,5/9] bridge: mcast: Use MDB group key from configuration structure https://git.kernel.org/netdev/net-next/c/9f52a5142979 - [net-next,v2,6/9] bridge: mcast: Remove br_mdb_parse() https://git.kernel.org/netdev/net-next/c/3ee5662345f2 - [net-next,v2,7/9] bridge: mcast: Move checks out of critical section https://git.kernel.org/netdev/net-next/c/4c1ebc6c1f21 - [net-next,v2,8/9] bridge: mcast: Remove redundant function arguments https://git.kernel.org/netdev/net-next/c/090149eaf391 - [net-next,v2,9/9] bridge: mcast: Constify 'group' argument in br_multicast_new_port_group() https://git.kernel.org/netdev/net-next/c/f86c3e2c1b5e
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html