Skip to content

Commit

Permalink
Make functions and variables static whenever possible.
Browse files Browse the repository at this point in the history
style(9) says:
"Function prototypes for private functions (i.e., functions not used
elsewhere) go at the top of the first source module. In userland,
functions local to one source module should be declared 'static'".

The benefits of doing so include:
* clean up of the eigrpd global namespace;
* improved readability;
* more hints to the compiler/linker to generate more efficient code.

Additional changes:
* Declare all extern variables in header files;
* Clean up the indentation of all function prototypes and global
  variables.

ok claudio@ benno@
  • Loading branch information
rwestphal committed Sep 2, 2016
1 parent 0c82e3c commit b0ce0b5
Show file tree
Hide file tree
Showing 20 changed files with 440 additions and 458 deletions.
18 changes: 10 additions & 8 deletions control.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@

#define CONTROL_BACKLOG 5

struct ctl_conn *control_connbyfd(int);
struct ctl_conn *control_connbypid(pid_t);
void control_close(int);
static void control_accept(int, short, void *);
static struct ctl_conn *control_connbyfd(int);
static struct ctl_conn *control_connbypid(pid_t);
static void control_close(int);
static void control_dispatch_imsg(int, short, void *);

int
control_init(char *path)
Expand Down Expand Up @@ -109,7 +111,7 @@ control_cleanup(char *path)
}

/* ARGSUSED */
void
static void
control_accept(int listenfd, short event, void *bula)
{
int connfd;
Expand Down Expand Up @@ -155,7 +157,7 @@ control_accept(int listenfd, short event, void *bula)
TAILQ_INSERT_TAIL(&ctl_conns, c, entry);
}

struct ctl_conn *
static struct ctl_conn *
control_connbyfd(int fd)
{
struct ctl_conn *c;
Expand All @@ -167,7 +169,7 @@ control_connbyfd(int fd)
return (c);
}

struct ctl_conn *
static struct ctl_conn *
control_connbypid(pid_t pid)
{
struct ctl_conn *c;
Expand All @@ -179,7 +181,7 @@ control_connbypid(pid_t pid)
return (c);
}

void
static void
control_close(int fd)
{
struct ctl_conn *c;
Expand All @@ -205,7 +207,7 @@ control_close(int fd)
}

/* ARGSUSED */
void
static void
control_dispatch_imsg(int fd, short event, void *bula)
{
struct ctl_conn *c;
Expand Down
4 changes: 1 addition & 3 deletions control.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ struct ctl_conn {

int control_init(char *);
int control_listen(void);
void control_accept(int, short, void *);
void control_dispatch_imsg(int, short, void *);
int control_imsg_relay(struct imsg *);
void control_cleanup(char *);
int control_imsg_relay(struct imsg *);

#endif /* _CONTROL_H_ */
71 changes: 33 additions & 38 deletions eigrpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,30 +37,31 @@
#include "rde.h"
#include "log.h"

void main_sig_handler(int, short, void *);
__dead void usage(void);
__dead void eigrpd_shutdown(void);
pid_t start_child(enum eigrpd_process, char *, int, int, int, char *);

void main_dispatch_eigrpe(int, short, void *);
void main_dispatch_rde(int, short, void *);
int main_imsg_send_ipc_sockets(struct imsgbuf *, struct imsgbuf *);

int main_imsg_send_config(struct eigrpd_conf *);
int eigrp_reload(void);
int eigrp_sendboth(enum imsg_type, void *, uint16_t);
void merge_instances(struct eigrpd_conf *, struct eigrp *, struct eigrp *);

struct eigrpd_conf *eigrpd_conf = NULL;
struct imsgev *iev_eigrpe;
struct imsgev *iev_rde;
char *conffile;

pid_t eigrpe_pid = 0;
pid_t rde_pid = 0;
static void main_sig_handler(int, short, void *);
static __dead void usage(void);
static __dead void eigrpd_shutdown(void);
static pid_t start_child(enum eigrpd_process, char *, int, int, int,
char *);
static void main_dispatch_eigrpe(int, short, void *);
static void main_dispatch_rde(int, short, void *);
static int main_imsg_send_ipc_sockets(struct imsgbuf *,
struct imsgbuf *);
static int main_imsg_send_config(struct eigrpd_conf *);
static int eigrp_reload(void);
static int eigrp_sendboth(enum imsg_type, void *, uint16_t);
static void merge_instances(struct eigrpd_conf *, struct eigrp *,
struct eigrp *);

struct eigrpd_conf *eigrpd_conf;

static char *conffile;
static struct imsgev *iev_eigrpe;
static struct imsgev *iev_rde;
static pid_t eigrpe_pid;
static pid_t rde_pid;

/* ARGSUSED */
void
static void
main_sig_handler(int sig, short event, void *arg)
{
/* signal handler rules don't apply, libevent decouples for us */
Expand All @@ -81,7 +82,7 @@ main_sig_handler(int sig, short event, void *arg)
}
}

__dead void
static __dead void
usage(void)
{
extern char *__progname;
Expand Down Expand Up @@ -276,7 +277,7 @@ main(int argc, char *argv[])
return (0);
}

__dead void
static __dead void
eigrpd_shutdown(void)
{
pid_t pid;
Expand Down Expand Up @@ -310,7 +311,7 @@ eigrpd_shutdown(void)
exit(0);
}

pid_t
static pid_t
start_child(enum eigrpd_process p, char *argv0, int fd, int debug, int verbose,
char *sockname)
{
Expand Down Expand Up @@ -358,7 +359,7 @@ start_child(enum eigrpd_process p, char *argv0, int fd, int debug, int verbose,

/* imsg handling */
/* ARGSUSED */
void
static void
main_dispatch_eigrpe(int fd, short event, void *bula)
{
struct imsgev *iev = bula;
Expand Down Expand Up @@ -435,7 +436,7 @@ main_dispatch_eigrpe(int fd, short event, void *bula)
}

/* ARGSUSED */
void
static void
main_dispatch_rde(int fd, short event, void *bula)
{
struct imsgev *iev = bula;
Expand Down Expand Up @@ -538,7 +539,7 @@ imsg_compose_event(struct imsgev *iev, uint16_t type, uint32_t peerid,
return (ret);
}

int
static int
main_imsg_send_ipc_sockets(struct imsgbuf *eigrpe_buf, struct imsgbuf *rde_buf)
{
int pipe_eigrpe2rde[2];
Expand All @@ -557,12 +558,6 @@ main_imsg_send_ipc_sockets(struct imsgbuf *eigrpe_buf, struct imsgbuf *rde_buf)
return (0);
}

uint32_t
eigrp_router_id(struct eigrpd_conf *xconf)
{
return (xconf->rtr_id.s_addr);
}

struct eigrp *
eigrp_find(struct eigrpd_conf *xconf, int af, uint16_t as)
{
Expand All @@ -575,7 +570,7 @@ eigrp_find(struct eigrpd_conf *xconf, int af, uint16_t as)
return (NULL);
}

int
static int
main_imsg_send_config(struct eigrpd_conf *xconf)
{
struct eigrp *eigrp;
Expand Down Expand Up @@ -606,7 +601,7 @@ main_imsg_send_config(struct eigrpd_conf *xconf)
return (0);
}

int
static int
eigrp_reload(void)
{
struct eigrpd_conf *xconf;
Expand All @@ -622,7 +617,7 @@ eigrp_reload(void)
return (0);
}

int
static int
eigrp_sendboth(enum imsg_type type, void *buf, uint16_t len)
{
if (main_imsg_compose_eigrpe(type, 0, buf, len) == -1)
Expand Down Expand Up @@ -713,7 +708,7 @@ merge_config(struct eigrpd_conf *conf, struct eigrpd_conf *xconf)
free(xconf);
}

void
static void
merge_instances(struct eigrpd_conf *xconf, struct eigrp *eigrp, struct eigrp *xe)
{
/* TODO */
Expand Down
35 changes: 20 additions & 15 deletions eigrpd.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,17 @@ enum imsg_type {
IMSG_RECONF_END
};

/* forward declarations */
struct eigrp_iface;
RB_HEAD(iface_id_head, eigrp_iface);
struct nbr;
RB_HEAD(nbr_addr_head, nbr);
RB_HEAD(nbr_pid_head, nbr);
struct rde_nbr;
RB_HEAD(rde_nbr_head, rde_nbr);
struct rt_node;
RB_HEAD(rt_tree, rt_node);

union eigrpd_addr {
struct in_addr v4;
struct in6_addr v6;
Expand Down Expand Up @@ -215,6 +226,7 @@ struct eigrp_iface {
struct rinfo_head query_list; /* multicast queries */
TAILQ_HEAD(, summary_addr) summary_list;
};
RB_PROTOTYPE(iface_id_head, eigrp_iface, id_tree, iface_id_compare)

#define INADDRSZ 4
#define IN6ADDRSZ 16
Expand All @@ -226,12 +238,6 @@ struct seq_addr_entry {
};
TAILQ_HEAD(seq_addr_head, seq_addr_entry);

struct nbr;
RB_HEAD(nbr_addr_head, nbr);
RB_HEAD(nbr_pid_head, nbr);
struct rt_node;
RB_HEAD(rt_tree, rt_node);

#define REDIST_STATIC 0x01
#define REDIST_RIP 0x02
#define REDIST_OSPF 0x04
Expand Down Expand Up @@ -438,6 +444,9 @@ struct ctl_stats {
#define min(x,y) ((x) <= (y) ? (x) : (y))
#define max(x,y) ((x) > (y) ? (x) : (y))

extern struct eigrpd_conf *eigrpd_conf;
extern struct iface_id_head ifaces_by_id;

/* parse.y */
struct eigrpd_conf *parse_config(char *);
int cmdline_symset(char *);
Expand All @@ -447,20 +456,17 @@ uint16_t in_cksum(void *, size_t);

/* kroute.c */
int kif_init(void);
void kif_redistribute(void);
int kr_init(int, unsigned int);
void kif_redistribute(void);
int kr_change(struct kroute *);
int kr_delete(struct kroute *);
void kif_clear(void);
void kr_shutdown(void);
void kr_fib_couple(void);
void kr_fib_decouple(void);
void kr_fib_reload(void);
void kr_dispatch_msg(int, short, void *);
void kr_show_route(struct imsg *);
void kr_ifinfo(char *, pid_t);
struct kif *kif_findname(char *);
void kr_reload(void);
void kif_clear(void);

/* util.c */
uint8_t mask2prefixlen(in_addr_t);
Expand All @@ -486,14 +492,13 @@ void sa2addr(struct sockaddr *, int *, union eigrpd_addr *);
/* eigrpd.c */
int main_imsg_compose_eigrpe(int, pid_t, void *, uint16_t);
int main_imsg_compose_rde(int, pid_t, void *, uint16_t);
void merge_config(struct eigrpd_conf *, struct eigrpd_conf *);
struct eigrpd_conf *config_new_empty(void);
void config_clear(struct eigrpd_conf *);
void imsg_event_add(struct imsgev *);
int imsg_compose_event(struct imsgev *, uint16_t, uint32_t,
pid_t, int, void *, uint16_t);
uint32_t eigrp_router_id(struct eigrpd_conf *);
struct eigrp *eigrp_find(struct eigrpd_conf *, int, uint16_t);
void merge_config(struct eigrpd_conf *, struct eigrpd_conf *);
struct eigrpd_conf *config_new_empty(void);
void config_clear(struct eigrpd_conf *);

/* printconf.c */
void print_config(struct eigrpd_conf *);
Expand Down
27 changes: 12 additions & 15 deletions eigrpe.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,20 @@
#include "log.h"
#include "control.h"

void eigrpe_sig_handler(int, short, void *);
__dead void eigrpe_shutdown(void);
static void eigrpe_sig_handler(int, short, void *);
static __dead void eigrpe_shutdown(void);
static void eigrpe_dispatch_main(int, short, void *);
static void eigrpe_dispatch_rde(int, short, void *);

static struct event ev4;
static struct event ev6;
struct eigrpd_conf *econf;
struct imsgev *iev_main;
struct imsgev *iev_rde;

extern struct iface_id_head ifaces_by_id;
RB_PROTOTYPE(iface_id_head, eigrp_iface, id_tree, iface_id_compare)

extern struct nbr_addr_head nbrs_by_addr;
RB_PROTOTYPE(nbr_addr_head, nbr, addr_tree, nbr_compare)
static struct event ev4;
static struct event ev6;
static struct imsgev *iev_main;
static struct imsgev *iev_rde;

/* ARGSUSED */
void
static void
eigrpe_sig_handler(int sig, short event, void *bula)
{
switch (sig) {
Expand Down Expand Up @@ -180,7 +177,7 @@ eigrpe(int debug, int verbose, char *sockname)
return (0);
}

__dead void
static __dead void
eigrpe_shutdown(void)
{
/* close pipes */
Expand Down Expand Up @@ -224,7 +221,7 @@ eigrpe_imsg_compose_rde(int type, uint32_t peerid, pid_t pid,
}

/* ARGSUSED */
void
static void
eigrpe_dispatch_main(int fd, short event, void *bula)
{
static struct eigrpd_conf *nconf;
Expand Down Expand Up @@ -399,7 +396,7 @@ eigrpe_dispatch_main(int fd, short event, void *bula)
}

/* ARGSUSED */
void
static void
eigrpe_dispatch_rde(int fd, short event, void *bula)
{
struct imsgev *iev = bula;
Expand Down
Loading

0 comments on commit b0ce0b5

Please sign in to comment.