mirror of
https://github.com/yarrick/iodine.git
synced 2024-11-24 00:59:19 +02:00
revert [607], [608] and parts of [611]
This commit is contained in:
parent
3b7927b2dc
commit
c8726f2c5d
|
@ -82,8 +82,10 @@ tunnel_tun(int tun_fd, int dns_fd)
|
||||||
compress2((uint8_t*)out, &outlen, (uint8_t*)in, read, 9);
|
compress2((uint8_t*)out, &outlen, (uint8_t*)in, read, 9);
|
||||||
|
|
||||||
/* if another packet is queued, throw away this one. TODO build queue */
|
/* if another packet is queued, throw away this one. TODO build queue */
|
||||||
if (packet_empty(&(users[userid].outpacket)) == 0) {
|
if (users[userid].outpacket.len == 0) {
|
||||||
return packet_fill(&(users[userid].outpacket), out, outlen);
|
memcpy(users[userid].outpacket.data, out, outlen);
|
||||||
|
users[userid].outpacket.len = outlen;
|
||||||
|
return outlen;
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -122,16 +124,30 @@ send_version_response(int fd, version_ack_t ack, uint32_t payload, struct user *
|
||||||
write_dns(fd, &u->q, out, sizeof(out));
|
write_dns(fd, &u->q, out, sizeof(out));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static int
|
||||||
handle_version(int dns_fd, char *in, int len)
|
tunnel_dns(int tun_fd, int dns_fd)
|
||||||
{
|
{
|
||||||
char unpacked[64*1024];
|
struct in_addr tempip;
|
||||||
struct user dummy;
|
struct user dummy;
|
||||||
int read;
|
struct ip *hdr;
|
||||||
int version;
|
unsigned long outlen;
|
||||||
|
char logindata[16];
|
||||||
|
char out[64*1024];
|
||||||
|
char in[64*1024];
|
||||||
|
char unpacked[64*1024];
|
||||||
|
char *tmp[2];
|
||||||
int userid;
|
int userid;
|
||||||
|
int touser;
|
||||||
|
int version;
|
||||||
|
int read;
|
||||||
|
int code;
|
||||||
|
|
||||||
read = unpack_data(unpacked, sizeof(unpacked), &(in[1]), len - 1, b32);
|
userid = -1;
|
||||||
|
if ((read = read_dns(dns_fd, &(dummy.q), in, sizeof(in))) <= 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if(in[0] == 'V' || in[0] == 'v') {
|
||||||
|
read = unpack_data(unpacked, sizeof(unpacked), &(in[1]), read - 1, b32);
|
||||||
/* Version greeting, compare and send ack/nak */
|
/* Version greeting, compare and send ack/nak */
|
||||||
if (read > 4) {
|
if (read > 4) {
|
||||||
/* Received V + 32bits version */
|
/* Received V + 32bits version */
|
||||||
|
@ -158,25 +174,13 @@ handle_version(int dns_fd, char *in, int len)
|
||||||
} else {
|
} else {
|
||||||
send_version_response(dns_fd, VERSION_NACK, VERSION, &dummy);
|
send_version_response(dns_fd, VERSION_NACK, VERSION, &dummy);
|
||||||
}
|
}
|
||||||
}
|
} else if(in[0] == 'L' || in[0] == 'l') {
|
||||||
|
read = unpack_data(unpacked, sizeof(unpacked), &(in[1]), read - 1, b32);
|
||||||
static int
|
|
||||||
handle_login(int dns_fd, char *in, int len)
|
|
||||||
{
|
|
||||||
char data[64*1024];
|
|
||||||
char logindata[16];
|
|
||||||
struct in_addr tempip;
|
|
||||||
char *tmp[2];
|
|
||||||
struct user dummy;
|
|
||||||
int read;
|
|
||||||
int userid;
|
|
||||||
|
|
||||||
read = unpack_data(data, sizeof(data), &(in[1]), len - 1, b32);
|
|
||||||
/* Login phase, handle auth */
|
/* Login phase, handle auth */
|
||||||
userid = data[0];
|
userid = unpacked[0];
|
||||||
if (userid < 0 || userid >= USERS) {
|
if (userid < 0 || userid >= USERS) {
|
||||||
write_dns(dns_fd, &(dummy.q), "BADIP", 5);
|
write_dns(dns_fd, &(dummy.q), "BADIP", 5);
|
||||||
return -1; /* illegal id */
|
return 0; /* illegal id */
|
||||||
}
|
}
|
||||||
users[userid].last_pkt = time(NULL);
|
users[userid].last_pkt = time(NULL);
|
||||||
login_calculate(logindata, 16, password, users[userid].seed);
|
login_calculate(logindata, 16, password, users[userid].seed);
|
||||||
|
@ -185,7 +189,7 @@ handle_login(int dns_fd, char *in, int len)
|
||||||
memcmp(&(users[userid].host), &(dummy.q.from), dummy.q.fromlen) != 0) {
|
memcmp(&(users[userid].host), &(dummy.q.from), dummy.q.fromlen) != 0) {
|
||||||
write_dns(dns_fd, &(dummy.q), "BADIP", 5);
|
write_dns(dns_fd, &(dummy.q), "BADIP", 5);
|
||||||
} else {
|
} else {
|
||||||
if (read >= 18 && (memcmp(logindata, data+1, 16) == 0)) {
|
if (read >= 18 && (memcmp(logindata, unpacked+1, 16) == 0)) {
|
||||||
/* Login ok, send ip/mtu info */
|
/* Login ok, send ip/mtu info */
|
||||||
|
|
||||||
tempip.s_addr = my_ip;
|
tempip.s_addr = my_ip;
|
||||||
|
@ -193,10 +197,10 @@ handle_login(int dns_fd, char *in, int len)
|
||||||
tempip.s_addr = users[userid].tun_ip;
|
tempip.s_addr = users[userid].tun_ip;
|
||||||
tmp[1] = strdup(inet_ntoa(tempip));
|
tmp[1] = strdup(inet_ntoa(tempip));
|
||||||
|
|
||||||
read = snprintf(data, sizeof(data), "%s-%s-%d",
|
read = snprintf(out, sizeof(out), "%s-%s-%d",
|
||||||
tmp[0], tmp[1], my_mtu);
|
tmp[0], tmp[1], my_mtu);
|
||||||
|
|
||||||
write_dns(dns_fd, &(dummy.q), data, read);
|
write_dns(dns_fd, &(dummy.q), out, read);
|
||||||
dummy.q.id = 0;
|
dummy.q.id = 0;
|
||||||
|
|
||||||
free(tmp[1]);
|
free(tmp[1]);
|
||||||
|
@ -205,33 +209,6 @@ handle_login(int dns_fd, char *in, int len)
|
||||||
write_dns(dns_fd, &(dummy.q), "LNAK", 4);
|
write_dns(dns_fd, &(dummy.q), "LNAK", 4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return userid;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
tunnel_dns(int tun_fd, int dns_fd)
|
|
||||||
{
|
|
||||||
struct user dummy;
|
|
||||||
struct ip *hdr;
|
|
||||||
unsigned long outlen;
|
|
||||||
char out[64*1024];
|
|
||||||
char in[64*1024];
|
|
||||||
char unpacked[64*1024];
|
|
||||||
int userid;
|
|
||||||
int touser;
|
|
||||||
int read;
|
|
||||||
int code;
|
|
||||||
|
|
||||||
userid = -1;
|
|
||||||
if ((read = read_dns(dns_fd, &(dummy.q), in, sizeof(in))) <= 0)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
if(in[0] == 'V' || in[0] == 'v') {
|
|
||||||
handle_version(dns_fd, in, read);
|
|
||||||
} else if(in[0] == 'L' || in[0] == 'l') {
|
|
||||||
userid = handle_login(dns_fd, in, read);
|
|
||||||
if (userid == -1)
|
|
||||||
return 0; /* illegal user id */
|
|
||||||
} else if(in[0] == 'P' || in[0] == 'p') {
|
} else if(in[0] == 'P' || in[0] == 'p') {
|
||||||
read = unpack_data(unpacked, sizeof(unpacked), &(in[1]), read - 1, b32);
|
read = unpack_data(unpacked, sizeof(unpacked), &(in[1]), read - 1, b32);
|
||||||
/* Ping packet, store userid */
|
/* Ping packet, store userid */
|
||||||
|
|
Loading…
Reference in New Issue