]> git.ipfire.org Git - thirdparty/strongswan.git/blob - linux/net/ipv4/udp.c.fs2_2.patch
- import of strongswan-2.7.0
[thirdparty/strongswan.git] / linux / net / ipv4 / udp.c.fs2_2.patch
1 --- ./net/ipv4/udp.c Sun Mar 25 18:37:41 2001
2 +++ ./net/ipv4/udp.c Mon Jun 10 19:53:18 2002
3 @@ -965,6 +965,9 @@
4
5 static int udp_queue_rcv_skb(struct sock * sk, struct sk_buff *skb)
6 {
7 +#ifdef CONFIG_IPSEC_NAT_TRAVERSAL
8 + struct udp_opt *tp = &(sk->tp_pinfo.af_udp);
9 +#endif
10 /*
11 * Charge it to the socket, dropping if the queue is full.
12 */
13 @@ -982,6 +985,38 @@
14 }
15 #endif
16
17 +#ifdef CONFIG_IPSEC_NAT_TRAVERSAL
18 + if (tp->esp_in_udp) {
19 + /*
20 + * Set skb->sk and xmit packet to ipsec_rcv.
21 + *
22 + * If ret != 0, ipsec_rcv refused the packet (not ESPinUDP),
23 + * restore skb->sk and fall back to sock_queue_rcv_skb
24 + */
25 + struct inet_protocol *esp = NULL;
26 +
27 +#ifdef CONFIG_IPSEC_MODULE
28 + for (esp = (struct inet_protocol *)inet_protos[IPPROTO_ESP & (MAX_INET_PROTOS - 1)];
29 + (esp) && (esp->protocol != IPPROTO_ESP);
30 + esp = esp->next);
31 +#else
32 + extern struct inet_protocol esp_protocol;
33 + esp = &esp_protocol;
34 +#endif
35 +
36 + if (esp && esp->handler) {
37 + struct sock *sav_sk = skb->sk;
38 + skb->sk = sk;
39 + if (esp->handler(skb, 0) == 0) {
40 + skb->sk = sav_sk;
41 + /* not sure we might count ESPinUDP as UDP... */
42 + udp_statistics.UdpInDatagrams++;
43 + return 0;
44 + }
45 + skb->sk = sav_sk;
46 + }
47 + }
48 +#endif
49 if (sock_queue_rcv_skb(sk,skb)<0) {
50 udp_statistics.UdpInErrors++;
51 ip_statistics.IpInDiscards++;
52 @@ -1165,6 +1200,44 @@
53 return(0);
54 }
55
56 +#if 1
57 +static int udp_setsockopt(struct sock *sk, int level, int optname,
58 + char *optval, int optlen)
59 +{
60 + struct udp_opt *tp = &(sk->tp_pinfo.af_udp);
61 + int val;
62 + int err = 0;
63 +
64 + if (level != SOL_UDP)
65 + return ip_setsockopt(sk, level, optname, optval, optlen);
66 +
67 + if(optlen<sizeof(int))
68 + return -EINVAL;
69 +
70 + if (get_user(val, (int *)optval))
71 + return -EFAULT;
72 +
73 + lock_sock(sk);
74 +
75 + switch(optname) {
76 +#ifdef CONFIG_IPSEC_NAT_TRAVERSAL
77 +#ifndef UDP_ESPINUDP
78 +#define UDP_ESPINUDP 100
79 +#endif
80 + case UDP_ESPINUDP:
81 + tp->esp_in_udp = val;
82 + break;
83 +#endif
84 + default:
85 + err = -ENOPROTOOPT;
86 + break;
87 + }
88 +
89 + release_sock(sk);
90 + return err;
91 +}
92 +#endif
93 +
94 struct proto udp_prot = {
95 (struct sock *)&udp_prot, /* sklist_next */
96 (struct sock *)&udp_prot, /* sklist_prev */
97 @@ -1179,7 +1252,11 @@
98 NULL, /* init */
99 NULL, /* destroy */
100 NULL, /* shutdown */
101 +#if 1
102 + udp_setsockopt, /* setsockopt */
103 +#else
104 ip_setsockopt, /* setsockopt */
105 +#endif
106 ip_getsockopt, /* getsockopt */
107 udp_sendmsg, /* sendmsg */
108 udp_recvmsg, /* recvmsg */