netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC] net: netlink -- Allow netlink_dump to return error code if protocol handler is missed
@ 2012-11-02 17:35 Cyrill Gorcunov
  2012-11-03 16:17 ` Pavel Emelyanov
  0 siblings, 1 reply; 4+ messages in thread
From: Cyrill Gorcunov @ 2012-11-02 17:35 UTC (permalink / raw)
  To: NETDEV; +Cc: David Miller, Eric Dumazet, Pavel Emelyanov

We've observed that in case if UDP diag module is not
supported in kernel the netlink returns NLMSG_DONE without
notifying a caller that handler is missed.

This patch makes netlink_dump to return error code instead.

So as example it become possible to detect such situation
and handle it gracefully on userspace level.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
CC: David Miller <davem@davemloft.net>
CC: Eric Dumazet <eric.dumazet@gmail.com>
CC: Pavel Emelyanov <xemul@parallels.com>
---
 net/ipv4/inet_diag.c     |    5 ++++-
 net/netlink/af_netlink.c |    4 ++++
 2 files changed, 8 insertions(+), 1 deletion(-)

Index: linux-2.6.git/net/ipv4/inet_diag.c
===================================================================
--- linux-2.6.git.orig/net/ipv4/inet_diag.c
+++ linux-2.6.git/net/ipv4/inet_diag.c
@@ -895,13 +895,16 @@ static int __inet_diag_dump(struct sk_bu
 		struct inet_diag_req_v2 *r, struct nlattr *bc)
 {
 	const struct inet_diag_handler *handler;
+	int err = 0;
 
 	handler = inet_diag_lock_handler(r->sdiag_protocol);
 	if (!IS_ERR(handler))
 		handler->dump(skb, cb, r, bc);
+	else
+		err = PTR_ERR(handler);
 	inet_diag_unlock_handler(handler);
 
-	return skb->len;
+	return err ? : skb->len;
 }
 
 static int inet_diag_dump(struct sk_buff *skb, struct netlink_callback *cb)
Index: linux-2.6.git/net/netlink/af_netlink.c
===================================================================
--- linux-2.6.git.orig/net/netlink/af_netlink.c
+++ linux-2.6.git/net/netlink/af_netlink.c
@@ -1740,6 +1740,10 @@ static int netlink_dump(struct sock *sk)
 		else
 			__netlink_sendskb(sk, skb);
 		return 0;
+	} else if (len < 0) {
+		err = len;
+		nlk->cb = NULL;
+		goto errout_skb;
 	}
 
 	nlh = nlmsg_put_answer(skb, cb, NLMSG_DONE, sizeof(len), NLM_F_MULTI);

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [RFC] net: netlink -- Allow netlink_dump to return error code if protocol handler is missed
  2012-11-02 17:35 [RFC] net: netlink -- Allow netlink_dump to return error code if protocol handler is missed Cyrill Gorcunov
@ 2012-11-03 16:17 ` Pavel Emelyanov
  2012-11-03 16:39   ` Cyrill Gorcunov
  0 siblings, 1 reply; 4+ messages in thread
From: Pavel Emelyanov @ 2012-11-03 16:17 UTC (permalink / raw)
  To: Cyrill Gorcunov; +Cc: NETDEV, David Miller, Eric Dumazet

On 11/02/2012 09:35 PM, Cyrill Gorcunov wrote:
> We've observed that in case if UDP diag module is not
> supported in kernel the netlink returns NLMSG_DONE without
> notifying a caller that handler is missed.
> 
> This patch makes netlink_dump to return error code instead.
> 
> So as example it become possible to detect such situation
> and handle it gracefully on userspace level.
> 
> Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
> CC: David Miller <davem@davemloft.net>
> CC: Eric Dumazet <eric.dumazet@gmail.com>
> CC: Pavel Emelyanov <xemul@parallels.com>
> ---
>  net/ipv4/inet_diag.c     |    5 ++++-
>  net/netlink/af_netlink.c |    4 ++++
>  2 files changed, 8 insertions(+), 1 deletion(-)
> 
> Index: linux-2.6.git/net/ipv4/inet_diag.c
> ===================================================================
> --- linux-2.6.git.orig/net/ipv4/inet_diag.c
> +++ linux-2.6.git/net/ipv4/inet_diag.c
> @@ -895,13 +895,16 @@ static int __inet_diag_dump(struct sk_bu
>  		struct inet_diag_req_v2 *r, struct nlattr *bc)
>  {
>  	const struct inet_diag_handler *handler;
> +	int err = 0;
>  
>  	handler = inet_diag_lock_handler(r->sdiag_protocol);
>  	if (!IS_ERR(handler))
>  		handler->dump(skb, cb, r, bc);
> +	else
> +		err = PTR_ERR(handler);
>  	inet_diag_unlock_handler(handler);
>  
> -	return skb->len;
> +	return err ? : skb->len;
>  }
>  
>  static int inet_diag_dump(struct sk_buff *skb, struct netlink_callback *cb)
> Index: linux-2.6.git/net/netlink/af_netlink.c
> ===================================================================
> --- linux-2.6.git.orig/net/netlink/af_netlink.c
> +++ linux-2.6.git/net/netlink/af_netlink.c
> @@ -1740,6 +1740,10 @@ static int netlink_dump(struct sock *sk)
>  		else
>  			__netlink_sendskb(sk, skb);
>  		return 0;
> +	} else if (len < 0) {
> +		err = len;
> +		nlk->cb = NULL;
> +		goto errout_skb;

When family-level handler is absent and sock_diag returns error this error
gets propagated back to user without this fix. Why do we need it in case
we return error from protocol-level handler?

>  	}
>  
>  	nlh = nlmsg_put_answer(skb, cb, NLMSG_DONE, sizeof(len), NLM_F_MULTI);
> .
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [RFC] net: netlink -- Allow netlink_dump to return error code if protocol handler is missed
  2012-11-03 16:17 ` Pavel Emelyanov
@ 2012-11-03 16:39   ` Cyrill Gorcunov
  2012-11-03 19:16     ` Cyrill Gorcunov
  0 siblings, 1 reply; 4+ messages in thread
From: Cyrill Gorcunov @ 2012-11-03 16:39 UTC (permalink / raw)
  To: Pavel Emelyanov; +Cc: NETDEV, David Miller, Eric Dumazet

On Sat, Nov 03, 2012 at 08:17:50PM +0400, Pavel Emelyanov wrote:
> >  static int inet_diag_dump(struct sk_buff *skb, struct netlink_callback *cb)
> > Index: linux-2.6.git/net/netlink/af_netlink.c
> > ===================================================================
> > --- linux-2.6.git.orig/net/netlink/af_netlink.c
> > +++ linux-2.6.git/net/netlink/af_netlink.c
> > @@ -1740,6 +1740,10 @@ static int netlink_dump(struct sock *sk)
> >  		else
> >  			__netlink_sendskb(sk, skb);
> >  		return 0;
> > +	} else if (len < 0) {
> > +		err = len;
> > +		nlk->cb = NULL;
> > +		goto errout_skb;
> 
> When family-level handler is absent and sock_diag returns error this error
> gets propagated back to user without this fix. Why do we need it in case
> we return error from protocol-level handler?

Because as far as I can say the family-level handler already has such error
returning code in __sock_diag_rcv_msg. Or you mean something else?

	Cyrill

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [RFC] net: netlink -- Allow netlink_dump to return error code if protocol handler is missed
  2012-11-03 16:39   ` Cyrill Gorcunov
@ 2012-11-03 19:16     ` Cyrill Gorcunov
  0 siblings, 0 replies; 4+ messages in thread
From: Cyrill Gorcunov @ 2012-11-03 19:16 UTC (permalink / raw)
  To: Pavel Emelyanov; +Cc: NETDEV, David Miller, Eric Dumazet

On Sat, Nov 03, 2012 at 08:39:58PM +0400, Cyrill Gorcunov wrote:
> On Sat, Nov 03, 2012 at 08:17:50PM +0400, Pavel Emelyanov wrote:
> > >  static int inet_diag_dump(struct sk_buff *skb, struct netlink_callback *cb)
> > > Index: linux-2.6.git/net/netlink/af_netlink.c
> > > ===================================================================
> > > --- linux-2.6.git.orig/net/netlink/af_netlink.c
> > > +++ linux-2.6.git/net/netlink/af_netlink.c
> > > @@ -1740,6 +1740,10 @@ static int netlink_dump(struct sock *sk)
> > >  		else
> > >  			__netlink_sendskb(sk, skb);
> > >  		return 0;
> > > +	} else if (len < 0) {
> > > +		err = len;
> > > +		nlk->cb = NULL;
> > > +		goto errout_skb;
> > 
> > When family-level handler is absent and sock_diag returns error this error
> > gets propagated back to user without this fix. Why do we need it in case
> > we return error from protocol-level handler?
> 
> Because as far as I can say the family-level handler already has such error
> returning code in __sock_diag_rcv_msg. Or you mean something else?

OK, it seems I got what you mean, cooking/testing new patch.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-11-03 19:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-02 17:35 [RFC] net: netlink -- Allow netlink_dump to return error code if protocol handler is missed Cyrill Gorcunov
2012-11-03 16:17 ` Pavel Emelyanov
2012-11-03 16:39   ` Cyrill Gorcunov
2012-11-03 19:16     ` Cyrill Gorcunov

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).