2 +++ b/include/net/xfrmudp.h
5 + * pointer to function for type that xfrm4_input wants, to permit
6 + * decoupling of XFRM from udp.c
8 +#define HAVE_XFRM4_UDP_REGISTER
10 +typedef int (*xfrm4_rcv_encap_t)(struct sk_buff *skb, __u16 encap_type);
11 +extern int udp4_register_esp_rcvencap(xfrm4_rcv_encap_t func
12 + , xfrm4_rcv_encap_t *oldfunc);
13 +extern int udp4_unregister_esp_rcvencap(xfrm4_rcv_encap_t func);
14 --- a/net/ipv4/Kconfig
15 +++ b/net/ipv4/Kconfig
16 @@ -266,6 +266,12 @@ config NET_IPGRE_BROADCAST
17 Network), but can be distributed all over the Internet. If you want
18 to do that, say Y here and to "IP multicast routing" below.
20 +config IPSEC_NAT_TRAVERSAL
21 + bool "IPSEC NAT-Traversal (KLIPS compatible)"
24 + Includes support for RFC3947/RFC3948 NAT-Traversal of ESP over UDP.
27 bool "IP: multicast routing"
28 depends on IP_MULTICAST
32 #include <net/route.h>
33 #include <net/checksum.h>
35 +#include <net/xfrmudp.h>
39 * Snmp MIB for the UDP layer
42 +static xfrm4_rcv_encap_t xfrm4_rcv_encap_func;
44 DEFINE_SNMP_STAT(struct udp_mib, udp_statistics) __read_mostly;
46 struct hlist_head udp_hash[UDP_HTABLE_SIZE];
47 @@ -915,6 +918,42 @@ int udp_disconnect(struct sock *sk, int
51 +#if defined(CONFIG_XFRM) || defined(CONFIG_IPSEC_NAT_TRAVERSAL)
53 +/* if XFRM isn't a module, then register it directly. */
54 +#if 0 && !defined(CONFIG_XFRM_MODULE) && !defined(CONFIG_IPSEC_NAT_TRAVERSAL)
55 +static xfrm4_rcv_encap_t xfrm4_rcv_encap_func = xfrm4_rcv_encap;
57 +static xfrm4_rcv_encap_t xfrm4_rcv_encap_func = NULL;
60 +int udp4_register_esp_rcvencap(xfrm4_rcv_encap_t func
61 + , xfrm4_rcv_encap_t *oldfunc)
63 + if(oldfunc != NULL) {
64 + *oldfunc = xfrm4_rcv_encap_func;
68 + if(xfrm4_rcv_encap_func != NULL)
72 + xfrm4_rcv_encap_func = func;
76 +int udp4_unregister_esp_rcvencap(xfrm4_rcv_encap_t func)
78 + if(xfrm4_rcv_encap_func != func)
81 + xfrm4_rcv_encap_func = NULL;
84 +#endif /* CONFIG_XFRM_MODULE || CONFIG_IPSEC_NAT_TRAVERSAL */
88 * 1 if the the UDP system should process it
89 * 0 if we should drop this packet
90 @@ -922,7 +961,7 @@ int udp_disconnect(struct sock *sk, int
92 static int udp_encap_rcv(struct sock * sk, struct sk_buff *skb)
95 +#if !defined(CONFIG_XFRM) && !defined(CONFIG_IPSEC_NAT_TRAVERSAL)
98 struct udp_sock *up = udp_sk(sk);
99 @@ -937,11 +976,11 @@ static int udp_encap_rcv(struct sock * s
100 /* if we're overly short, let UDP handle it */
101 len = skb->len - sizeof(struct udphdr);
106 /* if this is not encapsulated socket, then just return now */
111 /* If this is a paged skb, make sure we pull up
112 * whatever data we need to look at. */
113 @@ -964,7 +1003,7 @@ static int udp_encap_rcv(struct sock * s
114 len = sizeof(struct udphdr);
116 /* Must be an IKE packet.. pass it through */
120 case UDP_ENCAP_ESPINUDP_NON_IKE:
121 /* Check if this is a keepalive packet. If so, eat it. */
122 @@ -977,7 +1016,7 @@ static int udp_encap_rcv(struct sock * s
123 len = sizeof(struct udphdr) + 2 * sizeof(u32);
125 /* Must be an IKE packet.. pass it through */
131 @@ -988,6 +1027,8 @@ static int udp_encap_rcv(struct sock * s
133 if (skb_cloned(skb) && pskb_expand_head(skb, 0, 0, GFP_ATOMIC))
135 + if (skb_cloned(skb) && pskb_expand_head(skb, 0, 0, GFP_ATOMIC))
138 /* Now we can update and verify the packet length... */
140 @@ -1051,9 +1092,13 @@ int udp_queue_rcv_skb(struct sock * sk,
144 - /* process the ESP packet */
145 - ret = xfrm4_rcv_encap(skb, up->encap_type);
146 - UDP_INC_STATS_BH(UDP_MIB_INDATAGRAMS, up->pcflag);
147 + if(xfrm4_rcv_encap_func != NULL) {
148 + ret = (*xfrm4_rcv_encap_func)(skb, up->encap_type);
149 + UDP_INC_STATS_BH(UDP_MIB_INDATAGRAMS, up->pcflag);
151 + UDP_INC_STATS_BH(UDP_MIB_INERRORS, up->pcflag);
156 /* FALLTHROUGH -- it's a UDP Packet */
157 @@ -1733,3 +1778,9 @@ EXPORT_SYMBOL(udp_poll);
158 EXPORT_SYMBOL(udp_proc_register);
159 EXPORT_SYMBOL(udp_proc_unregister);
162 +#if defined(CONFIG_IPSEC_NAT_TRAVERSAL)
163 +EXPORT_SYMBOL(udp4_register_esp_rcvencap);
164 +EXPORT_SYMBOL(udp4_unregister_esp_rcvencap);