mirror of
https://github.com/yarrick/iodine.git
synced 2024-11-22 06:41:26 +00:00
Warn, warn warn.
iodine does not seem to follow any styling guidelines (mixture of different function prototypes, ...). So let's introduce some. This will improve overall code quality and readability. Additionally, warnings will improve code quality as well. Let's turn on very pedantic warnings, and fix everything where the compiler barks back. Introduce the following function definition scheme: type function_name(type name, type1 name1 ...) { } This allows us to copy and paste the definition to the declaration by selecting one single line. Furthermore, limit line length to 80 characters. Signed-off-by: Ralf Ramsauer <ralf@ramses-pyramidenbau.de>
This commit is contained in:
parent
ccc49f16f7
commit
52c4940523
|
@ -11,6 +11,7 @@ HEAD_COMMIT = `git rev-parse --short HEAD`
|
||||||
LIBPATH = -L.
|
LIBPATH = -L.
|
||||||
LDFLAGS += -lz `sh osflags $(TARGETOS) link` $(LIBPATH)
|
LDFLAGS += -lz `sh osflags $(TARGETOS) link` $(LIBPATH)
|
||||||
CFLAGS += -std=c99 -c -g -Wall -D$(OS) -pedantic `sh osflags $(TARGETOS) cflags` -DGITREVISION=\"$(HEAD_COMMIT)\"
|
CFLAGS += -std=c99 -c -g -Wall -D$(OS) -pedantic `sh osflags $(TARGETOS) cflags` -DGITREVISION=\"$(HEAD_COMMIT)\"
|
||||||
|
CFLAGS += -Wstrict-prototypes -Wtype-limits -Wmissing-declarations -Wmissing-prototypes
|
||||||
|
|
||||||
all: stateos $(CLIENT) $(SERVER)
|
all: stateos $(CLIENT) $(SERVER)
|
||||||
|
|
||||||
|
|
|
@ -54,9 +54,9 @@ static int reverse_init = 0;
|
||||||
|
|
||||||
static int base128_encode(char *, size_t *, const void *, size_t);
|
static int base128_encode(char *, size_t *, const void *, size_t);
|
||||||
static int base128_decode(void *, size_t *, const char *, size_t);
|
static int base128_decode(void *, size_t *, const char *, size_t);
|
||||||
static int base128_handles_dots();
|
static int base128_handles_dots(void);
|
||||||
static int base128_blksize_raw();
|
static int base128_blksize_raw(void);
|
||||||
static int base128_blksize_enc();
|
static int base128_blksize_enc(void);
|
||||||
|
|
||||||
static struct encoder base128_encoder =
|
static struct encoder base128_encoder =
|
||||||
{
|
{
|
||||||
|
@ -69,32 +69,27 @@ static struct encoder base128_encoder =
|
||||||
base128_blksize_enc
|
base128_blksize_enc
|
||||||
};
|
};
|
||||||
|
|
||||||
struct encoder
|
struct encoder *get_base128_encoder(void)
|
||||||
*get_base128_encoder()
|
|
||||||
{
|
{
|
||||||
return &base128_encoder;
|
return &base128_encoder;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int base128_handles_dots(void)
|
||||||
base128_handles_dots()
|
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int base128_blksize_raw(void)
|
||||||
base128_blksize_raw()
|
|
||||||
{
|
{
|
||||||
return BLKSIZE_RAW;
|
return BLKSIZE_RAW;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int base128_blksize_enc(void)
|
||||||
base128_blksize_enc()
|
|
||||||
{
|
{
|
||||||
return BLKSIZE_ENC;
|
return BLKSIZE_ENC;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline static void
|
inline static void base128_reverse_init(void)
|
||||||
base128_reverse_init()
|
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
unsigned char c;
|
unsigned char c;
|
||||||
|
@ -109,8 +104,6 @@ base128_reverse_init()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
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.
|
||||||
*
|
*
|
||||||
|
@ -120,6 +113,8 @@ base128_encode(char *buf, size_t *buflen, const void *data, size_t size)
|
||||||
* return value : #bytes filled in buf (excluding \0)
|
* return value : #bytes filled in buf (excluding \0)
|
||||||
* sets *buflen to : #bytes encoded from data
|
* sets *buflen to : #bytes encoded from data
|
||||||
*/
|
*/
|
||||||
|
static int base128_encode(char *buf, size_t *buflen, const void *data,
|
||||||
|
size_t size)
|
||||||
{
|
{
|
||||||
unsigned char *ubuf = (unsigned char *) buf;
|
unsigned char *ubuf = (unsigned char *) buf;
|
||||||
unsigned char *udata = (unsigned char *) data;
|
unsigned char *udata = (unsigned char *) data;
|
||||||
|
@ -203,8 +198,6 @@ base128_encode(char *buf, size_t *buflen, const void *data, size_t size)
|
||||||
|
|
||||||
#define REV128(x) rev128[(int) (x)]
|
#define REV128(x) rev128[(int) (x)]
|
||||||
|
|
||||||
static int
|
|
||||||
base128_decode(void *buf, size_t *buflen, const char *str, size_t slen)
|
|
||||||
/*
|
/*
|
||||||
* Fills *buf with max. *buflen bytes, decoded from slen chars in *str.
|
* Fills *buf with max. *buflen bytes, decoded from slen chars in *str.
|
||||||
* Decoding stops early when *str contains \0.
|
* Decoding stops early when *str contains \0.
|
||||||
|
@ -216,6 +209,8 @@ base128_decode(void *buf, size_t *buflen, const char *str, size_t slen)
|
||||||
*
|
*
|
||||||
* return value : #bytes filled in buf (excluding \0)
|
* return value : #bytes filled in buf (excluding \0)
|
||||||
*/
|
*/
|
||||||
|
static int base128_decode(void *buf, size_t *buflen, const char *str,
|
||||||
|
size_t slen)
|
||||||
{
|
{
|
||||||
unsigned char *ustr = (unsigned char *) str;
|
unsigned char *ustr = (unsigned char *) str;
|
||||||
unsigned char *ubuf = (unsigned char *) buf;
|
unsigned char *ubuf = (unsigned char *) buf;
|
||||||
|
|
34
src/base32.c
34
src/base32.c
|
@ -35,9 +35,9 @@ static int reverse_init = 0;
|
||||||
|
|
||||||
static int base32_encode(char *, size_t *, const void *, size_t);
|
static int base32_encode(char *, size_t *, const void *, size_t);
|
||||||
static int base32_decode(void *, size_t *, const char *, size_t);
|
static int base32_decode(void *, size_t *, const char *, size_t);
|
||||||
static int base32_handles_dots();
|
static int base32_handles_dots(void);
|
||||||
static int base32_blksize_raw();
|
static int base32_blksize_raw(void);
|
||||||
static int base32_blksize_enc();
|
static int base32_blksize_enc(void);
|
||||||
|
|
||||||
static struct encoder base32_encoder =
|
static struct encoder base32_encoder =
|
||||||
{
|
{
|
||||||
|
@ -50,32 +50,27 @@ static struct encoder base32_encoder =
|
||||||
base32_blksize_enc
|
base32_blksize_enc
|
||||||
};
|
};
|
||||||
|
|
||||||
struct encoder
|
struct encoder *get_base32_encoder(void)
|
||||||
*get_base32_encoder()
|
|
||||||
{
|
{
|
||||||
return &base32_encoder;
|
return &base32_encoder;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int base32_handles_dots(void)
|
||||||
base32_handles_dots()
|
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int base32_blksize_raw(void)
|
||||||
base32_blksize_raw()
|
|
||||||
{
|
{
|
||||||
return BLKSIZE_RAW;
|
return BLKSIZE_RAW;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int base32_blksize_enc(void)
|
||||||
base32_blksize_enc()
|
|
||||||
{
|
{
|
||||||
return BLKSIZE_ENC;
|
return BLKSIZE_ENC;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline static void
|
inline static void base32_reverse_init(void)
|
||||||
base32_reverse_init()
|
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
unsigned char c;
|
unsigned char c;
|
||||||
|
@ -92,21 +87,17 @@ base32_reverse_init()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int b32_5to8(int in)
|
||||||
b32_5to8(int in)
|
|
||||||
{
|
{
|
||||||
return cb32[in & 31];
|
return cb32[in & 31];
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int b32_8to5(int in)
|
||||||
b32_8to5(int in)
|
|
||||||
{
|
{
|
||||||
base32_reverse_init();
|
base32_reverse_init();
|
||||||
return rev32[in];
|
return rev32[in];
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
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.
|
||||||
*
|
*
|
||||||
|
@ -116,6 +107,7 @@ base32_encode(char *buf, size_t *buflen, const void *data, size_t size)
|
||||||
* return value : #bytes filled in buf (excluding \0)
|
* return value : #bytes filled in buf (excluding \0)
|
||||||
* sets *buflen to : #bytes encoded from data
|
* sets *buflen to : #bytes encoded from data
|
||||||
*/
|
*/
|
||||||
|
static int base32_encode(char *buf, size_t *buflen, const void *data, size_t size)
|
||||||
{
|
{
|
||||||
unsigned char *udata = (unsigned char *) data;
|
unsigned char *udata = (unsigned char *) data;
|
||||||
int iout = 0; /* to-be-filled output char */
|
int iout = 0; /* to-be-filled output char */
|
||||||
|
@ -196,8 +188,6 @@ base32_encode(char *buf, size_t *buflen, const void *data, size_t size)
|
||||||
|
|
||||||
#define REV32(x) rev32[(int) (x)]
|
#define REV32(x) rev32[(int) (x)]
|
||||||
|
|
||||||
static int
|
|
||||||
base32_decode(void *buf, size_t *buflen, const char *str, size_t slen)
|
|
||||||
/*
|
/*
|
||||||
* Fills *buf with max. *buflen bytes, decoded from slen chars in *str.
|
* Fills *buf with max. *buflen bytes, decoded from slen chars in *str.
|
||||||
* Decoding stops early when *str contains \0.
|
* Decoding stops early when *str contains \0.
|
||||||
|
@ -209,6 +199,8 @@ base32_decode(void *buf, size_t *buflen, const char *str, size_t slen)
|
||||||
*
|
*
|
||||||
* return value : #bytes filled in buf (excluding \0)
|
* return value : #bytes filled in buf (excluding \0)
|
||||||
*/
|
*/
|
||||||
|
static int base32_decode(void *buf, size_t *buflen, const char *str,
|
||||||
|
size_t slen)
|
||||||
{
|
{
|
||||||
unsigned char *ubuf = (unsigned char *) buf;
|
unsigned char *ubuf = (unsigned char *) buf;
|
||||||
int iout = 0; /* to-be-filled output byte */
|
int iout = 0; /* to-be-filled output byte */
|
||||||
|
|
29
src/base64.c
29
src/base64.c
|
@ -35,9 +35,9 @@ static int reverse_init = 0;
|
||||||
|
|
||||||
static int base64_encode(char *, size_t *, const void *, size_t);
|
static int base64_encode(char *, size_t *, const void *, size_t);
|
||||||
static int base64_decode(void *, size_t *, const char *, size_t);
|
static int base64_decode(void *, size_t *, const char *, size_t);
|
||||||
static int base64_handles_dots();
|
static int base64_handles_dots(void);
|
||||||
static int base64_blksize_raw();
|
static int base64_blksize_raw(void);
|
||||||
static int base64_blksize_enc();
|
static int base64_blksize_enc(void);
|
||||||
|
|
||||||
static struct encoder base64_encoder =
|
static struct encoder base64_encoder =
|
||||||
{
|
{
|
||||||
|
@ -50,32 +50,27 @@ static struct encoder base64_encoder =
|
||||||
base64_blksize_enc
|
base64_blksize_enc
|
||||||
};
|
};
|
||||||
|
|
||||||
struct encoder
|
struct encoder *get_base64_encoder(void)
|
||||||
*get_base64_encoder()
|
|
||||||
{
|
{
|
||||||
return &base64_encoder;
|
return &base64_encoder;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int base64_handles_dots(void)
|
||||||
base64_handles_dots()
|
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int base64_blksize_raw(void)
|
||||||
base64_blksize_raw()
|
|
||||||
{
|
{
|
||||||
return BLKSIZE_RAW;
|
return BLKSIZE_RAW;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int base64_blksize_enc(void)
|
||||||
base64_blksize_enc()
|
|
||||||
{
|
{
|
||||||
return BLKSIZE_ENC;
|
return BLKSIZE_ENC;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline static void
|
inline static void base64_reverse_init(void)
|
||||||
base64_reverse_init()
|
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
unsigned char c;
|
unsigned char c;
|
||||||
|
@ -90,8 +85,6 @@ base64_reverse_init()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
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.
|
||||||
*
|
*
|
||||||
|
@ -101,6 +94,8 @@ base64_encode(char *buf, size_t *buflen, const void *data, size_t size)
|
||||||
* return value : #bytes filled in buf (excluding \0)
|
* return value : #bytes filled in buf (excluding \0)
|
||||||
* sets *buflen to : #bytes encoded from data
|
* sets *buflen to : #bytes encoded from data
|
||||||
*/
|
*/
|
||||||
|
static int base64_encode(char *buf, size_t *buflen, const void *data,
|
||||||
|
size_t size)
|
||||||
{
|
{
|
||||||
unsigned char *udata = (unsigned char *) data;
|
unsigned char *udata = (unsigned char *) data;
|
||||||
int iout = 0; /* to-be-filled output char */
|
int iout = 0; /* to-be-filled output char */
|
||||||
|
@ -151,8 +146,6 @@ base64_encode(char *buf, size_t *buflen, const void *data, size_t size)
|
||||||
|
|
||||||
#define REV64(x) rev64[(int) (x)]
|
#define REV64(x) rev64[(int) (x)]
|
||||||
|
|
||||||
static int
|
|
||||||
base64_decode(void *buf, size_t *buflen, const char *str, size_t slen)
|
|
||||||
/*
|
/*
|
||||||
* Fills *buf with max. *buflen bytes, decoded from slen chars in *str.
|
* Fills *buf with max. *buflen bytes, decoded from slen chars in *str.
|
||||||
* Decoding stops early when *str contains \0.
|
* Decoding stops early when *str contains \0.
|
||||||
|
@ -164,6 +157,8 @@ base64_decode(void *buf, size_t *buflen, const char *str, size_t slen)
|
||||||
*
|
*
|
||||||
* return value : #bytes filled in buf (excluding \0)
|
* return value : #bytes filled in buf (excluding \0)
|
||||||
*/
|
*/
|
||||||
|
static int base64_decode(void *buf, size_t *buflen, const char *str,
|
||||||
|
size_t slen)
|
||||||
{
|
{
|
||||||
unsigned char *ubuf = (unsigned char *) buf;
|
unsigned char *ubuf = (unsigned char *) buf;
|
||||||
int iout = 0; /* to-be-filled output byte */
|
int iout = 0; /* to-be-filled output byte */
|
||||||
|
|
|
@ -346,8 +346,7 @@ send_packet(int fd, char cmd, const char *data, const size_t datalen)
|
||||||
send_query(fd, buf);
|
send_query(fd, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static inline int is_sending(void)
|
||||||
is_sending()
|
|
||||||
{
|
{
|
||||||
return (outpkt.len != 0);
|
return (outpkt.len != 0);
|
||||||
}
|
}
|
||||||
|
|
10
src/client.h
10
src/client.h
|
@ -18,17 +18,17 @@
|
||||||
#ifndef __CLIENT_H__
|
#ifndef __CLIENT_H__
|
||||||
#define __CLIENT_H__
|
#define __CLIENT_H__
|
||||||
|
|
||||||
void client_init();
|
void client_init(void);
|
||||||
void client_stop();
|
void client_stop(void);
|
||||||
|
|
||||||
enum connection client_get_conn();
|
enum connection client_get_conn(void);
|
||||||
const char *client_get_raw_addr();
|
const char *client_get_raw_addr(void);
|
||||||
|
|
||||||
void client_set_nameserver(struct sockaddr_storage *, int);
|
void client_set_nameserver(struct sockaddr_storage *, int);
|
||||||
void client_set_topdomain(const char *cp);
|
void client_set_topdomain(const char *cp);
|
||||||
void client_set_password(const char *cp);
|
void client_set_password(const char *cp);
|
||||||
int client_set_qtype(char *qtype);
|
int client_set_qtype(char *qtype);
|
||||||
char *client_get_qtype();
|
char *client_get_qtype(void);
|
||||||
void client_set_downenc(char *encoding);
|
void client_set_downenc(char *encoding);
|
||||||
void client_set_selecttimeout(int select_timeout);
|
void client_set_selecttimeout(int select_timeout);
|
||||||
void client_set_lazymode(int lazy_mode);
|
void client_set_lazymode(int lazy_mode);
|
||||||
|
|
|
@ -118,7 +118,7 @@ void close_dns(int);
|
||||||
|
|
||||||
void do_chroot(char *);
|
void do_chroot(char *);
|
||||||
void do_setcon(char *);
|
void do_setcon(char *);
|
||||||
void do_detach();
|
void do_detach(void);
|
||||||
void do_pidfile(char *);
|
void do_pidfile(char *);
|
||||||
|
|
||||||
void read_password(char*, size_t);
|
void read_password(char*, size_t);
|
||||||
|
|
|
@ -33,7 +33,7 @@ struct fw_query {
|
||||||
unsigned short id;
|
unsigned short id;
|
||||||
};
|
};
|
||||||
|
|
||||||
void fw_query_init();
|
void fw_query_init(void);
|
||||||
void fw_query_put(struct fw_query *fw_query);
|
void fw_query_put(struct fw_query *fw_query);
|
||||||
void fw_query_get(unsigned short query_id, struct fw_query **fw_query);
|
void fw_query_get(unsigned short query_id, struct fw_query **fw_query);
|
||||||
|
|
||||||
|
|
|
@ -111,8 +111,7 @@ static inline void usage(void)
|
||||||
help(stderr, false);
|
help(stderr, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void version(void)
|
||||||
version()
|
|
||||||
{
|
{
|
||||||
fprintf(stderr, "iodine IP over DNS tunneling client\n"
|
fprintf(stderr, "iodine IP over DNS tunneling client\n"
|
||||||
"Git version: %s\n", GITREVISION);
|
"Git version: %s\n", GITREVISION);
|
||||||
|
@ -120,8 +119,7 @@ version()
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int main(int argc, char **argv)
|
||||||
main(int argc, char **argv)
|
|
||||||
{
|
{
|
||||||
char *nameserv_host;
|
char *nameserv_host;
|
||||||
char *topdomain;
|
char *topdomain;
|
||||||
|
|
|
@ -199,17 +199,15 @@ sigint(int sig)
|
||||||
#define LOG_NOTICE 5
|
#define LOG_NOTICE 5
|
||||||
#define LOG_INFO 6
|
#define LOG_INFO 6
|
||||||
#define LOG_DEBUG 7
|
#define LOG_DEBUG 7
|
||||||
static void
|
|
||||||
syslog(int a, const char *str, ...)
|
static void syslog(int a, const char *str, ...)
|
||||||
{
|
{
|
||||||
/* TODO: implement (add to event log), move to common.c */
|
/* TODO: implement (add to event log), move to common.c */
|
||||||
;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* This will not check that user has passed login challenge */
|
/* This will not check that user has passed login challenge */
|
||||||
static int
|
static int check_user_and_ip(int userid, struct query *q)
|
||||||
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 */
|
||||||
|
|
||||||
|
@ -252,8 +250,7 @@ check_user_and_ip(int userid, struct query *q)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This checks that user has passed normal (non-raw) login challenge */
|
/* This checks that user has passed normal (non-raw) login challenge */
|
||||||
static int
|
static int check_authenticated_user_and_ip(int userid, struct query *q)
|
||||||
check_authenticated_user_and_ip(int userid, struct query *q)
|
|
||||||
{
|
{
|
||||||
int res = check_user_and_ip(userid, q);
|
int res = check_user_and_ip(userid, q);
|
||||||
if (res)
|
if (res)
|
||||||
|
@ -265,8 +262,7 @@ check_authenticated_user_and_ip(int userid, struct query *q)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void send_raw(int fd, char *buf, int buflen, int user, int cmd, struct query *q)
|
||||||
send_raw(int fd, char *buf, int buflen, int user, int cmd, struct query *q)
|
|
||||||
{
|
{
|
||||||
char packet[4096];
|
char packet[4096];
|
||||||
int len;
|
int len;
|
||||||
|
@ -290,8 +286,7 @@ send_raw(int fd, char *buf, int buflen, int user, int cmd, struct query *q)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void start_new_outpacket(int userid, char *data, int datalen)
|
||||||
start_new_outpacket(int userid, char *data, int datalen)
|
|
||||||
/* Copies data to .outpacket and resets all counters.
|
/* Copies data to .outpacket and resets all counters.
|
||||||
data is expected to be compressed already. */
|
data is expected to be compressed already. */
|
||||||
{
|
{
|
||||||
|
@ -307,8 +302,7 @@ start_new_outpacket(int userid, char *data, int datalen)
|
||||||
|
|
||||||
#ifdef OUTPACKETQ_LEN
|
#ifdef OUTPACKETQ_LEN
|
||||||
|
|
||||||
static int
|
static int save_to_outpacketq(int userid, char *data, int datalen)
|
||||||
save_to_outpacketq(int userid, char *data, int datalen)
|
|
||||||
/* Find space in outpacket-queue and store data (expected compressed already).
|
/* Find space in outpacket-queue and store data (expected compressed already).
|
||||||
Returns: 1 = okay, 0 = no space. */
|
Returns: 1 = okay, 0 = no space. */
|
||||||
{
|
{
|
||||||
|
@ -336,8 +330,7 @@ save_to_outpacketq(int userid, char *data, int datalen)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int get_from_outpacketq(int userid)
|
||||||
get_from_outpacketq(int userid)
|
|
||||||
/* Starts new outpacket from queue, if any.
|
/* Starts new outpacket from queue, if any.
|
||||||
Returns: 1 = okay, 0 = no packets were waiting. */
|
Returns: 1 = okay, 0 = no packets were waiting. */
|
||||||
{
|
{
|
||||||
|
@ -384,8 +377,7 @@ get_from_outpacketq(int userid)
|
||||||
number, and of course data.)
|
number, and of course data.)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void
|
static void save_to_dnscache(int userid, struct query *q, char *answer, int answerlen)
|
||||||
save_to_dnscache(int userid, struct query *q, char *answer, int answerlen)
|
|
||||||
/* Store answer in our little DNS cache. */
|
/* Store answer in our little DNS cache. */
|
||||||
{
|
{
|
||||||
int fill;
|
int fill;
|
||||||
|
@ -404,8 +396,7 @@ save_to_dnscache(int userid, struct query *q, char *answer, int answerlen)
|
||||||
users[userid].dnscache_lastfilled = fill;
|
users[userid].dnscache_lastfilled = fill;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int answer_from_dnscache(int dns_fd, int userid, struct query *q)
|
||||||
answer_from_dnscache(int dns_fd, int userid, struct query *q)
|
|
||||||
/* Checks cache and sends repeated answer if we alreay saw this query recently.
|
/* Checks cache and sends repeated answer if we alreay saw this query recently.
|
||||||
Returns: 1 = answer sent, drop this query, 0 = no answer sent, this is
|
Returns: 1 = answer sent, drop this query, 0 = no answer sent, this is
|
||||||
a new query. */
|
a new query. */
|
||||||
|
@ -446,9 +437,10 @@ answer_from_dnscache(int dns_fd, int userid, struct query *q)
|
||||||
|
|
||||||
#endif /* DNSCACHE_LEN */
|
#endif /* DNSCACHE_LEN */
|
||||||
|
|
||||||
static inline void
|
static inline void save_to_qmem(unsigned char *qmem_cmc,
|
||||||
save_to_qmem(unsigned char *qmem_cmc, unsigned short *qmem_type, int qmem_len,
|
unsigned short *qmem_type, int qmem_len,
|
||||||
int *qmem_lastfilled, unsigned char *cmc_to_add,
|
int *qmem_lastfilled,
|
||||||
|
unsigned char *cmc_to_add,
|
||||||
unsigned short type_to_add)
|
unsigned short type_to_add)
|
||||||
/* Remember query to check for duplicates */
|
/* Remember query to check for duplicates */
|
||||||
{
|
{
|
||||||
|
@ -463,8 +455,7 @@ save_to_qmem(unsigned char *qmem_cmc, unsigned short *qmem_type, int qmem_len,
|
||||||
*qmem_lastfilled = fill;
|
*qmem_lastfilled = fill;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void save_to_qmem_pingordata(int userid, struct query *q)
|
||||||
save_to_qmem_pingordata(int userid, struct query *q)
|
|
||||||
{
|
{
|
||||||
/* Our CMC is a bit more than the "official" CMC; we store 4 bytes
|
/* Our CMC is a bit more than the "official" CMC; we store 4 bytes
|
||||||
just because we can, and because it may prevent some false matches.
|
just because we can, and because it may prevent some false matches.
|
||||||
|
@ -519,10 +510,9 @@ save_to_qmem_pingordata(int userid, struct query *q)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int answer_from_qmem(int dns_fd, struct query *q,
|
||||||
answer_from_qmem(int dns_fd, struct query *q, unsigned char *qmem_cmc,
|
unsigned char *qmem_cmc, unsigned short *qmem_type,
|
||||||
unsigned short *qmem_type, int qmem_len,
|
int qmem_len, unsigned char *cmc_to_check)
|
||||||
unsigned char *cmc_to_check)
|
|
||||||
/* Checks query memory and sends an (illegal) answer if this is a duplicate.
|
/* Checks query memory and sends an (illegal) answer if this is a duplicate.
|
||||||
Returns: 1 = answer sent, drop this query, 0 = no answer sent, this is
|
Returns: 1 = answer sent, drop this query, 0 = no answer sent, this is
|
||||||
not a duplicate. */
|
not a duplicate. */
|
||||||
|
@ -552,9 +542,9 @@ answer_from_qmem(int dns_fd, struct query *q, unsigned char *qmem_cmc,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
|
||||||
answer_from_qmem_data(int dns_fd, int userid, struct query *q)
|
|
||||||
/* Quick helper function to keep handle_null_request() clean */
|
/* Quick helper function to keep handle_null_request() clean */
|
||||||
|
static inline int answer_from_qmem_data(int dns_fd, int userid,
|
||||||
|
struct query *q)
|
||||||
{
|
{
|
||||||
char cmc[4];
|
char cmc[4];
|
||||||
int i;
|
int i;
|
||||||
|
@ -570,8 +560,6 @@ answer_from_qmem_data(int dns_fd, int userid, struct query *q)
|
||||||
(void *) cmc);
|
(void *) cmc);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
send_chunk_or_dataless(int dns_fd, int userid, struct query *q)
|
|
||||||
/* Sends current fragment to user, or dataless packet if there is no
|
/* Sends current fragment to user, or dataless packet if there is no
|
||||||
current fragment available (-> normal "quiet" ping reply).
|
current fragment available (-> normal "quiet" ping reply).
|
||||||
Does not update anything, except:
|
Does not update anything, except:
|
||||||
|
@ -581,6 +569,7 @@ send_chunk_or_dataless(int dns_fd, int userid, struct query *q)
|
||||||
Returns: 1 = can call us again immediately, new packet from queue;
|
Returns: 1 = can call us again immediately, new packet from queue;
|
||||||
0 = don't call us again for now.
|
0 = don't call us again for now.
|
||||||
*/
|
*/
|
||||||
|
static int send_chunk_or_dataless(int dns_fd, int userid, struct query *q)
|
||||||
{
|
{
|
||||||
char pkt[4096];
|
char pkt[4096];
|
||||||
int datalen = 0;
|
int datalen = 0;
|
||||||
|
@ -664,8 +653,7 @@ send_chunk_or_dataless(int dns_fd, int userid, struct query *q)
|
||||||
return 0; /* don't call us again */
|
return 0; /* don't call us again */
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int tunnel_tun(int tun_fd, struct dnsfd *dns_fds)
|
||||||
tunnel_tun(int tun_fd, struct dnsfd *dns_fds)
|
|
||||||
{
|
{
|
||||||
unsigned long outlen;
|
unsigned long outlen;
|
||||||
struct ip *header;
|
struct ip *header;
|
||||||
|
@ -722,8 +710,8 @@ typedef enum {
|
||||||
VERSION_FULL
|
VERSION_FULL
|
||||||
} version_ack_t;
|
} version_ack_t;
|
||||||
|
|
||||||
static void
|
static void send_version_response(int fd, version_ack_t ack, uint32_t payload,
|
||||||
send_version_response(int fd, version_ack_t ack, uint32_t payload, int userid, struct query *q)
|
int userid, struct query *q)
|
||||||
{
|
{
|
||||||
char out[9];
|
char out[9];
|
||||||
|
|
||||||
|
@ -748,12 +736,11 @@ send_version_response(int fd, version_ack_t ack, uint32_t payload, int userid, s
|
||||||
write_dns(fd, q, out, sizeof(out), users[userid].downenc);
|
write_dns(fd, q, out, sizeof(out), users[userid].downenc);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
process_downstream_ack(int userid, int down_seq, int down_frag)
|
|
||||||
/* Process acks from downstream fragments.
|
/* Process acks from downstream fragments.
|
||||||
After this, .offset and .fragment are updated (if ack correct),
|
After this, .offset and .fragment are updated (if ack correct),
|
||||||
or .len is set to zero when all is done.
|
or .len is set to zero when all is done.
|
||||||
*/
|
*/
|
||||||
|
static void process_downstream_ack(int userid, int down_seq, int down_frag)
|
||||||
{
|
{
|
||||||
if (users[userid].outpacket.len <= 0)
|
if (users[userid].outpacket.len <= 0)
|
||||||
/* No packet to apply acks to */
|
/* No packet to apply acks to */
|
||||||
|
@ -2340,16 +2327,15 @@ static void help(FILE *stream)
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void version(void)
|
||||||
version() {
|
{
|
||||||
fprintf(stderr, "iodine IP over DNS tunneling server\n"
|
fprintf(stderr, "iodine IP over DNS tunneling server\n"
|
||||||
"Git version: %s\n", GITREVISION);
|
"Git version: %s\n", GITREVISION);
|
||||||
|
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void prepare_dns_fd(int fd)
|
||||||
prepare_dns_fd(int fd)
|
|
||||||
{
|
{
|
||||||
#ifndef WINDOWS32
|
#ifndef WINDOWS32
|
||||||
int flag = 1;
|
int flag = 1;
|
||||||
|
|
21
src/user.c
21
src/user.c
|
@ -37,8 +37,7 @@
|
||||||
struct tun_user *users;
|
struct tun_user *users;
|
||||||
unsigned usercount;
|
unsigned usercount;
|
||||||
|
|
||||||
int
|
int init_users(in_addr_t my_ip, int netbits)
|
||||||
init_users(in_addr_t my_ip, int netbits)
|
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int skip = 0;
|
int skip = 0;
|
||||||
|
@ -84,16 +83,14 @@ init_users(in_addr_t my_ip, int netbits)
|
||||||
return usercount;
|
return usercount;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char*
|
const char *users_get_first_ip(void)
|
||||||
users_get_first_ip()
|
|
||||||
{
|
{
|
||||||
struct in_addr ip;
|
struct in_addr ip;
|
||||||
ip.s_addr = users[0].tun_ip;
|
ip.s_addr = users[0].tun_ip;
|
||||||
return strdup(inet_ntoa(ip));
|
return strdup(inet_ntoa(ip));
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int find_user_by_ip(uint32_t ip)
|
||||||
find_user_by_ip(uint32_t ip)
|
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
int i;
|
int i;
|
||||||
|
@ -112,13 +109,12 @@ find_user_by_ip(uint32_t ip)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
|
||||||
all_users_waiting_to_send()
|
|
||||||
/* If this returns true, then reading from tun device is blocked.
|
/* If this returns true, then reading from tun device is blocked.
|
||||||
So only return true when all clients have at least one packet in
|
So only return true when all clients have at least one packet in
|
||||||
the outpacket-queue, so that sending back-to-back is possible
|
the outpacket-queue, so that sending back-to-back is possible
|
||||||
without going through another select loop.
|
without going through another select loop.
|
||||||
*/
|
*/
|
||||||
|
int all_users_waiting_to_send(void)
|
||||||
{
|
{
|
||||||
time_t now;
|
time_t now;
|
||||||
int ret;
|
int ret;
|
||||||
|
@ -145,8 +141,7 @@ all_users_waiting_to_send()
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int find_available_user(void)
|
||||||
find_available_user()
|
|
||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
int i;
|
int i;
|
||||||
|
@ -166,8 +161,7 @@ find_available_user()
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void user_switch_codec(int userid, struct encoder *enc)
|
||||||
user_switch_codec(int userid, struct encoder *enc)
|
|
||||||
{
|
{
|
||||||
if (userid < 0 || userid >= usercount)
|
if (userid < 0 || userid >= usercount)
|
||||||
return;
|
return;
|
||||||
|
@ -175,8 +169,7 @@ user_switch_codec(int userid, struct encoder *enc)
|
||||||
users[userid].encoder = enc;
|
users[userid].encoder = enc;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void user_set_conn_type(int userid, enum connection c)
|
||||||
user_set_conn_type(int userid, enum connection c)
|
|
||||||
{
|
{
|
||||||
if (userid < 0 || userid >= usercount)
|
if (userid < 0 || userid >= usercount)
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -80,10 +80,10 @@ struct tun_user {
|
||||||
extern struct tun_user *users;
|
extern struct tun_user *users;
|
||||||
|
|
||||||
int init_users(in_addr_t, int);
|
int init_users(in_addr_t, int);
|
||||||
const char* users_get_first_ip();
|
const char* users_get_first_ip(void);
|
||||||
int find_user_by_ip(uint32_t);
|
int find_user_by_ip(uint32_t);
|
||||||
int all_users_waiting_to_send();
|
int all_users_waiting_to_send(void);
|
||||||
int find_available_user();
|
int find_available_user(void);
|
||||||
void user_switch_codec(int userid, struct encoder *enc);
|
void user_switch_codec(int userid, struct encoder *enc);
|
||||||
void user_set_conn_type(int userid, enum connection c);
|
void user_set_conn_type(int userid, enum connection c);
|
||||||
|
|
||||||
|
|
|
@ -19,8 +19,7 @@
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
char *
|
char *get_resolvconf_addr(void)
|
||||||
get_resolvconf_addr()
|
|
||||||
{
|
{
|
||||||
static char addr[16];
|
static char addr[16];
|
||||||
char *rv;
|
char *rv;
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
#ifndef __UTIL_H__
|
#ifndef __UTIL_H__
|
||||||
#define __UTIL_H__
|
#define __UTIL_H__
|
||||||
|
|
||||||
char *get_resolvconf_addr();
|
char *get_resolvconf_addr(void);
|
||||||
void socket_setrtable(int fd, int rtable);
|
void socket_setrtable(int fd, int rtable);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue