From: Vlad Yasevich <vyasevic@redhat.com>
To: netdev@vger.kernel.org
Cc: shemminger@vyatta.com, Vlad Yasevich <vyasevic@redhat.com>
Subject: [RFC PATCHv2 bridge 7/7] bridge: Add the ability to show dump the vlan map from a bridge port
Date: Wed, 19 Sep 2012 08:42:16 -0400 [thread overview]
Message-ID: <1348058536-22607-8-git-send-email-vyasevic@redhat.com> (raw)
In-Reply-To: <1348058536-22607-1-git-send-email-vyasevic@redhat.com>
Using the RTM_GETLINK dump the vlan map of a given bridge port.
Signed-off-by: Vlad Yasevich <vyasevic@redhat.com>
---
include/linux/if_link.h | 1 +
net/bridge/br_netlink.c | 73 +++++++++++++++++++++++++++++++++++++++++++---
net/bridge/br_private.h | 2 +
3 files changed, 71 insertions(+), 5 deletions(-)
diff --git a/include/linux/if_link.h b/include/linux/if_link.h
index 38dbcff..6953233 100644
--- a/include/linux/if_link.h
+++ b/include/linux/if_link.h
@@ -416,6 +416,7 @@ enum {
IFLA_BR_VLAN_UNSPEC,
IFLA_BR_VLAN_ADD,
IFLA_BR_VLAN_DEL,
+ IFLA_BR_VLAN_MAP,
__IFLA_BR_VLAN_MAX,
};
#define IFLA_BR_VLAN_MAX (__IFLA_BR_VLAN_MAX - 1)
diff --git a/net/bridge/br_netlink.c b/net/bridge/br_netlink.c
index 8a97f93..72fec1b 100644
--- a/net/bridge/br_netlink.c
+++ b/net/bridge/br_netlink.c
@@ -69,9 +69,35 @@ static int br_fill_ifinfo(struct sk_buff *skb, const struct net_bridge_port *por
nla_put(skb, IFLA_ADDRESS, dev->addr_len, dev->dev_addr)) ||
(dev->ifindex != dev->iflink &&
nla_put_u32(skb, IFLA_LINK, dev->iflink)) ||
- (event == RTM_NEWLINK &&
+ ((event == RTM_NEWLINK || event == RTM_GETLINK) &&
nla_put_u8(skb, IFLA_PROTINFO, port->state)))
goto nla_put_failure;
+
+ if (event == RTM_GETLINK) {
+ unsigned long *map = rcu_dereference(port->vlan_map);
+ struct nlattr *af;
+ struct nlattr *vidinfo;
+
+ if (!map)
+ goto done;
+
+ af = nla_nest_start(skb, IFLA_AF_SPEC);
+ if (!af)
+ goto nla_put_failure;
+
+ vidinfo = nla_nest_start(skb, IFLA_BR_VLAN_INFO);
+ if (!vidinfo)
+ goto nla_put_failure;
+
+ if (nla_put(skb, IFLA_BR_VLAN_MAP,
+ BITS_TO_LONGS(br_vid(VLAN_N_VID)), map))
+ goto nla_put_failure;
+
+ nla_nest_end(skb, vidinfo);
+ nla_nest_end(skb, af);
+ }
+
+done:
return nlmsg_end(skb, nlh);
nla_put_failure:
@@ -129,7 +155,7 @@ static int br_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb)
if (br_fill_ifinfo(skb, port,
NETLINK_CB(cb->skb).pid,
- cb->nlh->nlmsg_seq, RTM_NEWLINK,
+ cb->nlh->nlmsg_seq, RTM_GETLINK,
NLM_F_MULTI) < 0)
break;
skip:
@@ -283,6 +309,36 @@ static int br_validate(struct nlattr *tb[], struct nlattr *data[])
return 0;
}
+static size_t br_get_link_af_size(const struct net_device *dev)
+{
+ struct net_bridge_port *p;
+ unsigned long *map;
+
+ rcu_read_lock();
+ p = br_port_get_rcu(dev);
+ if (!p)
+ goto err;
+
+ map = rcu_dereference(p->vlan_map);
+ if (!map)
+ goto err;
+
+ rcu_read_unlock();
+
+ /* Account for the full bitmap length. We are going to export the
+ * whole bitmap.
+ */
+ return nla_total_size(BITS_TO_LONGS(br_vid(VLAN_N_VID)));
+err:
+ rcu_read_unlock();
+ return 0;
+}
+
+struct rtnl_af_ops br_af_ops = {
+ .family = AF_BRIDGE,
+ .get_link_af_size = br_get_link_af_size,
+};
+
struct rtnl_link_ops br_link_ops __read_mostly = {
.kind = "bridge",
.priv_size = sizeof(struct net_bridge),
@@ -299,19 +355,25 @@ int __init br_netlink_init(void)
if (err < 0)
goto err1;
+ err = rtnl_af_register(&br_af_ops);
+ if (err < 0)
+ goto err2;
+
err = __rtnl_register(PF_BRIDGE, RTM_GETLINK, NULL,
br_dump_ifinfo, NULL);
if (err)
- goto err2;
+ goto err3;
err = __rtnl_register(PF_BRIDGE, RTM_SETLINK,
br_rtm_setlink, NULL, NULL);
if (err)
- goto err3;
+ goto err4;
return 0;
-err3:
+err4:
rtnl_unregister_all(PF_BRIDGE);
+err3:
+ rtnl_af_unregister(&br_af_ops);
err2:
rtnl_link_unregister(&br_link_ops);
err1:
@@ -320,6 +382,7 @@ err1:
void __exit br_netlink_fini(void)
{
+ rtnl_af_unregister(&br_af_ops);
rtnl_link_unregister(&br_link_ops);
rtnl_unregister_all(PF_BRIDGE);
}
diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h
index 8eb3ffc..0575edb 100644
--- a/net/bridge/br_private.h
+++ b/net/bridge/br_private.h
@@ -419,6 +419,8 @@ extern netdev_features_t br_features_recompute(struct net_bridge *br,
netdev_features_t features);
extern int br_set_port_vlan(struct net_bridge_port *p, unsigned short vid);
extern int br_del_port_vlan(struct net_bridge_port *p, unsigned short vid);
+extern size_t br_port_fill_vlans(struct net_bridge_port *p, char *buf,
+ unsigned long max, unsigned long skip);
/* br_input.c */
extern int br_handle_frame_finish(struct sk_buff *skb);
--
1.7.7.6
next prev parent reply other threads:[~2012-09-19 12:42 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-19 12:42 [RFC PATCHv2 bridge 0/7] Add basic VLAN support to bridges Vlad Yasevich
2012-09-19 12:42 ` [RFC PATCHv2 bridge 1/7] bridge: Add vlan check to forwarding path Vlad Yasevich
2012-09-19 12:42 ` [RFC PATCHv2 bridge 2/7] bridge: Add vlan to unicast fdb entries Vlad Yasevich
2012-09-22 17:17 ` Ben Hutchings
2012-09-24 13:56 ` Vlad Yasevich
2012-09-19 12:42 ` [RFC PATCHv2 bridge 3/7] bridge: Add vlan id to multicast groups Vlad Yasevich
2012-09-19 12:42 ` [RFC PATCHv2 bridge 4/7] bridge: Add netlink interface to configure vlans on bridge ports Vlad Yasevich
2012-09-22 17:17 ` Ben Hutchings
2012-09-19 12:42 ` [RFC PATCHv2 bridge 5/7] bridge: Add vlan support to static neighbors Vlad Yasevich
2012-09-19 15:20 ` John Fastabend
2012-09-19 15:24 ` Vlad Yasevich
2012-09-19 12:42 ` [RFC PATCHv2 bridge 6/7] bridge: Add sysfs interface to display VLANS Vlad Yasevich
2012-09-19 12:42 ` Vlad Yasevich [this message]
2012-09-22 17:15 ` [RFC PATCHv2 bridge 7/7] bridge: Add the ability to show dump the vlan map from a bridge port Ben Hutchings
2012-09-22 17:27 ` David Miller
2012-09-22 20:05 ` Stephen Hemminger
2012-09-24 13:49 ` Vlad Yasevich
2012-09-24 18:39 ` Ben Hutchings
2012-09-24 20:29 ` Vlad Yasevich
2012-09-24 13:48 ` Vlad Yasevich
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=1348058536-22607-8-git-send-email-vyasevic@redhat.com \
--to=vyasevic@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=shemminger@vyatta.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;
as well as URLs for NNTP newsgroup(s).