mirror of
https://github.com/yarrick/iodine.git
synced 2024-11-25 15:41:26 +00:00
Move global values out of dns.c, into iodined.c
This commit is contained in:
parent
754998f7ef
commit
449bc77f57
48
dns.c
48
dns.c
|
@ -28,8 +28,9 @@
|
|||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "dns.h"
|
||||
#include "read.h"
|
||||
#include "structs.h"
|
||||
#include "dns.h"
|
||||
|
||||
static int host2dns(const char *, char *, int);
|
||||
static int dns_write(int, int, char *, int, char);
|
||||
|
@ -46,12 +47,6 @@ uint16_t chunkid;
|
|||
|
||||
uint16_t pingid;
|
||||
|
||||
char delayed_q_name[256];
|
||||
short delayed_q_type;
|
||||
short delayed_q_id;
|
||||
struct sockaddr_in delayed_q_from;
|
||||
int delayed_q_fromlen;
|
||||
|
||||
|
||||
int
|
||||
open_dns(const char *host, const char *domain)
|
||||
|
@ -145,10 +140,7 @@ open_dnsd(const char *domain)
|
|||
topdomain[sizeof(topdomain) - 1] = 0;
|
||||
|
||||
packetlen = 0;
|
||||
delayed_q_type = 0;
|
||||
delayed_q_id = 0;
|
||||
delayed_q_fromlen = 0;
|
||||
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
|
@ -422,14 +414,8 @@ host2dns(const char *host, char *buffer, int size)
|
|||
return p - buffer;
|
||||
}
|
||||
|
||||
int
|
||||
dnsd_hasack()
|
||||
{
|
||||
return (delayed_q_id != 0);
|
||||
}
|
||||
|
||||
void
|
||||
dnsd_send(int fd, char *data, int datalen)
|
||||
dnsd_send(int fd, struct query *q, char *data, int datalen)
|
||||
{
|
||||
int len;
|
||||
char *p;
|
||||
|
@ -441,7 +427,7 @@ dnsd_send(int fd, char *data, int datalen)
|
|||
len = 0;
|
||||
header = (HEADER*)buf;
|
||||
|
||||
header->id = htons(delayed_q_id);
|
||||
header->id = htons(q->id);
|
||||
header->qr = 1;
|
||||
header->opcode = 0;
|
||||
header->aa = 1;
|
||||
|
@ -454,16 +440,16 @@ dnsd_send(int fd, char *data, int datalen)
|
|||
|
||||
p = buf + sizeof(HEADER);
|
||||
|
||||
p += host2dns(delayed_q_name, p, strlen(delayed_q_name));
|
||||
PUTSHORT(delayed_q_type, p);
|
||||
p += host2dns(q->name, p, strlen(q->name));
|
||||
PUTSHORT(q->type, p);
|
||||
PUTSHORT(C_IN, p);
|
||||
|
||||
p += host2dns(delayed_q_name, p, strlen(delayed_q_name));
|
||||
PUTSHORT(delayed_q_type, p);
|
||||
p += host2dns(q->name, p, strlen(q->name));
|
||||
PUTSHORT(q->type, p);
|
||||
PUTSHORT(C_IN, p);
|
||||
PUTLONG(0, p);
|
||||
|
||||
delayed_q_id = 0;
|
||||
q->id = 0;
|
||||
|
||||
if(datalen > 0) {
|
||||
PUTSHORT(datalen, p);
|
||||
|
@ -474,7 +460,7 @@ dnsd_send(int fd, char *data, int datalen)
|
|||
}
|
||||
|
||||
len = p - buf;
|
||||
sendto(fd, buf, len, 0, (struct sockaddr*)&delayed_q_from, delayed_q_fromlen);
|
||||
sendto(fd, buf, len, 0, (struct sockaddr*)&q->from, q->fromlen);
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -518,7 +504,7 @@ close_dnsd(int fd)
|
|||
}
|
||||
|
||||
int
|
||||
dnsd_read(int fd, char *buf, int buflen)
|
||||
dnsd_read(int fd, struct query *q, char *buf, int buflen)
|
||||
{
|
||||
int r;
|
||||
short id;
|
||||
|
@ -554,11 +540,11 @@ dnsd_read(int fd, char *buf, int buflen)
|
|||
READSHORT(class, data);
|
||||
|
||||
// Store needed info about delayed response
|
||||
strncpy(delayed_q_name, name, 256);
|
||||
delayed_q_type = type;
|
||||
delayed_q_id = id;
|
||||
delayed_q_fromlen = addrlen;
|
||||
memcpy((struct sockaddr*)&delayed_q_from, (struct sockaddr*)&from, addrlen);
|
||||
strncpy(q->name, name, 256);
|
||||
q->type = type;
|
||||
q->id = id;
|
||||
q->fromlen = addrlen;
|
||||
memcpy((struct sockaddr*)&q->from, (struct sockaddr*)&from, addrlen);
|
||||
|
||||
return decodepacket(name, buf, buflen);
|
||||
}
|
||||
|
|
6
dns.h
6
dns.h
|
@ -17,8 +17,6 @@
|
|||
#ifndef _DNS_H_
|
||||
#define _DNS_H_
|
||||
|
||||
#define GOTHELLO -5
|
||||
|
||||
int open_dns(const char *, const char *);
|
||||
void close_dns(int);
|
||||
|
||||
|
@ -34,8 +32,8 @@ extern struct sockaddr_in peer;
|
|||
int open_dnsd(const char *);
|
||||
void close_dnsd(int);
|
||||
|
||||
int dnsd_read(int, char *, int);
|
||||
void dnsd_send(int, char *, int);
|
||||
int dnsd_read(int, struct query*, char *, int);
|
||||
void dnsd_send(int, struct query*, char *, int);
|
||||
|
||||
int dnsd_haspacket();
|
||||
int dnsd_hasack();
|
||||
|
|
1
iodine.c
1
iodine.c
|
@ -29,6 +29,7 @@
|
|||
#include <zlib.h>
|
||||
|
||||
#include "tun.h"
|
||||
#include "structs.h"
|
||||
#include "dns.h"
|
||||
|
||||
#ifndef MAX
|
||||
|
|
25
iodined.c
25
iodined.c
|
@ -29,6 +29,7 @@
|
|||
#include <zlib.h>
|
||||
|
||||
#include "tun.h"
|
||||
#include "structs.h"
|
||||
#include "dns.h"
|
||||
|
||||
#ifndef MAX
|
||||
|
@ -37,17 +38,12 @@
|
|||
|
||||
int running = 1;
|
||||
|
||||
struct packet
|
||||
{
|
||||
int len;
|
||||
int offset;
|
||||
char data[64*1024];
|
||||
};
|
||||
|
||||
struct packet packetbuf;
|
||||
struct packet outpacket;
|
||||
int outid;
|
||||
|
||||
struct query q;
|
||||
|
||||
static void
|
||||
sigint(int sig) {
|
||||
running = 0;
|
||||
|
@ -66,7 +62,7 @@ tunnel(int tun_fd, int dns_fd)
|
|||
char out[64*1024];
|
||||
|
||||
while (running) {
|
||||
if (dnsd_hasack()) {
|
||||
if (q.id != 0) {
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 5000;
|
||||
} else {
|
||||
|
@ -88,9 +84,10 @@ tunnel(int tun_fd, int dns_fd)
|
|||
}
|
||||
|
||||
if (i==0) {
|
||||
if (dnsd_hasack())
|
||||
dnsd_send(dns_fd, outpacket.data, outpacket.len);
|
||||
if (q.type != 0)
|
||||
dnsd_send(dns_fd, &q, outpacket.data, outpacket.len);
|
||||
outpacket.len = 0;
|
||||
q.id = 0;
|
||||
} else {
|
||||
if(FD_ISSET(tun_fd, &fds)) {
|
||||
read = read_tun(tun_fd, in, sizeof(in));
|
||||
|
@ -103,13 +100,13 @@ tunnel(int tun_fd, int dns_fd)
|
|||
outpacket.len = outlen;
|
||||
}
|
||||
if(FD_ISSET(dns_fd, &fds)) {
|
||||
read = dnsd_read(dns_fd, in, sizeof(in));
|
||||
read = dnsd_read(dns_fd, &q, in, sizeof(in));
|
||||
if (read < 0)
|
||||
continue;
|
||||
|
||||
if(in[0] == 'H' || in[0] == 'h') {
|
||||
read = snprintf(out, sizeof(out), "%s-%d", "172.30.5.2", 1023);
|
||||
dnsd_send(dns_fd, out, read);
|
||||
dnsd_send(dns_fd, &q, out, read);
|
||||
} else if((in[0] >= '0' && in[0] <= '9')
|
||||
|| (in[0] >= 'a' && in[0] <= 'f')
|
||||
|| (in[0] >= 'A' && in[0] <= 'F')) {
|
||||
|
@ -133,8 +130,9 @@ tunnel(int tun_fd, int dns_fd)
|
|||
packetbuf.len = packetbuf.offset = 0;
|
||||
}
|
||||
if (outpacket.len > 0) {
|
||||
dnsd_send(dns_fd, outpacket.data, outpacket.len);
|
||||
dnsd_send(dns_fd, &q, outpacket.data, outpacket.len);
|
||||
outpacket.len = 0;
|
||||
q.id = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -194,6 +192,7 @@ main(int argc, char **argv)
|
|||
packetbuf.len = 0;
|
||||
packetbuf.offset = 0;
|
||||
outpacket.len = 0;
|
||||
q.id = 0;
|
||||
|
||||
while ((choice = getopt(argc, argv, "vfhu:t:m:")) != -1) {
|
||||
switch(choice) {
|
||||
|
|
35
structs.h
Normal file
35
structs.h
Normal file
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Copyright (c) 2006 Bjorn Andersson <flex@kryo.se>, Erik Ekman <yarrick@kryo.se>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef _STRUCTS_H_
|
||||
#define _STRUCTS_H_
|
||||
|
||||
struct packet
|
||||
{
|
||||
int len;
|
||||
int offset;
|
||||
char data[64*1024];
|
||||
};
|
||||
|
||||
struct query {
|
||||
char name[256];
|
||||
short type;
|
||||
short id;
|
||||
struct sockaddr_in from;
|
||||
int fromlen;
|
||||
};
|
||||
|
||||
#endif /* _STRUCTS_H_ */
|
Loading…
Reference in a new issue