Give ip and mtu to client

This commit is contained in:
Bjorn Andersson 2006-06-11 17:23:26 +00:00
parent 03509b9e78
commit 6864263aac
3 changed files with 27 additions and 17 deletions

32
dns.c
View file

@ -55,6 +55,15 @@ short delayed_q_id;
struct sockaddr_in delayed_q_from; struct sockaddr_in delayed_q_from;
int delayed_q_fromlen; int delayed_q_fromlen;
struct packet
{
int len;
int offset;
char data[64*1024];
};
struct packet packetbuf;
int int
open_dns(const char *host, const char *domain) open_dns(const char *host, const char *domain)
{ {
@ -503,13 +512,6 @@ dnsd_forceack(int fd)
delayed_q_id = 0; delayed_q_id = 0;
} }
struct packet
{
int len;
int offset;
char data[64*1024];
};
static int static int
decodepacket(const char *name, struct packet *packet) decodepacket(const char *name, struct packet *packet)
{ {
@ -517,6 +519,7 @@ decodepacket(const char *name, struct packet *packet)
int len; int len;
int last; int last;
int ping; int ping;
int hello;
char *dp; char *dp;
char *domain; char *domain;
const char *np; const char *np;
@ -524,10 +527,11 @@ decodepacket(const char *name, struct packet *packet)
len = 0; len = 0;
last = (name[0] == '1'); last = (name[0] == '1');
ping = (name[0] == 'p' || name[0] == 'P'); ping = (name[0] == 'p' || name[0] == 'P');
hello = (name[0] == 'h' || name[0] == 'H');
domain = strstr(name, topdomain); domain = strstr(name, topdomain);
if (!ping && domain) { if (!ping && !hello && domain) {
np = name + 1; np = name + 1;
dp = packet->data + packet->offset; dp = packet->data + packet->offset;
@ -550,6 +554,8 @@ decodepacket(const char *name, struct packet *packet)
if(last) { if(last) {
len = packet->len; len = packet->len;
packet->len = packet->offset = 0; packet->len = packet->offset = 0;
} else if (hello) {
len = GOTHELLO;
} else { } else {
len = 0; len = 0;
} }
@ -563,8 +569,6 @@ close_dnsd(int fd)
close(fd); close(fd);
} }
struct packet packetbuf;
int int
dnsd_read(int fd, char *buf, int buflen) dnsd_read(int fd, char *buf, int buflen)
{ {
@ -587,20 +591,20 @@ dnsd_read(int fd, char *buf, int buflen)
perror("recvfrom"); perror("recvfrom");
} else { } else {
header = (HEADER*)packet; header = (HEADER*)packet;
id = ntohs(header->id); id = ntohs(header->id);
data = packet + sizeof(HEADER); data = packet + sizeof(HEADER);
if(!header->qr) { if(!header->qr) {
qdcount = ntohs(header->qdcount); qdcount = ntohs(header->qdcount);
if(qdcount == 1) { if(qdcount == 1) {
bzero(name, sizeof(name)); bzero(name, sizeof(name));
READNAME(packet, name, data); READNAME(packet, name, data);
READSHORT(type, data); READSHORT(type, data);
READSHORT(class, data); READSHORT(class, data);
if (dnsd_haspacket()) { if (dnsd_haspacket()) {
dnsd_send(fd, name, type, id, from); dnsd_send(fd, name, type, id, from);
} else { } else {
@ -615,7 +619,7 @@ dnsd_read(int fd, char *buf, int buflen)
r = decodepacket(name, &packetbuf); r = decodepacket(name, &packetbuf);
memcpy(buf, packetbuf.data, r); memcpy(buf, packetbuf.data, r);
return r; return r;
} }
} }

2
dns.h
View file

@ -17,6 +17,8 @@
#ifndef _DNS_H_ #ifndef _DNS_H_
#define _DNS_H_ #define _DNS_H_
#define GOTHELLO -5
int open_dns(const char *, const char *); int open_dns(const char *, const char *);
void close_dns(int); void close_dns(int);

View file

@ -81,7 +81,7 @@ tunnel(int tun_fd, int dns_fd)
} else { } else {
if(FD_ISSET(tun_fd, &fds)) { if(FD_ISSET(tun_fd, &fds)) {
read = read_tun(tun_fd, in, sizeof(in)); read = read_tun(tun_fd, in, sizeof(in));
if (read <= 0) if (read <= 0)
continue; continue;
outlen = sizeof(out); outlen = sizeof(out);
@ -90,8 +90,13 @@ tunnel(int tun_fd, int dns_fd)
} }
if(FD_ISSET(dns_fd, &fds)) { if(FD_ISSET(dns_fd, &fds)) {
read = dnsd_read(dns_fd, in, sizeof(in)); 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; continue;
}
outlen = sizeof(out); outlen = sizeof(out);
uncompress(out, &outlen, in, read); uncompress(out, &outlen, in, read);
@ -208,7 +213,6 @@ main(int argc, char **argv)
if ((dnsd_fd = open_dnsd(argv[1])) == -1) if ((dnsd_fd = open_dnsd(argv[1])) == -1)
goto cleanup2; goto cleanup2;
if (newroot) { if (newroot) {
if (chroot(newroot) != 0 || chdir("/") != 0) if (chroot(newroot) != 0 || chdir("/") != 0)
err(1, "%s", newroot); err(1, "%s", newroot);