mirror of
https://github.com/yarrick/iodine.git
synced 2024-11-21 23:59:19 +02:00
Remove trailing whitespace
This commit is contained in:
parent
388afe3845
commit
a23899513d
2
Makefile
2
Makefile
|
@ -16,7 +16,7 @@ RM_FLAGS=-f
|
||||||
|
|
||||||
TARGETOS = `uname`
|
TARGETOS = `uname`
|
||||||
|
|
||||||
all:
|
all:
|
||||||
@(cd src; $(MAKE) TARGETOS=$(TARGETOS) all)
|
@(cd src; $(MAKE) TARGETOS=$(TARGETOS) all)
|
||||||
|
|
||||||
install: all
|
install: all
|
||||||
|
|
|
@ -27,7 +27,7 @@ $(SERVER): $(COMMONOBJS) $(SERVEROBJS)
|
||||||
@mkdir -p ../bin
|
@mkdir -p ../bin
|
||||||
@$(CC) $(COMMONOBJS) $(SERVEROBJS) -o $(SERVER) $(LDFLAGS)
|
@$(CC) $(COMMONOBJS) $(SERVEROBJS) -o $(SERVER) $(LDFLAGS)
|
||||||
|
|
||||||
.c.o:
|
.c.o:
|
||||||
@echo CC $<
|
@echo CC $<
|
||||||
@$(CC) $(CFLAGS) $< -o $@
|
@$(CC) $(CFLAGS) $< -o $@
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
* accent chars since they might readily be entered in normal use,
|
* accent chars since they might readily be entered in normal use,
|
||||||
* don't use 254-255 because of possible function overloading in DNS systems.
|
* don't use 254-255 because of possible function overloading in DNS systems.
|
||||||
*/
|
*/
|
||||||
static const unsigned char cb128[] =
|
static const unsigned char cb128[] =
|
||||||
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
||||||
"\274\275\276\277"
|
"\274\275\276\277"
|
||||||
"\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317"
|
"\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317"
|
||||||
|
@ -75,19 +75,19 @@ struct encoder
|
||||||
return &base128_encoder;
|
return &base128_encoder;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
base128_handles_dots()
|
base128_handles_dots()
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
base128_blksize_raw()
|
base128_blksize_raw()
|
||||||
{
|
{
|
||||||
return BLKSIZE_RAW;
|
return BLKSIZE_RAW;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
base128_blksize_enc()
|
base128_blksize_enc()
|
||||||
{
|
{
|
||||||
return BLKSIZE_ENC;
|
return BLKSIZE_ENC;
|
||||||
|
@ -109,7 +109,7 @@ base128_reverse_init()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
base128_encode(char *buf, size_t *buflen, const void *data, size_t size)
|
base128_encode(char *buf, size_t *buflen, const void *data, size_t size)
|
||||||
/*
|
/*
|
||||||
* Fills *buf with max. *buflen characters, encoding size bytes of *data.
|
* Fills *buf with max. *buflen characters, encoding size bytes of *data.
|
||||||
|
@ -231,7 +231,7 @@ base128_decode(void *buf, size_t *buflen, const char *str, size_t slen)
|
||||||
if (iout >= *buflen || iin + 1 >= slen ||
|
if (iout >= *buflen || iin + 1 >= slen ||
|
||||||
str[iin] == '\0' || str[iin + 1] == '\0')
|
str[iin] == '\0' || str[iin + 1] == '\0')
|
||||||
break;
|
break;
|
||||||
ubuf[iout] = ((REV128(ustr[iin]) & 0x7f) << 1) |
|
ubuf[iout] = ((REV128(ustr[iin]) & 0x7f) << 1) |
|
||||||
((REV128(ustr[iin + 1]) & 0x40) >> 6);
|
((REV128(ustr[iin + 1]) & 0x40) >> 6);
|
||||||
iin++; /* 0 used up, iin=1 */
|
iin++; /* 0 used up, iin=1 */
|
||||||
iout++;
|
iout++;
|
||||||
|
|
18
src/base32.c
18
src/base32.c
|
@ -26,9 +26,9 @@
|
||||||
#define BLKSIZE_RAW 5
|
#define BLKSIZE_RAW 5
|
||||||
#define BLKSIZE_ENC 8
|
#define BLKSIZE_ENC 8
|
||||||
|
|
||||||
static const char cb32[] =
|
static const char cb32[] =
|
||||||
"abcdefghijklmnopqrstuvwxyz012345";
|
"abcdefghijklmnopqrstuvwxyz012345";
|
||||||
static const char cb32_ucase[] =
|
static const char cb32_ucase[] =
|
||||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ012345";
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZ012345";
|
||||||
static unsigned char rev32[256];
|
static unsigned char rev32[256];
|
||||||
static int reverse_init = 0;
|
static int reverse_init = 0;
|
||||||
|
@ -56,19 +56,19 @@ struct encoder
|
||||||
return &base32_encoder;
|
return &base32_encoder;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
base32_handles_dots()
|
base32_handles_dots()
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
base32_blksize_raw()
|
base32_blksize_raw()
|
||||||
{
|
{
|
||||||
return BLKSIZE_RAW;
|
return BLKSIZE_RAW;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
base32_blksize_enc()
|
base32_blksize_enc()
|
||||||
{
|
{
|
||||||
return BLKSIZE_ENC;
|
return BLKSIZE_ENC;
|
||||||
|
@ -105,7 +105,7 @@ b32_8to5(int in)
|
||||||
return rev32[in];
|
return rev32[in];
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
base32_encode(char *buf, size_t *buflen, const void *data, size_t size)
|
base32_encode(char *buf, size_t *buflen, const void *data, size_t size)
|
||||||
/*
|
/*
|
||||||
* Fills *buf with max. *buflen characters, encoding size bytes of *data.
|
* Fills *buf with max. *buflen characters, encoding size bytes of *data.
|
||||||
|
@ -223,7 +223,7 @@ base32_decode(void *buf, size_t *buflen, const char *str, size_t slen)
|
||||||
if (iout >= *buflen || iin + 1 >= slen ||
|
if (iout >= *buflen || iin + 1 >= slen ||
|
||||||
str[iin] == '\0' || str[iin + 1] == '\0')
|
str[iin] == '\0' || str[iin + 1] == '\0')
|
||||||
break;
|
break;
|
||||||
ubuf[iout] = ((REV32(str[iin]) & 0x1f) << 3) |
|
ubuf[iout] = ((REV32(str[iin]) & 0x1f) << 3) |
|
||||||
((REV32(str[iin + 1]) & 0x1c) >> 2);
|
((REV32(str[iin + 1]) & 0x1c) >> 2);
|
||||||
iin++; /* 0 used up, iin=1 */
|
iin++; /* 0 used up, iin=1 */
|
||||||
iout++;
|
iout++;
|
||||||
|
@ -232,8 +232,8 @@ base32_decode(void *buf, size_t *buflen, const char *str, size_t slen)
|
||||||
str[iin] == '\0' || str[iin + 1] == '\0' ||
|
str[iin] == '\0' || str[iin + 1] == '\0' ||
|
||||||
str[iin + 2] == '\0')
|
str[iin + 2] == '\0')
|
||||||
break;
|
break;
|
||||||
ubuf[iout] = ((REV32(str[iin]) & 0x03) << 6) |
|
ubuf[iout] = ((REV32(str[iin]) & 0x03) << 6) |
|
||||||
((REV32(str[iin + 1]) & 0x1f) << 1) |
|
((REV32(str[iin + 1]) & 0x1f) << 1) |
|
||||||
((REV32(str[iin + 2]) & 0x10) >> 4);
|
((REV32(str[iin + 2]) & 0x10) >> 4);
|
||||||
iin += 2; /* 1,2 used up, iin=3 */
|
iin += 2; /* 1,2 used up, iin=3 */
|
||||||
iout++;
|
iout++;
|
||||||
|
|
14
src/base64.c
14
src/base64.c
|
@ -28,7 +28,7 @@
|
||||||
|
|
||||||
/* Note: the "unofficial" char is last here, which means that the \377 pattern
|
/* Note: the "unofficial" char is last here, which means that the \377 pattern
|
||||||
in DOWNCODECCHECK1 ('Y' request) will properly test it. */
|
in DOWNCODECCHECK1 ('Y' request) will properly test it. */
|
||||||
static const char cb64[] =
|
static const char cb64[] =
|
||||||
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789+";
|
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789+";
|
||||||
static unsigned char rev64[256];
|
static unsigned char rev64[256];
|
||||||
static int reverse_init = 0;
|
static int reverse_init = 0;
|
||||||
|
@ -56,19 +56,19 @@ struct encoder
|
||||||
return &base64_encoder;
|
return &base64_encoder;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
base64_handles_dots()
|
base64_handles_dots()
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
base64_blksize_raw()
|
base64_blksize_raw()
|
||||||
{
|
{
|
||||||
return BLKSIZE_RAW;
|
return BLKSIZE_RAW;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
base64_blksize_enc()
|
base64_blksize_enc()
|
||||||
{
|
{
|
||||||
return BLKSIZE_ENC;
|
return BLKSIZE_ENC;
|
||||||
|
@ -90,7 +90,7 @@ base64_reverse_init()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
base64_encode(char *buf, size_t *buflen, const void *data, size_t size)
|
base64_encode(char *buf, size_t *buflen, const void *data, size_t size)
|
||||||
/*
|
/*
|
||||||
* Fills *buf with max. *buflen characters, encoding size bytes of *data.
|
* Fills *buf with max. *buflen characters, encoding size bytes of *data.
|
||||||
|
@ -178,7 +178,7 @@ base64_decode(void *buf, size_t *buflen, const char *str, size_t slen)
|
||||||
if (iout >= *buflen || iin + 1 >= slen ||
|
if (iout >= *buflen || iin + 1 >= slen ||
|
||||||
str[iin] == '\0' || str[iin + 1] == '\0')
|
str[iin] == '\0' || str[iin + 1] == '\0')
|
||||||
break;
|
break;
|
||||||
ubuf[iout] = ((REV64(str[iin]) & 0x3f) << 2) |
|
ubuf[iout] = ((REV64(str[iin]) & 0x3f) << 2) |
|
||||||
((REV64(str[iin + 1]) & 0x30) >> 4);
|
((REV64(str[iin + 1]) & 0x30) >> 4);
|
||||||
iin++; /* 0 used up, iin=1 */
|
iin++; /* 0 used up, iin=1 */
|
||||||
iout++;
|
iout++;
|
||||||
|
@ -186,7 +186,7 @@ base64_decode(void *buf, size_t *buflen, const char *str, size_t slen)
|
||||||
if (iout >= *buflen || iin + 1 >= slen ||
|
if (iout >= *buflen || iin + 1 >= slen ||
|
||||||
str[iin] == '\0' || str[iin + 1] == '\0')
|
str[iin] == '\0' || str[iin + 1] == '\0')
|
||||||
break;
|
break;
|
||||||
ubuf[iout] = ((REV64(str[iin]) & 0x0f) << 4) |
|
ubuf[iout] = ((REV64(str[iin]) & 0x0f) << 4) |
|
||||||
((REV64(str[iin + 1]) & 0x3c) >> 2);
|
((REV64(str[iin + 1]) & 0x3c) >> 2);
|
||||||
iin++; /* 1 used up, iin=2 */
|
iin++; /* 1 used up, iin=2 */
|
||||||
iout++;
|
iout++;
|
||||||
|
|
74
src/client.c
74
src/client.c
|
@ -93,10 +93,10 @@ static struct encoder *b128;
|
||||||
/* The encoder used for data packets
|
/* The encoder used for data packets
|
||||||
* Defaults to Base32, can be changed after handshake */
|
* Defaults to Base32, can be changed after handshake */
|
||||||
static struct encoder *dataenc;
|
static struct encoder *dataenc;
|
||||||
|
|
||||||
/* The encoder to use for downstream data */
|
/* The encoder to use for downstream data */
|
||||||
static char downenc = ' ';
|
static char downenc = ' ';
|
||||||
|
|
||||||
/* set query type to send */
|
/* set query type to send */
|
||||||
static unsigned short do_qtype = T_UNSET;
|
static unsigned short do_qtype = T_UNSET;
|
||||||
|
|
||||||
|
@ -214,7 +214,7 @@ set_downenc(char *encoding)
|
||||||
downenc = 'R';
|
downenc = 'R';
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
client_set_selecttimeout(int select_timeout)
|
client_set_selecttimeout(int select_timeout)
|
||||||
{
|
{
|
||||||
selecttimeout = select_timeout;
|
selecttimeout = select_timeout;
|
||||||
|
@ -333,7 +333,7 @@ send_packet(int fd, char cmd, const char *data, const size_t datalen)
|
||||||
char buf[4096];
|
char buf[4096];
|
||||||
|
|
||||||
buf[0] = cmd;
|
buf[0] = cmd;
|
||||||
|
|
||||||
build_hostname(buf + 1, sizeof(buf) - 1, data, datalen, topdomain,
|
build_hostname(buf + 1, sizeof(buf) - 1, data, datalen, topdomain,
|
||||||
b32, hostname_maxlen);
|
b32, hostname_maxlen);
|
||||||
send_query(fd, buf);
|
send_query(fd, buf);
|
||||||
|
@ -366,7 +366,7 @@ send_chunk(int fd)
|
||||||
/* Build upstream data header (see doc/proto_xxxxxxxx.txt) */
|
/* Build upstream data header (see doc/proto_xxxxxxxx.txt) */
|
||||||
|
|
||||||
buf[0] = userid_char; /* First byte is hex userid */
|
buf[0] = userid_char; /* First byte is hex userid */
|
||||||
|
|
||||||
code = ((outpkt.seqno & 7) << 2) | ((outpkt.fragment & 15) >> 2);
|
code = ((outpkt.seqno & 7) << 2) | ((outpkt.fragment & 15) >> 2);
|
||||||
buf[1] = b32_5to8(code); /* Second byte is 3 bits seqno, 2 upper bits fragment count */
|
buf[1] = b32_5to8(code); /* Second byte is 3 bits seqno, 2 upper bits fragment count */
|
||||||
|
|
||||||
|
@ -380,7 +380,7 @@ send_chunk(int fd)
|
||||||
datacmc++;
|
datacmc++;
|
||||||
if (datacmc >= 36)
|
if (datacmc >= 36)
|
||||||
datacmc = 0;
|
datacmc = 0;
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
fprintf(stderr, " Send: down %d/%d up %d/%d, %d bytes\n",
|
fprintf(stderr, " Send: down %d/%d up %d/%d, %d bytes\n",
|
||||||
inpkt.seqno, inpkt.fragment, outpkt.seqno, outpkt.fragment,
|
inpkt.seqno, inpkt.fragment, outpkt.seqno, outpkt.fragment,
|
||||||
|
@ -395,12 +395,12 @@ send_ping(int fd)
|
||||||
{
|
{
|
||||||
if (conn == CONN_DNS_NULL) {
|
if (conn == CONN_DNS_NULL) {
|
||||||
char data[4];
|
char data[4];
|
||||||
|
|
||||||
data[0] = userid;
|
data[0] = userid;
|
||||||
data[1] = ((inpkt.seqno & 7) << 4) | (inpkt.fragment & 15);
|
data[1] = ((inpkt.seqno & 7) << 4) | (inpkt.fragment & 15);
|
||||||
data[2] = (rand_seed >> 8) & 0xff;
|
data[2] = (rand_seed >> 8) & 0xff;
|
||||||
data[3] = (rand_seed >> 0) & 0xff;
|
data[3] = (rand_seed >> 0) & 0xff;
|
||||||
|
|
||||||
rand_seed++;
|
rand_seed++;
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
|
@ -566,7 +566,7 @@ read_dns_withq(int dns_fd, int tun_fd, char *buf, int buflen, struct query *q)
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
addrlen = sizeof(from);
|
addrlen = sizeof(from);
|
||||||
if ((r = recvfrom(dns_fd, data, sizeof(data), 0,
|
if ((r = recvfrom(dns_fd, data, sizeof(data), 0,
|
||||||
(struct sockaddr*)&from, &addrlen)) < 0) {
|
(struct sockaddr*)&from, &addrlen)) < 0) {
|
||||||
warn("recvfrom");
|
warn("recvfrom");
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -588,9 +588,9 @@ read_dns_withq(int dns_fd, int tun_fd, char *buf, int buflen, struct query *q)
|
||||||
/*
|
/*
|
||||||
* buf is a hostname or txt stream that we still need to
|
* buf is a hostname or txt stream that we still need to
|
||||||
* decode to binary
|
* decode to binary
|
||||||
*
|
*
|
||||||
* also update rv with the number of valid bytes
|
* also update rv with the number of valid bytes
|
||||||
*
|
*
|
||||||
* data is unused here, and will certainly hold the smaller binary
|
* data is unused here, and will certainly hold the smaller binary
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -1131,11 +1131,11 @@ client_tunnel(int tun_fd, int dns_fd)
|
||||||
warnx("No downstream data received in 60 seconds, shutting down.");
|
warnx("No downstream data received in 60 seconds, shutting down.");
|
||||||
running = 0;
|
running = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (running == 0)
|
if (running == 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (i < 0)
|
if (i < 0)
|
||||||
err(1, "select");
|
err(1, "select");
|
||||||
|
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
|
@ -1178,7 +1178,7 @@ client_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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1196,7 +1196,7 @@ send_login(int fd, char *login, int len)
|
||||||
|
|
||||||
data[17] = (rand_seed >> 8) & 0xff;
|
data[17] = (rand_seed >> 8) & 0xff;
|
||||||
data[18] = (rand_seed >> 0) & 0xff;
|
data[18] = (rand_seed >> 0) & 0xff;
|
||||||
|
|
||||||
rand_seed++;
|
rand_seed++;
|
||||||
|
|
||||||
send_packet(fd, 'l', data, sizeof(data));
|
send_packet(fd, 'l', data, sizeof(data));
|
||||||
|
@ -1235,23 +1235,23 @@ static void
|
||||||
send_set_downstream_fragsize(int fd, int fragsize)
|
send_set_downstream_fragsize(int fd, int fragsize)
|
||||||
{
|
{
|
||||||
char data[5];
|
char data[5];
|
||||||
|
|
||||||
data[0] = userid;
|
data[0] = userid;
|
||||||
data[1] = (fragsize & 0xff00) >> 8;
|
data[1] = (fragsize & 0xff00) >> 8;
|
||||||
data[2] = (fragsize & 0x00ff);
|
data[2] = (fragsize & 0x00ff);
|
||||||
data[3] = (rand_seed >> 8) & 0xff;
|
data[3] = (rand_seed >> 8) & 0xff;
|
||||||
data[4] = (rand_seed >> 0) & 0xff;
|
data[4] = (rand_seed >> 0) & 0xff;
|
||||||
|
|
||||||
rand_seed++;
|
rand_seed++;
|
||||||
|
|
||||||
send_packet(fd, 'n', data, sizeof(data));
|
send_packet(fd, 'n', data, sizeof(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
send_version(int fd, uint32_t version)
|
send_version(int fd, uint32_t version)
|
||||||
{
|
{
|
||||||
char data[6];
|
char data[6];
|
||||||
|
|
||||||
data[0] = (version >> 24) & 0xff;
|
data[0] = (version >> 24) & 0xff;
|
||||||
data[1] = (version >> 16) & 0xff;
|
data[1] = (version >> 16) & 0xff;
|
||||||
data[2] = (version >> 8) & 0xff;
|
data[2] = (version >> 8) & 0xff;
|
||||||
|
@ -1259,7 +1259,7 @@ send_version(int fd, uint32_t version)
|
||||||
|
|
||||||
data[4] = (rand_seed >> 8) & 0xff;
|
data[4] = (rand_seed >> 8) & 0xff;
|
||||||
data[5] = (rand_seed >> 0) & 0xff;
|
data[5] = (rand_seed >> 0) & 0xff;
|
||||||
|
|
||||||
rand_seed++;
|
rand_seed++;
|
||||||
|
|
||||||
send_packet(fd, 'v', data, sizeof(data));
|
send_packet(fd, 'v', data, sizeof(data));
|
||||||
|
@ -1270,7 +1270,7 @@ send_ip_request(int fd, int userid)
|
||||||
{
|
{
|
||||||
char buf[512] = "i____.";
|
char buf[512] = "i____.";
|
||||||
buf[1] = b32_5to8(userid);
|
buf[1] = b32_5to8(userid);
|
||||||
|
|
||||||
buf[2] = b32_5to8((rand_seed >> 10) & 0x1f);
|
buf[2] = b32_5to8((rand_seed >> 10) & 0x1f);
|
||||||
buf[3] = b32_5to8((rand_seed >> 5) & 0x1f);
|
buf[3] = b32_5to8((rand_seed >> 5) & 0x1f);
|
||||||
buf[4] = b32_5to8((rand_seed ) & 0x1f);
|
buf[4] = b32_5to8((rand_seed ) & 0x1f);
|
||||||
|
@ -1294,7 +1294,7 @@ send_upenctest(int fd, char *s)
|
||||||
/* NOTE: String may be at most 63-4=59 chars to fit in 1 dns chunk. */
|
/* NOTE: String may be at most 63-4=59 chars to fit in 1 dns chunk. */
|
||||||
{
|
{
|
||||||
char buf[512] = "z___";
|
char buf[512] = "z___";
|
||||||
|
|
||||||
buf[1] = b32_5to8((rand_seed >> 10) & 0x1f);
|
buf[1] = b32_5to8((rand_seed >> 10) & 0x1f);
|
||||||
buf[2] = b32_5to8((rand_seed >> 5) & 0x1f);
|
buf[2] = b32_5to8((rand_seed >> 5) & 0x1f);
|
||||||
buf[3] = b32_5to8((rand_seed ) & 0x1f);
|
buf[3] = b32_5to8((rand_seed ) & 0x1f);
|
||||||
|
@ -1330,7 +1330,7 @@ send_codec_switch(int fd, int userid, int bits)
|
||||||
char buf[512] = "s_____.";
|
char buf[512] = "s_____.";
|
||||||
buf[1] = b32_5to8(userid);
|
buf[1] = b32_5to8(userid);
|
||||||
buf[2] = b32_5to8(bits);
|
buf[2] = b32_5to8(bits);
|
||||||
|
|
||||||
buf[3] = b32_5to8((rand_seed >> 10) & 0x1f);
|
buf[3] = b32_5to8((rand_seed >> 10) & 0x1f);
|
||||||
buf[4] = b32_5to8((rand_seed >> 5) & 0x1f);
|
buf[4] = b32_5to8((rand_seed >> 5) & 0x1f);
|
||||||
buf[5] = b32_5to8((rand_seed ) & 0x1f);
|
buf[5] = b32_5to8((rand_seed ) & 0x1f);
|
||||||
|
@ -1408,7 +1408,7 @@ handshake_version(int dns_fd, int *seed)
|
||||||
fprintf(stderr, "Version ok, both using protocol v 0x%08x. You are user #%d\n", VERSION, userid);
|
fprintf(stderr, "Version ok, both using protocol v 0x%08x. You are user #%d\n", VERSION, userid);
|
||||||
return 0;
|
return 0;
|
||||||
} else if (strncmp("VNAK", in, 4) == 0) {
|
} else if (strncmp("VNAK", in, 4) == 0) {
|
||||||
warnx("You use protocol v 0x%08x, server uses v 0x%08x. Giving up",
|
warnx("You use protocol v 0x%08x, server uses v 0x%08x. Giving up",
|
||||||
VERSION, payload);
|
VERSION, payload);
|
||||||
return 1;
|
return 1;
|
||||||
} else if (strncmp("VFUL", in, 4) == 0) {
|
} else if (strncmp("VFUL", in, 4) == 0) {
|
||||||
|
@ -1417,7 +1417,7 @@ handshake_version(int dns_fd, int *seed)
|
||||||
}
|
}
|
||||||
} else if (read > 0)
|
} else if (read > 0)
|
||||||
warnx("did not receive proper login challenge");
|
warnx("did not receive proper login challenge");
|
||||||
|
|
||||||
fprintf(stderr, "Retrying version check...\n");
|
fprintf(stderr, "Retrying version check...\n");
|
||||||
}
|
}
|
||||||
warnx("couldn't connect to server (maybe other -T options will work)");
|
warnx("couldn't connect to server (maybe other -T options will work)");
|
||||||
|
@ -1436,7 +1436,7 @@ handshake_login(int dns_fd, int seed)
|
||||||
int read;
|
int read;
|
||||||
|
|
||||||
login_calculate(login, 16, password, seed);
|
login_calculate(login, 16, password, seed);
|
||||||
|
|
||||||
for (i=0; running && i<5 ;i++) {
|
for (i=0; running && i<5 ;i++) {
|
||||||
|
|
||||||
send_login(dns_fd, login, 16);
|
send_login(dns_fd, login, 16);
|
||||||
|
@ -1510,7 +1510,7 @@ handshake_raw_udp(int dns_fd, int seed)
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
if (!running)
|
if (!running)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (!remoteaddr) {
|
if (!remoteaddr) {
|
||||||
fprintf(stderr, "Failed to get raw server IP, will use DNS mode.\n");
|
fprintf(stderr, "Failed to get raw server IP, will use DNS mode.\n");
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1524,7 +1524,7 @@ handshake_raw_udp(int dns_fd, int seed)
|
||||||
raw_serv.sin_port = htons(53);
|
raw_serv.sin_port = htons(53);
|
||||||
raw_serv.sin_addr = server;
|
raw_serv.sin_addr = server;
|
||||||
|
|
||||||
/* do login against port 53 on remote server
|
/* do login against port 53 on remote server
|
||||||
* based on the old seed. If reply received,
|
* based on the old seed. If reply received,
|
||||||
* switch to raw udp mode */
|
* switch to raw udp mode */
|
||||||
for (i=0; running && i<4 ;i++) {
|
for (i=0; running && i<4 ;i++) {
|
||||||
|
@ -1532,7 +1532,7 @@ handshake_raw_udp(int dns_fd, int seed)
|
||||||
tv.tv_usec = 0;
|
tv.tv_usec = 0;
|
||||||
|
|
||||||
send_raw_udp_login(dns_fd, userid, seed);
|
send_raw_udp_login(dns_fd, userid, seed);
|
||||||
|
|
||||||
FD_ZERO(&fds);
|
FD_ZERO(&fds);
|
||||||
FD_SET(dns_fd, &fds);
|
FD_SET(dns_fd, &fds);
|
||||||
|
|
||||||
|
@ -1545,7 +1545,7 @@ handshake_raw_udp(int dns_fd, int seed)
|
||||||
char hash[16];
|
char hash[16];
|
||||||
login_calculate(hash, 16, password, seed - 1);
|
login_calculate(hash, 16, password, seed - 1);
|
||||||
if (memcmp(in, raw_header, RAW_HDR_IDENT_LEN) == 0
|
if (memcmp(in, raw_header, RAW_HDR_IDENT_LEN) == 0
|
||||||
&& RAW_HDR_GET_CMD(in) == RAW_HDR_CMD_LOGIN
|
&& RAW_HDR_GET_CMD(in) == RAW_HDR_CMD_LOGIN
|
||||||
&& memcmp(&in[RAW_HDR_LEN], hash, sizeof(hash)) == 0) {
|
&& memcmp(&in[RAW_HDR_LEN], hash, sizeof(hash)) == 0) {
|
||||||
|
|
||||||
fprintf(stderr, "OK\n");
|
fprintf(stderr, "OK\n");
|
||||||
|
@ -1556,7 +1556,7 @@ handshake_raw_udp(int dns_fd, int seed)
|
||||||
fprintf(stderr, ".");
|
fprintf(stderr, ".");
|
||||||
fflush(stderr);
|
fflush(stderr);
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stderr, "failed\n");
|
fprintf(stderr, "failed\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -2024,7 +2024,7 @@ handshake_switch_codec(int dns_fd, int bits)
|
||||||
for (i=0; running && i<5 ;i++) {
|
for (i=0; running && i<5 ;i++) {
|
||||||
|
|
||||||
send_codec_switch(dns_fd, userid, bits);
|
send_codec_switch(dns_fd, userid, bits);
|
||||||
|
|
||||||
read = handshake_waitdns(dns_fd, in, sizeof(in), 's', 'S', i+1);
|
read = handshake_waitdns(dns_fd, in, sizeof(in), 's', 'S', i+1);
|
||||||
|
|
||||||
if (read > 0) {
|
if (read > 0) {
|
||||||
|
@ -2051,7 +2051,7 @@ handshake_switch_codec(int dns_fd, int bits)
|
||||||
|
|
||||||
fprintf(stderr, "No reply from server on codec switch. ");
|
fprintf(stderr, "No reply from server on codec switch. ");
|
||||||
|
|
||||||
codec_revert:
|
codec_revert:
|
||||||
fprintf(stderr, "Falling back to upstream codec %s\n", dataenc->name);
|
fprintf(stderr, "Falling back to upstream codec %s\n", dataenc->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2103,7 +2103,7 @@ handshake_switch_downenc(int dns_fd)
|
||||||
|
|
||||||
fprintf(stderr, "No reply from server on codec switch. ");
|
fprintf(stderr, "No reply from server on codec switch. ");
|
||||||
|
|
||||||
codec_revert:
|
codec_revert:
|
||||||
fprintf(stderr, "Falling back to downstream codec Base32\n");
|
fprintf(stderr, "Falling back to downstream codec Base32\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2145,7 +2145,7 @@ handshake_try_lazy(int dns_fd)
|
||||||
|
|
||||||
fprintf(stderr, "No reply from server on lazy switch. ");
|
fprintf(stderr, "No reply from server on lazy switch. ");
|
||||||
|
|
||||||
codec_revert:
|
codec_revert:
|
||||||
fprintf(stderr, "Falling back to legacy mode\n");
|
fprintf(stderr, "Falling back to legacy mode\n");
|
||||||
lazymode = 0;
|
lazymode = 0;
|
||||||
selecttimeout = 1;
|
selecttimeout = 1;
|
||||||
|
@ -2262,7 +2262,7 @@ handshake_autoprobe_fragsize(int dns_fd)
|
||||||
int max_fragsize;
|
int max_fragsize;
|
||||||
|
|
||||||
max_fragsize = 0;
|
max_fragsize = 0;
|
||||||
fprintf(stderr, "Autoprobing max downstream fragment size... (skip with -m fragsize)\n");
|
fprintf(stderr, "Autoprobing max downstream fragment size... (skip with -m fragsize)\n");
|
||||||
while (running && range > 0 && (range >= 8 || max_fragsize < 300)) {
|
while (running && range > 0 && (range >= 8 || max_fragsize < 300)) {
|
||||||
/* stop the slow probing early when we have enough bytes anyway */
|
/* stop the slow probing early when we have enough bytes anyway */
|
||||||
for (i=0; running && i<3 ;i++) {
|
for (i=0; running && i<3 ;i++) {
|
||||||
|
@ -2270,7 +2270,7 @@ handshake_autoprobe_fragsize(int dns_fd)
|
||||||
send_fragsize_probe(dns_fd, proposed_fragsize);
|
send_fragsize_probe(dns_fd, proposed_fragsize);
|
||||||
|
|
||||||
read = handshake_waitdns(dns_fd, in, sizeof(in), 'r', 'R', 1);
|
read = handshake_waitdns(dns_fd, in, sizeof(in), 'r', 'R', 1);
|
||||||
|
|
||||||
if (read > 0) {
|
if (read > 0) {
|
||||||
/* We got a reply */
|
/* We got a reply */
|
||||||
if (fragsize_check(in, read, proposed_fragsize, &max_fragsize) == 1)
|
if (fragsize_check(in, read, proposed_fragsize, &max_fragsize) == 1)
|
||||||
|
|
18
src/common.c
18
src/common.c
|
@ -61,7 +61,7 @@ const unsigned char raw_header[RAW_HDR_LEN] = { 0x10, 0xd1, 0x9e, 0x00 };
|
||||||
static int daemon(int nochdir, int noclose)
|
static int daemon(int nochdir, int noclose)
|
||||||
{
|
{
|
||||||
int fd, i;
|
int fd, i;
|
||||||
|
|
||||||
switch (fork()) {
|
switch (fork()) {
|
||||||
case 0:
|
case 0:
|
||||||
break;
|
break;
|
||||||
|
@ -70,15 +70,15 @@ static int daemon(int nochdir, int noclose)
|
||||||
default:
|
default:
|
||||||
_exit(0);
|
_exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!nochdir) {
|
if (!nochdir) {
|
||||||
chdir("/");
|
chdir("/");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (setsid() < 0) {
|
if (setsid() < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!noclose) {
|
if (!noclose) {
|
||||||
if ((fd = open("/dev/null", O_RDWR)) >= 0) {
|
if ((fd = open("/dev/null", O_RDWR)) >= 0) {
|
||||||
for (i = 0; i < 3; i++) {
|
for (i = 0; i < 3; i++) {
|
||||||
|
@ -170,7 +170,7 @@ get_addr(char *host, int port, int addr_family, int flags, struct sockaddr_stora
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
open_dns(struct sockaddr_storage *sockaddr, size_t sockaddr_len)
|
open_dns(struct sockaddr_storage *sockaddr, size_t sockaddr_len)
|
||||||
{
|
{
|
||||||
int flag = 1;
|
int flag = 1;
|
||||||
|
@ -291,7 +291,7 @@ read_password(char *buf, size_t len)
|
||||||
|
|
||||||
tcgetattr(0, &tp);
|
tcgetattr(0, &tp);
|
||||||
old = tp;
|
old = tp;
|
||||||
|
|
||||||
tp.c_lflag &= (~ECHO);
|
tp.c_lflag &= (~ECHO);
|
||||||
tcsetattr(0, TCSANOW, &tp);
|
tcsetattr(0, TCSANOW, &tp);
|
||||||
#else
|
#else
|
||||||
|
@ -317,7 +317,7 @@ read_password(char *buf, size_t len)
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
|
|
||||||
#ifndef WINDOWS32
|
#ifndef WINDOWS32
|
||||||
tcsetattr(0, TCSANOW, &old);
|
tcsetattr(0, TCSANOW, &old);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
strncpy(buf, pwd, len);
|
strncpy(buf, pwd, len);
|
||||||
|
@ -360,7 +360,7 @@ check_topdomain(char *str, char **errormsg)
|
||||||
} else {
|
} else {
|
||||||
chunklen++;
|
chunklen++;
|
||||||
}
|
}
|
||||||
if( (str[i] >= 'a' && str[i] <= 'z') || (str[i] >= 'A' && str[i] <= 'Z') ||
|
if( (str[i] >= 'a' && str[i] <= 'z') || (str[i] >= 'A' && str[i] <= 'Z') ||
|
||||||
isdigit(str[i]) || str[i] == '-' || str[i] == '.' ) {
|
isdigit(str[i]) || str[i] == '-' || str[i] == '.' ) {
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
|
@ -404,7 +404,7 @@ warn(const char *fmt, ...)
|
||||||
if (fmt) fprintf(stderr, fmt, list);
|
if (fmt) fprintf(stderr, fmt, list);
|
||||||
#ifndef ANDROID
|
#ifndef ANDROID
|
||||||
if (errno == 0) {
|
if (errno == 0) {
|
||||||
fprintf(stderr, ": WSA error %d\n", WSAGetLastError());
|
fprintf(stderr, ": WSA error %d\n", WSAGetLastError());
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, ": %s\n", strerror(errno));
|
fprintf(stderr, ": %s\n", strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
14
src/common.h
14
src/common.h
|
@ -53,12 +53,12 @@ extern const unsigned char raw_header[RAW_HDR_LEN];
|
||||||
|
|
||||||
#define QUERY_NAME_SIZE 256
|
#define QUERY_NAME_SIZE 256
|
||||||
|
|
||||||
#if defined IP_RECVDSTADDR
|
#if defined IP_RECVDSTADDR
|
||||||
# define DSTADDR_SOCKOPT IP_RECVDSTADDR
|
# define DSTADDR_SOCKOPT IP_RECVDSTADDR
|
||||||
# define dstaddr(x) ((struct in_addr *) CMSG_DATA(x))
|
# define dstaddr(x) ((struct in_addr *) CMSG_DATA(x))
|
||||||
#elif defined IP_PKTINFO
|
#elif defined IP_PKTINFO
|
||||||
# define DSTADDR_SOCKOPT IP_PKTINFO
|
# define DSTADDR_SOCKOPT IP_PKTINFO
|
||||||
# define dstaddr(x) (&(((struct in_pktinfo *)(CMSG_DATA(x)))->ipi_addr))
|
# define dstaddr(x) (&(((struct in_pktinfo *)(CMSG_DATA(x)))->ipi_addr))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined IP_MTU_DISCOVER
|
#if defined IP_MTU_DISCOVER
|
||||||
|
@ -78,7 +78,7 @@ extern const unsigned char raw_header[RAW_HDR_LEN];
|
||||||
#define T_UNSET 65432
|
#define T_UNSET 65432
|
||||||
/* Unused RR type; "private use" range, see http://www.bind9.net/dns-parameters */
|
/* Unused RR type; "private use" range, see http://www.bind9.net/dns-parameters */
|
||||||
|
|
||||||
struct packet
|
struct packet
|
||||||
{
|
{
|
||||||
int len; /* Total packet length */
|
int len; /* Total packet length */
|
||||||
int sentlen; /* Length of chunk currently transmitted */
|
int sentlen; /* Length of chunk currently transmitted */
|
||||||
|
|
48
src/dns.c
48
src/dns.c
|
@ -62,9 +62,9 @@ dns_encode(char *buf, size_t buflen, struct query *q, qr_t qr, char *data, size_
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
memset(buf, 0, buflen);
|
memset(buf, 0, buflen);
|
||||||
|
|
||||||
header = (HEADER*)buf;
|
header = (HEADER*)buf;
|
||||||
|
|
||||||
header->id = htons(q->id);
|
header->id = htons(q->id);
|
||||||
header->qr = (qr == QR_ANSWER);
|
header->qr = (qr == QR_ANSWER);
|
||||||
header->opcode = 0;
|
header->opcode = 0;
|
||||||
|
@ -78,7 +78,7 @@ dns_encode(char *buf, size_t buflen, struct query *q, qr_t qr, char *data, size_
|
||||||
switch (qr) {
|
switch (qr) {
|
||||||
case QR_ANSWER:
|
case QR_ANSWER:
|
||||||
header->qdcount = htons(1);
|
header->qdcount = htons(1);
|
||||||
|
|
||||||
name = 0xc000 | ((p - buf) & 0x3fff);
|
name = 0xc000 | ((p - buf) & 0x3fff);
|
||||||
|
|
||||||
/* Question section */
|
/* Question section */
|
||||||
|
@ -97,7 +97,7 @@ dns_encode(char *buf, size_t buflen, struct query *q, qr_t qr, char *data, size_
|
||||||
int namelen;
|
int namelen;
|
||||||
|
|
||||||
CHECKLEN(10);
|
CHECKLEN(10);
|
||||||
putshort(&p, name);
|
putshort(&p, name);
|
||||||
if (q->type == T_A)
|
if (q->type == T_A)
|
||||||
/* answer CNAME to A question */
|
/* answer CNAME to A question */
|
||||||
putshort(&p, T_CNAME);
|
putshort(&p, T_CNAME);
|
||||||
|
@ -127,7 +127,7 @@ dns_encode(char *buf, size_t buflen, struct query *q, qr_t qr, char *data, size_
|
||||||
ancnt = 1;
|
ancnt = 1;
|
||||||
while (1) {
|
while (1) {
|
||||||
CHECKLEN(10);
|
CHECKLEN(10);
|
||||||
putshort(&p, name);
|
putshort(&p, name);
|
||||||
putshort(&p, q->type);
|
putshort(&p, q->type);
|
||||||
putshort(&p, C_IN);
|
putshort(&p, C_IN);
|
||||||
putlong(&p, 0); /* TTL */
|
putlong(&p, 0); /* TTL */
|
||||||
|
@ -162,7 +162,7 @@ dns_encode(char *buf, size_t buflen, struct query *q, qr_t qr, char *data, size_
|
||||||
int txtlen;
|
int txtlen;
|
||||||
|
|
||||||
CHECKLEN(10);
|
CHECKLEN(10);
|
||||||
putshort(&p, name);
|
putshort(&p, name);
|
||||||
putshort(&p, q->type);
|
putshort(&p, q->type);
|
||||||
putshort(&p, C_IN);
|
putshort(&p, C_IN);
|
||||||
putlong(&p, 0); /* TTL */
|
putlong(&p, 0); /* TTL */
|
||||||
|
@ -179,7 +179,7 @@ dns_encode(char *buf, size_t buflen, struct query *q, qr_t qr, char *data, size_
|
||||||
/* NULL has raw binary data */
|
/* NULL has raw binary data */
|
||||||
|
|
||||||
CHECKLEN(10);
|
CHECKLEN(10);
|
||||||
putshort(&p, name);
|
putshort(&p, name);
|
||||||
putshort(&p, q->type);
|
putshort(&p, q->type);
|
||||||
putshort(&p, C_IN);
|
putshort(&p, C_IN);
|
||||||
putlong(&p, 0); /* TTL */
|
putlong(&p, 0); /* TTL */
|
||||||
|
@ -198,7 +198,7 @@ dns_encode(char *buf, size_t buflen, struct query *q, qr_t qr, char *data, size_
|
||||||
/* Note that iodined also uses this for forward queries */
|
/* Note that iodined also uses this for forward queries */
|
||||||
|
|
||||||
header->qdcount = htons(1);
|
header->qdcount = htons(1);
|
||||||
|
|
||||||
datalen = MIN(datalen, buflen - (p - buf));
|
datalen = MIN(datalen, buflen - (p - buf));
|
||||||
putname(&p, datalen, data);
|
putname(&p, datalen, data);
|
||||||
|
|
||||||
|
@ -221,7 +221,7 @@ dns_encode(char *buf, size_t buflen, struct query *q, qr_t qr, char *data, size_
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
len = p - buf;
|
len = p - buf;
|
||||||
|
|
||||||
return len;
|
return len;
|
||||||
|
@ -245,9 +245,9 @@ dns_encode_ns_response(char *buf, size_t buflen, struct query *q, char *topdomai
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
memset(buf, 0, buflen);
|
memset(buf, 0, buflen);
|
||||||
|
|
||||||
header = (HEADER*)buf;
|
header = (HEADER*)buf;
|
||||||
|
|
||||||
header->id = htons(q->id);
|
header->id = htons(q->id);
|
||||||
header->qr = 1;
|
header->qr = 1;
|
||||||
header->opcode = 0;
|
header->opcode = 0;
|
||||||
|
@ -334,9 +334,9 @@ dns_encode_a_response(char *buf, size_t buflen, struct query *q)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
memset(buf, 0, buflen);
|
memset(buf, 0, buflen);
|
||||||
|
|
||||||
header = (HEADER*)buf;
|
header = (HEADER*)buf;
|
||||||
|
|
||||||
header->id = htons(q->id);
|
header->id = htons(q->id);
|
||||||
header->qr = 1;
|
header->qr = 1;
|
||||||
header->opcode = 0;
|
header->opcode = 0;
|
||||||
|
@ -408,7 +408,7 @@ dns_decode(char *buf, size_t buflen, struct query *q, qr_t qr, char *packet, siz
|
||||||
short type;
|
short type;
|
||||||
char *data;
|
char *data;
|
||||||
short rlen;
|
short rlen;
|
||||||
int id;
|
int id;
|
||||||
int rv;
|
int rv;
|
||||||
|
|
||||||
q->id2 = 0;
|
q->id2 = 0;
|
||||||
|
@ -416,9 +416,9 @@ dns_decode(char *buf, size_t buflen, struct query *q, qr_t qr, char *packet, siz
|
||||||
header = (HEADER*)packet;
|
header = (HEADER*)packet;
|
||||||
|
|
||||||
/* Reject short packets */
|
/* Reject short packets */
|
||||||
if (packetlen < sizeof(HEADER))
|
if (packetlen < sizeof(HEADER))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (header->qr != qr) {
|
if (header->qr != qr) {
|
||||||
warnx("header->qr does not match the requested qr");
|
warnx("header->qr does not match the requested qr");
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -427,13 +427,13 @@ dns_decode(char *buf, size_t buflen, struct query *q, qr_t qr, char *packet, siz
|
||||||
data = packet + sizeof(HEADER);
|
data = packet + sizeof(HEADER);
|
||||||
qdcount = ntohs(header->qdcount);
|
qdcount = ntohs(header->qdcount);
|
||||||
ancount = ntohs(header->ancount);
|
ancount = ntohs(header->ancount);
|
||||||
|
|
||||||
id = ntohs(header->id);
|
id = ntohs(header->id);
|
||||||
id = id & 0xFFFF; /* Kill any sign extension */
|
id = id & 0xFFFF; /* Kill any sign extension */
|
||||||
|
|
||||||
rlen = 0;
|
rlen = 0;
|
||||||
|
|
||||||
if (q != NULL)
|
if (q != NULL)
|
||||||
q->rcode = header->rcode;
|
q->rcode = header->rcode;
|
||||||
|
|
||||||
switch (qr) {
|
switch (qr) {
|
||||||
|
@ -443,7 +443,7 @@ dns_decode(char *buf, size_t buflen, struct query *q, qr_t qr, char *packet, siz
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (q != NULL)
|
if (q != NULL)
|
||||||
q->id = id;
|
q->id = id;
|
||||||
|
|
||||||
/* Read name even if no answer, to give better error message */
|
/* Read name even if no answer, to give better error message */
|
||||||
|
@ -451,14 +451,14 @@ dns_decode(char *buf, size_t buflen, struct query *q, qr_t qr, char *packet, siz
|
||||||
CHECKLEN(4);
|
CHECKLEN(4);
|
||||||
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 CHECKLEN okay, then we're sure to have a proper name */
|
||||||
if (q != NULL) {
|
if (q != NULL) {
|
||||||
/* We only need the first char to check it */
|
/* We only need the first char to check it */
|
||||||
q->name[0] = name[0];
|
q->name[0] = name[0];
|
||||||
q->name[1] = '\0';
|
q->name[1] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ancount < 1) {
|
if (ancount < 1) {
|
||||||
/* DNS errors like NXDOMAIN have ancount=0 and
|
/* DNS errors like NXDOMAIN have ancount=0 and
|
||||||
stop here. CNAME may also have A; MX/SRV may have
|
stop here. CNAME may also have A; MX/SRV may have
|
||||||
|
@ -539,7 +539,7 @@ dns_decode(char *buf, size_t buflen, struct query *q, qr_t qr, char *packet, siz
|
||||||
names[pref / 10 - 1][QUERY_NAME_SIZE-1] = '\0';
|
names[pref / 10 - 1][QUERY_NAME_SIZE-1] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
/* always trust rlen, not name encoding */
|
/* always trust rlen, not name encoding */
|
||||||
data = rdatastart + rlen;
|
data = rdatastart + rlen;
|
||||||
CHECKLEN(0);
|
CHECKLEN(0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,8 +20,8 @@
|
||||||
#include "encoding.h"
|
#include "encoding.h"
|
||||||
|
|
||||||
int
|
int
|
||||||
build_hostname(char *buf, size_t buflen,
|
build_hostname(char *buf, size_t buflen,
|
||||||
const char *data, const size_t datalen,
|
const char *data, const size_t datalen,
|
||||||
const char *topdomain, struct encoder *encoder, int maxlen)
|
const char *topdomain, struct encoder *encoder, int maxlen)
|
||||||
{
|
{
|
||||||
size_t space;
|
size_t space;
|
||||||
|
@ -34,7 +34,7 @@ build_hostname(char *buf, size_t buflen,
|
||||||
space -= (space / 57); /* space for dots */
|
space -= (space / 57); /* space for dots */
|
||||||
|
|
||||||
memset(buf, 0, buflen);
|
memset(buf, 0, buflen);
|
||||||
|
|
||||||
encoder->encode(buf, &space, data, datalen);
|
encoder->encode(buf, &space, data, datalen);
|
||||||
|
|
||||||
if (!encoder->places_dots())
|
if (!encoder->places_dots())
|
||||||
|
@ -45,7 +45,7 @@ build_hostname(char *buf, size_t buflen,
|
||||||
|
|
||||||
/* move b back one step to see if the dot is there */
|
/* move b back one step to see if the dot is there */
|
||||||
b--;
|
b--;
|
||||||
if (*b != '.')
|
if (*b != '.')
|
||||||
*++b = '.';
|
*++b = '.';
|
||||||
b++;
|
b++;
|
||||||
/* move b ahead of the string so we can copy to it */
|
/* move b ahead of the string so we can copy to it */
|
||||||
|
@ -63,7 +63,7 @@ unpack_data(char *buf, size_t buflen, char *data, size_t datalen, struct encoder
|
||||||
return enc->decode(buf, &buflen, data, datalen);
|
return enc->decode(buf, &buflen, data, datalen);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
inline_dotify(char *buf, size_t buflen)
|
inline_dotify(char *buf, size_t buflen)
|
||||||
{
|
{
|
||||||
unsigned dots;
|
unsigned dots;
|
||||||
|
@ -101,7 +101,7 @@ inline_dotify(char *buf, size_t buflen)
|
||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
inline_undotify(char *buf, size_t len)
|
inline_undotify(char *buf, size_t len)
|
||||||
{
|
{
|
||||||
unsigned pos;
|
unsigned pos;
|
||||||
|
@ -124,7 +124,7 @@ inline_undotify(char *buf, size_t len)
|
||||||
*writer++ = *reader++;
|
*writer++ = *reader++;
|
||||||
pos++;
|
pos++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* return new length of string */
|
/* return new length of string */
|
||||||
return len - dots;
|
return len - dots;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,9 +29,9 @@ void fw_query_init()
|
||||||
void fw_query_put(struct fw_query *fw_query)
|
void fw_query_put(struct fw_query *fw_query)
|
||||||
{
|
{
|
||||||
memcpy(&(fwq[fwq_ix]), fw_query, sizeof(struct fw_query));
|
memcpy(&(fwq[fwq_ix]), fw_query, sizeof(struct fw_query));
|
||||||
|
|
||||||
++fwq_ix;
|
++fwq_ix;
|
||||||
if (fwq_ix >= FW_QUERY_CACHE_SIZE)
|
if (fwq_ix >= FW_QUERY_CACHE_SIZE)
|
||||||
fwq_ix = 0;
|
fwq_ix = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
28
src/iodine.c
28
src/iodine.c
|
@ -53,7 +53,7 @@ static char *__progname;
|
||||||
#define PASSWORD_ENV_VAR "IODINE_PASS"
|
#define PASSWORD_ENV_VAR "IODINE_PASS"
|
||||||
|
|
||||||
static void
|
static void
|
||||||
sighandler(int sig)
|
sighandler(int sig)
|
||||||
{
|
{
|
||||||
client_stop();
|
client_stop();
|
||||||
}
|
}
|
||||||
|
@ -179,7 +179,7 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
srand((unsigned) time(NULL));
|
srand((unsigned) time(NULL));
|
||||||
client_init();
|
client_init();
|
||||||
|
|
||||||
#if !defined(BSD) && !defined(__GLIBC__)
|
#if !defined(BSD) && !defined(__GLIBC__)
|
||||||
__progname = strrchr(argv[0], '/');
|
__progname = strrchr(argv[0], '/');
|
||||||
if (__progname == NULL)
|
if (__progname == NULL)
|
||||||
|
@ -227,9 +227,9 @@ main(int argc, char **argv)
|
||||||
case 'P':
|
case 'P':
|
||||||
strncpy(password, optarg, sizeof(password));
|
strncpy(password, optarg, sizeof(password));
|
||||||
password[sizeof(password)-1] = 0;
|
password[sizeof(password)-1] = 0;
|
||||||
|
|
||||||
/* XXX: find better way of cleaning up ps(1) */
|
/* XXX: find better way of cleaning up ps(1) */
|
||||||
memset(optarg, 0, strlen(optarg));
|
memset(optarg, 0, strlen(optarg));
|
||||||
break;
|
break;
|
||||||
case 'm':
|
case 'm':
|
||||||
autodetect_frag_size = 0;
|
autodetect_frag_size = 0;
|
||||||
|
@ -247,7 +247,7 @@ main(int argc, char **argv)
|
||||||
break;
|
break;
|
||||||
case 'F':
|
case 'F':
|
||||||
pidfile = optarg;
|
pidfile = optarg;
|
||||||
break;
|
break;
|
||||||
case 'T':
|
case 'T':
|
||||||
set_qtype(optarg);
|
set_qtype(optarg);
|
||||||
break;
|
break;
|
||||||
|
@ -273,7 +273,7 @@ main(int argc, char **argv)
|
||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
check_superuser(usage);
|
check_superuser(usage);
|
||||||
|
|
||||||
argc -= optind;
|
argc -= optind;
|
||||||
|
@ -310,7 +310,7 @@ main(int argc, char **argv)
|
||||||
warnx("No nameserver found - not connected to any network?\n");
|
warnx("No nameserver found - not connected to any network?\n");
|
||||||
usage();
|
usage();
|
||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
}
|
}
|
||||||
|
|
||||||
if(check_topdomain(topdomain, &errormsg)) {
|
if(check_topdomain(topdomain, &errormsg)) {
|
||||||
warnx("Invalid topdomain: %s", errormsg);
|
warnx("Invalid topdomain: %s", errormsg);
|
||||||
|
@ -322,7 +322,7 @@ main(int argc, char **argv)
|
||||||
client_set_lazymode(lazymode);
|
client_set_lazymode(lazymode);
|
||||||
client_set_topdomain(topdomain);
|
client_set_topdomain(topdomain);
|
||||||
client_set_hostname_maxlen(hostname_maxlen);
|
client_set_hostname_maxlen(hostname_maxlen);
|
||||||
|
|
||||||
if (username != NULL) {
|
if (username != NULL) {
|
||||||
#ifndef WINDOWS32
|
#ifndef WINDOWS32
|
||||||
if ((pw = getpwnam(username)) == NULL) {
|
if ((pw = getpwnam(username)) == NULL) {
|
||||||
|
@ -332,14 +332,14 @@ main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strlen(password) == 0) {
|
if (strlen(password) == 0) {
|
||||||
if (NULL != getenv(PASSWORD_ENV_VAR))
|
if (NULL != getenv(PASSWORD_ENV_VAR))
|
||||||
snprintf(password, sizeof(password), "%s", getenv(PASSWORD_ENV_VAR));
|
snprintf(password, sizeof(password), "%s", getenv(PASSWORD_ENV_VAR));
|
||||||
else
|
else
|
||||||
read_password(password, sizeof(password));
|
read_password(password, sizeof(password));
|
||||||
}
|
}
|
||||||
|
|
||||||
client_set_password(password);
|
client_set_password(password);
|
||||||
|
|
||||||
if ((tun_fd = open_tun(device)) == -1) {
|
if ((tun_fd = open_tun(device)) == -1) {
|
||||||
|
@ -365,22 +365,22 @@ main(int argc, char **argv)
|
||||||
retval = 1;
|
retval = 1;
|
||||||
goto cleanup2;
|
goto cleanup2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (client_get_conn() == CONN_RAW_UDP) {
|
if (client_get_conn() == CONN_RAW_UDP) {
|
||||||
fprintf(stderr, "Sending raw traffic directly to %s\n", client_get_raw_addr());
|
fprintf(stderr, "Sending raw traffic directly to %s\n", client_get_raw_addr());
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stderr, "Connection setup complete, transmitting data.\n");
|
fprintf(stderr, "Connection setup complete, transmitting data.\n");
|
||||||
|
|
||||||
if (foreground == 0)
|
if (foreground == 0)
|
||||||
do_detach();
|
do_detach();
|
||||||
|
|
||||||
if (pidfile != NULL)
|
if (pidfile != NULL)
|
||||||
do_pidfile(pidfile);
|
do_pidfile(pidfile);
|
||||||
|
|
||||||
if (newroot != NULL)
|
if (newroot != NULL)
|
||||||
do_chroot(newroot);
|
do_chroot(newroot);
|
||||||
|
|
||||||
if (username != NULL) {
|
if (username != NULL) {
|
||||||
#ifndef WINDOWS32
|
#ifndef WINDOWS32
|
||||||
gid_t gids[1];
|
gid_t gids[1];
|
||||||
|
|
148
src/iodined.c
148
src/iodined.c
|
@ -152,7 +152,7 @@ static int get_external_ip(struct in_addr *ip)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
sigint(int sig)
|
sigint(int sig)
|
||||||
{
|
{
|
||||||
running = 0;
|
running = 0;
|
||||||
}
|
}
|
||||||
|
@ -182,7 +182,7 @@ check_user_and_ip(int userid, struct query *q)
|
||||||
/* Note: duplicate in handle_raw_login() except IP-address check */
|
/* Note: duplicate in handle_raw_login() except IP-address check */
|
||||||
|
|
||||||
if (userid < 0 || userid >= created_users ) {
|
if (userid < 0 || userid >= created_users ) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (!users[userid].active || users[userid].disabled) {
|
if (!users[userid].active || users[userid].disabled) {
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -217,7 +217,7 @@ send_raw(int fd, char *buf, int buflen, int user, int cmd, struct query *q)
|
||||||
packet[RAW_HDR_CMD] = cmd | (user & 0x0F);
|
packet[RAW_HDR_CMD] = cmd | (user & 0x0F);
|
||||||
|
|
||||||
if (debug >= 2) {
|
if (debug >= 2) {
|
||||||
fprintf(stderr, "TX-raw: client %s, cmd %d, %d bytes\n",
|
fprintf(stderr, "TX-raw: client %s, cmd %d, %d bytes\n",
|
||||||
format_addr(&q->from, q->fromlen), cmd, len);
|
format_addr(&q->from, q->fromlen), cmd, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -552,12 +552,12 @@ send_chunk_or_dataless(int dns_fd, int userid, struct query *q)
|
||||||
pkt[0] = (1<<7) | ((users[userid].inpacket.seqno & 7) << 4) |
|
pkt[0] = (1<<7) | ((users[userid].inpacket.seqno & 7) << 4) |
|
||||||
(users[userid].inpacket.fragment & 15);
|
(users[userid].inpacket.fragment & 15);
|
||||||
/* Second byte is 3 bits downstream seqno, 4 bits downstream fragment, 1 bit last flag */
|
/* Second byte is 3 bits downstream seqno, 4 bits downstream fragment, 1 bit last flag */
|
||||||
pkt[1] = ((users[userid].outpacket.seqno & 7) << 5) |
|
pkt[1] = ((users[userid].outpacket.seqno & 7) << 5) |
|
||||||
((users[userid].outpacket.fragment & 15) << 1) | (last & 1);
|
((users[userid].outpacket.fragment & 15) << 1) | (last & 1);
|
||||||
|
|
||||||
if (debug >= 1) {
|
if (debug >= 1) {
|
||||||
fprintf(stderr, "OUT pkt seq# %d, frag %d (last=%d), offset %d, fragsize %d, total %d, to user %d\n",
|
fprintf(stderr, "OUT pkt seq# %d, frag %d (last=%d), offset %d, fragsize %d, total %d, to user %d\n",
|
||||||
users[userid].outpacket.seqno & 7, users[userid].outpacket.fragment & 15,
|
users[userid].outpacket.seqno & 7, users[userid].outpacket.fragment & 15,
|
||||||
last, users[userid].outpacket.offset, datalen, users[userid].outpacket.len, userid);
|
last, users[userid].outpacket.offset, datalen, users[userid].outpacket.len, userid);
|
||||||
}
|
}
|
||||||
write_dns(dns_fd, q, pkt, datalen + 2, users[userid].downenc);
|
write_dns(dns_fd, q, pkt, datalen + 2, users[userid].downenc);
|
||||||
|
@ -611,7 +611,7 @@ tunnel_tun(int tun_fd, int dns_fd)
|
||||||
|
|
||||||
if ((read = read_tun(tun_fd, in, sizeof(in))) <= 0)
|
if ((read = read_tun(tun_fd, in, sizeof(in))) <= 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* find target ip in packet, in is padded with 4 bytes TUN header */
|
/* find target ip in packet, in is padded with 4 bytes TUN header */
|
||||||
header = (struct ip*) (in + 4);
|
header = (struct ip*) (in + 4);
|
||||||
userid = find_user_by_ip(header->ip_dst.s_addr);
|
userid = find_user_by_ip(header->ip_dst.s_addr);
|
||||||
|
@ -657,7 +657,7 @@ static void
|
||||||
send_version_response(int fd, version_ack_t ack, uint32_t payload, int userid, struct query *q)
|
send_version_response(int fd, version_ack_t ack, uint32_t payload, int userid, struct query *q)
|
||||||
{
|
{
|
||||||
char out[9];
|
char out[9];
|
||||||
|
|
||||||
switch (ack) {
|
switch (ack) {
|
||||||
case VERSION_ACK:
|
case VERSION_ACK:
|
||||||
strncpy(out, "VACK", sizeof(out));
|
strncpy(out, "VACK", sizeof(out));
|
||||||
|
@ -669,7 +669,7 @@ send_version_response(int fd, version_ack_t ack, uint32_t payload, int userid, s
|
||||||
strncpy(out, "VFUL", sizeof(out));
|
strncpy(out, "VFUL", sizeof(out));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
out[4] = ((payload >> 24) & 0xff);
|
out[4] = ((payload >> 24) & 0xff);
|
||||||
out[5] = ((payload >> 16) & 0xff);
|
out[5] = ((payload >> 16) & 0xff);
|
||||||
out[6] = ((payload >> 8) & 0xff);
|
out[6] = ((payload >> 8) & 0xff);
|
||||||
|
@ -742,7 +742,7 @@ handle_null_request(int tun_fd, int dns_fd, struct query *q, int domain_len)
|
||||||
|
|
||||||
read = unpack_data(unpacked, sizeof(unpacked), &(in[1]), domain_len - 1, b32);
|
read = unpack_data(unpacked, sizeof(unpacked), &(in[1]), domain_len - 1, b32);
|
||||||
/* Version greeting, compare and send ack/nak */
|
/* Version greeting, compare and send ack/nak */
|
||||||
if (read > 4) {
|
if (read > 4) {
|
||||||
/* Received V + 32bits version */
|
/* Received V + 32bits version */
|
||||||
version = (((unpacked[0] & 0xff) << 24) |
|
version = (((unpacked[0] & 0xff) << 24) |
|
||||||
((unpacked[1] & 0xff) << 16) |
|
((unpacked[1] & 0xff) << 16) |
|
||||||
|
@ -760,7 +760,7 @@ handle_null_request(int tun_fd, int dns_fd, struct query *q, int domain_len)
|
||||||
/* Store remote IP number */
|
/* Store remote IP number */
|
||||||
tempin = (struct sockaddr_in *) &(q->from);
|
tempin = (struct sockaddr_in *) &(q->from);
|
||||||
memcpy(&(users[userid].host), &(tempin->sin_addr), sizeof(struct in_addr));
|
memcpy(&(users[userid].host), &(tempin->sin_addr), sizeof(struct in_addr));
|
||||||
|
|
||||||
memcpy(&(users[userid].q), q, sizeof(struct query));
|
memcpy(&(users[userid].q), q, sizeof(struct query));
|
||||||
users[userid].encoder = get_base32_encoder();
|
users[userid].encoder = get_base32_encoder();
|
||||||
users[userid].downenc = 'T';
|
users[userid].downenc = 'T';
|
||||||
|
@ -807,12 +807,12 @@ handle_null_request(int tun_fd, int dns_fd, struct query *q, int domain_len)
|
||||||
} 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);
|
||||||
syslog(LOG_INFO, "dropped user from %s, server full",
|
syslog(LOG_INFO, "dropped user from %s, server full",
|
||||||
format_addr(&q->from, q->fromlen));
|
format_addr(&q->from, q->fromlen));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
send_version_response(dns_fd, VERSION_NACK, VERSION, 0, q);
|
send_version_response(dns_fd, VERSION_NACK, VERSION, 0, q);
|
||||||
syslog(LOG_INFO, "dropped user from %s, sent bad version %08X",
|
syslog(LOG_INFO, "dropped user from %s, sent bad version %08X",
|
||||||
format_addr(&q->from, q->fromlen), version);
|
format_addr(&q->from, q->fromlen), version);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
@ -843,7 +843,7 @@ handle_null_request(int tun_fd, int dns_fd, struct query *q, int domain_len)
|
||||||
tempip.s_addr = users[userid].tun_ip;
|
tempip.s_addr = users[userid].tun_ip;
|
||||||
tmp[1] = strdup(inet_ntoa(tempip));
|
tmp[1] = strdup(inet_ntoa(tempip));
|
||||||
|
|
||||||
read = snprintf(out, sizeof(out), "%s-%s-%d-%d",
|
read = snprintf(out, sizeof(out), "%s-%s-%d-%d",
|
||||||
tmp[0], tmp[1], my_mtu, netmask);
|
tmp[0], tmp[1], my_mtu, netmask);
|
||||||
|
|
||||||
write_dns(dns_fd, q, out, read, users[userid].downenc);
|
write_dns(dns_fd, q, out, read, users[userid].downenc);
|
||||||
|
@ -864,7 +864,7 @@ handle_null_request(int tun_fd, int dns_fd, struct query *q, int domain_len)
|
||||||
in_addr_t replyaddr;
|
in_addr_t replyaddr;
|
||||||
unsigned addr;
|
unsigned addr;
|
||||||
char reply[5];
|
char reply[5];
|
||||||
|
|
||||||
userid = b32_8to5(in[1]);
|
userid = b32_8to5(in[1]);
|
||||||
if (check_user_and_ip(userid, q) != 0) {
|
if (check_user_and_ip(userid, q) != 0) {
|
||||||
write_dns(dns_fd, q, "BADIP", 5, 'T');
|
write_dns(dns_fd, q, "BADIP", 5, 'T');
|
||||||
|
@ -902,12 +902,12 @@ handle_null_request(int tun_fd, int dns_fd, struct query *q, int domain_len)
|
||||||
}
|
}
|
||||||
|
|
||||||
userid = b32_8to5(in[1]);
|
userid = b32_8to5(in[1]);
|
||||||
|
|
||||||
if (check_user_and_ip(userid, q) != 0) {
|
if (check_user_and_ip(userid, q) != 0) {
|
||||||
write_dns(dns_fd, q, "BADIP", 5, 'T');
|
write_dns(dns_fd, q, "BADIP", 5, 'T');
|
||||||
return; /* illegal id */
|
return; /* illegal id */
|
||||||
}
|
}
|
||||||
|
|
||||||
codec = b32_8to5(in[2]);
|
codec = b32_8to5(in[2]);
|
||||||
|
|
||||||
switch (codec) {
|
switch (codec) {
|
||||||
|
@ -1076,9 +1076,9 @@ handle_null_request(int tun_fd, int dns_fd, struct query *q, int domain_len)
|
||||||
write_dns(dns_fd, q, "BADIP", 5, 'T');
|
write_dns(dns_fd, q, "BADIP", 5, 'T');
|
||||||
return; /* illegal id */
|
return; /* illegal id */
|
||||||
}
|
}
|
||||||
|
|
||||||
req_frag_size = ((b32_8to5(in[1]) & 1) << 10) | ((b32_8to5(in[2]) & 31) << 5) | (b32_8to5(in[3]) & 31);
|
req_frag_size = ((b32_8to5(in[1]) & 1) << 10) | ((b32_8to5(in[2]) & 31) << 5) | (b32_8to5(in[3]) & 31);
|
||||||
if (req_frag_size < 2 || req_frag_size > 2047) {
|
if (req_frag_size < 2 || req_frag_size > 2047) {
|
||||||
write_dns(dns_fd, q, "BADFRAG", 7, users[userid].downenc);
|
write_dns(dns_fd, q, "BADFRAG", 7, users[userid].downenc);
|
||||||
} else {
|
} else {
|
||||||
char buf[2048];
|
char buf[2048];
|
||||||
|
@ -1111,9 +1111,9 @@ handle_null_request(int tun_fd, int dns_fd, struct query *q, int domain_len)
|
||||||
write_dns(dns_fd, q, "BADIP", 5, 'T');
|
write_dns(dns_fd, q, "BADIP", 5, 'T');
|
||||||
return; /* illegal id */
|
return; /* illegal id */
|
||||||
}
|
}
|
||||||
|
|
||||||
max_frag_size = ((unpacked[1] & 0xff) << 8) | (unpacked[2] & 0xff);
|
max_frag_size = ((unpacked[1] & 0xff) << 8) | (unpacked[2] & 0xff);
|
||||||
if (max_frag_size < 2) {
|
if (max_frag_size < 2) {
|
||||||
write_dns(dns_fd, q, "BADFRAG", 7, users[userid].downenc);
|
write_dns(dns_fd, q, "BADFRAG", 7, users[userid].downenc);
|
||||||
} else {
|
} else {
|
||||||
users[userid].fragsize = max_frag_size;
|
users[userid].fragsize = max_frag_size;
|
||||||
|
@ -1178,7 +1178,7 @@ handle_null_request(int tun_fd, int dns_fd, struct query *q, int domain_len)
|
||||||
memcpy(&(users[userid].q.from2), &(q->from), q->fromlen);
|
memcpy(&(users[userid].q.from2), &(q->from), q->fromlen);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (users[userid].q_sendrealsoon.id != 0 &&
|
if (users[userid].q_sendrealsoon.id != 0 &&
|
||||||
q->type == users[userid].q_sendrealsoon.type &&
|
q->type == users[userid].q_sendrealsoon.type &&
|
||||||
!strcmp(q->name, users[userid].q_sendrealsoon.name)) {
|
!strcmp(q->name, users[userid].q_sendrealsoon.name)) {
|
||||||
|
@ -1194,7 +1194,7 @@ handle_null_request(int tun_fd, int dns_fd, struct query *q, int domain_len)
|
||||||
&(q->from), q->fromlen);
|
&(q->from), q->fromlen);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
dn_seq = unpacked[1] >> 4;
|
dn_seq = unpacked[1] >> 4;
|
||||||
dn_frag = unpacked[1] & 15;
|
dn_frag = unpacked[1] & 15;
|
||||||
|
|
||||||
|
@ -1289,7 +1289,7 @@ handle_null_request(int tun_fd, int dns_fd, struct query *q, int domain_len)
|
||||||
like to re-try early and often (with _different_ .id!) */
|
like to re-try early and often (with _different_ .id!) */
|
||||||
if (users[userid].q.id != 0 &&
|
if (users[userid].q.id != 0 &&
|
||||||
q->type == users[userid].q.type &&
|
q->type == users[userid].q.type &&
|
||||||
!strcmp(q->name, users[userid].q.name) &&
|
!strcmp(q->name, users[userid].q.name) &&
|
||||||
users[userid].lazy) {
|
users[userid].lazy) {
|
||||||
/* We have this packet already, and it's waiting to be
|
/* We have this packet already, and it's waiting to be
|
||||||
answered. Always keep the last duplicate, since the
|
answered. Always keep the last duplicate, since the
|
||||||
|
@ -1306,7 +1306,7 @@ handle_null_request(int tun_fd, int dns_fd, struct query *q, int domain_len)
|
||||||
memcpy(&(users[userid].q.from2), &(q->from), q->fromlen);
|
memcpy(&(users[userid].q.from2), &(q->from), q->fromlen);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (users[userid].q_sendrealsoon.id != 0 &&
|
if (users[userid].q_sendrealsoon.id != 0 &&
|
||||||
q->type == users[userid].q_sendrealsoon.type &&
|
q->type == users[userid].q_sendrealsoon.type &&
|
||||||
!strcmp(q->name, users[userid].q_sendrealsoon.name)) {
|
!strcmp(q->name, users[userid].q_sendrealsoon.name)) {
|
||||||
|
@ -1322,7 +1322,7 @@ handle_null_request(int tun_fd, int dns_fd, struct query *q, int domain_len)
|
||||||
&(q->from), q->fromlen);
|
&(q->from), q->fromlen);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Decode data header */
|
/* Decode data header */
|
||||||
up_seq = (b32_8to5(in[1]) >> 2) & 7;
|
up_seq = (b32_8to5(in[1]) >> 2) & 7;
|
||||||
|
@ -1333,7 +1333,7 @@ handle_null_request(int tun_fd, int dns_fd, struct query *q, int domain_len)
|
||||||
|
|
||||||
process_downstream_ack(userid, dn_seq, dn_frag);
|
process_downstream_ack(userid, dn_seq, dn_frag);
|
||||||
|
|
||||||
if (up_seq == users[userid].inpacket.seqno &&
|
if (up_seq == users[userid].inpacket.seqno &&
|
||||||
up_frag <= users[userid].inpacket.fragment) {
|
up_frag <= users[userid].inpacket.fragment) {
|
||||||
/* Got repeated old packet _with data_, probably
|
/* Got repeated old packet _with data_, probably
|
||||||
because client didn't receive our ack. So re-send
|
because client didn't receive our ack. So re-send
|
||||||
|
@ -1491,9 +1491,9 @@ handle_ns_request(int dns_fd, struct query *q)
|
||||||
warnx("dns_encode_ns_response doesn't fit");
|
warnx("dns_encode_ns_response doesn't fit");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (debug >= 2) {
|
if (debug >= 2) {
|
||||||
fprintf(stderr, "TX: client %s, type %d, name %s, %d bytes NS reply\n",
|
fprintf(stderr, "TX: client %s, type %d, name %s, %d bytes NS reply\n",
|
||||||
format_addr(&q->from, q->fromlen), q->type, q->name, len);
|
format_addr(&q->from, q->fromlen), q->type, q->name, len);
|
||||||
}
|
}
|
||||||
if (sendto(dns_fd, buf, len, 0, (struct sockaddr*)&q->from, q->fromlen) <= 0) {
|
if (sendto(dns_fd, buf, len, 0, (struct sockaddr*)&q->from, q->fromlen) <= 0) {
|
||||||
|
@ -1523,7 +1523,7 @@ handle_a_request(int dns_fd, struct query *q, int fakeip)
|
||||||
warnx("dns_encode_a_response doesn't fit");
|
warnx("dns_encode_a_response doesn't fit");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (debug >= 2) {
|
if (debug >= 2) {
|
||||||
fprintf(stderr, "TX: client %s, type %d, name %s, %d bytes A reply\n",
|
fprintf(stderr, "TX: client %s, type %d, name %s, %d bytes A reply\n",
|
||||||
format_addr(&q->from, q->fromlen), q->type, q->name, len);
|
format_addr(&q->from, q->fromlen), q->type, q->name, len);
|
||||||
|
@ -1558,7 +1558,7 @@ forward_query(int bind_fd, struct query *q)
|
||||||
myaddr = (struct sockaddr_in *) &(q->from);
|
myaddr = (struct sockaddr_in *) &(q->from);
|
||||||
memcpy(&(myaddr->sin_addr), &newaddr, sizeof(in_addr_t));
|
memcpy(&(myaddr->sin_addr), &newaddr, sizeof(in_addr_t));
|
||||||
myaddr->sin_port = htons(bind_port);
|
myaddr->sin_port = htons(bind_port);
|
||||||
|
|
||||||
if (debug >= 2) {
|
if (debug >= 2) {
|
||||||
fprintf(stderr, "TX: NS reply \n");
|
fprintf(stderr, "TX: NS reply \n");
|
||||||
}
|
}
|
||||||
|
@ -1567,7 +1567,7 @@ forward_query(int bind_fd, struct query *q)
|
||||||
warn("forward query error");
|
warn("forward query error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
tunnel_bind(int bind_fd, int dns_fd)
|
tunnel_bind(int bind_fd, int dns_fd)
|
||||||
{
|
{
|
||||||
|
@ -1579,14 +1579,14 @@ tunnel_bind(int bind_fd, int dns_fd)
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
fromlen = sizeof(struct sockaddr);
|
fromlen = sizeof(struct sockaddr);
|
||||||
r = recvfrom(bind_fd, packet, sizeof(packet), 0,
|
r = recvfrom(bind_fd, packet, sizeof(packet), 0,
|
||||||
(struct sockaddr*)&from, &fromlen);
|
(struct sockaddr*)&from, &fromlen);
|
||||||
|
|
||||||
if (r <= 0)
|
if (r <= 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
id = dns_get_id(packet, r);
|
id = dns_get_id(packet, r);
|
||||||
|
|
||||||
if (debug >= 2) {
|
if (debug >= 2) {
|
||||||
fprintf(stderr, "RX: Got response on query %u from DNS\n", (id & 0xFFFF));
|
fprintf(stderr, "RX: Got response on query %u from DNS\n", (id & 0xFFFF));
|
||||||
}
|
}
|
||||||
|
@ -1604,8 +1604,8 @@ tunnel_bind(int bind_fd, int dns_fd)
|
||||||
fprintf(stderr, "TX: client %s id %u, %d bytes\n",
|
fprintf(stderr, "TX: client %s id %u, %d bytes\n",
|
||||||
format_addr(&query->addr, query->addrlen), (id & 0xffff), r);
|
format_addr(&query->addr, query->addrlen), (id & 0xffff), r);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sendto(dns_fd, packet, r, 0, (const struct sockaddr *) &(query->addr),
|
if (sendto(dns_fd, packet, r, 0, (const struct sockaddr *) &(query->addr),
|
||||||
query->addrlen) <= 0) {
|
query->addrlen) <= 0) {
|
||||||
warn("forward reply error");
|
warn("forward reply error");
|
||||||
}
|
}
|
||||||
|
@ -1625,7 +1625,7 @@ tunnel_dns(int tun_fd, int dns_fd, int bind_fd)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (debug >= 2) {
|
if (debug >= 2) {
|
||||||
fprintf(stderr, "RX: client %s, type %d, name %s\n",
|
fprintf(stderr, "RX: client %s, type %d, name %s\n",
|
||||||
format_addr(&q.from, q.fromlen), q.type, q.name);
|
format_addr(&q.from, q.fromlen), q.type, q.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1736,9 +1736,9 @@ tunnel(int tun_fd, int dns_fd, int bind_fd, int max_idle_time)
|
||||||
}
|
}
|
||||||
|
|
||||||
i = select(maxfd + 1, &fds, NULL, NULL, &tv);
|
i = select(maxfd + 1, &fds, NULL, NULL, &tv);
|
||||||
|
|
||||||
if(i < 0) {
|
if(i < 0) {
|
||||||
if (running)
|
if (running)
|
||||||
warn("select");
|
warn("select");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -1763,7 +1763,7 @@ tunnel(int tun_fd, int dns_fd, int bind_fd, int max_idle_time)
|
||||||
}
|
}
|
||||||
if (FD_ISSET(dns_fd, &fds)) {
|
if (FD_ISSET(dns_fd, &fds)) {
|
||||||
tunnel_dns(tun_fd, dns_fd, bind_fd);
|
tunnel_dns(tun_fd, dns_fd, bind_fd);
|
||||||
}
|
}
|
||||||
if (FD_ISSET(bind_fd, &fds)) {
|
if (FD_ISSET(bind_fd, &fds)) {
|
||||||
tunnel_bind(bind_fd, dns_fd);
|
tunnel_bind(bind_fd, dns_fd);
|
||||||
}
|
}
|
||||||
|
@ -1791,7 +1791,7 @@ handle_full_packet(int tun_fd, int dns_fd, int userid)
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
outlen = sizeof(out);
|
outlen = sizeof(out);
|
||||||
ret = uncompress((uint8_t*)out, &outlen,
|
ret = uncompress((uint8_t*)out, &outlen,
|
||||||
(uint8_t*)users[userid].inpacket.data, users[userid].inpacket.len);
|
(uint8_t*)users[userid].inpacket.data, users[userid].inpacket.len);
|
||||||
|
|
||||||
if (ret == Z_OK) {
|
if (ret == Z_OK) {
|
||||||
|
@ -1843,7 +1843,7 @@ static void
|
||||||
handle_raw_login(char *packet, int len, struct query *q, int fd, int userid)
|
handle_raw_login(char *packet, int len, struct query *q, int fd, int userid)
|
||||||
{
|
{
|
||||||
char myhash[16];
|
char myhash[16];
|
||||||
|
|
||||||
if (len < 16) return;
|
if (len < 16) return;
|
||||||
|
|
||||||
/* can't use check_user_and_ip() since IP address will be different,
|
/* can't use check_user_and_ip() since IP address will be different,
|
||||||
|
@ -1869,7 +1869,7 @@ handle_raw_login(char *packet, int len, struct query *q, int fd, int userid)
|
||||||
/* Store remote IP number */
|
/* Store remote IP number */
|
||||||
tempin = (struct sockaddr_in *) &(q->from);
|
tempin = (struct sockaddr_in *) &(q->from);
|
||||||
memcpy(&(users[userid].host), &(tempin->sin_addr), sizeof(struct in_addr));
|
memcpy(&(users[userid].host), &(tempin->sin_addr), sizeof(struct in_addr));
|
||||||
|
|
||||||
/* Correct hash, reply with hash of seed - 1 */
|
/* Correct hash, reply with hash of seed - 1 */
|
||||||
user_set_conn_type(userid, CONN_RAW_UDP);
|
user_set_conn_type(userid, CONN_RAW_UDP);
|
||||||
login_calculate(myhash, 16, password, users[userid].seed - 1);
|
login_calculate(myhash, 16, password, users[userid].seed - 1);
|
||||||
|
@ -1975,7 +1975,7 @@ read_dns(int fd, int tun_fd, struct query *q) /* FIXME: tun_fd is because of raw
|
||||||
msg.msg_control = address;
|
msg.msg_control = address;
|
||||||
msg.msg_controllen = sizeof(address);
|
msg.msg_controllen = sizeof(address);
|
||||||
msg.msg_flags = 0;
|
msg.msg_flags = 0;
|
||||||
|
|
||||||
r = recvmsg(fd, &msg, 0);
|
r = recvmsg(fd, &msg, 0);
|
||||||
#else
|
#else
|
||||||
addrlen = sizeof(struct sockaddr);
|
addrlen = sizeof(struct sockaddr);
|
||||||
|
@ -1993,22 +1993,22 @@ read_dns(int fd, int tun_fd, struct query *q) /* FIXME: tun_fd is because of raw
|
||||||
if (dns_decode(NULL, 0, q, QR_QUERY, packet, r) < 0) {
|
if (dns_decode(NULL, 0, q, QR_QUERY, packet, r) < 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef WINDOWS32
|
#ifndef WINDOWS32
|
||||||
for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL;
|
for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL;
|
||||||
cmsg = CMSG_NXTHDR(&msg, cmsg)) {
|
cmsg = CMSG_NXTHDR(&msg, cmsg)) {
|
||||||
|
|
||||||
if (cmsg->cmsg_level == IPPROTO_IP &&
|
if (cmsg->cmsg_level == IPPROTO_IP &&
|
||||||
cmsg->cmsg_type == DSTADDR_SOCKOPT) {
|
cmsg->cmsg_type == DSTADDR_SOCKOPT) {
|
||||||
|
|
||||||
q->destination = *dstaddr(cmsg);
|
q->destination = *dstaddr(cmsg);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return strlen(q->name);
|
return strlen(q->name);
|
||||||
} else if (r < 0) {
|
} else if (r < 0) {
|
||||||
/* Error */
|
/* Error */
|
||||||
warn("read dns");
|
warn("read dns");
|
||||||
}
|
}
|
||||||
|
@ -2073,7 +2073,7 @@ write_dns_nameenc(char *buf, size_t buflen, char *data, int datalen, char downen
|
||||||
/* Add dot (if it wasn't there already) and topdomain */
|
/* Add dot (if it wasn't there already) and topdomain */
|
||||||
b = buf;
|
b = buf;
|
||||||
b += strlen(buf) - 1;
|
b += strlen(buf) - 1;
|
||||||
if (*b != '.')
|
if (*b != '.')
|
||||||
*++b = '.';
|
*++b = '.';
|
||||||
b++;
|
b++;
|
||||||
|
|
||||||
|
@ -2165,9 +2165,9 @@ write_dns(int fd, struct query *q, char *data, int datalen, char downenc)
|
||||||
warnx("dns_encode doesn't fit");
|
warnx("dns_encode doesn't fit");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (debug >= 2) {
|
if (debug >= 2) {
|
||||||
fprintf(stderr, "TX: client %s, type %d, name %s, %d bytes data\n",
|
fprintf(stderr, "TX: client %s, type %d, name %s, %d bytes data\n",
|
||||||
format_addr(&q->from, q->fromlen), q->type, q->name, datalen);
|
format_addr(&q->from, q->fromlen), q->type, q->name, datalen);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2247,11 +2247,11 @@ main(int argc, char **argv)
|
||||||
int dnsd_fd;
|
int dnsd_fd;
|
||||||
int tun_fd;
|
int tun_fd;
|
||||||
|
|
||||||
/* settings for forwarding normal DNS to
|
/* settings for forwarding normal DNS to
|
||||||
* local real DNS server */
|
* local real DNS server */
|
||||||
int bind_fd;
|
int bind_fd;
|
||||||
int bind_enable;
|
int bind_enable;
|
||||||
|
|
||||||
int choice;
|
int choice;
|
||||||
int port;
|
int port;
|
||||||
int mtu;
|
int mtu;
|
||||||
|
@ -2293,7 +2293,7 @@ main(int argc, char **argv)
|
||||||
b64 = get_base64_encoder();
|
b64 = get_base64_encoder();
|
||||||
b64u = get_base64u_encoder();
|
b64u = get_base64u_encoder();
|
||||||
b128 = get_base128_encoder();
|
b128 = get_base128_encoder();
|
||||||
|
|
||||||
retval = 0;
|
retval = 0;
|
||||||
|
|
||||||
#ifdef WINDOWS32
|
#ifdef WINDOWS32
|
||||||
|
@ -2311,7 +2311,7 @@ main(int argc, char **argv)
|
||||||
memset(password, 0, sizeof(password));
|
memset(password, 0, sizeof(password));
|
||||||
srand(time(NULL));
|
srand(time(NULL));
|
||||||
fw_query_init();
|
fw_query_init();
|
||||||
|
|
||||||
while ((choice = getopt(argc, argv, "vcsfhDu:t:d:m:l:p:n:b:P:z:F:i:")) != -1) {
|
while ((choice = getopt(argc, argv, "vcsfhDu:t:d:m:l:p:n:b:P:z:F:i:")) != -1) {
|
||||||
switch(choice) {
|
switch(choice) {
|
||||||
case 'v':
|
case 'v':
|
||||||
|
@ -2363,16 +2363,16 @@ main(int argc, char **argv)
|
||||||
break;
|
break;
|
||||||
case 'F':
|
case 'F':
|
||||||
pidfile = optarg;
|
pidfile = optarg;
|
||||||
break;
|
break;
|
||||||
case 'i':
|
case 'i':
|
||||||
max_idle_time = atoi(optarg);
|
max_idle_time = atoi(optarg);
|
||||||
break;
|
break;
|
||||||
case 'P':
|
case 'P':
|
||||||
strncpy(password, optarg, sizeof(password));
|
strncpy(password, optarg, sizeof(password));
|
||||||
password[sizeof(password)-1] = 0;
|
password[sizeof(password)-1] = 0;
|
||||||
|
|
||||||
/* XXX: find better way of cleaning up ps(1) */
|
/* XXX: find better way of cleaning up ps(1) */
|
||||||
memset(optarg, 0, strlen(optarg));
|
memset(optarg, 0, strlen(optarg));
|
||||||
break;
|
break;
|
||||||
case 'z':
|
case 'z':
|
||||||
context = optarg;
|
context = optarg;
|
||||||
|
@ -2388,9 +2388,9 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
check_superuser(usage);
|
check_superuser(usage);
|
||||||
|
|
||||||
if (argc != 2)
|
if (argc != 2)
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
netsize = strchr(argv[0], '/');
|
netsize = strchr(argv[0], '/');
|
||||||
if (netsize) {
|
if (netsize) {
|
||||||
*netsize = 0;
|
*netsize = 0;
|
||||||
|
@ -2399,7 +2399,7 @@ main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
my_ip = inet_addr(argv[0]);
|
my_ip = inet_addr(argv[0]);
|
||||||
|
|
||||||
if (my_ip == INADDR_NONE) {
|
if (my_ip == INADDR_NONE) {
|
||||||
warnx("Bad IP address to use inside tunnel.");
|
warnx("Bad IP address to use inside tunnel.");
|
||||||
usage();
|
usage();
|
||||||
|
@ -2425,12 +2425,12 @@ main(int argc, char **argv)
|
||||||
warnx("Bad MTU given.");
|
warnx("Bad MTU given.");
|
||||||
usage();
|
usage();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(port < 1 || port > 65535) {
|
if(port < 1 || port > 65535) {
|
||||||
warnx("Bad port number given.");
|
warnx("Bad port number given.");
|
||||||
usage();
|
usage();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (port != 53) {
|
if (port != 53) {
|
||||||
fprintf(stderr, "ALERT! Other dns servers expect you to run on port 53.\n");
|
fprintf(stderr, "ALERT! Other dns servers expect you to run on port 53.\n");
|
||||||
fprintf(stderr, "You must manually forward port 53 to port %d for things to work.\n", port);
|
fprintf(stderr, "You must manually forward port 53 to port %d for things to work.\n", port);
|
||||||
|
@ -2485,7 +2485,7 @@ main(int argc, char **argv)
|
||||||
warnx("Bad netmask (%d bits). Use 8-30 bits.", netmask);
|
warnx("Bad netmask (%d bits). Use 8-30 bits.", netmask);
|
||||||
usage();
|
usage();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strlen(password) == 0) {
|
if (strlen(password) == 0) {
|
||||||
if (NULL != getenv(PASSWORD_ENV_VAR))
|
if (NULL != getenv(PASSWORD_ENV_VAR))
|
||||||
snprintf(password, sizeof(password), "%s", getenv(PASSWORD_ENV_VAR));
|
snprintf(password, sizeof(password), "%s", getenv(PASSWORD_ENV_VAR));
|
||||||
|
@ -2533,16 +2533,16 @@ main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
my_mtu = mtu;
|
my_mtu = mtu;
|
||||||
|
|
||||||
if (created_users < USERS) {
|
if (created_users < USERS) {
|
||||||
fprintf(stderr, "Limiting to %d simultaneous users because of netmask /%d\n",
|
fprintf(stderr, "Limiting to %d simultaneous users because of netmask /%d\n",
|
||||||
created_users, netmask);
|
created_users, netmask);
|
||||||
}
|
}
|
||||||
fprintf(stderr, "Listening to dns for domain %s\n", topdomain);
|
fprintf(stderr, "Listening to dns for domain %s\n", topdomain);
|
||||||
|
|
||||||
if (foreground == 0)
|
if (foreground == 0)
|
||||||
do_detach();
|
do_detach();
|
||||||
|
|
||||||
if (pidfile != NULL)
|
if (pidfile != NULL)
|
||||||
do_pidfile(pidfile);
|
do_pidfile(pidfile);
|
||||||
|
|
||||||
|
@ -2572,7 +2572,7 @@ main(int argc, char **argv)
|
||||||
do_setcon(context);
|
do_setcon(context);
|
||||||
|
|
||||||
syslog(LOG_INFO, "started, listening on port %d", port);
|
syslog(LOG_INFO, "started, listening on port %d", port);
|
||||||
|
|
||||||
tunnel(tun_fd, dnsd_fd, bind_fd, max_idle_time);
|
tunnel(tun_fd, dnsd_fd, bind_fd, max_idle_time);
|
||||||
|
|
||||||
syslog(LOG_INFO, "stopping");
|
syslog(LOG_INFO, "stopping");
|
||||||
|
@ -2581,7 +2581,7 @@ cleanup3:
|
||||||
cleanup2:
|
cleanup2:
|
||||||
close_dns(dnsd_fd);
|
close_dns(dnsd_fd);
|
||||||
cleanup1:
|
cleanup1:
|
||||||
close_tun(tun_fd);
|
close_tun(tun_fd);
|
||||||
cleanup0:
|
cleanup0:
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
|
|
10
src/login.c
10
src/login.c
|
@ -27,11 +27,11 @@
|
||||||
|
|
||||||
#include "md5.h"
|
#include "md5.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Needs a 16byte array for output, and 32 bytes password
|
* Needs a 16byte array for output, and 32 bytes password
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
login_calculate(char *buf, int buflen, const char *pass, int seed)
|
login_calculate(char *buf, int buflen, const char *pass, int seed)
|
||||||
{
|
{
|
||||||
unsigned char temp[32];
|
unsigned char temp[32];
|
||||||
md5_state_t ctx;
|
md5_state_t ctx;
|
||||||
|
@ -39,7 +39,7 @@ login_calculate(char *buf, int buflen, const char *pass, int seed)
|
||||||
int i;
|
int i;
|
||||||
int k;
|
int k;
|
||||||
|
|
||||||
if (buflen < 16)
|
if (buflen < 16)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
memcpy(temp, pass, 32);
|
memcpy(temp, pass, 32);
|
||||||
|
|
|
@ -71,7 +71,7 @@ typedef struct md5_state_s {
|
||||||
} md5_state_t;
|
} md5_state_t;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
10
src/read.c
10
src/read.c
|
@ -61,7 +61,7 @@ readname_loop(char *packet, int packetlen, char **src, char *dst, size_t length,
|
||||||
|
|
||||||
c--;
|
c--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (len >= length - 1) {
|
if (len >= length - 1) {
|
||||||
break; /* We used up all space */
|
break; /* We used up all space */
|
||||||
}
|
}
|
||||||
|
@ -104,8 +104,8 @@ readlong(char *packet, char **src, uint32_t *dst)
|
||||||
|
|
||||||
p = (unsigned char *) *src;
|
p = (unsigned char *) *src;
|
||||||
|
|
||||||
*dst = ((uint32_t)p[0] << 24)
|
*dst = ((uint32_t)p[0] << 24)
|
||||||
| ((uint32_t)p[1] << 16)
|
| ((uint32_t)p[1] << 16)
|
||||||
| ((uint32_t)p[2] << 8)
|
| ((uint32_t)p[2] << 8)
|
||||||
| ((uint32_t)p[3]);
|
| ((uint32_t)p[3]);
|
||||||
|
|
||||||
|
@ -163,7 +163,7 @@ putname(char **buf, size_t buflen, const char *host)
|
||||||
h = strdup(host);
|
h = strdup(host);
|
||||||
left = buflen;
|
left = buflen;
|
||||||
p = *buf;
|
p = *buf;
|
||||||
|
|
||||||
word = strtok(h, ".");
|
word = strtok(h, ".");
|
||||||
while(word) {
|
while(word) {
|
||||||
if (strlen(word) > 63 || strlen(word) > left) {
|
if (strlen(word) > 63 || strlen(word) > left) {
|
||||||
|
@ -231,7 +231,7 @@ int
|
||||||
putdata(char **dst, char *data, size_t len)
|
putdata(char **dst, char *data, size_t len)
|
||||||
{
|
{
|
||||||
memcpy(*dst, data, len);
|
memcpy(*dst, data, len);
|
||||||
|
|
||||||
(*dst) += len;
|
(*dst) += len;
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
58
src/tun.c
58
src/tun.c
|
@ -69,8 +69,8 @@ char if_name[250];
|
||||||
#include <net/if.h>
|
#include <net/if.h>
|
||||||
#include <linux/if_tun.h>
|
#include <linux/if_tun.h>
|
||||||
|
|
||||||
int
|
int
|
||||||
open_tun(const char *tun_device)
|
open_tun(const char *tun_device)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int tun_fd;
|
int tun_fd;
|
||||||
|
@ -88,7 +88,7 @@ open_tun(const char *tun_device)
|
||||||
|
|
||||||
memset(&ifreq, 0, sizeof(ifreq));
|
memset(&ifreq, 0, sizeof(ifreq));
|
||||||
|
|
||||||
ifreq.ifr_flags = IFF_TUN;
|
ifreq.ifr_flags = IFF_TUN;
|
||||||
|
|
||||||
if (tun_device != NULL) {
|
if (tun_device != NULL) {
|
||||||
strncpy(ifreq.ifr_name, tun_device, IFNAMSIZ);
|
strncpy(ifreq.ifr_name, tun_device, IFNAMSIZ);
|
||||||
|
@ -129,8 +129,8 @@ open_tun(const char *tun_device)
|
||||||
|
|
||||||
#else /* BSD */
|
#else /* BSD */
|
||||||
|
|
||||||
int
|
int
|
||||||
open_tun(const char *tun_device)
|
open_tun(const char *tun_device)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int tun_fd;
|
int tun_fd;
|
||||||
|
@ -184,7 +184,7 @@ get_device(char *device, int device_len, const char *wanted_dev)
|
||||||
warnx("Error opening registry key " TAP_ADAPTER_KEY );
|
warnx("Error opening registry key " TAP_ADAPTER_KEY );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (TRUE) {
|
while (TRUE) {
|
||||||
char name[256];
|
char name[256];
|
||||||
char unit[256];
|
char unit[256];
|
||||||
|
@ -222,7 +222,7 @@ get_device(char *device, int device_len, const char *wanted_dev)
|
||||||
strncmp(TAP_VERSION_ID_0901, component, strlen(TAP_VERSION_ID_0901)) == 0) {
|
strncmp(TAP_VERSION_ID_0901, component, strlen(TAP_VERSION_ID_0901)) == 0) {
|
||||||
/* We found a TAP32 device, get its NetCfgInstanceId */
|
/* We found a TAP32 device, get its NetCfgInstanceId */
|
||||||
char iid_string[256] = NET_CFG_INST_ID;
|
char iid_string[256] = NET_CFG_INST_ID;
|
||||||
|
|
||||||
status = RegQueryValueEx(device_key, iid_string, NULL, &datatype, (LPBYTE) device, (DWORD *) &device_len);
|
status = RegQueryValueEx(device_key, iid_string, NULL, &datatype, (LPBYTE) device, (DWORD *) &device_len);
|
||||||
if (status != ERROR_SUCCESS || datatype != REG_SZ) {
|
if (status != ERROR_SUCCESS || datatype != REG_SZ) {
|
||||||
warnx("Error reading registry key %s\\%s on TAP device", unit, iid_string);
|
warnx("Error reading registry key %s\\%s on TAP device", unit, iid_string);
|
||||||
|
@ -299,7 +299,7 @@ DWORD WINAPI tun_reader(LPVOID arg)
|
||||||
if (!res) {
|
if (!res) {
|
||||||
WaitForSingleObject(olpd.hEvent, INFINITE);
|
WaitForSingleObject(olpd.hEvent, INFINITE);
|
||||||
res = GetOverlappedResult(dev_handle, &olpd, (LPDWORD) &len, FALSE);
|
res = GetOverlappedResult(dev_handle, &olpd, (LPDWORD) &len, FALSE);
|
||||||
res = sendto(sock, buf, len, 0, (struct sockaddr*) &(tun->addr),
|
res = sendto(sock, buf, len, 0, (struct sockaddr*) &(tun->addr),
|
||||||
tun->addrlen);
|
tun->addrlen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -307,8 +307,8 @@ DWORD WINAPI tun_reader(LPVOID arg)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
open_tun(const char *tun_device)
|
open_tun(const char *tun_device)
|
||||||
{
|
{
|
||||||
char adapter[256];
|
char adapter[256];
|
||||||
char tapfile[512];
|
char tapfile[512];
|
||||||
|
@ -328,7 +328,7 @@ open_tun(const char *tun_device)
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stderr, "Opening device %s\n", if_name);
|
fprintf(stderr, "Opening device %s\n", if_name);
|
||||||
snprintf(tapfile, sizeof(tapfile), "%s%s.tap", TAP_DEVICE_SPACE, adapter);
|
snprintf(tapfile, sizeof(tapfile), "%s%s.tap", TAP_DEVICE_SPACE, adapter);
|
||||||
dev_handle = CreateFile(tapfile, GENERIC_WRITE | GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_OVERLAPPED, NULL);
|
dev_handle = CreateFile(tapfile, GENERIC_WRITE | GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_OVERLAPPED, NULL);
|
||||||
|
@ -339,9 +339,9 @@ open_tun(const char *tun_device)
|
||||||
|
|
||||||
/* Use a UDP connection to forward packets from tun,
|
/* Use a UDP connection to forward packets from tun,
|
||||||
* so we can still use select() in main code.
|
* so we can still use select() in main code.
|
||||||
* A thread does blocking reads on tun device and
|
* A thread does blocking reads on tun device and
|
||||||
* sends data as udp to this socket */
|
* sends data as udp to this socket */
|
||||||
|
|
||||||
localsock_len = get_addr("127.0.0.1", 55353, AF_INET, 0, &localsock);
|
localsock_len = get_addr("127.0.0.1", 55353, AF_INET, 0, &localsock);
|
||||||
tunfd = open_dns(&localsock, localsock_len);
|
tunfd = open_dns(&localsock, localsock_len);
|
||||||
|
|
||||||
|
@ -349,20 +349,20 @@ open_tun(const char *tun_device)
|
||||||
memcpy(&(data.addr), &localsock, localsock_len);
|
memcpy(&(data.addr), &localsock, localsock_len);
|
||||||
data.addrlen = localsock_len;
|
data.addrlen = localsock_len;
|
||||||
CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)tun_reader, &data, 0, NULL);
|
CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)tun_reader, &data, 0, NULL);
|
||||||
|
|
||||||
return tunfd;
|
return tunfd;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void
|
void
|
||||||
close_tun(int tun_fd)
|
close_tun(int tun_fd)
|
||||||
{
|
{
|
||||||
if (tun_fd >= 0)
|
if (tun_fd >= 0)
|
||||||
close(tun_fd);
|
close(tun_fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
write_tun(int tun_fd, char *data, size_t len)
|
write_tun(int tun_fd, char *data, size_t len)
|
||||||
{
|
{
|
||||||
#if defined (FREEBSD) || defined (DARWIN) || defined(NETBSD) || defined(WINDOWS32)
|
#if defined (FREEBSD) || defined (DARWIN) || defined(NETBSD) || defined(WINDOWS32)
|
||||||
data += 4;
|
data += 4;
|
||||||
|
@ -409,7 +409,7 @@ write_tun(int tun_fd, char *data, size_t len)
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t
|
ssize_t
|
||||||
read_tun(int tun_fd, char *buf, size_t len)
|
read_tun(int tun_fd, char *buf, size_t len)
|
||||||
{
|
{
|
||||||
#if defined (FREEBSD) || defined (DARWIN) || defined(NETBSD) || defined(WINDOWS32)
|
#if defined (FREEBSD) || defined (DARWIN) || defined(NETBSD) || defined(WINDOWS32)
|
||||||
/* FreeBSD/Darwin/NetBSD has no header */
|
/* FreeBSD/Darwin/NetBSD has no header */
|
||||||
|
@ -471,13 +471,13 @@ tun_setip(const char *ip, const char *other_ip, int netbits)
|
||||||
# else
|
# else
|
||||||
display_ip = ip;
|
display_ip = ip;
|
||||||
# endif
|
# endif
|
||||||
snprintf(cmdline, sizeof(cmdline),
|
snprintf(cmdline, sizeof(cmdline),
|
||||||
IFCONFIGPATH "ifconfig %s %s %s netmask %s",
|
IFCONFIGPATH "ifconfig %s %s %s netmask %s",
|
||||||
if_name,
|
if_name,
|
||||||
ip,
|
ip,
|
||||||
display_ip,
|
display_ip,
|
||||||
inet_ntoa(net));
|
inet_ntoa(net));
|
||||||
|
|
||||||
fprintf(stderr, "Setting IP of %s to %s\n", if_name, ip);
|
fprintf(stderr, "Setting IP of %s to %s\n", if_name, ip);
|
||||||
#ifndef LINUX
|
#ifndef LINUX
|
||||||
netip.s_addr = inet_addr(ip);
|
netip.s_addr = inet_addr(ip);
|
||||||
|
@ -486,7 +486,7 @@ tun_setip(const char *ip, const char *other_ip, int netbits)
|
||||||
if(r != 0) {
|
if(r != 0) {
|
||||||
return r;
|
return r;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
snprintf(cmdline, sizeof(cmdline),
|
snprintf(cmdline, sizeof(cmdline),
|
||||||
"/sbin/route add %s/%d %s",
|
"/sbin/route add %s/%d %s",
|
||||||
inet_ntoa(netip), netbits, ip);
|
inet_ntoa(netip), netbits, ip);
|
||||||
|
@ -499,13 +499,13 @@ tun_setip(const char *ip, const char *other_ip, int netbits)
|
||||||
/* Set device as connected */
|
/* Set device as connected */
|
||||||
fprintf(stderr, "Enabling interface '%s'\n", if_name);
|
fprintf(stderr, "Enabling interface '%s'\n", if_name);
|
||||||
status = 1;
|
status = 1;
|
||||||
r = DeviceIoControl(dev_handle, TAP_IOCTL_SET_MEDIA_STATUS, &status,
|
r = DeviceIoControl(dev_handle, TAP_IOCTL_SET_MEDIA_STATUS, &status,
|
||||||
sizeof(status), &status, sizeof(status), &len, NULL);
|
sizeof(status), &status, sizeof(status), &len, NULL);
|
||||||
if (!r) {
|
if (!r) {
|
||||||
fprintf(stderr, "Failed to enable interface\n");
|
fprintf(stderr, "Failed to enable interface\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inet_aton(ip, &addr)) {
|
if (inet_aton(ip, &addr)) {
|
||||||
ipdata[0] = (DWORD) addr.s_addr; /* local ip addr */
|
ipdata[0] = (DWORD) addr.s_addr; /* local ip addr */
|
||||||
ipdata[1] = net.s_addr & ipdata[0]; /* network addr */
|
ipdata[1] = net.s_addr & ipdata[0]; /* network addr */
|
||||||
|
@ -515,7 +515,7 @@ tun_setip(const char *ip, const char *other_ip, int netbits)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Tell ip/networkaddr/netmask to device for arp use */
|
/* Tell ip/networkaddr/netmask to device for arp use */
|
||||||
r = DeviceIoControl(dev_handle, TAP_IOCTL_CONFIG_TUN, &ipdata,
|
r = DeviceIoControl(dev_handle, TAP_IOCTL_CONFIG_TUN, &ipdata,
|
||||||
sizeof(ipdata), &ipdata, sizeof(ipdata), &len, NULL);
|
sizeof(ipdata), &ipdata, sizeof(ipdata), &len, NULL);
|
||||||
if (!r) {
|
if (!r) {
|
||||||
fprintf(stderr, "Failed to set interface in TUN mode\n");
|
fprintf(stderr, "Failed to set interface in TUN mode\n");
|
||||||
|
@ -530,18 +530,18 @@ tun_setip(const char *ip, const char *other_ip, int netbits)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
tun_setmtu(const unsigned mtu)
|
tun_setmtu(const unsigned mtu)
|
||||||
{
|
{
|
||||||
#ifndef WINDOWS32
|
#ifndef WINDOWS32
|
||||||
char cmdline[512];
|
char cmdline[512];
|
||||||
|
|
||||||
if (mtu > 200 && mtu <= 1500) {
|
if (mtu > 200 && mtu <= 1500) {
|
||||||
snprintf(cmdline, sizeof(cmdline),
|
snprintf(cmdline, sizeof(cmdline),
|
||||||
IFCONFIGPATH "ifconfig %s mtu %u",
|
IFCONFIGPATH "ifconfig %s mtu %u",
|
||||||
if_name,
|
if_name,
|
||||||
mtu);
|
mtu);
|
||||||
|
|
||||||
fprintf(stderr, "Setting MTU of %s to %u\n", if_name, mtu);
|
fprintf(stderr, "Setting MTU of %s to %u\n", if_name, mtu);
|
||||||
return system(cmdline);
|
return system(cmdline);
|
||||||
} else {
|
} else {
|
||||||
|
|
16
src/user.c
16
src/user.c
|
@ -59,7 +59,7 @@ init_users(in_addr_t my_ip, int netbits)
|
||||||
|
|
||||||
maxusers = (1 << (32-netbits)) - 3; /* 3: Net addr, broadcast addr, iodined addr */
|
maxusers = (1 << (32-netbits)) - 3; /* 3: Net addr, broadcast addr, iodined addr */
|
||||||
usercount = MIN(maxusers, USERS);
|
usercount = MIN(maxusers, USERS);
|
||||||
|
|
||||||
users = calloc(usercount, sizeof(struct tun_user));
|
users = calloc(usercount, sizeof(struct tun_user));
|
||||||
for (i = 0; i < usercount; i++) {
|
for (i = 0; i < usercount; i++) {
|
||||||
in_addr_t ip;
|
in_addr_t ip;
|
||||||
|
@ -98,13 +98,13 @@ users_waiting_on_reply()
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
for (i = 0; i < usercount; i++) {
|
for (i = 0; i < usercount; i++) {
|
||||||
if (users[i].active && !users[i].disabled &&
|
if (users[i].active && !users[i].disabled &&
|
||||||
users[i].last_pkt + 60 > time(NULL) &&
|
users[i].last_pkt + 60 > time(NULL) &&
|
||||||
users[i].q.id != 0 && users[i].conn == CONN_DNS_NULL) {
|
users[i].q.id != 0 && users[i].conn == CONN_DNS_NULL) {
|
||||||
ret++;
|
ret++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,8 +143,8 @@ all_users_waiting_to_send()
|
||||||
for (i = 0; i < usercount; i++) {
|
for (i = 0; i < usercount; 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].conn == CONN_RAW_UDP) ||
|
((users[i].conn == CONN_RAW_UDP) ||
|
||||||
((users[i].conn == CONN_DNS_NULL)
|
((users[i].conn == CONN_DNS_NULL)
|
||||||
#ifdef OUTPACKETQ_LEN
|
#ifdef OUTPACKETQ_LEN
|
||||||
&& users[i].outpacketq_filled < 1
|
&& users[i].outpacketq_filled < 1
|
||||||
#else
|
#else
|
||||||
|
@ -183,7 +183,7 @@ user_switch_codec(int userid, struct encoder *enc)
|
||||||
{
|
{
|
||||||
if (userid < 0 || userid >= usercount)
|
if (userid < 0 || userid >= usercount)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
users[userid].encoder = enc;
|
users[userid].encoder = enc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,7 +195,7 @@ user_set_conn_type(int userid, enum connection c)
|
||||||
|
|
||||||
if (c < 0 || c >= CONN_MAX)
|
if (c < 0 || c >= CONN_MAX)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
users[userid].conn = c;
|
users[userid].conn = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,12 +36,12 @@ get_resolvconf_addr()
|
||||||
rv = addr;
|
rv = addr;
|
||||||
pclose(fp);
|
pclose(fp);
|
||||||
#else
|
#else
|
||||||
|
|
||||||
rv = NULL;
|
rv = NULL;
|
||||||
|
|
||||||
if ((fp = fopen("/etc/resolv.conf", "r")) == NULL)
|
if ((fp = fopen("/etc/resolv.conf", "r")) == NULL)
|
||||||
err(1, "/etc/resolv.conf");
|
err(1, "/etc/resolv.conf");
|
||||||
|
|
||||||
while (feof(fp) == 0) {
|
while (feof(fp) == 0) {
|
||||||
fgets(buf, sizeof(buf), fp);
|
fgets(buf, sizeof(buf), fp);
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ get_resolvconf_addr()
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
#endif
|
#endif
|
||||||
#else /* !WINDOWS32 */
|
#else /* !WINDOWS32 */
|
||||||
|
|
|
@ -13,9 +13,9 @@ all: $(TEST)
|
||||||
|
|
||||||
$(TEST): $(OBJS) $(SRCOBJS)
|
$(TEST): $(OBJS) $(SRCOBJS)
|
||||||
@echo LD $(TEST)
|
@echo LD $(TEST)
|
||||||
@$(CC) -o $@ $(SRCOBJS) $(OBJS) $(LDFLAGS)
|
@$(CC) -o $@ $(SRCOBJS) $(OBJS) $(LDFLAGS)
|
||||||
|
|
||||||
.c.o:
|
.c.o:
|
||||||
@echo CC $<
|
@echo CC $<
|
||||||
@$(CC) $(CFLAGS) -c $<
|
@$(CC) $(CFLAGS) -c $<
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,7 @@ START_TEST(test_base32_decode)
|
||||||
char buf[4096];
|
char buf[4096];
|
||||||
struct encoder *b32;
|
struct encoder *b32;
|
||||||
int val;
|
int val;
|
||||||
|
|
||||||
b32 = get_base32_encoder();
|
b32 = get_base32_encoder();
|
||||||
|
|
||||||
len = sizeof(buf);
|
len = sizeof(buf);
|
||||||
|
@ -81,7 +81,7 @@ START_TEST(test_base32_5to8_8to5)
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
for (i = 0; i < 32; i++) {
|
for (i = 0; i < 32; i++) {
|
||||||
c = b32_5to8(i);
|
c = b32_5to8(i);
|
||||||
fail_unless(b32_8to5(c) == i);
|
fail_unless(b32_8to5(c) == i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,7 +85,7 @@ START_TEST(test_build_hostname)
|
||||||
}
|
}
|
||||||
|
|
||||||
buflen = sizeof(buf);
|
buflen = sizeof(buf);
|
||||||
|
|
||||||
for (i = 1; i < sizeof(data); i++) {
|
for (i = 1; i < sizeof(data); i++) {
|
||||||
int len = build_hostname(buf, buflen, data, i, topdomain, get_base32_encoder(), sizeof(buf));
|
int len = build_hostname(buf, buflen, data, i, topdomain, get_base32_encoder(), sizeof(buf));
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ START_TEST(test_fw_query_simple)
|
||||||
q.id = 0x848A;
|
q.id = 0x848A;
|
||||||
|
|
||||||
fw_query_init();
|
fw_query_init();
|
||||||
|
|
||||||
/* Test empty cache */
|
/* Test empty cache */
|
||||||
fw_query_get(0x848A, &qp);
|
fw_query_get(0x848A, &qp);
|
||||||
fail_unless(qp == NULL);
|
fail_unless(qp == NULL);
|
||||||
|
@ -49,7 +49,7 @@ START_TEST(test_fw_query_edge)
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
fw_query_init();
|
fw_query_init();
|
||||||
|
|
||||||
q.addrlen = 33;
|
q.addrlen = 33;
|
||||||
q.id = 0x848A;
|
q.id = 0x848A;
|
||||||
fw_query_put(&q);
|
fw_query_put(&q);
|
||||||
|
@ -64,7 +64,7 @@ START_TEST(test_fw_query_edge)
|
||||||
fw_query_get(0x848A, &qp);
|
fw_query_get(0x848A, &qp);
|
||||||
fail_unless(qp->addrlen == 33);
|
fail_unless(qp->addrlen == 33);
|
||||||
fail_unless(qp->id == 0x848A);
|
fail_unless(qp->id == 0x848A);
|
||||||
|
|
||||||
q.addrlen++;
|
q.addrlen++;
|
||||||
q.id++;
|
q.id++;
|
||||||
fw_query_put(&q);
|
fw_query_put(&q);
|
||||||
|
|
|
@ -29,11 +29,11 @@ TCase *test_user_create_tests();
|
||||||
TCase *test_fw_query_create_tests();
|
TCase *test_fw_query_create_tests();
|
||||||
|
|
||||||
char *va_str(const char *, ...);
|
char *va_str(const char *, ...);
|
||||||
|
|
||||||
#if (CHECK_MAJOR_VERSION == 0 && \
|
#if (CHECK_MAJOR_VERSION == 0 && \
|
||||||
((CHECK_MINOR_VERSION == 9 && CHECK_MICRO_VERSION < 2) || \
|
((CHECK_MINOR_VERSION == 9 && CHECK_MICRO_VERSION < 2) || \
|
||||||
(CHECK_MINOR_VERSION < 9)))
|
(CHECK_MINOR_VERSION < 9)))
|
||||||
#define tcase_set_timeout(...)
|
#define tcase_set_timeout(...)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
30
tests/user.c
30
tests/user.c
|
@ -62,12 +62,12 @@ START_TEST(test_users_waiting)
|
||||||
fail_unless(users_waiting_on_reply() == 0);
|
fail_unless(users_waiting_on_reply() == 0);
|
||||||
|
|
||||||
users[3].last_pkt = time(NULL);
|
users[3].last_pkt = time(NULL);
|
||||||
|
|
||||||
fail_unless(users_waiting_on_reply() == 0);
|
fail_unless(users_waiting_on_reply() == 0);
|
||||||
|
|
||||||
users[3].conn = CONN_DNS_NULL;
|
users[3].conn = CONN_DNS_NULL;
|
||||||
users[3].q.id = 1;
|
users[3].q.id = 1;
|
||||||
|
|
||||||
fail_unless(users_waiting_on_reply() == 1);
|
fail_unless(users_waiting_on_reply() == 1);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
@ -83,17 +83,17 @@ START_TEST(test_find_user_by_ip)
|
||||||
|
|
||||||
testip = (unsigned int) inet_addr("10.0.0.1");
|
testip = (unsigned int) inet_addr("10.0.0.1");
|
||||||
fail_unless(find_user_by_ip(testip) == -1);
|
fail_unless(find_user_by_ip(testip) == -1);
|
||||||
|
|
||||||
testip = (unsigned int) inet_addr("127.0.0.2");
|
testip = (unsigned int) inet_addr("127.0.0.2");
|
||||||
fail_unless(find_user_by_ip(testip) == -1);
|
fail_unless(find_user_by_ip(testip) == -1);
|
||||||
|
|
||||||
users[0].active = 1;
|
users[0].active = 1;
|
||||||
|
|
||||||
testip = (unsigned int) inet_addr("127.0.0.2");
|
testip = (unsigned int) inet_addr("127.0.0.2");
|
||||||
fail_unless(find_user_by_ip(testip) == -1);
|
fail_unless(find_user_by_ip(testip) == -1);
|
||||||
|
|
||||||
users[0].last_pkt = time(NULL);
|
users[0].last_pkt = time(NULL);
|
||||||
|
|
||||||
testip = (unsigned int) inet_addr("127.0.0.2");
|
testip = (unsigned int) inet_addr("127.0.0.2");
|
||||||
fail_unless(find_user_by_ip(testip) == 0);
|
fail_unless(find_user_by_ip(testip) == 0);
|
||||||
}
|
}
|
||||||
|
@ -107,15 +107,15 @@ START_TEST(test_all_users_waiting_to_send)
|
||||||
init_users(ip, 27);
|
init_users(ip, 27);
|
||||||
|
|
||||||
fail_unless(all_users_waiting_to_send() == 1);
|
fail_unless(all_users_waiting_to_send() == 1);
|
||||||
|
|
||||||
users[0].conn = CONN_DNS_NULL;
|
users[0].conn = CONN_DNS_NULL;
|
||||||
users[0].active = 1;
|
users[0].active = 1;
|
||||||
|
|
||||||
fail_unless(all_users_waiting_to_send() == 1);
|
fail_unless(all_users_waiting_to_send() == 1);
|
||||||
|
|
||||||
users[0].last_pkt = time(NULL);
|
users[0].last_pkt = time(NULL);
|
||||||
users[0].outpacket.len = 0;
|
users[0].outpacket.len = 0;
|
||||||
|
|
||||||
fail_unless(all_users_waiting_to_send() == 0);
|
fail_unless(all_users_waiting_to_send() == 0);
|
||||||
|
|
||||||
#ifdef OUTPACKETQ_LEN
|
#ifdef OUTPACKETQ_LEN
|
||||||
|
@ -123,7 +123,7 @@ START_TEST(test_all_users_waiting_to_send)
|
||||||
#else
|
#else
|
||||||
users[0].outpacket.len = 44;
|
users[0].outpacket.len = 44;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
fail_unless(all_users_waiting_to_send() == 1);
|
fail_unless(all_users_waiting_to_send() == 1);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
@ -150,7 +150,7 @@ START_TEST(test_find_available_user)
|
||||||
fail_unless(find_available_user() == -1);
|
fail_unless(find_available_user() == -1);
|
||||||
|
|
||||||
users[3].last_pkt = 55;
|
users[3].last_pkt = 55;
|
||||||
|
|
||||||
fail_unless(find_available_user() == 3);
|
fail_unless(find_available_user() == 3);
|
||||||
fail_unless(find_available_user() == -1);
|
fail_unless(find_available_user() == -1);
|
||||||
}
|
}
|
||||||
|
@ -178,7 +178,7 @@ START_TEST(test_find_available_user_small_net)
|
||||||
fail_unless(find_available_user() == -1);
|
fail_unless(find_available_user() == -1);
|
||||||
|
|
||||||
users[3].last_pkt = 55;
|
users[3].last_pkt = 55;
|
||||||
|
|
||||||
fail_unless(find_available_user() == 3);
|
fail_unless(find_available_user() == 3);
|
||||||
fail_unless(find_available_user() == -1);
|
fail_unless(find_available_user() == -1);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue