Skip to contentSkip to conversation

rtnetlink: Add method to calculate dump info data size

RFC PATCH In review Greg Rose 4 participants 11 messages May 9, 2011 – May 10, 2011

Subsystems (8)
lore
Share & tools
lore

Greg Rose

author
#0 lore raw

RFC PATCH v2 1/1 rtnetlink: Add method to calculate dump info data size

The message size allocated for rtnl info dumps was limited to a single page. This is not enough for additional interface info available with devices that support SR-IOV. Calculate the amount of data required so the dump can allocate enough data to satisfy the request.

V2 of this patch adds a new argument to the rtnl_register service that allows for a new method to calculate the amount of data required to complete the info dump request. So far the method is only implemented for the RTM_GETLINK slot.

---

 include/linux/netlink.h              |    6 ++-
 include/net/rtnetlink.h              |    5 +-
 net/bridge/br_netlink.c              |   15 ++++---
 net/core/fib_rules.c                 |    6 +--
 net/core/neighbour.c                 |   10 ++--
 net/core/rtnetlink.c                 |   76 ++++++++++++++++++++++++++++++----
 net/dcb/dcbnl.c                      |    4 +-
 net/decnet/dn_dev.c                  |    6 +--
 net/decnet/dn_fib.c                  |    4 +-
 net/decnet/dn_route.c                |    5 +-
 net/ipv4/devinet.c                   |    6 +--
 net/ipv4/fib_frontend.c              |    6 +--
 net/ipv4/inet_diag.c                 |    2 -
 net/ipv4/ipmr.c                      |    3 +
 net/ipv4/route.c                     |    2 -
 net/ipv6/addrconf.c                  |   12 +++--
 net/ipv6/addrlabel.c                 |    6 +--
 net/ipv6/ip6_fib.c                   |    2 -
 net/ipv6/ip6mr.c                     |    2 -
 net/ipv6/route.c                     |    6 +--
 net/netfilter/ipset/ip_set_core.c    |    2 -
 net/netfilter/nf_conntrack_netlink.c |    4 +-
 net/netlink/af_netlink.c             |   17 +++++---
 net/netlink/genetlink.c              |    2 -
 net/phonet/pn_netlink.c              |   12 +++--
 net/sched/act_api.c                  |    6 +--
 net/sched/cls_api.c                  |    6 +--
 net/sched/sch_api.c                  |   12 +++--
 net/xfrm/xfrm_user.c                 |    2 -
 29 files changed, 159 insertions(+), 88 deletions(-)
include/linux/netlink.h +4 -2
index 4c4ac3f..8b8dfb8 100644
@@ -220,7 +220,8 @@ struct netlink_callback {
 	int			(*dump)(struct sk_buff * skb,
 					struct netlink_callback *cb);
 	int			(*done)(struct netlink_callback *cb);
-	int			family;
+	u16			family;
+	u16			min_dump_alloc;
 	long			args[6];
 };
 
@@ -258,7 +259,8 @@ __nlmsg_put(struct sk_buff *skb, u32 pid, u32 seq, int type, int len, int flags)
 extern int netlink_dump_start(struct sock *ssk, struct sk_buff *skb,
 			      const struct nlmsghdr *nlh,
 			      int (*dump)(struct sk_buff *skb, struct netlink_callback*),
-			      int (*done)(struct netlink_callback*));
+			      int (*done)(struct netlink_callback*),
+			      u16 min_dump_alloc);
 
 
 #define NL_NONROOT_RECV 0x1
include/net/rtnetlink.h +3 -2
index 4093ca7..d1ac642 100644
@@ -6,11 +6,12 @@
 
 typedef int (*rtnl_doit_func)(struct sk_buff *, struct nlmsghdr *, void *);
 typedef int (*rtnl_dumpit_func)(struct sk_buff *, struct netlink_callback *);
+typedef u16 (*rtnl_calcit_func)(struct sk_buff *);
 
 extern int	__rtnl_register(int protocol, int msgtype,
-				rtnl_doit_func, rtnl_dumpit_func);
+				rtnl_doit_func, rtnl_dumpit_func, rtnl_calcit_func);
 extern void	rtnl_register(int protocol, int msgtype,
-			      rtnl_doit_func, rtnl_dumpit_func);
+			      rtnl_doit_func, rtnl_dumpit_func, rtnl_calcit_func);
 extern int	rtnl_unregister(int protocol, int msgtype);
 extern void	rtnl_unregister_all(int protocol);
 
net/bridge/br_netlink.c +10 -5
index ffb0dc4..6814083 100644
@@ -218,19 +218,24 @@ int __init br_netlink_init(void)
 	if (err < 0)
 		goto err1;
 
-	err = __rtnl_register(PF_BRIDGE, RTM_GETLINK, NULL, br_dump_ifinfo);
+	err = __rtnl_register(PF_BRIDGE, RTM_GETLINK, NULL,
+			      br_dump_ifinfo, NULL);
 	if (err)
 		goto err2;
-	err = __rtnl_register(PF_BRIDGE, RTM_SETLINK, br_rtm_setlink, NULL);
+	err = __rtnl_register(PF_BRIDGE, RTM_SETLINK,
+			      br_rtm_setlink, NULL, NULL);
 	if (err)
 		goto err3;
-	err = __rtnl_register(PF_BRIDGE, RTM_NEWNEIGH, br_fdb_add, NULL);
+	err = __rtnl_register(PF_BRIDGE, RTM_NEWNEIGH,
+			      br_fdb_add, NULL, NULL);
 	if (err)
 		goto err3;
-	err = __rtnl_register(PF_BRIDGE, RTM_DELNEIGH, br_fdb_delete, NULL);
+	err = __rtnl_register(PF_BRIDGE, RTM_DELNEIGH,
+			      br_fdb_delete, NULL, NULL);
 	if (err)
 		goto err3;
-	err = __rtnl_register(PF_BRIDGE, RTM_GETNEIGH, NULL, br_fdb_dump);
+	err = __rtnl_register(PF_BRIDGE, RTM_GETNEIGH,
+			      NULL, br_fdb_dump, NULL);
 	if (err)
 		goto err3;
 
net/core/fib_rules.c +3 -3
index 3911586..56e6fc8 100644
@@ -739,9 +739,9 @@ static struct pernet_operations fib_rules_net_ops = {
 static int __init fib_rules_init(void)
 {
 	int err;
-	rtnl_register(PF_UNSPEC, RTM_NEWRULE, fib_nl_newrule, NULL);
-	rtnl_register(PF_UNSPEC, RTM_DELRULE, fib_nl_delrule, NULL);
-	rtnl_register(PF_UNSPEC, RTM_GETRULE, NULL, fib_nl_dumprule);
+	rtnl_register(PF_UNSPEC, RTM_NEWRULE, fib_nl_newrule, NULL, NULL);
+	rtnl_register(PF_UNSPEC, RTM_DELRULE, fib_nl_delrule, NULL, NULL);
+	rtnl_register(PF_UNSPEC, RTM_GETRULE, NULL, fib_nl_dumprule, NULL);
 
 	err = register_pernet_subsys(&fib_rules_net_ops);
 	if (err < 0)
net/core/neighbour.c +5 -5
index 799f06e..a880b83 100644
@@ -2909,12 +2909,12 @@ EXPORT_SYMBOL(neigh_sysctl_unregister);
 
 static int __init neigh_init(void)
 {
-	rtnl_register(PF_UNSPEC, RTM_NEWNEIGH, neigh_add, NULL);
-	rtnl_register(PF_UNSPEC, RTM_DELNEIGH, neigh_delete, NULL);
-	rtnl_register(PF_UNSPEC, RTM_GETNEIGH, NULL, neigh_dump_info);
+	rtnl_register(PF_UNSPEC, RTM_NEWNEIGH, neigh_add, NULL, NULL);
+	rtnl_register(PF_UNSPEC, RTM_DELNEIGH, neigh_delete, NULL, NULL);
+	rtnl_register(PF_UNSPEC, RTM_GETNEIGH, NULL, neigh_dump_info, NULL);
 
-	rtnl_register(PF_UNSPEC, RTM_GETNEIGHTBL, NULL, neightbl_dump_info);
-	rtnl_register(PF_UNSPEC, RTM_SETNEIGHTBL, neightbl_set, NULL);
+	rtnl_register(PF_UNSPEC, RTM_GETNEIGHTBL, NULL, neightbl_dump_info, NULL);
+	rtnl_register(PF_UNSPEC, RTM_SETNEIGHTBL, neightbl_set, NULL, NULL);
 
 	return 0;
 }
net/core/rtnetlink.c +66 -10

137 lines not on this page · raw message

net/dcb/dcbnl.c +2 -2
index 3609eac..ed1bb8c 100644
@@ -1819,8 +1819,8 @@ static int __init dcbnl_init(void)
 {
 	INIT_LIST_HEAD(&dcb_app_list);
 
-	rtnl_register(PF_UNSPEC, RTM_GETDCB, dcb_doit, NULL);
-	rtnl_register(PF_UNSPEC, RTM_SETDCB, dcb_doit, NULL);
+	rtnl_register(PF_UNSPEC, RTM_GETDCB, dcb_doit, NULL, NULL);
+	rtnl_register(PF_UNSPEC, RTM_SETDCB, dcb_doit, NULL, NULL);
 
 	return 0;
 }
net/decnet/dn_dev.c +3 -3
index 404fa15..0011eba 100644
@@ -1419,9 +1419,9 @@ void __init dn_dev_init(void)
 
 	dn_dev_devices_on();
 
-	rtnl_register(PF_DECnet, RTM_NEWADDR, dn_nl_newaddr, NULL);
-	rtnl_register(PF_DECnet, RTM_DELADDR, dn_nl_deladdr, NULL);
-	rtnl_register(PF_DECnet, RTM_GETADDR, NULL, dn_nl_dump_ifaddr);
+	rtnl_register(PF_DECnet, RTM_NEWADDR, dn_nl_newaddr, NULL, NULL);
+	rtnl_register(PF_DECnet, RTM_DELADDR, dn_nl_deladdr, NULL, NULL);
+	rtnl_register(PF_DECnet, RTM_GETADDR, NULL, dn_nl_dump_ifaddr, NULL);
 
 	proc_net_fops_create(&init_net, "decnet_dev", S_IRUGO, &dn_dev_seq_fops);
 
net/decnet/dn_fib.c +2 -2
index 1c74ed3..104324d 100644
@@ -763,8 +763,8 @@ void __init dn_fib_init(void)
 
 	register_dnaddr_notifier(&dn_fib_dnaddr_notifier);
 
-	rtnl_register(PF_DECnet, RTM_NEWROUTE, dn_fib_rtm_newroute, NULL);
-	rtnl_register(PF_DECnet, RTM_DELROUTE, dn_fib_rtm_delroute, NULL);
+	rtnl_register(PF_DECnet, RTM_NEWROUTE, dn_fib_rtm_newroute, NULL, NULL);
+	rtnl_register(PF_DECnet, RTM_DELROUTE, dn_fib_rtm_delroute, NULL, NULL);
 }
 
 
net/decnet/dn_route.c +3 -2
index 74544bc..2949ca4 100644
@@ -1841,10 +1841,11 @@ void __init dn_route_init(void)
 	proc_net_fops_create(&init_net, "decnet_cache", S_IRUGO, &dn_rt_cache_seq_fops);
 
 #ifdef CONFIG_DECNET_ROUTER
-	rtnl_register(PF_DECnet, RTM_GETROUTE, dn_cache_getroute, dn_fib_dump);
+	rtnl_register(PF_DECnet, RTM_GETROUTE, dn_cache_getroute,
+		      dn_fib_dump, NULL);
 #else
 	rtnl_register(PF_DECnet, RTM_GETROUTE, dn_cache_getroute,
-		      dn_cache_dump);
+		      dn_cache_dump, NULL);
 #endif
 }
 
net/ipv4/devinet.c +3 -3
index 5345b0b..fee7550 100644
@@ -1833,8 +1833,8 @@ void __init devinet_init(void)
 
 	rtnl_af_register(&inet_af_ops);
 
-	rtnl_register(PF_INET, RTM_NEWADDR, inet_rtm_newaddr, NULL);
-	rtnl_register(PF_INET, RTM_DELADDR, inet_rtm_deladdr, NULL);
-	rtnl_register(PF_INET, RTM_GETADDR, NULL, inet_dump_ifaddr);
+	rtnl_register(PF_INET, RTM_NEWADDR, inet_rtm_newaddr, NULL, NULL);
+	rtnl_register(PF_INET, RTM_DELADDR, inet_rtm_deladdr, NULL, NULL);
+	rtnl_register(PF_INET, RTM_GETADDR, NULL, inet_dump_ifaddr, NULL);
 }
 
net/ipv4/fib_frontend.c +3 -3
index 2252471..92fc5f6 100644
@@ -1124,9 +1124,9 @@ static struct pernet_operations fib_net_ops = {
 
 void __init ip_fib_init(void)
 {
-	rtnl_register(PF_INET, RTM_NEWROUTE, inet_rtm_newroute, NULL);
-	rtnl_register(PF_INET, RTM_DELROUTE, inet_rtm_delroute, NULL);
-	rtnl_register(PF_INET, RTM_GETROUTE, NULL, inet_dump_fib);
+	rtnl_register(PF_INET, RTM_NEWROUTE, inet_rtm_newroute, NULL, NULL);
+	rtnl_register(PF_INET, RTM_DELROUTE, inet_rtm_delroute, NULL, NULL);
+	rtnl_register(PF_INET, RTM_GETROUTE, NULL, inet_dump_fib, NULL);
 
 	register_pernet_subsys(&fib_net_ops);
 	register_netdevice_notifier(&fib_netdev_notifier);
net/ipv4/inet_diag.c +1 -1
index 6ffe94c..5ff4765 100644
@@ -871,7 +871,7 @@ static int inet_diag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
 		}
 
 		return netlink_dump_start(idiagnl, skb, nlh,
-					  inet_diag_dump, NULL);
+					  inet_diag_dump, NULL, 0);
 	}
 
 	return inet_diag_get_exact(skb, nlh);
net/ipv4/ipmr.c +2 -1
index 30a7763..aae2bd8 100644
@@ -2544,7 +2544,8 @@ int __init ip_mr_init(void)
 		goto add_proto_fail;
 	}
 #endif
-	rtnl_register(RTNL_FAMILY_IPMR, RTM_GETROUTE, NULL, ipmr_rtm_dumproute);
+	rtnl_register(RTNL_FAMILY_IPMR, RTM_GETROUTE,
+		      NULL, ipmr_rtm_dumproute, NULL);
 	return 0;
 
 #ifdef CONFIG_IP_PIMSM_V2
net/ipv4/route.c +1 -1
index 6a83840..eec0caa 100644
@@ -3312,7 +3312,7 @@ int __init ip_rt_init(void)
 	xfrm_init();
 	xfrm4_init(ip_rt_max_size);
 #endif
-	rtnl_register(PF_INET, RTM_GETROUTE, inet_rtm_getroute, NULL);
+	rtnl_register(PF_INET, RTM_GETROUTE, inet_rtm_getroute, NULL, NULL);
 
 #ifdef CONFIG_SYSCTL
 	register_pernet_subsys(&sysctl_route_ops);
net/ipv6/addrconf.c +6 -6
index c663a3b..3629ae7 100644
@@ -4704,16 +4704,16 @@ int __init addrconf_init(void)
 	if (err < 0)
 		goto errout_af;
 
-	err = __rtnl_register(PF_INET6, RTM_GETLINK, NULL, inet6_dump_ifinfo);
+	err = __rtnl_register(PF_INET6, RTM_GETLINK, NULL, inet6_dump_ifinfo, NULL);
 	if (err < 0)
 		goto errout;
 
 	/* Only the first call to __rtnl_register can fail */
-	__rtnl_register(PF_INET6, RTM_NEWADDR, inet6_rtm_newaddr, NULL);
-	__rtnl_register(PF_INET6, RTM_DELADDR, inet6_rtm_deladdr, NULL);
-	__rtnl_register(PF_INET6, RTM_GETADDR, inet6_rtm_getaddr, inet6_dump_ifaddr);
-	__rtnl_register(PF_INET6, RTM_GETMULTICAST, NULL, inet6_dump_ifmcaddr);
-	__rtnl_register(PF_INET6, RTM_GETANYCAST, NULL, inet6_dump_ifacaddr);
+	__rtnl_register(PF_INET6, RTM_NEWADDR, inet6_rtm_newaddr, NULL, NULL);
+	__rtnl_register(PF_INET6, RTM_DELADDR, inet6_rtm_deladdr, NULL, NULL);
+	__rtnl_register(PF_INET6, RTM_GETADDR, inet6_rtm_getaddr, inet6_dump_ifaddr, NULL);
+	__rtnl_register(PF_INET6, RTM_GETMULTICAST, NULL, inet6_dump_ifmcaddr, NULL);
+	__rtnl_register(PF_INET6, RTM_GETANYCAST, NULL, inet6_dump_ifacaddr, NULL);
 
 	ipv6_addr_label_rtnl_register();
 
net/ipv6/addrlabel.c +3 -3
index c8993e5..f3aa749 100644
@@ -592,8 +592,8 @@ out:
 
 void __init ipv6_addr_label_rtnl_register(void)
 {
-	__rtnl_register(PF_INET6, RTM_NEWADDRLABEL, ip6addrlbl_newdel, NULL);
-	__rtnl_register(PF_INET6, RTM_DELADDRLABEL, ip6addrlbl_newdel, NULL);
-	__rtnl_register(PF_INET6, RTM_GETADDRLABEL, ip6addrlbl_get, ip6addrlbl_dump);
+	__rtnl_register(PF_INET6, RTM_NEWADDRLABEL, ip6addrlbl_newdel, NULL, NULL);
+	__rtnl_register(PF_INET6, RTM_DELADDRLABEL, ip6addrlbl_newdel, NULL, NULL);
+	__rtnl_register(PF_INET6, RTM_GETADDRLABEL, ip6addrlbl_get, ip6addrlbl_dump, NULL);
 }
 
net/ipv6/ip6_fib.c +1 -1
index 4076a0b..9b257da 100644
@@ -1586,7 +1586,7 @@ int __init fib6_init(void)
 	if (ret)
 		goto out_kmem_cache_create;
 
-	ret = __rtnl_register(PF_INET6, RTM_GETROUTE, NULL, inet6_dump_fib);
+	ret = __rtnl_register(PF_INET6, RTM_GETROUTE, NULL, inet6_dump_fib, NULL);
 	if (ret)
 		goto out_unregister_subsys;
 out:
net/ipv6/ip6mr.c +1 -1
index 82a8099..1edfcc9 100644
@@ -1354,7 +1354,7 @@ int __init ip6_mr_init(void)
 		goto add_proto_fail;
 	}
 #endif
-	rtnl_register(RTNL_FAMILY_IP6MR, RTM_GETROUTE, NULL, ip6mr_rtm_dumproute);
+	rtnl_register(RTNL_FAMILY_IP6MR, RTM_GETROUTE, NULL, ip6mr_rtm_dumproute, NULL);
 	return 0;
 #ifdef CONFIG_IPV6_PIMSM_V2
 add_proto_fail:
net/ipv6/route.c +3 -3
index f1be5c5..1c49165 100644
@@ -2924,9 +2924,9 @@ int __init ip6_route_init(void)
 		goto xfrm6_init;
 
 	ret = -ENOBUFS;
-	if (__rtnl_register(PF_INET6, RTM_NEWROUTE, inet6_rtm_newroute, NULL) ||
-	    __rtnl_register(PF_INET6, RTM_DELROUTE, inet6_rtm_delroute, NULL) ||
-	    __rtnl_register(PF_INET6, RTM_GETROUTE, inet6_rtm_getroute, NULL))
+	if (__rtnl_register(PF_INET6, RTM_NEWROUTE, inet6_rtm_newroute, NULL, NULL) ||
+	    __rtnl_register(PF_INET6, RTM_DELROUTE, inet6_rtm_delroute, NULL, NULL) ||
+	    __rtnl_register(PF_INET6, RTM_GETROUTE, inet6_rtm_getroute, NULL, NULL))
 		goto fib6_rules_init;
 
 	ret = register_netdevice_notifier(&ip6_route_dev_notifier);
net/netfilter/ipset/ip_set_core.c +1 -1
index 72d1ac6..dc1528c 100644
@@ -1120,7 +1120,7 @@ ip_set_dump(struct sock *ctnl, struct sk_buff *skb,
 
 	return netlink_dump_start(ctnl, skb, nlh,
 				  ip_set_dump_start,
-				  ip_set_dump_done);
+				  ip_set_dump_done, 0);
 }
 
 /* Add, del and test */
net/netfilter/nf_conntrack_netlink.c +2 -2
index 30bf8a1..e3e8d4c 100644
@@ -970,7 +970,7 @@ ctnetlink_get_conntrack(struct sock *ctnl, struct sk_buff *skb,
 
 	if (nlh->nlmsg_flags & NLM_F_DUMP)
 		return netlink_dump_start(ctnl, skb, nlh, ctnetlink_dump_table,
-					  ctnetlink_done);
+					  ctnetlink_done, 0);
 
 	err = ctnetlink_parse_zone(cda[CTA_ZONE], &zone);
 	if (err < 0)
@@ -1836,7 +1836,7 @@ ctnetlink_get_expect(struct sock *ctnl, struct sk_buff *skb,
 	if (nlh->nlmsg_flags & NLM_F_DUMP) {
 		return netlink_dump_start(ctnl, skb, nlh,
 					  ctnetlink_exp_dump_table,
-					  ctnetlink_exp_done);
+					  ctnetlink_exp_done, 0);
 	}
 
 	err = ctnetlink_parse_zone(cda[CTA_EXPECT_ZONE], &zone);
net/netlink/af_netlink.c +11 -6
index c8f35b5..063bee9 100644
@@ -1665,13 +1665,10 @@ static int netlink_dump(struct sock *sk)
 {
 	struct netlink_sock *nlk = nlk_sk(sk);
 	struct netlink_callback *cb;
-	struct sk_buff *skb;
+	struct sk_buff *skb = NULL;
 	struct nlmsghdr *nlh;
 	int len, err = -ENOBUFS;
-
-	skb = sock_rmalloc(sk, NLMSG_GOODSIZE, 0, GFP_KERNEL);
-	if (!skb)
-		goto errout;
+	int alloc_size;
 
 	mutex_lock(nlk->cb_mutex);
 
@@ -1681,6 +1678,12 @@ static int netlink_dump(struct sock *sk)
 		goto errout_skb;
 	}
 
+	alloc_size = max_t(int, cb->min_dump_alloc, NLMSG_GOODSIZE);
+
+	skb = sock_rmalloc(sk, alloc_size, 0, GFP_KERNEL);
+	if (!skb)
+		goto errout;
+
 	len = cb->dump(skb, cb);
 
 	if (len > 0) {
@@ -1727,7 +1730,8 @@ int netlink_dump_start(struct sock *ssk, struct sk_buff *skb,
 		       const struct nlmsghdr *nlh,
 		       int (*dump)(struct sk_buff *skb,
 				   struct netlink_callback *),
-		       int (*done)(struct netlink_callback *))
+		       int (*done)(struct netlink_callback *),
+		       u16 min_dump_alloc)
 {
 	struct netlink_callback *cb;
 	struct sock *sk;
@@ -1741,6 +1745,7 @@ int netlink_dump_start(struct sock *ssk, struct sk_buff *skb,
 	cb->dump = dump;
 	cb->done = done;
 	cb->nlh = nlh;
+	cb->min_dump_alloc = min_dump_alloc;
 	atomic_inc(&skb->users);
 	cb->skb = skb;
 
net/netlink/genetlink.c +1 -1
index 1781d99..482fa57 100644
@@ -525,7 +525,7 @@ static int genl_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
 
 		genl_unlock();
 		err = netlink_dump_start(net->genl_sock, skb, nlh,
-					 ops->dumpit, ops->done);
+					 ops->dumpit, ops->done, 0);
 		genl_lock();
 		return err;
 	}
net/phonet/pn_netlink.c +6 -6
index 438accb..4ad4bb9 100644
@@ -289,15 +289,15 @@ out:
 
 int __init phonet_netlink_register(void)
 {
-	int err = __rtnl_register(PF_PHONET, RTM_NEWADDR, addr_doit, NULL);
+	int err = __rtnl_register(PF_PHONET, RTM_NEWADDR, addr_doit, NULL, NULL);
 	if (err)
 		return err;
 
 	/* Further __rtnl_register() cannot fail */
-	__rtnl_register(PF_PHONET, RTM_DELADDR, addr_doit, NULL);
-	__rtnl_register(PF_PHONET, RTM_GETADDR, NULL, getaddr_dumpit);
-	__rtnl_register(PF_PHONET, RTM_NEWROUTE, route_doit, NULL);
-	__rtnl_register(PF_PHONET, RTM_DELROUTE, route_doit, NULL);
-	__rtnl_register(PF_PHONET, RTM_GETROUTE, NULL, route_dumpit);
+	__rtnl_register(PF_PHONET, RTM_DELADDR, addr_doit, NULL, NULL);
+	__rtnl_register(PF_PHONET, RTM_GETADDR, NULL, getaddr_dumpit, NULL);
+	__rtnl_register(PF_PHONET, RTM_NEWROUTE, route_doit, NULL, NULL);
+	__rtnl_register(PF_PHONET, RTM_DELROUTE, route_doit, NULL, NULL);
+	__rtnl_register(PF_PHONET, RTM_GETROUTE, NULL, route_dumpit, NULL);
 	return 0;
 }
net/sched/act_api.c +3 -3
index 14b42f4..c857763 100644
@@ -1120,9 +1120,9 @@ nlmsg_failure:
 
 static int __init tc_action_init(void)
 {
-	rtnl_register(PF_UNSPEC, RTM_NEWACTION, tc_ctl_action, NULL);
-	rtnl_register(PF_UNSPEC, RTM_DELACTION, tc_ctl_action, NULL);
-	rtnl_register(PF_UNSPEC, RTM_GETACTION, tc_ctl_action, tc_dump_action);
+	rtnl_register(PF_UNSPEC, RTM_NEWACTION, tc_ctl_action, NULL, NULL);
+	rtnl_register(PF_UNSPEC, RTM_DELACTION, tc_ctl_action, NULL, NULL);
+	rtnl_register(PF_UNSPEC, RTM_GETACTION, tc_ctl_action, tc_dump_action, NULL);
 
 	return 0;
 }
net/sched/cls_api.c +3 -3
index bb2c523..9563887 100644
@@ -610,10 +610,10 @@ EXPORT_SYMBOL(tcf_exts_dump_stats);
 
 static int __init tc_filter_init(void)
 {
-	rtnl_register(PF_UNSPEC, RTM_NEWTFILTER, tc_ctl_tfilter, NULL);
-	rtnl_register(PF_UNSPEC, RTM_DELTFILTER, tc_ctl_tfilter, NULL);
+	rtnl_register(PF_UNSPEC, RTM_NEWTFILTER, tc_ctl_tfilter, NULL, NULL);
+	rtnl_register(PF_UNSPEC, RTM_DELTFILTER, tc_ctl_tfilter, NULL, NULL);
 	rtnl_register(PF_UNSPEC, RTM_GETTFILTER, tc_ctl_tfilter,
-						 tc_dump_tfilter);
+		      tc_dump_tfilter, NULL);
 
 	return 0;
 }
net/sched/sch_api.c +6 -6
index 7490f3f..7870a92 100644
@@ -1794,12 +1794,12 @@ static int __init pktsched_init(void)
 	register_qdisc(&pfifo_head_drop_qdisc_ops);
 	register_qdisc(&mq_qdisc_ops);
 
-	rtnl_register(PF_UNSPEC, RTM_NEWQDISC, tc_modify_qdisc, NULL);
-	rtnl_register(PF_UNSPEC, RTM_DELQDISC, tc_get_qdisc, NULL);
-	rtnl_register(PF_UNSPEC, RTM_GETQDISC, tc_get_qdisc, tc_dump_qdisc);
-	rtnl_register(PF_UNSPEC, RTM_NEWTCLASS, tc_ctl_tclass, NULL);
-	rtnl_register(PF_UNSPEC, RTM_DELTCLASS, tc_ctl_tclass, NULL);
-	rtnl_register(PF_UNSPEC, RTM_GETTCLASS, tc_ctl_tclass, tc_dump_tclass);
+	rtnl_register(PF_UNSPEC, RTM_NEWQDISC, tc_modify_qdisc, NULL, NULL);
+	rtnl_register(PF_UNSPEC, RTM_DELQDISC, tc_get_qdisc, NULL, NULL);
+	rtnl_register(PF_UNSPEC, RTM_GETQDISC, tc_get_qdisc, tc_dump_qdisc, NULL);
+	rtnl_register(PF_UNSPEC, RTM_NEWTCLASS, tc_ctl_tclass, NULL, NULL);
+	rtnl_register(PF_UNSPEC, RTM_DELTCLASS, tc_ctl_tclass, NULL, NULL);
+	rtnl_register(PF_UNSPEC, RTM_GETTCLASS, tc_ctl_tclass, tc_dump_tclass, NULL);
 
 	return 0;
 }
net/xfrm/xfrm_user.c +1 -1
index 5d1d60d..d31e914 100644
@@ -2296,7 +2296,7 @@ static int xfrm_user_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
 		if (link->dump == NULL)
 			return -EINVAL;
 
-		return netlink_dump_start(net->xfrm.nlsk, skb, nlh, link->dump, link->done);
+		return netlink_dump_start(net->xfrm.nlsk, skb, nlh, link->dump, link->done, 0);
 	}
 
 	err = nlmsg_parse(nlh, xfrm_msg_min[type], attrs, XFRMA_MAX,
#1 lore raw

net/core/rtnetlink.c line 60

Quoted 8 lines · On Mon, 09 May 2011 15:26:29 -0700 Greg Rose <[email protected]> wrote:
net/core/rtnetlink.c +1 -0
@@ -56,6 +56,7 @@
 struct rtnl_link {
 	rtnl_doit_func		doit;
 	rtnl_dumpit_func	dumpit;
+	rtnl_calcit_func calcit;
 };

Minor nit, why not line up the columns like the other two?

#2 lore raw
Quoted 11 lines

-----Original Message-----
From: Stephen Hemminger [mailto:[email protected]]
Sent: Monday, May 09, 2011 3:45 PM
To: Rose, Gregory V
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [RFC V2 PATCH] rtnetlink: Add method to calculate dump info data size

On Mon, 09 May 2011 15:26:29 -0700
Greg Rose <[email protected]> wrote:

Quoted 10 lines

net/core/rtnetlink.c line 60

Quoted 8 lines
net/core/rtnetlink.c +1 -0
@@ -56,6 +56,7 @@
 struct rtnl_link {
 	rtnl_doit_func		doit;
 	rtnl_dumpit_func	dumpit;
+	rtnl_calcit_func calcit;
 };

Minor nit, why not line up the columns like the other two?

Haste I suppose.

If this RFC gets the go ahead I'll clean it up. There's other check patch failures I need to fix anyways but I didn't want to spend a lot of time on something I wasn't sure would fly.

Thanks,

- Greg

#3 lore raw
In reply to Greg Rose
Quoted 29 lines · Greg Rose

The message size allocated for rtnl info dumps was limited to a single page. This is not enough for additional interface info available with devices that support SR-IOV. Calculate the amount of data required so the dump can allocate enough data to satisfy the request.

V2 of this patch adds a new argument to the rtnl_register service that allows for a new method to calculate the amount of data required to complete the info dump request. So far the method is only implemented for the RTM_GETLINK slot.

net/core/rtnetlink.c +16 -0
+static u16 rtnl_calcit(struct sk_buff *skb)
+{
+	struct net *net = sock_net(skb->sk);
+	int h;
+	int idx = 0, s_idx;
+	struct net_device *dev;
+	struct hlist_head *head;
+	struct hlist_node *node;
+	u16 alloc_size = 0;
+
+	for (h = 0; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
+		idx = 0;
+		head = &net->dev_index_head[h];
+		hlist_for_each_entry(dev, node, head, index_hlist) {
+			if (idx < s_idx) {
+				idx++;

net/core/rtnetlink.c static int rtnl_getlink(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg) · line 1869

Quoted 10 lines
net/core/rtnetlink.c +10 -0
+				continue;
+			}
+			alloc_size = (u16)if_nlmsg_size(dev);
+			break;
+		}
+	}
+
+	return alloc_size;
+}
+

Sorry this wont scale. Some machines have thousand of devices.

Just make an upper approximation, you dont need an exact one ;)

#4 lore raw
Quoted 44 lines · On Tue, 10 May 2011 04:43:33 +0200 Eric Dumazet <[email protected]> wrote:
Quoted 29 lines · Greg Rose

The message size allocated for rtnl info dumps was limited to a single page. This is not enough for additional interface info available with devices that support SR-IOV. Calculate the amount of data required so the dump can allocate enough data to satisfy the request.

V2 of this patch adds a new argument to the rtnl_register service that allows for a new method to calculate the amount of data required to complete the info dump request. So far the method is only implemented for the RTM_GETLINK slot.

net/core/rtnetlink.c +16 -0
+static u16 rtnl_calcit(struct sk_buff *skb)
+{
+	struct net *net = sock_net(skb->sk);
+	int h;
+	int idx = 0, s_idx;
+	struct net_device *dev;
+	struct hlist_head *head;
+	struct hlist_node *node;
+	u16 alloc_size = 0;
+
+	for (h = 0; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
+		idx = 0;
+		head = &net->dev_index_head[h];
+		hlist_for_each_entry(dev, node, head, index_hlist) {
+			if (idx < s_idx) {
+				idx++;

net/core/rtnetlink.c static int rtnl_getlink(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg) · line 1869

Quoted 10 lines
net/core/rtnetlink.c +10 -0
+				continue;
+			}
+			alloc_size = (u16)if_nlmsg_size(dev);
+			break;
+		}
+	}
+
+	return alloc_size;
+}
+

Sorry this wont scale. Some machines have thousand of devices.

Quoted 1 line

Just make an upper approximation, you dont need an exact one ;)

The route dump does scale, can't you use a similar logic? The result doesn't come back as one huge allocation. I regularly test 600K routes on small machines.

#5 lore raw
Quoted 47 lines · Stephen Hemminger
Quoted 44 lines · On Tue, 10 May 2011 04:43:33 +0200 Eric Dumazet <[email protected]> wrote:
Quoted 29 lines · Greg Rose

The message size allocated for rtnl info dumps was limited to a single page. This is not enough for additional interface info available with devices that support SR-IOV. Calculate the amount of data required so the dump can allocate enough data to satisfy the request.

V2 of this patch adds a new argument to the rtnl_register service that allows for a new method to calculate the amount of data required to complete the info dump request. So far the method is only implemented for the RTM_GETLINK slot.

net/core/rtnetlink.c +16 -0
+static u16 rtnl_calcit(struct sk_buff *skb)
+{
+	struct net *net = sock_net(skb->sk);
+	int h;
+	int idx = 0, s_idx;
+	struct net_device *dev;
+	struct hlist_head *head;
+	struct hlist_node *node;
+	u16 alloc_size = 0;
+
+	for (h = 0; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
+		idx = 0;
+		head = &net->dev_index_head[h];
+		hlist_for_each_entry(dev, node, head, index_hlist) {
+			if (idx < s_idx) {
+				idx++;

net/core/rtnetlink.c static int rtnl_getlink(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg) · line 1869

Quoted 10 lines
net/core/rtnetlink.c +10 -0
+				continue;
+			}
+			alloc_size = (u16)if_nlmsg_size(dev);
+			break;
+		}
+	}
+
+	return alloc_size;
+}
+

Sorry this wont scale. Some machines have thousand of devices.

Quoted 6 lines
Quoted 1 line

Just make an upper approximation, you dont need an exact one ;)

The route dump does scale, can't you use a similar logic? The result doesn't come back as one huge allocation. I regularly test 600K routes on small machines.

Not sure I understand you Stephen.

In Greg patch, rtnl_calcit() would be called for every 4K/8K block "ip" gets from kernel.

If you add a function to route dump that would scan the 600K routes to get the max route size, surely you notice O(N^2) complexity instead of O(N)

We only need to maintain a global variable to hold min_dump_alloc

[ and only increase this variable when necessary, not bother to decrease it when removing a driver ]

maintainer
#6 lore raw

From: Eric Dumazet <[email protected]>
Date: Tue, 10 May 2011 05:45:27 +0200

Quoted 4 lines

We only need to maintain a global variable to hold min_dump_alloc

[ and only increase this variable when necessary, not bother to decrease it when removing a driver ]

Agreed, this is probably the best approach.

#8 lore raw
In reply to Eric Dumazet
Quoted 57 lines · On Tue, 10 May 2011 05:45:27 +0200 Eric Dumazet <[email protected]> wrote:
Quoted 47 lines · Stephen Hemminger
Quoted 44 lines · On Tue, 10 May 2011 04:43:33 +0200 Eric Dumazet <[email protected]> wrote:
Quoted 29 lines · Greg Rose

The message size allocated for rtnl info dumps was limited to a single page. This is not enough for additional interface info available with devices that support SR-IOV. Calculate the amount of data required so the dump can allocate enough data to satisfy the request.

V2 of this patch adds a new argument to the rtnl_register service that allows for a new method to calculate the amount of data required to complete the info dump request. So far the method is only implemented for the RTM_GETLINK slot.

net/core/rtnetlink.c +16 -0
+static u16 rtnl_calcit(struct sk_buff *skb)
+{
+	struct net *net = sock_net(skb->sk);
+	int h;
+	int idx = 0, s_idx;
+	struct net_device *dev;
+	struct hlist_head *head;
+	struct hlist_node *node;
+	u16 alloc_size = 0;
+
+	for (h = 0; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
+		idx = 0;
+		head = &net->dev_index_head[h];
+		hlist_for_each_entry(dev, node, head, index_hlist) {
+			if (idx < s_idx) {
+				idx++;

net/core/rtnetlink.c static int rtnl_getlink(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg) · line 1869

Quoted 10 lines
net/core/rtnetlink.c +10 -0
+				continue;
+			}
+			alloc_size = (u16)if_nlmsg_size(dev);
+			break;
+		}
+	}
+
+	return alloc_size;
+}
+

Sorry this wont scale. Some machines have thousand of devices.

Quoted 6 lines
Quoted 1 line

Just make an upper approximation, you dont need an exact one ;)

The route dump does scale, can't you use a similar logic? The result doesn't come back as one huge allocation. I regularly test 600K routes on small machines.

Not sure I understand you Stephen.

Quoted 8 lines

In Greg patch, rtnl_calcit() would be called for every 4K/8K block "ip" gets from kernel.

If you add a function to route dump that would scan the 600K routes to get the max route size, surely you notice O(N^2) complexity instead of O(N)

We only need to maintain a global variable to hold min_dump_alloc

I was hoping that the new interface dump would not need a pre-calculated size and could just incrementally add values. I was trying to use an analogy with route dumping. The current route dump does not precalculate size.

What happens is dump iterates over the table and puts entries into skb. When space is exhausted in skb the iterator stops and records the key of the where to restart. Then restarts with next skb from there.

This scales O(N) with number of routes and does not have to precompute size.

maintainer
#9 lore raw

From: Stephen Hemminger <[email protected]>
Date: Mon, 9 May 2011 20:56:26 -0700

Quoted 4 lines

I was hoping that the new interface dump would not need a pre-calculated size and could just incrementally add values. I was trying to use an analogy with route dumping. The current route dump does not precalculate size.

Stephen the problem here is that one netdevice being dumped is highly variable because of the VF netlink attributes.

Routes have a fixed reasonably low upper bound in size, so we always are able to fit one route in an SKB.

Netdevices, on the other hand, can have so many VFs that one netdevice entry does not fit even in a single 8K allocated SKB.

That's the failure case this code is trying to fix.

#10 lore raw
In reply to Stephen Hemminger
Quoted 3 lines · Stephen Hemminger

What happens is dump iterates over the table and puts entries into skb. When space is exhausted in skb the iterator stops and records the key of the where to restart.

Exactly : We would increase min_dump_alloc at this point, and not fully recompute it at each round ;)

Problem is we could return an empty answer if first device ever dumped in "ip link" would be a 'large one' and min_dump_alloc not yet increased, so "ip link" would consider table is empty ?

Thats why I suggested to increase min_dump_alloc() when bloated^W driver is loaded.

#7 lore raw
In reply to David Miller
Quoted 12 lines

-----Original Message-----
From: David Miller [mailto:[email protected]]
Sent: Monday, May 09, 2011 8:50 PM
To: [email protected]
Cc: [email protected]; Rose, Gregory V; [email protected]; [email protected]
Subject: Re: [RFC V2 PATCH] rtnetlink: Add method to calculate dump info data size

From: Eric Dumazet <[email protected]>
Date: Tue, 10 May 2011 05:45:27 +0200

Quoted 6 lines
Quoted 4 lines

We only need to maintain a global variable to hold min_dump_alloc

[ and only increase this variable when necessary, not bother to decrease it when removing a driver ]

Agreed, this is probably the best approach.

[Greg Rose]

OK, let me go back and look at doing it this way. I was sort of scratching my head about doing that device lookup on every dump, so this is a good suggestion.

Thanks,

- Greg