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!

This commit is contained in:
MissValeska 2014-11-06 19:17:14 -08:00
parent 8c39cf1d98
commit 704b7ebd76
7 changed files with 97 additions and 11 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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;
}
}*/

58
src/netsplit.h Normal file
View File

@ -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 */

View File

@ -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;

View File

@ -29,6 +29,11 @@
#define VERSION_STR "NetsukukuD "VERSION" (debug)"
#endif
struct {
int netsplit_inet_mode;
int netsplit_ntk_mode;
} netsplit;
/*
* current_globals
*