mirror of
https://github.com/yarrick/iodine.git
synced 2025-04-11 21:10:56 +00:00
---
This commit is contained in:
parent
5ef46f4053
commit
d0acc7fd34
4 changed files with 28 additions and 17 deletions
11
src/client.c
11
src/client.c
|
@ -42,6 +42,7 @@
|
||||||
#include <grp.h>
|
#include <grp.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
|
#include <netinet/ip.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "common.h"
|
#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;
|
r -= RAW_HDR_LEN;
|
||||||
datalen = sizeof(buf);
|
datalen = sizeof(buf);
|
||||||
if (uncompress((uint8_t*)buf, &datalen, (uint8_t*) &data[RAW_HDR_LEN], r) == Z_OK) {
|
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 */
|
/* don't process any further */
|
||||||
|
@ -1069,7 +1073,10 @@ tunnel_dns(int tun_fd, int dns_fd)
|
||||||
/* RE-USES buf[] */
|
/* RE-USES buf[] */
|
||||||
datalen = sizeof(buf);
|
datalen = sizeof(buf);
|
||||||
if (uncompress((uint8_t*)buf, &datalen, (uint8_t*) inpkt.data, inpkt.len) == Z_OK) {
|
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;
|
inpkt.len = 0;
|
||||||
/* Keep .seqno and .fragment as is, so that we won't
|
/* Keep .seqno and .fragment as is, so that we won't
|
||||||
|
|
|
@ -567,8 +567,8 @@ tunnel_tun(int tun_fd, int dns_fd)
|
||||||
userid = find_user_by_ip(header->ip_dst.s_addr);
|
userid = find_user_by_ip(header->ip_dst.s_addr);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
header = (struct ip6_hdr*) (in + 4);
|
header6 = (struct ip6_hdr*) (in + 4);
|
||||||
userid = find_user_by_ip6(header->ip6_dst);
|
userid = find_user_by_ip6(header6->ip6_dst);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (userid < 0)
|
if (userid < 0)
|
||||||
|
@ -1758,13 +1758,10 @@ handle_full_packet(int tun_fd, int dns_fd, int userid)
|
||||||
|
|
||||||
if (ret == Z_OK) {
|
if (ret == Z_OK) {
|
||||||
|
|
||||||
uint16_t *header_info = (uint16_t*)out;
|
struct ip *hdr;
|
||||||
if(ntohs(header_info[1]) == 0x0008) {
|
hdr = (struct ip*) (out + 4);
|
||||||
struct ip *hdr;
|
if(hdr->ip_v == 0x04)
|
||||||
|
|
||||||
hdr = (struct ip*) (out + 4);
|
|
||||||
touser = find_user_by_ip(hdr->ip_dst.s_addr);
|
touser = find_user_by_ip(hdr->ip_dst.s_addr);
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
struct ip6_hdr *hdr;
|
struct ip6_hdr *hdr;
|
||||||
hdr = (struct ip6_hdr*) (out + 4);
|
hdr = (struct ip6_hdr*) (out + 4);
|
||||||
|
@ -1773,7 +1770,7 @@ handle_full_packet(int tun_fd, int dns_fd, int userid)
|
||||||
|
|
||||||
if (touser == -1) {
|
if (touser == -1) {
|
||||||
/* send the uncompressed packet to tun device */
|
/* send the uncompressed packet to tun device */
|
||||||
write_tun(tun_fd, out, outlen);
|
write_tun(tun_fd, out, outlen, hdr->ip_v);
|
||||||
} else {
|
} else {
|
||||||
/* send the compressed(!) packet to other client */
|
/* send the compressed(!) packet to other client */
|
||||||
/*XXX START adjust indent 1 tab forward*/
|
/*XXX START adjust indent 1 tab forward*/
|
||||||
|
|
17
src/tun.c
17
src/tun.c
|
@ -363,17 +363,24 @@ close_tun(int tun_fd)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
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)
|
#if defined (FREEBSD) || defined (DARWIN) || defined(NETBSD) || defined(WINDOWS32)
|
||||||
data += 4;
|
data += 4;
|
||||||
len -= 4;
|
len -= 4;
|
||||||
#else /* !FREEBSD/DARWIN */
|
#else /* !FREEBSD/DARWIN */
|
||||||
#ifdef LINUX
|
#ifdef LINUX
|
||||||
data[0] = 0x00;
|
if (version == 6) {
|
||||||
data[1] = 0x00;
|
data[0] = 0x00;
|
||||||
data[2] = 0x86;
|
data[1] = 0x00;
|
||||||
data[3] = 0xdd;
|
data[2] = 0x86;
|
||||||
|
data[3] = 0xdd;
|
||||||
|
} else {
|
||||||
|
data[0] = 0x00;
|
||||||
|
data[1] = 0x00;
|
||||||
|
data[2] = 0x08;
|
||||||
|
data[3] = 0x00;
|
||||||
|
}
|
||||||
#else /* OPENBSD */
|
#else /* OPENBSD */
|
||||||
data[0] = 0x00;
|
data[0] = 0x00;
|
||||||
data[1] = 0x00;
|
data[1] = 0x00;
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
int open_tun(const char *);
|
int open_tun(const char *);
|
||||||
void close_tun(int);
|
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);
|
ssize_t read_tun(int, char *, size_t);
|
||||||
int tun_setip(const char *, const char *, int);
|
int tun_setip(const char *, const char *, int);
|
||||||
int tun_setip6(char const *ip6, char netmask6);
|
int tun_setip6(char const *ip6, char netmask6);
|
||||||
|
|
Loading…
Add table
Reference in a new issue