mirror of
https://github.com/yarrick/iodine.git
synced 2024-09-07 03:27:00 +00:00
Give ip and mtu to client
This commit is contained in:
parent
03509b9e78
commit
6864263aac
32
dns.c
32
dns.c
|
@ -55,6 +55,15 @@ short delayed_q_id;
|
|||
struct sockaddr_in delayed_q_from;
|
||||
int delayed_q_fromlen;
|
||||
|
||||
struct packet
|
||||
{
|
||||
int len;
|
||||
int offset;
|
||||
char data[64*1024];
|
||||
};
|
||||
|
||||
struct packet packetbuf;
|
||||
|
||||
int
|
||||
open_dns(const char *host, const char *domain)
|
||||
{
|
||||
|
@ -503,13 +512,6 @@ dnsd_forceack(int fd)
|
|||
delayed_q_id = 0;
|
||||
}
|
||||
|
||||
struct packet
|
||||
{
|
||||
int len;
|
||||
int offset;
|
||||
char data[64*1024];
|
||||
};
|
||||
|
||||
static int
|
||||
decodepacket(const char *name, struct packet *packet)
|
||||
{
|
||||
|
@ -517,6 +519,7 @@ decodepacket(const char *name, struct packet *packet)
|
|||
int len;
|
||||
int last;
|
||||
int ping;
|
||||
int hello;
|
||||
char *dp;
|
||||
char *domain;
|
||||
const char *np;
|
||||
|
@ -524,10 +527,11 @@ decodepacket(const char *name, struct packet *packet)
|
|||
len = 0;
|
||||
last = (name[0] == '1');
|
||||
ping = (name[0] == 'p' || name[0] == 'P');
|
||||
hello = (name[0] == 'h' || name[0] == 'H');
|
||||
|
||||
domain = strstr(name, topdomain);
|
||||
|
||||
if (!ping && domain) {
|
||||
if (!ping && !hello && domain) {
|
||||
np = name + 1;
|
||||
dp = packet->data + packet->offset;
|
||||
|
||||
|
@ -550,6 +554,8 @@ decodepacket(const char *name, struct packet *packet)
|
|||
if(last) {
|
||||
len = packet->len;
|
||||
packet->len = packet->offset = 0;
|
||||
} else if (hello) {
|
||||
len = GOTHELLO;
|
||||
} else {
|
||||
len = 0;
|
||||
}
|
||||
|
@ -563,8 +569,6 @@ close_dnsd(int fd)
|
|||
close(fd);
|
||||
}
|
||||
|
||||
struct packet packetbuf;
|
||||
|
||||
int
|
||||
dnsd_read(int fd, char *buf, int buflen)
|
||||
{
|
||||
|
@ -587,20 +591,20 @@ dnsd_read(int fd, char *buf, int buflen)
|
|||
perror("recvfrom");
|
||||
} else {
|
||||
header = (HEADER*)packet;
|
||||
|
||||
|
||||
id = ntohs(header->id);
|
||||
|
||||
data = packet + sizeof(HEADER);
|
||||
|
||||
if(!header->qr) {
|
||||
qdcount = ntohs(header->qdcount);
|
||||
qdcount = ntohs(header->qdcount);
|
||||
|
||||
if(qdcount == 1) {
|
||||
bzero(name, sizeof(name));
|
||||
READNAME(packet, name, data);
|
||||
READSHORT(type, data);
|
||||
READSHORT(class, data);
|
||||
|
||||
|
||||
if (dnsd_haspacket()) {
|
||||
dnsd_send(fd, name, type, id, from);
|
||||
} else {
|
||||
|
@ -615,7 +619,7 @@ dnsd_read(int fd, char *buf, int buflen)
|
|||
r = decodepacket(name, &packetbuf);
|
||||
|
||||
memcpy(buf, packetbuf.data, r);
|
||||
|
||||
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
|
2
dns.h
2
dns.h
|
@ -17,6 +17,8 @@
|
|||
#ifndef _DNS_H_
|
||||
#define _DNS_H_
|
||||
|
||||
#define GOTHELLO -5
|
||||
|
||||
int open_dns(const char *, const char *);
|
||||
void close_dns(int);
|
||||
|
||||
|
|
10
iodined.c
10
iodined.c
|
@ -81,7 +81,7 @@ tunnel(int tun_fd, int dns_fd)
|
|||
} else {
|
||||
if(FD_ISSET(tun_fd, &fds)) {
|
||||
read = read_tun(tun_fd, in, sizeof(in));
|
||||
if (read <= 0)
|
||||
if (read <= 0)
|
||||
continue;
|
||||
|
||||
outlen = sizeof(out);
|
||||
|
@ -90,8 +90,13 @@ tunnel(int tun_fd, int dns_fd)
|
|||
}
|
||||
if(FD_ISSET(dns_fd, &fds)) {
|
||||
read = dnsd_read(dns_fd, in, sizeof(in));
|
||||
if (read <= 0)
|
||||
if (read <= 0) {
|
||||
if (read == GOTHELLO) {
|
||||
read = snprintf(in, sizeof(in), "%s-%d", "172.30.5.2", 1023);
|
||||
dnsd_queuepacket(in, read);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
outlen = sizeof(out);
|
||||
uncompress(out, &outlen, in, read);
|
||||
|
@ -208,7 +213,6 @@ main(int argc, char **argv)
|
|||
if ((dnsd_fd = open_dnsd(argv[1])) == -1)
|
||||
goto cleanup2;
|
||||
|
||||
|
||||
if (newroot) {
|
||||
if (chroot(newroot) != 0 || chdir("/") != 0)
|
||||
err(1, "%s", newroot);
|
||||
|
|
Loading…
Reference in a new issue