mirror of
https://github.com/yarrick/iodine.git
synced 2025-04-07 11:07:03 +00:00
---
This commit is contained in:
parent
5447492c80
commit
5ef46f4053
5 changed files with 56 additions and 10 deletions
|
@ -365,3 +365,11 @@ void inet6_addr_add(struct in6_addr *addr, uint8_t amount) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
char inet6_addr_equals(struct in6_addr *a, struct in6_addr *b) {
|
||||
char i;
|
||||
for (i = 4; i >= 0; --i)
|
||||
if(a->__in6_u.__u6_addr32[i] != b->__in6_u.__u6_addr32[i])
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -134,5 +134,6 @@ void warnx(const char *fmt, ...);
|
|||
int recent_seqno(int , int);
|
||||
|
||||
void inet6_addr_add(struct in6_addr *addr, uint8_t amount);
|
||||
char inet6_addr_equals(struct in6_addr *a, struct in6_addr *b);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
#define _XPG4_2
|
||||
#include <netinet/in_systm.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/ip6.h>
|
||||
#include <grp.h>
|
||||
#include <sys/uio.h>
|
||||
#include <pwd.h>
|
||||
|
@ -136,7 +137,7 @@ check_user_and_ip(int userid, struct query *q)
|
|||
}
|
||||
|
||||
/* return early if IP checking is disabled */
|
||||
if (!check_ip || 1) {
|
||||
if (!check_ip) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -550,6 +551,7 @@ tunnel_tun(int tun_fd, int dns_fd)
|
|||
{
|
||||
unsigned long outlen;
|
||||
struct ip *header;
|
||||
struct ip6_hdr *header6;
|
||||
char out[64*1024];
|
||||
char in[64*1024];
|
||||
int userid;
|
||||
|
@ -558,9 +560,17 @@ tunnel_tun(int tun_fd, int dns_fd)
|
|||
if ((read = read_tun(tun_fd, in, sizeof(in))) <= 0)
|
||||
return 0;
|
||||
|
||||
/* find target ip in packet, in is padded with 4 bytes TUN header */
|
||||
header = (struct ip*) (in + 4);
|
||||
userid = find_user_by_ip(header->ip_dst.s_addr);
|
||||
uint16_t *header_info = (uint16_t*)in;
|
||||
if(ntohs(header_info[1]) == 0x0008) {
|
||||
/* find target ip in packet, in is padded with 4 bytes TUN header */
|
||||
header = (struct ip*) (in + 4);
|
||||
userid = find_user_by_ip(header->ip_dst.s_addr);
|
||||
}
|
||||
else {
|
||||
header = (struct ip6_hdr*) (in + 4);
|
||||
userid = find_user_by_ip6(header->ip6_dst);
|
||||
}
|
||||
|
||||
if (userid < 0)
|
||||
return 0;
|
||||
|
||||
|
@ -1747,12 +1757,19 @@ handle_full_packet(int tun_fd, int dns_fd, int userid)
|
|||
(uint8_t*)users[userid].inpacket.data, users[userid].inpacket.len);
|
||||
|
||||
if (ret == Z_OK) {
|
||||
struct ip *hdr;
|
||||
|
||||
hdr = (struct ip*) (out + 4);
|
||||
touser = find_user_by_ip(hdr->ip_dst.s_addr);
|
||||
uint16_t *header_info = (uint16_t*)out;
|
||||
if(ntohs(header_info[1]) == 0x0008) {
|
||||
struct ip *hdr;
|
||||
|
||||
touser = -1;
|
||||
hdr = (struct ip*) (out + 4);
|
||||
touser = find_user_by_ip(hdr->ip_dst.s_addr);
|
||||
}
|
||||
else {
|
||||
struct ip6_hdr *hdr;
|
||||
hdr = (struct ip6_hdr*) (out + 4);
|
||||
touser = find_user_by_ip6(hdr->ip6_dst);
|
||||
}
|
||||
|
||||
if (touser == -1) {
|
||||
/* send the uncompressed packet to tun device */
|
||||
|
@ -1886,8 +1903,7 @@ raw_decode(char *packet, int len, struct query *q, int dns_fd, int tun_fd)
|
|||
/* should start with header */
|
||||
if (memcmp(packet, raw_header, RAW_HDR_IDENT_LEN)) return 0;
|
||||
|
||||
//raw_user = RAW_HDR_GET_USR(packet);
|
||||
raw_user = 0;
|
||||
raw_user = RAW_HDR_GET_USR(packet);
|
||||
switch (RAW_HDR_GET_CMD(packet)) {
|
||||
case RAW_HDR_CMD_LOGIN:
|
||||
/* Login challenge */
|
||||
|
|
20
src/user.c
20
src/user.c
|
@ -135,6 +135,26 @@ find_user_by_ip(uint32_t ip)
|
|||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
find_user_by_ip6(struct in6_addr ip)
|
||||
{
|
||||
int ret;
|
||||
int i;
|
||||
|
||||
return 0;
|
||||
|
||||
ret = -1;
|
||||
for (i = 0; i < usercount; i++) {
|
||||
if (users[i].active && !users[i].disabled &&
|
||||
users[i].last_pkt + 60 > time(NULL) &&
|
||||
inet6_addr_equals(&ip, &(users[i].tun_ip6))) {
|
||||
ret = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
all_users_waiting_to_send()
|
||||
/* If this returns true, then reading from tun device is blocked.
|
||||
|
|
|
@ -80,6 +80,7 @@ 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);
|
||||
int find_user_by_ip6(struct in6_addr ip);
|
||||
int all_users_waiting_to_send();
|
||||
int find_available_user();
|
||||
void user_switch_codec(int userid, struct encoder *enc);
|
||||
|
|
Loading…
Add table
Reference in a new issue