From 5ef46f40537339fe5b171015a1bb08db530129f7 Mon Sep 17 00:00:00 2001 From: Julian Kranz Date: Sun, 1 Jan 2012 19:26:24 +0100 Subject: [PATCH] --- --- src/common.c | 8 ++++++++ src/common.h | 1 + src/iodined.c | 36 ++++++++++++++++++++++++++---------- src/user.c | 20 ++++++++++++++++++++ src/user.h | 1 + 5 files changed, 56 insertions(+), 10 deletions(-) diff --git a/src/common.c b/src/common.c index 845bd28..d6f92f9 100644 --- a/src/common.c +++ b/src/common.c @@ -365,3 +365,11 @@ void inet6_addr_add(struct in6_addr *addr, uint8_t amount) { break; } } + +char inet6_addr_equals(struct in6_addr *a, struct in6_addr *b) { + char i; + for (i = 4; i >= 0; --i) + if(a->__in6_u.__u6_addr32[i] != b->__in6_u.__u6_addr32[i]) + return 0; + return 1; +} diff --git a/src/common.h b/src/common.h index 3bf38f7..2bfaf7d 100644 --- a/src/common.h +++ b/src/common.h @@ -134,5 +134,6 @@ void warnx(const char *fmt, ...); int recent_seqno(int , int); void inet6_addr_add(struct in6_addr *addr, uint8_t amount); +char inet6_addr_equals(struct in6_addr *a, struct in6_addr *b); #endif diff --git a/src/iodined.c b/src/iodined.c index b470b1e..914a89d 100644 --- a/src/iodined.c +++ b/src/iodined.c @@ -40,6 +40,7 @@ #define _XPG4_2 #include #include +#include #include #include #include @@ -136,7 +137,7 @@ check_user_and_ip(int userid, struct query *q) } /* return early if IP checking is disabled */ - if (!check_ip || 1) { + if (!check_ip) { return 0; } @@ -550,6 +551,7 @@ tunnel_tun(int tun_fd, int dns_fd) { unsigned long outlen; struct ip *header; + struct ip6_hdr *header6; char out[64*1024]; char in[64*1024]; int userid; @@ -558,9 +560,17 @@ tunnel_tun(int tun_fd, int dns_fd) if ((read = read_tun(tun_fd, in, sizeof(in))) <= 0) return 0; - /* find target ip in packet, in is padded with 4 bytes TUN header */ - header = (struct ip*) (in + 4); - userid = find_user_by_ip(header->ip_dst.s_addr); + uint16_t *header_info = (uint16_t*)in; + if(ntohs(header_info[1]) == 0x0008) { + /* find target ip in packet, in is padded with 4 bytes TUN header */ + header = (struct ip*) (in + 4); + 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); + } + if (userid < 0) return 0; @@ -1747,12 +1757,19 @@ handle_full_packet(int tun_fd, int dns_fd, int userid) (uint8_t*)users[userid].inpacket.data, users[userid].inpacket.len); if (ret == Z_OK) { - struct ip *hdr; - hdr = (struct ip*) (out + 4); - touser = find_user_by_ip(hdr->ip_dst.s_addr); + uint16_t *header_info = (uint16_t*)out; + if(ntohs(header_info[1]) == 0x0008) { + struct ip *hdr; - touser = -1; + hdr = (struct ip*) (out + 4); + touser = find_user_by_ip(hdr->ip_dst.s_addr); + } + else { + struct ip6_hdr *hdr; + hdr = (struct ip6_hdr*) (out + 4); + touser = find_user_by_ip6(hdr->ip6_dst); + } if (touser == -1) { /* send the uncompressed packet to tun device */ @@ -1886,8 +1903,7 @@ raw_decode(char *packet, int len, struct query *q, int dns_fd, int tun_fd) /* should start with header */ if (memcmp(packet, raw_header, RAW_HDR_IDENT_LEN)) return 0; - //raw_user = RAW_HDR_GET_USR(packet); - raw_user = 0; + raw_user = RAW_HDR_GET_USR(packet); switch (RAW_HDR_GET_CMD(packet)) { case RAW_HDR_CMD_LOGIN: /* Login challenge */ diff --git a/src/user.c b/src/user.c index 9897e63..74d1cb3 100644 --- a/src/user.c +++ b/src/user.c @@ -135,6 +135,26 @@ find_user_by_ip(uint32_t ip) return ret; } +int +find_user_by_ip6(struct in6_addr ip) +{ + int ret; + int i; + + return 0; + + ret = -1; + for (i = 0; i < usercount; i++) { + if (users[i].active && !users[i].disabled && + users[i].last_pkt + 60 > time(NULL) && + inet6_addr_equals(&ip, &(users[i].tun_ip6))) { + ret = i; + break; + } + } + return ret; +} + int all_users_waiting_to_send() /* If this returns true, then reading from tun device is blocked. diff --git a/src/user.h b/src/user.h index d1cf28c..b5f0f23 100644 --- a/src/user.h +++ b/src/user.h @@ -80,6 +80,7 @@ int init_users(in_addr_t my_ip, int netbits, struct in6_addr my_net6); const char* users_get_first_ip(); int users_waiting_on_reply(); int find_user_by_ip(uint32_t); +int find_user_by_ip6(struct in6_addr ip); int all_users_waiting_to_send(); int find_available_user(); void user_switch_codec(int userid, struct encoder *enc);