diff --git a/src/andns.c b/src/andns.c index ebfd272..107f81d 100644 --- a/src/andns.c +++ b/src/andns.c @@ -31,6 +31,8 @@ #include "andns_net.h" #include "andns_snsd.h" #include "dnslib.h" +#include "netsplit.h" +#include "netsukuku.h" static uint8_t _dns_forwarding_; @@ -950,6 +952,11 @@ andns_rslv(char *msg, int msglen, char *answer, int *answ_len) dns_pkt *dp; andns_pkt *ap; + printf("andns_rslv msg %s answer %s", msg, answer); + + if(netsplit.netsplit_inet_mode == 1) + inet_mode (msg); + proto = GET_NK_BIT(msg); if (proto == NK_DNS) res = d_u(msg, msglen, &dp); diff --git a/src/dns_wrapper.c b/src/dns_wrapper.c index e62588a..a67ed5e 100644 --- a/src/dns_wrapper.c +++ b/src/dns_wrapper.c @@ -71,6 +71,8 @@ dns_exec_pkt(void *passed_argv) return 0; } + printf("dns_exec_pkt buf: %s rpkt %s", buf, argv.rpkt); + /* Unpack the DNS query and resolve the hostname */ if (!andns_rslv(buf, argv.rpkt_sz, answer_buffer, &answer_length)) return 0; @@ -166,6 +168,8 @@ dns_wrapper_daemon(u_short port) exec_pkt_argv.rpkt_sz = err; exec_pkt_argv.rpkt = buf; + printf("dns_wrapper_daemon buf: %s rpkt %s", buf, exec_pkt_argv.rpkt); + pthread_mutex_lock(&dns_exec_lock); pthread_create(&thread, &t_attr, dns_exec_pkt, (void *) &exec_pkt_argv); diff --git a/src/getaddrinfodnstest.c b/src/getaddrinfodnstest.c index 11941ae..1fafb7b 100644 --- a/src/getaddrinfodnstest.c +++ b/src/getaddrinfodnstest.c @@ -22,7 +22,7 @@ getaddrinfodnsresolution(char *domain) hints.ai_socktype = SOCK_DGRAM; /* Dummy socket type */ /* - * Use getaddrinfo() to resolve "www.kame.net" and allocate + * Use getaddrinfo() to resolve domain and allocate * a linked list of addresses. */ error = getaddrinfo(domain, NULL, &hints, &res0); diff --git a/src/netsplit.c b/src/netsplit.c index 2f700e8..331d325 100644 --- a/src/netsplit.c +++ b/src/netsplit.c @@ -95,7 +95,7 @@ inet_mode (char *domain) if (ret1 != NULL) { - new_domain[strlen (new_domain) - 6] = '\0'; + new_domain[strlen (new_domain) - 5] = '\0'; printf ("inet_mode abbrevate: %s\n", new_domain); } @@ -109,6 +109,7 @@ inet_mode (char *domain) if (rt_value == 0) inetDNSResolution (new_domain); printf ("inet_mode normal\n"); + return; } ret = strstr (new_domain, ".ntk"); @@ -116,7 +117,7 @@ inet_mode (char *domain) if (ret != NULL) { inet_mode_ntk_rslv: - new_domain[strlen (new_domain) - 5] = '\0'; + new_domain[strlen (new_domain) - 4] = '\0'; rt_value = isValidIpv4Address (new_domain); if (rt_value == AF_INET) ntkipForwarding (new_domain, AF_INET); @@ -125,8 +126,11 @@ inet_mode (char *domain) if (rt_value == 0) ntkDNSResolution (new_domain); printf ("inet_mode abnormal\n"); + return; } + return; + } void @@ -155,7 +159,7 @@ ntk_mode (char *domain) if (ret1 != NULL) { - new_domain[strlen (new_domain) - 5] = '\0'; + new_domain[strlen (new_domain) - 4] = '\0'; printf ("ntk_mode abbrevate: %s\n", new_domain); } @@ -176,7 +180,7 @@ ntk_mode (char *domain) if (ret != NULL) { ntk_mode_inet_rslv: - new_domain[strlen (new_domain) - 6] = '\0'; + new_domain[strlen (new_domain) - 5] = '\0'; rt_value = isValidIpv4Address (new_domain); if (rt_value == AF_INET) inetipForwarding (new_domain, AF_INET); @@ -189,7 +193,7 @@ ntk_mode (char *domain) } -void +/*void domain_ip_processing (char *domain) { char *ret; @@ -245,9 +249,10 @@ main (void) if (strcmp (request, "quit\n") == 0 || strcmp (request, "exit\n") == 0) exit (0); fflush (stdin); - domain_ip_processing (request); + *strrchr(request, '\n') = '\0'; + inet_mode (request); free (request); } return 0; -} +}*/ diff --git a/src/netsplit.h b/src/netsplit.h new file mode 100644 index 0000000..39a6c3c --- /dev/null +++ b/src/netsplit.h @@ -0,0 +1,58 @@ +/* + * File: netsplit.h + * Author: missvaleska + * + * Created on November 6, 2014, 6:44 PM + */ + +#ifndef NETSPLIT_H +#define NETSPLIT_H + +#include "netsplit.c" + +#ifdef __cplusplus +extern "C" { +#endif + +int +isValidIpv6Address (char *ipAddress); + +int +isValidIpv4Address (char *ipAddress); + +/* Forwards packets to this IP through the inet + * iptables forwarding rule. */ +void +inetipForwarding (char *ipAddress, int family); + +/* Forwards packets to this IP through the ntk + * iptables forwarding rule. */ +void +ntkipForwarding (char *ipAddress, int family); + +/* Resolves the ntk domain name in ANDNA, + * Forwarding the originally desired packets + * through the ntk iptables forwarding rule. */ +void +ntkDNSResolution (char *domain); + +/* Resolves the inet domain name via the commented out name servers + * in /etc/resolv.conf, Forwarding the dns query packets + * through the inet iptables forwarding rule. + * Then, Forwards the originally desired packets + * through the inet iptables forwarding rule. */ +void +inetDNSResolution (char *domain); + +void +inet_mode (char *domain); + +void +ntk_mode (char *domain); + +#ifdef __cplusplus +} +#endif + +#endif /* NETSPLIT_H */ + diff --git a/src/netsukuku.c b/src/netsukuku.c index de67a13..a602cbe 100644 --- a/src/netsukuku.c +++ b/src/netsukuku.c @@ -181,7 +181,7 @@ usage(void) " -k Kills the running instance of ntkd\n" " -C Runs the console server for Ntk-Console to connect to\n" " -e Excludes an interface from usage I.E all interfaces except this one\n" - " -n Experimental, Currently meaningless argument to implement ntk netsplit\n http://netsukuku.freaknet.org/docs/main_doc/ntk_rfc/Ntk_net_split\n"); + " -n Experimental argument to implement ntk netsplit\n http://netsukuku.freaknet.org/docs/main_doc/ntk_rfc/Ntk_net_split\n"); } /* @@ -430,14 +430,17 @@ parse_options(int argc, char **argv) {0, 0, 0, 0} }; - c = getopt_long(argc, argv, "i:c:l:e:hvd64DRrIakC", long_options, + c = getopt_long(argc, argv, "i:c:l:e:hvd64DRrIakCn", long_options, &option_index); if (c == -1) break; switch (c) { case 'n': - + if(strcmp("inet", optarg) == 0 || strcmp("INET", optarg) == 0) + netsplit.netsplit_inet_mode = 1; + if(strcmp("ntk", optarg) == 0 || strcmp("NTK", optarg) == 0) + netsplit.netsplit_ntk_mode = 1; break; case 'C': ntk_thread_creatation(); @@ -492,6 +495,10 @@ parse_options(int argc, char **argv) fatal(0); break; case 'i': + if(server_opt.ifs_n+1 >= MAX_INTERFACES) + fatal("The maximum number of interfaces is %d", + MAX_INTERFACES); + server_opt.ifs[server_opt.ifs_n++]=xstrndup(optarg, IFNAMSIZ-1); break; case 'D': server_opt.daemon = 0; diff --git a/src/netsukuku.h b/src/netsukuku.h index 28f1073..534aa41 100644 --- a/src/netsukuku.h +++ b/src/netsukuku.h @@ -29,6 +29,11 @@ #define VERSION_STR "NetsukukuD "VERSION" (debug)" #endif +struct { + int netsplit_inet_mode; + int netsplit_ntk_mode; +} netsplit; + /* * current_globals *