From: Nikolay Aleksandrov <razor@blackwall.org>
To: netdev@vger.kernel.org
Cc: bridge@lists.linux-foundation.org,
Nikolay Aleksandrov <nikolay@nvidia.com>,
roopa@nvidia.com
Subject: [Bridge] [PATCH net-next 14/15] net: bridge: vlan: notify when global options change
Date: Mon, 19 Jul 2021 20:06:36 +0300 [thread overview]
Message-ID: <20210719170637.435541-15-razor@blackwall.org> (raw)
In-Reply-To: <20210719170637.435541-1-razor@blackwall.org>
From: Nikolay Aleksandrov <nikolay@nvidia.com>
Add support for global options notifications. They use only RTM_NEWVLAN
since global options can only be set and are contained in a separate
vlan global options attribute. Notifications are compressed in ranges
where possible, i.e. the sequential vlan options are equal.
Signed-off-by: Nikolay Aleksandrov <nikolay@nvidia.com>
---
net/bridge/br_vlan_options.c | 80 +++++++++++++++++++++++++++++++++++-
1 file changed, 79 insertions(+), 1 deletion(-)
diff --git a/net/bridge/br_vlan_options.c b/net/bridge/br_vlan_options.c
index f290f5140547..827bfc319599 100644
--- a/net/bridge/br_vlan_options.c
+++ b/net/bridge/br_vlan_options.c
@@ -290,6 +290,57 @@ bool br_vlan_global_opts_fill(struct sk_buff *skb, u16 vid, u16 vid_range,
return false;
}
+static size_t rtnl_vlan_global_opts_nlmsg_size(void)
+{
+ return NLMSG_ALIGN(sizeof(struct br_vlan_msg))
+ + nla_total_size(0) /* BRIDGE_VLANDB_GLOBAL_OPTIONS */
+ + nla_total_size(sizeof(u16)) /* BRIDGE_VLANDB_GOPTS_ID */
+ + nla_total_size(sizeof(u16)); /* BRIDGE_VLANDB_GOPTS_RANGE */
+}
+
+static void br_vlan_global_opts_notify(const struct net_bridge *br,
+ u16 vid, u16 vid_range)
+{
+ struct net_bridge_vlan *v;
+ struct br_vlan_msg *bvm;
+ struct nlmsghdr *nlh;
+ struct sk_buff *skb;
+ int err = -ENOBUFS;
+
+ /* right now notifications are done only with rtnl held */
+ ASSERT_RTNL();
+
+ skb = nlmsg_new(rtnl_vlan_global_opts_nlmsg_size(), GFP_KERNEL);
+ if (!skb)
+ goto out_err;
+
+ err = -EMSGSIZE;
+ nlh = nlmsg_put(skb, 0, 0, RTM_NEWVLAN, sizeof(*bvm), 0);
+ if (!nlh)
+ goto out_err;
+ bvm = nlmsg_data(nlh);
+ memset(bvm, 0, sizeof(*bvm));
+ bvm->family = AF_BRIDGE;
+ bvm->ifindex = br->dev->ifindex;
+
+ /* need to find the vlan due to flags/options */
+ v = br_vlan_find(br_vlan_group(br), vid);
+ if (!v)
+ goto out_kfree;
+
+ if (!br_vlan_global_opts_fill(skb, vid, vid_range, v))
+ goto out_err;
+
+ nlmsg_end(skb, nlh);
+ rtnl_notify(skb, dev_net(br->dev), 0, RTNLGRP_BRVLAN, NULL, GFP_KERNEL);
+ return;
+
+out_err:
+ rtnl_set_sk_err(dev_net(br->dev), RTNLGRP_BRVLAN, err);
+out_kfree:
+ kfree_skb(skb);
+}
+
static int br_vlan_process_global_one_opts(const struct net_bridge *br,
struct net_bridge_vlan_group *vg,
struct net_bridge_vlan *v,
@@ -311,9 +362,9 @@ int br_vlan_rtm_process_global_options(struct net_device *dev,
int cmd,
struct netlink_ext_ack *extack)
{
+ struct net_bridge_vlan *v, *curr_start = NULL, *curr_end = NULL;
struct nlattr *tb[BRIDGE_VLANDB_GOPTS_MAX + 1];
struct net_bridge_vlan_group *vg;
- struct net_bridge_vlan *v;
u16 vid, vid_range = 0;
struct net_bridge *br;
int err = 0;
@@ -370,7 +421,34 @@ int br_vlan_rtm_process_global_options(struct net_device *dev,
extack);
if (err)
break;
+
+ if (changed) {
+ /* vlan options changed, check for range */
+ if (!curr_start) {
+ curr_start = v;
+ curr_end = v;
+ continue;
+ }
+
+ if (!br_vlan_global_opts_can_enter_range(v, curr_end)) {
+ br_vlan_global_opts_notify(br, curr_start->vid,
+ curr_end->vid);
+ curr_start = v;
+ }
+ curr_end = v;
+ } else {
+ /* nothing changed and nothing to notify yet */
+ if (!curr_start)
+ continue;
+
+ br_vlan_global_opts_notify(br, curr_start->vid,
+ curr_end->vid);
+ curr_start = NULL;
+ curr_end = NULL;
+ }
}
+ if (curr_start)
+ br_vlan_global_opts_notify(br, curr_start->vid, curr_end->vid);
return err;
}
--
2.31.1
next prev parent reply other threads:[~2021-07-19 17:06 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-19 17:06 [Bridge] [PATCH net-next 00/15] net: bridge: multicast: add vlan support Nikolay Aleksandrov
2021-07-19 17:06 ` [Bridge] [PATCH net-next 01/15] net: bridge: multicast: factor out port multicast context Nikolay Aleksandrov
2021-07-19 17:06 ` [Bridge] [PATCH net-next 02/15] net: bridge: multicast: factor out bridge " Nikolay Aleksandrov
2021-07-19 17:06 ` [Bridge] [PATCH net-next 03/15] net: bridge: multicast: use multicast contexts instead of bridge or port Nikolay Aleksandrov
2021-07-19 17:06 ` [Bridge] [PATCH net-next 04/15] net: bridge: vlan: add global and per-port multicast context Nikolay Aleksandrov
2021-07-19 17:06 ` [Bridge] [PATCH net-next 05/15] net: bridge: multicast: add vlan state initialization and control Nikolay Aleksandrov
2021-07-19 17:06 ` [Bridge] [PATCH net-next 06/15] net: bridge: add vlan mcast snooping knob Nikolay Aleksandrov
2021-07-19 17:06 ` [Bridge] [PATCH net-next 07/15] net: bridge: multicast: add helper to get port mcast context from port group Nikolay Aleksandrov
2021-07-19 17:06 ` [Bridge] [PATCH net-next 08/15] net: bridge: multicast: use the port group to port context helper Nikolay Aleksandrov
2021-07-19 17:06 ` [Bridge] [PATCH net-next 09/15] net: bridge: multicast: check if should use vlan mcast ctx Nikolay Aleksandrov
2021-07-19 17:06 ` [Bridge] [PATCH net-next 10/15] net: bridge: multicast: add vlan querier and query support Nikolay Aleksandrov
2021-07-19 17:06 ` [Bridge] [PATCH net-next 11/15] net: bridge: multicast: include router port vlan id in notifications Nikolay Aleksandrov
2021-07-19 17:06 ` [Bridge] [PATCH net-next 12/15] net: bridge: vlan: add support for global options Nikolay Aleksandrov
2021-07-19 17:06 ` [Bridge] [PATCH net-next 13/15] net: bridge: vlan: add support for dumping global vlan options Nikolay Aleksandrov
2021-07-19 17:06 ` Nikolay Aleksandrov [this message]
2021-07-19 17:06 ` [Bridge] [PATCH net-next 15/15] net: bridge: vlan: add mcast snooping control Nikolay Aleksandrov
2021-07-20 13:30 ` [Bridge] [PATCH net-next 00/15] net: bridge: multicast: add vlan support patchwork-bot+netdevbpf
2021-08-19 16:01 ` Joachim Wiberg
2021-08-19 16:22 ` Nikolay Aleksandrov
2021-08-20 6:26 ` Joachim Wiberg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210719170637.435541-15-razor@blackwall.org \
--to=razor@blackwall.org \
--cc=bridge@lists.linux-foundation.org \
--cc=netdev@vger.kernel.org \
--cc=nikolay@nvidia.com \
--cc=roopa@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox