1
0
Fork 0
mirror of https://github.com/yarrick/iodine.git synced 2025-04-07 11:07:03 +00:00

Iodine: Cleaned up

This commit is contained in:
Julian Kranz 2012-01-07 02:29:21 +01:00 committed by Barak A. Pearlmutter
parent 1f756d0f12
commit 119c78c253
6 changed files with 39 additions and 1 deletions

View file

@ -1,5 +1,6 @@
/*
* Copyright (c) 2006-2009 Bjorn Andersson <flex@kryo.se>, Erik Ekman <yarrick@kryo.se>
* Copyright (c) 2011-2012 Julian Kranz <julian@juliankranz.de>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@ -68,7 +69,9 @@ static const char *topdomain;
static uint16_t rand_seed;
#ifdef LINUX
static char _v6;
#endif
/* Current up/downstream IP packet */
static struct packet outpkt;
@ -301,11 +304,13 @@ client_set_hostname_maxlen(int i)
hostname_maxlen = i;
}
#ifdef LINUX
void
client_set_v6(char v6)
{
_v6 = v6;
}
#endif
const char *
client_get_raw_addr()
@ -1507,10 +1512,12 @@ handshake_version(int dns_fd, int *seed)
static char handshake_login_info_check(char *in, char *server, char *client,
int *mtu, int *netmask, char *server6, char *client6, int *netmask6) {
#ifdef LINUX
if (_v6)
return sscanf(in, "%64[^-]-%64[^-]-%d-%d-%64[^-]-%64[^-]-%d", server,
client, mtu, netmask, server6, client6, netmask6) == 7;
else
#endif
return sscanf(in, "%64[^-]-%64[^-]-%d-%d", server, client, mtu, netmask)
== 4;
}
@ -1548,23 +1555,31 @@ handshake_login(int dns_fd, int seed)
} else if (handshake_login_info_check(in, server, client, &mtu, &netmask,
server6, client6, &netmask6)) {
#ifdef LINUX
if(_v6 && mtu < 1280) {
fprintf(stderr, "Increasing MTU from %u to 1280 (as needed by IPv6)\n", mtu);
mtu = 1280;
}
#endif
server[64] = 0;
client[64] = 0;
if (tun_setip(client, server, netmask) == 0 &&
tun_setmtu(mtu) == 0 && (!_v6 || !tun_setip6(client6, netmask6))) {
tun_setmtu(mtu) == 0
#ifdef LINUX
&& (!_v6 || !tun_setip6(client6, netmask6))
#endif
) {
fprintf(stderr, "Server tunnel IP is %s\n", server);
#ifdef LINUX
if (_v6) {
fprintf(stderr, "Server tunnel IPv6 is %s\n", server6);
fprintf(stderr, "Client tunnel IPv6 is %s\n", client6);
fprintf(stderr, "Tunnel netmask6 is %d\n", netmask6);
}
#endif
return 0;
} else {

View file

@ -1,5 +1,6 @@
/*
* Copyright (c) 2006-2009 Bjorn Andersson <flex@kryo.se>, Erik Ekman <yarrick@kryo.se>
* Copyright (c) 2011-2012 Julian Kranz <julian@juliankranz.de>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@ -32,7 +33,9 @@ void set_downenc(char *encoding);
void client_set_selecttimeout(int select_timeout);
void client_set_lazymode(int lazy_mode);
void client_set_hostname_maxlen(int i);
#ifdef LINUX
void client_set_v6(char v6);
#endif
int client_handshake(int dns_fd, int raw_mode, int autodetect_frag_size, int fragsize);
int client_tunnel(int tun_fd, int dns_fd);

View file

@ -1,5 +1,6 @@
/* Copyright (c) 2006-2009 Bjorn Andersson <flex@kryo.se>, Erik Ekman <yarrick@kryo.se>
* Copyright (c) 2007 Albert Lee <trisk@acm.jhu.edu>.
* Copyright (c) 2011-2012 Julian Kranz <julian@juliankranz.de>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@ -353,6 +354,7 @@ int recent_seqno(int ourseqno, int gotseqno)
return 0;
}
#ifdef LINUX
void ipv6_addr_add(struct in6_addr *addr, uint8_t amount) {
int i;
for (i = 15; i >= 0; --i) {
@ -401,3 +403,4 @@ void ipv6_print(struct in6_addr *ip, char netmask6) {
: "/");
printf("%d\n", netmask6);
}
#endif

View file

@ -1,5 +1,6 @@
/*
* Copyright (c) 2006-2009 Bjorn Andersson <flex@kryo.se>, Erik Ekman <yarrick@kryo.se>
* Copyright (c) 2011-2012 Julian Kranz <julian@juliankranz.de>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@ -133,9 +134,11 @@ void warnx(const char *fmt, ...);
int recent_seqno(int , int);
#ifdef LINUX
void ipv6_addr_add(struct in6_addr *addr, uint8_t amount);
char ipv6_addr_equals(struct in6_addr *a, struct in6_addr *b);
char ipv6_net_check(struct in6_addr *net, char netmask);
void ipv6_print(struct in6_addr *ip, char netmask6);
#endif
#endif

View file

@ -38,7 +38,11 @@ struct user *users;
unsigned usercount;
int
#ifdef LINUX
init_users(in_addr_t my_ip, int netbits, struct in6_addr my_net6)
#elif
init_users(in_addr_t my_ip, int netbits)
#endif
{
int i;
int skip = 0;
@ -50,9 +54,11 @@ init_users(in_addr_t my_ip, int netbits, struct in6_addr my_net6)
struct in_addr net;
struct in_addr ipstart;
#ifdef LINUX
struct in6_addr next_v6;
memcpy(&next_v6, &my_net6, sizeof(my_net6));
ipv6_addr_add(&next_v6, 1);
#endif
for (i = 0; i < netbits; i++) {
netmask = (netmask << 1) | 1;
@ -81,8 +87,10 @@ init_users(in_addr_t my_ip, int netbits, struct in6_addr my_net6)
users[i].disabled = 0;
users[i].active = 0;
#ifdef LINUX
ipv6_addr_add(&next_v6, 1);
memcpy(&(users[i].tun_ip6), &next_v6, sizeof(struct in6_addr));
#endif
/* Rest is reset on login ('V' packet) */
}

View file

@ -41,7 +41,9 @@ struct user {
time_t last_pkt;
int seed;
in_addr_t tun_ip;
#ifdef LINUX
struct in6_addr tun_ip6;
#endif
struct in_addr host;
struct query q;
struct query q_sendrealsoon;
@ -77,7 +79,11 @@ struct user {
extern struct user *users;
#ifdef LINUX
int init_users(in_addr_t my_ip, int netbits, struct in6_addr my_net6);
#elif
int init_users(in_addr_t my_ip, int netbits);
#endif
const char* users_get_first_ip();
int users_waiting_on_reply();
int find_user_by_ip(uint32_t);