|
@@ -17,7 +17,7 @@
|
17
|
17
|
* Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
18
|
18
|
*
|
19
|
19
|
* --
|
20
|
|
- * This code derives from iproute2/iprule.c, it was modified to fit in
|
|
20
|
+ * This code derives from iproute2/iprule.c, it was modified to fit in
|
21
|
21
|
* Netsukuku.
|
22
|
22
|
*
|
23
|
23
|
* Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
|
|
@@ -49,13 +49,14 @@ int do_del(inet_prefix *remote, inet_prefix *local, char *dev,
|
49
|
49
|
int tunnel_add(inet_prefix *remote, inet_prefix *local, char *dev,
|
50
|
50
|
char *tunl_prefix, int tunl_number)
|
51
|
51
|
{
|
52
|
|
- return do_add(SIOCADDTUNNEL, remote, local, dev, tunl_prefix,
|
|
52
|
+ return do_add(SIOCADDTUNNEL, remote, local, dev, tunl_prefix,
|
53
|
53
|
tunl_number);
|
54
|
54
|
}
|
55
|
55
|
|
56
|
56
|
int tunnel_change(inet_prefix *remote, inet_prefix *local, char *dev,
|
57
|
57
|
char *tunl_prefix, int tunl_number)
|
58
|
58
|
{
|
|
59
|
+ error("The value of siocchgtunnel is: %d", SIOCCHGTUNNEL);
|
59
|
60
|
return do_add(SIOCCHGTUNNEL, remote, local, dev, tunl_prefix,
|
60
|
61
|
tunl_number);
|
61
|
62
|
}
|
|
@@ -150,6 +151,7 @@ static int do_add_ioctl(int cmd, const char *basedev, struct ip_tunnel_parm *p)
|
150
|
151
|
ifr.ifr_ifru.ifru_data = (void*)p;
|
151
|
152
|
fd = socket(AF_INET, SOCK_DGRAM, 0);
|
152
|
153
|
err = ioctl(fd, cmd, &ifr);
|
|
154
|
+ error("Socket File Descriptor Is: %i cmd is: %i err is: %i ifr is: %s Errno is: %d", fd, cmd, err, &ifr, errno);
|
153
|
155
|
if (err)
|
154
|
156
|
error(ERROR_MSG "ioctl: %s",ERROR_POS, strerror(errno));
|
155
|
157
|
close(fd);
|
|
@@ -179,7 +181,7 @@ static int do_del_ioctl(const char *basedev, struct ip_tunnel_parm *p)
|
179
|
181
|
* fill_tunnel_parm: fills the `p' struct.
|
180
|
182
|
* `remote' and `local' must be in host order
|
181
|
183
|
*/
|
182
|
|
-static int fill_tunnel_parm(int cmd, inet_prefix *remote, inet_prefix *local,
|
|
184
|
+static int fill_tunnel_parm(int cmd, inet_prefix *remote, inet_prefix *local,
|
183
|
185
|
char *dev, char *tunl_prefix, int tunl_number,
|
184
|
186
|
struct ip_tunnel_parm *p)
|
185
|
187
|
{
|
|
@@ -229,7 +231,7 @@ static int fill_tunnel_parm(int cmd, inet_prefix *remote, inet_prefix *local,
|
229
|
231
|
return 0;
|
230
|
232
|
}
|
231
|
233
|
|
232
|
|
-/*
|
|
234
|
+/*
|
233
|
235
|
* do_get: returns 1 if the tunnel named `dev' exists.
|
234
|
236
|
*/
|
235
|
237
|
int do_get(char *dev)
|
|
@@ -246,9 +248,10 @@ int do_get(char *dev)
|
246
|
248
|
static int do_add(int cmd, inet_prefix *remote, inet_prefix *local, char *dev,
|
247
|
249
|
char *tunl_prefix, int tunl_number)
|
248
|
250
|
{
|
|
251
|
+ error("This is the do_add function.");
|
249
|
252
|
struct ip_tunnel_parm p;
|
250
|
253
|
|
251
|
|
- if (fill_tunnel_parm(cmd, remote, local, dev, tunl_prefix,
|
|
254
|
+ if (fill_tunnel_parm(cmd, remote, local, dev, tunl_prefix,
|
252
|
255
|
tunl_number, &p) < 0)
|
253
|
256
|
return -1;
|
254
|
257
|
|
|
@@ -258,7 +261,7 @@ static int do_add(int cmd, inet_prefix *remote, inet_prefix *local, char *dev,
|
258
|
261
|
switch (p.iph.protocol) {
|
259
|
262
|
case IPPROTO_IPIP:
|
260
|
263
|
return do_add_ioctl(cmd, DEFAULT_TUNL_IF, &p);
|
261
|
|
- default:
|
|
264
|
+ default:
|
262
|
265
|
fatal("cannot determine tunnel mode (ipip, gre or sit)\n");
|
263
|
266
|
}
|
264
|
267
|
return -1;
|
|
@@ -276,14 +279,14 @@ int do_del(inet_prefix *remote, inet_prefix *local, char *dev, char *tunl_prefix
|
276
|
279
|
switch (p.iph.protocol) {
|
277
|
280
|
case IPPROTO_IPIP:
|
278
|
281
|
return do_del_ioctl(DEFAULT_TUNL_IF, &p);
|
279
|
|
- default:
|
|
282
|
+ default:
|
280
|
283
|
return do_del_ioctl(p.name, &p);
|
281
|
284
|
}
|
282
|
285
|
return -1;
|
283
|
286
|
}
|
284
|
287
|
|
285
|
288
|
/*
|
286
|
|
- * tun_add_tunl: it adds in the `ifs' array a new struct which refers to
|
|
289
|
+ * tun_add_tunl: it adds in the `ifs' array a new struct which refers to
|
287
|
290
|
* the tunnel "tunlX", where X is a number equal to `tunl'.
|
288
|
291
|
*/
|
289
|
292
|
int tun_add_tunl(interface *ifs, char *tunl_prefix, u_char tunl_number)
|
|
@@ -298,7 +301,7 @@ int tun_add_tunl(interface *ifs, char *tunl_prefix, u_char tunl_number)
|
298
|
301
|
return 0;
|
299
|
302
|
}
|
300
|
303
|
|
301
|
|
-/*
|
|
304
|
+/*
|
302
|
305
|
* tun_del_tunl: it removes from the `ifs' array, which must have at least
|
303
|
306
|
* MAX_TUNNEL_IFS members, the struct which refers the tunnel "tunlX", where X
|
304
|
307
|
* is a number equal to `tunl'.
|
|
@@ -308,7 +311,7 @@ int tun_del_tunl(interface *ifs, char *tunl_prefix, u_char tunl_number)
|
308
|
311
|
{
|
309
|
312
|
char tunl_name[IFNAMSIZ];
|
310
|
313
|
int i;
|
311
|
|
-
|
|
314
|
+
|
312
|
315
|
sprintf(tunl_name, TUNL_STRING, TUNL_N(tunl_prefix, tunl_number));
|
313
|
316
|
|
314
|
317
|
for(i=0; i<MAX_TUNNEL_IFS; i++)
|
|
@@ -316,7 +319,7 @@ int tun_del_tunl(interface *ifs, char *tunl_prefix, u_char tunl_number)
|
316
|
319
|
memset(&ifs[i], 0, sizeof(interface));
|
317
|
320
|
return 0;
|
318
|
321
|
}
|
319
|
|
-
|
|
322
|
+
|
320
|
323
|
return -1;
|
321
|
324
|
}
|
322
|
325
|
|
|
@@ -328,7 +331,7 @@ void init_tunnels_ifs(void)
|
328
|
331
|
}
|
329
|
332
|
|
330
|
333
|
/*
|
331
|
|
- * first_free_tunnel_if: returns the position of the first member of the
|
|
334
|
+ * first_free_tunnel_if: returns the position of the first member of the
|
332
|
335
|
* `tunnel_ifs' array which isn't used yet.
|
333
|
336
|
* If the whole array is full, -1 is returned.
|
334
|
337
|
*/
|
|
@@ -369,14 +372,14 @@ int add_tunnel_if(inet_prefix *remote, inet_prefix *local, char *dev,
|
369
|
372
|
char *tunl_prefix, int tunl_number, inet_prefix *tunl_ip)
|
370
|
373
|
{
|
371
|
374
|
char tunl_name[IFNAMSIZ];
|
372
|
|
-
|
373
|
|
- /*
|
|
375
|
+
|
|
376
|
+ /*
|
374
|
377
|
* tunl0 zero is a special tunnel, it cannot be created nor destroyed.
|
375
|
378
|
* It's pure energy.
|
376
|
379
|
*/
|
377
|
380
|
if(!strcmp(tunl_prefix, DEFAULT_TUNL_PREFIX) && !tunl_number)
|
378
|
381
|
goto skip_krnl_add_tunl;
|
379
|
|
-
|
|
382
|
+
|
380
|
383
|
if(tunnel_add(remote, local, dev, tunl_prefix, tunl_number) < 0) {
|
381
|
384
|
error("Cannot add the \"" TUNL_STRING "\" tunnel",
|
382
|
385
|
TUNL_N(tunl_prefix, tunl_number));
|
|
@@ -396,14 +399,14 @@ skip_krnl_add_tunl:
|
396
|
399
|
if(set_tunnel_ip(tunl_prefix, tunl_number, tunl_ip) < 0)
|
397
|
400
|
return -1;
|
398
|
401
|
|
399
|
|
-
|
|
402
|
+
|
400
|
403
|
/*
|
401
|
404
|
* ip route append tunl_ip_subnet dev tunnel proto kernel \
|
402
|
405
|
* scope link src `tunl_ip'
|
403
|
406
|
*/
|
404
|
407
|
sprintf(tunl_name, TUNL_STRING, TUNL_N(tunl_prefix, tunl_number));
|
405
|
408
|
rt_append_subnet_src(tunl_ip, tunl_name);
|
406
|
|
-
|
|
409
|
+
|
407
|
410
|
if(route_rp_filter_all_dev(my_family, &tunnel_ifs[tunl_number],
|
408
|
411
|
1, 0) < 0)
|
409
|
412
|
return -1;
|
|
@@ -434,7 +437,7 @@ skip_krnl_del_tunl:
|
434
|
437
|
return 0;
|
435
|
438
|
}
|
436
|
439
|
|
437
|
|
-void del_all_tunnel_ifs(inet_prefix *remote, inet_prefix *local, char *dev,
|
|
440
|
+void del_all_tunnel_ifs(inet_prefix *remote, inet_prefix *local, char *dev,
|
438
|
441
|
char *tunl_prefix)
|
439
|
442
|
{
|
440
|
443
|
char tunl_name[IFNAMSIZ];
|