All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next 1/2] net/ipv6/udp: Add encap_rcv support to IPv6 UDP
@ 2012-04-11  2:20 Benjamin LaHaise
  2012-04-11 11:51 ` James Chapman
  2012-04-13 17:24 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Benjamin LaHaise @ 2012-04-11  2:20 UTC (permalink / raw)
  To: David S. Miller, James Chapman; +Cc: netdev

At present, UDP encapsulated protocols (like L2TP) are only able to use the
encap_rcv hook with UDP over IPv4.  This patch adds the same support for use
with UDP over IPv6.

Signed-off-by: Benjamin LaHaise <bcrl@kvack.org>
---
 net/ipv6/udp.c |   31 +++++++++++++++++++++++++++++++
 1 files changed, 31 insertions(+), 0 deletions(-)

diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
index 37b0699..4d7cd72 100644
--- a/net/ipv6/udp.c
+++ b/net/ipv6/udp.c
@@ -515,6 +515,37 @@ int udpv6_queue_rcv_skb(struct sock * sk, struct sk_buff *skb)
 	if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb))
 		goto drop;
 
+	if (up->encap_type) {
+		int (*encap_rcv)(struct sock *sk, struct sk_buff *skb);
+
+		/*
+		 * This is an encapsulation socket so pass the skb to
+		 * the socket's udp_encap_rcv() hook. Otherwise, just
+		 * fall through and pass this up the UDP socket.
+		 * up->encap_rcv() returns the following value:
+		 * =0 if skb was successfully passed to the encap
+		 *    handler or was discarded by it.
+		 * >0 if skb should be passed on to UDP.
+		 * <0 if skb should be resubmitted as proto -N
+		 */
+
+		/* if we're overly short, let UDP handle it */
+		encap_rcv = ACCESS_ONCE(up->encap_rcv);
+		if (skb->len > sizeof(struct udphdr) && encap_rcv != NULL) {
+			int ret;
+
+			ret = encap_rcv(sk, skb);
+			if (ret <= 0) {
+				UDP6_INC_STATS_BH(sock_net(sk),
+						  UDP_MIB_INDATAGRAMS,
+						  is_udplite);
+				return -ret;
+			}
+		}
+
+		/* FALLTHROUGH -- it's a UDP Packet */
+	}
+
 	/*
 	 * UDP-Lite specific tests, ignored on UDP sockets (see net/ipv4/udp.c).
 	 */
-- 
1.7.4.1


-- 
"Thought is the essence of where you are now."

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

* Re: [PATCH net-next 1/2] net/ipv6/udp: Add encap_rcv support to IPv6 UDP
  2012-04-11  2:20 [PATCH net-next 1/2] net/ipv6/udp: Add encap_rcv support to IPv6 UDP Benjamin LaHaise
@ 2012-04-11 11:51 ` James Chapman
  2012-04-13 17:24 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: James Chapman @ 2012-04-11 11:51 UTC (permalink / raw)
  To: Benjamin LaHaise; +Cc: David S. Miller, netdev

On 11/04/12 03:20, Benjamin LaHaise wrote:
> At present, UDP encapsulated protocols (like L2TP) are only able to use the
> encap_rcv hook with UDP over IPv4.  This patch adds the same support for use
> with UDP over IPv6.
> 
> Signed-off-by: Benjamin LaHaise <bcrl@kvack.org>
Signed-off-by: James Chapman <jchapman@katalix.com>

> ---
>  net/ipv6/udp.c |   31 +++++++++++++++++++++++++++++++
>  1 files changed, 31 insertions(+), 0 deletions(-)
> 
> diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
> index 37b0699..4d7cd72 100644
> --- a/net/ipv6/udp.c
> +++ b/net/ipv6/udp.c
> @@ -515,6 +515,37 @@ int udpv6_queue_rcv_skb(struct sock * sk, struct sk_buff *skb)
>  	if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb))
>  		goto drop;
>  
> +	if (up->encap_type) {
> +		int (*encap_rcv)(struct sock *sk, struct sk_buff *skb);
> +
> +		/*
> +		 * This is an encapsulation socket so pass the skb to
> +		 * the socket's udp_encap_rcv() hook. Otherwise, just
> +		 * fall through and pass this up the UDP socket.
> +		 * up->encap_rcv() returns the following value:
> +		 * =0 if skb was successfully passed to the encap
> +		 *    handler or was discarded by it.
> +		 * >0 if skb should be passed on to UDP.
> +		 * <0 if skb should be resubmitted as proto -N
> +		 */
> +
> +		/* if we're overly short, let UDP handle it */
> +		encap_rcv = ACCESS_ONCE(up->encap_rcv);
> +		if (skb->len > sizeof(struct udphdr) && encap_rcv != NULL) {
> +			int ret;
> +
> +			ret = encap_rcv(sk, skb);
> +			if (ret <= 0) {
> +				UDP6_INC_STATS_BH(sock_net(sk),
> +						  UDP_MIB_INDATAGRAMS,
> +						  is_udplite);
> +				return -ret;
> +			}
> +		}
> +
> +		/* FALLTHROUGH -- it's a UDP Packet */
> +	}
> +
>  	/*
>  	 * UDP-Lite specific tests, ignored on UDP sockets (see net/ipv4/udp.c).
>  	 */



-- 
James Chapman
Katalix Systems Ltd
http://www.katalix.com
Catalysts for your Embedded Linux software development

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

* Re: [PATCH net-next 1/2] net/ipv6/udp: Add encap_rcv support to IPv6 UDP
  2012-04-11  2:20 [PATCH net-next 1/2] net/ipv6/udp: Add encap_rcv support to IPv6 UDP Benjamin LaHaise
  2012-04-11 11:51 ` James Chapman
@ 2012-04-13 17:24 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2012-04-13 17:24 UTC (permalink / raw)
  To: bcrl; +Cc: jchapman, netdev

From: Benjamin LaHaise <bcrl@kvack.org>
Date: Tue, 10 Apr 2012 22:20:47 -0400

> At present, UDP encapsulated protocols (like L2TP) are only able to use the
> encap_rcv hook with UDP over IPv4.  This patch adds the same support for use
> with UDP over IPv6.
> 
> Signed-off-by: Benjamin LaHaise <bcrl@kvack.org>

This isn't right at all.

The return value of udpv6_queue_rcv_skb() ignorred at all
call sites except when it is invoked via ->backlog_rcv(), which
expects a different kind of return value, not an encap operation
indication.

So the whole "requeue as proto '-N'" logic isn't going to ever work.

You need to do what the ipv4 side does, split the routine into
two parts:

1) A __udpv6_queue_rcv_skb() which purely handles socket queueing
   cases.  It does not handle encap or anything like that.

   This is what is what you hook into ->backlog_rcv for ipv6 udp.

2) A udpv6_queue_rcv_skb() which is invoked by the UDPv6 socket demux
   on receive, and which will properly propagate the return values
   back down into ipv6 input to do the "requeue as proto '-N'" stuff.

Please resubmit both of these patches once you've fixed this up (and
tested it).

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

end of thread, other threads:[~2012-04-13 17:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-11  2:20 [PATCH net-next 1/2] net/ipv6/udp: Add encap_rcv support to IPv6 UDP Benjamin LaHaise
2012-04-11 11:51 ` James Chapman
2012-04-13 17:24 ` David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.