diff --git a/src/client.c b/src/client.c index 4663e8b..df09e05 100644 --- a/src/client.c +++ b/src/client.c @@ -42,6 +42,7 @@ #include #include #include +#include #endif #include "common.h" @@ -715,7 +716,10 @@ read_dns_withq(int dns_fd, int tun_fd, char *buf, int buflen, struct query *q) r -= RAW_HDR_LEN; datalen = sizeof(buf); if (uncompress((uint8_t*)buf, &datalen, (uint8_t*) &data[RAW_HDR_LEN], r) == Z_OK) { - write_tun(tun_fd, buf, datalen); + struct ip *hdr; + hdr = (struct ip*) (buf + 4); + + write_tun(tun_fd, buf, datalen, hdr->ip_v); } /* don't process any further */ @@ -1069,7 +1073,10 @@ tunnel_dns(int tun_fd, int dns_fd) /* RE-USES buf[] */ datalen = sizeof(buf); if (uncompress((uint8_t*)buf, &datalen, (uint8_t*) inpkt.data, inpkt.len) == Z_OK) { - write_tun(tun_fd, buf, datalen); + struct ip *hdr; + hdr = (struct ip*) (buf + 4); + + write_tun(tun_fd, buf, datalen, hdr->ip_v); } inpkt.len = 0; /* Keep .seqno and .fragment as is, so that we won't diff --git a/src/iodined.c b/src/iodined.c index 914a89d..0941d32 100644 --- a/src/iodined.c +++ b/src/iodined.c @@ -567,8 +567,8 @@ tunnel_tun(int tun_fd, int dns_fd) userid = find_user_by_ip(header->ip_dst.s_addr); } else { - header = (struct ip6_hdr*) (in + 4); - userid = find_user_by_ip6(header->ip6_dst); + header6 = (struct ip6_hdr*) (in + 4); + userid = find_user_by_ip6(header6->ip6_dst); } if (userid < 0) @@ -1758,13 +1758,10 @@ handle_full_packet(int tun_fd, int dns_fd, int userid) if (ret == Z_OK) { - uint16_t *header_info = (uint16_t*)out; - if(ntohs(header_info[1]) == 0x0008) { - struct ip *hdr; - - hdr = (struct ip*) (out + 4); + struct ip *hdr; + hdr = (struct ip*) (out + 4); + if(hdr->ip_v == 0x04) touser = find_user_by_ip(hdr->ip_dst.s_addr); - } else { struct ip6_hdr *hdr; hdr = (struct ip6_hdr*) (out + 4); @@ -1773,7 +1770,7 @@ handle_full_packet(int tun_fd, int dns_fd, int userid) if (touser == -1) { /* send the uncompressed packet to tun device */ - write_tun(tun_fd, out, outlen); + write_tun(tun_fd, out, outlen, hdr->ip_v); } else { /* send the compressed(!) packet to other client */ /*XXX START adjust indent 1 tab forward*/ diff --git a/src/tun.c b/src/tun.c index 61df3f8..c2dd384 100644 --- a/src/tun.c +++ b/src/tun.c @@ -363,17 +363,24 @@ close_tun(int tun_fd) } int -write_tun(int tun_fd, unsigned char *data, size_t len) +write_tun(int tun_fd, unsigned char *data, size_t len, char version) { #if defined (FREEBSD) || defined (DARWIN) || defined(NETBSD) || defined(WINDOWS32) data += 4; len -= 4; #else /* !FREEBSD/DARWIN */ #ifdef LINUX - data[0] = 0x00; - data[1] = 0x00; - data[2] = 0x86; - data[3] = 0xdd; + if (version == 6) { + data[0] = 0x00; + data[1] = 0x00; + data[2] = 0x86; + data[3] = 0xdd; + } else { + data[0] = 0x00; + data[1] = 0x00; + data[2] = 0x08; + data[3] = 0x00; + } #else /* OPENBSD */ data[0] = 0x00; data[1] = 0x00; diff --git a/src/tun.h b/src/tun.h index e17d216..357b656 100644 --- a/src/tun.h +++ b/src/tun.h @@ -19,7 +19,7 @@ int open_tun(const char *); void close_tun(int); -int write_tun(int, unsigned char *, size_t); +int write_tun(int, unsigned char *, size_t, char version); ssize_t read_tun(int, char *, size_t); int tun_setip(const char *, const char *, int); int tun_setip6(char const *ip6, char netmask6);