1
0
Fork 0
mirror of https://github.com/yarrick/iodine.git synced 2025-04-07 11:07:03 +00:00
This commit is contained in:
Julian Kranz 2012-01-01 16:59:49 +01:00 committed by Barak A. Pearlmutter
parent 64a9e55e3e
commit ef124fcf3a
7 changed files with 59 additions and 8 deletions

View file

@ -352,3 +352,16 @@ int recent_seqno(int ourseqno, int gotseqno)
}
return 0;
}
void inet6_addr_add(struct in6_addr *addr, uint8_t amount) {
char i;
for (i = 15; i >= 0; --i) {
uint16_t next = addr->__in6_u.__u6_addr8[i];
next = next + amount;
addr->__in6_u.__u6_addr8[i] = next;
if(next & 0xff00)
amount = 1;
else
break;
}
}

View file

@ -39,6 +39,7 @@ extern const unsigned char raw_header[RAW_HDR_LEN];
#include <err.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <stdint.h>
#endif
#define DNS_PORT 53
@ -132,4 +133,6 @@ void warnx(const char *fmt, ...);
int recent_seqno(int , int);
void inet6_addr_add(struct in6_addr *addr, uint8_t amount);
#endif

View file

@ -78,7 +78,7 @@ static int created_users;
static int check_ip;
static int my_mtu;
static in_addr_t my_ip;
static struct in6_addr my_ip6;
static struct in6_addr my_net6;
static int netmask;
static char netmask6;
@ -2339,23 +2339,23 @@ main(int argc, char **argv)
* Todo: Fix ;-)
*/
if (v6) {
if (inet_pton(AF_INET6, "2001:4242:4242:4242:4242:4242:4242:1", &my_ip6)
if (inet_pton(AF_INET6, "2001:4242:4242:4242:4242:4242:4242:0000", &my_net6)
!= 1) {
warnx("Bad IPv6 address to use inside tunnel.");
usage();
}
netmask6 = 112;
printf("IPv6 address: ");
printf("IPv6 net: ");
char i;
for (i = 0; i < 8; ++i)
printf("%04x%s", ntohs(my_ip6.__in6_u.__u6_addr16[i]), i < 7 ? ":"
printf("%04x%s", ntohs(my_net6.__in6_u.__u6_addr16[i]), i < 7 ? ":"
: "\n");
if (my_ip == INADDR_NONE) {
warnx("Bad IP address to use inside tunnel.");
usage();
}
netmask6 = 112;
}
topdomain = strdup(argv[1]);
@ -2437,7 +2437,7 @@ main(int argc, char **argv)
read_password(password, sizeof(password));
}
created_users = init_users(my_ip, netmask);
created_users = init_users(my_ip, netmask, my_net6);
if ((tun_fd = open_tun(device)) == -1) {
retval = 1;
@ -2450,6 +2450,20 @@ main(int argc, char **argv)
free((void*) other_ip);
goto cleanup1;
}
if (v6) {
struct in6_addr my_ip6;
memcpy(&my_ip6, &my_net6, sizeof(my_net6));
inet6_addr_add(&my_ip6, 1);
char buf[41];
inet_ntop(AF_INET6, &my_ip6, buf, sizeof(buf));
if (tun_setip6(buf, netmask6) != 0) {
retval = 1;
free((void*) other_ip);
goto cleanup1;
}
}
free((void*) other_ip);
}
if ((dnsd_fd = open_dns(port, listen_ip)) == -1) {

View file

@ -433,6 +433,18 @@ read_tun(int tun_fd, char *buf, size_t len)
#endif /* !FREEBSD */
}
int tun_setip6(char const *ip6, char netmask6) {
char cmdline[512];
snprintf(cmdline, sizeof(cmdline),
IFCONFIGPATH "ifconfig %s inet6 add %s/%d",
if_name,
ip6,
netmask6);
return system(cmdline);
}
int
tun_setip(const char *ip, const char *other_ip, int netbits)
{

View file

@ -22,6 +22,7 @@ void close_tun(int);
int write_tun(int, unsigned char *, size_t);
ssize_t read_tun(int, char *, size_t);
int tun_setip(const char *, const char *, int);
int tun_setip6(char const *ip6, char netmask6);
int tun_setmtu(unsigned);
#endif /* _TUN_H_ */

View file

@ -37,7 +37,7 @@ struct user *users;
unsigned usercount;
int
init_users(in_addr_t my_ip, int netbits)
init_users(in_addr_t my_ip, int netbits, struct in6_addr my_net6)
{
int i;
int skip = 0;
@ -49,6 +49,10 @@ init_users(in_addr_t my_ip, int netbits)
struct in_addr net;
struct in_addr ipstart;
struct in6_addr next_v6;
memcpy(&next_v6, &my_net6, sizeof(my_net6));
inet6_addr_add(&next_v6, 1);
for (i = 0; i < netbits; i++) {
netmask = (netmask << 1) | 1;
}
@ -75,6 +79,10 @@ init_users(in_addr_t my_ip, int netbits)
net.s_addr = ip;
users[i].disabled = 0;
users[i].active = 0;
inet6_addr_add(&next_v6, 1);
memcpy(&(users[i].tun_ip6), &next_v6, sizeof(struct in6_addr));
/* Rest is reset on login ('V' packet) */
}

View file

@ -76,7 +76,7 @@ struct user {
extern struct user *users;
int init_users(in_addr_t, int);
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);