mirror of
https://github.com/yarrick/iodine.git
synced 2024-12-26 23:03:33 +02:00
Reverted [686], [689] and [692]. SSH login now works again. Increased version.
This commit is contained in:
parent
b4893e8a8b
commit
2eb78f9e8c
7 changed files with 82 additions and 60 deletions
|
@ -6,14 +6,7 @@ iodine - http://code.kryo.se/iodine
|
|||
CHANGES:
|
||||
|
||||
2008-xx-xx: 0.x.x
|
||||
- Delayed sending responses in server to improve latency. Pings from
|
||||
server to client are now always fast instead of cycling from
|
||||
fast to 1000 ms.
|
||||
- The server now replies to all received queries.
|
||||
- Fixed segfault in server when sending version reject.
|
||||
- The interval between "pings" from clients is now 5 seconds.
|
||||
- Eliminited extra "ping" messages from client to server when server
|
||||
sends data and gets data back directly.
|
||||
- Applied patch to make iodine build on BeOS R5-BONE and Haiku,
|
||||
from Francois Revol. Still work to do to get tun device working.
|
||||
- Added capability to forward DNS queries outside tunnel domain to
|
||||
|
|
27
src/iodine.c
27
src/iodine.c
|
@ -235,11 +235,14 @@ tunnel_dns(int tun_fd, int dns_fd)
|
|||
|
||||
outlen = sizeof(out);
|
||||
inlen = read;
|
||||
if (uncompress((uint8_t*)out, &outlen, (uint8_t*)in, inlen) != Z_OK)
|
||||
if (uncompress((uint8_t*)out, &outlen, (uint8_t*)in, inlen) != Z_OK) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
write_tun(tun_fd, out, outlen);
|
||||
|
||||
if (!is_sending())
|
||||
send_ping(dns_fd);
|
||||
|
||||
return read;
|
||||
}
|
||||
|
||||
|
@ -250,20 +253,12 @@ tunnel(int tun_fd, int dns_fd)
|
|||
fd_set fds;
|
||||
int rv;
|
||||
int i;
|
||||
int short_ping;
|
||||
|
||||
rv = 0;
|
||||
short_ping = 0;
|
||||
|
||||
while (running) {
|
||||
if (short_ping) {
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 5000;
|
||||
short_ping = 0;
|
||||
} else {
|
||||
tv.tv_sec = 5;
|
||||
tv.tv_usec = 0;
|
||||
}
|
||||
tv.tv_sec = 1;
|
||||
tv.tv_usec = 0;
|
||||
|
||||
FD_ZERO(&fds);
|
||||
if (!is_sending())
|
||||
|
@ -278,9 +273,9 @@ tunnel(int tun_fd, int dns_fd)
|
|||
if (i < 0)
|
||||
err(1, "select");
|
||||
|
||||
if (i == 0) { /* timeout */
|
||||
if (i == 0) /* timeout */
|
||||
send_ping(dns_fd);
|
||||
} else {
|
||||
else {
|
||||
if (FD_ISSET(tun_fd, &fds)) {
|
||||
if (tunnel_tun(tun_fd, dns_fd) <= 0)
|
||||
continue;
|
||||
|
@ -288,10 +283,6 @@ tunnel(int tun_fd, int dns_fd)
|
|||
if (FD_ISSET(dns_fd, &fds)) {
|
||||
if (tunnel_dns(tun_fd, dns_fd) <= 0)
|
||||
continue;
|
||||
/* If we have nothing to send within x ms, send a ping
|
||||
* to get more data from server */
|
||||
if (!is_sending())
|
||||
short_ping = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -111,13 +111,6 @@ tunnel_tun(int tun_fd, int dns_fd)
|
|||
if (users[userid].outpacket.len == 0) {
|
||||
memcpy(users[userid].outpacket.data, out, outlen);
|
||||
users[userid].outpacket.len = outlen;
|
||||
if (users[userid].q.id != 0) {
|
||||
/* If delayed response is kept, send reply immediately */
|
||||
write_dns(dns_fd, &(users[userid].q), users[userid].outpacket.data, users[userid].outpacket.len);
|
||||
users[userid].outpacket.len = 0;
|
||||
users[userid].q.id = 0;
|
||||
return 0;
|
||||
}
|
||||
return outlen;
|
||||
} else {
|
||||
return 0;
|
||||
|
@ -253,12 +246,6 @@ handle_null_request(int tun_fd, int dns_fd, struct query *q, int domain_len)
|
|||
write_dns(dns_fd, q, "BADIP", 5);
|
||||
return; /* illegal id */
|
||||
}
|
||||
if (users[userid].q.id != 0) {
|
||||
/* If delayed response is kept, send empty reply before overwriting */
|
||||
write_dns(dns_fd, &(users[userid].q), users[userid].outpacket.data, users[userid].outpacket.len);
|
||||
users[userid].outpacket.len = 0;
|
||||
users[userid].q.id = 0;
|
||||
}
|
||||
memcpy(&(users[userid].q), q, sizeof(struct query));
|
||||
users[userid].last_pkt = time(NULL);
|
||||
} else if(in[0] == 'Z' || in[0] == 'z') {
|
||||
|
@ -324,12 +311,6 @@ handle_null_request(int tun_fd, int dns_fd, struct query *q, int domain_len)
|
|||
users[userid].encoder);
|
||||
|
||||
users[userid].last_pkt = time(NULL);
|
||||
if (users[userid].q.id != 0) {
|
||||
/* If delayed response is kept, send empty reply before overwriting */
|
||||
write_dns(dns_fd, &(users[userid].q), users[userid].outpacket.data, users[userid].outpacket.len);
|
||||
users[userid].outpacket.len = 0;
|
||||
users[userid].q.id = 0;
|
||||
}
|
||||
memcpy(&(users[userid].q), q, sizeof(struct query));
|
||||
memcpy(users[userid].inpacket.data + users[userid].inpacket.offset, unpacked, read);
|
||||
users[userid].inpacket.len += read;
|
||||
|
@ -519,9 +500,13 @@ tunnel(int tun_fd, int dns_fd, int bind_fd)
|
|||
|
||||
while (running) {
|
||||
int maxfd;
|
||||
|
||||
tv.tv_sec = 1;
|
||||
tv.tv_usec = 0;
|
||||
if (users_waiting_on_reply()) {
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 15000;
|
||||
} else {
|
||||
tv.tv_sec = 1;
|
||||
tv.tv_usec = 0;
|
||||
}
|
||||
|
||||
FD_ZERO(&fds);
|
||||
|
||||
|
@ -547,18 +532,29 @@ tunnel(int tun_fd, int dns_fd, int bind_fd)
|
|||
warn("select");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(FD_ISSET(tun_fd, &fds)) {
|
||||
tunnel_tun(tun_fd, dns_fd);
|
||||
continue;
|
||||
}
|
||||
if(FD_ISSET(dns_fd, &fds)) {
|
||||
tunnel_dns(tun_fd, dns_fd, bind_fd);
|
||||
continue;
|
||||
}
|
||||
if(FD_ISSET(bind_fd, &fds)) {
|
||||
tunnel_bind(bind_fd, dns_fd);
|
||||
continue;
|
||||
|
||||
if (i==0) {
|
||||
int j;
|
||||
for (j = 0; j < USERS; j++) {
|
||||
if (users[j].q.id != 0) {
|
||||
write_dns(dns_fd, &(users[j].q), users[j].outpacket.data, users[j].outpacket.len);
|
||||
users[j].outpacket.len = 0;
|
||||
users[j].q.id = 0;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(FD_ISSET(tun_fd, &fds)) {
|
||||
tunnel_tun(tun_fd, dns_fd);
|
||||
continue;
|
||||
}
|
||||
if(FD_ISSET(dns_fd, &fds)) {
|
||||
tunnel_dns(tun_fd, dns_fd, bind_fd);
|
||||
continue;
|
||||
}
|
||||
if(FD_ISSET(bind_fd, &fds)) {
|
||||
tunnel_bind(bind_fd, dns_fd);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
17
src/user.c
17
src/user.c
|
@ -53,6 +53,23 @@ init_users(in_addr_t my_ip)
|
|||
}
|
||||
}
|
||||
|
||||
int
|
||||
users_waiting_on_reply()
|
||||
{
|
||||
int ret;
|
||||
int i;
|
||||
|
||||
ret = 0;
|
||||
for (i = 0; i < USERS; i++) {
|
||||
if (users[i].active && users[i].last_pkt + 60 > time(NULL) &&
|
||||
users[i].q.id != 0) {
|
||||
ret++;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
find_user_by_ip(uint32_t ip)
|
||||
{
|
||||
|
|
|
@ -35,6 +35,7 @@ struct user {
|
|||
extern struct user users[USERS];
|
||||
|
||||
void init_users(in_addr_t);
|
||||
int users_waiting_on_reply();
|
||||
int find_user_by_ip(uint32_t);
|
||||
int all_users_waiting_to_send();
|
||||
int find_available_user();
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
/* This is the version of the network protocol
|
||||
It is usually equal to the latest iodine version number */
|
||||
#define VERSION 0x00000402
|
||||
#define VERSION 0x00000403
|
||||
|
||||
#endif /* _VERSION_H_ */
|
||||
|
||||
|
|
24
tests/user.c
24
tests/user.c
|
@ -46,6 +46,29 @@ START_TEST(test_init_users)
|
|||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(test_users_waiting)
|
||||
{
|
||||
in_addr_t ip;
|
||||
|
||||
ip = inet_addr("127.0.0.1");
|
||||
init_users(ip);
|
||||
|
||||
fail_unless(users_waiting_on_reply() == 0);
|
||||
|
||||
users[3].active = 1;
|
||||
|
||||
fail_unless(users_waiting_on_reply() == 0);
|
||||
|
||||
users[3].last_pkt = time(NULL);
|
||||
|
||||
fail_unless(users_waiting_on_reply() == 0);
|
||||
|
||||
users[3].q.id = 1;
|
||||
|
||||
fail_unless(users_waiting_on_reply() == 1);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(test_find_user_by_ip)
|
||||
{
|
||||
in_addr_t ip;
|
||||
|
@ -130,6 +153,7 @@ test_user_create_tests()
|
|||
|
||||
tc = tcase_create("User");
|
||||
tcase_add_test(tc, test_init_users);
|
||||
tcase_add_test(tc, test_users_waiting);
|
||||
tcase_add_test(tc, test_find_user_by_ip);
|
||||
tcase_add_test(tc, test_all_users_waiting_to_send);
|
||||
tcase_add_test(tc, test_find_available_user);
|
||||
|
|
Loading…
Reference in a new issue