---
This commit is contained in:
parent
168998ec7f
commit
c9d3965a64
19
src/client.c
19
src/client.c
|
@ -158,7 +158,7 @@ client_get_conn()
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
client_set_nameserver(const char *cp, int port)
|
client_set_nameserver(const char *cp, int port)
|
||||||
{
|
{
|
||||||
#ifdef ANDROID
|
#ifdef ANDROID
|
||||||
struct addrinfo hints, *result, *p;
|
struct addrinfo hints, *result, *p;
|
||||||
|
@ -1687,6 +1687,9 @@ handshake_raw_udp(int dns_fd, int seed)
|
||||||
int len;
|
int len;
|
||||||
unsigned remoteaddr = 0;
|
unsigned remoteaddr = 0;
|
||||||
struct in_addr server;
|
struct in_addr server;
|
||||||
|
#ifdef LINUX
|
||||||
|
struct in6_addr server6;
|
||||||
|
#endif
|
||||||
|
|
||||||
fprintf(stderr, "Testing raw UDP data to the server (skip with -r)");
|
fprintf(stderr, "Testing raw UDP data to the server (skip with -r)");
|
||||||
for (i=0; running && i<3 ;i++) {
|
for (i=0; running && i<3 ;i++) {
|
||||||
|
@ -1708,6 +1711,15 @@ handshake_raw_udp(int dns_fd, int seed)
|
||||||
server.s_addr = ntohl(remoteaddr);
|
server.s_addr = ntohl(remoteaddr);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
#ifdef LINUX
|
||||||
|
if (len == 17 && in[0] == 'I') {
|
||||||
|
/* Received IP address */
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < sizeof(struct in6_addr); ++i)
|
||||||
|
server6.__in6_u.__u6_addr8[i] = in[i + 1];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
/*XXX END adjust indent 1 tab back*/
|
/*XXX END adjust indent 1 tab back*/
|
||||||
|
|
||||||
fprintf(stderr, ".");
|
fprintf(stderr, ".");
|
||||||
|
@ -1732,7 +1744,10 @@ handshake_raw_udp(int dns_fd, int seed)
|
||||||
|
|
||||||
raw_serv6.sin6_family = AF_INET6;
|
raw_serv6.sin6_family = AF_INET6;
|
||||||
raw_serv6.sin6_port = htons(53);
|
raw_serv6.sin6_port = htons(53);
|
||||||
inet_pton(AF_INET6, "2001:470:0:473::473", &(raw_serv6.sin6_addr));
|
raw_serv6.sin6_addr = server6;
|
||||||
|
// inet_pton(AF_INET6, "2001:470:0:473::473", &(raw_serv6.sin6_addr));
|
||||||
|
|
||||||
|
ipv6_print(&server6, 00);
|
||||||
|
|
||||||
/* do login against port 53 on remote server
|
/* do login against port 53 on remote server
|
||||||
* based on the old seed. If reply received,
|
* based on the old seed. If reply received,
|
||||||
|
|
|
@ -94,11 +94,10 @@ struct query {
|
||||||
unsigned short type;
|
unsigned short type;
|
||||||
unsigned short rcode;
|
unsigned short rcode;
|
||||||
unsigned short id;
|
unsigned short id;
|
||||||
// union {
|
union {
|
||||||
// struct in_addr v4;
|
struct in_addr v4;
|
||||||
// struct in6_addr v6;
|
struct in6_addr v6;
|
||||||
// } destination;
|
} destination;
|
||||||
struct in_addr destination;
|
|
||||||
union {
|
union {
|
||||||
struct sockaddr v4;
|
struct sockaddr v4;
|
||||||
struct sockaddr_in6 v6;
|
struct sockaddr_in6 v6;
|
||||||
|
|
120
src/iodined.c
120
src/iodined.c
|
@ -873,31 +873,61 @@ handle_null_request(int tun_fd, int dns_fd, struct query *q, int domain_len)
|
||||||
return;
|
return;
|
||||||
} else if(in[0] == 'I' || in[0] == 'i') {
|
} else if(in[0] == 'I' || in[0] == 'i') {
|
||||||
/* Request for IP number */
|
/* Request for IP number */
|
||||||
in_addr_t replyaddr;
|
int i;
|
||||||
unsigned addr;
|
|
||||||
char reply[5];
|
|
||||||
|
|
||||||
userid = b32_8to5(in[1]);
|
#ifdef LINUX
|
||||||
if (check_user_and_ip(userid, q) != 0) {
|
if (v6_listen) {
|
||||||
write_dns(dns_fd, q, "BADIP", 5, 'T');
|
struct in6_addr replyaddr;
|
||||||
return; /* illegal id */
|
char reply[sizeof(struct in6_addr) + 1];
|
||||||
}
|
|
||||||
|
|
||||||
if (ns_ip != INADDR_ANY) {
|
userid = b32_8to5(in[1]);
|
||||||
/* If set, use assigned external ip (-n option) */
|
if (check_user_and_ip(userid, q) != 0) {
|
||||||
replyaddr = ns_ip;
|
write_dns(dns_fd, q, "BADIP", 5, 'T');
|
||||||
|
return; /* illegal id */
|
||||||
|
}
|
||||||
|
|
||||||
|
if (memcmp(&ns_ip6, &in6addr_any, sizeof(struct in6_addr))) {
|
||||||
|
/* If set, use assigned external ip (-n option) */
|
||||||
|
memcpy(&replyaddr, &ns_ip6, sizeof(struct in6_addr));
|
||||||
|
} else {
|
||||||
|
/* otherwise return destination ip from packet */
|
||||||
|
memcpy(&replyaddr, &q->destination.v6, sizeof(struct in6_addr));
|
||||||
|
}
|
||||||
|
|
||||||
|
reply[0] = 'I';
|
||||||
|
for(i = 0; i < sizeof(struct in6_addr); i++)
|
||||||
|
reply[i + 1] = replyaddr.__in6_u.__u6_addr8[i];
|
||||||
|
write_dns(dns_fd, q, reply, sizeof(reply), 'T');
|
||||||
} else {
|
} else {
|
||||||
/* otherwise return destination ip from packet */
|
#endif
|
||||||
memcpy(&replyaddr, &q->destination.s_addr, sizeof(in_addr_t));
|
in_addr_t replyaddr;
|
||||||
}
|
unsigned addr;
|
||||||
|
char reply[5];
|
||||||
|
|
||||||
addr = htonl(replyaddr);
|
userid = b32_8to5(in[1]);
|
||||||
reply[0] = 'I';
|
if (check_user_and_ip(userid, q) != 0) {
|
||||||
reply[1] = (addr >> 24) & 0xFF;
|
write_dns(dns_fd, q, "BADIP", 5, 'T');
|
||||||
reply[2] = (addr >> 16) & 0xFF;
|
return; /* illegal id */
|
||||||
reply[3] = (addr >> 8) & 0xFF;
|
}
|
||||||
reply[4] = (addr >> 0) & 0xFF;
|
|
||||||
write_dns(dns_fd, q, reply, sizeof(reply), 'T');
|
if (ns_ip != INADDR_ANY) {
|
||||||
|
/* If set, use assigned external ip (-n option) */
|
||||||
|
replyaddr = ns_ip;
|
||||||
|
} else {
|
||||||
|
/* otherwise return destination ip from packet */
|
||||||
|
memcpy(&replyaddr, &q->destination.v4.s_addr, sizeof(in_addr_t));
|
||||||
|
}
|
||||||
|
|
||||||
|
addr = htonl(replyaddr);
|
||||||
|
reply[0] = 'I';
|
||||||
|
reply[1] = (addr >> 24) & 0xFF;
|
||||||
|
reply[2] = (addr >> 16) & 0xFF;
|
||||||
|
reply[3] = (addr >> 8) & 0xFF;
|
||||||
|
reply[4] = (addr >> 0) & 0xFF;
|
||||||
|
write_dns(dns_fd, q, reply, sizeof(reply), 'T');
|
||||||
|
#ifdef LINUX
|
||||||
|
}
|
||||||
|
#endif
|
||||||
} else if(in[0] == 'Z' || in[0] == 'z') {
|
} else if(in[0] == 'Z' || in[0] == 'z') {
|
||||||
/* Check for case conservation and chars not allowed according to RFC */
|
/* Check for case conservation and chars not allowed according to RFC */
|
||||||
|
|
||||||
|
@ -1492,10 +1522,16 @@ handle_ns_request(int dns_fd, struct query *q)
|
||||||
char buf[64*1024];
|
char buf[64*1024];
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
|
#ifdef LINUX
|
||||||
|
if (v6_listen) {
|
||||||
|
if(memcmp(&ns_ip6, &in6addr_any, sizeof(struct in6_addr)))
|
||||||
|
memcpy(&q->destination.v6, &ns_ip6, sizeof(struct in6_addr));
|
||||||
|
} else
|
||||||
|
#endif
|
||||||
if (ns_ip != INADDR_ANY) {
|
if (ns_ip != INADDR_ANY) {
|
||||||
/* If ns_ip set, overwrite destination addr with it.
|
/* If ns_ip set, overwrite destination addr with it.
|
||||||
* Destination addr will be sent as additional record (A, IN) */
|
* Destination addr will be sent as additional record (A, IN) */
|
||||||
memcpy(&q->destination.s_addr, &ns_ip, sizeof(in_addr_t));
|
memcpy(&q->destination.v4.s_addr, &ns_ip, sizeof(in_addr_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
len = dns_encode_ns_response(buf, sizeof(buf), q, topdomain);
|
len = dns_encode_ns_response(buf, sizeof(buf), q, topdomain);
|
||||||
|
@ -1522,15 +1558,30 @@ handle_a_request(int dns_fd, struct query *q, int fakeip)
|
||||||
char buf[64*1024];
|
char buf[64*1024];
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
if (fakeip) {
|
#ifdef LINUX
|
||||||
in_addr_t ip = inet_addr("127.0.0.1");
|
if (v6_listen) {
|
||||||
memcpy(&q->destination.s_addr, &ip, sizeof(in_addr_t));
|
if (fakeip)
|
||||||
|
memcpy(&q->destination.v6, &in6addr_loopback, sizeof(in_addr_t));
|
||||||
} else if (ns_ip != INADDR_ANY) {
|
else if (memcmp(&ns_ip6, &in6addr_any, sizeof(struct in6_addr))) {
|
||||||
/* If ns_ip set, overwrite destination addr with it.
|
/* If ns_ip set, overwrite destination addr with it.
|
||||||
* Destination addr will be sent as additional record (A, IN) */
|
* Destination addr will be sent as additional record (A, IN) */
|
||||||
memcpy(&q->destination.s_addr, &ns_ip, sizeof(in_addr_t));
|
memcpy(&q->destination.v4.s_addr, &ns_ip6, sizeof(struct in6_addr));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
else {
|
||||||
|
if (fakeip) {
|
||||||
|
in_addr_t ip = inet_addr("127.0.0.1");
|
||||||
|
memcpy(&q->destination.v4.s_addr, &ip, sizeof(in_addr_t));
|
||||||
|
} else if (ns_ip != INADDR_ANY) {
|
||||||
|
/* If ns_ip set, overwrite destination addr with it.
|
||||||
|
* Destination addr will be sent as additional record (A, IN) */
|
||||||
|
memcpy(&q->destination.v4.s_addr, &ns_ip, sizeof(in_addr_t));
|
||||||
|
}
|
||||||
|
#ifdef LINUX
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
len = dns_encode_a_response(buf, sizeof(buf), q);
|
len = dns_encode_a_response(buf, sizeof(buf), q);
|
||||||
if (len < 1) {
|
if (len < 1) {
|
||||||
|
@ -2051,7 +2102,14 @@ read_dns(int fd, int tun_fd, struct query *q) /* FIXME: tun_fd is because of raw
|
||||||
if (cmsg->cmsg_level == IPPROTO_IP &&
|
if (cmsg->cmsg_level == IPPROTO_IP &&
|
||||||
cmsg->cmsg_type == DSTADDR_SOCKOPT) {
|
cmsg->cmsg_type == DSTADDR_SOCKOPT) {
|
||||||
|
|
||||||
q->destination = *dstaddr(cmsg);
|
q->destination.v4 = *dstaddr(cmsg);
|
||||||
|
break;// printf("write_dns()\n");
|
||||||
|
// ipv6_print(&q->from.v6, 44);
|
||||||
|
}
|
||||||
|
if (cmsg->cmsg_level == IPPROTO_IPV6 &&
|
||||||
|
cmsg->cmsg_type == DSTADDR_SOCKOPT) {
|
||||||
|
|
||||||
|
memcpy(&q->destination.v6, dstaddr(cmsg), sizeof(struct in6_addr));
|
||||||
break;// printf("write_dns()\n");
|
break;// printf("write_dns()\n");
|
||||||
// ipv6_print(&q->from.v6, 44);
|
// ipv6_print(&q->from.v6, 44);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue