Skip to content

Commit b7853d7

Browse files
roopa-prabhudavem330
authored andcommitted
bridge: add vlan info to bridge setlink and dellink notification messages
vlan add/deletes are not notified to userspace today. This patch adds vlan info to bridge newlink/dellink notifications generated from the bridge driver. Notifications use the RTEXT_FILTER_BRVLAN_COMPRESSED flag to compress vlans into ranges whereever applicable. The size calculations does not take ranges into account for simplicity. This has the potential for allocating a larger skb than required. There is an existing inconsistency with bridge NEWLINK and DELLINK change notifications. Both generate NEWLINK notifications. Since its always a NEWLINK notification, this patch includes all vlans the port belongs to in the notification. The NEWLINK and DELLINK request messages however only include the vlans to be added and deleted. Signed-off-by: Roopa Prabhu <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent e099b2d commit b7853d7

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

net/bridge/br_netlink.c

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,24 @@
2222
#include "br_private.h"
2323
#include "br_private_stp.h"
2424

25+
static size_t br_get_link_af_size(const struct net_device *dev)
26+
{
27+
struct net_port_vlans *pv;
28+
29+
if (br_port_exists(dev))
30+
pv = nbp_get_vlan_info(br_port_get_rtnl(dev));
31+
else if (dev->priv_flags & IFF_EBRIDGE)
32+
pv = br_get_vlan_info((struct net_bridge *)netdev_priv(dev));
33+
else
34+
return 0;
35+
36+
if (!pv)
37+
return 0;
38+
39+
/* Each VLAN is returned in bridge_vlan_info along with flags */
40+
return pv->num_vlans * nla_total_size(sizeof(struct bridge_vlan_info));
41+
}
42+
2543
static inline size_t br_port_info_size(void)
2644
{
2745
return nla_total_size(1) /* IFLA_BRPORT_STATE */
@@ -36,7 +54,7 @@ static inline size_t br_port_info_size(void)
3654
+ 0;
3755
}
3856

39-
static inline size_t br_nlmsg_size(void)
57+
static inline size_t br_nlmsg_size(struct net_device *dev)
4058
{
4159
return NLMSG_ALIGN(sizeof(struct ifinfomsg))
4260
+ nla_total_size(IFNAMSIZ) /* IFLA_IFNAME */
@@ -45,7 +63,8 @@ static inline size_t br_nlmsg_size(void)
4563
+ nla_total_size(4) /* IFLA_MTU */
4664
+ nla_total_size(4) /* IFLA_LINK */
4765
+ nla_total_size(1) /* IFLA_OPERSTATE */
48-
+ nla_total_size(br_port_info_size()); /* IFLA_PROTINFO */
66+
+ nla_total_size(br_port_info_size()) /* IFLA_PROTINFO */
67+
+ nla_total_size(br_get_link_af_size(dev)); /* IFLA_AF_SPEC */
4968
}
5069

5170
static int br_port_fill_attrs(struct sk_buff *skb,
@@ -288,11 +307,12 @@ void br_ifinfo_notify(int event, struct net_bridge_port *port)
288307
br_debug(port->br, "port %u(%s) event %d\n",
289308
(unsigned int)port->port_no, port->dev->name, event);
290309

291-
skb = nlmsg_new(br_nlmsg_size(), GFP_ATOMIC);
310+
skb = nlmsg_new(br_nlmsg_size(port->dev), GFP_ATOMIC);
292311
if (skb == NULL)
293312
goto errout;
294313

295-
err = br_fill_ifinfo(skb, port, 0, 0, event, 0, 0, port->dev);
314+
err = br_fill_ifinfo(skb, port, 0, 0, event, 0,
315+
RTEXT_FILTER_BRVLAN_COMPRESSED, port->dev);
296316
if (err < 0) {
297317
/* -EMSGSIZE implies BUG in br_nlmsg_size() */
298318
WARN_ON(err == -EMSGSIZE);
@@ -703,24 +723,6 @@ static int br_fill_info(struct sk_buff *skb, const struct net_device *brdev)
703723
return 0;
704724
}
705725

706-
static size_t br_get_link_af_size(const struct net_device *dev)
707-
{
708-
struct net_port_vlans *pv;
709-
710-
if (br_port_exists(dev))
711-
pv = nbp_get_vlan_info(br_port_get_rtnl(dev));
712-
else if (dev->priv_flags & IFF_EBRIDGE)
713-
pv = br_get_vlan_info((struct net_bridge *)netdev_priv(dev));
714-
else
715-
return 0;
716-
717-
if (!pv)
718-
return 0;
719-
720-
/* Each VLAN is returned in bridge_vlan_info along with flags */
721-
return pv->num_vlans * nla_total_size(sizeof(struct bridge_vlan_info));
722-
}
723-
724726
static struct rtnl_af_ops br_af_ops __read_mostly = {
725727
.family = AF_BRIDGE,
726728
.get_link_af_size = br_get_link_af_size,

0 commit comments

Comments
 (0)