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 <[email protected]> --- include/linux/tcp.h | 5 +++++ net/ipv4/tcp_ipv4.c | 25 ++++++++++++++++++++++++- 2 files changed, 29 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..6d55863 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,29 @@ 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 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(tp->encap_rcv); + if (encap_rcv) + return encap_rcv(sk, skb); + } + nf_reset(skb); if (sk_filter(sk, skb)) @@ -1725,7 +1749,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 [email protected] http://openvswitch.org/mailman/listinfo/dev
