Skip to contentSkip to conversation

Rightsize IFLA_AF_SPEC size calculation

PATCH Superseded Ronen Arad 4 participants 17 messages Oct 14, 2015 – Oct 22, 2015

Subsystems (4)
lore
Share & tools
lore

Ronen Arad

author
#0 lore raw

cover Rightsize IFLA_AF_SPEC size calculation

if_nlmsg_size() overestimates the minimum allocation size of netlink dump request (when called from rtnl_calcit()) or the size of the message (when called from rtnl_getlink()). This is because ext_filter_mask is not supported by rtnl_link_get_af_size() and rtnl_link_get_size().

The over-estimation is significant when at least one netdev has many VLANs configured (8 bytes for each configured VLAN).

This patch-set "rightsizes" the protocol specific attribute size calculation by propagating ext_filter_mask to rtnl_link_get_af_size() and adding optional filtering aware get_af_size_filtered op in struct rtnl_af_ops. Bridge module, which already used filtering aware sizing for notification, is enhanced to do the same for netlink dump requests.

Ronen Arad (4):
rtnetlink: Add get_link_af_size_filtered to rtnl_af_ops
bridge: br_af_ops add br_get_link_af_size_filtered
rtnetlink: Prefer filtering-aware af sizing
bridge: Remove br_get_link_af_size

 include/net/rtnetlink.h |  2 ++
 net/bridge/br_netlink.c | 23 ++---------------------
 net/core/rtnetlink.c    | 12 +++++++++---
 3 files changed, 13 insertions(+), 24 deletions(-)

--
2.1.0

author
#1 lore raw

PATCH 1/4 rtnetlink: Add get_link_af_size_filtered to rtnl_af_ops

get_link_af_size_filtered() - a filtering-mask aware alternative function is added to struct rtnl_af_ops in order to allow for "rightsizing" the IFLA_AF_SPEC calculation in if_nlmsg_size(). This significantly reduces the message size when at least one netdev has large number of VLANs.

---
 include/net/rtnetlink.h | 2 ++
 1 file changed, 2 insertions(+)
include/net/rtnetlink.h +2 -0
index aff6ceb..96df9bb 100644
@@ -130,6 +130,8 @@ struct rtnl_af_ops {
 						    const struct nlattr *attr);
 	int			(*set_link_af)(struct net_device *dev,
 					       const struct nlattr *attr);
+	size_t			(*get_link_af_size_filtered)(const struct net_device *dev,
+							     u32 ext_filter_mask);
 };
 
 void __rtnl_af_unregister(struct rtnl_af_ops *ops);
Signature · 1 line
2.1.0
author
#4 lore raw

PATCH 2/4 bridge: br_af_ops add br_get_link_af_size_filtered

In reply to Ronen Arad

Provide get_af_size_filtered (set to br_get_link_af_size_filtered) in br_af_ops for proper filtering mask aware sizing of AF_BRIDGE attributes. This is an optimization of netlink message size when -c[compressvlans] option is entered for iproute2's bridge command. Optimization will get into effect with rtnetlink change in the next patch of this set.

---
 net/bridge/br_netlink.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
net/bridge/br_netlink.c +3 -2
index 94b4de8..d900881 100644
@@ -1235,8 +1235,9 @@ static size_t br_get_link_af_size(const struct net_device *dev)
 }
 
 static struct rtnl_af_ops br_af_ops __read_mostly = {
-	.family			= AF_BRIDGE,
-	.get_link_af_size	= br_get_link_af_size,
+	.family				= AF_BRIDGE,
+	.get_link_af_size		= br_get_link_af_size,
+	.get_link_af_size_filtered	= br_get_link_af_size_filtered,
 };
 
 struct rtnl_link_ops br_link_ops __read_mostly = {
Signature · 1 line
2.1.0
author
#5 lore raw

PATCH 3/4 rtnetlink: Prefer filtering-aware af sizing

In reply to Ronen Arad

Add ext_filter_mask arg to rtnl_link_get_af_size(). rtnl_link_get_af_size() will prefer filtering-aware af sizing when provided by an address family. It falls back to get_link_af_size for other families.

---
 net/core/rtnetlink.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
net/core/rtnetlink.c +9 -3
index 2477595..dd7cda7 100644
@@ -497,7 +497,8 @@ void rtnl_af_unregister(struct rtnl_af_ops *ops)
 }
 EXPORT_SYMBOL_GPL(rtnl_af_unregister);
 
-static size_t rtnl_link_get_af_size(const struct net_device *dev)
+static size_t rtnl_link_get_af_size(const struct net_device *dev,
+				    u32 ext_filter_mask)
 {
 	struct rtnl_af_ops *af_ops;
 	size_t size;
@@ -506,7 +507,12 @@ static size_t rtnl_link_get_af_size(const struct net_device *dev)
 	size = nla_total_size(sizeof(struct nlattr));
 
 	list_for_each_entry(af_ops, &rtnl_af_ops, list) {
-		if (af_ops->get_link_af_size) {
+		/* Prefer filtering-aware af sizing when available */
+		if (af_ops->get_link_af_size_filtered) {
+			/* AF_* + nested data */
+			size += nla_total_size(sizeof(struct nlattr)) +
+				af_ops->get_link_af_size_filtered(dev, ext_filter_mask);
+		} else if (af_ops->get_link_af_size) {
 			/* AF_* + nested data */
 			size += nla_total_size(sizeof(struct nlattr)) +
 				af_ops->get_link_af_size(dev);
@@ -900,7 +906,7 @@ static noinline size_t if_nlmsg_size(const struct net_device *dev,
 	       + rtnl_vfinfo_size(dev, ext_filter_mask) /* IFLA_VFINFO_LIST */
 	       + rtnl_port_size(dev, ext_filter_mask) /* IFLA_VF_PORTS + IFLA_PORT_SELF */
 	       + rtnl_link_get_size(dev) /* IFLA_LINKINFO */
-	       + rtnl_link_get_af_size(dev) /* IFLA_AF_SPEC */
+	       + rtnl_link_get_af_size(dev, ext_filter_mask) /* IFLA_AF_SPEC */
 	       + nla_total_size(MAX_PHYS_ITEM_ID_LEN) /* IFLA_PHYS_PORT_ID */
 	       + nla_total_size(MAX_PHYS_ITEM_ID_LEN) /* IFLA_PHYS_SWITCH_ID */
 	       + nla_total_size(1); /* IFLA_PROTO_DOWN */
Signature · 1 line
2.1.0
author
#6 lore raw

PATCH 4/4 bridge: Remove br_get_link_af_size

In reply to Ronen Arad

Unset get_link_af_size in br_af_ops. br_get_link_af_size() becomes unused and thus removed.

---
 net/bridge/br_netlink.c | 20 --------------------
 1 file changed, 20 deletions(-)
net/bridge/br_netlink.c +0 -20
index d900881..204222d 100644
@@ -1214,29 +1214,9 @@ static int br_fill_info(struct sk_buff *skb, const struct net_device *brdev)
 	return 0;
 }
 
-static size_t br_get_link_af_size(const struct net_device *dev)
-{
-	struct net_bridge_port *p;
-	struct net_bridge *br;
-	int num_vlans = 0;
-
-	if (br_port_exists(dev)) {
-		p = br_port_get_rtnl(dev);
-		num_vlans = br_get_num_vlan_infos(nbp_vlan_group(p),
-						  RTEXT_FILTER_BRVLAN);
-	} else if (dev->priv_flags & IFF_EBRIDGE) {
-		br = netdev_priv(dev);
-		num_vlans = br_get_num_vlan_infos(br_vlan_group(br),
-						  RTEXT_FILTER_BRVLAN);
-	}
-
-	/* Each VLAN is returned in bridge_vlan_info along with flags */
-	return num_vlans * nla_total_size(sizeof(struct bridge_vlan_info));
-}
 
 static struct rtnl_af_ops br_af_ops __read_mostly = {
 	.family				= AF_BRIDGE,
-	.get_link_af_size		= br_get_link_af_size,
 	.get_link_af_size_filtered	= br_get_link_af_size_filtered,
 };
 
Signature · 1 line
2.1.0
#2 lore raw

Re: [PATCH net-next 1/4] rtnetlink: Add get_link_af_size_filtered to rtnl_af_ops

In reply to Ronen Arad

include/net/rtnetlink.h struct rtnl_af_ops { · line 135

Quoted 9 lines · Ronen Arad
include/net/rtnetlink.h +2 -0
@@ -130,6 +130,8 @@ struct rtnl_af_ops {
 						    const struct nlattr *attr);
 	int			(*set_link_af)(struct net_device *dev,
 					       const struct nlattr *attr);
+	size_t			(*get_link_af_size_filtered)(const struct net_device *dev,
+							     u32 ext_filter_mask);
 };

There's not much point in having two callbacks doing essentially the same. Why you just don't add the new parameter to the existing get_link_af_size? Looking at what the patch 3 does, the current implementations of the callback can just ignore the new parameter and bridge can remove the current br_get_link_af and rename br_get_link_af_size_filtered to br_get_link_af.

Jiri

Signature · 1 line
Jiri Benc
#3 lore raw

RE: [PATCH net-next 1/4] rtnetlink: Add get_link_af_size_filtered to rtnl_af_ops

Quoted 19 lines

-----Original Message-----
From: Jiri Benc [mailto:[email protected]]
Sent: Wednesday, October 14, 2015 2:55 AM
To: Arad, Ronen
Cc: [email protected]
Subject: Re: [PATCH net-next 1/4] rtnetlink: Add get_link_af_size_filtered to rtnl_af_ops

include/net/rtnetlink.h struct rtnl_af_ops { · line 133

Quoted 7 lines · Ronen Arad
include/net/rtnetlink.h +1 -0
@@ -130,6 +130,8 @@ struct rtnl_af_ops {
 						    const struct nlattr *attr);
 	int			(*set_link_af)(struct net_device *dev,
 					       const struct nlattr *attr);
+	size_t			(*get_link_af_size_filtered)(const struct

net_device *dev,

Quoted 9 lines

include/net/rtnetlink.h struct rtnl_af_ops { · line 135

Quoted 2 lines
include/net/rtnetlink.h +1 -0
+							     u32 ext_filter_mask);
 };

There's not much point in having two callbacks doing essentially the same. Why you just don't add the new parameter to the existing get_link_af_size? Looking at what the patch 3 does, the current implementations of the callback can just ignore the new parameter and bridge can remove the current br_get_link_af and rename br_get_link_af_size_filtered to br_get_link_af.

[@Ronen] I agree with you about br_netlink. There was no need for both
so I removed br_get_link_af. Changing get_link_af_size signature, however,
will require change in other unrelated locations. I wanted to avoid that. The affected location are:
net/ipv4/devinet.c:2374: .get_link_af_size = inet_get_link_af_size,
net/ipv6/addrconf.c:5868: .get_link_af_size = inet6_get_link_af_size,

If there is a consensus that adding ext_filter_mask argument to get_link_af is preferred, I'll submit a v2.

Quoted 5 lines

Jiri

--
Jiri Benc

author
#7 lore raw

PATCH v2 1/1 netlink: Rightsize IFLA_AF_SPEC size calculation

In reply to Ronen Arad

This is a v2 of a 4-parts patch with same subject.
Giving up on backward compatibility allows for much simplified single patch.

if_nlmsg_size() overestimates the minimum allocation size of netlink dump request (when called from rtnl_calcit()) or the size of the message (when called from rtnl_getlink()). This is because ext_filter_mask is not supported by rtnl_link_get_af_size() and rtnl_link_get_size().

The over-estimation is significant when at least one netdev has many VLANs configured (8 bytes for each configured VLAN).

This patch-set "rightsizes" the protocol specific attribute size calculation by propagating ext_filter_mask to rtnl_link_get_af_size() and adding this a argument to get_link_af_size op in rtnl_af_ops.

Bridge module already used filtering aware sizing for notifications. br_get_link_af_size_filtered() is consistent with the modified get_link_af_size op so it replaces br_get_link_af_size() in br_af_ops. br_get_link_af_size() becomes unused and thus removed.

---
 include/net/rtnetlink.h |  3 ++-
 net/bridge/br_netlink.c | 21 +--------------------
 net/core/rtnetlink.c    |  8 ++++----
 net/ipv4/devinet.c      |  4 ++--
 net/ipv6/addrconf.c     |  3 ++-
 5 files changed, 11 insertions(+), 28 deletions(-)
include/net/rtnetlink.h +2 -1
index aff6ceb..2f87c1b 100644
@@ -124,7 +124,8 @@ struct rtnl_af_ops {
 	int			(*fill_link_af)(struct sk_buff *skb,
 						const struct net_device *dev,
 						u32 ext_filter_mask);
-	size_t			(*get_link_af_size)(const struct net_device *dev);
+	size_t			(*get_link_af_size)(const struct net_device *dev,
+						    u32 ext_filter_mask);
 
 	int			(*validate_link_af)(const struct net_device *dev,
 						    const struct nlattr *attr);
net/bridge/br_netlink.c +1 -20
index 94b4de8..40197ff 100644
@@ -1214,29 +1214,10 @@ static int br_fill_info(struct sk_buff *skb, const struct net_device *brdev)
 	return 0;
 }
 
-static size_t br_get_link_af_size(const struct net_device *dev)
-{
-	struct net_bridge_port *p;
-	struct net_bridge *br;
-	int num_vlans = 0;
-
-	if (br_port_exists(dev)) {
-		p = br_port_get_rtnl(dev);
-		num_vlans = br_get_num_vlan_infos(nbp_vlan_group(p),
-						  RTEXT_FILTER_BRVLAN);
-	} else if (dev->priv_flags & IFF_EBRIDGE) {
-		br = netdev_priv(dev);
-		num_vlans = br_get_num_vlan_infos(br_vlan_group(br),
-						  RTEXT_FILTER_BRVLAN);
-	}
-
-	/* Each VLAN is returned in bridge_vlan_info along with flags */
-	return num_vlans * nla_total_size(sizeof(struct bridge_vlan_info));
-}
 
 static struct rtnl_af_ops br_af_ops __read_mostly = {
 	.family			= AF_BRIDGE,
-	.get_link_af_size	= br_get_link_af_size,
+	.get_link_af_size	= br_get_link_af_size_filtered,
 };
 
 struct rtnl_link_ops br_link_ops __read_mostly = {
net/core/rtnetlink.c +4 -4
index 2477595..581aec4 100644
@@ -497,7 +497,8 @@ void rtnl_af_unregister(struct rtnl_af_ops *ops)
 }
 EXPORT_SYMBOL_GPL(rtnl_af_unregister);
 
-static size_t rtnl_link_get_af_size(const struct net_device *dev)
+static size_t rtnl_link_get_af_size(const struct net_device *dev,
+				    u32 ext_filter_mask)
 {
 	struct rtnl_af_ops *af_ops;
 	size_t size;
@@ -509,7 +510,7 @@ static size_t rtnl_link_get_af_size(const struct net_device *dev)
 		if (af_ops->get_link_af_size) {
 			/* AF_* + nested data */
 			size += nla_total_size(sizeof(struct nlattr)) +
-				af_ops->get_link_af_size(dev);
+				af_ops->get_link_af_size(dev, ext_filter_mask);
 		}
 	}
 
@@ -900,7 +901,7 @@ static noinline size_t if_nlmsg_size(const struct net_device *dev,
 	       + rtnl_vfinfo_size(dev, ext_filter_mask) /* IFLA_VFINFO_LIST */
 	       + rtnl_port_size(dev, ext_filter_mask) /* IFLA_VF_PORTS + IFLA_PORT_SELF */
 	       + rtnl_link_get_size(dev) /* IFLA_LINKINFO */
-	       + rtnl_link_get_af_size(dev) /* IFLA_AF_SPEC */
+		+ rtnl_link_get_af_size(dev, ext_filter_mask) /* IFLA_AF_SPEC */
 	       + nla_total_size(MAX_PHYS_ITEM_ID_LEN) /* IFLA_PHYS_PORT_ID */
 	       + nla_total_size(MAX_PHYS_ITEM_ID_LEN) /* IFLA_PHYS_SWITCH_ID */
 	       + nla_total_size(1); /* IFLA_PROTO_DOWN */
@@ -3443,4 +3444,3 @@ void __init rtnetlink_init(void)
 	rtnl_register(PF_BRIDGE, RTM_DELLINK, rtnl_bridge_dellink, NULL, NULL);
 	rtnl_register(PF_BRIDGE, RTM_SETLINK, rtnl_bridge_setlink, NULL, NULL);
 }
-
net/ipv4/devinet.c +2 -2
index 7350084..cebd9d3 100644
@@ -1644,7 +1644,8 @@ errout:
 		rtnl_set_sk_err(net, RTNLGRP_IPV4_IFADDR, err);
 }
 
-static size_t inet_get_link_af_size(const struct net_device *dev)
+static size_t inet_get_link_af_size(const struct net_device *dev,
+				    u32 ext_filter_mask)
 {
 	struct in_device *in_dev = rcu_dereference_rtnl(dev->ip_ptr);
 
@@ -2398,4 +2399,3 @@ void __init devinet_init(void)
 	rtnl_register(PF_INET, RTM_GETNETCONF, inet_netconf_get_devconf,
 		      inet_netconf_dump_devconf, NULL);
 }
-
net/ipv6/addrconf.c +2 -1
index f0326aa..0645fd1 100644
@@ -4786,7 +4786,8 @@ nla_put_failure:
 	return -EMSGSIZE;
 }
 
-static size_t inet6_get_link_af_size(const struct net_device *dev)
+static size_t inet6_get_link_af_size(const struct net_device *dev,
+				     u32 ext_filter_mask)
 {
 	if (!__in6_dev_get(dev))
 		return 0;

--
2.1.0

maintainer
#15 lore raw
In reply to Ronen Arad

From: Ronen Arad <[email protected]>
Date: Tue, 13 Oct 2015 22:58:30 -0700

Quoted 5 lines

if_nlmsg_size() overestimates the minimum allocation size of netlink dump request (when called from rtnl_calcit()) or the size of the message (when called from rtnl_getlink()). This is because ext_filter_mask is not supported by rtnl_link_get_af_size() and rtnl_link_get_size().

Quoted 8 lines

The over-estimation is significant when at least one netdev has many VLANs configured (8 bytes for each configured VLAN).

This patch-set "rightsizes" the protocol specific attribute size calculation by propagating ext_filter_mask to rtnl_link_get_af_size() and adding optional filtering aware get_af_size_filtered op in struct rtnl_af_ops. Bridge module, which already used filtering aware sizing for notification, is enhanced to do the same for netlink dump requests.

There are only three implementations of get_link_af_size, so please just simply change it's signature by adding the ext_filter_mask parameter instead of creating a completely new operation.

#16 lore raw
Quoted 27 lines

-----Original Message-----
From: David Miller [mailto:[email protected]]
Sent: Wednesday, October 14, 2015 6:44 PM
To: Arad, Ronen
Cc: [email protected]
Subject: Re: [PATCH net-next 0/4] Rightsize IFLA_AF_SPEC size calculation

From: Ronen Arad <[email protected]>
Date: Tue, 13 Oct 2015 22:58:30 -0700

Quoted 2 lines

if_nlmsg_size() overestimates the minimum allocation size of netlink dump request (when called from rtnl_calcit()) or the size of the message (when

called

Quoted 7 lines

from rtnl_getlink()). This is because ext_filter_mask is not supported by rtnl_link_get_af_size() and rtnl_link_get_size().

The over-estimation is significant when at least one netdev has many VLANs configured (8 bytes for each configured VLAN).

This patch-set "rightsizes" the protocol specific attribute size calculation

by

Quoted 2 lines

propagating ext_filter_mask to rtnl_link_get_af_size() and adding optional filtering aware get_af_size_filtered op in struct rtnl_af_ops. Bridge

module,

Quoted 1 line

which already used filtering aware sizing for notification, is enhanced to

Quoted 8 lines

do

Quoted 1 line

the same for netlink dump requests.

There are only three implementations of get_link_af_size, so please just simply
change it's signature by adding the ext_filter_mask parameter instead of creating
a completely new operation.

[@Ronen] I've already submitted a V2 that does that in a simplified single part patch.

maintainer
#8 lore raw

Re: [PATCH net-next v2] netlink: Rightsize IFLA_AF_SPEC size calculation

In reply to Ronen Arad

From: Ronen Arad <[email protected]>
Date: Wed, 14 Oct 2015 08:51:28 -0700

net/core/rtnetlink.c static noinline size_t if_nlmsg_size(const struct net_device *dev, · line 905

Quoted 7 lines
net/core/rtnetlink.c +1 -1
@@ -900,7 +901,7 @@ static noinline size_t if_nlmsg_size(const struct net_device *dev,
 	       + rtnl_vfinfo_size(dev, ext_filter_mask) /* IFLA_VFINFO_LIST */
 	       + rtnl_port_size(dev, ext_filter_mask) /* IFLA_VF_PORTS + IFLA_PORT_SELF */
 	       + rtnl_link_get_size(dev) /* IFLA_LINKINFO */
-	       + rtnl_link_get_af_size(dev) /* IFLA_AF_SPEC */
+		+ rtnl_link_get_af_size(dev, ext_filter_mask) /* IFLA_AF_SPEC */
 	       + nla_total_size(MAX_PHYS_ITEM_ID_LEN) /* IFLA_PHYS_PORT_ID */

Please don't change the indentation on this line, keep it matching the indentation of all of the surrounding lines of this expression.

Thanks.

author
#10 lore raw

PATCH v3 1/1 netlink: Rightsize IFLA_AF_SPEC size calculation

In reply to Ronen Arad

if_nlmsg_size() overestimates the minimum allocation size of netlink dump request (when called from rtnl_calcit()) or the size of the message (when called from rtnl_getlink()). This is because ext_filter_mask is not supported by rtnl_link_get_af_size() and rtnl_link_get_size().

The over-estimation is significant when at least one netdev has many VLANs configured (8 bytes for each configured VLAN).

This patch-set "rightsizes" the protocol specific attribute size calculation by propagating ext_filter_mask to rtnl_link_get_af_size() and adding this a argument to get_link_af_size op in rtnl_af_ops.

Bridge module already used filtering aware sizing for notifications. br_get_link_af_size_filtered() is consistent with the modified get_link_af_size op so it replaces br_get_link_af_size() in br_af_ops. br_get_link_af_size() becomes unused and thus removed.

---
 include/net/rtnetlink.h |  3 ++-
 net/bridge/br_netlink.c | 21 +--------------------
 net/core/rtnetlink.c    |  8 ++++----
 net/ipv4/devinet.c      |  4 ++--
 net/ipv6/addrconf.c     |  3 ++-
 5 files changed, 11 insertions(+), 28 deletions(-)
include/net/rtnetlink.h +2 -1
index aff6ceb..2f87c1b 100644
@@ -124,7 +124,8 @@ struct rtnl_af_ops {
 	int			(*fill_link_af)(struct sk_buff *skb,
 						const struct net_device *dev,
 						u32 ext_filter_mask);
-	size_t			(*get_link_af_size)(const struct net_device *dev);
+	size_t			(*get_link_af_size)(const struct net_device *dev,
+						    u32 ext_filter_mask);
 
 	int			(*validate_link_af)(const struct net_device *dev,
 						    const struct nlattr *attr);
net/bridge/br_netlink.c +1 -20
index 94b4de8..40197ff 100644
@@ -1214,29 +1214,10 @@ static int br_fill_info(struct sk_buff *skb, const struct net_device *brdev)
 	return 0;
 }
 
-static size_t br_get_link_af_size(const struct net_device *dev)
-{
-	struct net_bridge_port *p;
-	struct net_bridge *br;
-	int num_vlans = 0;
-
-	if (br_port_exists(dev)) {
-		p = br_port_get_rtnl(dev);
-		num_vlans = br_get_num_vlan_infos(nbp_vlan_group(p),
-						  RTEXT_FILTER_BRVLAN);
-	} else if (dev->priv_flags & IFF_EBRIDGE) {
-		br = netdev_priv(dev);
-		num_vlans = br_get_num_vlan_infos(br_vlan_group(br),
-						  RTEXT_FILTER_BRVLAN);
-	}
-
-	/* Each VLAN is returned in bridge_vlan_info along with flags */
-	return num_vlans * nla_total_size(sizeof(struct bridge_vlan_info));
-}
 
 static struct rtnl_af_ops br_af_ops __read_mostly = {
 	.family			= AF_BRIDGE,
-	.get_link_af_size	= br_get_link_af_size,
+	.get_link_af_size	= br_get_link_af_size_filtered,
 };
 
 struct rtnl_link_ops br_link_ops __read_mostly = {
net/core/rtnetlink.c +4 -4
index 2477595..7c78b5a 100644
@@ -497,7 +497,8 @@ void rtnl_af_unregister(struct rtnl_af_ops *ops)
 }
 EXPORT_SYMBOL_GPL(rtnl_af_unregister);
 
-static size_t rtnl_link_get_af_size(const struct net_device *dev)
+static size_t rtnl_link_get_af_size(const struct net_device *dev,
+				    u32 ext_filter_mask)
 {
 	struct rtnl_af_ops *af_ops;
 	size_t size;
@@ -509,7 +510,7 @@ static size_t rtnl_link_get_af_size(const struct net_device *dev)
 		if (af_ops->get_link_af_size) {
 			/* AF_* + nested data */
 			size += nla_total_size(sizeof(struct nlattr)) +
-				af_ops->get_link_af_size(dev);
+				af_ops->get_link_af_size(dev, ext_filter_mask);
 		}
 	}
 
@@ -900,7 +901,7 @@ static noinline size_t if_nlmsg_size(const struct net_device *dev,
 	       + rtnl_vfinfo_size(dev, ext_filter_mask) /* IFLA_VFINFO_LIST */
 	       + rtnl_port_size(dev, ext_filter_mask) /* IFLA_VF_PORTS + IFLA_PORT_SELF */
 	       + rtnl_link_get_size(dev) /* IFLA_LINKINFO */
-	       + rtnl_link_get_af_size(dev) /* IFLA_AF_SPEC */
+	       + rtnl_link_get_af_size(dev, ext_filter_mask) /* IFLA_AF_SPEC */
 	       + nla_total_size(MAX_PHYS_ITEM_ID_LEN) /* IFLA_PHYS_PORT_ID */
 	       + nla_total_size(MAX_PHYS_ITEM_ID_LEN) /* IFLA_PHYS_SWITCH_ID */
 	       + nla_total_size(1); /* IFLA_PROTO_DOWN */
@@ -3443,4 +3444,3 @@ void __init rtnetlink_init(void)
 	rtnl_register(PF_BRIDGE, RTM_DELLINK, rtnl_bridge_dellink, NULL, NULL);
 	rtnl_register(PF_BRIDGE, RTM_SETLINK, rtnl_bridge_setlink, NULL, NULL);
 }
-
net/ipv4/devinet.c +2 -2
index 7350084..cebd9d3 100644
@@ -1644,7 +1644,8 @@ errout:
 		rtnl_set_sk_err(net, RTNLGRP_IPV4_IFADDR, err);
 }
 
-static size_t inet_get_link_af_size(const struct net_device *dev)
+static size_t inet_get_link_af_size(const struct net_device *dev,
+				    u32 ext_filter_mask)
 {
 	struct in_device *in_dev = rcu_dereference_rtnl(dev->ip_ptr);
 
@@ -2398,4 +2399,3 @@ void __init devinet_init(void)
 	rtnl_register(PF_INET, RTM_GETNETCONF, inet_netconf_get_devconf,
 		      inet_netconf_dump_devconf, NULL);
 }
-
net/ipv6/addrconf.c +2 -1
index f0326aa..0645fd1 100644
@@ -4786,7 +4786,8 @@ nla_put_failure:
 	return -EMSGSIZE;
 }
 
-static size_t inet6_get_link_af_size(const struct net_device *dev)
+static size_t inet6_get_link_af_size(const struct net_device *dev,
+				     u32 ext_filter_mask)
 {
 	if (!__in6_dev_get(dev))
 		return 0;
Signature · 1 line
2.1.0
#9 lore raw

RE: [PATCH net-next v2] netlink: Rightsize IFLA_AF_SPEC size calculation

In reply to David Miller
Quoted 17 lines

-----Original Message-----
From: David Miller [mailto:[email protected]]
Sent: Wednesday, October 14, 2015 7:24 PM
To: Arad, Ronen
Cc: [email protected]
Subject: Re: [PATCH net-next v2] netlink: Rightsize IFLA_AF_SPEC size calculation

From: Ronen Arad <[email protected]>
Date: Wed, 14 Oct 2015 08:51:28 -0700

Review static noinline size_t if_nlmsg_size(const struct

Quoted 1 line
(quoted diff) +0 -0
@@ -900,7 +901,7 @@ static noinline size_t if_nlmsg_size(const struct

net_device *dev,

Review static noinline size_t if_nlmsg_size(const struct · line 902

Quoted 2 lines
(quoted diff) +0 -0
 	       + rtnl_vfinfo_size(dev, ext_filter_mask) /* IFLA_VFINFO_LIST */
 	       + rtnl_port_size(dev, ext_filter_mask) /* IFLA_VF_PORTS +
Quoted 8 lines

IFLA_PORT_SELF */

net/core/rtnetlink.c static noinline size_t if_nlmsg_size(const struct net_device *dev, · line 905

Quoted 4 lines
net/core/rtnetlink.c +1 -1
 	       + rtnl_link_get_size(dev) /* IFLA_LINKINFO */
-	       + rtnl_link_get_af_size(dev) /* IFLA_AF_SPEC */
+		+ rtnl_link_get_af_size(dev, ext_filter_mask) /* IFLA_AF_SPEC */
 	       + nla_total_size(MAX_PHYS_ITEM_ID_LEN) /* IFLA_PHYS_PORT_ID */

Please don't change the indentation on this line, keep it matching the indentation of all of the surrounding lines of this expression.

[@Ronen] Sure. V3 submitted. My editor didn't like the indentation of the surrounding lines which are one less than two TAB spaces but consistency is important.

Quoted 2 lines

Thanks.

maintainer
#11 lore raw

Re: [PATCH net-next v3] netlink: Rightsize IFLA_AF_SPEC size calculation

In reply to Ronen Arad

From: Ronen Arad <[email protected]>
Date: Wed, 14 Oct 2015 22:50:04 -0700

Quoted 9 lines

if_nlmsg_size() overestimates the minimum allocation size of netlink dump request (when called from rtnl_calcit()) or the size of the message (when called from rtnl_getlink()). This is because ext_filter_mask is not supported by rtnl_link_get_af_size() and rtnl_link_get_size().

The over-estimation is significant when at least one netdev has many VLANs configured (8 bytes for each configured VLAN).

Quoted 8 lines

This patch-set "rightsizes" the protocol specific attribute size calculation by propagating ext_filter_mask to rtnl_link_get_af_size() and adding this a argument to get_link_af_size op in rtnl_af_ops.

Bridge module already used filtering aware sizing for notifications. br_get_link_af_size_filtered() is consistent with the modified get_link_af_size op so it replaces br_get_link_af_size() in br_af_ops. br_get_link_af_size() becomes unused and thus removed.

This is missing a proper Signoff

author
#12 lore raw

PATCH v3 1/1 netlink: Rightsize IFLA_AF_SPEC size calculation

In reply to Ronen Arad

if_nlmsg_size() overestimates the minimum allocation size of netlink dump request (when called from rtnl_calcit()) or the size of the message (when called from rtnl_getlink()). This is because ext_filter_mask is not supported by rtnl_link_get_af_size() and rtnl_link_get_size().

The over-estimation is significant when at least one netdev has many VLANs configured (8 bytes for each configured VLAN).

This patch-set "rightsizes" the protocol specific attribute size calculation by propagating ext_filter_mask to rtnl_link_get_af_size() and adding this a argument to get_link_af_size op in rtnl_af_ops.

Bridge module already used filtering aware sizing for notifications. br_get_link_af_size_filtered() is consistent with the modified get_link_af_size op so it replaces br_get_link_af_size() in br_af_ops. br_get_link_af_size() becomes unused and thus removed.

---
 include/net/rtnetlink.h |  3 ++-
 net/bridge/br_netlink.c | 21 +--------------------
 net/core/rtnetlink.c    |  8 ++++----
 net/ipv4/devinet.c      |  4 ++--
 net/ipv6/addrconf.c     |  3 ++-
 5 files changed, 11 insertions(+), 28 deletions(-)
include/net/rtnetlink.h +2 -1
index aff6ceb..2f87c1b 100644
@@ -124,7 +124,8 @@ struct rtnl_af_ops {
 	int			(*fill_link_af)(struct sk_buff *skb,
 						const struct net_device *dev,
 						u32 ext_filter_mask);
-	size_t			(*get_link_af_size)(const struct net_device *dev);
+	size_t			(*get_link_af_size)(const struct net_device *dev,
+						    u32 ext_filter_mask);
 
 	int			(*validate_link_af)(const struct net_device *dev,
 						    const struct nlattr *attr);
net/bridge/br_netlink.c +1 -20
index 94b4de8..40197ff 100644
@@ -1214,29 +1214,10 @@ static int br_fill_info(struct sk_buff *skb, const struct net_device *brdev)
 	return 0;
 }
 
-static size_t br_get_link_af_size(const struct net_device *dev)
-{
-	struct net_bridge_port *p;
-	struct net_bridge *br;
-	int num_vlans = 0;
-
-	if (br_port_exists(dev)) {
-		p = br_port_get_rtnl(dev);
-		num_vlans = br_get_num_vlan_infos(nbp_vlan_group(p),
-						  RTEXT_FILTER_BRVLAN);
-	} else if (dev->priv_flags & IFF_EBRIDGE) {
-		br = netdev_priv(dev);
-		num_vlans = br_get_num_vlan_infos(br_vlan_group(br),
-						  RTEXT_FILTER_BRVLAN);
-	}
-
-	/* Each VLAN is returned in bridge_vlan_info along with flags */
-	return num_vlans * nla_total_size(sizeof(struct bridge_vlan_info));
-}
 
 static struct rtnl_af_ops br_af_ops __read_mostly = {
 	.family			= AF_BRIDGE,
-	.get_link_af_size	= br_get_link_af_size,
+	.get_link_af_size	= br_get_link_af_size_filtered,
 };
 
 struct rtnl_link_ops br_link_ops __read_mostly = {
net/core/rtnetlink.c +4 -4
index 2477595..7c78b5a 100644
@@ -497,7 +497,8 @@ void rtnl_af_unregister(struct rtnl_af_ops *ops)
 }
 EXPORT_SYMBOL_GPL(rtnl_af_unregister);
 
-static size_t rtnl_link_get_af_size(const struct net_device *dev)
+static size_t rtnl_link_get_af_size(const struct net_device *dev,
+				    u32 ext_filter_mask)
 {
 	struct rtnl_af_ops *af_ops;
 	size_t size;
@@ -509,7 +510,7 @@ static size_t rtnl_link_get_af_size(const struct net_device *dev)
 		if (af_ops->get_link_af_size) {
 			/* AF_* + nested data */
 			size += nla_total_size(sizeof(struct nlattr)) +
-				af_ops->get_link_af_size(dev);
+				af_ops->get_link_af_size(dev, ext_filter_mask);
 		}
 	}
 
@@ -900,7 +901,7 @@ static noinline size_t if_nlmsg_size(const struct net_device *dev,
 	       + rtnl_vfinfo_size(dev, ext_filter_mask) /* IFLA_VFINFO_LIST */
 	       + rtnl_port_size(dev, ext_filter_mask) /* IFLA_VF_PORTS + IFLA_PORT_SELF */
 	       + rtnl_link_get_size(dev) /* IFLA_LINKINFO */
-	       + rtnl_link_get_af_size(dev) /* IFLA_AF_SPEC */
+	       + rtnl_link_get_af_size(dev, ext_filter_mask) /* IFLA_AF_SPEC */
 	       + nla_total_size(MAX_PHYS_ITEM_ID_LEN) /* IFLA_PHYS_PORT_ID */
 	       + nla_total_size(MAX_PHYS_ITEM_ID_LEN) /* IFLA_PHYS_SWITCH_ID */
 	       + nla_total_size(1); /* IFLA_PROTO_DOWN */
@@ -3443,4 +3444,3 @@ void __init rtnetlink_init(void)
 	rtnl_register(PF_BRIDGE, RTM_DELLINK, rtnl_bridge_dellink, NULL, NULL);
 	rtnl_register(PF_BRIDGE, RTM_SETLINK, rtnl_bridge_setlink, NULL, NULL);
 }
-
net/ipv4/devinet.c +2 -2
index 7350084..cebd9d3 100644
@@ -1644,7 +1644,8 @@ errout:
 		rtnl_set_sk_err(net, RTNLGRP_IPV4_IFADDR, err);
 }
 
-static size_t inet_get_link_af_size(const struct net_device *dev)
+static size_t inet_get_link_af_size(const struct net_device *dev,
+				    u32 ext_filter_mask)
 {
 	struct in_device *in_dev = rcu_dereference_rtnl(dev->ip_ptr);
 
@@ -2398,4 +2399,3 @@ void __init devinet_init(void)
 	rtnl_register(PF_INET, RTM_GETNETCONF, inet_netconf_get_devconf,
 		      inet_netconf_dump_devconf, NULL);
 }
-
net/ipv6/addrconf.c +2 -1
index f0326aa..0645fd1 100644
@@ -4786,7 +4786,8 @@ nla_put_failure:
 	return -EMSGSIZE;
 }
 
-static size_t inet6_get_link_af_size(const struct net_device *dev)
+static size_t inet6_get_link_af_size(const struct net_device *dev,
+				     u32 ext_filter_mask)
 {
 	if (!__in6_dev_get(dev))
 		return 0;
Signature · 1 line
2.1.0
Acked-by on v3 1/1
#13 lore raw

Re: [PATCH net-next v3] netlink: Rightsize IFLA_AF_SPEC size calculation

Quoted 13 lines · Ronen Arad

if_nlmsg_size() overestimates the minimum allocation size of netlink dump request (when called from rtnl_calcit()) or the size of the message (when called from rtnl_getlink()). This is because ext_filter_mask is not supported by rtnl_link_get_af_size() and rtnl_link_get_size().

The over-estimation is significant when at least one netdev has many VLANs configured (8 bytes for each configured VLAN).

This patch-set "rightsizes" the protocol specific attribute size calculation by propagating ext_filter_mask to rtnl_link_get_af_size() and adding this a argument to get_link_af_size op in rtnl_af_ops.

Quoted 6 lines

Bridge module already used filtering aware sizing for notifications. br_get_link_af_size_filtered() is consistent with the modified get_link_af_size op so it replaces br_get_link_af_size() in br_af_ops. br_get_link_af_size() becomes unused and thus removed.

Quoted 127 lines
---
  include/net/rtnetlink.h |  3 ++-
  net/bridge/br_netlink.c | 21 +--------------------
  net/core/rtnetlink.c    |  8 ++++----
  net/ipv4/devinet.c      |  4 ++--
  net/ipv6/addrconf.c     |  3 ++-
  5 files changed, 11 insertions(+), 28 deletions(-)
include/net/rtnetlink.h +2 -1
index aff6ceb..2f87c1b 100644
@@ -124,7 +124,8 @@ struct rtnl_af_ops {
  	int			(*fill_link_af)(struct sk_buff *skb,
  						const struct net_device *dev,
  						u32 ext_filter_mask);
-	size_t			(*get_link_af_size)(const struct net_device *dev);
+	size_t			(*get_link_af_size)(const struct net_device *dev,
+						    u32 ext_filter_mask);
 
  	int			(*validate_link_af)(const struct net_device *dev,
  						    const struct nlattr *attr);
net/bridge/br_netlink.c +1 -20
index 94b4de8..40197ff 100644
@@ -1214,29 +1214,10 @@ static int br_fill_info(struct sk_buff *skb, const struct net_device *brdev)
  	return 0;
  }
 
-static size_t br_get_link_af_size(const struct net_device *dev)
-{
-	struct net_bridge_port *p;
-	struct net_bridge *br;
-	int num_vlans = 0;
-
-	if (br_port_exists(dev)) {
-		p = br_port_get_rtnl(dev);
-		num_vlans = br_get_num_vlan_infos(nbp_vlan_group(p),
-						  RTEXT_FILTER_BRVLAN);
-	} else if (dev->priv_flags & IFF_EBRIDGE) {
-		br = netdev_priv(dev);
-		num_vlans = br_get_num_vlan_infos(br_vlan_group(br),
-						  RTEXT_FILTER_BRVLAN);
-	}
-
-	/* Each VLAN is returned in bridge_vlan_info along with flags */
-	return num_vlans * nla_total_size(sizeof(struct bridge_vlan_info));
-}
 
  static struct rtnl_af_ops br_af_ops __read_mostly = {
  	.family			= AF_BRIDGE,
-	.get_link_af_size	= br_get_link_af_size,
+	.get_link_af_size	= br_get_link_af_size_filtered,
  };
 
  struct rtnl_link_ops br_link_ops __read_mostly = {
net/core/rtnetlink.c +4 -4
index 2477595..7c78b5a 100644
@@ -497,7 +497,8 @@ void rtnl_af_unregister(struct rtnl_af_ops *ops)
  }
  EXPORT_SYMBOL_GPL(rtnl_af_unregister);
 
-static size_t rtnl_link_get_af_size(const struct net_device *dev)
+static size_t rtnl_link_get_af_size(const struct net_device *dev,
+				    u32 ext_filter_mask)
  {
  	struct rtnl_af_ops *af_ops;
  	size_t size;
@@ -509,7 +510,7 @@ static size_t rtnl_link_get_af_size(const struct net_device *dev)
  		if (af_ops->get_link_af_size) {
  			/* AF_* + nested data */
  			size += nla_total_size(sizeof(struct nlattr)) +
-				af_ops->get_link_af_size(dev);
+				af_ops->get_link_af_size(dev, ext_filter_mask);
  		}
  	}
 
@@ -900,7 +901,7 @@ static noinline size_t if_nlmsg_size(const struct net_device *dev,
  	       + rtnl_vfinfo_size(dev, ext_filter_mask) /* IFLA_VFINFO_LIST */
  	       + rtnl_port_size(dev, ext_filter_mask) /* IFLA_VF_PORTS + IFLA_PORT_SELF */
  	       + rtnl_link_get_size(dev) /* IFLA_LINKINFO */
-	       + rtnl_link_get_af_size(dev) /* IFLA_AF_SPEC */
+	       + rtnl_link_get_af_size(dev, ext_filter_mask) /* IFLA_AF_SPEC */
  	       + nla_total_size(MAX_PHYS_ITEM_ID_LEN) /* IFLA_PHYS_PORT_ID */
  	       + nla_total_size(MAX_PHYS_ITEM_ID_LEN) /* IFLA_PHYS_SWITCH_ID */
  	       + nla_total_size(1); /* IFLA_PROTO_DOWN */
@@ -3443,4 +3444,3 @@ void __init rtnetlink_init(void)
  	rtnl_register(PF_BRIDGE, RTM_DELLINK, rtnl_bridge_dellink, NULL, NULL);
  	rtnl_register(PF_BRIDGE, RTM_SETLINK, rtnl_bridge_setlink, NULL, NULL);
  }
-
net/ipv4/devinet.c +2 -2
index 7350084..cebd9d3 100644
@@ -1644,7 +1644,8 @@ errout:
  		rtnl_set_sk_err(net, RTNLGRP_IPV4_IFADDR, err);
  }
 
-static size_t inet_get_link_af_size(const struct net_device *dev)
+static size_t inet_get_link_af_size(const struct net_device *dev,
+				    u32 ext_filter_mask)
  {
  	struct in_device *in_dev = rcu_dereference_rtnl(dev->ip_ptr);
 
@@ -2398,4 +2399,3 @@ void __init devinet_init(void)
  	rtnl_register(PF_INET, RTM_GETNETCONF, inet_netconf_get_devconf,
  		      inet_netconf_dump_devconf, NULL);
  }
-
net/ipv6/addrconf.c +2 -1
index f0326aa..0645fd1 100644
@@ -4786,7 +4786,8 @@ nla_put_failure:
  	return -EMSGSIZE;
  }
 
-static size_t inet6_get_link_af_size(const struct net_device *dev)
+static size_t inet6_get_link_af_size(const struct net_device *dev,
+				     u32 ext_filter_mask)
  {
  	if (!__in6_dev_get(dev))
  		return 0;
maintainer Applied
#14 lore raw

Re: [PATCH net-next v3] netlink: Rightsize IFLA_AF_SPEC size calculation

In reply to Ronen Arad

From: Ronen Arad <[email protected]>
Date: Mon, 19 Oct 2015 09:23:28 -0700

Quoted 13 lines

if_nlmsg_size() overestimates the minimum allocation size of netlink dump request (when called from rtnl_calcit()) or the size of the message (when called from rtnl_getlink()). This is because ext_filter_mask is not supported by rtnl_link_get_af_size() and rtnl_link_get_size().

The over-estimation is significant when at least one netdev has many VLANs configured (8 bytes for each configured VLAN).

This patch-set "rightsizes" the protocol specific attribute size calculation by propagating ext_filter_mask to rtnl_link_get_af_size() and adding this a argument to get_link_af_size op in rtnl_af_ops.

Quoted 6 lines

Bridge module already used filtering aware sizing for notifications. br_get_link_af_size_filtered() is consistent with the modified get_link_af_size op so it replaces br_get_link_af_size() in br_af_ops. br_get_link_af_size() becomes unused and thus removed.

Applied, thanks.