summaryrefslogtreecommitdiff
blob: 15402881341eb7aa766e183fcd661129ed25b872 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
diff -r 469eaa76099e GenDefs.h
--- a/GenDefs.h	Mon Apr 28 10:40:53 2008 +0200
+++ b/GenDefs.h	Mon Apr 28 10:47:51 2008 +0200
@@ -105,6 +105,12 @@ typedef int32 intptr_t;
 #define _INTPTR_T_DEFINED
 #endif
 
+/* uintptr_t has been defined in include/linux/types.h in 2.6.24.
+ * No need to define it here again (will only lead to compile errors)
+ *
+ * by Alexander Griesser <work@tuxx-home.at>, 2008-01-11
+ */
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
 #ifndef _UINTPTR_T_DEFINED
 #if defined(_LP64)
 #warning 64 bit
@@ -113,6 +119,7 @@ typedef uint32 uintptr_t;
 typedef uint32 uintptr_t;
 #endif
 #define _UINTPTR_T_DEFINED
+#endif
 #endif
 
 
diff -r 469eaa76099e Makefile
--- a/Makefile	Mon Apr 28 10:40:53 2008 +0200
+++ b/Makefile	Mon Apr 28 10:47:51 2008 +0200
@@ -12,7 +12,7 @@ SOURCE_OBJS := linuxcniapi.o frag.o IPSe
 SOURCE_OBJS := linuxcniapi.o frag.o IPSecDrvOS_linux.o interceptor.o linuxkernelapi.o
 
 ifeq ($(SUBARCH),x86_64)
-CFLAGS += -mcmodel=kernel -mno-red-zone
+EXTRA_CFLAGS += -mcmodel=kernel -mno-red-zone
 NO_SOURCE_OBJS := libdriver64.so
 else
 NO_SOURCE_OBJS := libdriver.so
diff -r 469eaa76099e interceptor.c
--- a/interceptor.c	Mon Apr 28 10:40:53 2008 +0200
+++ b/interceptor.c	Mon Apr 28 10:47:51 2008 +0200
@@ -28,6 +28,10 @@
 #include <linux/udp.h>
 #include <net/protocol.h>
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
+#include <net/net_namespace.h>
+#endif
+
 #include "linux_os.h"
 
 #include "vpn_ioctl_linux.h"
@@ -39,7 +43,7 @@
 
 static uint8_t interceptor_eth_addr[] = { 0x00, 0x0b, 0xfc, 0xf8, 0x01, 0x8f };
 
-// packet statistics 
+// packet statistics
 static unsigned long tx_packets;
 static unsigned long tx_dropped;
 static unsigned long tx_bytes;
@@ -48,7 +52,13 @@ unsigned long rx_bytes;
 unsigned long rx_bytes;
 
 /*methods of the cipsec network device*/
-static int interceptor_init(struct net_device *);
+static
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
+void
+#else
+int
+#endif
+interceptor_init(struct net_device *);
 static struct net_device_stats *interceptor_stats(struct net_device *dev);
 static int interceptor_ioctl(struct net_device *dev, struct ifreq *ifr,
                              int cmd);
@@ -82,12 +92,12 @@ struct packet_type_funcs
 {
     struct packet_type *pt;
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,14)
-    int (*orig_handler_func) (struct sk_buff *, 
+    int (*orig_handler_func) (struct sk_buff *,
                               struct net_device *,
                               struct packet_type *,
                               struct net_device *);
 #else
-    int (*orig_handler_func) (struct sk_buff *, 
+    int (*orig_handler_func) (struct sk_buff *,
                               struct net_device *,
                               struct packet_type *);
 #endif
@@ -107,16 +117,30 @@ static char interceptor_name[] = LINUX_V
 
 BINDING Bindings[MAX_INTERFACES];
 
+/* 2.6.24 handles net_devices a little bit different
+ *
+ * by Alexander Griesser <work@tuxx-home.at>, 2008-01-11
+ */
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
+static struct net_device* interceptor_dev;
+#else
 static struct net_device interceptor_dev = {
     .name = interceptor_name,
     .init = interceptor_init
 };
+#endif
+
 static struct notifier_block interceptor_notifier = {
     .notifier_call = handle_netdev_event,
 };
 
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-static int
+static
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
+void
+#else
+int
+#endif
 #else
 static int __init
 #endif
@@ -133,8 +157,9 @@ interceptor_init(struct net_device *dev)
     dev->flags |= IFF_NOARP;
     dev->flags &= ~(IFF_BROADCAST | IFF_MULTICAST);
     kernel_memset(dev->broadcast, 0xFF, ETH_ALEN);
-
-    return 0;
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
+	 return 0;
+#endif
 }
 
 static struct net_device_stats *
@@ -270,7 +295,7 @@ add_netdev(struct net_device *dev)
     Bindings[i].InjectReceive = original_ip_handler.orig_handler_func;
     Bindings[i].pPT = original_ip_handler.pt;
 
-    rc = 0; 
+    rc = 0;
 
 exit_gracefully:
     return rc;
@@ -284,7 +309,7 @@ remove_netdev(struct net_device *dev)
     b = getbindingbydev(dev);
 
     if (b)
-    {   
+    {
         rc = 0;
         dev->hard_start_xmit = b->InjectSend;
         kernel_memset(b, 0, sizeof(BINDING));
@@ -326,7 +351,7 @@ handle_vpnup(void)
     }
     /* find the handler for inbound IP packets by adding a dummy handler
      * for that packet type into the kernel. Because the packet handlers
-     * are stored in a hash table, we'll be able to pull the original 
+     * are stored in a hash table, we'll be able to pull the original
      * ip packet handler out of the list that dummy_pt was inserted into.*/
     kernel_memset(&dummy_pt, 0, sizeof(dummy_pt));
     dummy_pt.type = htons(ETH_P_IP);
@@ -363,7 +388,11 @@ handle_vpnup(void)
     dp = NULL;
     num_target_devices = 0;
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
-    for_each_netdev(dp)
+      for_each_netdev(
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
+                      &init_net,
+#endif
+                      dp)
 #else
     for (dp = dev_base; dp != NULL; dp = dp->next)
 #endif
@@ -494,7 +523,7 @@ getbindingbydev(struct net_device *dev)
 getbindingbydev(struct net_device *dev)
 {
     int i;
-    
+
     for (i=0; i <= MAX_INTERFACES; i++)
     {
         BINDING *b = &Bindings[i];
@@ -522,13 +551,13 @@ build_ppp_fake_mac_frag(struct ethhdr *d
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,14)
 static int
 recv_ip_packet_handler(struct sk_buff *skb,
-                       struct net_device *dev, 
+                       struct net_device *dev,
                        struct packet_type *type,
                        struct net_device *orig_dev)
 #else
 static int
 recv_ip_packet_handler(struct sk_buff *skb,
-                       struct net_device *dev, 
+                       struct net_device *dev,
                        struct packet_type *type)
 #endif
 {
@@ -932,15 +961,29 @@ interceptor_mod_init(void)
 
     rc = CniPluginLoad(&pcDeviceName, &PCNICallbackTable);
 
+/* 2.6.24 needs to allocate each netdevice before registering it, otherwise
+ * the kernel BUG()s.
+ *
+ * by Alexander Griesser <work@tuxx-home.at>, 2008-01-11
+ */
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
+    if(! (interceptor_dev = alloc_netdev(sizeof(struct net_device), interceptor_name, interceptor_init)))
+      return 0;
+#endif
+
     if (CNI_IS_SUCCESS(rc))
     {
 
         CNICallbackTable = *PCNICallbackTable;
         CniPluginDeviceCreated();
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
+	if ((status = register_netdev(interceptor_dev)) != 0)
+#else
         if ((status = register_netdev(&interceptor_dev)) != 0)
+#endif
         {
             printk(KERN_INFO "%s: error %d registering device \"%s\".\n",
-                   LINUX_VPN_IFNAME, status, interceptor_dev.name);
+                   LINUX_VPN_IFNAME, status, interceptor_name);
             CniPluginUnload();
 
         }
@@ -960,7 +1003,11 @@ interceptor_mod_cleanup(void)
     cleanup_frag_queue();
     CniPluginUnload();
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
+    unregister_netdev(interceptor_dev);
+#else
     unregister_netdev(&interceptor_dev);
+#endif
     unregister_netdevice_notifier(&interceptor_notifier);
 
     return;