diff options
author | Renato Westphal <renato@cvs.openbsd.org> | 2016-09-02 16:44:34 +0000 |
---|---|---|
committer | Renato Westphal <renato@cvs.openbsd.org> | 2016-09-02 16:44:34 +0000 |
commit | fcf9752bb7cfa0955234368e43600610c4308242 (patch) | |
tree | f12e2cdd668aab5d8339150fa1af1dfada1dda77 /usr.sbin/eigrpd | |
parent | dcaa3316f517f3e75debd2dc1ae2838de28a7b02 (diff) |
Make functions and variables static whenever possible.
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@
Diffstat (limited to 'usr.sbin/eigrpd')
-rw-r--r-- | usr.sbin/eigrpd/control.c | 20 | ||||
-rw-r--r-- | usr.sbin/eigrpd/control.h | 6 | ||||
-rw-r--r-- | usr.sbin/eigrpd/eigrpd.c | 73 | ||||
-rw-r--r-- | usr.sbin/eigrpd/eigrpd.h | 37 | ||||
-rw-r--r-- | usr.sbin/eigrpd/eigrpe.c | 29 | ||||
-rw-r--r-- | usr.sbin/eigrpd/eigrpe.h | 33 | ||||
-rw-r--r-- | usr.sbin/eigrpd/interface.c | 53 | ||||
-rw-r--r-- | usr.sbin/eigrpd/kroute.c | 154 | ||||
-rw-r--r-- | usr.sbin/eigrpd/log.h | 39 | ||||
-rw-r--r-- | usr.sbin/eigrpd/neighbor.c | 23 | ||||
-rw-r--r-- | usr.sbin/eigrpd/packet.c | 19 | ||||
-rw-r--r-- | usr.sbin/eigrpd/parse.y | 133 | ||||
-rw-r--r-- | usr.sbin/eigrpd/printconf.c | 30 | ||||
-rw-r--r-- | usr.sbin/eigrpd/query.c | 4 | ||||
-rw-r--r-- | usr.sbin/eigrpd/rde.c | 44 | ||||
-rw-r--r-- | usr.sbin/eigrpd/rde.h | 71 | ||||
-rw-r--r-- | usr.sbin/eigrpd/rde_dual.c | 123 | ||||
-rw-r--r-- | usr.sbin/eigrpd/reply.c | 4 | ||||
-rw-r--r-- | usr.sbin/eigrpd/rtp.c | 37 | ||||
-rw-r--r-- | usr.sbin/eigrpd/update.c | 4 |
20 files changed, 459 insertions, 477 deletions
diff --git a/usr.sbin/eigrpd/control.c b/usr.sbin/eigrpd/control.c index 5b7d3e8ca66..8100e9f97b7 100644 --- a/usr.sbin/eigrpd/control.c +++ b/usr.sbin/eigrpd/control.c @@ -1,4 +1,4 @@ -/* $OpenBSD: control.c,v 1.5 2016/09/02 16:29:54 renato Exp $ */ +/* $OpenBSD: control.c,v 1.6 2016/09/02 16:44:33 renato Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -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) @@ -109,7 +111,7 @@ control_cleanup(char *path) } /* ARGSUSED */ -void +static void control_accept(int listenfd, short event, void *bula) { int connfd; @@ -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; @@ -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; @@ -179,7 +181,7 @@ control_connbypid(pid_t pid) return (c); } -void +static void control_close(int fd) { struct ctl_conn *c; @@ -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; diff --git a/usr.sbin/eigrpd/control.h b/usr.sbin/eigrpd/control.h index 83b4b84e2e7..298c2d9aa99 100644 --- a/usr.sbin/eigrpd/control.h +++ b/usr.sbin/eigrpd/control.h @@ -1,4 +1,4 @@ -/* $OpenBSD: control.h,v 1.2 2016/09/02 16:29:54 renato Exp $ */ +/* $OpenBSD: control.h,v 1.3 2016/09/02 16:44:33 renato Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -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_ */ diff --git a/usr.sbin/eigrpd/eigrpd.c b/usr.sbin/eigrpd/eigrpd.c index 6a2664ec419..56f9b766a4e 100644 --- a/usr.sbin/eigrpd/eigrpd.c +++ b/usr.sbin/eigrpd/eigrpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: eigrpd.c,v 1.19 2016/09/02 16:29:54 renato Exp $ */ +/* $OpenBSD: eigrpd.c,v 1.20 2016/09/02 16:44:33 renato Exp $ */ /* * Copyright (c) 2015 Renato Westphal <renato@openbsd.org> @@ -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 */ @@ -81,7 +82,7 @@ main_sig_handler(int sig, short event, void *arg) } } -__dead void +static __dead void usage(void) { extern char *__progname; @@ -276,7 +277,7 @@ main(int argc, char *argv[]) return (0); } -__dead void +static __dead void eigrpd_shutdown(void) { pid_t pid; @@ -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) { @@ -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; @@ -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; @@ -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]; @@ -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) { @@ -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; @@ -606,7 +601,7 @@ main_imsg_send_config(struct eigrpd_conf *xconf) return (0); } -int +static int eigrp_reload(void) { struct eigrpd_conf *xconf; @@ -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) @@ -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 */ diff --git a/usr.sbin/eigrpd/eigrpd.h b/usr.sbin/eigrpd/eigrpd.h index 0fce1b9dd81..4a7cad10740 100644 --- a/usr.sbin/eigrpd/eigrpd.h +++ b/usr.sbin/eigrpd/eigrpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: eigrpd.h,v 1.19 2016/09/02 16:36:33 renato Exp $ */ +/* $OpenBSD: eigrpd.h,v 1.20 2016/09/02 16:44:33 renato Exp $ */ /* * Copyright (c) 2015 Renato Westphal <renato@openbsd.org> @@ -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; @@ -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 @@ -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 @@ -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 *); @@ -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); @@ -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 *); diff --git a/usr.sbin/eigrpd/eigrpe.c b/usr.sbin/eigrpd/eigrpe.c index fba71a9d162..825064eac0d 100644 --- a/usr.sbin/eigrpd/eigrpe.c +++ b/usr.sbin/eigrpd/eigrpe.c @@ -1,4 +1,4 @@ -/* $OpenBSD: eigrpe.c,v 1.31 2016/09/02 16:39:44 renato Exp $ */ +/* $OpenBSD: eigrpe.c,v 1.32 2016/09/02 16:44:33 renato Exp $ */ /* * Copyright (c) 2015 Renato Westphal <renato@openbsd.org> @@ -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) { @@ -180,7 +177,7 @@ eigrpe(int debug, int verbose, char *sockname) return (0); } -__dead void +static __dead void eigrpe_shutdown(void) { /* close pipes */ @@ -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; @@ -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; diff --git a/usr.sbin/eigrpd/eigrpe.h b/usr.sbin/eigrpd/eigrpe.h index a912c5fb165..b1d8e6a6c59 100644 --- a/usr.sbin/eigrpd/eigrpe.h +++ b/usr.sbin/eigrpd/eigrpe.h @@ -1,4 +1,4 @@ -/* $OpenBSD: eigrpe.h,v 1.13 2016/09/02 16:36:33 renato Exp $ */ +/* $OpenBSD: eigrpe.h,v 1.14 2016/09/02 16:44:33 renato Exp $ */ /* * Copyright (c) 2015 Renato Westphal <renato@openbsd.org> @@ -52,6 +52,9 @@ struct nbr { time_t uptime; uint16_t hello_holdtime; uint8_t flags; +#define F_EIGRP_NBR_SELF 0x01 +#define F_EIGRP_NBR_PENDING 0x02 +#define F_EIGRP_NBR_CR_MODE 0x04 struct rinfo_head update_list; /* unicast updates */ struct rinfo_head query_list; /* unicast queries */ @@ -62,17 +65,16 @@ struct nbr { uint32_t next_mcast_seq; TAILQ_HEAD(, packet) retrans_list; }; -#define F_EIGRP_NBR_SELF 0x01 -#define F_EIGRP_NBR_PENDING 0x02 -#define F_EIGRP_NBR_CR_MODE 0x04 +RB_PROTOTYPE(nbr_addr_head, nbr, addr_tree, nbr_compare) +RB_PROTOTYPE(nbr_pid_head, nbr, pid_tree, nbr_pid_compare) #define PREFIX_SIZE4(x) (((x - 1) / 8) + 1) #define PREFIX_SIZE6(x) ((x == 128) ? 16 : ((x / 8) + 1)) +extern struct eigrpd_conf *econf; + /* eigrpe.c */ pid_t eigrpe(int, int, char *); -void eigrpe_dispatch_main(int, short, void *); -void eigrpe_dispatch_rde(int, short, void *); int eigrpe_imsg_compose_parent(int, pid_t, void *, uint16_t); int eigrpe_imsg_compose_rde(int, uint32_t, pid_t, void *, uint16_t); @@ -88,13 +90,10 @@ void eigrpe_nbr_ctl(struct ctl_conn *); void eigrpe_stats_ctl(struct ctl_conn *); /* interface.c */ -struct iface *if_new(struct eigrpd_conf *, struct kif *); -void if_del(struct iface *); struct iface *if_lookup(struct eigrpd_conf *, unsigned int); void if_init(struct eigrpd_conf *, struct iface *); void if_addr_new(struct iface *, struct kaddr *); void if_addr_del(struct iface *, struct kaddr *); -struct if_addr *if_addr_lookup(struct if_addr_head *, struct kaddr *); in_addr_t if_primary_addr(struct iface *); uint8_t if_primary_addr_prefixlen(struct iface *); void if_update(struct iface *, int); @@ -103,19 +102,13 @@ struct eigrp_iface *eigrp_if_new(struct eigrpd_conf *, struct eigrp *, void eigrp_if_del(struct eigrp_iface *); struct eigrp_iface *eigrp_if_lookup(struct iface *, int, uint16_t); struct eigrp_iface *eigrp_if_lookup_id(uint32_t); -void eigrp_if_start(struct eigrp_iface *); -void eigrp_if_reset(struct eigrp_iface *); struct ctl_iface *if_to_ctl(struct eigrp_iface *); void if_set_sockbuf(int); -int if_join_ipv4_group(struct iface *, struct in_addr *); -int if_leave_ipv4_group(struct iface *, struct in_addr *); int if_set_ipv4_mcast_ttl(int, uint8_t); int if_set_ipv4_mcast(struct iface *); int if_set_ipv4_mcast_loop(int); int if_set_ipv4_recvif(int, int); int if_set_ipv4_hdrincl(int); -int if_join_ipv6_group(struct iface *, struct in6_addr *); -int if_leave_ipv6_group(struct iface *, struct in6_addr *); int if_set_ipv6_mcast(struct iface *); int if_set_ipv6_mcast_loop(int); int if_set_ipv6_pktinfo(int, int); @@ -126,26 +119,16 @@ struct nbr *nbr_new(struct eigrp_iface *, union eigrpd_addr *, uint16_t, int); void nbr_init(struct nbr *); void nbr_del(struct nbr *); -void nbr_update_peerid(struct nbr *); struct nbr *nbr_find(struct eigrp_iface *, union eigrpd_addr *); struct nbr *nbr_find_peerid(uint32_t); struct ctl_nbr *nbr_to_ctl(struct nbr *); void nbr_clear_ctl(struct ctl_nbr *); -void nbr_timeout(int, short, void *); void nbr_start_timeout(struct nbr *); -void nbr_stop_timeout(struct nbr *); /* rtp.c */ -struct pbuf *rtp_buf_new(struct ibuf *); -struct pbuf *rtp_buf_hold(struct pbuf *); -void rtp_buf_release(struct pbuf *); -struct packet *rtp_packet_new(struct nbr *, uint32_t, struct pbuf *); void rtp_packet_del(struct packet *); void rtp_process_ack(struct nbr *, uint32_t); -void rtp_send_packet(struct packet *); -void rtp_enqueue_packet(struct packet *); void rtp_send_ucast(struct nbr *, struct ibuf *); -void rtp_send_mcast(struct eigrp_iface *, struct ibuf *); void rtp_send(struct eigrp_iface *, struct nbr *, struct ibuf *); void rtp_send_ack(struct nbr *); void rtp_ack_timer(int, short, void *); diff --git a/usr.sbin/eigrpd/interface.c b/usr.sbin/eigrpd/interface.c index e02107eefe5..73077233be2 100644 --- a/usr.sbin/eigrpd/interface.c +++ b/usr.sbin/eigrpd/interface.c @@ -1,4 +1,4 @@ -/* $OpenBSD: interface.c,v 1.22 2016/09/02 16:39:44 renato Exp $ */ +/* $OpenBSD: interface.c,v 1.23 2016/09/02 16:44:33 renato Exp $ */ /* * Copyright (c) 2015 Renato Westphal <renato@openbsd.org> @@ -32,11 +32,24 @@ #include "eigrpe.h" #include "log.h" -extern struct eigrpd_conf *econf; +static __inline int iface_id_compare(struct eigrp_iface *, + struct eigrp_iface *); +static struct iface *if_new(struct eigrpd_conf *, struct kif *); +static void if_del(struct iface *); +static struct if_addr *if_addr_lookup(struct if_addr_head *, struct kaddr *); +static void eigrp_if_start(struct eigrp_iface *); +static void eigrp_if_reset(struct eigrp_iface *); +static void eigrp_if_hello_timer(int, short, void *); +static void eigrp_if_start_hello_timer(struct eigrp_iface *); +static void eigrp_if_stop_hello_timer(struct eigrp_iface *); +static int if_join_ipv4_group(struct iface *, struct in_addr *); +static int if_leave_ipv4_group(struct iface *, struct in_addr *); +static int if_join_ipv6_group(struct iface *, struct in6_addr *); +static int if_leave_ipv6_group(struct iface *, struct in6_addr *); -void eigrp_if_hello_timer(int, short, void *); -void eigrp_if_start_hello_timer(struct eigrp_iface *); -void eigrp_if_stop_hello_timer(struct eigrp_iface *); +RB_GENERATE(iface_id_head, eigrp_iface, id_tree, iface_id_compare) + +struct iface_id_head ifaces_by_id = RB_INITIALIZER(&ifaces_by_id); static __inline int iface_id_compare(struct eigrp_iface *a, struct eigrp_iface *b) @@ -44,13 +57,7 @@ iface_id_compare(struct eigrp_iface *a, struct eigrp_iface *b) return (a->ifaceid - b->ifaceid); } -RB_HEAD(iface_id_head, eigrp_iface); -RB_PROTOTYPE(iface_id_head, eigrp_iface, id_tree, iface_id_compare) -RB_GENERATE(iface_id_head, eigrp_iface, id_tree, iface_id_compare) - -struct iface_id_head ifaces_by_id = RB_INITIALIZER(&ifaces_by_id); - -struct iface * +static struct iface * if_new(struct eigrpd_conf *xconf, struct kif *kif) { struct iface *iface; @@ -85,7 +92,7 @@ if_new(struct eigrpd_conf *xconf, struct kif *kif) return (iface); } -void +static void if_del(struct iface *iface) { struct if_addr *if_addr; @@ -193,7 +200,7 @@ if_addr_del(struct iface *iface, struct kaddr *ka) if_update(iface, AF_INET); } -struct if_addr * +static struct if_addr * if_addr_lookup(struct if_addr_head *addr_list, struct kaddr *ka) { struct if_addr *if_addr; @@ -368,7 +375,7 @@ eigrp_if_lookup_id(uint32_t ifaceid) return (RB_FIND(iface_id_head, &ifaces_by_id, &e)); } -void +static void eigrp_if_start(struct eigrp_iface *ei) { struct eigrp *eigrp = ei->eigrp; @@ -414,7 +421,7 @@ eigrp_if_start(struct eigrp_iface *ei) eigrp_if_start_hello_timer(ei); } -void +static void eigrp_if_reset(struct eigrp_iface *ei) { struct eigrp *eigrp = ei->eigrp; @@ -448,7 +455,7 @@ eigrp_if_reset(struct eigrp_iface *ei) /* timers */ /* ARGSUSED */ -void +static void eigrp_if_hello_timer(int fd, short event, void *arg) { struct eigrp_iface *ei = arg; @@ -463,7 +470,7 @@ eigrp_if_hello_timer(int fd, short event, void *arg) fatal("eigrp_if_hello_timer"); } -void +static void eigrp_if_start_hello_timer(struct eigrp_iface *ei) { struct timeval tv; @@ -474,7 +481,7 @@ eigrp_if_start_hello_timer(struct eigrp_iface *ei) fatal("eigrp_if_start_hello_timer"); } -void +static void eigrp_if_stop_hello_timer(struct eigrp_iface *ei) { if (evtimer_pending(&ei->hello_timer, NULL) && @@ -558,7 +565,7 @@ if_set_sockbuf(int fd) log_warnx("%s: sendbuf size only %d", __func__, bsize); } -int +static int if_join_ipv4_group(struct iface *iface, struct in_addr *addr) { struct ip_mreq mreq; @@ -583,7 +590,7 @@ if_join_ipv4_group(struct iface *iface, struct in_addr *addr) return (0); } -int +static int if_leave_ipv4_group(struct iface *iface, struct in_addr *addr) { struct ip_mreq mreq; @@ -676,7 +683,7 @@ if_set_ipv4_hdrincl(int fd) return (0); } -int +static int if_join_ipv6_group(struct iface *iface, struct in6_addr *addr) { struct ipv6_mreq mreq; @@ -701,7 +708,7 @@ if_join_ipv6_group(struct iface *iface, struct in6_addr *addr) return (0); } -int +static int if_leave_ipv6_group(struct iface *iface, struct in6_addr *addr) { struct ipv6_mreq mreq; diff --git a/usr.sbin/eigrpd/kroute.c b/usr.sbin/eigrpd/kroute.c index a41daeb5032..d7602f37909 100644 --- a/usr.sbin/eigrpd/kroute.c +++ b/usr.sbin/eigrpd/kroute.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kroute.c,v 1.15 2016/09/02 16:29:55 renato Exp $ */ +/* $OpenBSD: kroute.c,v 1.16 2016/09/02 16:44:33 renato Exp $ */ /* * Copyright (c) 2015 Renato Westphal <renato@openbsd.org> @@ -35,9 +35,7 @@ #include "eigrpd.h" #include "log.h" -extern struct eigrpd_conf *eigrpd_conf; - -struct { +static struct { uint32_t rtseq; pid_t pid; int fib_sync; @@ -66,6 +64,8 @@ struct kroute_prefix { uint8_t prefixlen; TAILQ_HEAD(plist, kroute_priority) priorities; }; +RB_HEAD(kroute_tree, kroute_prefix); +RB_PROTOTYPE(kroute_tree, kroute_prefix, entry, kroute_compare) struct kif_addr { TAILQ_ENTRY(kif_addr) entry; @@ -77,55 +77,57 @@ struct kif_node { TAILQ_HEAD(, kif_addr) addrs; struct kif k; }; +RB_HEAD(kif_tree, kif_node); +RB_PROTOTYPE(kif_tree, kif_node, entry, kif_compare) -void kr_redist_remove(struct kroute *); -int kr_redist_eval(struct kroute *); -void kr_redistribute(struct kroute_prefix *); -int kroute_compare(struct kroute_prefix *, +static void kr_dispatch_msg(int, short, void *); +static void kr_redist_remove(struct kroute *); +static int kr_redist_eval(struct kroute *); +static void kr_redistribute(struct kroute_prefix *); +static __inline int kroute_compare(struct kroute_prefix *, struct kroute_prefix *); -struct kroute_prefix *kroute_find_prefix(int, union eigrpd_addr *, uint8_t); -struct kroute_priority *kroute_find_prio(struct kroute_prefix *, uint8_t); -struct kroute_node *kroute_find_gw(struct kroute_priority *, +static struct kroute_prefix *kroute_find_prefix(int, union eigrpd_addr *, + uint8_t); +static struct kroute_priority *kroute_find_prio(struct kroute_prefix *, + uint8_t); +static struct kroute_node *kroute_find_gw(struct kroute_priority *, union eigrpd_addr *); -struct kroute_node *kroute_insert(struct kroute *); -int kroute_remove(struct kroute *); -void kroute_clear(void); - -int kif_compare(struct kif_node *, struct kif_node *); -struct kif_node *kif_find(unsigned short); -struct kif_node *kif_insert(unsigned short); -int kif_remove(struct kif_node *); -struct kif *kif_update(unsigned short, int, struct if_data *, +static struct kroute_node *kroute_insert(struct kroute *); +static int kroute_remove(struct kroute *); +static void kroute_clear(void); +static __inline int kif_compare(struct kif_node *, struct kif_node *); +static struct kif_node *kif_find(unsigned short); +static struct kif_node *kif_insert(unsigned short); +static int kif_remove(struct kif_node *); +static struct kif *kif_update(unsigned short, int, struct if_data *, struct sockaddr_dl *); -int kif_validate(unsigned short); - -void protect_lo(void); -uint8_t prefixlen_classful(in_addr_t); -void get_rtaddrs(int, struct sockaddr *, struct sockaddr **); -void if_change(unsigned short, int, struct if_data *, - struct sockaddr_dl *); -void if_newaddr(unsigned short, struct sockaddr *, struct sockaddr *, - struct sockaddr *); -void if_deladdr(unsigned short, struct sockaddr *, struct sockaddr *, - struct sockaddr *); -void if_announce(void *); - -int send_rtmsg(int, int, struct kroute *); -int dispatch_rtmsg(void); -int fetchtable(void); -int fetchifs(void); -int rtmsg_process(char *, size_t); -int rtmsg_process_route(struct rt_msghdr *, - struct sockaddr *[RTAX_MAX]); - -RB_HEAD(kroute_tree, kroute_prefix) krt = RB_INITIALIZER(&krt); -RB_PROTOTYPE(kroute_tree, kroute_prefix, entry, kroute_compare) -RB_GENERATE(kroute_tree, kroute_prefix, entry, kroute_compare) +static int kif_validate(unsigned short); +static void protect_lo(void); +static uint8_t prefixlen_classful(in_addr_t); +static void get_rtaddrs(int, struct sockaddr *, struct sockaddr **); +static void if_change(unsigned short, int, struct if_data *, + struct sockaddr_dl *); +static void if_newaddr(unsigned short, struct sockaddr *, + struct sockaddr *, struct sockaddr *); +static void if_deladdr(unsigned short, struct sockaddr *, + struct sockaddr *, struct sockaddr *); +static void if_announce(void *); +static int send_rtmsg_v4(int, int, struct kroute *); +static int send_rtmsg_v6(int, int, struct kroute *); +static int send_rtmsg(int, int, struct kroute *); +static int fetchtable(void); +static int fetchifs(void); +static int dispatch_rtmsg(void); +static int rtmsg_process(char *, size_t); +static int rtmsg_process_route(struct rt_msghdr *, + struct sockaddr *[RTAX_MAX]); -RB_HEAD(kif_tree, kif_node) kit = RB_INITIALIZER(&kit); -RB_PROTOTYPE(kif_tree, kif_node, entry, kif_compare) +RB_GENERATE(kroute_tree, kroute_prefix, entry, kroute_compare) RB_GENERATE(kif_tree, kif_node, entry, kif_compare) +static struct kroute_tree krt = RB_INITIALIZER(&krt); +static struct kif_tree kit = RB_INITIALIZER(&kit); + int kif_init(void) { @@ -317,7 +319,7 @@ kr_fib_decouple(void) } /* ARGSUSED */ -void +static void kr_dispatch_msg(int fd, short event, void *bula) { if (dispatch_rtmsg() == -1) @@ -369,7 +371,7 @@ kr_ifinfo(char *ifname, pid_t pid) main_imsg_compose_eigrpe(IMSG_CTL_END, pid, NULL, 0); } -void +static void kr_redist_remove(struct kroute *kr) { /* was the route redistributed? */ @@ -381,7 +383,7 @@ kr_redist_remove(struct kroute *kr) main_imsg_compose_rde(IMSG_NETWORK_DEL, 0, kr, sizeof(*kr)); } -int +static int kr_redist_eval(struct kroute *kr) { /* Only non-eigrpd routes are considered for redistribution. */ @@ -431,7 +433,7 @@ dont_redistribute: return (0); } -void +static void kr_redistribute(struct kroute_prefix *kp) { struct kroute_priority *kprio; @@ -451,7 +453,7 @@ kr_redistribute(struct kroute_prefix *kp) } } -int +static __inline int kroute_compare(struct kroute_prefix *a, struct kroute_prefix *b) { int addrcmp; @@ -474,7 +476,7 @@ kroute_compare(struct kroute_prefix *a, struct kroute_prefix *b) } /* tree management */ -struct kroute_prefix * +static struct kroute_prefix * kroute_find_prefix(int af, union eigrpd_addr *prefix, uint8_t prefixlen) { struct kroute_prefix s; @@ -486,7 +488,7 @@ kroute_find_prefix(int af, union eigrpd_addr *prefix, uint8_t prefixlen) return (RB_FIND(kroute_tree, &krt, &s)); } -struct kroute_priority * +static struct kroute_priority * kroute_find_prio(struct kroute_prefix *kp, uint8_t prio) { struct kroute_priority *kprio; @@ -502,7 +504,7 @@ kroute_find_prio(struct kroute_prefix *kp, uint8_t prio) return (NULL); } -struct kroute_node * +static struct kroute_node * kroute_find_gw(struct kroute_priority *kprio, union eigrpd_addr *nh) { struct kroute_node *kn; @@ -514,7 +516,7 @@ kroute_find_gw(struct kroute_priority *kprio, union eigrpd_addr *nh) return (NULL); } -struct kroute_node * +static struct kroute_node * kroute_insert(struct kroute *kr) { struct kroute_prefix *kp; @@ -577,7 +579,7 @@ kroute_insert(struct kroute *kr) return (kn); } -int +static int kroute_remove(struct kroute *kr) { struct kroute_prefix *kp; @@ -622,7 +624,7 @@ notfound: return (-1); } -void +static void kroute_clear(void) { struct kroute_prefix *kp; @@ -643,14 +645,14 @@ kroute_clear(void) } } -int +static __inline int kif_compare(struct kif_node *a, struct kif_node *b) { return (b->k.ifindex - a->k.ifindex); } /* tree management */ -struct kif_node * +static struct kif_node * kif_find(unsigned short ifindex) { struct kif_node s; @@ -673,7 +675,7 @@ kif_findname(char *ifname) return (NULL); } -struct kif_node * +static struct kif_node * kif_insert(unsigned short ifindex) { struct kif_node *kif; @@ -690,7 +692,7 @@ kif_insert(unsigned short ifindex) return (kif); } -int +static int kif_remove(struct kif_node *kif) { struct kif_addr *ka; @@ -717,7 +719,7 @@ kif_clear(void) kif_remove(kif); } -struct kif * +static struct kif * kif_update(unsigned short ifindex, int flags, struct if_data *ifd, struct sockaddr_dl *sdl) { @@ -749,7 +751,7 @@ kif_update(unsigned short ifindex, int flags, struct if_data *ifd, return (&kif->k); } -int +static int kif_validate(unsigned short ifindex) { struct kif_node *kif; @@ -761,7 +763,7 @@ kif_validate(unsigned short ifindex) } /* misc */ -void +static void protect_lo(void) { struct kroute kr4, kr6; @@ -784,7 +786,7 @@ protect_lo(void) } /* misc */ -uint8_t +static uint8_t prefixlen_classful(in_addr_t ina) { /* it hurt to write this. */ @@ -804,7 +806,7 @@ prefixlen_classful(in_addr_t ina) #define ROUNDUP(a) \ (((a) & (sizeof(long) - 1)) ? (1 + ((a) | (sizeof(long) - 1))) : (a)) -void +static void get_rtaddrs(int addrs, struct sockaddr *sa, struct sockaddr **rti_info) { int i; @@ -819,7 +821,7 @@ get_rtaddrs(int addrs, struct sockaddr *sa, struct sockaddr **rti_info) } } -void +static void if_change(unsigned short ifindex, int flags, struct if_data *ifd, struct sockaddr_dl *sdl) { @@ -866,7 +868,7 @@ if_change(unsigned short ifindex, int flags, struct if_data *ifd, } } -void +static void if_newaddr(unsigned short ifindex, struct sockaddr *ifa, struct sockaddr *mask, struct sockaddr *brd) { @@ -933,7 +935,7 @@ if_newaddr(unsigned short ifindex, struct sockaddr *ifa, struct sockaddr *mask, main_imsg_compose_eigrpe(IMSG_NEWADDR, 0, &ka->a, sizeof(ka->a)); } -void +static void if_deladdr(unsigned short ifindex, struct sockaddr *ifa, struct sockaddr *mask, struct sockaddr *brd) { @@ -1008,7 +1010,7 @@ if_deladdr(unsigned short ifindex, struct sockaddr *ifa, struct sockaddr *mask, } } -void +static void if_announce(void *msg) { struct if_announcemsghdr *ifan; @@ -1212,7 +1214,7 @@ retry: return (0); } -int +static int send_rtmsg(int fd, int action, struct kroute *kr) { switch (kr->af) { @@ -1227,7 +1229,7 @@ send_rtmsg(int fd, int action, struct kroute *kr) return (-1); } -int +static int fetchtable(void) { size_t len; @@ -1263,7 +1265,7 @@ fetchtable(void) return (rv); } -int +static int fetchifs(void) { size_t len; @@ -1298,7 +1300,7 @@ fetchifs(void) return (rv); } -int +static int dispatch_rtmsg(void) { char buf[RT_BUF_SIZE]; @@ -1319,7 +1321,7 @@ dispatch_rtmsg(void) return (rtmsg_process(buf, n)); } -int +static int rtmsg_process(char *buf, size_t len) { struct rt_msghdr *rtm; @@ -1404,7 +1406,7 @@ rtmsg_process(char *buf, size_t len) return (offset); } -int +static int rtmsg_process_route(struct rt_msghdr *rtm, struct sockaddr *rti_info[RTAX_MAX]) { struct sockaddr *sa; diff --git a/usr.sbin/eigrpd/log.h b/usr.sbin/eigrpd/log.h index cfd1eac4a19..557a4d47ee4 100644 --- a/usr.sbin/eigrpd/log.h +++ b/usr.sbin/eigrpd/log.h @@ -1,4 +1,4 @@ -/* $OpenBSD: log.h,v 1.3 2016/07/18 21:14:30 benno Exp $ */ +/* $OpenBSD: log.h,v 1.4 2016/09/02 16:44:33 renato Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -21,25 +21,24 @@ #include <stdarg.h> -void log_init(int); -void log_verbose(int); -void logit(int, const char *, ...) - __attribute__((__format__ (printf, 2, 3))); -void vlog(int, const char *, va_list) - __attribute__((__format__ (printf, 2, 0))); -void log_warn(const char *, ...) - __attribute__((__format__ (printf, 1, 2))); -void log_warnx(const char *, ...) - __attribute__((__format__ (printf, 1, 2))); -void log_info(const char *, ...) - __attribute__((__format__ (printf, 1, 2))); -void log_debug(const char *, ...) - __attribute__((__format__ (printf, 1, 2))); -void fatal(const char *) __dead - __attribute__((__format__ (printf, 1, 0))); -void fatalx(const char *) __dead - __attribute__((__format__ (printf, 1, 0))); - +void log_init(int); +void log_verbose(int); +void logit(int, const char *, ...) + __attribute__((__format__ (printf, 2, 3))); +void vlog(int, const char *, va_list) + __attribute__((__format__ (printf, 2, 0))); +void log_warn(const char *, ...) + __attribute__((__format__ (printf, 1, 2))); +void log_warnx(const char *, ...) + __attribute__((__format__ (printf, 1, 2))); +void log_info(const char *, ...) + __attribute__((__format__ (printf, 1, 2))); +void log_debug(const char *, ...) + __attribute__((__format__ (printf, 1, 2))); +void fatal(const char *) __dead + __attribute__((__format__ (printf, 1, 0))); +void fatalx(const char *) __dead + __attribute__((__format__ (printf, 1, 0))); const char *log_in6addr(const struct in6_addr *); const char *log_in6addr_scope(const struct in6_addr *, unsigned int); const char *log_sockaddr(void *); diff --git a/usr.sbin/eigrpd/neighbor.c b/usr.sbin/eigrpd/neighbor.c index d8b5a2375db..2519273d2f3 100644 --- a/usr.sbin/eigrpd/neighbor.c +++ b/usr.sbin/eigrpd/neighbor.c @@ -1,4 +1,4 @@ -/* $OpenBSD: neighbor.c,v 1.9 2016/09/02 16:39:44 renato Exp $ */ +/* $OpenBSD: neighbor.c,v 1.10 2016/09/02 16:44:33 renato Exp $ */ /* * Copyright (c) 2015 Renato Westphal <renato@openbsd.org> @@ -26,14 +26,17 @@ #include "rde.h" #include "log.h" -static __inline int nbr_compare(struct nbr *, struct nbr *); -static __inline int nbr_pid_compare(struct nbr *, struct nbr *); +static __inline int nbr_compare(struct nbr *, struct nbr *); +static __inline int nbr_pid_compare(struct nbr *, struct nbr *); +static void nbr_update_peerid(struct nbr *); +static void nbr_timeout(int, short, void *); +static void nbr_stop_timeout(struct nbr *); -RB_PROTOTYPE(nbr_addr_head, nbr, addr_tree, nbr_compare) RB_GENERATE(nbr_addr_head, nbr, addr_tree, nbr_compare) -RB_PROTOTYPE(nbr_pid_head, nbr, pid_tree, nbr_pid_compare) RB_GENERATE(nbr_pid_head, nbr, pid_tree, nbr_pid_compare) +struct nbr_pid_head nbrs_by_pid = RB_INITIALIZER(&nbrs_by_pid); + static __inline int nbr_compare(struct nbr *a, struct nbr *b) { @@ -51,10 +54,6 @@ nbr_pid_compare(struct nbr *a, struct nbr *b) return (a->peerid - b->peerid); } -struct nbr_pid_head nbrs_by_pid = RB_INITIALIZER(&nbrs_by_pid); - -extern struct eigrpd_conf *econf; - struct nbr * nbr_new(struct eigrp_iface *ei, union eigrpd_addr *addr, uint16_t holdtime, int self) @@ -145,7 +144,7 @@ nbr_del(struct nbr *nbr) free(nbr); } -void +static void nbr_update_peerid(struct nbr *nbr) { static uint32_t peercnt = NBR_CNTSTART; @@ -234,7 +233,7 @@ nbr_clear_ctl(struct ctl_nbr *nctl) /* timers */ /* ARGSUSED */ -void +static void nbr_timeout(int fd, short event, void *arg) { struct nbr *nbr = arg; @@ -257,7 +256,7 @@ nbr_start_timeout(struct nbr *nbr) fatal("nbr_start_timeout"); } -void +static void nbr_stop_timeout(struct nbr *nbr) { if (evtimer_pending(&nbr->ev_hello_timeout, NULL) && diff --git a/usr.sbin/eigrpd/packet.c b/usr.sbin/eigrpd/packet.c index bae07831c62..519dba6e22a 100644 --- a/usr.sbin/eigrpd/packet.c +++ b/usr.sbin/eigrpd/packet.c @@ -1,4 +1,4 @@ -/* $OpenBSD: packet.c,v 1.17 2016/09/02 16:36:33 renato Exp $ */ +/* $OpenBSD: packet.c,v 1.18 2016/09/02 16:44:33 renato Exp $ */ /* * Copyright (c) 2015 Renato Westphal <renato@openbsd.org> @@ -32,11 +32,16 @@ #include "eigrpe.h" #include "log.h" -extern struct eigrpd_conf *econf; - -int eigrp_hdr_sanity_check(int, union eigrpd_addr *, +static int send_packet_v4(struct iface *, struct nbr *, struct ibuf *); +static int send_packet_v6(struct iface *, struct nbr *, struct ibuf *); +static int recv_packet_nbr(struct nbr *, struct eigrp_hdr *, + struct seq_addr_head *, struct tlv_mcast_seq *); +static void recv_packet_eigrp(int, union eigrpd_addr *, + union eigrpd_addr *, struct iface *, struct eigrp_hdr *, + char *, uint16_t); +static int eigrp_hdr_sanity_check(int, union eigrpd_addr *, struct eigrp_hdr *, uint16_t, const struct iface *); -struct iface *find_iface(unsigned int, int, union eigrpd_addr *); +static struct iface *find_iface(unsigned int, int, union eigrpd_addr *); int gen_eigrp_hdr(struct ibuf *buf, uint16_t opcode, uint8_t flags, @@ -600,7 +605,7 @@ recv_packet(int fd, short event, void *bula) recv_packet_eigrp(af, &src, &dest, iface, eigrp_hdr, buf, len); } -int +static int eigrp_hdr_sanity_check(int af, union eigrpd_addr *addr, struct eigrp_hdr *eigrp_hdr, uint16_t len, const struct iface *iface) { @@ -647,7 +652,7 @@ eigrp_hdr_sanity_check(int af, union eigrpd_addr *addr, return (0); } -struct iface * +static struct iface * find_iface(unsigned int ifindex, int af, union eigrpd_addr *src) { struct iface *iface; diff --git a/usr.sbin/eigrpd/parse.y b/usr.sbin/eigrpd/parse.y index a821a04be3d..04309e4405f 100644 --- a/usr.sbin/eigrpd/parse.y +++ b/usr.sbin/eigrpd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.18 2016/09/02 16:39:44 renato Exp $ */ +/* $OpenBSD: parse.y,v 1.19 2016/09/02 16:44:33 renato Exp $ */ /* * Copyright (c) 2015 Renato Westphal <renato@openbsd.org> @@ -41,29 +41,15 @@ #include "eigrpe.h" #include "log.h" -TAILQ_HEAD(files, file) files = TAILQ_HEAD_INITIALIZER(files); -static struct file { +struct file { TAILQ_ENTRY(file) entry; FILE *stream; char *name; int lineno; int errors; -} *file, *topfile; -struct file *pushfile(const char *, int); -int popfile(void); -int check_file_secrecy(int, const char *); -int yyparse(void); -int yylex(void); -int yyerror(const char *, ...) - __attribute__((__format__ (printf, 1, 2))) - __attribute__((__nonnull__ (1))); -int kw_cmp(const void *, const void *); -int lookup(char *); -int lgetc(int); -int lungetc(int); -int findeol(void); +}; +TAILQ_HEAD(files, file); -TAILQ_HEAD(symhead, sym) symhead = TAILQ_HEAD_INITIALIZER(symhead); struct sym { TAILQ_ENTRY(sym) entry; int used; @@ -71,19 +57,7 @@ struct sym { char *nam; char *val; }; -int symset(const char *, const char *, int); -char *symget(const char *); - -void clear_config(struct eigrpd_conf *xconf); -uint32_t get_rtr_id(void); -int get_prefix(const char *, union eigrpd_addr *, uint8_t *); - -static struct eigrpd_conf *conf; -static int errors; - -int af; -struct eigrp *eigrp; -struct eigrp_iface *ei; +TAILQ_HEAD(symhead, sym); struct config_defaults { uint8_t kvalues[6]; @@ -99,15 +73,6 @@ struct config_defaults { uint8_t splithorizon; }; -struct config_defaults globaldefs; -struct config_defaults afdefs; -struct config_defaults asdefs; -struct config_defaults ifacedefs; -struct config_defaults *defs; - -struct eigrp *conf_get_instance(uint16_t); -struct eigrp_iface *conf_get_if(struct kif *); - typedef struct { union { int64_t number; @@ -118,6 +83,50 @@ typedef struct { int lineno; } YYSTYPE; +#define MAXPUSHBACK 128 + +static int yyerror(const char *, ...) + __attribute__((__format__ (printf, 1, 2))) + __attribute__((__nonnull__ (1))); +static int kw_cmp(const void *, const void *); +static int lookup(char *); +static int lgetc(int); +static int lungetc(int); +static int findeol(void); +static int yylex(void); +static int check_file_secrecy(int, const char *); +static struct file *pushfile(const char *, int); +static int popfile(void); +static int yyparse(void); +static int symset(const char *, const char *, int); +static char *symget(const char *); +static struct eigrp *conf_get_instance(uint16_t); +static struct eigrp_iface *conf_get_if(struct kif *); +static void clear_config(struct eigrpd_conf *xconf); +static uint32_t get_rtr_id(void); +static int get_prefix(const char *, union eigrpd_addr *, uint8_t *); + +static struct file *file, *topfile; +static struct files files = TAILQ_HEAD_INITIALIZER(files); +static struct symhead symhead = TAILQ_HEAD_INITIALIZER(symhead); +static struct eigrpd_conf *conf; +static int errors; + +static int af; +static struct eigrp *eigrp; +static struct eigrp_iface *ei; + +static struct config_defaults globaldefs; +static struct config_defaults afdefs; +static struct config_defaults asdefs; +static struct config_defaults ifacedefs; +static struct config_defaults *defs; + +static unsigned char *parsebuf; +static int parseindex; +static unsigned char pushback_buffer[MAXPUSHBACK]; +static int pushback_index; + %} %token ROUTERID AS FIBUPDATE RDOMAIN REDISTRIBUTE METRIC DFLTMETRIC @@ -573,7 +582,7 @@ struct keywords { int k_val; }; -int +static int yyerror(const char *fmt, ...) { va_list ap; @@ -589,13 +598,13 @@ yyerror(const char *fmt, ...) return (0); } -int +static int kw_cmp(const void *k, const void *e) { return (strcmp(k, ((const struct keywords *)e)->k_name)); } -int +static int lookup(char *s) { /* this has to be sorted always */ @@ -641,14 +650,7 @@ lookup(char *s) return (STRING); } -#define MAXPUSHBACK 128 - -unsigned char *parsebuf; -int parseindex; -unsigned char pushback_buffer[MAXPUSHBACK]; -int pushback_index = 0; - -int +static int lgetc(int quotec) { int c, next; @@ -696,7 +698,7 @@ lgetc(int quotec) return (c); } -int +static int lungetc(int c) { if (c == EOF) @@ -712,7 +714,7 @@ lungetc(int c) return (EOF); } -int +static int findeol(void) { int c; @@ -735,7 +737,7 @@ findeol(void) return (ERROR); } -int +static int yylex(void) { unsigned char buf[8096]; @@ -884,7 +886,7 @@ nodigits: return (c); } -int +static int check_file_secrecy(int fd, const char *fname) { struct stat st; @@ -904,7 +906,7 @@ check_file_secrecy(int fd, const char *fname) return (0); } -struct file * +static struct file * pushfile(const char *name, int secret) { struct file *nfile; @@ -935,7 +937,7 @@ pushfile(const char *name, int secret) return (nfile); } -int +static int popfile(void) { struct file *prev; @@ -1010,7 +1012,7 @@ parse_config(char *filename) return (conf); } -int +static int symset(const char *nam, const char *val, int persist) { struct sym *sym; @@ -1071,7 +1073,7 @@ cmdline_symset(char *s) return (ret); } -char * +static char * symget(const char *nam) { struct sym *sym; @@ -1084,7 +1086,7 @@ symget(const char *nam) return (NULL); } -struct eigrp * +static struct eigrp * conf_get_instance(uint16_t as) { struct eigrp *e, *tmp; @@ -1122,7 +1124,7 @@ conf_get_instance(uint16_t as) return (e); } -struct eigrp_iface * +static struct eigrp_iface * conf_get_if(struct kif *kif) { struct eigrp_iface *e; @@ -1141,10 +1143,7 @@ conf_get_if(struct kif *kif) return (e); } -extern struct iface_id_head ifaces_by_id; -RB_PROTOTYPE(iface_id_head, eigrp_iface, id_tree, iface_id_compare) - -void +static void clear_config(struct eigrpd_conf *xconf) { struct eigrp *e; @@ -1181,7 +1180,7 @@ clear_config(struct eigrpd_conf *xconf) free(xconf); } -uint32_t +static uint32_t get_rtr_id(void) { struct ifaddrs *ifap, *ifa; @@ -1211,7 +1210,7 @@ get_rtr_id(void) return (ip); } -int +static int get_prefix(const char *s, union eigrpd_addr *addr, uint8_t *plen) { char *p, *ps; diff --git a/usr.sbin/eigrpd/printconf.c b/usr.sbin/eigrpd/printconf.c index a4ba0c3c6e7..826ef1d2436 100644 --- a/usr.sbin/eigrpd/printconf.c +++ b/usr.sbin/eigrpd/printconf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: printconf.c,v 1.5 2016/09/02 16:29:55 renato Exp $ */ +/* $OpenBSD: printconf.c,v 1.6 2016/09/02 16:44:33 renato Exp $ */ /* * Copyright (c) 2015 Renato Westphal <renato@openbsd.org> @@ -24,15 +24,15 @@ #include "eigrpd.h" #include "log.h" -void print_mainconf(struct eigrpd_conf *); -const char *print_no(uint16_t); -void print_redist_metric(struct redist_metric *); -void print_redistribute(struct eigrp *); -void print_iface(struct eigrp_iface *); -void print_as(struct eigrp *); -void print_af(struct eigrpd_conf *, int); +static void print_mainconf(struct eigrpd_conf *); +static const char *print_no(uint16_t); +static void print_redist_metric(struct redist_metric *); +static void print_redistribute(struct eigrp *); +static void print_iface(struct eigrp_iface *); +static void print_as(struct eigrp *); +static void print_af(struct eigrpd_conf *, int); -void +static void print_mainconf(struct eigrpd_conf *conf) { printf("router-id %s\n", inet_ntoa(conf->rtr_id)); @@ -48,7 +48,7 @@ print_mainconf(struct eigrpd_conf *conf) printf("fib-priority-summary %u\n", conf->fib_priority_summary); } -const char * +static const char * print_no(uint16_t type) { if (type & REDIST_NO) @@ -57,14 +57,14 @@ print_no(uint16_t type) return (""); } -void +static void print_redist_metric(struct redist_metric *metric) { printf(" %u %u %u %u %u", metric->bandwidth, metric->delay, metric->reliability, metric->load, metric->mtu); } -void +static void print_redistribute(struct eigrp *eigrp) { struct redistribute *r; @@ -108,7 +108,7 @@ print_redistribute(struct eigrp *eigrp) } } -void +static void print_iface(struct eigrp_iface *ei) { struct summary_addr *summary; @@ -127,7 +127,7 @@ print_iface(struct eigrp_iface *ei) printf("\t\t}\n"); } -void +static void print_as(struct eigrp *eigrp) { struct eigrp_iface *ei; @@ -147,7 +147,7 @@ print_as(struct eigrp *eigrp) printf("\t}\n"); } -void +static void print_af(struct eigrpd_conf *conf, int af) { struct eigrp *eigrp; diff --git a/usr.sbin/eigrpd/query.c b/usr.sbin/eigrpd/query.c index a28ca2ffc7c..70d60d81b7b 100644 --- a/usr.sbin/eigrpd/query.c +++ b/usr.sbin/eigrpd/query.c @@ -1,4 +1,4 @@ -/* $OpenBSD: query.c,v 1.3 2016/09/02 16:29:55 renato Exp $ */ +/* $OpenBSD: query.c,v 1.4 2016/09/02 16:44:33 renato Exp $ */ /* * Copyright (c) 2015 Renato Westphal <renato@openbsd.org> @@ -27,8 +27,6 @@ #include "eigrpe.h" #include "log.h" -extern struct eigrpd_conf *econf; - /* query packet handling */ void diff --git a/usr.sbin/eigrpd/rde.c b/usr.sbin/eigrpd/rde.c index 6eb797ca0b2..aea52e4f66c 100644 --- a/usr.sbin/eigrpd/rde.c +++ b/usr.sbin/eigrpd/rde.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde.c,v 1.21 2016/09/02 16:39:44 renato Exp $ */ +/* $OpenBSD: rde.c,v 1.22 2016/09/02 16:44:33 renato Exp $ */ /* * Copyright (c) 2015 Renato Westphal <renato@openbsd.org> @@ -35,25 +35,23 @@ #include "rde.h" #include "log.h" -void rde_sig_handler(int sig, short, void *); -__dead void rde_shutdown(void); -void rde_dispatch_imsg(int, short, void *); -void rde_dispatch_parent(int, short, void *); +static void rde_sig_handler(int sig, short, void *); +static __dead void rde_shutdown(void); +static void rde_dispatch_imsg(int, short, void *); +static void rde_dispatch_parent(int, short, void *); +static struct redistribute *eigrp_redistribute(struct eigrp *, struct kroute *); +static void rt_redist_set(struct kroute *, int); +static void rt_snap(struct rde_nbr *); +static struct ctl_rt *rt_to_ctl(struct rt_node *, struct eigrp_route *); +static void rt_dump(struct ctl_show_topology_req *, pid_t); struct eigrpd_conf *rdeconf; -struct imsgev *iev_eigrpe; -struct imsgev *iev_main; -extern struct iface_id_head ifaces_by_id; -RB_PROTOTYPE(iface_id_head, eigrp_iface, id_tree, iface_id_compare) - -RB_PROTOTYPE(rt_tree, rt_node, entry, rt_compare) - -extern struct rde_nbr_head rde_nbrs; -RB_PROTOTYPE(rde_nbr_head, rde_nbr, entry, rde_nbr_compare) +static struct imsgev *iev_eigrpe; +static struct imsgev *iev_main; /* ARGSUSED */ -void +static void rde_sig_handler(int sig, short event, void *arg) { /* @@ -133,7 +131,7 @@ rde(int debug, int verbose) return (0); } -__dead void +static __dead void rde_shutdown(void) { /* close pipes */ @@ -167,7 +165,7 @@ rde_imsg_compose_eigrpe(int type, uint32_t peerid, pid_t pid, void *data, } /* ARGSUSED */ -void +static void rde_dispatch_imsg(int fd, short event, void *bula) { struct imsgev *iev = bula; @@ -301,7 +299,7 @@ rde_dispatch_imsg(int fd, short event, void *bula) } /* ARGSUSED */ -void +static void rde_dispatch_parent(int fd, short event, void *bula) { static struct eigrpd_conf *nconf; @@ -639,7 +637,7 @@ eigrp_redistribute(struct eigrp *eigrp, struct kroute *kr) return (NULL); } -void +static void rt_redist_set(struct kroute *kr, int withdraw) { struct eigrp *eigrp; @@ -683,7 +681,7 @@ rt_redist_set(struct kroute *kr, int withdraw) ri.metric.flags = 0; /* external metric */ - ri.emetric.routerid = htonl(eigrp_router_id(rdeconf)); + ri.emetric.routerid = htonl(rdeconf->rtr_id.s_addr); ri.emetric.as = r->emetric.as; ri.emetric.tag = r->emetric.tag; ri.emetric.metric = r->emetric.metric; @@ -720,7 +718,7 @@ rt_summary_set(struct eigrp *eigrp, struct summary_addr *summary, } /* send all known routing information to new neighbor */ -void +static void rt_snap(struct rde_nbr *nbr) { struct eigrp *eigrp = nbr->eigrp; @@ -739,7 +737,7 @@ rt_snap(struct rde_nbr *nbr) NULL, 0); } -struct ctl_rt * +static struct ctl_rt * rt_to_ctl(struct rt_node *rn, struct eigrp_route *route) { static struct ctl_rt rtctl; @@ -782,7 +780,7 @@ rt_to_ctl(struct rt_node *rn, struct eigrp_route *route) return (&rtctl); } -void +static void rt_dump(struct ctl_show_topology_req *treq, pid_t pid) { struct eigrp *eigrp; diff --git a/usr.sbin/eigrpd/rde.h b/usr.sbin/eigrpd/rde.h index d95228bf24f..55122ffd41d 100644 --- a/usr.sbin/eigrpd/rde.h +++ b/usr.sbin/eigrpd/rde.h @@ -1,4 +1,4 @@ -/* $OpenBSD: rde.h,v 1.10 2016/09/02 16:29:55 renato Exp $ */ +/* $OpenBSD: rde.h,v 1.11 2016/09/02 16:44:33 renato Exp $ */ /* * Copyright (c) 2015 Renato Westphal <renato@openbsd.org> @@ -33,19 +33,21 @@ struct rde_nbr { struct eigrp_iface *ei; struct eigrp *eigrp; TAILQ_HEAD(,reply_node) rijk; /* outstanding replies */ + + /* + * We have one "self" neighbor for each interface on which EIGRP is + * configured. This way we can inject local routes into the DUAL FSM + * just like any other route received from a remote neighbor. For each + * instance, we also have two additional special neighbors used to + * inject redistributed and summarized routes. + */ uint8_t flags; -}; -/* - * We have one "self" neighbor for each interface on which EIGRP is configured. - * This way we can inject local routes into the DUAL FSM just like any other - * route received from a remote neighbor. For each instance, we also have two - * additional special neighbors used to inject redistributed and summarized - * routes. - */ #define F_RDE_NBR_SELF 0x01 #define F_RDE_NBR_LOCAL 0x02 #define F_RDE_NBR_REDIST 0x04 #define F_RDE_NBR_SUMMARY 0x08 +}; +RB_PROTOTYPE(rde_nbr_head, rde_nbr, entry, rde_nbr_compare) struct reply_node { TAILQ_ENTRY(reply_node) rn_entry; @@ -90,6 +92,7 @@ struct rt_node { struct classic_emetric emetric; } successor; }; +RB_PROTOTYPE(rt_tree, rt_node, entry, rt_compare) /* DUAL states */ #define DUAL_STA_PASSIVE 0x0001 @@ -119,74 +122,33 @@ enum dual_event { DUAL_EVT_16 }; +extern struct eigrpd_conf *rdeconf; +extern struct rde_nbr_head rde_nbrs; + /* rde.c */ pid_t rde(int, int); int rde_imsg_compose_parent(int, pid_t, void *, uint16_t); int rde_imsg_compose_eigrpe(int, uint32_t, pid_t, void *, uint16_t); - void rde_instance_init(struct eigrp *); void rde_instance_del(struct eigrp *); void rde_send_change_kroute(struct rt_node *, struct eigrp_route *); void rde_send_delete_kroute(struct rt_node *, struct eigrp_route *); -void rt_redist_set(struct kroute *, int); void rt_summary_set(struct eigrp *, struct summary_addr *, struct classic_metric *); -void rt_snap(struct rde_nbr *); -struct ctl_rt *rt_to_ctl(struct rt_node *, struct eigrp_route *); -void rt_dump(struct ctl_show_topology_req *, pid_t); - -/* rde_nbr.c */ -struct rde_nbr *rde_nbr_find(uint32_t); -struct rde_nbr *rde_nbr_new(uint32_t, struct rde_nbr *); -void rde_nbr_del(struct rde_nbr *, int); /* rde_dual.c */ -int dual_fsm(struct rt_node *, enum dual_event); -struct rt_node *rt_find(struct eigrp *, struct rinfo *); -struct rt_node *rt_new(struct eigrp *, struct rinfo *); void rt_del(struct rt_node *); -struct eigrp_route *route_find(struct rde_nbr *, struct rt_node *); -struct eigrp_route *route_new(struct rt_node *, struct rde_nbr *, - struct rinfo *); -void route_del(struct rt_node *, struct eigrp_route *); -uint32_t safe_sum_uint32(uint32_t, uint32_t); -uint32_t safe_mul_uint32(uint32_t, uint32_t); uint32_t eigrp_composite_delay(uint32_t); uint32_t eigrp_real_delay(uint32_t); uint32_t eigrp_composite_bandwidth(uint32_t); uint32_t eigrp_real_bandwidth(uint32_t); -uint32_t route_composite_metric(uint8_t *, uint32_t, uint32_t, - uint8_t, uint8_t); -void route_update_metrics(struct eigrp *, - struct eigrp_route *, struct rinfo *); -void reply_outstanding_add(struct rt_node *, - struct rde_nbr *); -struct reply_node *reply_outstanding_find(struct rt_node *, - struct rde_nbr *); -void reply_outstanding_remove(struct reply_node *); void rinfo_fill_successor(struct rt_node *, struct rinfo *); -void rinfo_fill_infinite(struct rt_node *, enum route_type, - struct rinfo *); -void rt_update_fib(struct rt_node *); -void rt_set_successor(struct rt_node *, - struct eigrp_route *); -struct eigrp_route *rt_get_successor_fc(struct rt_node *); - struct summary_addr *rde_summary_check(struct eigrp_iface *, union eigrpd_addr *, uint8_t); -void rde_send_update(struct eigrp_iface *, struct rinfo *); -void rde_send_update_all(struct rt_node *, struct rinfo *); -void rde_send_query(struct eigrp_iface *, struct rinfo *, - int); -void rde_send_siaquery(struct rde_nbr *, struct rinfo *); -void rde_send_query_all(struct eigrp *, struct rt_node *, - int); void rde_flush_queries(void); -void rde_send_reply(struct rde_nbr *, struct rinfo *, int); void rde_check_update(struct rde_nbr *, struct rinfo *); void rde_check_query(struct rde_nbr *, struct rinfo *, int); -void rde_last_reply(struct rt_node *); void rde_check_reply(struct rde_nbr *, struct rinfo *, int); void rde_check_link_down_rn(struct rde_nbr *, struct rt_node *, struct eigrp_route *); @@ -194,5 +156,8 @@ void rde_check_link_down_nbr(struct rde_nbr *); void rde_check_link_down(unsigned int); void rde_check_link_cost_change(struct rde_nbr *, struct eigrp_iface *); +struct rde_nbr *rde_nbr_find(uint32_t); +struct rde_nbr *rde_nbr_new(uint32_t, struct rde_nbr *); +void rde_nbr_del(struct rde_nbr *, int); #endif /* _RDE_H_ */ diff --git a/usr.sbin/eigrpd/rde_dual.c b/usr.sbin/eigrpd/rde_dual.c index 9170f9d9955..f1ed306e137 100644 --- a/usr.sbin/eigrpd/rde_dual.c +++ b/usr.sbin/eigrpd/rde_dual.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde_dual.c,v 1.27 2016/09/02 16:29:55 renato Exp $ */ +/* $OpenBSD: rde_dual.c,v 1.28 2016/09/02 16:44:33 renato Exp $ */ /* * Copyright (c) 2015 Renato Westphal <renato@openbsd.org> @@ -26,22 +26,49 @@ #include "rde.h" #include "log.h" -void reply_active_timer(int, short, void *); -void reply_active_start_timer(struct reply_node *); -void reply_active_stop_timer(struct reply_node *); -void reply_sia_timer(int, short, void *); -void reply_sia_start_timer(struct reply_node *); -void reply_sia_stop_timer(struct reply_node *); +static int dual_fsm(struct rt_node *, enum dual_event); +static __inline int rt_compare(struct rt_node *, struct rt_node *); +static struct rt_node *rt_find(struct eigrp *, struct rinfo *); +static struct rt_node *rt_new(struct eigrp *, struct rinfo *); +static struct eigrp_route *route_find(struct rde_nbr *, struct rt_node *); +static struct eigrp_route *route_new(struct rt_node *, struct rde_nbr *, + struct rinfo *); +static void route_del(struct rt_node *, struct eigrp_route *); +static uint32_t safe_sum_uint32(uint32_t, uint32_t); +static uint32_t safe_mul_uint32(uint32_t, uint32_t); +static uint32_t route_composite_metric(uint8_t *, uint32_t, uint32_t, + uint8_t, uint8_t); +static void route_update_metrics(struct eigrp *, + struct eigrp_route *, struct rinfo *); +static void reply_outstanding_add(struct rt_node *, + struct rde_nbr *); +static struct reply_node *reply_outstanding_find(struct rt_node *, + struct rde_nbr *); +static void reply_outstanding_remove(struct reply_node *); +static void reply_active_timer(int, short, void *); +static void reply_active_start_timer(struct reply_node *); +static void reply_active_stop_timer(struct reply_node *); +static void reply_sia_timer(int, short, void *); +static void reply_sia_start_timer(struct reply_node *); +static void reply_sia_stop_timer(struct reply_node *); +static void rinfo_fill_infinite(struct rt_node *, enum route_type, + struct rinfo *); +static void rt_update_fib(struct rt_node *); +static void rt_set_successor(struct rt_node *, + struct eigrp_route *); +static struct eigrp_route *rt_get_successor_fc(struct rt_node *); +static void rde_send_update(struct eigrp_iface *, struct rinfo *); +static void rde_send_update_all(struct rt_node *, struct rinfo *); +static void rde_send_query(struct eigrp_iface *, struct rinfo *, + int); +static void rde_send_siaquery(struct rde_nbr *, struct rinfo *); +static void rde_send_query_all(struct eigrp *, struct rt_node *, + int); +static void rde_send_reply(struct rde_nbr *, struct rinfo *, int); +static void rde_last_reply(struct rt_node *); +static __inline int rde_nbr_compare(struct rde_nbr *, struct rde_nbr *); -extern struct eigrpd_conf *rdeconf; - -static int rt_compare(struct rt_node *, struct rt_node *); -RB_PROTOTYPE(rt_tree, rt_node, entry, rt_compare) RB_GENERATE(rt_tree, rt_node, entry, rt_compare) - -static __inline int rde_nbr_compare(struct rde_nbr *, struct rde_nbr *); -RB_HEAD(rde_nbr_head, rde_nbr); -RB_PROTOTYPE(rde_nbr_head, rde_nbr, entry, rde_nbr_compare) RB_GENERATE(rde_nbr_head, rde_nbr, entry, rde_nbr_compare) struct rde_nbr_head rde_nbrs = RB_INITIALIZER(&rde_nbrs); @@ -50,7 +77,7 @@ struct rde_nbr_head rde_nbrs = RB_INITIALIZER(&rde_nbrs); * NOTE: events that don't cause a state transition aren't triggered to avoid * too much verbosity and are here mostly for illustration purposes. */ -struct { +static struct { int state; enum dual_event event; int new_state; @@ -83,7 +110,7 @@ struct { {-1, 0, 0}, }; -const char * const dual_event_names[] = { +static const char * const dual_event_names[] = { "DUAL_EVT_1", "DUAL_EVT_2", "DUAL_EVT_3", @@ -102,7 +129,7 @@ const char * const dual_event_names[] = { "DUAL_EVT_16" }; -int +static int dual_fsm(struct rt_node *rn, enum dual_event event) { int old_state; @@ -142,7 +169,7 @@ dual_fsm(struct rt_node *rn, enum dual_event event) return (0); } -static int +static __inline int rt_compare(struct rt_node *a, struct rt_node *b) { int addrcmp; @@ -159,7 +186,7 @@ rt_compare(struct rt_node *a, struct rt_node *b) return (0); } -struct rt_node * +static struct rt_node * rt_find(struct eigrp *eigrp, struct rinfo *ri) { struct rt_node rn; @@ -171,7 +198,7 @@ rt_find(struct eigrp *eigrp, struct rinfo *ri) return (RB_FIND(rt_tree, &eigrp->topology, &rn)); } -struct rt_node * +static struct rt_node * rt_new(struct eigrp *eigrp, struct rinfo *ri) { struct rt_node *rn; @@ -214,7 +241,7 @@ rt_del(struct rt_node *rn) free(rn); } -struct eigrp_route * +static struct eigrp_route * route_find(struct rde_nbr *nbr, struct rt_node *rn) { struct eigrp_route *route; @@ -226,7 +253,7 @@ route_find(struct rde_nbr *nbr, struct rt_node *rn) return (NULL); } -struct eigrp_route * +static struct eigrp_route * route_new(struct rt_node *rn, struct rde_nbr *nbr, struct rinfo *ri) { struct eigrp *eigrp = rn->eigrp; @@ -260,7 +287,7 @@ route_new(struct rt_node *rn, struct rde_nbr *nbr, struct rinfo *ri) return (route); } -void +static void route_del(struct rt_node *rn, struct eigrp_route *route) { struct eigrp *eigrp = rn->eigrp; @@ -275,7 +302,7 @@ route_del(struct rt_node *rn, struct eigrp_route *route) free(route); } -uint32_t +static uint32_t safe_sum_uint32(uint32_t a, uint32_t b) { uint64_t total; @@ -288,7 +315,7 @@ safe_sum_uint32(uint32_t a, uint32_t b) return ((uint32_t) total); } -uint32_t +static uint32_t safe_mul_uint32(uint32_t a, uint32_t b) { uint64_t total; @@ -333,7 +360,7 @@ eigrp_real_bandwidth(uint32_t bandwidth) return ((EIGRP_SCALING_FACTOR * (uint32_t)10000000) / bandwidth); } -uint32_t +static uint32_t route_composite_metric(uint8_t *kvalues, uint32_t delay, uint32_t bandwidth, uint8_t load, uint8_t reliability) { @@ -368,7 +395,7 @@ route_composite_metric(uint8_t *kvalues, uint32_t delay, uint32_t bandwidth, return ((uint32_t) distance); } -void +static void route_update_metrics(struct eigrp *eigrp, struct eigrp_route *route, struct rinfo *ri) { @@ -411,7 +438,7 @@ route_update_metrics(struct eigrp *eigrp, struct eigrp_route *route, bandwidth, DEFAULT_LOAD, DEFAULT_RELIABILITY); } -void +static void reply_outstanding_add(struct rt_node *rn, struct rde_nbr *nbr) { struct reply_node *reply; @@ -434,7 +461,7 @@ reply_outstanding_add(struct rt_node *rn, struct rde_nbr *nbr) } } -struct reply_node * +static struct reply_node * reply_outstanding_find(struct rt_node *rn, struct rde_nbr *nbr) { struct reply_node *reply; @@ -446,7 +473,7 @@ reply_outstanding_find(struct rt_node *rn, struct rde_nbr *nbr) return (NULL); } -void +static void reply_outstanding_remove(struct reply_node *reply) { reply_active_stop_timer(reply); @@ -457,7 +484,7 @@ reply_outstanding_remove(struct reply_node *reply) } /* ARGSUSED */ -void +static void reply_active_timer(int fd, short event, void *arg) { struct reply_node *reply = arg; @@ -469,7 +496,7 @@ reply_active_timer(int fd, short event, void *arg) rde_nbr_del(reply->nbr, 1); } -void +static void reply_active_start_timer(struct reply_node *reply) { struct eigrp *eigrp = reply->nbr->eigrp; @@ -481,7 +508,7 @@ reply_active_start_timer(struct reply_node *reply) fatal("reply_active_start_timer"); } -void +static void reply_active_stop_timer(struct reply_node *reply) { if (evtimer_pending(&reply->ev_active_timeout, NULL) && @@ -490,7 +517,7 @@ reply_active_stop_timer(struct reply_node *reply) } /* ARGSUSED */ -void +static void reply_sia_timer(int fd, short event, void *arg) { struct reply_node *reply = arg; @@ -530,7 +557,7 @@ reply_sia_timer(int fd, short event, void *arg) rde_send_siaquery(nbr, &ri); } -void +static void reply_sia_start_timer(struct reply_node *reply) { struct eigrp *eigrp = reply->nbr->eigrp; @@ -547,7 +574,7 @@ reply_sia_start_timer(struct reply_node *reply) fatal("reply_sia_start_timer"); } -void +static void reply_sia_stop_timer(struct reply_node *reply) { if (evtimer_pending(&reply->ev_sia_timeout, NULL) && @@ -573,7 +600,7 @@ rinfo_fill_successor(struct rt_node *rn, struct rinfo *ri) ri->emetric = rn->successor.emetric; } -void +static void rinfo_fill_infinite(struct rt_node *rn, enum route_type type, struct rinfo *ri) { memset(ri, 0, sizeof(*ri)); @@ -584,7 +611,7 @@ rinfo_fill_infinite(struct rt_node *rn, enum route_type type, struct rinfo *ri) ri->metric.delay = EIGRP_INFINITE_METRIC; } -void +static void rt_update_fib(struct rt_node *rn) { struct eigrp *eigrp = rn->eigrp; @@ -638,7 +665,7 @@ uninstall: } } -void +static void rt_set_successor(struct rt_node *rn, struct eigrp_route *successor) { struct eigrp *eigrp = rn->eigrp; @@ -671,7 +698,7 @@ rt_set_successor(struct rt_node *rn, struct eigrp_route *successor) } } -struct eigrp_route * +static struct eigrp_route * rt_get_successor_fc(struct rt_node *rn) { struct eigrp_route *route, *successor = NULL; @@ -731,7 +758,7 @@ rde_summary_check(struct eigrp_iface *ei, union eigrpd_addr *prefix, return (NULL); } -void +static void rde_send_update(struct eigrp_iface *ei, struct rinfo *ri) { if (ri->metric.hop_count >= ei->eigrp->maximum_hops || @@ -744,7 +771,7 @@ rde_send_update(struct eigrp_iface *ei, struct rinfo *ri) NULL, 0); } -void +static void rde_send_update_all(struct rt_node *rn, struct rinfo *ri) { struct eigrp *eigrp = rn->eigrp; @@ -759,7 +786,7 @@ rde_send_update_all(struct rt_node *rn, struct rinfo *ri) } } -void +static void rde_send_query(struct eigrp_iface *ei, struct rinfo *ri, int push) { rde_imsg_compose_eigrpe(IMSG_SEND_MQUERY, ei->ifaceid, 0, @@ -769,7 +796,7 @@ rde_send_query(struct eigrp_iface *ei, struct rinfo *ri, int push) 0, NULL, 0); } -void +static void rde_send_siaquery(struct rde_nbr *nbr, struct rinfo *ri) { rde_imsg_compose_eigrpe(IMSG_SEND_QUERY, nbr->peerid, 0, @@ -778,7 +805,7 @@ rde_send_siaquery(struct rde_nbr *nbr, struct rinfo *ri) NULL, 0); } -void +static void rde_send_query_all(struct eigrp *eigrp, struct rt_node *rn, int push) { struct eigrp_iface *ei; @@ -821,7 +848,7 @@ rde_flush_queries(void) ei->ifaceid, 0, NULL, 0); } -void +static void rde_send_reply(struct rde_nbr *nbr, struct rinfo *ri, int siareply) { int type; @@ -1015,7 +1042,7 @@ rde_check_query(struct rde_nbr *nbr, struct rinfo *ri, int siaquery) } } -void +static void rde_last_reply(struct rt_node *rn) { struct eigrp *eigrp = rn->eigrp; diff --git a/usr.sbin/eigrpd/reply.c b/usr.sbin/eigrpd/reply.c index 9e4ee903480..f12f6dae10a 100644 --- a/usr.sbin/eigrpd/reply.c +++ b/usr.sbin/eigrpd/reply.c @@ -1,4 +1,4 @@ -/* $OpenBSD: reply.c,v 1.3 2016/09/02 16:29:55 renato Exp $ */ +/* $OpenBSD: reply.c,v 1.4 2016/09/02 16:44:33 renato Exp $ */ /* * Copyright (c) 2015 Renato Westphal <renato@openbsd.org> @@ -27,8 +27,6 @@ #include "eigrpe.h" #include "log.h" -extern struct eigrpd_conf *econf; - /* reply packet handling */ void diff --git a/usr.sbin/eigrpd/rtp.c b/usr.sbin/eigrpd/rtp.c index 302ec97106f..3a62ee9f4e0 100644 --- a/usr.sbin/eigrpd/rtp.c +++ b/usr.sbin/eigrpd/rtp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtp.c,v 1.6 2016/09/02 16:29:55 renato Exp $ */ +/* $OpenBSD: rtp.c,v 1.7 2016/09/02 16:44:33 renato Exp $ */ /* * Copyright (c) 2015 Renato Westphal <renato@openbsd.org> @@ -26,11 +26,18 @@ #include "eigrpe.h" #include "log.h" -void rtp_retrans_timer(int, short, void *); -void rtp_retrans_start_timer(struct packet *); -void rtp_retrans_stop_timer(struct packet *); - -struct pbuf * +static struct pbuf *rtp_buf_new(struct ibuf *); +static struct pbuf *rtp_buf_hold(struct pbuf *); +static void rtp_buf_release(struct pbuf *); +static struct packet *rtp_packet_new(struct nbr *, uint32_t, struct pbuf *); +static void rtp_send_packet(struct packet *); +static void rtp_enqueue_packet(struct packet *); +static void rtp_send_mcast(struct eigrp_iface *, struct ibuf *); +static void rtp_retrans_timer(int, short, void *); +static void rtp_retrans_start_timer(struct packet *); +static void rtp_retrans_stop_timer(struct packet *); + +static struct pbuf * rtp_buf_new(struct ibuf *buf) { struct pbuf *pbuf; @@ -42,14 +49,14 @@ rtp_buf_new(struct ibuf *buf) return (pbuf); } -struct pbuf * +static struct pbuf * rtp_buf_hold(struct pbuf *pbuf) { pbuf->refcnt++; return (pbuf); } -void +static void rtp_buf_release(struct pbuf *pbuf) { if (--pbuf->refcnt == 0) { @@ -58,7 +65,7 @@ rtp_buf_release(struct pbuf *pbuf) } } -struct packet * +static struct packet * rtp_packet_new(struct nbr *nbr, uint32_t seq_num, struct pbuf *pbuf) { struct packet *pkt; @@ -106,14 +113,14 @@ rtp_process_ack(struct nbr *nbr, uint32_t ack_num) } } -void +static void rtp_send_packet(struct packet *pkt) { rtp_retrans_start_timer(pkt); send_packet(pkt->nbr->ei, pkt->nbr, 0, pkt->pbuf->buf); } -void +static void rtp_enqueue_packet(struct packet *pkt) { /* only send packet if transmission queue is empty */ @@ -147,7 +154,7 @@ rtp_send_ucast(struct nbr *nbr, struct ibuf *buf) rtp_seq_inc(eigrp); } -void +static void rtp_send_mcast(struct eigrp_iface *ei, struct ibuf *buf) { struct eigrp *eigrp = ei->eigrp; @@ -242,7 +249,7 @@ rtp_send_ack(struct nbr *nbr) /* timers */ /* ARGSUSED */ -void +static void rtp_retrans_timer(int fd, short event, void *arg) { struct packet *pkt = arg; @@ -260,7 +267,7 @@ rtp_retrans_timer(int fd, short event, void *arg) rtp_send_packet(pkt); } -void +static void rtp_retrans_start_timer(struct packet *pkt) { struct timeval tv; @@ -271,7 +278,7 @@ rtp_retrans_start_timer(struct packet *pkt) fatal("rtp_retrans_start_timer"); } -void +static void rtp_retrans_stop_timer(struct packet *pkt) { if (evtimer_pending(&pkt->ev_timeout, NULL) && diff --git a/usr.sbin/eigrpd/update.c b/usr.sbin/eigrpd/update.c index 3579c5b409f..03b38fb35cd 100644 --- a/usr.sbin/eigrpd/update.c +++ b/usr.sbin/eigrpd/update.c @@ -1,4 +1,4 @@ -/* $OpenBSD: update.c,v 1.4 2016/09/02 16:29:55 renato Exp $ */ +/* $OpenBSD: update.c,v 1.5 2016/09/02 16:44:33 renato Exp $ */ /* * Copyright (c) 2015 Renato Westphal <renato@openbsd.org> @@ -27,8 +27,6 @@ #include "eigrpe.h" #include "log.h" -extern struct eigrpd_conf *econf; - /* update packet handling */ void |