1
0
mirror of https://github.com/yarrick/iodine.git synced 2024-11-26 06:56:05 +03:00

merge dns and user #76

This commit is contained in:
J. A. Bezemer 2009-09-20 21:10:39 +00:00 committed by Erik Ekman
parent 05e99c7a3f
commit 60dfbf1b34
4 changed files with 46 additions and 10 deletions

View File

@ -356,6 +356,13 @@ dns_decode(char *buf, size_t buflen, struct query *q, qr_t qr, char *packet, siz
readshort(packet, &data, &type); readshort(packet, &data, &type);
readshort(packet, &data, &class); readshort(packet, &data, &class);
/* if CHECKLEN okay, then we're sure to have a proper name */
if (q != NULL) {
/* We only need the first char to check it */
q->name[0] = name[0];
q->name[1] = '\0';
}
/* Assume that first answer is NULL/CNAME that we wanted */ /* Assume that first answer is NULL/CNAME that we wanted */
readname(packet, packetlen, &data, name, sizeof(name)); readname(packet, packetlen, &data, name, sizeof(name));
CHECKLEN(10); CHECKLEN(10);

View File

@ -376,6 +376,7 @@ handle_null_request(int tun_fd, int dns_fd, struct query *q, int domain_len)
users[userid].inpacket.seqno = 0; users[userid].inpacket.seqno = 0;
users[userid].inpacket.fragment = 0; users[userid].inpacket.fragment = 0;
users[userid].fragsize = 100; /* very safe */ users[userid].fragsize = 100; /* very safe */
users[userid].conn = CONN_DNS_NULL;
} else { } else {
/* No space for another user */ /* No space for another user */
send_version_response(dns_fd, VERSION_FULL, created_users, 0, q); send_version_response(dns_fd, VERSION_FULL, created_users, 0, q);

View File

@ -78,14 +78,8 @@ init_users(in_addr_t my_ip, int netbits)
users[i].disabled = 0; users[i].disabled = 0;
created_users++; created_users++;
} }
users[i].inpacket.len = 0; users[i].active = 0;
users[i].inpacket.offset = 0; /* Rest is reset on login ('V' packet) */
users[i].outpacket.len = 0;
users[i].q.id = 0;
users[i].out_acked_seqno = 0;
users[i].out_acked_fragment = 0;
users[i].fragsize = 4096;
users[i].conn = CONN_DNS_NULL;
} }
return created_users; return created_users;
@ -129,6 +123,11 @@ find_user_by_ip(uint32_t ip)
int int
all_users_waiting_to_send() all_users_waiting_to_send()
/* If this returns true, then reading from tun device is blocked.
So only return true when all clients have at least one packet in
the outpacket-queue, so that sending back-to-back is possible
without going through another select loop.
*/
{ {
time_t now; time_t now;
int ret; int ret;
@ -139,8 +138,14 @@ all_users_waiting_to_send()
for (i = 0; i < USERS; i++) { for (i = 0; i < USERS; i++) {
if (users[i].active && !users[i].disabled && if (users[i].active && !users[i].disabled &&
users[i].last_pkt + 60 > now && users[i].last_pkt + 60 > now &&
((users[i].outpacket.len == 0 && users[i].conn == CONN_DNS_NULL) ((users[i].conn == CONN_RAW_UDP) ||
|| users[i].conn == CONN_RAW_UDP)) { ((users[i].conn == CONN_DNS_NULL)
#ifdef OUTPACKETQ_LEN
&& users[i].outpacketq_filled < 1
#else
&& users[i].outpacket.len == 0
#endif
))) {
ret = 0; ret = 0;
break; break;

View File

@ -19,6 +19,13 @@
#define USERS 16 #define USERS 16
#define OUTPACKETQ_LEN 4 /* Note: 16 users * 1 packet = 1MB */
/* Undefine to have no queue for packets coming in from tun device, which may
lead to massive dropping in multi-user situations with high traffic. */
#define DNSCACHE_LEN 4
/* Undefine to disable. MUST be less than 7; also see comments in iodined.c */
struct user { struct user {
char id; char id;
int active; int active;
@ -28,14 +35,30 @@ struct user {
in_addr_t tun_ip; in_addr_t tun_ip;
struct in_addr host; struct in_addr host;
struct query q; struct query q;
struct query q_prev;
struct query q_sendrealsoon;
int q_sendrealsoon_new;
struct packet inpacket; struct packet inpacket;
struct packet outpacket; struct packet outpacket;
int outfragresent;
struct encoder *encoder; struct encoder *encoder;
char downenc; char downenc;
int out_acked_seqno; int out_acked_seqno;
int out_acked_fragment; int out_acked_fragment;
int fragsize; int fragsize;
enum connection conn; enum connection conn;
int lazy;
#ifdef OUTPACKETQ_LEN
struct packet outpacketq[OUTPACKETQ_LEN];
int outpacketq_nexttouse;
int outpacketq_filled;
#endif
#ifdef DNSCACHE_LEN
struct query dnscache_q[DNSCACHE_LEN];
char dnscache_answer[DNSCACHE_LEN][4096];
int dnscache_answerlen[DNSCACHE_LEN];
int dnscache_lastfilled;
#endif
}; };
extern struct user users[USERS]; extern struct user users[USERS];