From 6864263aac3d84ad033e36778211ef9c2caacf92 Mon Sep 17 00:00:00 2001 From: Bjorn Andersson Date: Sun, 11 Jun 2006 17:23:26 +0000 Subject: [PATCH] Give ip and mtu to client --- dns.c | 32 ++++++++++++++++++-------------- dns.h | 2 ++ iodined.c | 10 +++++++--- 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/dns.c b/dns.c index 1861d06..2039528 100644 --- a/dns.c +++ b/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; } } diff --git a/dns.h b/dns.h index 781d585..16b58cb 100644 --- a/dns.h +++ b/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); diff --git a/iodined.c b/iodined.c index 8a1710f..9951fef 100644 --- a/iodined.c +++ b/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);