1 diff -Naur openswan-2.6.20.org/linux/include/openswan/ipsec_kversion.h openswan-2.6.20/linux/include/openswan/ipsec_kversion.h
2 --- openswan-2.6.20.org/linux/include/openswan/ipsec_kversion.h 2009-02-10 05:54:47.000000000 +0100
3 +++ openswan-2.6.20/linux/include/openswan/ipsec_kversion.h 2009-03-14 22:36:22.000000000 +0100
5 # define HAVE_KMEM_CACHE_MACRO
7 /* Try using the new kernel encaps hook for nat-t, instead of udp.c */
8 -# ifdef NOT_YET_FINISHED
9 -# define HAVE_UDP_ENCAP_CONVERT
11 +#if !defined(CONFIG_IPSEC_NAT_TRAVERSAL) || CONFIG_IPSEC_NAT_TRAVERSAL == 0
12 +# define HAVE_UDP_ENCAP_CONVERT
14 +# warning "It seems you are using a post 2.6.22 kernel with the NAT-T-patch - please consider using the new ENCAP nat-traversal code"
19 diff -Naur openswan-2.6.20.org/linux/include/openswan/ipsec_param.h openswan-2.6.20/linux/include/openswan/ipsec_param.h
20 --- openswan-2.6.20.org/linux/include/openswan/ipsec_param.h 2009-02-10 05:54:47.000000000 +0100
21 +++ openswan-2.6.20/linux/include/openswan/ipsec_param.h 2009-03-14 22:36:22.000000000 +0100
23 #endif /* __KERNEL__ */
26 + * These constants are used to indicate what type of NAT-T code is used
28 +#define NAT_OLD_STYLE 1
29 +#define NAT_NEW_STYLE 2
32 * This is for the SA reference table. This number is related to the
33 * maximum number of SAs that KLIPS can concurrently deal with, plus enough
34 * space for keeping expired SAs around.
39 +#ifdef HAVE_UDP_ENCAP_CONVERT
40 +# define NAT_TRAVERSAL 1
43 #ifndef IPSEC_DEFAULT_TTL
44 #define IPSEC_DEFAULT_TTL 64
46 diff -Naur openswan-2.6.20.org/linux/include/openswan/ipsec_rcv.h openswan-2.6.20/linux/include/openswan/ipsec_rcv.h
47 --- openswan-2.6.20.org/linux/include/openswan/ipsec_rcv.h 2009-02-10 05:54:47.000000000 +0100
48 +++ openswan-2.6.20/linux/include/openswan/ipsec_rcv.h 2009-03-14 22:36:22.000000000 +0100
50 struct ipcomphdr *compp;
53 -#ifdef CONFIG_IPSEC_NAT_TRAVERSAL
54 +#if defined(CONFIG_IPSEC_NAT_TRAVERSAL) || defined(HAVE_UDP_ENCAP_CONVERT)
58 diff -Naur openswan-2.6.20.org/linux/include/openswan/ipsec_tunnel.h openswan-2.6.20/linux/include/openswan/ipsec_tunnel.h
59 --- openswan-2.6.20.org/linux/include/openswan/ipsec_tunnel.h 2009-02-10 05:54:47.000000000 +0100
60 +++ openswan-2.6.20/linux/include/openswan/ipsec_tunnel.h 2009-03-14 22:36:22.000000000 +0100
62 #define cf_name cf_u.cfu_name
65 +struct nattraversalconf
71 #define IPSEC_SET_DEV (SIOCDEVPRIVATE)
72 #define IPSEC_DEL_DEV (SIOCDEVPRIVATE + 1)
73 #define IPSEC_CLR_DEV (SIOCDEVPRIVATE + 2)
74 diff -Naur openswan-2.6.20.org/linux/include/openswan/ipsec_xmit.h openswan-2.6.20/linux/include/openswan/ipsec_xmit.h
75 --- openswan-2.6.20.org/linux/include/openswan/ipsec_xmit.h 2009-02-10 05:54:47.000000000 +0100
76 +++ openswan-2.6.20/linux/include/openswan/ipsec_xmit.h 2009-03-14 22:36:22.000000000 +0100
81 -#ifdef CONFIG_IPSEC_NAT_TRAVERSAL
82 +#if defined(CONFIG_IPSEC_NAT_TRAVERSAL) || defined(HAVE_UDP_ENCAP_CONVERT)
86 diff -Naur openswan-2.6.20.org/linux/net/ipsec/ipsec_mast.c openswan-2.6.20/linux/net/ipsec/ipsec_mast.c
87 --- openswan-2.6.20.org/linux/net/ipsec/ipsec_mast.c 2009-02-10 05:54:47.000000000 +0100
88 +++ openswan-2.6.20/linux/net/ipsec/ipsec_mast.c 2009-03-14 22:36:22.000000000 +0100
93 -#ifdef CONFIG_IPSEC_NAT_TRAVERSAL
94 +#if defined(CONFIG_IPSEC_NAT_TRAVERSAL) || defined(HAVE_UDP_ENCAP_CONVERT)
95 /* do any final NAT-encapsulation */
96 stat = ipsec_nat_encap(ixs);
97 if(stat != IPSEC_XMIT_OK) {
98 diff -Naur openswan-2.6.20.org/linux/net/ipsec/ipsec_proc.c openswan-2.6.20/linux/net/ipsec/ipsec_proc.c
99 --- openswan-2.6.20.org/linux/net/ipsec/ipsec_proc.c 2009-02-10 05:54:47.000000000 +0100
100 +++ openswan-2.6.20/linux/net/ipsec/ipsec_proc.c 2009-03-14 22:36:22.000000000 +0100
103 #endif /* CONFIG_KLIPS_IPCOMP */
105 -#ifdef CONFIG_IPSEC_NAT_TRAVERSAL
106 +#if defined(CONFIG_IPSEC_NAT_TRAVERSAL) || defined(HAVE_UDP_ENCAP_CONVERT)
110 @@ -635,11 +635,15 @@
114 -#ifdef CONFIG_IPSEC_NAT_TRAVERSAL
115 -unsigned int natt_available = 1;
116 +#if defined(CONFIG_IPSEC_NAT_TRAVERSAL)
117 +unsigned int natt_available = NAT_OLD_STYLE;
119 +#if defined(HAVE_UDP_ENCAP_CONVERT)
120 +unsigned int natt_available = NAT_NEW_STYLE;
122 unsigned int natt_available = 0;
125 module_param(natt_available,int,0644);
127 IPSEC_PROCFS_DEBUG_NO_STATIC
128 @@ -654,11 +658,15 @@
130 len += ipsec_snprintf(buffer + len,
132 -#ifdef CONFIG_IPSEC_NAT_TRAVERSAL
134 +#if defined(CONFIG_IPSEC_NAT_TRAVERSAL)
137 +#if defined(HAVE_UDP_ENCAP_CONVERT)
145 *start = buffer + (offset - begin); /* Start of wanted data */
146 diff -Naur openswan-2.6.20.org/linux/net/ipsec/ipsec_rcv.c openswan-2.6.20/linux/net/ipsec/ipsec_rcv.c
147 --- openswan-2.6.20.org/linux/net/ipsec/ipsec_rcv.c 2009-02-10 05:54:47.000000000 +0100
148 +++ openswan-2.6.20/linux/net/ipsec/ipsec_rcv.c 2009-03-14 22:41:35.000000000 +0100
149 @@ -1054,7 +1054,7 @@
150 irs->sa_len ? irs->sa : " (error)");
153 -#ifdef CONFIG_IPSEC_NAT_TRAVERSAL
154 +#if defined(CONFIG_IPSEC_NAT_TRAVERSAL) || defined(HAVE_UDP_ENCAP_CONVERT)
155 if (irs->proto == IPPROTO_ESP) {
156 KLIPS_PRINT(debug_rcv,
157 "klips_debug:ipsec_rcv: "
158 @@ -1172,7 +1172,7 @@
159 * if skb->sk is guaranteed to be valid here.
160 * 2005-04-16: mcr@xelerance.com
162 -#ifdef CONFIG_IPSEC_NAT_TRAVERSAL
163 +#if defined(CONFIG_IPSEC_NAT_TRAVERSAL) || defined(HAVE_UDP_ENCAP_CONVERT)
166 * XXX we should ONLY update pluto if the SA passes all checks,
167 @@ -1638,7 +1638,7 @@
169 #endif /* CONFIG_KLIPS_IPCOMP */
171 -#ifdef CONFIG_IPSEC_NAT_TRAVERSAL
172 +#if defined(CONFIG_IPSEC_NAT_TRAVERSAL) || defined(HAVE_UDP_ENCAP_CONVERT)
173 if ((irs->natt_type) && (ipp->protocol != IPPROTO_IPIP)) {
175 * NAT-Traversal and Transport Mode:
176 @@ -1943,7 +1943,116 @@
178 int klips26_udp_encap_rcv(struct sock *sk, struct sk_buff *skb)
180 - return klips26_rcv_encap(skb, udp_sk(sk)->encap_type);
181 + struct udp_sock *up = udp_sk(sk);
189 + __u16 encap_type = up->encap_type;
191 + /* if this is not encapsulated socket, then just return now */
195 + /* If this is a paged skb, make sure we pull up
196 + * whatever data we need to look at. */
197 + len = skb->len - sizeof(struct udphdr);
198 + if (!pskb_may_pull(skb, sizeof(struct udphdr) + min(len, 8)))
201 + /* Now we can get the pointers */
203 + udpdata = (__u8 *)uh + sizeof(struct udphdr);
204 + udpdata32 = (__be32 *)udpdata;
206 + switch (encap_type) {
208 + case UDP_ENCAP_ESPINUDP:
209 + /* Check if this is a keepalive packet. If so, eat it. */
210 + if (len == 1 && udpdata[0] == 0xff) {
211 + KLIPS_PRINT(debug_rcv,
212 + "UDP_ENCAP_ESPINUDP: keepalive packet detected\n");
214 + } else if (len > sizeof(struct ip_esp_hdr) && udpdata32[0] != 0) {
215 + KLIPS_PRINT(debug_rcv,
216 + "UDP_ENCAP_ESPINUDP: ESP IN UDP packet detected\n");
217 + /* ESP Packet without Non-ESP header */
218 + len = sizeof(struct udphdr);
220 + /* Must be an IKE packet.. pass it through */
221 + KLIPS_PRINT(debug_rcv,
222 + "UDP_ENCAP_ESPINUDP: IKE packet detected\n");
226 + case UDP_ENCAP_ESPINUDP_NON_IKE:
227 + KLIPS_PRINT(debug_rcv,
228 + "UDP_ENCAP_ESPINUDP_NON_IKE: %d\n",
230 + /* Check if this is a keepalive packet. If so, eat it. */
231 + if (len == 1 && udpdata[0] == 0xff) {
232 + KLIPS_PRINT(debug_rcv,
233 + "UDP_ENCAP_ESPINUDP_NON_IKE: keepalive packet detected\n");
235 + } else if (len > 2 * sizeof(u32) + sizeof(struct ip_esp_hdr) &&
236 + udpdata32[0] == 0 && udpdata32[1] == 0) {
237 + KLIPS_PRINT(debug_rcv,
238 + "UDP_ENCAP_ESPINUDP_NON_IKE: ESP IN UDP NON IKE packet detected\n");
239 + /* ESP Packet with Non-IKE marker */
240 + len = sizeof(struct udphdr) + 2 * sizeof(u32);
242 + /* Must be an IKE packet.. pass it through */
243 + KLIPS_PRINT(debug_rcv,
244 + "UDP_ENCAP_ESPINUDP_NON_IKE: IKE packet detected\n");
250 + /* At this point we are sure that this is an ESPinUDP packet,
251 + * so we need to remove 'len' bytes from the packet (the UDP
252 + * header and optional ESP marker bytes) and then modify the
253 + * protocol to ESP, and then call into the transform receiver.
255 + if (skb_cloned(skb) && pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) {
256 + KLIPS_PRINT(debug_rcv,
257 + "clone or expand problem\n");
261 + /* Now we can update and verify the packet length... */
263 + iphlen = iph->ihl << 2;
264 + iph->tot_len = htons(ntohs(iph->tot_len) - len);
265 + if (skb->len < iphlen + len) {
266 + /* packet is too small!?! */
267 + KLIPS_PRINT(debug_rcv,
268 + "packet too small\n");
272 + /* pull the data buffer up to the ESP header and set the
273 + * transport header to point to ESP. Keep UDP on the stack
276 + __skb_pull(skb, len);
277 + skb_reset_transport_header(skb);
279 + /* modify the protocol (it's ESP!) */
280 + iph->protocol = IPPROTO_ESP;
283 + KLIPS_PRINT(debug_rcv,
284 + "starting processing ESP packet\n");
285 + ret = klips26_rcv_encap(skb, encap_type);
293 int klips26_rcv_encap(struct sk_buff *skb, __u16 encap_type)
294 @@ -2011,7 +2120,7 @@
296 irs->hard_header_len = skb->dev->hard_header_len;
298 -#ifdef CONFIG_IPSEC_NAT_TRAVERSAL
299 +#if defined(CONFIG_IPSEC_NAT_TRAVERSAL) || defined(HAVE_UDP_ENCAP_CONVERT)
301 case UDP_ENCAP_ESPINUDP:
302 irs->natt_type = ESPINUDP_WITH_NON_ESP;
303 @@ -2143,7 +2252,7 @@
306 irs->hard_header_len = 0;
307 -#ifdef CONFIG_IPSEC_NAT_TRAVERSAL
308 +#if defined(CONFIG_IPSEC_NAT_TRAVERSAL) || defined(HAVE_UDP_ENCAP_CONVERT)
312 diff -Naur openswan-2.6.20.org/linux/net/ipsec/ipsec_sa.c openswan-2.6.20/linux/net/ipsec/ipsec_sa.c
313 --- openswan-2.6.20.org/linux/net/ipsec/ipsec_sa.c 2009-02-10 05:54:47.000000000 +0100
314 +++ openswan-2.6.20/linux/net/ipsec/ipsec_sa.c 2009-03-14 22:36:22.000000000 +0100
315 @@ -1011,7 +1011,7 @@
317 ips->ips_addr_p = NULL;
319 -#ifdef CONFIG_IPSEC_NAT_TRAVERSAL
320 +#if defined(CONFIG_IPSEC_NAT_TRAVERSAL) || defined(HAVE_UDP_ENCAP_CONVERT)
321 if(ips->ips_natt_oa) {
322 memset((caddr_t)(ips->ips_natt_oa), 0, ips->ips_natt_oa_size);
323 kfree(ips->ips_natt_oa);
324 diff -Naur openswan-2.6.20.org/linux/net/ipsec/ipsec_tunnel.c openswan-2.6.20/linux/net/ipsec/ipsec_tunnel.c
325 --- openswan-2.6.20.org/linux/net/ipsec/ipsec_tunnel.c 2009-02-10 05:54:47.000000000 +0100
326 +++ openswan-2.6.20/linux/net/ipsec/ipsec_tunnel.c 2009-03-14 22:36:22.000000000 +0100
328 #include <linux/udp.h>
331 +#ifdef HAVE_UDP_ENCAP_CONVERT
332 +#include <linux/file.h>
333 +#include "openswan/ipsec_rcv.h"
336 static __u32 zeroes[64];
343 -#ifdef CONFIG_IPSEC_NAT_TRAVERSAL
344 +#if defined(CONFIG_IPSEC_NAT_TRAVERSAL) || defined(HAVE_UDP_ENCAP_CONVERT)
345 stat = ipsec_nat_encap(ixs);
346 if(stat != IPSEC_XMIT_OK) {
348 @@ -1403,19 +1408,27 @@
350 #ifdef HAVE_UDP_ENCAP_CONVERT
351 case IPSEC_UDP_ENCAP_CONVERT:
353 - unsigned int *socknum =(unsigned int *)&ifr->ifr_data;
355 + struct nattraversalconf *nf = (struct nattraversalconf *)&ifr->ifr_data;
356 + unsigned int socknum = nf->cf_fd;
357 + unsigned int encaptype = nf->cf_type;
360 int err, fput_needed;
362 /* that's a static function in socket.c
363 * sock = sockfd_lookup_light(*socknum, &err, &fput_needed); */
364 - sock = sockfd_lookup(*socknum, &err);
365 + sock = sockfd_lookup(socknum, &err);
366 + KLIPS_PRINT(debug_tunnel
367 + , "socknum: %u, err: %d\n"
374 /* check that it's a UDP socket */
375 - udp_sk(sk)->encap_type = UDP_ENCAP_ESPINUDP_NON_IKE;
376 + udp_sk(sk)->encap_type = encaptype;
377 udp_sk(sk)->encap_rcv = klips26_udp_encap_rcv;
379 KLIPS_PRINT(debug_tunnel
380 @@ -1976,7 +1989,7 @@
381 ixs->ips.ips_ident_s.data = NULL;
382 ixs->ips.ips_ident_d.data = NULL;
383 ixs->outgoing_said.proto = 0;
384 -#ifdef CONFIG_IPSEC_NAT_TRAVERSAL
385 +#if defined(CONFIG_IPSEC_NAT_TRAVERSAL) || defined(HAVE_UDP_ENCAP_CONVERT)
386 ixs->natt_type = 0, ixs->natt_head = 0;
387 ixs->natt_sport = 0, ixs->natt_dport = 0;
389 diff -Naur openswan-2.6.20.org/linux/net/ipsec/ipsec_xmit.c openswan-2.6.20/linux/net/ipsec/ipsec_xmit.c
390 --- openswan-2.6.20.org/linux/net/ipsec/ipsec_xmit.c 2009-02-10 05:54:47.000000000 +0100
391 +++ openswan-2.6.20/linux/net/ipsec/ipsec_xmit.c 2009-03-14 22:36:22.000000000 +0100
392 @@ -1597,7 +1597,7 @@
393 ixs->tailroom += ixs->blocksize != 1 ?
394 ((ixs->blocksize - ((ixs->pyldsz + 2) % ixs->blocksize)) % ixs->blocksize) + 2 :
395 ((4 - ((ixs->pyldsz + 2) % 4)) % 4) + 2;
396 -#ifdef CONFIG_IPSEC_NAT_TRAVERSAL
397 +#if defined(CONFIG_IPSEC_NAT_TRAVERSAL) || defined(HAVE_UDP_ENCAP_CONVERT)
398 if ((ixs->ipsp->ips_natt_type) && (!ixs->natt_type)) {
399 ixs->natt_type = ixs->ipsp->ips_natt_type;
400 ixs->natt_sport = ixs->ipsp->ips_natt_sport;
401 @@ -1762,7 +1762,7 @@
403 #endif /* MSS_HACK */
405 -#ifdef CONFIG_IPSEC_NAT_TRAVERSAL
406 +#if defined(CONFIG_IPSEC_NAT_TRAVERSAL) || defined(HAVE_UDP_ENCAP_CONVERT)
407 if ((ixs->natt_type) && (ixs->outgoing_said.proto != IPPROTO_IPIP)) {
409 * NAT-Traversal and Transport Mode:
410 @@ -1929,7 +1929,7 @@
412 #endif /* NETDEV_23 */
414 -#ifdef CONFIG_IPSEC_NAT_TRAVERSAL
415 +#if defined(CONFIG_IPSEC_NAT_TRAVERSAL) || defined(HAVE_UDP_ENCAP_CONVERT)
416 enum ipsec_xmit_value ipsec_nat_encap(struct ipsec_xmit_state *ixs)
418 if (ixs->natt_type && ixs->natt_head) {
419 diff -Naur openswan-2.6.20.org/linux/net/ipsec/pfkey_v2_ext_process.c openswan-2.6.20/linux/net/ipsec/pfkey_v2_ext_process.c
420 --- openswan-2.6.20.org/linux/net/ipsec/pfkey_v2_ext_process.c 2009-02-10 05:54:47.000000000 +0100
421 +++ openswan-2.6.20/linux/net/ipsec/pfkey_v2_ext_process.c 2009-03-14 22:36:22.000000000 +0100
426 -#ifdef CONFIG_IPSEC_NAT_TRAVERSAL
427 +#if defined(CONFIG_IPSEC_NAT_TRAVERSAL) || defined(HAVE_UDP_ENCAP_CONVERT)
429 pfkey_x_nat_t_type_process(struct sadb_ext *pfkey_ext, struct pfkey_extracted_data* extr)
431 diff -Naur openswan-2.6.20.org/linux/net/ipsec/pfkey_v2_parser.c openswan-2.6.20/linux/net/ipsec/pfkey_v2_parser.c
432 --- openswan-2.6.20.org/linux/net/ipsec/pfkey_v2_parser.c 2009-02-10 05:54:47.000000000 +0100
433 +++ openswan-2.6.20/linux/net/ipsec/pfkey_v2_parser.c 2009-03-14 22:36:22.000000000 +0100
435 struct sadb_msg *pfkey_reply = NULL;
436 struct socket_list *pfkey_socketsp;
437 uint8_t satype = ((struct sadb_msg*)extensions[K_SADB_EXT_RESERVED])->sadb_msg_satype;
438 -#ifdef CONFIG_IPSEC_NAT_TRAVERSAL
439 +#if defined(CONFIG_IPSEC_NAT_TRAVERSAL) || defined(HAVE_UDP_ENCAP_CONVERT)
440 struct ipsec_sa *nat_t_ips_saved = NULL;
442 KLIPS_PRINT(debug_pfkey,
444 sa_len ? sa : " (error)",
445 extr->ips->ips_flags & EMT_INBOUND ? "in" : "out");
447 -#ifdef CONFIG_IPSEC_NAT_TRAVERSAL
448 +#if defined(CONFIG_IPSEC_NAT_TRAVERSAL) || defined(HAVE_UDP_ENCAP_CONVERT)
449 if (extr->ips->ips_natt_sport || extr->ips->ips_natt_dport) {
450 KLIPS_PRINT(debug_pfkey,
451 "klips_debug:pfkey_update_parse: only updating NAT-T ports "
453 pfkey_socketsp->socketp);
456 -#ifdef CONFIG_IPSEC_NAT_TRAVERSAL
457 +#if defined(CONFIG_IPSEC_NAT_TRAVERSAL) || defined(HAVE_UDP_ENCAP_CONVERT)
458 if (nat_t_ips_saved) {
460 * As we _really_ update existing SA, we keep tdbq and need to delete
461 @@ -2547,7 +2547,7 @@
465 -#ifdef CONFIG_IPSEC_NAT_TRAVERSAL
466 +#if defined(CONFIG_IPSEC_NAT_TRAVERSAL) || defined(HAVE_UDP_ENCAP_CONVERT)
468 pfkey_nat_t_new_mapping(struct ipsec_sa *ipsp, struct sockaddr *ipaddr,
470 @@ -2707,7 +2707,7 @@
471 pfkey_address_process,
472 pfkey_x_debug_process,
473 pfkey_x_protocol_process,
474 -#ifdef CONFIG_IPSEC_NAT_TRAVERSAL
475 +#if defined(CONFIG_IPSEC_NAT_TRAVERSAL) || defined(HAVE_UDP_ENCAP_CONVERT)
476 pfkey_x_nat_t_type_process,
477 pfkey_x_nat_t_port_process,
478 pfkey_x_nat_t_port_process,
479 @@ -2812,7 +2812,7 @@
480 pfkey_x_addflow_parse,
481 pfkey_x_delflow_parse,
482 pfkey_x_msg_debug_parse,
483 -#ifdef CONFIG_IPSEC_NAT_TRAVERSAL
484 +#if defined(CONFIG_IPSEC_NAT_TRAVERSAL) || defined(HAVE_UDP_ENCAP_CONVERT)
485 pfkey_x_nat_t_new_mapping_parse,
488 diff -Naur openswan-2.6.20.org/programs/pluto/nat_traversal.c openswan-2.6.20/programs/pluto/nat_traversal.c
489 --- openswan-2.6.20.org/programs/pluto/nat_traversal.c 2009-02-10 05:54:47.000000000 +0100
490 +++ openswan-2.6.20/programs/pluto/nat_traversal.c 2009-03-14 22:36:22.000000000 +0100
494 #include <signal.h> /* used only if MSG_NOSIGNAL not defined */
495 +#include <sys/ioctl.h>
498 #include <openswan.h>
499 #include <openswan/ipsec_policy.h>
500 #include <openswan/pfkeyv2.h>
501 #include <openswan/pfkey.h>
502 +#include <openswan/ipsec_param.h>
503 +#include <openswan/ipsec_tunnel.h>
506 #include "constants.h"
509 #define DEFAULT_KEEP_ALIVE_PERIOD 20
511 +static unsigned int nat_traversal_type = 0;
513 bool nat_traversal_enabled = FALSE;
514 bool nat_traversal_support_non_ike = FALSE;
515 bool nat_traversal_support_port_floating = FALSE;
517 nat_traversal_support_port_floating=FALSE;
518 openswan_log(" KLIPS does not have NAT-Traversal built in (see /proc/net/ipsec/natt)\n");
521 + nat_traversal_type = atoi(&n);
522 + openswan_log(" KLIPS using NAT-Traversal Method %c\n", n);
528 int nat_traversal_espinudp_socket (int sk, const char *fam, u_int32_t type)
531 - r = setsockopt(sk, SOL_UDP, UDP_ESPINUDP, &type, sizeof(type));
532 + if (nat_traversal_type == NAT_OLD_STYLE) {
533 + loglog(RC_LOG_SERIOUS,
534 + "NAT-Traversal: Trying old style NAT-T");
535 + r = setsockopt(sk, SOL_UDP, UDP_ESPINUDP, &type, sizeof(type));
537 + if (nat_traversal_type == NAT_NEW_STYLE) {
538 + loglog(RC_LOG_SERIOUS,
539 + "NAT-Traversal: Trying new style NAT-T");
541 + struct nattraversalconf *ntc=(struct nattraversalconf *)&ifr.ifr_data;
542 + memset(&ifr, 0, sizeof(ifr));
543 + strcpy(ifr.ifr_name, "ipsec0");
545 + ntc->cf_type = type;
546 + r = ioctl(sk, IPSEC_UDP_ENCAP_CONVERT, &ifr);
548 if ((r<0) && (errno == ENOPROTOOPT)) {
549 loglog(RC_LOG_SERIOUS,
550 "NAT-Traversal: ESPINUDP(%d) not supported by kernel for family %s"