mirror of
https://github.com/yarrick/iodine.git
synced 2024-11-23 00:29:20 +02:00
Move global values out of dns.c, into iodined.c
This commit is contained in:
parent
754998f7ef
commit
449bc77f57
46
dns.c
46
dns.c
|
@ -28,8 +28,9 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
#include "dns.h"
|
|
||||||
#include "read.h"
|
#include "read.h"
|
||||||
|
#include "structs.h"
|
||||||
|
#include "dns.h"
|
||||||
|
|
||||||
static int host2dns(const char *, char *, int);
|
static int host2dns(const char *, char *, int);
|
||||||
static int dns_write(int, int, char *, int, char);
|
static int dns_write(int, int, char *, int, char);
|
||||||
|
@ -46,12 +47,6 @@ uint16_t chunkid;
|
||||||
|
|
||||||
uint16_t pingid;
|
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
|
int
|
||||||
open_dns(const char *host, const char *domain)
|
open_dns(const char *host, const char *domain)
|
||||||
|
@ -145,9 +140,6 @@ open_dnsd(const char *domain)
|
||||||
topdomain[sizeof(topdomain) - 1] = 0;
|
topdomain[sizeof(topdomain) - 1] = 0;
|
||||||
|
|
||||||
packetlen = 0;
|
packetlen = 0;
|
||||||
delayed_q_type = 0;
|
|
||||||
delayed_q_id = 0;
|
|
||||||
delayed_q_fromlen = 0;
|
|
||||||
|
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
@ -422,14 +414,8 @@ host2dns(const char *host, char *buffer, int size)
|
||||||
return p - buffer;
|
return p - buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
|
||||||
dnsd_hasack()
|
|
||||||
{
|
|
||||||
return (delayed_q_id != 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
dnsd_send(int fd, char *data, int datalen)
|
dnsd_send(int fd, struct query *q, char *data, int datalen)
|
||||||
{
|
{
|
||||||
int len;
|
int len;
|
||||||
char *p;
|
char *p;
|
||||||
|
@ -441,7 +427,7 @@ dnsd_send(int fd, char *data, int datalen)
|
||||||
len = 0;
|
len = 0;
|
||||||
header = (HEADER*)buf;
|
header = (HEADER*)buf;
|
||||||
|
|
||||||
header->id = htons(delayed_q_id);
|
header->id = htons(q->id);
|
||||||
header->qr = 1;
|
header->qr = 1;
|
||||||
header->opcode = 0;
|
header->opcode = 0;
|
||||||
header->aa = 1;
|
header->aa = 1;
|
||||||
|
@ -454,16 +440,16 @@ dnsd_send(int fd, char *data, int datalen)
|
||||||
|
|
||||||
p = buf + sizeof(HEADER);
|
p = buf + sizeof(HEADER);
|
||||||
|
|
||||||
p += host2dns(delayed_q_name, p, strlen(delayed_q_name));
|
p += host2dns(q->name, p, strlen(q->name));
|
||||||
PUTSHORT(delayed_q_type, p);
|
PUTSHORT(q->type, p);
|
||||||
PUTSHORT(C_IN, p);
|
PUTSHORT(C_IN, p);
|
||||||
|
|
||||||
p += host2dns(delayed_q_name, p, strlen(delayed_q_name));
|
p += host2dns(q->name, p, strlen(q->name));
|
||||||
PUTSHORT(delayed_q_type, p);
|
PUTSHORT(q->type, p);
|
||||||
PUTSHORT(C_IN, p);
|
PUTSHORT(C_IN, p);
|
||||||
PUTLONG(0, p);
|
PUTLONG(0, p);
|
||||||
|
|
||||||
delayed_q_id = 0;
|
q->id = 0;
|
||||||
|
|
||||||
if(datalen > 0) {
|
if(datalen > 0) {
|
||||||
PUTSHORT(datalen, p);
|
PUTSHORT(datalen, p);
|
||||||
|
@ -474,7 +460,7 @@ dnsd_send(int fd, char *data, int datalen)
|
||||||
}
|
}
|
||||||
|
|
||||||
len = p - buf;
|
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
|
static int
|
||||||
|
@ -518,7 +504,7 @@ close_dnsd(int fd)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
dnsd_read(int fd, char *buf, int buflen)
|
dnsd_read(int fd, struct query *q, char *buf, int buflen)
|
||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
short id;
|
short id;
|
||||||
|
@ -554,11 +540,11 @@ dnsd_read(int fd, char *buf, int buflen)
|
||||||
READSHORT(class, data);
|
READSHORT(class, data);
|
||||||
|
|
||||||
// Store needed info about delayed response
|
// Store needed info about delayed response
|
||||||
strncpy(delayed_q_name, name, 256);
|
strncpy(q->name, name, 256);
|
||||||
delayed_q_type = type;
|
q->type = type;
|
||||||
delayed_q_id = id;
|
q->id = id;
|
||||||
delayed_q_fromlen = addrlen;
|
q->fromlen = addrlen;
|
||||||
memcpy((struct sockaddr*)&delayed_q_from, (struct sockaddr*)&from, addrlen);
|
memcpy((struct sockaddr*)&q->from, (struct sockaddr*)&from, addrlen);
|
||||||
|
|
||||||
return decodepacket(name, buf, buflen);
|
return decodepacket(name, buf, buflen);
|
||||||
}
|
}
|
||||||
|
|
6
dns.h
6
dns.h
|
@ -17,8 +17,6 @@
|
||||||
#ifndef _DNS_H_
|
#ifndef _DNS_H_
|
||||||
#define _DNS_H_
|
#define _DNS_H_
|
||||||
|
|
||||||
#define GOTHELLO -5
|
|
||||||
|
|
||||||
int open_dns(const char *, const char *);
|
int open_dns(const char *, const char *);
|
||||||
void close_dns(int);
|
void close_dns(int);
|
||||||
|
|
||||||
|
@ -34,8 +32,8 @@ extern struct sockaddr_in peer;
|
||||||
int open_dnsd(const char *);
|
int open_dnsd(const char *);
|
||||||
void close_dnsd(int);
|
void close_dnsd(int);
|
||||||
|
|
||||||
int dnsd_read(int, char *, int);
|
int dnsd_read(int, struct query*, char *, int);
|
||||||
void dnsd_send(int, char *, int);
|
void dnsd_send(int, struct query*, char *, int);
|
||||||
|
|
||||||
int dnsd_haspacket();
|
int dnsd_haspacket();
|
||||||
int dnsd_hasack();
|
int dnsd_hasack();
|
||||||
|
|
1
iodine.c
1
iodine.c
|
@ -29,6 +29,7 @@
|
||||||
#include <zlib.h>
|
#include <zlib.h>
|
||||||
|
|
||||||
#include "tun.h"
|
#include "tun.h"
|
||||||
|
#include "structs.h"
|
||||||
#include "dns.h"
|
#include "dns.h"
|
||||||
|
|
||||||
#ifndef MAX
|
#ifndef MAX
|
||||||
|
|
25
iodined.c
25
iodined.c
|
@ -29,6 +29,7 @@
|
||||||
#include <zlib.h>
|
#include <zlib.h>
|
||||||
|
|
||||||
#include "tun.h"
|
#include "tun.h"
|
||||||
|
#include "structs.h"
|
||||||
#include "dns.h"
|
#include "dns.h"
|
||||||
|
|
||||||
#ifndef MAX
|
#ifndef MAX
|
||||||
|
@ -37,17 +38,12 @@
|
||||||
|
|
||||||
int running = 1;
|
int running = 1;
|
||||||
|
|
||||||
struct packet
|
|
||||||
{
|
|
||||||
int len;
|
|
||||||
int offset;
|
|
||||||
char data[64*1024];
|
|
||||||
};
|
|
||||||
|
|
||||||
struct packet packetbuf;
|
struct packet packetbuf;
|
||||||
struct packet outpacket;
|
struct packet outpacket;
|
||||||
int outid;
|
int outid;
|
||||||
|
|
||||||
|
struct query q;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
sigint(int sig) {
|
sigint(int sig) {
|
||||||
running = 0;
|
running = 0;
|
||||||
|
@ -66,7 +62,7 @@ tunnel(int tun_fd, int dns_fd)
|
||||||
char out[64*1024];
|
char out[64*1024];
|
||||||
|
|
||||||
while (running) {
|
while (running) {
|
||||||
if (dnsd_hasack()) {
|
if (q.id != 0) {
|
||||||
tv.tv_sec = 0;
|
tv.tv_sec = 0;
|
||||||
tv.tv_usec = 5000;
|
tv.tv_usec = 5000;
|
||||||
} else {
|
} else {
|
||||||
|
@ -88,9 +84,10 @@ tunnel(int tun_fd, int dns_fd)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i==0) {
|
if (i==0) {
|
||||||
if (dnsd_hasack())
|
if (q.type != 0)
|
||||||
dnsd_send(dns_fd, outpacket.data, outpacket.len);
|
dnsd_send(dns_fd, &q, outpacket.data, outpacket.len);
|
||||||
outpacket.len = 0;
|
outpacket.len = 0;
|
||||||
|
q.id = 0;
|
||||||
} else {
|
} else {
|
||||||
if(FD_ISSET(tun_fd, &fds)) {
|
if(FD_ISSET(tun_fd, &fds)) {
|
||||||
read = read_tun(tun_fd, in, sizeof(in));
|
read = read_tun(tun_fd, in, sizeof(in));
|
||||||
|
@ -103,13 +100,13 @@ tunnel(int tun_fd, int dns_fd)
|
||||||
outpacket.len = outlen;
|
outpacket.len = outlen;
|
||||||
}
|
}
|
||||||
if(FD_ISSET(dns_fd, &fds)) {
|
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)
|
if (read < 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if(in[0] == 'H' || in[0] == 'h') {
|
if(in[0] == 'H' || in[0] == 'h') {
|
||||||
read = snprintf(out, sizeof(out), "%s-%d", "172.30.5.2", 1023);
|
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')
|
} else if((in[0] >= '0' && in[0] <= '9')
|
||||||
|| (in[0] >= 'a' && in[0] <= 'f')
|
|| (in[0] >= 'a' && in[0] <= 'f')
|
||||||
|| (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;
|
packetbuf.len = packetbuf.offset = 0;
|
||||||
}
|
}
|
||||||
if (outpacket.len > 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;
|
outpacket.len = 0;
|
||||||
|
q.id = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -194,6 +192,7 @@ main(int argc, char **argv)
|
||||||
packetbuf.len = 0;
|
packetbuf.len = 0;
|
||||||
packetbuf.offset = 0;
|
packetbuf.offset = 0;
|
||||||
outpacket.len = 0;
|
outpacket.len = 0;
|
||||||
|
q.id = 0;
|
||||||
|
|
||||||
while ((choice = getopt(argc, argv, "vfhu:t:m:")) != -1) {
|
while ((choice = getopt(argc, argv, "vfhu:t:m:")) != -1) {
|
||||||
switch(choice) {
|
switch(choice) {
|
||||||
|
|
|
@ -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 New Issue