]> pilppa.org Git - familiar-h63xx-build.git/blob - org.handhelds.familiar/packages/linux/linux-mtx-1-2.4.27/12-openswan-2.2.0-nat-t.diff
OE tree imported from monotone branch org.openembedded.oz354fam083 at revision 8b12e3...
[familiar-h63xx-build.git] / org.handhelds.familiar / packages / linux / linux-mtx-1-2.4.27 / 12-openswan-2.2.0-nat-t.diff
1 diff -Nurb linux-08/include/net/sock.h linux/include/net/sock.h
2 --- linux-08/include/net/sock.h 2004-11-19 11:37:23.376715120 +0100
3 +++ linux/include/net/sock.h    2004-11-19 11:39:29.874484536 +0100
4 @@ -256,6 +256,13 @@
5         __u32   end_seq;
6  };
7  
8 +#if 1
9 +#define UDP_OPT_IN_SOCK 1
10 +struct udp_opt {
11 +       __u32 esp_in_udp;
12 +};
13 +#endif
14 +
15  struct tcp_opt {
16         int     tcp_header_len; /* Bytes of tcp header to send          */
17  
18 @@ -648,6 +655,9 @@
19  #if defined(CONFIG_SPX) || defined (CONFIG_SPX_MODULE)
20                 struct spx_opt          af_spx;
21  #endif /* CONFIG_SPX */
22 +#if 1
23 +               struct udp_opt          af_udp;
24 +#endif
25  
26         } tp_pinfo;
27  
28 diff -Nurb linux-08/net/Config.in linux/net/Config.in
29 --- linux-08/net/Config.in      2004-11-19 11:37:23.770655232 +0100
30 +++ linux/net/Config.in 2004-11-19 11:39:29.874484536 +0100
31 @@ -102,4 +102,6 @@
32  dep_tristate 'Packet Generator (USE WITH CAUTION)' CONFIG_NET_PKTGEN $CONFIG_PROC_FS
33  endmenu
34  
35 +bool 'IPSEC NAT-Traversal' CONFIG_IPSEC_NAT_TRAVERSAL
36 +
37  endmenu
38 diff -Nurb linux-08/net/ipv4/udp.c linux/net/ipv4/udp.c
39 --- linux-08/net/ipv4/udp.c     2004-11-19 11:37:23.897635928 +0100
40 +++ linux/net/ipv4/udp.c        2004-11-19 11:39:29.875484384 +0100
41 @@ -810,6 +810,9 @@
42  
43  static int udp_queue_rcv_skb(struct sock * sk, struct sk_buff *skb)
44  {
45 +#ifdef CONFIG_IPSEC_NAT_TRAVERSAL
46 +       struct udp_opt *tp =  &(sk->tp_pinfo.af_udp);
47 +#endif
48         /*
49          *      Charge it to the socket, dropping if the queue is full.
50          */
51 @@ -827,6 +830,40 @@
52         }
53  #endif
54  
55 +#ifdef CONFIG_IPSEC_NAT_TRAVERSAL
56 +       if (tp->esp_in_udp) {
57 +               /*
58 +                * Set skb->sk and xmit packet to ipsec_rcv.
59 +                *
60 +                * If ret != 0, ipsec_rcv refused the packet (not ESPinUDP),
61 +                * restore skb->sk and fall back to sock_queue_rcv_skb
62 +                */
63 +               struct inet_protocol *esp = NULL;
64 +
65 +#if defined(CONFIG_IPSEC) && !defined(CONFIG_IPSEC_MODULE)
66 +               /* optomize only when we know it is statically linked */
67 +               extern struct inet_protocol esp_protocol;
68 +               esp = &esp_protocol;
69 +#else
70 +               for (esp = (struct inet_protocol *)inet_protos[IPPROTO_ESP & (MAX_INET_PROTOS - 1)];
71 +                       (esp) && (esp->protocol != IPPROTO_ESP);
72 +                       esp = esp->next);
73 +#endif
74 +
75 +               if (esp && esp->handler) {
76 +                       struct sock *sav_sk = skb->sk;
77 +                       skb->sk = sk;
78 +                       if (esp->handler(skb) == 0) {
79 +                               skb->sk = sav_sk;
80 +                               /*not sure we might count ESPinUDP as UDP...*/
81 +                               UDP_INC_STATS_BH(UdpInDatagrams);
82 +                               return 0;
83 +                       }
84 +                       skb->sk = sav_sk;
85 +               }
86 +       }
87 +#endif
88 +
89         if (sock_queue_rcv_skb(sk,skb)<0) {
90                 UDP_INC_STATS_BH(UdpInErrors);
91                 IP_INC_STATS_BH(IpInDiscards);
92 @@ -1050,13 +1087,49 @@
93         return len;
94  }
95  
96 +static int udp_setsockopt(struct sock *sk, int level, int optname,
97 +       char *optval, int optlen)
98 +{
99 +       struct udp_opt *tp = &(sk->tp_pinfo.af_udp);
100 +       int val;
101 +       int err = 0;
102 +
103 +       if (level != SOL_UDP)
104 +               return ip_setsockopt(sk, level, optname, optval, optlen);
105 +
106 +       if(optlen<sizeof(int))
107 +               return -EINVAL;
108 +
109 +       if (get_user(val, (int *)optval))
110 +               return -EFAULT;
111 +       
112 +       lock_sock(sk);
113 +
114 +       switch(optname) {
115 +#ifdef CONFIG_IPSEC_NAT_TRAVERSAL
116 +#ifndef UDP_ESPINUDP
117 +#define UDP_ESPINUDP 100
118 +#endif
119 +               case UDP_ESPINUDP:
120 +                       tp->esp_in_udp = val;
121 +                       break;
122 +#endif
123 +               default:
124 +                       err = -ENOPROTOOPT;
125 +                       break;
126 +       }
127 +
128 +       release_sock(sk);
129 +       return err;
130 +}
131 +
132  struct proto udp_prot = {
133         name:           "UDP",
134         close:          udp_close,
135         connect:        udp_connect,
136         disconnect:     udp_disconnect,
137         ioctl:          udp_ioctl,
138 -       setsockopt:     ip_setsockopt,
139 +       setsockopt:     udp_setsockopt,
140         getsockopt:     ip_getsockopt,
141         sendmsg:        udp_sendmsg,
142         recvmsg:        udp_recvmsg,
143