mirror of
https://github.com/yarrick/iodine.git
synced 2024-11-26 01:59:19 +02:00
revert [607], [608] and parts of [611]
This commit is contained in:
parent
468844b0a9
commit
a114ab3ff9
|
@ -82,8 +82,10 @@ tunnel_tun(int tun_fd, int dns_fd)
|
|||
compress2((uint8_t*)out, &outlen, (uint8_t*)in, read, 9);
|
||||
|
||||
/* if another packet is queued, throw away this one. TODO build queue */
|
||||
if (packet_empty(&(users[userid].outpacket)) == 0) {
|
||||
return packet_fill(&(users[userid].outpacket), out, outlen);
|
||||
if (users[userid].outpacket.len == 0) {
|
||||
memcpy(users[userid].outpacket.data, out, outlen);
|
||||
users[userid].outpacket.len = outlen;
|
||||
return outlen;
|
||||
} else {
|
||||
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));
|
||||
}
|
||||
|
||||
static void
|
||||
handle_version(int dns_fd, char *in, int len)
|
||||
static int
|
||||
tunnel_dns(int tun_fd, int dns_fd)
|
||||
{
|
||||
char unpacked[64*1024];
|
||||
struct in_addr tempip;
|
||||
struct user dummy;
|
||||
int read;
|
||||
int version;
|
||||
struct ip *hdr;
|
||||
unsigned long outlen;
|
||||
char logindata[16];
|
||||
char out[64*1024];
|
||||
char in[64*1024];
|
||||
char unpacked[64*1024];
|
||||
char *tmp[2];
|
||||
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 */
|
||||
if (read > 4) {
|
||||
/* Received V + 32bits version */
|
||||
|
@ -158,25 +174,13 @@ handle_version(int dns_fd, char *in, int len)
|
|||
} else {
|
||||
send_version_response(dns_fd, VERSION_NACK, VERSION, &dummy);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
} else if(in[0] == 'L' || in[0] == 'l') {
|
||||
read = unpack_data(unpacked, sizeof(unpacked), &(in[1]), read - 1, b32);
|
||||
/* Login phase, handle auth */
|
||||
userid = data[0];
|
||||
userid = unpacked[0];
|
||||
if (userid < 0 || userid >= USERS) {
|
||||
write_dns(dns_fd, &(dummy.q), "BADIP", 5);
|
||||
return -1; /* illegal id */
|
||||
return 0; /* illegal id */
|
||||
}
|
||||
users[userid].last_pkt = time(NULL);
|
||||
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) {
|
||||
write_dns(dns_fd, &(dummy.q), "BADIP", 5);
|
||||
} 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 */
|
||||
|
||||
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;
|
||||
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);
|
||||
|
||||
write_dns(dns_fd, &(dummy.q), data, read);
|
||||
write_dns(dns_fd, &(dummy.q), out, read);
|
||||
dummy.q.id = 0;
|
||||
|
||||
free(tmp[1]);
|
||||
|
@ -205,33 +209,6 @@ handle_login(int dns_fd, char *in, int len)
|
|||
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') {
|
||||
read = unpack_data(unpacked, sizeof(unpacked), &(in[1]), read - 1, b32);
|
||||
/* Ping packet, store userid */
|
||||
|
|
Loading…
Reference in New Issue