* [PATCH] phonet netlink: allow multiple messages per skb in route dump
@ 2015-01-19 11:15 Johannes Berg
2015-01-19 20:11 ` Rémi Denis-Courmont
2015-01-19 21:20 ` David Miller
0 siblings, 2 replies; 4+ messages in thread
From: Johannes Berg @ 2015-01-19 11:15 UTC (permalink / raw)
To: netdev; +Cc: Sakari Ailus, Remi Denis-Courmont, Johannes Berg
From: Johannes Berg <johannes.berg@intel.com>
My previous patch to this file changed the code to be bug-compatible
towards userspace. Unless userspace (which I wasn't able to find)
implements the dump reader by hand in a wrong way, this isn't needed.
If it uses libnl or similar code putting multiple messages into a
single SKB is far more efficient.
Change the code to do this. While at it, also clean it up and don't
use so many variables - just store the address in the callback args
directly.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
---
net/phonet/pn_netlink.c | 22 +++++++---------------
1 file changed, 7 insertions(+), 15 deletions(-)
diff --git a/net/phonet/pn_netlink.c b/net/phonet/pn_netlink.c
index 54d766842c2b..bc5ee5fbe6ae 100644
--- a/net/phonet/pn_netlink.c
+++ b/net/phonet/pn_netlink.c
@@ -272,31 +272,23 @@ static int route_doit(struct sk_buff *skb, struct nlmsghdr *nlh)
static int route_dumpit(struct sk_buff *skb, struct netlink_callback *cb)
{
struct net *net = sock_net(skb->sk);
- u8 addr, addr_idx = 0, addr_start_idx = cb->args[0];
+ u8 addr;
rcu_read_lock();
- for (addr = 0; addr < 64; addr++) {
- struct net_device *dev;
+ for (addr = cb->args[0]; addr < 64; addr++) {
+ struct net_device *dev = phonet_route_get_rcu(net, addr << 2);
- dev = phonet_route_get_rcu(net, addr << 2);
if (!dev)
continue;
- if (addr_idx++ < addr_start_idx)
- continue;
- fill_route(skb, dev, addr << 2, NETLINK_CB(cb->skb).portid,
- cb->nlh->nlmsg_seq, RTM_NEWROUTE);
- /* fill_route() used to return > 0 (or negative errors) but
- * never 0 - ignore the return value and just go out to
- * call dumpit again from outside to preserve the behavior
- */
- goto out;
+ if (fill_route(skb, dev, addr << 2, NETLINK_CB(cb->skb).portid,
+ cb->nlh->nlmsg_seq, RTM_NEWROUTE) < 0)
+ goto out;
}
out:
rcu_read_unlock();
- cb->args[0] = addr_idx;
- cb->args[1] = 0;
+ cb->args[0] = addr;
return skb->len;
}
--
2.1.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] phonet netlink: allow multiple messages per skb in route dump
2015-01-19 11:15 [PATCH] phonet netlink: allow multiple messages per skb in route dump Johannes Berg
@ 2015-01-19 20:11 ` Rémi Denis-Courmont
2015-01-19 20:14 ` Johannes Berg
2015-01-19 21:20 ` David Miller
1 sibling, 1 reply; 4+ messages in thread
From: Rémi Denis-Courmont @ 2015-01-19 20:11 UTC (permalink / raw)
To: Johannes Berg; +Cc: netdev, Sakari Ailus, Remi Denis-Courmont, Johannes Berg
Le lundi 19 janvier 2015, 12:15:24 Johannes Berg a écrit :
> From: Johannes Berg <johannes.berg@intel.com>
>
> My previous patch to this file changed the code to be bug-compatible
> towards userspace. Unless userspace (which I wasn't able to find)
> implements the dump reader by hand in a wrong way, this isn't needed.
The canonical userspace is there (specifically src/pnroute.c):
https://gitorious.org/meego-cellular/phonet-utils/
AFAICT, it should work either way. By now, I expect what's left of the
Maemo/Meego/Mer/whatever community has forked or rewritten it though.
> If it uses libnl or similar code putting multiple messages into a
> single SKB is far more efficient.
>
> Change the code to do this. While at it, also clean it up and don't
> use so many variables - just store the address in the callback args
> directly.
>
> Signed-off-by: Johannes Berg <johannes.berg@intel.com>
> ---
> net/phonet/pn_netlink.c | 22 +++++++---------------
> 1 file changed, 7 insertions(+), 15 deletions(-)
>
> diff --git a/net/phonet/pn_netlink.c b/net/phonet/pn_netlink.c
> index 54d766842c2b..bc5ee5fbe6ae 100644
> --- a/net/phonet/pn_netlink.c
> +++ b/net/phonet/pn_netlink.c
> @@ -272,31 +272,23 @@ static int route_doit(struct sk_buff *skb, struct
> nlmsghdr *nlh) static int route_dumpit(struct sk_buff *skb, struct
> netlink_callback *cb) {
> struct net *net = sock_net(skb->sk);
> - u8 addr, addr_idx = 0, addr_start_idx = cb->args[0];
> + u8 addr;
>
> rcu_read_lock();
> - for (addr = 0; addr < 64; addr++) {
> - struct net_device *dev;
> + for (addr = cb->args[0]; addr < 64; addr++) {
> + struct net_device *dev = phonet_route_get_rcu(net, addr << 2);
>
> - dev = phonet_route_get_rcu(net, addr << 2);
> if (!dev)
> continue;
>
> - if (addr_idx++ < addr_start_idx)
> - continue;
> - fill_route(skb, dev, addr << 2, NETLINK_CB(cb->skb).portid,
> - cb->nlh->nlmsg_seq, RTM_NEWROUTE);
> - /* fill_route() used to return > 0 (or negative errors) but
> - * never 0 - ignore the return value and just go out to
> - * call dumpit again from outside to preserve the behavior
> - */
> - goto out;
> + if (fill_route(skb, dev, addr << 2, NETLINK_CB(cb->skb).portid,
> + cb->nlh->nlmsg_seq, RTM_NEWROUTE) < 0)
> + goto out;
> }
>
> out:
> rcu_read_unlock();
> - cb->args[0] = addr_idx;
> - cb->args[1] = 0;
> + cb->args[0] = addr;
>
> return skb->len;
> }
--
Rémi
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] phonet netlink: allow multiple messages per skb in route dump
2015-01-19 20:11 ` Rémi Denis-Courmont
@ 2015-01-19 20:14 ` Johannes Berg
0 siblings, 0 replies; 4+ messages in thread
From: Johannes Berg @ 2015-01-19 20:14 UTC (permalink / raw)
To: Rémi Denis-Courmont; +Cc: netdev, Sakari Ailus, Remi Denis-Courmont
On Mon, 2015-01-19 at 22:11 +0200, Rémi Denis-Courmont wrote:
> Le lundi 19 janvier 2015, 12:15:24 Johannes Berg a écrit :
> > From: Johannes Berg <johannes.berg@intel.com>
> >
> > My previous patch to this file changed the code to be bug-compatible
> > towards userspace. Unless userspace (which I wasn't able to find)
> > implements the dump reader by hand in a wrong way, this isn't needed.
>
> The canonical userspace is there (specifically src/pnroute.c):
> https://gitorious.org/meego-cellular/phonet-utils/
Ah, cool.
> AFAICT, it should work either way. By now, I expect what's left of the
> Maemo/Meego/Mer/whatever community has forked or rewritten it though.
The loop
for (struct nlmsghdr *nlh = (struct nlmsghdr *)&req;
NLMSG_OK (nlh, (size_t)ret); nlh = NLMSG_NEXT (nlh, ret))
should make it do the right thing, I agree.
johannes
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] phonet netlink: allow multiple messages per skb in route dump
2015-01-19 11:15 [PATCH] phonet netlink: allow multiple messages per skb in route dump Johannes Berg
2015-01-19 20:11 ` Rémi Denis-Courmont
@ 2015-01-19 21:20 ` David Miller
1 sibling, 0 replies; 4+ messages in thread
From: David Miller @ 2015-01-19 21:20 UTC (permalink / raw)
To: johannes; +Cc: netdev, sakari.ailus, courmisch, johannes.berg
From: Johannes Berg <johannes@sipsolutions.net>
Date: Mon, 19 Jan 2015 12:15:24 +0100
> From: Johannes Berg <johannes.berg@intel.com>
>
> My previous patch to this file changed the code to be bug-compatible
> towards userspace. Unless userspace (which I wasn't able to find)
> implements the dump reader by hand in a wrong way, this isn't needed.
> If it uses libnl or similar code putting multiple messages into a
> single SKB is far more efficient.
>
> Change the code to do this. While at it, also clean it up and don't
> use so many variables - just store the address in the callback args
> directly.
>
> Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Applied, thanks.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-01-19 21:20 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-19 11:15 [PATCH] phonet netlink: allow multiple messages per skb in route dump Johannes Berg
2015-01-19 20:11 ` Rémi Denis-Courmont
2015-01-19 20:14 ` Johannes Berg
2015-01-19 21:20 ` David Miller
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).