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; 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 <err.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <stdint.h>
#endif #endif
#define DNS_PORT 53 #define DNS_PORT 53
@ -132,4 +133,6 @@ void warnx(const char *fmt, ...);
int recent_seqno(int , int); int recent_seqno(int , int);
void inet6_addr_add(struct in6_addr *addr, uint8_t amount);
#endif #endif

View File

@ -78,7 +78,7 @@ static int created_users;
static int check_ip; static int check_ip;
static int my_mtu; static int my_mtu;
static in_addr_t my_ip; static in_addr_t my_ip;
static struct in6_addr my_ip6; static struct in6_addr my_net6;
static int netmask; static int netmask;
static char netmask6; static char netmask6;
@ -2339,23 +2339,23 @@ main(int argc, char **argv)
* Todo: Fix ;-) * Todo: Fix ;-)
*/ */
if (v6) { 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) { != 1) {
warnx("Bad IPv6 address to use inside tunnel."); warnx("Bad IPv6 address to use inside tunnel.");
usage(); usage();
} }
netmask6 = 112;
printf("IPv6 address: "); printf("IPv6 net: ");
char i; char i;
for (i = 0; i < 8; ++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"); : "\n");
if (my_ip == INADDR_NONE) { if (my_ip == INADDR_NONE) {
warnx("Bad IP address to use inside tunnel."); warnx("Bad IP address to use inside tunnel.");
usage(); usage();
} }
netmask6 = 112;
} }
topdomain = strdup(argv[1]); topdomain = strdup(argv[1]);
@ -2437,7 +2437,7 @@ main(int argc, char **argv)
read_password(password, sizeof(password)); 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) { if ((tun_fd = open_tun(device)) == -1) {
retval = 1; retval = 1;
@ -2450,6 +2450,20 @@ main(int argc, char **argv)
free((void*) other_ip); free((void*) other_ip);
goto cleanup1; 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); free((void*) other_ip);
} }
if ((dnsd_fd = open_dns(port, listen_ip)) == -1) { 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 */ #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 int
tun_setip(const char *ip, const char *other_ip, int netbits) 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); int write_tun(int, unsigned char *, size_t);
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_setmtu(unsigned); int tun_setmtu(unsigned);
#endif /* _TUN_H_ */ #endif /* _TUN_H_ */

View File

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

View File

@ -76,7 +76,7 @@ struct user {
extern struct user *users; 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(); const char* users_get_first_ip();
int users_waiting_on_reply(); int users_waiting_on_reply();
int find_user_by_ip(uint32_t); int find_user_by_ip(uint32_t);