1
0
mirror of https://github.com/yarrick/iodine.git synced 2024-11-23 13:36:06 +03:00

Use packet functions for packet handling. Prepare for sending fragmented ( #7 )

This commit is contained in:
Erik Ekman 2007-12-01 23:33:51 +00:00
parent de4a726cb9
commit 4c6aae9e90

View File

@ -122,6 +122,16 @@ send_version_response(int fd, version_ack_t ack, uint32_t payload, struct user *
write_dns(fd, &u->q, out, sizeof(out)); write_dns(fd, &u->q, out, sizeof(out));
} }
static void
send_chunk(int dns_fd, struct query *q, int userid)
{
/* XXX: check MTU and only send part of packet if needed */
write_dns(dns_fd, q, users[userid].outpacket.data, users[userid].outpacket.len);
/* move this reset to after receiving ack */
users[userid].outpacket.len = 0;
users[userid].q.id = 0;
}
static int static int
tunnel_dns(int tun_fd, int dns_fd) tunnel_dns(int tun_fd, int dns_fd)
{ {
@ -257,8 +267,8 @@ tunnel_dns(int tun_fd, int dns_fd)
if (code & 1) { if (code & 1) {
outlen = sizeof(out); outlen = sizeof(out);
uncompress((uint8_t*)out, &outlen, uncompress((uint8_t*)out, &outlen, (uint8_t*)users[userid].inpacket.data,
(uint8_t*)users[userid].inpacket.data, users[userid].inpacket.len); users[userid].inpacket.len);
hdr = (struct ip*) (out + 4); hdr = (struct ip*) (out + 4);
touser = find_user_by_ip(hdr->ip_dst.s_addr); touser = find_user_by_ip(hdr->ip_dst.s_addr);
@ -269,23 +279,21 @@ tunnel_dns(int tun_fd, int dns_fd)
} else { } else {
/* send the compressed packet to other client /* send the compressed packet to other client
* if another packet is queued, throw away this one. TODO build queue */ * if another packet is queued, throw away this one. TODO build queue */
if (users[touser].outpacket.len == 0) { if (packet_empty(&(users[touser].outpacket))) {
memcpy(users[touser].outpacket.data, users[userid].inpacket.data, users[userid].inpacket.len); packet_fill(&(users[touser].outpacket), users[userid].inpacket.data,
users[touser].outpacket.len = users[userid].inpacket.len; users[userid].inpacket.len);
} }
} }
users[userid].inpacket.len = users[userid].inpacket.offset = 0; packet_init(&(users[userid].inpacket)); /* clear inpacket */
} }
} }
} }
/* userid must be set for a reply to be sent */ /* userid must be set for a reply to be sent */
if (userid >= 0 && userid < USERS && dummy.q.fromlen == users[userid].addrlen && if (userid >= 0 && userid < USERS && dummy.q.fromlen == users[userid].addrlen &&
memcmp(&(users[userid].host), &(dummy.q.from), dummy.q.fromlen) == 0 && memcmp(&(users[userid].host), &(dummy.q.from), dummy.q.fromlen) == 0 &&
users[userid].outpacket.len > 0) { packet_empty(&(users[userid].outpacket)) == 0) {
write_dns(dns_fd, &(dummy.q), users[userid].outpacket.data, users[userid].outpacket.len); send_chunk(dns_fd, &(dummy.q), userid);
users[userid].outpacket.len = 0;
users[userid].q.id = 0;
} }
return 0; return 0;
@ -326,9 +334,7 @@ tunnel(int tun_fd, int dns_fd)
if (i==0) { if (i==0) {
for (j = 0; j < USERS; j++) { for (j = 0; j < USERS; j++) {
if (users[j].q.id != 0) { if (users[j].q.id != 0) {
write_dns(dns_fd, &(users[j].q), users[j].outpacket.data, users[j].outpacket.len); send_chunk(dns_fd, &(users[j].q), j);
users[j].outpacket.len = 0;
users[j].q.id = 0;
} }
} }
} else { } else {