Browse Source

I have found some stuff in netsukuku which I have used to fix the exclude argument, It should now function correctly. Testing is needed.

MissValeska 9 years ago
parent
commit
454aa9a776
1 changed files with 12 additions and 104 deletions
  1. 12
    104
      src/netsukuku.c

+ 12
- 104
src/netsukuku.c View File

@@ -51,8 +51,6 @@ extern int optind, opterr, optopt;
51 51
 int destroy_netsukuku_mutex;
52 52
 int pid_saved;
53 53
 
54
-int prevent_duplication;
55
-
56 54
 int options_parsed = 0;			/* How many times parse_options() has been called */
57 55
 
58 56
 void
@@ -359,118 +357,30 @@ free_server_opt(void)
359 357
 		xfree(server_opt.ifs[i]);
360 358
 }
361 359
 
362
-/* Checks and removes any existing interface which is intended to be excluded*/
360
+/* Removes specified existing interface, Ntkd should populate the device list
361
+ * prior to this.
362
+ * returns 0 on success, And closes ntkd on error.
363
+*/
363 364
 
364
-void
365
-check_excluded(void)
365
+int
366
+exclude_interface(void)
366 367
 {
367
-
368 368
 	int i;
369 369
 
370 370
 	printf("Number of Interfaces in Use: %d\n", server_opt.ifs_n);
371 371
 	printf("Interface names in Use: %s", (char *) server_opt.ifs);
372 372
 
373
-	for (i = 0; i < server_opt.ifs_n; i++) {
374
-		if (strcmp(server_opt.ifs[i], optarg) == 0) {
373
+	for (i = 0; i < me.cur_ifs_n; i++) {
374
+		if (strcmp(me.cur_ifs[i], optarg) == 0) {
375 375
 			printf("Interface %s removed, And replaced with %s",
376
-				   server_opt.ifs[i], server_opt.ifs[server_opt.ifs_n]);
377
-			strncpy(server_opt.ifs[i], server_opt.ifs[server_opt.ifs_n],
378
-					strlen(server_opt.ifs[server_opt.ifs_n]));
379
-			server_opt.ifs_n -= 1;
380
-		}
381
-
382
-	}
383
-
384
-}
385
-
386
-/* Adds all interfaces available which are up, And not the interface set by the user.
387
- * -e eth0 would exclude eth0 from being used by netsukuku. It, Also, Excludes the 
388
- * loopback interface, And tunl0, and tunl1, If it exists.
389
- * 
390
- * It iterates through a pointer to the getifaddrs struct, Using the ifa_name member 
391
- * for reading the interface name, And ifa_next to move to the next
392
- * interface in the array.
393
- * 
394
- * It commits every up interface name that is not the one specified to be excluded
395
- * by the user, Nor the loop back interface to server_opt.ifs and to pointer
396
- * to the struct interface in the member dev_name, And increments the server_opt.ifs_n member. 
397
- * It, Also, Sets the index of each interface to a pointer to the struct interface 
398
- * in the member dev_idx
399
- * 
400
- * It checks if it has already been run, If it has, It just runs check_excluded()
401
- * and then exits. check_excluded() is run at the end of the function
402
- * to check for errors in excluding optarg.
403
- * 
404
- * returns 0 on success, -1 on error, And 1 if it has already been run.
405
-*/
406
-
407
-void
408
-exclude_interface()
409
-{
410
-
411
-	if (prevent_duplication == 1) {
412
-		check_excluded();
413
-		return;
414
-	}
415
-
416
-	char *ifs = "null1";
417
-	char *old_tmp = "null2";
418
-	interface *ifs_a;
419
-	int ifs_n = 1;
420
-	struct ifaddrs *addrs, *tmp;
421
-
422
-	if (getifaddrs(&addrs) != 0) {
423
-		printf("%s\n", strerror(errno));
424
-		exit(-1);
425
-	}
426
-	tmp = addrs;
427
-	while (tmp) {
428
-
429
-		old_tmp = ifs;
430
-
431
-		if (tmp && tmp->ifa_addr && tmp->ifa_addr->sa_family == AF_PACKET
432
-			&& tmp->ifa_flags & IFF_UP && !(tmp->ifa_flags & IFF_LOOPBACK
433
-											&& strncmp(tmp->ifa_name,
434
-													   "tunl0",
435
-													   (int) strlen(tmp->
436
-																	ifa_name))
437
-											!= 0
438
-											&& strncmp(tmp->ifa_name,
439
-													   "tunl1",
440
-													   (int) strlen(tmp->
441
-																	ifa_name))
442
-											!= 0
443
-											&& strcmp(optarg,
444
-													  tmp->ifa_name) !=
445
-											0)) {
446
-			ifs = tmp->ifa_name;
447
-			ifs_n++;
448
-		}
449
-
450
-		printf("Good ifs is: %s\n", ifs);
451
-
452
-		if (strcmp(old_tmp, ifs) == 0) {
453
-			printf("Loop finished: %s\n", ifs);
454
-			check_excluded();
455
-			return;
376
+			me.cur_ifs[i], me.cur_ifs[me.cur_ifs_n]);
377
+                        ifs_del(me.cur_ifs, &me.cur_ifs_n, i);
378
+                        return 0;
456 379
 		}
457
-
458
-		tmp = tmp->ifa_next;
459
-		server_opt.ifs[server_opt.ifs_n++] = xstrndup(ifs, IFNAMSIZ - 1);
460
-		printf("Using Interface: %s\n", ifs);
461
-
462
-		ifs_a[ifs_n].dev_idx = (int) tmp->ifa_flags;
463
-
464
-		strncpy(ifs_a[ifs_n].dev_name, ifs, (int) strlen(ifs));
465
-
466 380
 	}
467
-
468
-	check_excluded();
469
-
470
-	freeifaddrs(addrs);
381
+        fatal("Interface %s not found!", optarg);
471 382
 }
472 383
 
473
-
474 384
 void
475 385
 ntk_thread_creatation(void)
476 386
 {
@@ -530,8 +440,6 @@ parse_options(int argc, char **argv)
530 440
 			exit(0);
531 441
 			break;
532 442
 		case 'e':
533
-			prevent_duplication = -1;
534
-			prevent_duplication++;
535 443
 			exclude_interface();
536 444
 			break;
537 445
 		case 'k':

Loading…
Cancel
Save