Skip to content

Commit

Permalink
Applying patch that reduces compile warnings and fixes warnings from …
Browse files Browse the repository at this point in the history
…gcc and clang.

Patch contributed by: Gareth ([email protected])
  • Loading branch information
shussain committed Dec 3, 2018
1 parent 69813b5 commit bca2026
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ OSFLAGS+= -DUSE_KERNEL

IPFLAGS?= -DIP_ALLOCATION

CFLAGS+= $(DFLAGS) -Os -Wall -DSANITY $(OSFLAGS) $(IPFLAGS)
CFLAGS+= $(DFLAGS) -Os -Wall -Wextra -DSANITY $(OSFLAGS) $(IPFLAGS)
HDRS=l2tp.h avp.h misc.h control.h call.h scheduler.h file.h aaa.h md5.h
OBJS=xl2tpd.o pty.o misc.o control.o avp.o call.o network.o avpsend.o scheduler.o file.o aaa.o md5.o
SRCS=${OBJS:.o=.c} ${HDRS}
Expand Down
3 changes: 3 additions & 0 deletions avp.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,8 @@ int ignore_avp (struct tunnel *t, struct call *c, void *data, int datalen)
* One option is to simply change the options we pass to pppd.
*
*/
UNUSED(data);
UNUSED(datalen);
if (gconfig.debug_avp)
{
if (DEBUG)
Expand All @@ -398,6 +400,7 @@ int ignore_avp (struct tunnel *t, struct call *c, void *data, int datalen)

int seq_reqd_avp (struct tunnel *t, struct call *c, void *data, int datalen)
{
UNUSED(data);
#ifdef SANITY
if (t->sanity)
{
Expand Down
2 changes: 2 additions & 0 deletions call.c
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,8 @@ struct call *new_call (struct tunnel *parent)

struct call *get_tunnel (int tunnel, unsigned int addr, int port)
{
UNUSED(addr);
UNUSED(port);
struct tunnel *st;
if (tunnel)
{
Expand Down
21 changes: 11 additions & 10 deletions control.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void add_fcs (struct buffer *buf)
{
_u16 fcs = PPP_INITFCS;
unsigned char *c = buf->start;
int x;
size_t x;
for (x = 0; x < buf->len; x++)
{
fcs = PPP_FCS (fcs, *c);
Expand Down Expand Up @@ -1314,7 +1314,7 @@ static inline int check_payload (struct buffer *buf, struct tunnel *t,
* or not. Returns 0 on success.
*/

int ehlen = MIN_PAYLOAD_HDR_LEN;
size_t ehlen = MIN_PAYLOAD_HDR_LEN;
struct payload_hdr *h = (struct payload_hdr *) (buf->start);
if (!c)
{
Expand Down Expand Up @@ -1415,6 +1415,7 @@ static inline int check_payload (struct buffer *buf, struct tunnel *t,
static inline int expand_payload (struct buffer *buf, struct tunnel *t,
struct call *c)
{
UNUSED(t);
/*
* Expands payload header. Does not check for valid header,
* check_payload() should already be called as a prerequisite.
Expand Down Expand Up @@ -1599,7 +1600,7 @@ static inline int write_packet (struct buffer *buf, struct tunnel *t, struct cal
* Write a packet, doing sync->async conversion if
* necessary
*/
int x;
size_t x;
unsigned char e;
int err;
static unsigned char wbuf[MAX_RECV_SIZE];
Expand Down Expand Up @@ -1629,17 +1630,17 @@ static inline int write_packet (struct buffer *buf, struct tunnel *t, struct cal
/* We are given async frames, so write them
directly to the tty */
err = write (c->fd, buf->start, buf->len);
if (err == buf->len)
if ((size_t)err == buf->len)
{
return 0;
}
else if (err == 0)
else if ((size_t)err == 0)
{
l2tp_log (LOG_WARNING, "%s: wrote no bytes of async packet\n",
__FUNCTION__);
return -EINVAL;
}
else if (err < 0)
else if ((size_t)err < 0)
{
if ((errno == EAGAIN) || (errno == EINTR))
{
Expand All @@ -1651,13 +1652,13 @@ static inline int write_packet (struct buffer *buf, struct tunnel *t, struct cal
strerror (errno));
}
}
else if (err < buf->len)
else if ((size_t)err < buf->len)
{
l2tp_log (LOG_WARNING, "%s: short write (%d of %d bytes)\n", __FUNCTION__,
err, buf->len);
return -EINVAL;
}
else if (err > buf->len)
else if ((size_t)err > buf->len)
{
l2tp_log (LOG_WARNING, "%s: write returned LONGER than buffer length?\n",
__FUNCTION__);
Expand All @@ -1678,7 +1679,7 @@ static inline int write_packet (struct buffer *buf, struct tunnel *t, struct cal
{
// we must at least still have 3 bytes left in the worst case scenario:
// 1 for a possible escape, 1 for the value and 1 to end the PPP stream.
if(pos >= (sizeof(wbuf) - 4)) {
if((size_t)pos >= (sizeof(wbuf) - 4)) {
if(DEBUG)
l2tp_log(LOG_CRIT, "%s: rx packet is too big after PPP encoding (size %u, max is %u)\n",
__FUNCTION__, buf->len, MAX_RECV_SIZE);
Expand All @@ -1704,7 +1705,7 @@ static inline int write_packet (struct buffer *buf, struct tunnel *t, struct cal
#endif

x = 0;
while ( pos != x )
while ((size_t) pos != x )
{
err = write (c->fd, wbuf+x, pos-x);
if ( err < 0 ) {
Expand Down
6 changes: 5 additions & 1 deletion file.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ int set_int (char *word, char *value, int *ptr)

int set_string (char *word, char *value, char *ptr, int len)
{
UNUSED(word);
#ifdef DEBUG_FILE
l2tp_log (LOG_DEBUG, "set_%s: %s flag to '%s'\n", word, word, value);
#endif /* ; */
Expand Down Expand Up @@ -930,7 +931,7 @@ struct iprange *set_range (char *word, char *value, struct iprange *in)
}
}
/* Copy the last field + null terminator */
if (ip_hi + sizeof(ip_hi)-e > strlen(d)) {
if ((size_t)(ip_hi + sizeof(ip_hi)-e) > strlen(d)) {
strcpy(e, d);
d = ip_hi;
}
Expand Down Expand Up @@ -1058,6 +1059,7 @@ int set_exclusive (char *word, char *value, int context, void *item)

int set_ip (char *word, char *value, unsigned int *addr)
{
UNUSED(word);
struct hostent *hp;
hp = gethostbyname (value);
if (!hp)
Expand Down Expand Up @@ -1244,13 +1246,15 @@ int set_rand_dev ()

int set_rand_egd (char *value)
{
UNUSED(value);
l2tp_log(LOG_WARNING, "%s: not yet implemented!\n", __FUNCTION__);
rand_source = RAND_EGD;
return -1;
}

int set_rand_source (char *word, char *value, int context, void *item)
{
UNUSED(item);
time_t seconds;
/*
* We're going to go ahead and seed the rand() function with srand()
Expand Down
1 change: 1 addition & 0 deletions l2tp.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ typedef unsigned long long _u64;

#define CONTROL_PIPE "/var/run/xl2tpd/l2tp-control"
#define CONTROL_PIPE_MESSAGE_SIZE 1024
#define UNUSED(x) (void)(x)

/* Control pip request types */
#define CONTROL_PIPE_REQ_LAC_REMOVE 'r'
Expand Down
6 changes: 5 additions & 1 deletion misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ static int syslog_nesting = 0;
--syslog_nesting; \
} while(0)

#define UNUSED(x) (void)(x)

void init_log()
{
static int logopen=0;
Expand Down Expand Up @@ -150,7 +152,7 @@ void bufferDump (unsigned char *buf, int buflen)

void do_packet_dump (struct buffer *buf)
{
int x;
size_t x;
unsigned char *c = buf->start;
printf ("packet dump: \nHEX: { ");
for (x = 0; x < buf->len; x++)
Expand Down Expand Up @@ -260,6 +262,8 @@ void opt_destroy (struct ppp_opts *option)

int get_egd_entropy(char *buf, int count)
{
UNUSED(buf);
UNUSED(count);
return -1;
}

Expand Down
4 changes: 2 additions & 2 deletions misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ struct buffer
void *rstart;
void *rend;
void *start;
int len;
int maxlen;
size_t len;
size_t maxlen;
#if 0
unsigned int addr;
int port;
Expand Down
1 change: 1 addition & 0 deletions network.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ static inline void fix_hdr (void *buf)

void dethrottle (void *call)
{
UNUSED(call);
/* struct call *c = (struct call *)call; */
/* if (c->throttle) {
#ifdef DEBUG_FLOW
Expand Down
30 changes: 21 additions & 9 deletions xl2tpd-control.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,22 @@ struct command_t commands[] = {
},

/* LAC commands */
{"add-lac", &command_add_lac, TUNNEL_REQUIRED},
{"connect-lac", &command_connect_lac, TUNNEL_REQUIRED},
{"disconnect-lac", &command_disconnect_lac, TUNNEL_REQUIRED},
{"remove-lac", &command_remove_lac, TUNNEL_REQUIRED},
{"add-lac", &command_add_lac, TUNNEL_REQUIRED, ""},
{"connect-lac", &command_connect_lac, TUNNEL_REQUIRED, ""},
{"disconnect-lac", &command_disconnect_lac, TUNNEL_REQUIRED, ""},
{"remove-lac", &command_remove_lac, TUNNEL_REQUIRED, ""},

/* LNS commands */
{"add-lns", &command_add_lns, TUNNEL_REQUIRED,
"\tadd-lns\tadds new or modify existing lns configuration.\n"
},
{"remove-lns", &command_remove_lns, TUNNEL_REQUIRED},
{"remove-lns", &command_remove_lns, TUNNEL_REQUIRED, ""},

/* Generic commands */
{"status", &command_status_lac, TUNNEL_REQUIRED},
{"status-lns", &command_status_lns, TUNNEL_REQUIRED},
{"available", &command_available, TUNNEL_NOT_REQUIRED},
{NULL, NULL}
{"status", &command_status_lac, TUNNEL_REQUIRED, ""},
{"status-lns", &command_status_lns, TUNNEL_REQUIRED, ""},
{"available", &command_available, TUNNEL_NOT_REQUIRED, ""},
{NULL, NULL, 0, NULL}
};

void usage()
Expand Down Expand Up @@ -463,41 +463,53 @@ int command_connect_lac
int command_disconnect_lac
(FILE* mesf, char* tunnel, int optc, char *optv[])
{
UNUSED(optc);
UNUSED(optv);
fprintf (mesf, "%c %s", CONTROL_PIPE_REQ_LAC_DISCONNECT, tunnel);
return 0;
}

int command_remove_lac
(FILE* mesf, char* tunnel, int optc, char *optv[])
{
UNUSED(optc);
UNUSED(optv);
fprintf (mesf, "%c %s", CONTROL_PIPE_REQ_LAC_REMOVE, tunnel);
return 0;
}

int command_status_lns
(FILE* mesf, char* tunnel, int optc, char *optv[])
{
UNUSED(optc);
UNUSED(optv);
fprintf (mesf, "%c %s", CONTROL_PIPE_REQ_LNS_STATUS, tunnel);
return 0;
}

int command_status_lac
(FILE* mesf, char* tunnel, int optc, char *optv[])
{
UNUSED(optc);
UNUSED(optv);
fprintf (mesf, "%c %s", CONTROL_PIPE_REQ_LAC_STATUS, tunnel);
return 0;
}

int command_available
(FILE* mesf, char* tunnel, int optc, char *optv[])
{
UNUSED(optc);
UNUSED(optv);
fprintf (mesf, "%c %s", CONTROL_PIPE_REQ_AVAILABLE, tunnel);
return 0;
}

int command_remove_lns
(FILE* mesf, char* tunnel, int optc, char *optv[])
{
UNUSED(optc);
UNUSED(optv);
fprintf (mesf, "%c %s", CONTROL_PIPE_REQ_LNS_REMOVE, tunnel);
return 0;
}
Expand Down
17 changes: 13 additions & 4 deletions xl2tpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ int control_handle_lac_hangup(FILE* resf, char* bufp);
int control_handle_lac_disconnect(FILE* resf, char* bufp);
int control_handle_lac_add_modify(FILE* resf, char* bufp);
int control_handle_lac_remove(FILE* resf, char* bufp);
int control_handle_lac_status(FILE* resf, char* bufp);
int control_handle_lac_status();
int control_handle_lns_remove(FILE* resf, char* bufp);

struct control_requests_handler control_handlers[] = {
Expand Down Expand Up @@ -210,6 +210,7 @@ void show_status (void)

void null_handler(int sig)
{
UNUSED(sig);
/* FIXME
* A sighup is received when a call is terminated, unknown origine ..
* I catch it and ll looks good, but ..
Expand All @@ -218,11 +219,13 @@ void null_handler(int sig)

void status_handler (int sig)
{
UNUSED(sig);
show_status ();
}

void child_handler (int signal)
void child_handler (int sig)
{
UNUSED(sig);
/*
* Oops, somebody we launched was killed.
* It's time to reap them and close that call.
Expand Down Expand Up @@ -340,26 +343,31 @@ void death_handler (int signal)

void sigterm_handler(int sig)
{
UNUSED(sig);
sigterm_received = 1;
}

void sigint_handler(int sig)
{
UNUSED(sig);
sigint_received = 1;
}

void sigchld_handler(int sig)
{
UNUSED(sig);
sigchld_received = 1;
}

void sigusr1_handler(int sig)
{
UNUSED(sig);
sigusr1_received = 1;
}

void sighup_handler(int sig)
{
UNUSED(sig);
sighup_received = 1;
}

Expand Down Expand Up @@ -1020,7 +1028,8 @@ struct lns* find_lns_by_name(char* name){
return NULL; /* ml: Ok we could not find anything*/
}

int control_handle_available(FILE* resf, char* bufp){
int control_handle_available(FILE* resf, char* bufp) {
UNUSED(bufp);
struct lac *lac;
struct lns *lns;

Expand Down Expand Up @@ -1529,7 +1538,7 @@ int control_handle_lac_remove(FILE* resf, char* bufp){
return 1;
}

int control_handle_lac_status(FILE* resf, char* bufp){
int control_handle_lac_status(){
show_status ();
return 1;
}
Expand Down

0 comments on commit bca2026

Please sign in to comment.