On Wed, Apr 04, 2012 at 09:10:52AM -0700, Ben Pfaff wrote:
> On Wed, Apr 04, 2012 at 02:15:00PM +0900, Simon Horman wrote:
> > This hook is based on a hook of the same name provided by UDP.  It provides
> > a way for to receive packets that have a TCP header but are not in fact
> > TCP.  It is intended to be used by an implementation of the STT tunneling
> > protocol within Open vSwtich's datapath. A prototype of such an
> > implementation has been made.
> > 
> > Signed-off-by: Simon Horman <ho...@verge.net.au>
> 
> The comments still talk about UDP.

Ooops, here is a fresh version

[RFC] [linux kernel patch] Add TCP encap_rcv hook

This hook is based on a hook of the same name provided by UDP.  It provides
a way for to receive packets that have a TCP header and treat them in some
alternate way.

It is intended to be used by an implementation of the STT tunneling
protocol within Open vSwtich's datapath. A prototype of such an
implementation has been made.

Signed-off-by: Simon Horman <ho...@verge.net.au>

---
v2
* Fix comment to refer to TCP rather than UDP
* Allow skb to continue traversing the stack if
  the encap_rcv callback returns a positive value.
  This is the same behaviour as the UDP hook.
---
 include/linux/tcp.h |    5 +++++
 net/ipv4/tcp_ipv4.c |   28 +++++++++++++++++++++++++++-
 2 files changed, 32 insertions(+), 1 deletions(-)

diff --git a/include/linux/tcp.h b/include/linux/tcp.h
index 3c7ffdb..36e794b 100644
--- a/include/linux/tcp.h
+++ b/include/linux/tcp.h
@@ -472,6 +472,11 @@ struct tcp_sock {
         * contains related tcp_cookie_transactions fields.
         */
        struct tcp_cookie_values  *cookie_values;
+
+       /* For encapsulation sockets. */
+       __u16            encap_type;
+       /* Hole */
+       int (*encap_rcv)(struct sock *sk, struct sk_buff *skb);
 };
 
 static inline struct tcp_sock *tcp_sk(const struct sock *sk)
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index fd54c5f..ce56c6c 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -1663,6 +1663,7 @@ int tcp_v4_rcv(struct sk_buff *skb)
        const struct iphdr *iph;
        const struct tcphdr *th;
        struct sock *sk;
+       struct tcp_sock *tp;
        int ret;
        struct net *net = dev_net(skb->dev);
 
@@ -1714,6 +1715,32 @@ process:
 
        if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb))
                goto discard_and_relse;
+
+       tp = tcp_sk(sk);
+
+       if (tp->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 TCP 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 TCP.
+                * <0 if skb should be resubmitted as proto -N
+                */
+
+               /* if we're overly short, let UDP handle it */
+               encap_rcv = ACCESS_ONCE(tp->encap_rcv);
+               if (encap_rcv) {
+                       int ret = encap_rcv(sk, skb);
+                       if (ret <= 0)
+                               return -ret;
+               }
+       }
+
        nf_reset(skb);
 
        if (sk_filter(sk, skb))
@@ -1725,7 +1752,6 @@ process:
        ret = 0;
        if (!sock_owned_by_user(sk)) {
 #ifdef CONFIG_NET_DMA
-               struct tcp_sock *tp = tcp_sk(sk);
                if (!tp->ucopy.dma_chan && tp->ucopy.pinned_list)
                        tp->ucopy.dma_chan = dma_find_channel(DMA_MEMCPY);
                if (tp->ucopy.dma_chan)
-- 
1.7.9.1

_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev

Reply via email to