Browse Source

I changed a lot in implementing and setting up testing stuff for netsplit, Including a new netsplit struct in netsukuku.h which may or may not be permanent. It was the only way I could find to preserve a variable from netsukuku.c to andns.c. Also, The netsukuku.c interface argument has, apparently, been just a break statement for a long time, I have reverted it. I still don't totally understand how it works, though. There is more to come!

MissValeska 9 years ago
parent
commit
704b7ebd76
7 changed files with 97 additions and 11 deletions
  1. 7
    0
      src/andns.c
  2. 4
    0
      src/dns_wrapper.c
  3. 1
    1
      src/getaddrinfodnstest.c
  4. 12
    7
      src/netsplit.c
  5. 58
    0
      src/netsplit.h
  6. 10
    3
      src/netsukuku.c
  7. 5
    0
      src/netsukuku.h

+ 7
- 0
src/andns.c View File

@@ -31,6 +31,8 @@
31 31
 #include "andns_net.h"
32 32
 #include "andns_snsd.h"
33 33
 #include "dnslib.h"
34
+#include "netsplit.h"
35
+#include "netsukuku.h"
34 36
 
35 37
 
36 38
 static uint8_t _dns_forwarding_;
@@ -950,6 +952,11 @@ andns_rslv(char *msg, int msglen, char *answer, int *answ_len)
950 952
 	dns_pkt *dp;
951 953
 	andns_pkt *ap;
952 954
 
955
+        printf("andns_rslv msg %s answer %s", msg, answer);
956
+        
957
+        if(netsplit.netsplit_inet_mode == 1)
958
+        inet_mode (msg);
959
+        
953 960
 	proto = GET_NK_BIT(msg);
954 961
 	if (proto == NK_DNS)
955 962
 		res = d_u(msg, msglen, &dp);

+ 4
- 0
src/dns_wrapper.c View File

@@ -71,6 +71,8 @@ dns_exec_pkt(void *passed_argv)
71 71
 		return 0;
72 72
 	}
73 73
 
74
+        printf("dns_exec_pkt buf: %s rpkt %s", buf, argv.rpkt);
75
+        
74 76
 	/* Unpack the DNS query and resolve the hostname */
75 77
 	if (!andns_rslv(buf, argv.rpkt_sz, answer_buffer, &answer_length))
76 78
 		return 0;
@@ -166,6 +168,8 @@ dns_wrapper_daemon(u_short port)
166 168
 		exec_pkt_argv.rpkt_sz = err;
167 169
 		exec_pkt_argv.rpkt = buf;
168 170
 
171
+                printf("dns_wrapper_daemon buf: %s rpkt %s", buf, exec_pkt_argv.rpkt);
172
+                
169 173
 		pthread_mutex_lock(&dns_exec_lock);
170 174
 		pthread_create(&thread, &t_attr, dns_exec_pkt,
171 175
 					   (void *) &exec_pkt_argv);

+ 1
- 1
src/getaddrinfodnstest.c View File

@@ -22,7 +22,7 @@ getaddrinfodnsresolution(char *domain)
22 22
 	hints.ai_socktype = SOCK_DGRAM;  /* Dummy socket type */
23 23
 
24 24
 	/*
25
-	 * Use getaddrinfo() to resolve "www.kame.net" and allocate
25
+	 * Use getaddrinfo() to resolve domain and allocate
26 26
 	 * a linked list of addresses.
27 27
 	 */
28 28
 	error = getaddrinfo(domain, NULL, &hints, &res0);

+ 12
- 7
src/netsplit.c View File

@@ -95,7 +95,7 @@ inet_mode (char *domain)
95 95
 
96 96
   if (ret1 != NULL)
97 97
     {
98
-      new_domain[strlen (new_domain) - 6] = '\0';
98
+      new_domain[strlen (new_domain) - 5] = '\0';
99 99
       printf ("inet_mode abbrevate: %s\n", new_domain);
100 100
     }
101 101
 
@@ -109,6 +109,7 @@ inet_mode (char *domain)
109 109
       if (rt_value == 0)
110 110
 	inetDNSResolution (new_domain);
111 111
       printf ("inet_mode normal\n");
112
+      return;
112 113
     }
113 114
 
114 115
   ret = strstr (new_domain, ".ntk");
@@ -116,7 +117,7 @@ inet_mode (char *domain)
116 117
   if (ret != NULL)
117 118
     {
118 119
     inet_mode_ntk_rslv:
119
-      new_domain[strlen (new_domain) - 5] = '\0';
120
+      new_domain[strlen (new_domain) - 4] = '\0';
120 121
       rt_value = isValidIpv4Address (new_domain);
121 122
       if (rt_value == AF_INET)
122 123
 	ntkipForwarding (new_domain, AF_INET);
@@ -125,8 +126,11 @@ inet_mode (char *domain)
125 126
       if (rt_value == 0)
126 127
 	ntkDNSResolution (new_domain);
127 128
       printf ("inet_mode abnormal\n");
129
+      return;
128 130
     }
129 131
 
132
+  return;
133
+  
130 134
 }
131 135
 
132 136
 void
@@ -155,7 +159,7 @@ ntk_mode (char *domain)
155 159
 
156 160
   if (ret1 != NULL)
157 161
     {
158
-      new_domain[strlen (new_domain) - 5] = '\0';
162
+      new_domain[strlen (new_domain) - 4] = '\0';
159 163
       printf ("ntk_mode abbrevate: %s\n", new_domain);
160 164
     }
161 165
 
@@ -176,7 +180,7 @@ ntk_mode (char *domain)
176 180
   if (ret != NULL)
177 181
     {
178 182
     ntk_mode_inet_rslv:
179
-      new_domain[strlen (new_domain) - 6] = '\0';
183
+      new_domain[strlen (new_domain) - 5] = '\0';
180 184
       rt_value = isValidIpv4Address (new_domain);
181 185
       if (rt_value == AF_INET)
182 186
 	inetipForwarding (new_domain, AF_INET);
@@ -189,7 +193,7 @@ ntk_mode (char *domain)
189 193
 
190 194
 }
191 195
 
192
-void
196
+/*void
193 197
 domain_ip_processing (char *domain)
194 198
 {
195 199
   char *ret;
@@ -245,9 +249,10 @@ main (void)
245 249
       if (strcmp (request, "quit\n") == 0 || strcmp (request, "exit\n") == 0)
246 250
 	exit (0);
247 251
       fflush (stdin);
248
-      domain_ip_processing (request);
252
+      *strrchr(request, '\n') = '\0';
253
+      inet_mode (request);
249 254
       free (request);
250 255
     }
251 256
 
252 257
   return 0;
253
-}
258
+}*/

+ 58
- 0
src/netsplit.h View File

@@ -0,0 +1,58 @@
1
+/* 
2
+ * File:   netsplit.h
3
+ * Author: missvaleska
4
+ *
5
+ * Created on November 6, 2014, 6:44 PM
6
+ */
7
+
8
+#ifndef NETSPLIT_H
9
+#define	NETSPLIT_H
10
+
11
+#include "netsplit.c"
12
+
13
+#ifdef	__cplusplus
14
+extern "C" {
15
+#endif
16
+
17
+int
18
+isValidIpv6Address (char *ipAddress);
19
+
20
+int
21
+isValidIpv4Address (char *ipAddress);
22
+
23
+/* Forwards packets to this IP through the inet 
24
+ * iptables forwarding rule. */
25
+void
26
+inetipForwarding (char *ipAddress, int family);
27
+
28
+/* Forwards packets to this IP through the ntk 
29
+ * iptables forwarding rule. */
30
+void
31
+ntkipForwarding (char *ipAddress, int family);
32
+
33
+/* Resolves the ntk domain name in ANDNA, 
34
+ * Forwarding the originally desired packets
35
+ * through the ntk iptables forwarding rule. */
36
+void
37
+ntkDNSResolution (char *domain);
38
+
39
+/* Resolves the inet domain name via the commented out name servers
40
+ * in /etc/resolv.conf, Forwarding the dns query packets
41
+ * through the inet iptables forwarding rule.
42
+ * Then, Forwards the originally desired packets
43
+ * through the inet iptables forwarding rule. */
44
+void
45
+inetDNSResolution (char *domain);
46
+
47
+void
48
+inet_mode (char *domain);
49
+
50
+void
51
+ntk_mode (char *domain);
52
+
53
+#ifdef	__cplusplus
54
+}
55
+#endif
56
+
57
+#endif	/* NETSPLIT_H */
58
+

+ 10
- 3
src/netsukuku.c View File

@@ -181,7 +181,7 @@ usage(void)
181 181
 		   " -k     Kills the running instance of ntkd\n"
182 182
 		   " -C	Runs the console server for Ntk-Console to connect to\n"
183 183
 		   " -e     Excludes an interface from usage I.E all interfaces except this one\n"
184
-                   " -n     Experimental, Currently meaningless argument to implement ntk netsplit\n        http://netsukuku.freaknet.org/docs/main_doc/ntk_rfc/Ntk_net_split\n");
184
+                   " -n     Experimental argument to implement ntk netsplit\n        http://netsukuku.freaknet.org/docs/main_doc/ntk_rfc/Ntk_net_split\n");
185 185
 }
186 186
 
187 187
 /*
@@ -430,14 +430,17 @@ parse_options(int argc, char **argv)
430 430
 			{0, 0, 0, 0}
431 431
 		};
432 432
 
433
-		c = getopt_long(argc, argv, "i:c:l:e:hvd64DRrIakC", long_options,
433
+		c = getopt_long(argc, argv, "i:c:l:e:hvd64DRrIakCn", long_options,
434 434
 						&option_index);
435 435
 		if (c == -1)
436 436
 			break;
437 437
 
438 438
 		switch (c) {
439 439
                 case 'n':
440
-                    
440
+                    if(strcmp("inet", optarg) == 0 || strcmp("INET", optarg) == 0)
441
+                        netsplit.netsplit_inet_mode = 1;
442
+                    if(strcmp("ntk", optarg) == 0 || strcmp("NTK", optarg) == 0)
443
+                        netsplit.netsplit_ntk_mode = 1;
441 444
                     break;
442 445
 		case 'C':
443 446
 			ntk_thread_creatation();
@@ -492,6 +495,10 @@ parse_options(int argc, char **argv)
492 495
 				fatal(0);
493 496
 			break;
494 497
 		case 'i':
498
+                    	if(server_opt.ifs_n+1 >= MAX_INTERFACES)
499
+                            fatal("The maximum number of interfaces is %d",
500
+							MAX_INTERFACES);
501
+			server_opt.ifs[server_opt.ifs_n++]=xstrndup(optarg, IFNAMSIZ-1);
495 502
 			break;
496 503
 		case 'D':
497 504
 			server_opt.daemon = 0;

+ 5
- 0
src/netsukuku.h View File

@@ -29,6 +29,11 @@
29 29
 #define VERSION_STR				"NetsukukuD "VERSION" (debug)"
30 30
 #endif
31 31
 
32
+struct {
33
+        int netsplit_inet_mode;
34
+        int netsplit_ntk_mode;
35
+} netsplit;
36
+
32 37
 /*
33 38
  * current_globals
34 39
  *

Loading…
Cancel
Save