Reverted [686], [689] and [692]. SSH login now works again. Increased version.

This commit is contained in:
Erik Ekman 2008-09-14 12:44:55 +00:00
parent b4893e8a8b
commit 2eb78f9e8c
7 changed files with 82 additions and 60 deletions

View file

@ -6,14 +6,7 @@ iodine - http://code.kryo.se/iodine
CHANGES: CHANGES:
2008-xx-xx: 0.x.x 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. - 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, - Applied patch to make iodine build on BeOS R5-BONE and Haiku,
from Francois Revol. Still work to do to get tun device working. from Francois Revol. Still work to do to get tun device working.
- Added capability to forward DNS queries outside tunnel domain to - Added capability to forward DNS queries outside tunnel domain to

View file

@ -235,10 +235,13 @@ tunnel_dns(int tun_fd, int dns_fd)
outlen = sizeof(out); outlen = sizeof(out);
inlen = read; 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; return -1;
}
write_tun(tun_fd, out, outlen); write_tun(tun_fd, out, outlen);
if (!is_sending())
send_ping(dns_fd);
return read; return read;
} }
@ -250,20 +253,12 @@ tunnel(int tun_fd, int dns_fd)
fd_set fds; fd_set fds;
int rv; int rv;
int i; int i;
int short_ping;
rv = 0; rv = 0;
short_ping = 0;
while (running) { while (running) {
if (short_ping) { tv.tv_sec = 1;
tv.tv_sec = 0; tv.tv_usec = 0;
tv.tv_usec = 5000;
short_ping = 0;
} else {
tv.tv_sec = 5;
tv.tv_usec = 0;
}
FD_ZERO(&fds); FD_ZERO(&fds);
if (!is_sending()) if (!is_sending())
@ -278,9 +273,9 @@ tunnel(int tun_fd, int dns_fd)
if (i < 0) if (i < 0)
err(1, "select"); err(1, "select");
if (i == 0) { /* timeout */ if (i == 0) /* timeout */
send_ping(dns_fd); send_ping(dns_fd);
} else { else {
if (FD_ISSET(tun_fd, &fds)) { if (FD_ISSET(tun_fd, &fds)) {
if (tunnel_tun(tun_fd, dns_fd) <= 0) if (tunnel_tun(tun_fd, dns_fd) <= 0)
continue; continue;
@ -288,10 +283,6 @@ tunnel(int tun_fd, int dns_fd)
if (FD_ISSET(dns_fd, &fds)) { if (FD_ISSET(dns_fd, &fds)) {
if (tunnel_dns(tun_fd, dns_fd) <= 0) if (tunnel_dns(tun_fd, dns_fd) <= 0)
continue; 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;
} }
} }
} }

View file

@ -111,13 +111,6 @@ tunnel_tun(int tun_fd, int dns_fd)
if (users[userid].outpacket.len == 0) { if (users[userid].outpacket.len == 0) {
memcpy(users[userid].outpacket.data, out, outlen); memcpy(users[userid].outpacket.data, out, outlen);
users[userid].outpacket.len = 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; return outlen;
} else { } else {
return 0; 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); write_dns(dns_fd, q, "BADIP", 5);
return; /* illegal id */ 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)); memcpy(&(users[userid].q), q, sizeof(struct query));
users[userid].last_pkt = time(NULL); users[userid].last_pkt = time(NULL);
} else if(in[0] == 'Z' || in[0] == 'z') { } 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].encoder);
users[userid].last_pkt = time(NULL); 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].q), q, sizeof(struct query));
memcpy(users[userid].inpacket.data + users[userid].inpacket.offset, unpacked, read); memcpy(users[userid].inpacket.data + users[userid].inpacket.offset, unpacked, read);
users[userid].inpacket.len += read; users[userid].inpacket.len += read;
@ -519,9 +500,13 @@ tunnel(int tun_fd, int dns_fd, int bind_fd)
while (running) { while (running) {
int maxfd; int maxfd;
if (users_waiting_on_reply()) {
tv.tv_sec = 1; tv.tv_sec = 0;
tv.tv_usec = 0; tv.tv_usec = 15000;
} else {
tv.tv_sec = 1;
tv.tv_usec = 0;
}
FD_ZERO(&fds); FD_ZERO(&fds);
@ -548,17 +533,28 @@ tunnel(int tun_fd, int dns_fd, int bind_fd)
return 1; return 1;
} }
if(FD_ISSET(tun_fd, &fds)) { if (i==0) {
tunnel_tun(tun_fd, dns_fd); int j;
continue; for (j = 0; j < USERS; j++) {
} if (users[j].q.id != 0) {
if(FD_ISSET(dns_fd, &fds)) { write_dns(dns_fd, &(users[j].q), users[j].outpacket.data, users[j].outpacket.len);
tunnel_dns(tun_fd, dns_fd, bind_fd); users[j].outpacket.len = 0;
continue; users[j].q.id = 0;
} }
if(FD_ISSET(bind_fd, &fds)) { }
tunnel_bind(bind_fd, dns_fd); } else {
continue; 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;
}
} }
} }

View file

@ -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 int
find_user_by_ip(uint32_t ip) find_user_by_ip(uint32_t ip)
{ {

View file

@ -35,6 +35,7 @@ struct user {
extern struct user users[USERS]; extern struct user users[USERS];
void init_users(in_addr_t); void init_users(in_addr_t);
int users_waiting_on_reply();
int find_user_by_ip(uint32_t); int find_user_by_ip(uint32_t);
int all_users_waiting_to_send(); int all_users_waiting_to_send();
int find_available_user(); int find_available_user();

View file

@ -19,7 +19,7 @@
/* This is the version of the network protocol /* This is the version of the network protocol
It is usually equal to the latest iodine version number */ It is usually equal to the latest iodine version number */
#define VERSION 0x00000402 #define VERSION 0x00000403
#endif /* _VERSION_H_ */ #endif /* _VERSION_H_ */

View file

@ -46,6 +46,29 @@ START_TEST(test_init_users)
} }
END_TEST 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) START_TEST(test_find_user_by_ip)
{ {
in_addr_t ip; in_addr_t ip;
@ -130,6 +153,7 @@ test_user_create_tests()
tc = tcase_create("User"); tc = tcase_create("User");
tcase_add_test(tc, test_init_users); 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_find_user_by_ip);
tcase_add_test(tc, test_all_users_waiting_to_send); tcase_add_test(tc, test_all_users_waiting_to_send);
tcase_add_test(tc, test_find_available_user); tcase_add_test(tc, test_find_available_user);