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:
Ralf Ramsauer 2017-03-11 02:36:54 -08:00
parent ccc49f16f7
commit 52c4940523
15 changed files with 90 additions and 132 deletions

View File

@ -11,6 +11,7 @@ HEAD_COMMIT = `git rev-parse --short HEAD`
LIBPATH = -L.
LDFLAGS += -lz `sh osflags $(TARGETOS) link` $(LIBPATH)
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)

View File

@ -47,7 +47,7 @@ typedef struct {
#define C_IN 1
#define T_A 1
#define T_A 1
#define T_CNAME 5
#define T_NULL 10
#define T_MX 15

View File

@ -54,9 +54,9 @@ static int reverse_init = 0;
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_handles_dots();
static int base128_blksize_raw();
static int base128_blksize_enc();
static int base128_handles_dots(void);
static int base128_blksize_raw(void);
static int base128_blksize_enc(void);
static struct encoder base128_encoder =
{
@ -69,32 +69,27 @@ static struct encoder base128_encoder =
base128_blksize_enc
};
struct encoder
*get_base128_encoder()
struct encoder *get_base128_encoder(void)
{
return &base128_encoder;
}
static int
base128_handles_dots()
static int base128_handles_dots(void)
{
return 0;
}
static int
base128_blksize_raw()
static int base128_blksize_raw(void)
{
return BLKSIZE_RAW;
}
static int
base128_blksize_enc()
static int base128_blksize_enc(void)
{
return BLKSIZE_ENC;
}
inline static void
base128_reverse_init()
inline static void base128_reverse_init(void)
{
int i;
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.
*
@ -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)
* 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 *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)]
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.
* 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)
*/
static int base128_decode(void *buf, size_t *buflen, const char *str,
size_t slen)
{
unsigned char *ustr = (unsigned char *) str;
unsigned char *ubuf = (unsigned char *) buf;

View File

@ -35,9 +35,9 @@ static int reverse_init = 0;
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_handles_dots();
static int base32_blksize_raw();
static int base32_blksize_enc();
static int base32_handles_dots(void);
static int base32_blksize_raw(void);
static int base32_blksize_enc(void);
static struct encoder base32_encoder =
{
@ -50,32 +50,27 @@ static struct encoder base32_encoder =
base32_blksize_enc
};
struct encoder
*get_base32_encoder()
struct encoder *get_base32_encoder(void)
{
return &base32_encoder;
}
static int
base32_handles_dots()
static int base32_handles_dots(void)
{
return 0;
}
static int
base32_blksize_raw()
static int base32_blksize_raw(void)
{
return BLKSIZE_RAW;
}
static int
base32_blksize_enc()
static int base32_blksize_enc(void)
{
return BLKSIZE_ENC;
}
inline static void
base32_reverse_init()
inline static void base32_reverse_init(void)
{
int i;
unsigned char c;
@ -92,21 +87,17 @@ base32_reverse_init()
}
}
int
b32_5to8(int in)
int b32_5to8(int in)
{
return cb32[in & 31];
}
int
b32_8to5(int in)
int b32_8to5(int in)
{
base32_reverse_init();
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.
*
@ -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)
* 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;
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)]
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.
* 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)
*/
static int base32_decode(void *buf, size_t *buflen, const char *str,
size_t slen)
{
unsigned char *ubuf = (unsigned char *) buf;
int iout = 0; /* to-be-filled output byte */

View File

@ -35,9 +35,9 @@ static int reverse_init = 0;
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_handles_dots();
static int base64_blksize_raw();
static int base64_blksize_enc();
static int base64_handles_dots(void);
static int base64_blksize_raw(void);
static int base64_blksize_enc(void);
static struct encoder base64_encoder =
{
@ -50,32 +50,27 @@ static struct encoder base64_encoder =
base64_blksize_enc
};
struct encoder
*get_base64_encoder()
struct encoder *get_base64_encoder(void)
{
return &base64_encoder;
}
static int
base64_handles_dots()
static int base64_handles_dots(void)
{
return 0;
}
static int
base64_blksize_raw()
static int base64_blksize_raw(void)
{
return BLKSIZE_RAW;
}
static int
base64_blksize_enc()
static int base64_blksize_enc(void)
{
return BLKSIZE_ENC;
}
inline static void
base64_reverse_init()
inline static void base64_reverse_init(void)
{
int i;
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.
*
@ -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)
* 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;
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)]
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.
* 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)
*/
static int base64_decode(void *buf, size_t *buflen, const char *str,
size_t slen)
{
unsigned char *ubuf = (unsigned char *) buf;
int iout = 0; /* to-be-filled output byte */

View File

@ -346,8 +346,7 @@ send_packet(int fd, char cmd, const char *data, const size_t datalen)
send_query(fd, buf);
}
static inline int
is_sending()
static inline int is_sending(void)
{
return (outpkt.len != 0);
}

View File

@ -18,17 +18,17 @@
#ifndef __CLIENT_H__
#define __CLIENT_H__
void client_init();
void client_stop();
void client_init(void);
void client_stop(void);
enum connection client_get_conn();
const char *client_get_raw_addr();
enum connection client_get_conn(void);
const char *client_get_raw_addr(void);
void client_set_nameserver(struct sockaddr_storage *, int);
void client_set_topdomain(const char *cp);
void client_set_password(const char *cp);
int client_set_qtype(char *qtype);
char *client_get_qtype();
char *client_get_qtype(void);
void client_set_downenc(char *encoding);
void client_set_selecttimeout(int select_timeout);
void client_set_lazymode(int lazy_mode);

View File

@ -118,7 +118,7 @@ void close_dns(int);
void do_chroot(char *);
void do_setcon(char *);
void do_detach();
void do_detach(void);
void do_pidfile(char *);
void read_password(char*, size_t);

View File

@ -33,7 +33,7 @@ struct fw_query {
unsigned short id;
};
void fw_query_init();
void fw_query_init(void);
void fw_query_put(struct fw_query *fw_query);
void fw_query_get(unsigned short query_id, struct fw_query **fw_query);

View File

@ -111,8 +111,7 @@ static inline void usage(void)
help(stderr, false);
}
static void
version()
static void version(void)
{
fprintf(stderr, "iodine IP over DNS tunneling client\n"
"Git version: %s\n", GITREVISION);
@ -120,8 +119,7 @@ version()
exit(0);
}
int
main(int argc, char **argv)
int main(int argc, char **argv)
{
char *nameserv_host;
char *topdomain;

View File

@ -199,17 +199,15 @@ sigint(int sig)
#define LOG_NOTICE 5
#define LOG_INFO 6
#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 */
;
}
#endif
/* This will not check that user has passed login challenge */
static int
check_user_and_ip(int userid, struct query *q)
static int check_user_and_ip(int userid, struct query *q)
{
/* 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 */
static int
check_authenticated_user_and_ip(int userid, struct query *q)
static int check_authenticated_user_and_ip(int userid, struct query *q)
{
int res = check_user_and_ip(userid, q);
if (res)
@ -265,8 +262,7 @@ check_authenticated_user_and_ip(int userid, struct query *q)
return 0;
}
static void
send_raw(int fd, char *buf, int buflen, int user, int cmd, struct query *q)
static void send_raw(int fd, char *buf, int buflen, int user, int cmd, struct query *q)
{
char packet[4096];
int len;
@ -290,8 +286,7 @@ send_raw(int fd, char *buf, int buflen, int user, int cmd, struct query *q)
}
static void
start_new_outpacket(int userid, char *data, int datalen)
static void start_new_outpacket(int userid, char *data, int datalen)
/* Copies data to .outpacket and resets all counters.
data is expected to be compressed already. */
{
@ -307,8 +302,7 @@ start_new_outpacket(int userid, char *data, int datalen)
#ifdef OUTPACKETQ_LEN
static int
save_to_outpacketq(int userid, char *data, int datalen)
static int save_to_outpacketq(int userid, char *data, int datalen)
/* Find space in outpacket-queue and store data (expected compressed already).
Returns: 1 = okay, 0 = no space. */
{
@ -336,8 +330,7 @@ save_to_outpacketq(int userid, char *data, int datalen)
return 1;
}
static int
get_from_outpacketq(int userid)
static int get_from_outpacketq(int userid)
/* Starts new outpacket from queue, if any.
Returns: 1 = okay, 0 = no packets were waiting. */
{
@ -384,8 +377,7 @@ get_from_outpacketq(int userid)
number, and of course data.)
*/
static void
save_to_dnscache(int userid, struct query *q, char *answer, int answerlen)
static void save_to_dnscache(int userid, struct query *q, char *answer, int answerlen)
/* Store answer in our little DNS cache. */
{
int fill;
@ -404,8 +396,7 @@ save_to_dnscache(int userid, struct query *q, char *answer, int answerlen)
users[userid].dnscache_lastfilled = fill;
}
static int
answer_from_dnscache(int dns_fd, int userid, struct query *q)
static int answer_from_dnscache(int dns_fd, int userid, struct query *q)
/* 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
a new query. */
@ -446,10 +437,11 @@ answer_from_dnscache(int dns_fd, int userid, struct query *q)
#endif /* DNSCACHE_LEN */
static inline void
save_to_qmem(unsigned char *qmem_cmc, unsigned short *qmem_type, int qmem_len,
int *qmem_lastfilled, unsigned char *cmc_to_add,
unsigned short type_to_add)
static inline void save_to_qmem(unsigned char *qmem_cmc,
unsigned short *qmem_type, int qmem_len,
int *qmem_lastfilled,
unsigned char *cmc_to_add,
unsigned short type_to_add)
/* Remember query to check for duplicates */
{
int fill;
@ -463,8 +455,7 @@ save_to_qmem(unsigned char *qmem_cmc, unsigned short *qmem_type, int qmem_len,
*qmem_lastfilled = fill;
}
static inline void
save_to_qmem_pingordata(int userid, struct query *q)
static inline void save_to_qmem_pingordata(int userid, struct query *q)
{
/* 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.
@ -519,10 +510,9 @@ save_to_qmem_pingordata(int userid, struct query *q)
}
}
static int
answer_from_qmem(int dns_fd, struct query *q, unsigned char *qmem_cmc,
unsigned short *qmem_type, int qmem_len,
unsigned char *cmc_to_check)
static int answer_from_qmem(int dns_fd, struct query *q,
unsigned char *qmem_cmc, unsigned short *qmem_type,
int qmem_len, unsigned char *cmc_to_check)
/* 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
not a duplicate. */
@ -552,9 +542,9 @@ answer_from_qmem(int dns_fd, struct query *q, unsigned char *qmem_cmc,
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 */
static inline int answer_from_qmem_data(int dns_fd, int userid,
struct query *q)
{
char cmc[4];
int i;
@ -570,8 +560,6 @@ answer_from_qmem_data(int dns_fd, int userid, struct query *q)
(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
current fragment available (-> normal "quiet" ping reply).
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;
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];
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 */
}
static int
tunnel_tun(int tun_fd, struct dnsfd *dns_fds)
static int tunnel_tun(int tun_fd, struct dnsfd *dns_fds)
{
unsigned long outlen;
struct ip *header;
@ -722,8 +710,8 @@ typedef enum {
VERSION_FULL
} version_ack_t;
static void
send_version_response(int fd, version_ack_t ack, uint32_t payload, int userid, struct query *q)
static void send_version_response(int fd, version_ack_t ack, uint32_t payload,
int userid, struct query *q)
{
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);
}
static void
process_downstream_ack(int userid, int down_seq, int down_frag)
/* Process acks from downstream fragments.
After this, .offset and .fragment are updated (if ack correct),
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)
/* No packet to apply acks to */
@ -2340,16 +2327,15 @@ static void help(FILE *stream)
exit(0);
}
static void
version() {
static void version(void)
{
fprintf(stderr, "iodine IP over DNS tunneling server\n"
"Git version: %s\n", GITREVISION);
exit(0);
}
static void
prepare_dns_fd(int fd)
static void prepare_dns_fd(int fd)
{
#ifndef WINDOWS32
int flag = 1;

View File

@ -37,8 +37,7 @@
struct tun_user *users;
unsigned usercount;
int
init_users(in_addr_t my_ip, int netbits)
int init_users(in_addr_t my_ip, int netbits)
{
int i;
int skip = 0;
@ -84,16 +83,14 @@ init_users(in_addr_t my_ip, int netbits)
return usercount;
}
const char*
users_get_first_ip()
const char *users_get_first_ip(void)
{
struct in_addr ip;
ip.s_addr = users[0].tun_ip;
return strdup(inet_ntoa(ip));
}
int
find_user_by_ip(uint32_t ip)
int find_user_by_ip(uint32_t ip)
{
int ret;
int i;
@ -112,13 +109,12 @@ find_user_by_ip(uint32_t ip)
return ret;
}
int
all_users_waiting_to_send()
/* If this returns true, then reading from tun device is blocked.
So only return true when all clients have at least one packet in
the outpacket-queue, so that sending back-to-back is possible
without going through another select loop.
*/
int all_users_waiting_to_send(void)
{
time_t now;
int ret;
@ -145,8 +141,7 @@ all_users_waiting_to_send()
return ret;
}
int
find_available_user()
int find_available_user(void)
{
int ret = -1;
int i;
@ -166,8 +161,7 @@ find_available_user()
return ret;
}
void
user_switch_codec(int userid, struct encoder *enc)
void user_switch_codec(int userid, struct encoder *enc)
{
if (userid < 0 || userid >= usercount)
return;
@ -175,8 +169,7 @@ user_switch_codec(int userid, struct encoder *enc)
users[userid].encoder = enc;
}
void
user_set_conn_type(int userid, enum connection c)
void user_set_conn_type(int userid, enum connection c)
{
if (userid < 0 || userid >= usercount)
return;

View File

@ -80,10 +80,10 @@ struct tun_user {
extern struct tun_user *users;
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 all_users_waiting_to_send();
int find_available_user();
int all_users_waiting_to_send(void);
int find_available_user(void);
void user_switch_codec(int userid, struct encoder *enc);
void user_set_conn_type(int userid, enum connection c);

View File

@ -19,8 +19,7 @@
#include "common.h"
#include "util.h"
char *
get_resolvconf_addr()
char *get_resolvconf_addr(void)
{
static char addr[16];
char *rv;

View File

@ -18,7 +18,7 @@
#ifndef __UTIL_H__
#define __UTIL_H__
char *get_resolvconf_addr();
char *get_resolvconf_addr(void);
void socket_setrtable(int fd, int rtable);
#endif