~ubuntu-branches/ubuntu/hardy/openswan/hardy-updates

« back to all changes in this revision

Viewing changes to linux/net/ipsec/ipsec_tunnel.c

  • Committer: Bazaar Package Importer
  • Author(s): Rene Mayrhofer
  • Date: 2005-01-27 16:10:11 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050127161011-idgybmyz3vwhpfiq
Tags: 2.3.0-2
Urgency HIGH due to security issue and problems with build-deps in sarge.
* Fix the security issue. Please see
  http://www.idefense.com/application/poi/display?id=190&
      type=vulnerabilities&flashstatus=false
  for more details. Thanks to Martin Schulze for informing me about
  this issue.
  Closes: #292458: Openswan XAUTH/PAM Buffer Overflow Vulnerability
* Added a Build-Dependency to lynx.
  Closes: #291143: openswan: FTBFS: Missing build dependency.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
 * for more details.
15
15
 */
16
16
 
17
 
char ipsec_tunnel_c_version[] = "RCSID $Id: ipsec_tunnel.c,v 1.219 2004/02/03 03:13:17 mcr Exp $";
 
17
char ipsec_tunnel_c_version[] = "RCSID $Id: ipsec_tunnel.c,v 1.227 2004/12/10 21:16:08 ken Exp $";
18
18
 
19
19
#define __NO_VERSION__
20
20
#include <linux/module.h>
22
22
#include <linux/version.h>
23
23
#include <linux/kernel.h> /* printk() */
24
24
 
25
 
#include "freeswan/ipsec_param.h"
 
25
#include "openswan/ipsec_param.h"
26
26
 
27
27
#ifdef MALLOC_SLAB
28
28
# include <linux/slab.h> /* kmalloc() */
33
33
#include <linux/types.h>  /* size_t */
34
34
#include <linux/interrupt.h> /* mark_bh */
35
35
 
 
36
#include <net/tcp.h>
 
37
#include <net/udp.h>
 
38
#include <linux/skbuff.h>
 
39
 
36
40
#include <linux/netdevice.h>   /* struct device, struct net_device_stats, dev_queue_xmit() and other headers */
37
41
#include <linux/etherdevice.h> /* eth_type_trans */
38
42
#include <linux/ip.h>          /* struct iphdr */
39
 
#include <linux/tcp.h>         /* struct tcphdr */
40
 
#include <linux/udp.h>         /* struct udphdr */
41
43
#include <linux/skbuff.h>
42
 
#include <freeswan.h>
 
44
 
 
45
#include <openswan.h>
 
46
 
43
47
#ifdef NET_21
44
48
# include <asm/uaccess.h>
45
49
# include <linux/in6.h>
59
63
 
60
64
#include <linux/if_arp.h>
61
65
 
62
 
#include "freeswan/radij.h"
63
 
#include "freeswan/ipsec_life.h"
64
 
#include "freeswan/ipsec_xform.h"
65
 
#include "freeswan/ipsec_eroute.h"
66
 
#include "freeswan/ipsec_encap.h"
67
 
#include "freeswan/ipsec_radij.h"
68
 
#include "freeswan/ipsec_sa.h"
69
 
#include "freeswan/ipsec_tunnel.h"
70
 
#include "freeswan/ipsec_xmit.h"
71
 
#include "freeswan/ipsec_ipe4.h"
72
 
#include "freeswan/ipsec_ah.h"
73
 
#include "freeswan/ipsec_esp.h"
 
66
#include "openswan/ipsec_kversion.h"
 
67
#include "openswan/radij.h"
 
68
#include "openswan/ipsec_life.h"
 
69
#include "openswan/ipsec_xform.h"
 
70
#include "openswan/ipsec_eroute.h"
 
71
#include "openswan/ipsec_encap.h"
 
72
#include "openswan/ipsec_radij.h"
 
73
#include "openswan/ipsec_sa.h"
 
74
#include "openswan/ipsec_tunnel.h"
 
75
#include "openswan/ipsec_xmit.h"
 
76
#include "openswan/ipsec_ipe4.h"
 
77
#include "openswan/ipsec_ah.h"
 
78
#include "openswan/ipsec_esp.h"
 
79
#include "openswan/ipsec_kern24.h"
74
80
 
75
81
#include <pfkeyv2.h>
76
82
#include <pfkey.h>
77
83
 
78
 
#include "freeswan/ipsec_proto.h"
79
 
#ifdef CONFIG_IPSEC_NAT_TRAVERSAL
 
84
#include "openswan/ipsec_proto.h"
 
85
#ifdef CONFIG_KLIPS_NAT_TRAVERSAL
80
86
#include <linux/udp.h>
81
87
#endif
82
88
 
83
89
static __u32 zeroes[64];
84
90
 
85
 
#ifdef CONFIG_IPSEC_DEBUG
 
91
#ifdef CONFIG_KLIPS_DEBUG
86
92
int debug_tunnel = 0;
87
 
#endif /* CONFIG_IPSEC_DEBUG */
 
93
#endif /* CONFIG_KLIPS_DEBUG */
88
94
 
89
95
DEBUG_NO_STATIC int
90
 
ipsec_tunnel_open(struct device *dev)
 
96
ipsec_tunnel_open(struct net_device *dev)
91
97
{
92
98
        struct ipsecpriv *prv = dev->priv;
93
99
        
103
109
        if (prv->dev == NULL)
104
110
                return -ENODEV;
105
111
        
106
 
        MOD_INC_USE_COUNT;
 
112
        KLIPS_INC_USE;
107
113
        return 0;
108
114
}
109
115
 
110
116
DEBUG_NO_STATIC int
111
 
ipsec_tunnel_close(struct device *dev)
 
117
ipsec_tunnel_close(struct net_device *dev)
112
118
{
113
 
        MOD_DEC_USE_COUNT;
 
119
        KLIPS_DEC_USE;
114
120
        return 0;
115
121
}
116
122
 
149
155
                ixs->hard_header_len = ixs->physdev->hard_header_len;
150
156
        }
151
157
 
152
 
#ifdef CONFIG_IPSEC_DEBUG
 
158
#ifdef CONFIG_KLIPS_DEBUG
153
159
        if (debug_tunnel & DB_TN_XMIT) {
154
160
                int i;
155
161
                char c;
164
170
                }
165
171
                printk(" \n");
166
172
        }
167
 
#endif /* CONFIG_IPSEC_DEBUG */
 
173
#endif /* CONFIG_KLIPS_DEBUG */
168
174
 
169
175
        KLIPS_IP_PRINT(debug_tunnel & DB_TN_XMIT, ixs->iph);
170
176
 
179
185
enum ipsec_xmit_value
180
186
ipsec_tunnel_SAlookup(struct ipsec_xmit_state *ixs)
181
187
{
 
188
        unsigned int bypass;
 
189
 
 
190
        bypass = FALSE;
 
191
 
182
192
        /*
183
193
         * First things first -- look us up in the erouting tables.
184
194
         */
199
209
        ixs->eroute = ipsec_findroute(&ixs->matcher);
200
210
 
201
211
        if(ixs->iph->protocol == IPPROTO_UDP) {
202
 
                if(ixs->skb->sk) {
203
 
                        ixs->sport=ntohs(ixs->skb->sk->sport);
204
 
                        ixs->dport=ntohs(ixs->skb->sk->dport);
205
 
                } else if((ntohs(ixs->iph->frag_off) & IP_OFFSET) == 0 &&
206
 
                          ((ixs->skb->len - ixs->hard_header_len) >=
207
 
                           ((ixs->iph->ihl << 2) + sizeof(struct udphdr)))) {
208
 
                        ixs->sport=ntohs(((struct udphdr*)((caddr_t)ixs->iph+(ixs->iph->ihl<<2)))->source);
209
 
                        ixs->dport=ntohs(((struct udphdr*)((caddr_t)ixs->iph + (ixs->iph->ihl<<2)))->dest);
210
 
                } else {
211
 
                        ixs->sport=0; ixs->dport=0;
212
 
                }
213
 
        }
214
 
 
 
212
                struct udphdr *t = NULL;
 
213
 
 
214
                KLIPS_PRINT(debug_tunnel & DB_TN_XMIT,
 
215
                            "klips_debug:udp port check: "
 
216
                            "fragoff: %d len: %d>%ld \n",
 
217
                            ntohs(ixs->iph->frag_off) & IP_OFFSET,
 
218
                            (ixs->skb->len - ixs->hard_header_len),
 
219
                            (unsigned long int) ((ixs->iph->ihl << 2) + sizeof(struct udphdr)));
 
220
                
 
221
                if((ntohs(ixs->iph->frag_off) & IP_OFFSET) == 0 &&
 
222
                   ((ixs->skb->len - ixs->hard_header_len) >=
 
223
                    ((ixs->iph->ihl << 2) + sizeof(struct udphdr))))
 
224
                {
 
225
                        t =((struct udphdr*)((caddr_t)ixs->iph+(ixs->iph->ihl<<2)));
 
226
                        KLIPS_PRINT(debug_tunnel & DB_TN_XMIT,
 
227
                                    "klips_debug:udp port in packet: "
 
228
                                    "port %d -> %d\n",
 
229
                                    ntohs(t->source), ntohs(t->dest));
 
230
                }
 
231
 
 
232
                ixs->sport=0; ixs->dport=0;
 
233
 
 
234
                if(ixs->skb->sk) {
 
235
#ifdef NET_26
 
236
                        struct udp_sock *us;
 
237
                        
 
238
                        us = (struct udp_sock *)ixs->skb->sk;
 
239
 
 
240
                        ixs->sport = ntohs(us->inet.sport);
 
241
                        ixs->dport = ntohs(us->inet.dport);
 
242
#else
 
243
                        ixs->sport = ntohs(ixs->skb->sk->sport);
 
244
                        ixs->dport = ntohs(ixs->skb->sk->dport);
 
245
#endif
 
246
 
 
247
                } 
 
248
 
 
249
                if(t != NULL) {
 
250
                        if(ixs->sport == 0) {
 
251
                                ixs->sport = ntohs(t->source);
 
252
                        }
 
253
                        if(ixs->dport == 0) {
 
254
                                ixs->dport = ntohs(t->dest);
 
255
                        }
 
256
                }
 
257
        }
 
258
 
 
259
        /*
 
260
         * practically identical to above, but let's be careful about
 
261
         * tcp vs udp headers
 
262
         */
 
263
        if(ixs->iph->protocol == IPPROTO_TCP) {
 
264
                struct tcphdr *t = NULL;
 
265
 
 
266
                if((ntohs(ixs->iph->frag_off) & IP_OFFSET) == 0 &&
 
267
                   ((ixs->skb->len - ixs->hard_header_len) >=
 
268
                    ((ixs->iph->ihl << 2) + sizeof(struct tcphdr)))) {
 
269
                        t =((struct tcphdr*)((caddr_t)ixs->iph+(ixs->iph->ihl<<2)));
 
270
                }
 
271
 
 
272
                ixs->sport=0; ixs->dport=0;
 
273
 
 
274
                if(ixs->skb->sk) {
 
275
#ifdef NET_26
 
276
                        struct tcp_tw_bucket *tw;
 
277
                        
 
278
                        tw = (struct tcp_tw_bucket *)ixs->skb->sk;
 
279
 
 
280
                        ixs->sport = ntohs(tw->tw_sport);
 
281
                        ixs->dport = ntohs(tw->tw_dport);
 
282
#else
 
283
                        ixs->sport = ntohs(ixs->skb->sk->sport);
 
284
                        ixs->dport = ntohs(ixs->skb->sk->dport);
 
285
#endif
 
286
                } 
 
287
 
 
288
                if(t != NULL) {
 
289
                        if(ixs->sport == 0) {
 
290
                                ixs->sport = ntohs(t->source);
 
291
                        }
 
292
                        if(ixs->dport == 0) {
 
293
                                ixs->dport = ntohs(t->dest);
 
294
                        }
 
295
                }
 
296
        }
 
297
        
215
298
        /* default to a %drop eroute */
216
299
        ixs->outgoing_said.proto = IPPROTO_INT;
217
300
        ixs->outgoing_said.spi = htonl(SPI_DROP);
229
312
                    ixs->dport); 
230
313
 
231
314
        /*
232
 
         * Quick cheat for now...are we udp/500? If so, let it through
 
315
         * cheat for now...are we udp/500? If so, let it through
233
316
         * without interference since it is most likely an IKE packet.
234
317
         */
235
318
 
236
319
        if (ip_chk_addr((unsigned long)ixs->iph->saddr) == IS_MYADDR
237
 
            && (!ixs->eroute
 
320
            && (ixs->eroute==NULL
238
321
                || ixs->iph->daddr == ixs->eroute->er_said.dst.u.v4.sin_addr.s_addr
239
322
                || INADDR_ANY == ixs->eroute->er_said.dst.u.v4.sin_addr.s_addr)
240
 
 
241
 
            && ((ixs->sport == 500) || (ixs->sport == 4500))) {
242
 
                /* Whatever the eroute, this is an IKE message
 
323
            && (ixs->iph->protocol == IPPROTO_UDP && ixs->sport == 500)) {
 
324
                /* Whatever the eroute, this is an IKE message 
243
325
                 * from us (i.e. not being forwarded).
244
326
                 * Furthermore, if there is a tunnel eroute,
245
327
                 * the destination is the peer for this eroute.
246
328
                 * So %pass the packet: modify the default %drop.
247
329
                 */
 
330
 
248
331
                ixs->outgoing_said.spi = htonl(SPI_PASS);
249
332
                if(!(ixs->skb->sk) && ((ntohs(ixs->iph->frag_off) & IP_MF) != 0)) {
250
333
                        KLIPS_PRINT(debug_tunnel & DB_TN_XMIT,
251
334
                                    "klips_debug:ipsec_xmit_SAlookup: "
252
335
                                    "local UDP/500 (probably IKE) passthrough: base fragment, rest of fragments will probably get filtered.\n");
253
336
                }
254
 
        } else if (ixs->eroute) {
 
337
                bypass = TRUE;
 
338
        }
 
339
 
 
340
#ifdef KLIPS_EXCEPT_DNS53
 
341
        /*
 
342
         *
 
343
         * if we are udp/53 or tcp/53, also let it through a %trap or %hold,
 
344
         * since it is DNS, but *also* follow the %trap.
 
345
         * 
 
346
         * we do not do this for tunnels, only %trap's and %hold's.
 
347
         *
 
348
         */
 
349
 
 
350
        if (ip_chk_addr((unsigned long)ixs->iph->saddr) == IS_MYADDR
 
351
            && (ixs->eroute==NULL
 
352
                || ixs->iph->daddr == ixs->eroute->er_said.dst.u.v4.sin_addr.s_addr
 
353
                || INADDR_ANY == ixs->eroute->er_said.dst.u.v4.sin_addr.s_addr)
 
354
            && ((ixs->iph->protocol == IPPROTO_UDP
 
355
                 || ixs->iph->protocol == IPPROTO_TCP)
 
356
                && ixs->dport == 53)) {
 
357
                
 
358
                KLIPS_PRINT(debug_tunnel & DB_TN_XMIT,
 
359
                            "klips_debug:ipsec_xmit_SAlookup: "
 
360
                            "possible DNS packet\n");
 
361
 
 
362
                if(ixs->eroute)
 
363
                {
 
364
                        if(ixs->eroute->er_said.spi == htonl(SPI_TRAP)
 
365
                           || ixs->eroute->er_said.spi == htonl(SPI_HOLD))
 
366
                        {
 
367
                                ixs->outgoing_said.spi = htonl(SPI_PASSTRAP);
 
368
                                bypass = TRUE;
 
369
                        }
 
370
                }
 
371
                else
 
372
                {
 
373
                        ixs->outgoing_said.spi = htonl(SPI_PASSTRAP);
 
374
                        bypass = TRUE;
 
375
                }
 
376
                                
 
377
                KLIPS_PRINT(debug_tunnel & DB_TN_XMIT,
 
378
                            "klips_debug:ipsec_xmit_SAlookup: "
 
379
                            "bypass = %d\n", bypass);
 
380
 
 
381
                if(bypass
 
382
                   && !(ixs->skb->sk)
 
383
                   && ((ntohs(ixs->iph->frag_off) & IP_MF) != 0))
 
384
                {
 
385
                        KLIPS_PRINT(debug_tunnel & DB_TN_XMIT,
 
386
                                    "klips_debug:ipsec_xmit_SAlookup: "
 
387
                                    "local port 53 (probably DNS) passthrough:"
 
388
                                    "base fragment, rest of fragments will "
 
389
                                    "probably get filtered.\n");
 
390
                }
 
391
        }
 
392
#endif
 
393
 
 
394
        if (bypass==FALSE && ixs->eroute) {
255
395
                ixs->eroute->er_count++;
256
396
                ixs->eroute->er_lasttime = jiffies/HZ;
257
397
                if(ixs->eroute->er_said.proto==IPPROTO_INT
258
 
                   && ixs->eroute->er_said.spi==htonl(SPI_HOLD)) {
 
398
                   && ixs->eroute->er_said.spi==htonl(SPI_HOLD))
 
399
                {
259
400
                        KLIPS_PRINT(debug_tunnel & DB_TN_XMIT,
260
401
                                    "klips_debug:ipsec_xmit_SAlookup: "
261
402
                                    "shunt SA of HOLD: skb stored in HOLD.\n");
270
411
                }
271
412
                ixs->outgoing_said = ixs->eroute->er_said;
272
413
                ixs->eroute_pid = ixs->eroute->er_pid;
 
414
 
273
415
                /* Copy of the ident for the TRAP/TRAPSUBNET eroutes */
274
416
                if(ixs->outgoing_said.proto==IPPROTO_INT
275
417
                   && (ixs->outgoing_said.spi==htonl(SPI_TRAP)
279
421
                        ixs->ips.ips_ident_s.type = ixs->eroute->er_ident_s.type;
280
422
                        ixs->ips.ips_ident_s.id = ixs->eroute->er_ident_s.id;
281
423
                        ixs->ips.ips_ident_s.len = ixs->eroute->er_ident_s.len;
282
 
                        if (ixs->ips.ips_ident_s.len) {
 
424
                        if (ixs->ips.ips_ident_s.len)
 
425
                        {
283
426
                                len = ixs->ips.ips_ident_s.len * IPSEC_PFKEYv2_ALIGN - sizeof(struct sadb_ident);
284
427
                                KLIPS_PRINT(debug_tunnel & DB_TN_XMIT,
285
428
                                            "klips_debug:ipsec_xmit_SAlookup: "
298
441
                        ixs->ips.ips_ident_d.type = ixs->eroute->er_ident_d.type;
299
442
                        ixs->ips.ips_ident_d.id = ixs->eroute->er_ident_d.id;
300
443
                        ixs->ips.ips_ident_d.len = ixs->eroute->er_ident_d.len;
301
 
                        if (ixs->ips.ips_ident_d.len) {
 
444
                        if (ixs->ips.ips_ident_d.len)
 
445
                        {
302
446
                                len = ixs->ips.ips_ident_d.len * IPSEC_PFKEYv2_ALIGN - sizeof(struct sadb_ident);
303
447
                                KLIPS_PRINT(debug_tunnel & DB_TN_XMIT,
304
448
                                            "klips_debug:ipsec_xmit_SAlookup: "
321
465
        return IPSEC_XMIT_OK;
322
466
}
323
467
 
 
468
 
324
469
enum ipsec_xmit_value
325
470
ipsec_tunnel_restore_hard_header(struct ipsec_xmit_state*ixs)
326
471
{
349
494
                        }
350
495
                }
351
496
        }
352
 
#ifdef CONFIG_IPSEC_NAT_TRAVERSAL
 
497
#ifdef CONFIG_KLIPS_NAT_TRAVERSAL
353
498
        if (ixs->natt_type && ixs->natt_head) {
354
499
                struct iphdr *ipp = ixs->skb->nh.iph;
355
500
                struct udphdr *udp;
542
687
 *      and that skb is filled properly by that function.
543
688
 */
544
689
int
545
 
ipsec_tunnel_start_xmit(struct sk_buff *skb, struct device *dev)
 
690
ipsec_tunnel_start_xmit(struct sk_buff *skb, struct net_device *dev)
546
691
{
547
692
        struct ipsec_xmit_state ixs_mem;
548
693
        struct ipsec_xmit_state *ixs = &ixs_mem;
549
694
        enum ipsec_xmit_value stat;
550
695
 
551
 
#ifdef CONFIG_IPSEC_NAT_TRAVERSAL
 
696
#ifdef CONFIG_KLIPS_NAT_TRAVERSAL
552
697
        ixs->natt_type = 0, ixs->natt_head = 0;
553
698
        ixs->natt_sport = 0, ixs->natt_dport = 0;
554
699
#endif
642
787
}
643
788
 
644
789
DEBUG_NO_STATIC struct net_device_stats *
645
 
ipsec_tunnel_get_stats(struct device *dev)
 
790
ipsec_tunnel_get_stats(struct net_device *dev)
646
791
{
647
792
        return &(((struct ipsecpriv *)(dev->priv))->mystats);
648
793
}
653
798
 */
654
799
 
655
800
DEBUG_NO_STATIC int
656
 
ipsec_tunnel_hard_header(struct sk_buff *skb, struct device *dev,
 
801
ipsec_tunnel_hard_header(struct sk_buff *skb, struct net_device *dev,
657
802
        unsigned short type, void *daddr, void *saddr, unsigned len)
658
803
{
659
804
        struct ipsecpriv *prv = dev->priv;
660
 
        struct device *tmp;
 
805
        struct net_device *tmp;
661
806
        int ret;
662
807
        struct net_device_stats *stats; /* This device's statistics */
663
808
        
737
882
                        return -ENODEV;
738
883
                }
739
884
                
740
 
#define da ((struct device *)(prv->dev))->dev_addr
 
885
#define da ((struct net_device *)(prv->dev))->dev_addr
741
886
                KLIPS_PRINT(debug_tunnel & DB_TN_REVEC,
742
887
                            "klips_debug:ipsec_tunnel_hard_header: "
743
888
                            "Revectored 0p%p->0p%p len=%d type=%d dev=%s->%s dev_addr=%02x:%02x:%02x:%02x:%02x:%02x ",
775
920
#ifdef NET_21
776
921
ipsec_tunnel_rebuild_header(struct sk_buff *skb)
777
922
#else /* NET_21 */
778
 
ipsec_tunnel_rebuild_header(void *buff, struct device *dev,
 
923
ipsec_tunnel_rebuild_header(void *buff, struct net_device *dev,
779
924
                        unsigned long raddr, struct sk_buff *skb)
780
925
#endif /* NET_21 */
781
926
{
782
927
        struct ipsecpriv *prv = skb->dev->priv;
783
 
        struct device *tmp;
 
928
        struct net_device *tmp;
784
929
        int ret;
785
930
        struct net_device_stats *stats; /* This device's statistics */
786
931
        
858
1003
}
859
1004
 
860
1005
DEBUG_NO_STATIC int
861
 
ipsec_tunnel_set_mac_address(struct device *dev, void *addr)
 
1006
ipsec_tunnel_set_mac_address(struct net_device *dev, void *addr)
862
1007
{
863
1008
        struct ipsecpriv *prv = dev->priv;
864
1009
        
908
1053
 
909
1054
#ifndef NET_21
910
1055
DEBUG_NO_STATIC void
911
 
ipsec_tunnel_cache_bind(struct hh_cache **hhp, struct device *dev,
 
1056
ipsec_tunnel_cache_bind(struct hh_cache **hhp, struct net_device *dev,
912
1057
                                 unsigned short htype, __u32 daddr)
913
1058
{
914
1059
        struct ipsecpriv *prv = dev->priv;
960
1105
 
961
1106
 
962
1107
DEBUG_NO_STATIC void
963
 
ipsec_tunnel_cache_update(struct hh_cache *hh, struct device *dev, unsigned char *  haddr)
 
1108
ipsec_tunnel_cache_update(struct hh_cache *hh, struct net_device *dev, unsigned char *  haddr)
964
1109
{
965
1110
        struct ipsecpriv *prv = dev->priv;
966
1111
        
1022
1167
}
1023
1168
 
1024
1169
DEBUG_NO_STATIC int
1025
 
ipsec_tunnel_neigh_setup_dev(struct device *dev, struct neigh_parms *p)
 
1170
ipsec_tunnel_neigh_setup_dev(struct net_device *dev, struct neigh_parms *p)
1026
1171
{
1027
1172
        KLIPS_PRINT(debug_tunnel & DB_TN_REVEC,
1028
1173
                    "klips_debug:ipsec_tunnel_neigh_setup_dev: "
1043
1188
 */
1044
1189
 
1045
1190
DEBUG_NO_STATIC int
1046
 
ipsec_tunnel_attach(struct device *dev, struct device *physdev)
 
1191
ipsec_tunnel_attach(struct net_device *dev, struct net_device *physdev)
1047
1192
{
1048
1193
        int i;
1049
1194
        struct ipsecpriv *prv = dev->priv;
1116
1261
        for (i=0; i<dev->addr_len; i++) {
1117
1262
                dev->dev_addr[i] = physdev->dev_addr[i];
1118
1263
        }
1119
 
#ifdef CONFIG_IPSEC_DEBUG
 
1264
#ifdef CONFIG_KLIPS_DEBUG
1120
1265
        if(debug_tunnel & DB_TN_INIT) {
1121
1266
                printk(KERN_INFO "klips_debug:ipsec_tunnel_attach: "
1122
1267
                       "physical device %s being attached has HW address: %2x",
1126
1271
                }
1127
1272
                printk("\n");
1128
1273
        }
1129
 
#endif /* CONFIG_IPSEC_DEBUG */
 
1274
#endif /* CONFIG_KLIPS_DEBUG */
1130
1275
 
1131
1276
        return 0;
1132
1277
}
1136
1281
 */
1137
1282
 
1138
1283
DEBUG_NO_STATIC int
1139
 
ipsec_tunnel_detach(struct device *dev)
 
1284
ipsec_tunnel_detach(struct net_device *dev)
1140
1285
{
1141
1286
        int i;
1142
1287
        struct ipsecpriv *prv = dev->priv;
1223
1368
ipsec_tunnel_clear(void)
1224
1369
{
1225
1370
        int i;
1226
 
        struct device *ipsecdev = NULL, *prvdev;
 
1371
        struct net_device *ipsecdev = NULL, *prvdev;
1227
1372
        struct ipsecpriv *prv;
1228
1373
        char name[9];
1229
1374
        int ret;
1235
1380
                ipsecdev = ipsecdevices[i];
1236
1381
                if(ipsecdev != NULL) {
1237
1382
                        if((prv = (struct ipsecpriv *)(ipsecdev->priv))) {
1238
 
                                prvdev = (struct device *)(prv->dev);
 
1383
                                prvdev = (struct net_device *)(prv->dev);
1239
1384
                                if(prvdev) {
1240
1385
                                        KLIPS_PRINT(debug_tunnel & DB_TN_INIT,
1241
1386
                                                    "klips_debug:ipsec_tunnel_clear: "
1256
1401
}
1257
1402
 
1258
1403
DEBUG_NO_STATIC int
1259
 
ipsec_tunnel_ioctl(struct device *dev, struct ifreq *ifr, int cmd)
 
1404
ipsec_tunnel_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
1260
1405
{
1261
1406
        struct ipsectunnelconf *cf = (struct ipsectunnelconf *)&ifr->ifr_data;
1262
1407
        struct ipsecpriv *prv = dev->priv;
1263
 
        struct device *them; /* physical device */
 
1408
        struct net_device *them; /* physical device */
1264
1409
#ifdef CONFIG_IP_ALIAS
1265
1410
        char *colon;
1266
1411
        char realphysname[IFNAMSIZ];
1300
1445
                                    "klips_debug:ipsec_tunnel_ioctl: "
1301
1446
                                    "physical device %s requested is null\n",
1302
1447
                                    cf->cf_name);
1303
 
                        ipsec_dev_put(them);
1304
1448
                        return -ENXIO;
1305
1449
                }
1306
1450
                
1355
1499
int
1356
1500
ipsec_device_event(struct notifier_block *unused, unsigned long event, void *ptr)
1357
1501
{
1358
 
        struct device *dev = ptr;
1359
 
        struct device *ipsec_dev;
 
1502
        struct net_device *dev = ptr;
 
1503
        struct net_device *ipsec_dev;
1360
1504
        struct ipsecpriv *priv;
1361
1505
        int i;
1362
1506
 
1411
1555
                                priv = (struct ipsecpriv *)(ipsec_dev->priv);
1412
1556
                                if(priv) {
1413
1557
                                        ;
1414
 
                                        if(((struct device *)(priv->dev)) == dev) {
 
1558
                                        if(((struct net_device *)(priv->dev)) == dev) {
1415
1559
                                                /* dev_close(ipsec_dev); */
1416
1560
                                                /* return */ ipsec_tunnel_detach(ipsec_dev);
1417
1561
                                                KLIPS_PRINT(debug_tunnel & DB_TN_INIT,
1498
1642
 */
1499
1643
 
1500
1644
int
1501
 
ipsec_tunnel_init(struct device *dev)
 
1645
ipsec_tunnel_init(struct net_device *dev)
1502
1646
{
1503
1647
        int i;
1504
1648
 
1552
1696
 
1553
1697
        /* New-style flags. */
1554
1698
        dev->flags              = IFF_NOARP /* 0 */ /* Petr Novak */;
 
1699
 
 
1700
#if 0
1555
1701
#ifdef NET_21
1556
1702
        dev_init_buffers(dev);
1557
1703
#else /* NET_21 */
1561
1707
        dev->pa_mask            = 0;
1562
1708
        dev->pa_alen            = 4;
1563
1709
#endif /* NET_21 */
 
1710
#endif
1564
1711
 
1565
1712
        /* We're done.  Have I forgotten anything? */
1566
1713
        return 0;
1571
1718
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1572
1719
 
1573
1720
int
1574
 
ipsec_tunnel_probe(struct device *dev)
 
1721
ipsec_tunnel_probe(struct net_device *dev)
1575
1722
{
1576
1723
        ipsec_tunnel_init(dev); 
1577
1724
        return 0;
1578
1725
}
1579
1726
 
1580
 
struct device *ipsecdevices[IPSEC_NUM_IF];
 
1727
struct net_device *ipsecdevices[IPSEC_NUM_IF];
1581
1728
 
1582
1729
int 
1583
1730
ipsec_tunnel_init_devices(void)
1584
1731
{
1585
1732
        int i;
1586
1733
        char name[IFNAMSIZ];
1587
 
        struct device *dev_ipsec;
 
1734
        struct net_device *dev_ipsec;
1588
1735
        
1589
1736
        KLIPS_PRINT(debug_tunnel & DB_TN_INIT,
1590
1737
                    "klips_debug:ipsec_tunnel_init_devices: "
1591
1738
                    "creating and registering IPSEC_NUM_IF=%u devices, allocating %lu per device, IFNAMSIZ=%u.\n",
1592
1739
                    IPSEC_NUM_IF,
1593
 
                    (unsigned long) (sizeof(struct device) + IFNAMSIZ),
 
1740
                    (unsigned long) (sizeof(struct net_device) + IFNAMSIZ),
1594
1741
                    IFNAMSIZ);
1595
1742
 
1596
1743
        for(i = 0; i < IPSEC_NUM_IF; i++) {
1597
1744
                sprintf(name, IPSEC_DEV_FORMAT, i);
1598
 
                dev_ipsec = (struct device*)kmalloc(sizeof(struct device), GFP_KERNEL);
 
1745
                dev_ipsec = (struct net_device*)kmalloc(sizeof(struct net_device), GFP_KERNEL);
1599
1746
                if (dev_ipsec == NULL) {
1600
1747
                        KLIPS_PRINT(debug_tunnel & DB_TN_INIT,
1601
1748
                                    "klips_debug:ipsec_tunnel_init_devices: "
1603
1750
                                    name);
1604
1751
                        return -ENOMEM;
1605
1752
                }
1606
 
                memset((caddr_t)dev_ipsec, 0, sizeof(struct device));
 
1753
                memset((caddr_t)dev_ipsec, 0, sizeof(struct net_device));
1607
1754
#ifdef NETDEV_23
1608
1755
                strncpy(dev_ipsec->name, name, sizeof(dev_ipsec->name));
1609
1756
#else /* NETDEV_23 */
1652
1799
        int error = 0;
1653
1800
        int i;
1654
1801
        char name[32];
1655
 
        struct device *dev_ipsec;
 
1802
        struct net_device *dev_ipsec;
1656
1803
        
1657
1804
        for(i = 0; i < IPSEC_NUM_IF; i++) {
1658
1805
                dev_ipsec = ipsecdevices[i];
1681
1828
 
1682
1829
/*
1683
1830
 * $Log: ipsec_tunnel.c,v $
 
1831
 * Revision 1.227  2004/12/10 21:16:08  ken
 
1832
 * 64bit fixes from Opteron port of KLIPS 2.6
 
1833
 *
 
1834
 * Revision 1.226  2004/12/04 07:11:23  mcr
 
1835
 *      fix for snmp SIOCPRIVATE use of snmpd.
 
1836
 *      http://bugs.xelerance.com/view.php?id=144
 
1837
 *
 
1838
 * Revision 1.225  2004/12/03 21:25:57  mcr
 
1839
 *      compile time fixes for running on 2.6.
 
1840
 *      still experimental.
 
1841
 *
 
1842
 * Revision 1.224  2004/08/14 03:28:24  mcr
 
1843
 *      fixed log comment to remove warning about embedded comment.
 
1844
 *
 
1845
 * Revision 1.223  2004/08/04 15:57:07  mcr
 
1846
 *      moved des .h files to include/des/ *
 
1847
 *      included 2.6 protocol specific things
 
1848
 *      started at NAT-T support, but it will require a kernel patch.
 
1849
 *
 
1850
 * Revision 1.222  2004/08/03 18:19:08  mcr
 
1851
 *      in 2.6, use "net_device" instead of #define device->net_device.
 
1852
 *      this probably breaks 2.0 compiles.
 
1853
 *
 
1854
 * Revision 1.221  2004/07/10 19:11:18  mcr
 
1855
 *      CONFIG_IPSEC -> CONFIG_KLIPS.
 
1856
 *
 
1857
 * Revision 1.220  2004/04/06 02:49:26  mcr
 
1858
 *      pullup of algo code from alg-branch.
 
1859
 *
1684
1860
 * Revision 1.219  2004/02/03 03:13:17  mcr
1685
1861
 *      minor edits for readability, and error reporting.
1686
1862
 *