summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrenato <renato@openbsd.org>2016-05-23 19:09:25 +0000
committerrenato <renato@openbsd.org>2016-05-23 19:09:25 +0000
commitc28a25a1463c46f98e1aa4db41e1d80505f68682 (patch)
tree9d5a3f05682077daecc59e521beacf1bca6ddf54
parentIntroduce the 'ldpctl clear neighbors' command. (diff)
downloadwireguard-openbsd-c28a25a1463c46f98e1aa4db41e1d80505f68682.tar.xz
wireguard-openbsd-c28a25a1463c46f98e1aa4db41e1d80505f68682.zip
Make functions and variables static whenever possible.
The benefits of this include: * clean up of the ldpd global namespace; * improved readability; * more hints to the compiler/linker to generate more efficient code. Whenever possible, move global static variables to a smaller scope (function). All extern variables are now declared in header files to avoid unnecessary duplication. This patch also cleans up the indentation of all function prototypes and global variables.
-rw-r--r--usr.sbin/ldpd/accept.c18
-rw-r--r--usr.sbin/ldpd/address.c9
-rw-r--r--usr.sbin/ldpd/adjacency.c23
-rw-r--r--usr.sbin/ldpd/control.c22
-rw-r--r--usr.sbin/ldpd/control.h6
-rw-r--r--usr.sbin/ldpd/hello.c30
-rw-r--r--usr.sbin/ldpd/init.c12
-rw-r--r--usr.sbin/ldpd/interface.c43
-rw-r--r--usr.sbin/ldpd/kroute.c166
-rw-r--r--usr.sbin/ldpd/l2vpn.c10
-rw-r--r--usr.sbin/ldpd/labelmapping.c18
-rw-r--r--usr.sbin/ldpd/lde.c70
-rw-r--r--usr.sbin/ldpd/lde.h72
-rw-r--r--usr.sbin/ldpd/lde_lib.c37
-rw-r--r--usr.sbin/ldpd/ldpd.c106
-rw-r--r--usr.sbin/ldpd/ldpd.h43
-rw-r--r--usr.sbin/ldpd/ldpe.c43
-rw-r--r--usr.sbin/ldpd/ldpe.h128
-rw-r--r--usr.sbin/ldpd/log.c10
-rw-r--r--usr.sbin/ldpd/log.h44
-rw-r--r--usr.sbin/ldpd/neighbor.c99
-rw-r--r--usr.sbin/ldpd/notification.c6
-rw-r--r--usr.sbin/ldpd/packet.c32
-rw-r--r--usr.sbin/ldpd/parse.y163
-rw-r--r--usr.sbin/ldpd/pfkey.c48
-rw-r--r--usr.sbin/ldpd/printconf.c30
-rw-r--r--usr.sbin/ldpd/socket.c5
27 files changed, 628 insertions, 665 deletions
diff --git a/usr.sbin/ldpd/accept.c b/usr.sbin/ldpd/accept.c
index 0f352c0d86a..d4c4a10483d 100644
--- a/usr.sbin/ldpd/accept.c
+++ b/usr.sbin/ldpd/accept.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: accept.c,v 1.5 2016/05/23 17:43:42 renato Exp $ */
+/* $OpenBSD: accept.c,v 1.6 2016/05/23 19:09:25 renato Exp $ */
/*
* Copyright (c) 2012 Claudio Jeker <claudio@openbsd.org>
@@ -38,10 +38,10 @@ struct {
struct event evt;
} accept_queue;
-void accept_arm(void);
-void accept_unarm(void);
-void accept_cb(int, short, void *);
-void accept_timeout(int, short, void *);
+static void accept_arm(void);
+static void accept_unarm(void);
+static void accept_cb(int, short, void *);
+static void accept_timeout(int, short, void *);
void
accept_init(void)
@@ -105,7 +105,7 @@ accept_unpause(void)
}
}
-void
+static void
accept_arm(void)
{
struct accept_ev *av;
@@ -113,7 +113,7 @@ accept_arm(void)
event_add(&av->ev, NULL);
}
-void
+static void
accept_unarm(void)
{
struct accept_ev *av;
@@ -121,7 +121,7 @@ accept_unarm(void)
event_del(&av->ev);
}
-void
+static void
accept_cb(int fd, short event, void *arg)
{
struct accept_ev *av = arg;
@@ -129,7 +129,7 @@ accept_cb(int fd, short event, void *arg)
av->accept_cb(fd, event, av->arg);
}
-void
+static void
accept_timeout(int fd, short event, void *bula)
{
log_debug(__func__);
diff --git a/usr.sbin/ldpd/address.c b/usr.sbin/ldpd/address.c
index 45e85e99b8f..e15514f51ab 100644
--- a/usr.sbin/ldpd/address.c
+++ b/usr.sbin/ldpd/address.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: address.c,v 1.23 2016/05/23 18:58:48 renato Exp $ */
+/* $OpenBSD: address.c,v 1.24 2016/05/23 19:09:25 renato Exp $ */
/*
* Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
@@ -36,9 +36,8 @@
#include "lde.h"
#include "log.h"
-extern struct ldpd_conf *leconf;
-
-void gen_address_list_tlv(struct ibuf *, uint16_t, int, struct if_addr *);
+static void gen_address_list_tlv(struct ibuf *, uint16_t, int,
+ struct if_addr *);
void
send_address(struct nbr *nbr, int af, struct if_addr *if_addr, int withdraw)
@@ -181,7 +180,7 @@ recv_address(struct nbr *nbr, char *buf, uint16_t len)
return (0);
}
-void
+static void
gen_address_list_tlv(struct ibuf *buf, uint16_t size, int af,
struct if_addr *if_addr)
{
diff --git a/usr.sbin/ldpd/adjacency.c b/usr.sbin/ldpd/adjacency.c
index a116b4592b1..f55fce564c2 100644
--- a/usr.sbin/ldpd/adjacency.c
+++ b/usr.sbin/ldpd/adjacency.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: adjacency.c,v 1.19 2016/05/23 18:58:48 renato Exp $ */
+/* $OpenBSD: adjacency.c,v 1.20 2016/05/23 19:09:25 renato Exp $ */
/*
* Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
@@ -31,12 +31,11 @@
#include "control.h"
#include "log.h"
-extern struct ldpd_conf *leconf;
-
-void adj_itimer(int, short, void *);
-void tnbr_hello_timer(int, short, void *);
-void tnbr_start_hello_timer(struct tnbr *);
-void tnbr_stop_hello_timer(struct tnbr *);
+static void adj_itimer(int, short, void *);
+static void tnbr_del(struct tnbr *);
+static void tnbr_hello_timer(int, short, void *);
+static void tnbr_start_hello_timer(struct tnbr *);
+static void tnbr_stop_hello_timer(struct tnbr *);
struct adj *
adj_new(struct in_addr lsr_id, struct hello_source *source,
@@ -134,7 +133,7 @@ adj_get_af(struct adj *adj)
/* adjacency timers */
/* ARGSUSED */
-void
+static void
adj_itimer(int fd, short event, void *arg)
{
struct adj *adj = arg;
@@ -192,7 +191,7 @@ tnbr_new(struct ldpd_conf *xconf, int af, union ldpd_addr *addr)
return (tnbr);
}
-void
+static void
tnbr_del(struct tnbr *tnbr)
{
tnbr_stop_hello_timer(tnbr);
@@ -274,7 +273,7 @@ tnbr_update_all(int af)
/* target neighbors timers */
/* ARGSUSED */
-void
+static void
tnbr_hello_timer(int fd, short event, void *arg)
{
struct tnbr *tnbr = arg;
@@ -283,7 +282,7 @@ tnbr_hello_timer(int fd, short event, void *arg)
tnbr_start_hello_timer(tnbr);
}
-void
+static void
tnbr_start_hello_timer(struct tnbr *tnbr)
{
struct timeval tv;
@@ -294,7 +293,7 @@ tnbr_start_hello_timer(struct tnbr *tnbr)
fatal(__func__);
}
-void
+static void
tnbr_stop_hello_timer(struct tnbr *tnbr)
{
if (evtimer_pending(&tnbr->hello_timer, NULL) &&
diff --git a/usr.sbin/ldpd/control.c b/usr.sbin/ldpd/control.c
index 266f3850313..e9ed9d1fc61 100644
--- a/usr.sbin/ldpd/control.c
+++ b/usr.sbin/ldpd/control.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: control.c,v 1.24 2016/05/23 18:55:21 renato Exp $ */
+/* $OpenBSD: control.c,v 1.25 2016/05/23 19:09:25 renato Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -34,13 +34,15 @@
#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 *);
struct ctl_conns ctl_conns;
-int control_fd;
+static int control_fd;
int
control_init(void)
@@ -107,7 +109,7 @@ control_cleanup(void)
}
/* ARGSUSED */
-void
+static void
control_accept(int listenfd, short event, void *bula)
{
int connfd;
@@ -146,7 +148,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;
@@ -158,7 +160,7 @@ control_connbyfd(int fd)
return (c);
}
-struct ctl_conn *
+static struct ctl_conn *
control_connbypid(pid_t pid)
{
struct ctl_conn *c;
@@ -170,7 +172,7 @@ control_connbypid(pid_t pid)
return (c);
}
-void
+static void
control_close(int fd)
{
struct ctl_conn *c;
@@ -190,7 +192,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/ldpd/control.h b/usr.sbin/ldpd/control.h
index bd6911c9f36..b59002209d1 100644
--- a/usr.sbin/ldpd/control.h
+++ b/usr.sbin/ldpd/control.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: control.h,v 1.6 2016/05/23 18:55:21 renato Exp $ */
+/* $OpenBSD: control.h,v 1.7 2016/05/23 19:09:25 renato Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -33,9 +33,7 @@ extern struct ctl_conns ctl_conns;
int control_init(void);
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(void);
+int control_imsg_relay(struct imsg *);
#endif /* _CONTROL_H_ */
diff --git a/usr.sbin/ldpd/hello.c b/usr.sbin/ldpd/hello.c
index 043eac8b7da..588f46d3519 100644
--- a/usr.sbin/ldpd/hello.c
+++ b/usr.sbin/ldpd/hello.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: hello.c,v 1.40 2016/05/23 18:58:48 renato Exp $ */
+/* $OpenBSD: hello.c,v 1.41 2016/05/23 19:09:25 renato Exp $ */
/*
* Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
@@ -35,15 +35,13 @@
#include "log.h"
#include "ldpe.h"
-extern struct ldpd_conf *leconf;
-
-int tlv_decode_hello_prms(char *, uint16_t, uint16_t *, uint16_t *);
-int tlv_decode_opt_hello_prms(char *, uint16_t, int *, int,
- union ldpd_addr *, uint32_t *, uint16_t *);
-int gen_hello_prms_tlv(struct ibuf *buf, uint16_t, uint16_t);
-int gen_opt4_hello_prms_tlv(struct ibuf *, uint16_t, uint32_t);
-int gen_opt16_hello_prms_tlv(struct ibuf *, uint16_t, uint8_t *);
-int gen_ds_hello_prms_tlv(struct ibuf *, uint32_t);
+static int gen_hello_prms_tlv(struct ibuf *buf, uint16_t, uint16_t);
+static int gen_opt4_hello_prms_tlv(struct ibuf *, uint16_t, uint32_t);
+static int gen_opt16_hello_prms_tlv(struct ibuf *, uint16_t, uint8_t *);
+static int gen_ds_hello_prms_tlv(struct ibuf *, uint32_t);
+static int tlv_decode_hello_prms(char *, uint16_t, uint16_t *, uint16_t *);
+static int tlv_decode_opt_hello_prms(char *, uint16_t, int *, int,
+ union ldpd_addr *, uint32_t *, uint16_t *);
int
send_hello(enum hello_type type, struct iface_af *ia, struct tnbr *tnbr)
@@ -387,7 +385,7 @@ recv_hello(struct in_addr lsr_id, struct ldp_msg *lm, int af,
nbr_establish_connection(nbr);
}
-int
+static int
gen_hello_prms_tlv(struct ibuf *buf, uint16_t holdtime, uint16_t flags)
{
struct hello_prms_tlv parms;
@@ -401,7 +399,7 @@ gen_hello_prms_tlv(struct ibuf *buf, uint16_t holdtime, uint16_t flags)
return (ibuf_add(buf, &parms, sizeof(parms)));
}
-int
+static int
gen_opt4_hello_prms_tlv(struct ibuf *buf, uint16_t type, uint32_t value)
{
struct hello_prms_opt4_tlv parms;
@@ -414,7 +412,7 @@ gen_opt4_hello_prms_tlv(struct ibuf *buf, uint16_t type, uint32_t value)
return (ibuf_add(buf, &parms, sizeof(parms)));
}
-int
+static int
gen_opt16_hello_prms_tlv(struct ibuf *buf, uint16_t type, uint8_t *value)
{
struct hello_prms_opt16_tlv parms;
@@ -427,7 +425,7 @@ gen_opt16_hello_prms_tlv(struct ibuf *buf, uint16_t type, uint8_t *value)
return (ibuf_add(buf, &parms, sizeof(parms)));
}
-int
+static int
gen_ds_hello_prms_tlv(struct ibuf *buf, uint32_t value)
{
if (leconf->flags & F_LDPD_DS_CISCO_INTEROP)
@@ -438,7 +436,7 @@ gen_ds_hello_prms_tlv(struct ibuf *buf, uint32_t value)
return (gen_opt4_hello_prms_tlv(buf, TLV_TYPE_DUALSTACK, value));
}
-int
+static int
tlv_decode_hello_prms(char *buf, uint16_t len, uint16_t *holdtime,
uint16_t *flags)
{
@@ -459,7 +457,7 @@ tlv_decode_hello_prms(char *buf, uint16_t len, uint16_t *holdtime,
return (sizeof(tlv));
}
-int
+static int
tlv_decode_opt_hello_prms(char *buf, uint16_t len, int *tlvs_rcvd, int af,
union ldpd_addr *addr, uint32_t *conf_number, uint16_t *trans_pref)
{
diff --git a/usr.sbin/ldpd/init.c b/usr.sbin/ldpd/init.c
index 4e162bc8788..7d81c988d2d 100644
--- a/usr.sbin/ldpd/init.c
+++ b/usr.sbin/ldpd/init.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: init.c,v 1.25 2016/05/23 18:58:48 renato Exp $ */
+/* $OpenBSD: init.c,v 1.26 2016/05/23 19:09:25 renato Exp $ */
/*
* Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
@@ -36,10 +36,8 @@
#include "log.h"
#include "ldpe.h"
-extern struct ldpd_conf *leconf;
-
-int gen_init_prms_tlv(struct ibuf *, struct nbr *, uint16_t);
-int tlv_decode_opt_init_prms(char *, uint16_t);
+static int gen_init_prms_tlv(struct ibuf *, struct nbr *, uint16_t);
+static int tlv_decode_opt_init_prms(char *, uint16_t);
void
send_init(struct nbr *nbr)
@@ -122,7 +120,7 @@ recv_init(struct nbr *nbr, char *buf, uint16_t len)
return (0);
}
-int
+static int
gen_init_prms_tlv(struct ibuf *buf, struct nbr *nbr, uint16_t size)
{
struct sess_prms_tlv parms;
@@ -141,7 +139,7 @@ gen_init_prms_tlv(struct ibuf *buf, struct nbr *nbr, uint16_t size)
return (ibuf_add(buf, &parms, SESS_PRMS_SIZE));
}
-int
+static int
tlv_decode_opt_init_prms(char *buf, uint16_t len)
{
struct tlv tlv;
diff --git a/usr.sbin/ldpd/interface.c b/usr.sbin/ldpd/interface.c
index fcaefed8c15..9ef13fc4ae4 100644
--- a/usr.sbin/ldpd/interface.c
+++ b/usr.sbin/ldpd/interface.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: interface.c,v 1.41 2016/05/23 18:58:48 renato Exp $ */
+/* $OpenBSD: interface.c,v 1.42 2016/05/23 19:09:25 renato Exp $ */
/*
* Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org>
@@ -39,11 +39,18 @@
#include "log.h"
#include "ldpe.h"
-extern struct ldpd_conf *leconf;
-
-void if_hello_timer(int, short, void *);
-void if_start_hello_timer(struct iface_af *);
-void if_stop_hello_timer(struct iface_af *);
+static struct if_addr *if_addr_new(struct kaddr *);
+static struct if_addr *if_addr_lookup(struct if_addr_head *, struct kaddr *);
+static int if_start(struct iface *, int);
+static int if_reset(struct iface *, int);
+static void if_update_af(struct iface_af *, int);
+static void if_hello_timer(int, short, void *);
+static void if_start_hello_timer(struct iface_af *);
+static void if_stop_hello_timer(struct iface_af *);
+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 *);
struct iface *
if_new(struct kif *kif)
@@ -131,7 +138,7 @@ iface_af_get(struct iface *iface, int af)
}
}
-struct if_addr *
+static struct if_addr *
if_addr_new(struct kaddr *ka)
{
struct if_addr *if_addr;
@@ -147,7 +154,7 @@ if_addr_new(struct kaddr *ka)
return (if_addr);
}
-struct if_addr *
+static struct if_addr *
if_addr_lookup(struct if_addr_head *addr_list, struct kaddr *ka)
{
struct if_addr *if_addr;
@@ -235,7 +242,7 @@ if_addr_del(struct kaddr *ka)
}
}
-int
+static int
if_start(struct iface *iface, int af)
{
struct iface_af *ia;
@@ -269,7 +276,7 @@ if_start(struct iface *iface, int af)
return (0);
}
-int
+static int
if_reset(struct iface *iface, int af)
{
struct iface_af *ia;
@@ -301,7 +308,7 @@ if_reset(struct iface *iface, int af)
return (0);
}
-void
+static void
if_update_af(struct iface_af *ia, int link_ok)
{
int addr_ok = 0, socket_ok, rtr_id_ok;
@@ -380,7 +387,7 @@ if_update_all(int af)
/* timers */
/* ARGSUSED */
-void
+static void
if_hello_timer(int fd, short event, void *arg)
{
struct iface_af *ia = arg;
@@ -389,7 +396,7 @@ if_hello_timer(int fd, short event, void *arg)
if_start_hello_timer(ia);
}
-void
+static void
if_start_hello_timer(struct iface_af *ia)
{
struct timeval tv;
@@ -400,7 +407,7 @@ if_start_hello_timer(struct iface_af *ia)
fatal(__func__);
}
-void
+static void
if_stop_hello_timer(struct iface_af *ia)
{
if (evtimer_pending(&ia->hello_timer, NULL) &&
@@ -453,7 +460,7 @@ if_get_ipv4_addr(struct iface *iface)
return (INADDR_ANY);
}
-int
+static int
if_join_ipv4_group(struct iface *iface, struct in_addr *addr)
{
struct ip_mreq mreq;
@@ -473,7 +480,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;
@@ -494,7 +501,7 @@ if_leave_ipv4_group(struct iface *iface, struct in_addr *addr)
return (0);
}
-int
+static int
if_join_ipv6_group(struct iface *iface, struct in6_addr *addr)
{
struct ipv6_mreq mreq;
@@ -515,7 +522,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/ldpd/kroute.c b/usr.sbin/ldpd/kroute.c
index bf4adb43415..3c5bd14857e 100644
--- a/usr.sbin/ldpd/kroute.c
+++ b/usr.sbin/ldpd/kroute.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kroute.c,v 1.57 2016/05/23 18:58:48 renato Exp $ */
+/* $OpenBSD: kroute.c,v 1.58 2016/05/23 19:09:25 renato Exp $ */
/*
* Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
@@ -72,6 +72,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;
@@ -84,60 +86,60 @@ struct kif_node {
struct kif k;
struct kpw *kpw;
};
+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 ldpd_addr *, uint8_t);
-struct kroute_priority *kroute_find_prio(struct kroute_prefix *, uint8_t);
-struct kroute_node *kroute_find_gw(struct kroute_priority *,
- union ldpd_addr *);
-
-int kroute_insert(struct kroute *);
-int kroute_uninstall(struct kroute_node *);
-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_node *kif_update(unsigned short, int, struct if_data *,
+static struct kroute_prefix *kroute_find_prefix(int, union ldpd_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 ldpd_addr *);
+static int kroute_insert(struct kroute *);
+static int kroute_uninstall(struct kroute_node *);
+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_node *kif_update(unsigned short, int, struct if_data *,
struct sockaddr_dl *, int *);
+static struct kroute_priority *kroute_match(int, union ldpd_addr *);
+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(int, int, struct kroute *, int);
+static int send_rtmsg_v4(int fd, int, struct kroute *, int);
+static int send_rtmsg_v6(int fd, int, struct kroute *, int);
+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]);
+static int kmpw_install(const char *, struct kpw *);
+static int kmpw_uninstall(const char *);
-struct kroute_priority *kroute_match(int, union ldpd_addr *);
-
-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);
-int send_rtmsg_v4(int, int, struct kroute *, int);
-int send_rtmsg_v6(int, int, struct kroute *, int);
-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)
-
-RB_HEAD(kif_tree, kif_node) kit = RB_INITIALIZER(&kit);
-RB_PROTOTYPE(kif_tree, kif_node, entry, kif_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)
{
@@ -437,7 +439,7 @@ kr_change_egress_label(int af, int was_implicit)
}
/* ARGSUSED */
-void
+static void
kr_dispatch_msg(int fd, short event, void *bula)
{
if (dispatch_rtmsg() == -1)
@@ -508,7 +510,7 @@ kr_ifinfo(char *ifname, pid_t pid)
main_imsg_compose_ldpe(IMSG_CTL_END, pid, NULL, 0);
}
-void
+static void
kr_redist_remove(struct kroute *kr)
{
/* was the route redistributed? */
@@ -520,7 +522,7 @@ kr_redist_remove(struct kroute *kr)
main_imsg_compose_lde(IMSG_NETWORK_DEL, 0, kr, sizeof(*kr));
}
-int
+static int
kr_redist_eval(struct kroute *kr)
{
/* was the route redistributed? */
@@ -569,7 +571,7 @@ dont_redistribute:
return (0);
}
-void
+static void
kr_redistribute(struct kroute_prefix *kp)
{
struct kroute_priority *kprio;
@@ -587,7 +589,7 @@ kr_redistribute(struct kroute_prefix *kp)
}
/* rb-tree compare */
-int
+static __inline int
kroute_compare(struct kroute_prefix *a, struct kroute_prefix *b)
{
int addrcmp;
@@ -610,7 +612,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 ldpd_addr *prefix, uint8_t prefixlen)
{
struct kroute_prefix s;
@@ -622,7 +624,7 @@ kroute_find_prefix(int af, union ldpd_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;
@@ -638,7 +640,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 ldpd_addr *nh)
{
struct kroute_node *kn;
@@ -650,7 +652,7 @@ kroute_find_gw(struct kroute_priority *kprio, union ldpd_addr *nh)
return (NULL);
}
-int
+static int
kroute_insert(struct kroute *kr)
{
struct kroute_prefix *kp;
@@ -702,7 +704,7 @@ kroute_insert(struct kroute *kr)
return (0);
}
-int
+static int
kroute_uninstall(struct kroute_node *kn)
{
/* kill MPLS LSP if one was installed */
@@ -714,7 +716,7 @@ kroute_uninstall(struct kroute_node *kn)
return (0);
}
-int
+static int
kroute_remove(struct kroute *kr)
{
struct kroute_prefix *kp;
@@ -760,7 +762,7 @@ notfound:
return (-1);
}
-void
+static void
kroute_clear(void)
{
struct kroute_prefix *kp;
@@ -783,14 +785,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;
@@ -813,7 +815,7 @@ kif_findname(char *ifname)
return (NULL);
}
-struct kif_node *
+static struct kif_node *
kif_insert(unsigned short ifindex)
{
struct kif_node *kif;
@@ -830,7 +832,7 @@ kif_insert(unsigned short ifindex)
return (kif);
}
-int
+static int
kif_remove(struct kif_node *kif)
{
struct kif_addr *ka;
@@ -858,7 +860,7 @@ kif_clear(void)
kif_remove(kif);
}
-struct kif_node *
+static struct kif_node *
kif_update(unsigned short ifindex, int flags, struct if_data *ifd,
struct sockaddr_dl *sdl, int *link_old)
{
@@ -890,7 +892,7 @@ kif_update(unsigned short ifindex, int flags, struct if_data *ifd,
return (kif);
}
-struct kroute_priority *
+static struct kroute_priority *
kroute_match(int af, union ldpd_addr *key)
{
int i, maxprefixlen;
@@ -926,7 +928,7 @@ kroute_match(int af, union ldpd_addr *key)
}
/* misc */
-uint8_t
+static uint8_t
prefixlen_classful(in_addr_t ina)
{
/* it hurt to write this. */
@@ -946,7 +948,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;
@@ -961,7 +963,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)
{
@@ -992,7 +994,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)
{
@@ -1059,7 +1061,7 @@ if_newaddr(unsigned short ifindex, struct sockaddr *ifa, struct sockaddr *mask,
main_imsg_compose_ldpe(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)
{
@@ -1132,7 +1134,7 @@ if_deladdr(unsigned short ifindex, struct sockaddr *ifa, struct sockaddr *mask,
}
}
-void
+static void
if_announce(void *msg)
{
struct if_announcemsghdr *ifan;
@@ -1156,7 +1158,7 @@ if_announce(void *msg)
}
/* rtsock */
-int
+static int
send_rtmsg(int fd, int action, struct kroute *kr, int family)
{
switch (kr->af) {
@@ -1169,7 +1171,7 @@ send_rtmsg(int fd, int action, struct kroute *kr, int family)
}
}
-int
+static int
send_rtmsg_v4(int fd, int action, struct kroute *kr, int family)
{
struct iovec iov[5];
@@ -1303,13 +1305,13 @@ retry:
return (0);
}
-int
+static int
send_rtmsg_v6(int fd, int action, struct kroute *kr, int family)
{
return (0);
}
-int
+static int
fetchtable(void)
{
size_t len;
@@ -1345,7 +1347,7 @@ fetchtable(void)
return (rv);
}
-int
+static int
fetchifs(void)
{
size_t len;
@@ -1380,7 +1382,7 @@ fetchifs(void)
return (rv);
}
-int
+static int
dispatch_rtmsg(void)
{
char buf[RT_BUF_SIZE];
@@ -1401,7 +1403,7 @@ dispatch_rtmsg(void)
return (rtmsg_process(buf, n));
}
-int
+static int
rtmsg_process(char *buf, size_t len)
{
struct rt_msghdr *rtm;
@@ -1491,7 +1493,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;
@@ -1660,7 +1662,7 @@ kmpw_unset(struct kpw *kpw)
return (kmpw_uninstall(kif->k.ifname));
}
-int
+static int
kmpw_install(const char *ifname, struct kpw *kpw)
{
struct ifreq ifr;
@@ -1700,7 +1702,7 @@ kmpw_install(const char *ifname, struct kpw *kpw)
return (0);
}
-int
+static int
kmpw_uninstall(const char *ifname)
{
struct ifreq ifr;
diff --git a/usr.sbin/ldpd/l2vpn.c b/usr.sbin/ldpd/l2vpn.c
index a1328f4cb4b..d852877f960 100644
--- a/usr.sbin/ldpd/l2vpn.c
+++ b/usr.sbin/ldpd/l2vpn.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: l2vpn.c,v 1.14 2016/05/23 18:58:48 renato Exp $ */
+/* $OpenBSD: l2vpn.c,v 1.15 2016/05/23 19:09:25 renato Exp $ */
/*
* Copyright (c) 2015 Renato Westphal <renato@openbsd.org>
@@ -34,11 +34,7 @@
#include "control.h"
#include "log.h"
-RB_PROTOTYPE(fec_tree, fec, entry, fec_compare)
-extern struct fec_tree ft;
-
-extern struct ldpd_conf *ldeconf;
-extern struct ldpd_conf *leconf;
+static void l2vpn_pw_fec(struct l2vpn_pw *, struct fec *);
struct l2vpn *
l2vpn_new(const char *name)
@@ -177,7 +173,7 @@ l2vpn_pw_exit(struct l2vpn_pw *pw)
lde_kernel_remove(&fec, AF_INET, (union ldpd_addr*)&pw->lsr_id);
}
-void
+static void
l2vpn_pw_fec(struct l2vpn_pw *pw, struct fec *fec)
{
memset(fec, 0, sizeof(*fec));
diff --git a/usr.sbin/ldpd/labelmapping.c b/usr.sbin/ldpd/labelmapping.c
index ed98c95c4bf..3697f483466 100644
--- a/usr.sbin/ldpd/labelmapping.c
+++ b/usr.sbin/ldpd/labelmapping.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: labelmapping.c,v 1.43 2016/05/23 18:58:48 renato Exp $ */
+/* $OpenBSD: labelmapping.c,v 1.44 2016/05/23 19:09:25 renato Exp $ */
/*
* Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
@@ -38,11 +38,11 @@
#include "log.h"
#include "ldpe.h"
-void gen_label_tlv(struct ibuf *, uint32_t);
-void gen_reqid_tlv(struct ibuf *, uint32_t);
-
-int tlv_decode_label(struct nbr *, struct ldp_msg *, char *, uint16_t,
- uint32_t *);
+static void enqueue_pdu(struct nbr *, struct ibuf *, uint16_t);
+static void gen_label_tlv(struct ibuf *, uint32_t);
+static int tlv_decode_label(struct nbr *, struct ldp_msg *, char *,
+ uint16_t, uint32_t *);
+static void gen_reqid_tlv(struct ibuf *, uint32_t);
static void
enqueue_pdu(struct nbr *nbr, struct ibuf *buf, uint16_t size)
@@ -439,7 +439,7 @@ err:
}
/* Other TLV related functions */
-void
+static void
gen_label_tlv(struct ibuf *buf, uint32_t label)
{
struct label_tlv lt;
@@ -451,7 +451,7 @@ gen_label_tlv(struct ibuf *buf, uint32_t label)
ibuf_add(buf, &lt, sizeof(lt));
}
-int
+static int
tlv_decode_label(struct nbr *nbr, struct ldp_msg *lm, char *buf,
uint16_t len, uint32_t *label)
{
@@ -498,7 +498,7 @@ tlv_decode_label(struct nbr *nbr, struct ldp_msg *lm, char *buf,
return (sizeof(lt));
}
-void
+static void
gen_reqid_tlv(struct ibuf *buf, uint32_t reqid)
{
struct reqid_tlv rt;
diff --git a/usr.sbin/ldpd/lde.c b/usr.sbin/ldpd/lde.c
index 3e7afac9d89..71b711e62b2 100644
--- a/usr.sbin/ldpd/lde.c
+++ b/usr.sbin/ldpd/lde.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: lde.c,v 1.54 2016/05/23 18:58:48 renato Exp $ */
+/* $OpenBSD: lde.c,v 1.55 2016/05/23 19:09:25 renato Exp $ */
/*
* Copyright (c) 2004, 2005 Claudio Jeker <claudio@openbsd.org>
@@ -39,33 +39,32 @@
#include "log.h"
#include "lde.h"
-void lde_sig_handler(int sig, short, void *);
-void lde_shutdown(void);
-void lde_dispatch_imsg(int, short, void *);
-void lde_dispatch_parent(int, short, void *);
+static void lde_sig_handler(int sig, short, void *);
+static void lde_shutdown(void);
+static int lde_imsg_compose_parent(int, pid_t, void *, uint16_t);
+static void lde_dispatch_imsg(int, short, void *);
+static void lde_dispatch_parent(int, short, void *);
+static __inline int lde_nbr_compare(struct lde_nbr *,
+ struct lde_nbr *);
+static struct lde_nbr *lde_nbr_new(uint32_t, struct lde_nbr *);
+static void lde_nbr_del(struct lde_nbr *);
+static struct lde_nbr *lde_nbr_find(uint32_t);
+static void lde_nbr_clear(void);
+static void lde_map_free(void *);
+static int lde_address_add(struct lde_nbr *, struct lde_addr *);
+static int lde_address_del(struct lde_nbr *, struct lde_addr *);
+static void lde_address_list_free(struct lde_nbr *);
-struct lde_nbr *lde_nbr_find(uint32_t);
-struct lde_nbr *lde_nbr_new(uint32_t, struct lde_nbr *);
-void lde_nbr_del(struct lde_nbr *);
-void lde_nbr_clear(void);
-
-void lde_map_free(void *);
-void lde_address_list_free(struct lde_nbr *);
-
-struct ldpd_conf *ldeconf = NULL, *nconf = NULL;
-struct imsgev *iev_ldpe;
-struct imsgev *iev_main;
-
-static __inline int lde_nbr_compare(struct lde_nbr *, struct lde_nbr *);
-
-RB_HEAD(nbr_tree, lde_nbr);
-RB_PROTOTYPE(nbr_tree, lde_nbr, entry, lde_nbr_compare)
RB_GENERATE(nbr_tree, lde_nbr, entry, lde_nbr_compare)
-struct nbr_tree lde_nbrs = RB_INITIALIZER(&lde_nbrs);
+struct ldpd_conf *ldeconf;
+struct nbr_tree lde_nbrs = RB_INITIALIZER(&lde_nbrs);
+
+static struct imsgev *iev_ldpe;
+static struct imsgev *iev_main;
/* ARGSUSED */
-void
+static void
lde_sig_handler(int sig, short event, void *arg)
{
/*
@@ -178,7 +177,7 @@ lde(struct ldpd_conf *xconf, int pipe_parent2lde[2], int pipe_ldpe2lde[2],
return (0);
}
-void
+static void
lde_shutdown(void)
{
lde_gc_stop_timer();
@@ -197,7 +196,7 @@ lde_shutdown(void)
}
/* imesg */
-int
+static int
lde_imsg_compose_parent(int type, pid_t pid, void *data, uint16_t datalen)
{
return (imsg_compose_event(iev_main, type, 0, pid, -1, data, datalen));
@@ -212,7 +211,7 @@ lde_imsg_compose_ldpe(int type, uint32_t peerid, pid_t pid, void *data,
}
/* ARGSUSED */
-void
+static void
lde_dispatch_imsg(int fd, short event, void *bula)
{
struct imsgev *iev = bula;
@@ -402,9 +401,10 @@ lde_dispatch_imsg(int fd, short event, void *bula)
}
/* ARGSUSED */
-void
+static void
lde_dispatch_parent(int fd, short event, void *bula)
{
+ static struct ldpd_conf *nconf;
struct iface *niface;
struct tnbr *ntnbr;
struct nbr_params *nnbrp;
@@ -947,7 +947,7 @@ lde_nbr_compare(struct lde_nbr *a, struct lde_nbr *b)
return (a->peerid - b->peerid);
}
-struct lde_nbr *
+static struct lde_nbr *
lde_nbr_new(uint32_t peerid, struct lde_nbr *new)
{
struct lde_nbr *ln;
@@ -973,7 +973,7 @@ lde_nbr_new(uint32_t peerid, struct lde_nbr *new)
return (ln);
}
-void
+static void
lde_nbr_del(struct lde_nbr *ln)
{
struct fec *f;
@@ -1025,7 +1025,7 @@ lde_nbr_del(struct lde_nbr *ln)
free(ln);
}
-struct lde_nbr *
+static struct lde_nbr *
lde_nbr_find(uint32_t peerid)
{
struct lde_nbr ln;
@@ -1059,7 +1059,7 @@ lde_nbr_find_by_addr(int af, union ldpd_addr *addr)
return (NULL);
}
-void
+static void
lde_nbr_clear(void)
{
struct lde_nbr *ln;
@@ -1107,7 +1107,7 @@ lde_map_del(struct lde_nbr *ln, struct lde_map *me, int sent)
lde_map_free(me);
}
-void
+static void
lde_map_free(void *ptr)
{
struct lde_map *map = ptr;
@@ -1223,7 +1223,7 @@ lde_change_egress_label(int af, int was_implicit)
}
}
-int
+static int
lde_address_add(struct lde_nbr *ln, struct lde_addr *lde_addr)
{
struct lde_addr *new;
@@ -1241,7 +1241,7 @@ lde_address_add(struct lde_nbr *ln, struct lde_addr *lde_addr)
return (0);
}
-int
+static int
lde_address_del(struct lde_nbr *ln, struct lde_addr *lde_addr)
{
lde_addr = lde_address_find(ln, lde_addr->af, &lde_addr->addr);
@@ -1267,7 +1267,7 @@ lde_address_find(struct lde_nbr *ln, int af, union ldpd_addr *addr)
return (NULL);
}
-void
+static void
lde_address_list_free(struct lde_nbr *ln)
{
struct lde_addr *lde_addr;
diff --git a/usr.sbin/ldpd/lde.h b/usr.sbin/ldpd/lde.h
index 92d9ab936c8..463f2255ed4 100644
--- a/usr.sbin/ldpd/lde.h
+++ b/usr.sbin/ldpd/lde.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: lde.h,v 1.35 2016/05/23 18:58:48 renato Exp $ */
+/* $OpenBSD: lde.h,v 1.36 2016/05/23 19:09:25 renato Exp $ */
/*
* Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org>
@@ -26,8 +26,6 @@
#include <event.h>
#include <limits.h>
-RB_HEAD(fec_tree, fec);
-
enum fec_type {
FEC_TYPE_IPV4,
FEC_TYPE_IPV6,
@@ -53,8 +51,8 @@ struct fec {
} pwid;
} u;
};
+RB_HEAD(fec_tree, fec);
RB_PROTOTYPE(fec_tree, fec, entry, fec_compare)
-extern struct fec_tree ft;
/* request entries */
struct lde_req {
@@ -97,6 +95,8 @@ struct lde_nbr {
struct fec_tree sent_wdraw;
TAILQ_HEAD(, lde_addr) addr_list;
};
+RB_HEAD(nbr_tree, lde_nbr);
+RB_PROTOTYPE(nbr_tree, lde_nbr, entry, lde_nbr_compare)
struct fec_nh {
LIST_ENTRY(fec_nh) entry;
@@ -116,47 +116,50 @@ struct fec_node {
void *data; /* fec specific data */
};
+#define LDE_GC_INTERVAL 300
+
+extern struct ldpd_conf *ldeconf;
+extern struct fec_tree ft;
+extern struct nbr_tree lde_nbrs;
+extern struct event gc_timer;
+
/* lde.c */
-pid_t lde(struct ldpd_conf *, int [2], int [2], int [2]);
-int lde_imsg_compose_parent(int, pid_t, void *, uint16_t);
-int lde_imsg_compose_ldpe(int, uint32_t, pid_t, void *, uint16_t);
-uint32_t lde_assign_label(void);
-void lde_fec2map(struct fec *, struct map *);
-void lde_map2fec(struct map *, struct in_addr, struct fec *);
-
-void lde_send_change_klabel(struct fec_node *, struct fec_nh *);
-void lde_send_delete_klabel(struct fec_node *, struct fec_nh *);
-void lde_send_labelmapping(struct lde_nbr *, struct fec_node *, int);
-void lde_send_labelwithdraw(struct lde_nbr *, struct fec_node *, uint32_t);
-void lde_send_labelwithdraw_all(struct fec_node *, uint32_t);
-void lde_send_labelrelease(struct lde_nbr *, struct fec_node *, uint32_t);
-void lde_send_notification(uint32_t, uint32_t, uint32_t, uint16_t);
+pid_t lde(struct ldpd_conf *, int [2], int [2], int [2]);
+int lde_imsg_compose_ldpe(int, uint32_t, pid_t, void *, uint16_t);
+uint32_t lde_assign_label(void);
+void lde_send_change_klabel(struct fec_node *, struct fec_nh *);
+void lde_send_delete_klabel(struct fec_node *, struct fec_nh *);
+void lde_fec2map(struct fec *, struct map *);
+void lde_map2fec(struct map *, struct in_addr, struct fec *);
+void lde_send_labelmapping(struct lde_nbr *, struct fec_node *,
+ int);
+void lde_send_labelwithdraw(struct lde_nbr *, struct fec_node *,
+ uint32_t);
+void lde_send_labelwithdraw_all(struct fec_node *, uint32_t);
+void lde_send_labelrelease(struct lde_nbr *, struct fec_node *,
+ uint32_t);
+void lde_send_notification(uint32_t, uint32_t, uint32_t, uint16_t);
struct lde_nbr *lde_nbr_find_by_lsrid(struct in_addr);
struct lde_nbr *lde_nbr_find_by_addr(int, union ldpd_addr *);
-struct lde_map *lde_map_add(struct lde_nbr *, struct fec_node *, int);
-void lde_map_del(struct lde_nbr *, struct lde_map *, int);
-struct lde_req *lde_req_add(struct lde_nbr *, struct fec *, int);
-void lde_req_del(struct lde_nbr *, struct lde_req *, int);
+struct lde_map *lde_map_add(struct lde_nbr *, struct fec_node *, int);
+void lde_map_del(struct lde_nbr *, struct lde_map *, int);
+struct lde_req *lde_req_add(struct lde_nbr *, struct fec *, int);
+void lde_req_del(struct lde_nbr *, struct lde_req *, int);
struct lde_wdraw *lde_wdraw_add(struct lde_nbr *, struct fec_node *);
-void lde_wdraw_del(struct lde_nbr *, struct lde_wdraw *);
-void lde_change_egress_label(int, int);
-
-int lde_address_add(struct lde_nbr *, struct lde_addr *);
-struct lde_addr *lde_address_find(struct lde_nbr *, int,
- union ldpd_addr *);
-int lde_address_del(struct lde_nbr *, struct lde_addr *);
+void lde_wdraw_del(struct lde_nbr *, struct lde_wdraw *);
+void lde_change_egress_label(int, int);
+struct lde_addr *lde_address_find(struct lde_nbr *, int,
+ union ldpd_addr *);
/* lde_lib.c */
void fec_init(struct fec_tree *);
+struct fec *fec_find(struct fec_tree *, struct fec *);
int fec_insert(struct fec_tree *, struct fec *);
int fec_remove(struct fec_tree *, struct fec *);
-struct fec *fec_find(struct fec_tree *, struct fec *);
void fec_clear(struct fec_tree *, void (*)(void *));
-
void rt_dump(pid_t);
void fec_snap(struct lde_nbr *);
void fec_tree_clear(void);
-
struct fec_nh *fec_nh_find(struct fec_node *, int, union ldpd_addr *);
uint32_t egress_label(enum fec_type);
void lde_kernel_insert(struct fec *, int, union ldpd_addr *, int, void *);
@@ -167,14 +170,10 @@ void lde_check_release(struct map *, struct lde_nbr *);
void lde_check_release_wcard(struct map *, struct lde_nbr *);
void lde_check_withdraw(struct map *, struct lde_nbr *);
void lde_check_withdraw_wcard(struct map *, struct lde_nbr *);
-void lde_label_list_free(struct lde_nbr *);
void lde_gc_timer(int, short, void *);
void lde_gc_start_timer(void);
void lde_gc_stop_timer(void);
-#define LDE_GC_INTERVAL 300
-extern struct event gc_timer;
-
/* l2vpn.c */
struct l2vpn *l2vpn_new(const char *);
struct l2vpn *l2vpn_find(struct ldpd_conf *, const char *);
@@ -186,7 +185,6 @@ struct l2vpn_pw *l2vpn_pw_new(struct l2vpn *, struct kif *);
struct l2vpn_pw *l2vpn_pw_find(struct l2vpn *, unsigned int);
void l2vpn_pw_init(struct l2vpn_pw *);
void l2vpn_pw_exit(struct l2vpn_pw *);
-void l2vpn_pw_fec(struct l2vpn_pw *, struct fec *);
void l2vpn_pw_reset(struct l2vpn_pw *);
int l2vpn_pw_ok(struct l2vpn_pw *, struct fec_nh *);
int l2vpn_pw_negotiate(struct lde_nbr *, struct fec_node *,
diff --git a/usr.sbin/ldpd/lde_lib.c b/usr.sbin/ldpd/lde_lib.c
index f8099d086b9..ab0a8797506 100644
--- a/usr.sbin/ldpd/lde_lib.c
+++ b/usr.sbin/ldpd/lde_lib.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: lde_lib.c,v 1.55 2016/05/23 18:58:48 renato Exp $ */
+/* $OpenBSD: lde_lib.c,v 1.56 2016/05/23 19:09:25 renato Exp $ */
/*
* Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
@@ -38,23 +38,18 @@
#include "log.h"
#include "lde.h"
-static int fec_compare(struct fec *, struct fec *);
-
-void fec_free(void *);
-struct fec_node *fec_add(struct fec *fec);
-struct fec_nh *fec_nh_add(struct fec_node *, int, union ldpd_addr *);
-void fec_nh_del(struct fec_nh *);
-int lde_nbr_is_nexthop(struct fec_node *, struct lde_nbr *);
+static __inline int fec_compare(struct fec *, struct fec *);
+static int lde_nbr_is_nexthop(struct fec_node *,
+ struct lde_nbr *);
+static void fec_free(void *);
+static struct fec_node *fec_add(struct fec *fec);
+static struct fec_nh *fec_nh_add(struct fec_node *, int, union ldpd_addr *);
+static void fec_nh_del(struct fec_nh *);
RB_GENERATE(fec_tree, fec, entry, fec_compare)
-extern struct nbr_tree lde_nbrs;
-RB_PROTOTYPE(nbr_tree, lde_nbr, entry, lde_nbr_compare)
-
-extern struct ldpd_conf *ldeconf;
-
-struct fec_tree ft = RB_INITIALIZER(&ft);
-struct event gc_timer;
+struct fec_tree ft = RB_INITIALIZER(&ft);
+struct event gc_timer;
/* FEC tree functions */
void
@@ -63,7 +58,7 @@ fec_init(struct fec_tree *fh)
RB_INIT(fh);
}
-static int
+static __inline int
fec_compare(struct fec *a, struct fec *b)
{
if (a->type < b->type)
@@ -153,7 +148,7 @@ fec_clear(struct fec_tree *fh, void (*free_cb)(void *))
}
/* routing table functions */
-int
+static int
lde_nbr_is_nexthop(struct fec_node *fn, struct lde_nbr *ln)
{
struct fec_nh *fnh;
@@ -231,7 +226,7 @@ fec_snap(struct lde_nbr *ln)
lde_imsg_compose_ldpe(IMSG_MAPPING_ADD_END, ln->peerid, 0, NULL, 0);
}
-void
+static void
fec_free(void *arg)
{
struct fec_node *fn = arg;
@@ -255,7 +250,7 @@ fec_tree_clear(void)
fec_clear(&ft, fec_free);
}
-struct fec_node *
+static struct fec_node *
fec_add(struct fec *fec)
{
struct fec_node *fn;
@@ -290,7 +285,7 @@ fec_nh_find(struct fec_node *fn, int af, union ldpd_addr *nexthop)
return (NULL);
}
-struct fec_nh *
+static struct fec_nh *
fec_nh_add(struct fec_node *fn, int af, union ldpd_addr *nexthop)
{
struct fec_nh *fnh;
@@ -307,7 +302,7 @@ fec_nh_add(struct fec_node *fn, int af, union ldpd_addr *nexthop)
return (fnh);
}
-void
+static void
fec_nh_del(struct fec_nh *fnh)
{
LIST_REMOVE(fnh, entry);
diff --git a/usr.sbin/ldpd/ldpd.c b/usr.sbin/ldpd/ldpd.c
index 8d464b17c87..d4509c8274f 100644
--- a/usr.sbin/ldpd/ldpd.c
+++ b/usr.sbin/ldpd/ldpd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ldpd.c,v 1.44 2016/05/23 18:58:48 renato Exp $ */
+/* $OpenBSD: ldpd.c,v 1.45 2016/05/23 19:09:25 renato Exp $ */
/*
* Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org>
@@ -46,42 +46,42 @@
#include "log.h"
#include "lde.h"
-void main_sig_handler(int, short, void *);
-__dead void usage(void);
-void ldpd_shutdown(void);
-int check_child(pid_t, const char *);
-
-void main_dispatch_ldpe(int, short, void *);
-void main_dispatch_lde(int, short, void *);
-int main_imsg_compose_both(enum imsg_type, void *, uint16_t);
-void main_imsg_send_net_sockets(int);
-void main_imsg_send_net_socket(int, enum socket_type);
-int ldp_reload(void);
-void merge_global(struct ldpd_conf *, struct ldpd_conf *);
-void merge_af(int, struct ldpd_af_conf *, struct ldpd_af_conf *);
-void merge_ifaces(struct ldpd_conf *, struct ldpd_conf *);
-void merge_iface_af(struct iface_af *, struct iface_af *);
-void merge_tnbrs(struct ldpd_conf *, struct ldpd_conf *);
-void merge_nbrps(struct ldpd_conf *, struct ldpd_conf *);
-void merge_l2vpns(struct ldpd_conf *, struct ldpd_conf *);
-void merge_l2vpn(struct ldpd_conf *, struct l2vpn *, struct l2vpn *);
-
-int pipe_parent2ldpe[2];
-int pipe_parent2lde[2];
-int pipe_ldpe2lde[2];
-
-struct ldpd_conf *ldpd_conf = NULL;
-struct imsgev *iev_ldpe;
-struct imsgev *iev_lde;
-char *conffile;
-
-pid_t ldpe_pid = 0;
-pid_t lde_pid = 0;
-
-extern struct ldpd_conf *leconf;
+static void main_sig_handler(int, short, void *);
+static __dead void usage(void);
+static void ldpd_shutdown(void);
+static int check_child(pid_t, const char *);
+static void main_dispatch_ldpe(int, short, void *);
+static void main_dispatch_lde(int, short, void *);
+static int main_imsg_compose_both(enum imsg_type, void *,
+ uint16_t);
+static void main_imsg_send_net_sockets(int);
+static void main_imsg_send_net_socket(int, enum socket_type);
+static int ldp_reload(void);
+static void merge_global(struct ldpd_conf *, struct ldpd_conf *);
+static void merge_af(int, struct ldpd_af_conf *,
+ struct ldpd_af_conf *);
+static void merge_ifaces(struct ldpd_conf *, struct ldpd_conf *);
+static void merge_iface_af(struct iface_af *, struct iface_af *);
+static void merge_tnbrs(struct ldpd_conf *, struct ldpd_conf *);
+static void merge_nbrps(struct ldpd_conf *, struct ldpd_conf *);
+static void merge_l2vpns(struct ldpd_conf *, struct ldpd_conf *);
+static void merge_l2vpn(struct ldpd_conf *, struct l2vpn *,
+ struct l2vpn *);
+
+struct ldpd_global global;
+struct ldpd_conf *ldpd_conf;
+
+static char *conffile;
+static int pipe_parent2ldpe[2];
+static int pipe_parent2lde[2];
+static int pipe_ldpe2lde[2];
+static struct imsgev *iev_ldpe;
+static struct imsgev *iev_lde;
+static pid_t ldpe_pid;
+static pid_t lde_pid;
/* ARGSUSED */
-void
+static void
main_sig_handler(int sig, short event, void *arg)
{
/*
@@ -119,7 +119,7 @@ main_sig_handler(int sig, short event, void *arg)
}
}
-__dead void
+static __dead void
usage(void)
{
extern char *__progname;
@@ -129,8 +129,6 @@ usage(void)
exit(1);
}
-struct ldpd_global global;
-
int
main(int argc, char *argv[])
{
@@ -278,7 +276,7 @@ main(int argc, char *argv[])
return (0);
}
-void
+static void
ldpd_shutdown(void)
{
pid_t pid;
@@ -308,7 +306,7 @@ ldpd_shutdown(void)
exit(0);
}
-int
+static int
check_child(pid_t pid, const char *pname)
{
int status;
@@ -330,7 +328,7 @@ check_child(pid_t pid, const char *pname)
/* imsg handling */
/* ARGSUSED */
-void
+static void
main_dispatch_ldpe(int fd, short event, void *bula)
{
struct imsgev *iev = bula;
@@ -411,7 +409,7 @@ main_dispatch_ldpe(int fd, short event, void *bula)
}
/* ARGSUSED */
-void
+static void
main_dispatch_lde(int fd, short event, void *bula)
{
struct imsgev *iev = bula;
@@ -501,7 +499,7 @@ main_imsg_compose_lde(int type, pid_t pid, void *data, uint16_t datalen)
imsg_compose_event(iev_lde, type, 0, pid, -1, data, datalen);
}
-int
+static int
main_imsg_compose_both(enum imsg_type type, void *buf, uint16_t len)
{
if (imsg_compose_event(iev_ldpe, type, 0, 0, -1, buf, len) == -1)
@@ -566,7 +564,7 @@ evbuf_clear(struct evbuf *eb)
eb->wbuf.fd = -1;
}
-void
+static void
main_imsg_send_net_sockets(int af)
{
main_imsg_send_net_socket(af, LDP_SOCKET_DISC);
@@ -575,7 +573,7 @@ main_imsg_send_net_sockets(int af)
imsg_compose_event(iev_ldpe, IMSG_SETUP_SOCKETS, af, 0, -1, NULL, 0);
}
-void
+static void
main_imsg_send_net_socket(int af, enum socket_type type)
{
int fd;
@@ -624,7 +622,7 @@ ldp_is_dual_stack(struct ldpd_conf *xconf)
(xconf->ipv6.flags & F_LDPD_AF_ENABLED));
}
-int
+static int
ldp_reload(void)
{
struct iface *iface;
@@ -698,7 +696,7 @@ merge_config(struct ldpd_conf *conf, struct ldpd_conf *xconf)
free(xconf);
}
-void
+static void
merge_global(struct ldpd_conf *conf, struct ldpd_conf *xconf)
{
/* change of router-id requires resetting all neighborships */
@@ -730,7 +728,7 @@ merge_global(struct ldpd_conf *conf, struct ldpd_conf *xconf)
conf->flags = xconf->flags;
}
-void
+static void
merge_af(int af, struct ldpd_af_conf *af_conf, struct ldpd_af_conf *xa)
{
struct nbr *nbr;
@@ -794,7 +792,7 @@ merge_af(int af, struct ldpd_af_conf *af_conf, struct ldpd_af_conf *xa)
}
}
-void
+static void
merge_ifaces(struct ldpd_conf *conf, struct ldpd_conf *xconf)
{
struct iface *iface, *itmp, *xi;
@@ -829,7 +827,7 @@ merge_ifaces(struct ldpd_conf *conf, struct ldpd_conf *xconf)
}
}
-void
+static void
merge_iface_af(struct iface_af *ia, struct iface_af *xi)
{
if (ia->enabled != xi->enabled) {
@@ -841,7 +839,7 @@ merge_iface_af(struct iface_af *ia, struct iface_af *xi)
ia->hello_interval = xi->hello_interval;
}
-void
+static void
merge_tnbrs(struct ldpd_conf *conf, struct ldpd_conf *xconf)
{
struct tnbr *tnbr, *ttmp, *xt;
@@ -882,7 +880,7 @@ merge_tnbrs(struct ldpd_conf *conf, struct ldpd_conf *xconf)
}
}
-void
+static void
merge_nbrps(struct ldpd_conf *conf, struct ldpd_conf *xconf)
{
struct nbr_params *nbrp, *ntmp, *xn;
@@ -949,7 +947,7 @@ merge_nbrps(struct ldpd_conf *conf, struct ldpd_conf *xconf)
}
}
-void
+static void
merge_l2vpns(struct ldpd_conf *conf, struct ldpd_conf *xconf)
{
struct l2vpn *l2vpn, *ltmp, *xl;
@@ -999,7 +997,7 @@ merge_l2vpns(struct ldpd_conf *conf, struct ldpd_conf *xconf)
}
}
-void
+static void
merge_l2vpn(struct ldpd_conf *xconf, struct l2vpn *l2vpn, struct l2vpn *xl)
{
struct l2vpn_if *lif, *ftmp, *xf;
diff --git a/usr.sbin/ldpd/ldpd.h b/usr.sbin/ldpd/ldpd.h
index ddd1ddcbd0c..757191f6a9c 100644
--- a/usr.sbin/ldpd/ldpd.h
+++ b/usr.sbin/ldpd/ldpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ldpd.h,v 1.71 2016/05/23 18:58:48 renato Exp $ */
+/* $OpenBSD: ldpd.h,v 1.72 2016/05/23 19:09:25 renato Exp $ */
/*
* Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
@@ -402,8 +402,6 @@ struct ldpd_global {
TAILQ_HEAD(, pending_conn) pending_conns;
};
-extern struct ldpd_global global;
-
/* kroute */
struct kroute {
int af;
@@ -505,35 +503,29 @@ struct ctl_pw {
uint32_t status;
};
+extern struct ldpd_conf *ldpd_conf;
+extern struct ldpd_global global;
+
/* parse.y */
struct ldpd_conf *parse_config(char *);
int cmdline_symset(char *);
/* kroute.c */
int kif_init(void);
-void kif_redistribute(const char *);
int kr_init(int);
+void kif_redistribute(const char *);
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_change_egress_label(int, int);
-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 kif_clear(void);
int kmpw_set(struct kpw *);
int kmpw_unset(struct kpw *);
-int kmpw_install(const char *, struct kpw *);
-int kmpw_uninstall(const char *);
-
-/* log.h */
-const char *nbr_state_name(int);
-const char *if_state_name(int);
-const char *if_type_name(enum iface_type);
-const char *notification_name(uint32_t);
/* util.c */
uint8_t mask2prefixlen(in_addr_t);
@@ -558,21 +550,20 @@ struct sockaddr *addr2sa(int af, union ldpd_addr *, uint16_t);
void sa2addr(struct sockaddr *, int *, union ldpd_addr *);
/* ldpd.c */
-void main_imsg_compose_ldpe(int, pid_t, void *, uint16_t);
-void main_imsg_compose_lde(int, pid_t, void *, uint16_t);
-void merge_config(struct ldpd_conf *, struct ldpd_conf *);
-void config_clear(struct ldpd_conf *);
-int imsg_compose_event(struct imsgev *, uint16_t, uint32_t, pid_t,
- int, void *, uint16_t);
-void imsg_event_add(struct imsgev *);
-void evbuf_enqueue(struct evbuf *, struct ibuf *);
-void evbuf_event_add(struct evbuf *);
-void evbuf_init(struct evbuf *, int, void (*)(int, short, void *), void *);
-void evbuf_clear(struct evbuf *);
-
+void main_imsg_compose_ldpe(int, pid_t, void *, uint16_t);
+void main_imsg_compose_lde(int, pid_t, void *, uint16_t);
+void imsg_event_add(struct imsgev *);
+int imsg_compose_event(struct imsgev *, uint16_t, uint32_t, pid_t,
+ int, void *, uint16_t);
+void evbuf_enqueue(struct evbuf *, struct ibuf *);
+void evbuf_event_add(struct evbuf *);
+void evbuf_init(struct evbuf *, int, void (*)(int, short, void *), void *);
+void evbuf_clear(struct evbuf *);
struct ldpd_af_conf *ldp_af_conf_get(struct ldpd_conf *, int);
struct ldpd_af_global *ldp_af_global_get(struct ldpd_global *, int);
int ldp_is_dual_stack(struct ldpd_conf *);
+void merge_config(struct ldpd_conf *, struct ldpd_conf *);
+void config_clear(struct ldpd_conf *);
/* socket.c */
int ldp_create_socket(int, enum socket_type);
diff --git a/usr.sbin/ldpd/ldpe.c b/usr.sbin/ldpd/ldpe.c
index a269298d55d..93050d50224 100644
--- a/usr.sbin/ldpd/ldpe.c
+++ b/usr.sbin/ldpd/ldpe.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ldpe.c,v 1.57 2016/05/23 18:58:48 renato Exp $ */
+/* $OpenBSD: ldpe.c,v 1.58 2016/05/23 19:09:25 renato Exp $ */
/*
* Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org>
@@ -44,17 +44,24 @@
#include "control.h"
#include "log.h"
-void ldpe_sig_handler(int, short, void *);
-void ldpe_shutdown(void);
+static void ldpe_sig_handler(int, short, void *);
+static void ldpe_shutdown(void);
+static void ldpe_dispatch_main(int, short, void *);
+static void ldpe_dispatch_lde(int, short, void *);
+static void ldpe_dispatch_pfkey(int, short, void *);
+static void ldpe_setup_sockets(int, int, int, int);
+static void ldpe_close_sockets(int);
+static void ldpe_iface_af_ctl(struct ctl_conn *, int, unsigned int);
-struct ldpd_conf *leconf = NULL, *nconf;
-struct imsgev *iev_main;
-struct imsgev *iev_lde;
-struct event pfkey_ev;
+struct ldpd_conf *leconf;
struct ldpd_sysdep sysdep;
+static struct imsgev *iev_main;
+static struct imsgev *iev_lde;
+static struct event pfkey_ev;
+
/* ARGSUSED */
-void
+static void
ldpe_sig_handler(int sig, short event, void *bula)
{
switch (sig) {
@@ -102,7 +109,7 @@ ldpe(struct ldpd_conf *xconf, int pipe_parent2ldpe[2], int pipe_ldpe2lde[2],
fatal("inet_pton");
if (inet_pton(AF_INET6, AllRouters_v6, &global.mcast_addr_v6) != 1)
fatal("inet_pton");
- global.pfkeysock = pfkey_init(&sysdep);
+ global.pfkeysock = pfkey_init();
if ((pw = getpwnam(LDPD_USER)) == NULL)
fatal("getpwnam");
@@ -188,7 +195,7 @@ ldpe(struct ldpd_conf *xconf, int pipe_parent2ldpe[2], int pipe_ldpe2lde[2],
return (0);
}
-void
+static void
ldpe_shutdown(void)
{
struct if_addr *if_addr;
@@ -241,9 +248,10 @@ ldpe_imsg_compose_lde(int type, uint32_t peerid, pid_t pid, void *data,
}
/* ARGSUSED */
-void
+static void
ldpe_dispatch_main(int fd, short event, void *bula)
{
+ static struct ldpd_conf *nconf;
struct iface *niface;
struct tnbr *ntnbr;
struct nbr_params *nnbrp;
@@ -450,7 +458,7 @@ ldpe_dispatch_main(int fd, short event, void *bula)
}
/* ARGSUSED */
-void
+static void
ldpe_dispatch_lde(int fd, short event, void *bula)
{
struct imsgev *iev = bula;
@@ -584,7 +592,7 @@ ldpe_dispatch_lde(int fd, short event, void *bula)
}
/* ARGSUSED */
-void
+static void
ldpe_dispatch_pfkey(int fd, short event, void *bula)
{
if (event & EV_READ) {
@@ -594,8 +602,9 @@ ldpe_dispatch_pfkey(int fd, short event, void *bula)
}
}
-void
-ldpe_setup_sockets(int af, int disc_socket, int edisc_socket, int session_socket)
+static void
+ldpe_setup_sockets(int af, int disc_socket, int edisc_socket,
+ int session_socket)
{
struct ldpd_af_global *af_global;
@@ -618,7 +627,7 @@ ldpe_setup_sockets(int af, int disc_socket, int edisc_socket, int session_socket
accept_add(af_global->ldp_session_socket, session_accept, NULL);
}
-void
+static void
ldpe_close_sockets(int af)
{
struct ldpd_af_global *af_global;
@@ -698,7 +707,7 @@ ldpe_stop_init_backoff(int af)
}
}
-void
+static void
ldpe_iface_af_ctl(struct ctl_conn *c, int af, unsigned int idx)
{
struct iface *iface;
diff --git a/usr.sbin/ldpd/ldpe.h b/usr.sbin/ldpd/ldpe.h
index 8caea614685..83248b5f78f 100644
--- a/usr.sbin/ldpd/ldpe.h
+++ b/usr.sbin/ldpd/ldpe.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ldpe.h,v 1.52 2016/05/23 18:58:48 renato Exp $ */
+/* $OpenBSD: ldpe.h,v 1.53 2016/05/23 19:09:25 renato Exp $ */
/*
* Copyright (c) 2004, 2005, 2008 Esben Norby <norby@openbsd.org>
@@ -97,6 +97,12 @@ struct nbr {
char md5key[TCP_MD5_KEY_LEN];
} auth;
};
+RB_HEAD(nbr_id_head, nbr);
+RB_PROTOTYPE(nbr_id_head, nbr, id_tree, nbr_id_compare)
+RB_HEAD(nbr_addr_head, nbr);
+RB_PROTOTYPE(nbr_addr_head, nbr, addr_tree, nbr_addr_compare)
+RB_HEAD(nbr_pid_head, nbr);
+RB_PROTOTYPE(nbr_pid_head, nbr, pid_tree, nbr_pid_compare)
struct pending_conn {
TAILQ_ENTRY(pending_conn) entry;
@@ -117,6 +123,12 @@ struct ldpd_sysdep {
uint8_t no_md5sig;
};
+extern struct ldpd_conf *leconf;
+extern struct ldpd_sysdep sysdep;
+extern struct nbr_id_head nbrs_by_id;
+extern struct nbr_addr_head nbrs_by_addr;
+extern struct nbr_pid_head nbrs_by_pid;
+
/* accept.c */
void accept_init(void);
int accept_add(int, void (*)(int, short, void *), void *);
@@ -138,10 +150,10 @@ void send_keepalive(struct nbr *);
int recv_keepalive(struct nbr *, char *, uint16_t);
/* notification.c */
-void send_notification_nbr(struct nbr *, uint32_t, uint32_t, uint32_t);
+void send_notification_full(struct tcp_conn *, struct notify_msg *);
void send_notification(uint32_t, struct tcp_conn *, uint32_t,
uint32_t);
-void send_notification_full(struct tcp_conn *, struct notify_msg *);
+void send_notification_nbr(struct nbr *, uint32_t, uint32_t, uint32_t);
int recv_notification(struct nbr *, char *, uint16_t);
/* address.c */
@@ -152,8 +164,8 @@ int recv_address(struct nbr *, char *, uint16_t);
#define PREFIX_SIZE(x) (((x) + 7) / 8)
void send_labelmessage(struct nbr *, uint16_t, struct mapping_head *);
int recv_labelmessage(struct nbr *, char *, uint16_t, uint16_t);
-void gen_fec_tlv(struct ibuf *, struct map *);
void gen_pw_status_tlv(struct ibuf *, uint32_t);
+void gen_fec_tlv(struct ibuf *, struct map *);
int tlv_decode_fec_elm(struct nbr *, struct ldp_msg *, char *,
uint16_t, struct map *);
@@ -163,17 +175,11 @@ int ldpe_imsg_compose_parent(int, pid_t, void *,
uint16_t);
int ldpe_imsg_compose_lde(int, uint32_t, pid_t, void *,
uint16_t);
-void ldpe_dispatch_main(int, short, void *);
-void ldpe_dispatch_lde(int, short, void *);
-void ldpe_dispatch_pfkey(int, short, void *);
-void ldpe_setup_sockets(int, int, int, int);
-void ldpe_close_sockets(int);
void ldpe_reset_nbrs(int);
void ldpe_reset_ds_nbrs(void);
void ldpe_remove_dynamic_tnbrs(int);
void ldpe_stop_init_backoff(int);
struct ctl_conn;
-void ldpe_iface_af_ctl(struct ctl_conn *, int, unsigned int);
void ldpe_iface_ctl(struct ctl_conn *, unsigned int);
void ldpe_adj_ctl(struct ctl_conn *);
void ldpe_nbr_ctl(struct ctl_conn *);
@@ -181,104 +187,68 @@ void mapping_list_add(struct mapping_head *, struct map *);
void mapping_list_clr(struct mapping_head *);
/* interface.c */
-int if_start(struct iface *, int);
-int if_reset(struct iface *, int);
-void if_update_af(struct iface_af *, int);
-void if_update(struct iface *, int);
-void if_update_all(int);
-
struct iface *if_new(struct kif *);
void if_del(struct iface *);
struct iface *if_lookup(struct ldpd_conf *, unsigned short);
struct iface_af *iface_af_get(struct iface *, int);
-struct if_addr *if_addr_new(struct kaddr *);
-struct if_addr *if_addr_lookup(struct if_addr_head *, struct kaddr *);
void if_addr_add(struct kaddr *);
void if_addr_del(struct kaddr *);
-
-struct ctl_iface *if_to_ctl(struct iface_af *);
-
+void if_update(struct iface *, int);
+void if_update_all(int);
+struct ctl_iface *if_to_ctl(struct iface_af *);
in_addr_t if_get_ipv4_addr(struct iface *);
-int if_join_ipv4_group(struct iface *, struct in_addr *);
-int if_leave_ipv4_group(struct iface *, struct in_addr *);
-int if_join_ipv6_group(struct iface *, struct in6_addr *);
-int if_leave_ipv6_group(struct iface *, struct in6_addr *);
/* adjacency.c */
struct adj *adj_new(struct in_addr, struct hello_source *,
- union ldpd_addr *);
+ union ldpd_addr *);
void adj_del(struct adj *);
struct adj *adj_find(struct hello_source *);
int adj_get_af(struct adj *adj);
void adj_start_itimer(struct adj *);
void adj_stop_itimer(struct adj *);
struct tnbr *tnbr_new(struct ldpd_conf *, int, union ldpd_addr *);
-void tnbr_del(struct tnbr *);
struct tnbr *tnbr_find(struct ldpd_conf *, int, union ldpd_addr *);
struct tnbr *tnbr_check(struct tnbr *);
void tnbr_update(struct tnbr *);
void tnbr_update_all(int);
-
struct ctl_adj *adj_to_ctl(struct adj *);
/* neighbor.c */
-struct nbr *nbr_new(struct in_addr, int, int, union ldpd_addr *, uint32_t);
-void nbr_del(struct nbr *);
-void nbr_update_peerid(struct nbr *);
-
-struct nbr *nbr_find_ldpid(uint32_t);
-struct nbr *nbr_find_addr(int, union ldpd_addr *);
-struct nbr *nbr_find_peerid(uint32_t);
-int nbr_adj_count(struct nbr *, int);
-
-int nbr_fsm(struct nbr *, enum nbr_event);
-int nbr_session_active_role(struct nbr *);
-
-void nbr_ktimer(int, short, void *);
-void nbr_start_ktimer(struct nbr *);
-void nbr_stop_ktimer(struct nbr *);
-void nbr_ktimeout(int, short, void *);
-void nbr_start_ktimeout(struct nbr *);
-void nbr_stop_ktimeout(struct nbr *);
-void nbr_idtimer(int, short, void *);
-void nbr_start_idtimer(struct nbr *);
-void nbr_stop_idtimer(struct nbr *);
-int nbr_pending_idtimer(struct nbr *);
-int nbr_pending_connect(struct nbr *);
-int nbr_establish_connection(struct nbr *);
-
-uint16_t nbr_get_keepalive(int, struct in_addr);
+int nbr_fsm(struct nbr *, enum nbr_event);
+struct nbr *nbr_new(struct in_addr, int, int, union ldpd_addr *,
+ uint32_t);
+void nbr_del(struct nbr *);
+struct nbr *nbr_find_ldpid(uint32_t);
+struct nbr *nbr_find_addr(int, union ldpd_addr *);
+struct nbr *nbr_find_peerid(uint32_t);
+int nbr_adj_count(struct nbr *, int);
+int nbr_session_active_role(struct nbr *);
+void nbr_stop_ktimer(struct nbr *);
+void nbr_stop_ktimeout(struct nbr *);
+void nbr_start_idtimer(struct nbr *);
+void nbr_stop_idtimer(struct nbr *);
+int nbr_pending_idtimer(struct nbr *);
+int nbr_pending_connect(struct nbr *);
+int nbr_establish_connection(struct nbr *);
struct nbr_params *nbr_params_new(struct in_addr);
struct nbr_params *nbr_params_find(struct ldpd_conf *, struct in_addr);
-
-struct ctl_nbr *nbr_to_ctl(struct nbr *);
-
-extern struct nbr_id_head nbrs_by_id;
-RB_PROTOTYPE(nbr_id_head, nbr, id_tree, nbr_id_compare)
-extern struct nbr_addr_head nbrs_by_addr;
-RB_PROTOTYPE(nbr_addr_head, nbr, addr_tree, nbr_addr_compare)
-extern struct nbr_pid_head nbrs_by_pid;
-RB_PROTOTYPE(nbr_pid_head, nbr, pid_tree, nbr_pid_compare)
+uint16_t nbr_get_keepalive(int, struct in_addr);
+struct ctl_nbr *nbr_to_ctl(struct nbr *);
/* packet.c */
-int gen_ldp_hdr(struct ibuf *, uint16_t);
-int gen_msg_hdr(struct ibuf *, uint32_t, uint16_t);
-int send_packet(int, int, union ldpd_addr *, struct iface_af *, void *,
- size_t);
-void disc_recv_packet(int, short, void *);
-void session_accept(int, short, void *);
-void session_accept_nbr(struct nbr *, int);
-void session_read(int, short, void *);
-void session_write(int, short, void *);
-void session_close(struct nbr *);
-void session_shutdown(struct nbr *, uint32_t, uint32_t, uint32_t);
-
+int gen_ldp_hdr(struct ibuf *, uint16_t);
+int gen_msg_hdr(struct ibuf *, uint32_t, uint16_t);
+int send_packet(int, int, union ldpd_addr *,
+ struct iface_af *, void *, size_t);
+void disc_recv_packet(int, short, void *);
+void session_accept(int, short, void *);
+void session_accept_nbr(struct nbr *, int);
+void session_shutdown(struct nbr *, uint32_t, uint32_t,
+ uint32_t);
+void session_close(struct nbr *);
struct tcp_conn *tcp_new(int, struct nbr *);
-void tcp_close(struct tcp_conn *);
-struct pending_conn *pending_conn_new(int, int, union ldpd_addr *);
void pending_conn_del(struct pending_conn *);
struct pending_conn *pending_conn_find(int, union ldpd_addr *);
-void pending_conn_timeout(int, short, void *);
char *pkt_ptr; /* packet buffer */
@@ -286,7 +256,7 @@ char *pkt_ptr; /* packet buffer */
int pfkey_read(int, struct sadb_msg *);
int pfkey_establish(struct nbr *, struct nbr_params *);
int pfkey_remove(struct nbr *);
-int pfkey_init(struct ldpd_sysdep *);
+int pfkey_init(void);
/* l2vpn.c */
void ldpe_l2vpn_init(struct l2vpn *);
diff --git a/usr.sbin/ldpd/log.c b/usr.sbin/ldpd/log.c
index 077189a8c17..df44847c68b 100644
--- a/usr.sbin/ldpd/log.c
+++ b/usr.sbin/ldpd/log.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: log.c,v 1.25 2016/05/23 18:58:48 renato Exp $ */
+/* $OpenBSD: log.c,v 1.26 2016/05/23 19:09:25 renato Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -41,8 +41,10 @@ static const char * const procnames[] = {
"lde"
};
-int debug;
-int verbose;
+static void vlog(int, const char *, va_list);
+
+static int debug;
+static int verbose;
void
log_init(int n_debug)
@@ -73,7 +75,7 @@ logit(int pri, const char *fmt, ...)
va_end(ap);
}
-void
+static void
vlog(int pri, const char *fmt, va_list ap)
{
char *nfmt;
diff --git a/usr.sbin/ldpd/log.h b/usr.sbin/ldpd/log.h
index aedc26dccc1..18a338ac7af 100644
--- a/usr.sbin/ldpd/log.h
+++ b/usr.sbin/ldpd/log.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: log.h,v 1.10 2016/05/23 18:58:48 renato Exp $ */
+/* $OpenBSD: log.h,v 1.11 2016/05/23 19:09:25 renato Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -23,30 +23,32 @@
struct in6_addr;
union ldpd_addr;
-
-void log_init(int);
-void log_verbose(int);
-void logit(int, const char *, ...);
-void vlog(int, const char *, va_list);
-void log_warn(const char *, ...);
-void log_warnx(const char *, ...);
-void log_info(const char *, ...);
-void log_debug(const char *, ...);
-void fatal(const char *) __dead;
-void fatalx(const char *) __dead;
-const char *af_name(int);
-const char *socket_name(int);
-const char *pw_type_name(uint16_t);
-const char *log_map(const struct map *);
-struct fec;
-const char *log_fec(const struct fec *);
-void log_rtmsg(unsigned char);
struct hello_source;
-char *log_hello_src(const struct hello_source *);
+struct fec;
+void log_init(int);
+void log_verbose(int);
+void logit(int, const char *, ...);
+void log_warn(const char *, ...);
+void log_warnx(const char *, ...);
+void log_info(const char *, ...);
+void log_debug(const char *, ...);
+void fatal(const char *) __dead;
+void fatalx(const char *) __dead;
+const char *log_sockaddr(void *);
const char *log_in6addr(const struct in6_addr *);
const char *log_in6addr_scope(const struct in6_addr *, unsigned int);
-const char *log_sockaddr(void *);
const char *log_addr(int, const union ldpd_addr *);
+const char *af_name(int);
+const char *socket_name(int);
+const char *nbr_state_name(int);
+const char *if_state_name(int);
+const char *if_type_name(enum iface_type);
+const char *notification_name(uint32_t);
+const char *pw_type_name(uint16_t);
+char *log_hello_src(const struct hello_source *);
+const char *log_map(const struct map *);
+const char *log_fec(const struct fec *);
+void log_rtmsg(unsigned char);
#endif /* _LOG_H_ */
diff --git a/usr.sbin/ldpd/neighbor.c b/usr.sbin/ldpd/neighbor.c
index 2d1c3dab295..f56462956c0 100644
--- a/usr.sbin/ldpd/neighbor.c
+++ b/usr.sbin/ldpd/neighbor.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: neighbor.c,v 1.68 2016/05/23 18:58:48 renato Exp $ */
+/* $OpenBSD: neighbor.c,v 1.69 2016/05/23 19:09:25 renato Exp $ */
/*
* Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
@@ -43,52 +43,22 @@
#include "log.h"
#include "lde.h"
-void nbr_send_labelmappings(struct nbr *);
-int nbr_act_session_operational(struct nbr *);
+static __inline int nbr_id_compare(struct nbr *, struct nbr *);
+static __inline int nbr_addr_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_ktimer(int, short, void *);
+static void nbr_start_ktimer(struct nbr *);
+static void nbr_ktimeout(int, short, void *);
+static void nbr_start_ktimeout(struct nbr *);
+static void nbr_idtimer(int, short, void *);
+static int nbr_act_session_operational(struct nbr *);
+static void nbr_send_labelmappings(struct nbr *);
-static __inline int nbr_id_compare(struct nbr *, struct nbr *);
-static __inline int nbr_addr_compare(struct nbr *, struct nbr *);
-static __inline int nbr_pid_compare(struct nbr *, struct nbr *);
-
-RB_HEAD(nbr_id_head, nbr);
RB_GENERATE(nbr_id_head, nbr, id_tree, nbr_id_compare)
-RB_HEAD(nbr_addr_head, nbr);
RB_GENERATE(nbr_addr_head, nbr, addr_tree, nbr_addr_compare)
-RB_HEAD(nbr_pid_head, nbr);
RB_GENERATE(nbr_pid_head, nbr, pid_tree, nbr_pid_compare)
-static __inline int
-nbr_id_compare(struct nbr *a, struct nbr *b)
-{
- return (ntohl(a->id.s_addr) - ntohl(b->id.s_addr));
-}
-
-static __inline int
-nbr_addr_compare(struct nbr *a, struct nbr *b)
-{
- if (a->af < b->af)
- return (-1);
- if (a->af > b->af)
- return (1);
-
- return (ldp_addrcmp(a->af, &a->raddr, &b->raddr));
-}
-
-static __inline int
-nbr_pid_compare(struct nbr *a, struct nbr *b)
-{
- return (a->peerid - b->peerid);
-}
-
-struct nbr_id_head nbrs_by_id = RB_INITIALIZER(&nbrs_by_id);
-struct nbr_addr_head nbrs_by_addr = RB_INITIALIZER(&nbrs_by_addr);
-struct nbr_pid_head nbrs_by_pid = RB_INITIALIZER(&nbrs_by_pid);
-
-uint32_t peercnt = 1;
-
-extern struct ldpd_conf *leconf;
-extern struct ldpd_sysdep sysdep;
-
struct {
int state;
enum nbr_event event;
@@ -136,6 +106,33 @@ const char * const nbr_action_names[] = {
"CLOSE SESSION"
};
+struct nbr_id_head nbrs_by_id = RB_INITIALIZER(&nbrs_by_id);
+struct nbr_addr_head nbrs_by_addr = RB_INITIALIZER(&nbrs_by_addr);
+struct nbr_pid_head nbrs_by_pid = RB_INITIALIZER(&nbrs_by_pid);
+
+static __inline int
+nbr_id_compare(struct nbr *a, struct nbr *b)
+{
+ return (ntohl(a->id.s_addr) - ntohl(b->id.s_addr));
+}
+
+static __inline int
+nbr_addr_compare(struct nbr *a, struct nbr *b)
+{
+ if (a->af < b->af)
+ return (-1);
+ if (a->af > b->af)
+ return (1);
+
+ return (ldp_addrcmp(a->af, &a->raddr, &b->raddr));
+}
+
+static __inline int
+nbr_pid_compare(struct nbr *a, struct nbr *b)
+{
+ return (a->peerid - b->peerid);
+}
+
int
nbr_fsm(struct nbr *nbr, enum nbr_event event)
{
@@ -315,9 +312,11 @@ nbr_del(struct nbr *nbr)
free(nbr);
}
-void
+static void
nbr_update_peerid(struct nbr *nbr)
{
+ static uint32_t peercnt = 1;
+
if (nbr->peerid)
RB_REMOVE(nbr_pid_head, &nbrs_by_pid, nbr);
@@ -381,7 +380,7 @@ nbr_session_active_role(struct nbr *nbr)
/* Keepalive timer: timer to send keepalive message to neighbors */
-void
+static void
nbr_ktimer(int fd, short event, void *arg)
{
struct nbr *nbr = arg;
@@ -390,7 +389,7 @@ nbr_ktimer(int fd, short event, void *arg)
nbr_start_ktimer(nbr);
}
-void
+static void
nbr_start_ktimer(struct nbr *nbr)
{
struct timeval tv;
@@ -412,7 +411,7 @@ nbr_stop_ktimer(struct nbr *nbr)
/* Keepalive timeout: if the nbr hasn't sent keepalive */
-void
+static void
nbr_ktimeout(int fd, short event, void *arg)
{
struct nbr *nbr = arg;
@@ -422,7 +421,7 @@ nbr_ktimeout(int fd, short event, void *arg)
session_shutdown(nbr, S_KEEPALIVE_TMR, 0, 0);
}
-void
+static void
nbr_start_ktimeout(struct nbr *nbr)
{
struct timeval tv;
@@ -444,7 +443,7 @@ nbr_stop_ktimeout(struct nbr *nbr)
/* Init delay timer: timer to retry to iniziatize session */
-void
+static void
nbr_idtimer(int fd, short event, void *arg)
{
struct nbr *nbr = arg;
@@ -606,7 +605,7 @@ nbr_establish_connection(struct nbr *nbr)
return (0);
}
-int
+static int
nbr_act_session_operational(struct nbr *nbr)
{
struct lde_nbr lde_nbr;
@@ -624,7 +623,7 @@ nbr_act_session_operational(struct nbr *nbr)
&lde_nbr, sizeof(lde_nbr)));
}
-void
+static void
nbr_send_labelmappings(struct nbr *nbr)
{
ldpe_imsg_compose_lde(IMSG_LABEL_MAPPING_FULL, nbr->peerid, 0,
diff --git a/usr.sbin/ldpd/notification.c b/usr.sbin/ldpd/notification.c
index 30651896fd4..32bb2794bdc 100644
--- a/usr.sbin/ldpd/notification.c
+++ b/usr.sbin/ldpd/notification.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: notification.c,v 1.28 2016/05/23 17:43:42 renato Exp $ */
+/* $OpenBSD: notification.c,v 1.29 2016/05/23 19:09:25 renato Exp $ */
/*
* Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
@@ -36,7 +36,7 @@
#include "log.h"
#include "ldpe.h"
-int gen_status_tlv(struct ibuf *, uint32_t, uint32_t, uint32_t);
+static int gen_status_tlv(struct ibuf *, uint32_t, uint32_t, uint32_t);
void
send_notification_full(struct tcp_conn *tcp, struct notify_msg *nm)
@@ -235,7 +235,7 @@ recv_notification(struct nbr *nbr, char *buf, uint16_t len)
return (0);
}
-int
+static int
gen_status_tlv(struct ibuf *buf, uint32_t status, uint32_t msgid, uint32_t type)
{
struct status_tlv st;
diff --git a/usr.sbin/ldpd/packet.c b/usr.sbin/ldpd/packet.c
index 60e84b9bac9..e14f1a20e05 100644
--- a/usr.sbin/ldpd/packet.c
+++ b/usr.sbin/ldpd/packet.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: packet.c,v 1.55 2016/05/23 18:58:48 renato Exp $ */
+/* $OpenBSD: packet.c,v 1.56 2016/05/23 19:09:25 renato Exp $ */
/*
* Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
@@ -39,13 +39,14 @@
#include "log.h"
#include "ldpe.h"
-extern struct ldpd_conf *leconf;
-extern struct ldpd_sysdep sysdep;
-
-struct iface *disc_find_iface(unsigned int, int, union ldpd_addr *, int);
-ssize_t session_get_pdu(struct ibuf_read *, char **);
-
-static int msgcnt = 0;
+static struct iface *disc_find_iface(unsigned int, int,
+ union ldpd_addr *, int);
+static void session_read(int, short, void *);
+static void session_write(int, short, void *);
+static ssize_t session_get_pdu(struct ibuf_read *, char **);
+static void tcp_close(struct tcp_conn *);
+static struct pending_conn *pending_conn_new(int, int, union ldpd_addr *);
+static void pending_conn_timeout(int, short, void *);
int
gen_ldp_hdr(struct ibuf *buf, uint16_t size)
@@ -65,6 +66,7 @@ gen_ldp_hdr(struct ibuf *buf, uint16_t size)
int
gen_msg_hdr(struct ibuf *buf, uint32_t type, uint16_t size)
{
+ static int msgcnt = 0;
struct ldp_msg msg;
memset(&msg, 0, sizeof(msg));
@@ -258,7 +260,7 @@ disc_recv_packet(int fd, short event, void *bula)
}
}
-struct iface *
+static struct iface *
disc_find_iface(unsigned int ifindex, int af, union ldpd_addr *src,
int multicast)
{
@@ -414,7 +416,7 @@ session_accept_nbr(struct nbr *nbr, int fd)
nbr_fsm(nbr, NBR_EVT_MATCH_ADJ);
}
-void
+static void
session_read(int fd, short event, void *arg)
{
struct nbr *nbr = arg;
@@ -595,7 +597,7 @@ session_read(int fd, short event, void *arg)
}
}
-void
+static void
session_write(int fd, short event, void *arg)
{
struct tcp_conn *tcp = arg;
@@ -648,7 +650,7 @@ session_close(struct nbr *nbr)
nbr_stop_ktimeout(nbr);
}
-ssize_t
+static ssize_t
session_get_pdu(struct ibuf_read *r, char **b)
{
struct ldp_hdr l;
@@ -701,7 +703,7 @@ tcp_new(int fd, struct nbr *nbr)
return (tcp);
}
-void
+static void
tcp_close(struct tcp_conn *tcp)
{
evbuf_clear(&tcp->wbuf);
@@ -717,7 +719,7 @@ tcp_close(struct tcp_conn *tcp)
free(tcp);
}
-struct pending_conn *
+static struct pending_conn *
pending_conn_new(int fd, int af, union ldpd_addr *addr)
{
struct pending_conn *pconn;
@@ -764,7 +766,7 @@ pending_conn_find(int af, union ldpd_addr *addr)
return (NULL);
}
-void
+static void
pending_conn_timeout(int fd, short event, void *arg)
{
struct pending_conn *pconn = arg;
diff --git a/usr.sbin/ldpd/parse.y b/usr.sbin/ldpd/parse.y
index 174bdd303fe..963b59d2417 100644
--- a/usr.sbin/ldpd/parse.y
+++ b/usr.sbin/ldpd/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.50 2016/05/23 18:58:48 renato Exp $ */
+/* $OpenBSD: parse.y,v 1.51 2016/05/23 19:09:25 renato Exp $ */
/*
* Copyright (c) 2004, 2005, 2008 Esben Norby <norby@openbsd.org>
@@ -45,29 +45,15 @@
#include "ldpe.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;
@@ -75,26 +61,7 @@ struct sym {
char *nam;
char *val;
};
-
-int symset(const char *, const char *, int);
-char *symget(const char *);
-
-void clear_config(struct ldpd_conf *xconf);
-uint32_t get_rtr_id(void);
-int get_address(const char *, union ldpd_addr *);
-int get_af_address(const char *, int *, union ldpd_addr *);
-
-static struct ldpd_conf *conf;
-static int errors = 0;
-
-int af = AF_UNSPEC;
-struct ldpd_af_conf *af_conf = NULL;
-struct iface *iface = NULL;
-struct iface_af *ia = NULL;
-struct tnbr *tnbr = NULL;
-struct nbr_params *nbrp = NULL;
-struct l2vpn *l2vpn = NULL;
-struct l2vpn_pw *pw = NULL;
+TAILQ_HEAD(symhead, sym);
struct config_defaults {
uint16_t keepalive;
@@ -107,20 +74,6 @@ struct config_defaults {
uint8_t pwflags;
};
-struct config_defaults globaldefs;
-struct config_defaults afdefs;
-struct config_defaults ifacedefs;
-struct config_defaults tnbrdefs;
-struct config_defaults pwdefs;
-struct config_defaults *defs;
-
-struct iface *conf_get_if(struct kif *);
-struct tnbr *conf_get_tnbr(union ldpd_addr *);
-struct nbr_params *conf_get_nbrp(struct in_addr);
-struct l2vpn *conf_get_l2vpn(char *);
-struct l2vpn_if *conf_get_l2vpn_if(struct l2vpn *, struct kif *);
-struct l2vpn_pw *conf_get_l2vpn_pw(struct l2vpn *, struct kif *);
-
typedef struct {
union {
int64_t number;
@@ -129,6 +82,61 @@ 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 iface *conf_get_if(struct kif *);
+static struct tnbr *conf_get_tnbr(union ldpd_addr *);
+static struct nbr_params *conf_get_nbrp(struct in_addr);
+static struct l2vpn *conf_get_l2vpn(char *);
+static struct l2vpn_if *conf_get_l2vpn_if(struct l2vpn *, struct kif *);
+static struct l2vpn_pw *conf_get_l2vpn_pw(struct l2vpn *, struct kif *);
+static void clear_config(struct ldpd_conf *xconf);
+static uint32_t get_rtr_id(void);
+static int get_address(const char *, union ldpd_addr *);
+static int get_af_address(const char *, int *, union ldpd_addr *);
+
+static struct file *file, *topfile;
+static struct files files = TAILQ_HEAD_INITIALIZER(files);
+static struct symhead symhead = TAILQ_HEAD_INITIALIZER(symhead);
+static struct ldpd_conf *conf;
+static int errors;
+
+static int af;
+static struct ldpd_af_conf *af_conf;
+static struct iface *iface;
+static struct iface_af *ia;
+static struct tnbr *tnbr;
+static struct nbr_params *nbrp;
+static struct l2vpn *l2vpn;
+static struct l2vpn_pw *pw;
+
+static struct config_defaults globaldefs;
+static struct config_defaults afdefs;
+static struct config_defaults ifacedefs;
+static struct config_defaults tnbrdefs;
+static struct config_defaults pwdefs;
+static struct config_defaults *defs;
+
+static unsigned char *parsebuf;
+static int parseindex;
+static unsigned char pushback_buffer[MAXPUSHBACK];
+static int pushback_index;
+
%}
%token INTERFACE TNEIGHBOR ROUTERID FIBUPDATE EXPNULL
@@ -770,7 +778,7 @@ struct keywords {
int k_val;
};
-int
+static int
yyerror(const char *fmt, ...)
{
va_list ap;
@@ -786,13 +794,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 */
@@ -845,14 +853,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;
@@ -900,7 +901,7 @@ lgetc(int quotec)
return (c);
}
-int
+static int
lungetc(int c)
{
if (c == EOF)
@@ -916,7 +917,7 @@ lungetc(int c)
return (EOF);
}
-int
+static int
findeol(void)
{
int c;
@@ -939,7 +940,7 @@ findeol(void)
return (ERROR);
}
-int
+static int
yylex(void)
{
unsigned char buf[8096];
@@ -1088,7 +1089,7 @@ nodigits:
return (c);
}
-int
+static int
check_file_secrecy(int fd, const char *fname)
{
struct stat st;
@@ -1108,7 +1109,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;
@@ -1139,7 +1140,7 @@ pushfile(const char *name, int secret)
return (nfile);
}
-int
+static int
popfile(void)
{
struct file *prev;
@@ -1219,7 +1220,7 @@ parse_config(char *filename)
return (conf);
}
-int
+static int
symset(const char *nam, const char *val, int persist)
{
struct sym *sym;
@@ -1280,7 +1281,7 @@ cmdline_symset(char *s)
return (ret);
}
-char *
+static char *
symget(const char *nam)
{
struct sym *sym;
@@ -1293,7 +1294,7 @@ symget(const char *nam)
return (NULL);
}
-struct iface *
+static struct iface *
conf_get_if(struct kif *kif)
{
struct iface *i;
@@ -1315,7 +1316,7 @@ conf_get_if(struct kif *kif)
return (i);
}
-struct tnbr *
+static struct tnbr *
conf_get_tnbr(union ldpd_addr *addr)
{
struct tnbr *t;
@@ -1333,7 +1334,7 @@ conf_get_tnbr(union ldpd_addr *addr)
return (t);
}
-struct nbr_params *
+static struct nbr_params *
conf_get_nbrp(struct in_addr lsr_id)
{
struct nbr_params *n;
@@ -1351,7 +1352,7 @@ conf_get_nbrp(struct in_addr lsr_id)
return (n);
}
-struct l2vpn *
+static struct l2vpn *
conf_get_l2vpn(char *name)
{
struct l2vpn *l;
@@ -1366,7 +1367,7 @@ conf_get_l2vpn(char *name)
return (l);
}
-struct l2vpn_if *
+static struct l2vpn_if *
conf_get_l2vpn_if(struct l2vpn *l, struct kif *kif)
{
struct iface *i;
@@ -1393,7 +1394,7 @@ conf_get_l2vpn_if(struct l2vpn *l, struct kif *kif)
return (f);
}
-struct l2vpn_pw *
+static struct l2vpn_pw *
conf_get_l2vpn_pw(struct l2vpn *l, struct kif *kif)
{
struct l2vpn *ltmp;
@@ -1412,7 +1413,7 @@ conf_get_l2vpn_pw(struct l2vpn *l, struct kif *kif)
return (p);
}
-void
+static void
clear_config(struct ldpd_conf *xconf)
{
struct iface *i;
@@ -1453,7 +1454,7 @@ clear_config(struct ldpd_conf *xconf)
free(xconf);
}
-uint32_t
+static uint32_t
get_rtr_id(void)
{
struct ifaddrs *ifap, *ifa;
@@ -1482,7 +1483,7 @@ get_rtr_id(void)
return (ip);
}
-int
+static int
get_address(const char *s, union ldpd_addr *addr)
{
switch (af) {
@@ -1501,7 +1502,7 @@ get_address(const char *s, union ldpd_addr *addr)
return (0);
}
-int
+static int
get_af_address(const char *s, int *family, union ldpd_addr *addr)
{
if (inet_pton(AF_INET, s, &addr->v4) == 1) {
diff --git a/usr.sbin/ldpd/pfkey.c b/usr.sbin/ldpd/pfkey.c
index c1a412fb137..b31663726cd 100644
--- a/usr.sbin/ldpd/pfkey.c
+++ b/usr.sbin/ldpd/pfkey.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pfkey.c,v 1.8 2016/05/23 18:58:48 renato Exp $ */
+/* $OpenBSD: pfkey.c,v 1.9 2016/05/23 19:09:25 renato Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -33,27 +33,27 @@
#include "ldpe.h"
#include "log.h"
+static int pfkey_send(int, uint8_t, uint8_t, uint8_t,
+ int, union ldpd_addr *, union ldpd_addr *,
+ uint32_t, uint8_t, int, char *, uint8_t, int, char *,
+ uint16_t, uint16_t);
+static int pfkey_reply(int, uint32_t *);
+static int pfkey_sa_add(int, union ldpd_addr *, union ldpd_addr *,
+ uint8_t, char *, uint32_t *);
+static int pfkey_sa_remove(int, union ldpd_addr *, union ldpd_addr *,
+ uint32_t *);
+static int pfkey_md5sig_establish(struct nbr *, struct nbr_params *nbrp);
+static int pfkey_md5sig_remove(struct nbr *);
+
#define PFKEY2_CHUNK sizeof(uint64_t)
#define ROUNDUP(x) (((x) + (PFKEY2_CHUNK - 1)) & ~(PFKEY2_CHUNK - 1))
#define IOV_CNT 20
-static uint32_t sadb_msg_seq = 0;
-static uint32_t pid = 0; /* should pid_t but pfkey needs uint32_t */
-static int fd;
-
-int pfkey_reply(int, uint32_t *);
-int pfkey_send(int, uint8_t, uint8_t, uint8_t,
- int, union ldpd_addr *, union ldpd_addr *,
- uint32_t, uint8_t, int, char *, uint8_t, int, char *,
- uint16_t, uint16_t);
-int pfkey_sa_add(int, union ldpd_addr *, union ldpd_addr *, uint8_t, char *,
- uint32_t *);
-int pfkey_sa_remove(int, union ldpd_addr *, union ldpd_addr *, uint32_t *);
-
-int pfkey_md5sig_establish(struct nbr *, struct nbr_params *nbrp);
-int pfkey_md5sig_remove(struct nbr *);
+static uint32_t sadb_msg_seq;
+static uint32_t pid; /* should pid_t but pfkey needs uint32_t */
+static int fd;
-int
+static int
pfkey_send(int sd, uint8_t satype, uint8_t mtype, uint8_t dir,
int af, union ldpd_addr *src, union ldpd_addr *dst, uint32_t spi,
uint8_t aalg, int alen, char *akey, uint8_t ealg, int elen, char *ekey,
@@ -283,7 +283,7 @@ pfkey_read(int sd, struct sadb_msg *h)
return (1);
}
-int
+static int
pfkey_reply(int sd, uint32_t *spip)
{
struct sadb_msg hdr, *msg;
@@ -345,7 +345,7 @@ pfkey_reply(int sd, uint32_t *spip)
return (0);
}
-int
+static int
pfkey_sa_add(int af, union ldpd_addr *src, union ldpd_addr *dst, uint8_t keylen,
char *key, uint32_t *spi)
{
@@ -362,7 +362,7 @@ pfkey_sa_add(int af, union ldpd_addr *src, union ldpd_addr *dst, uint8_t keylen,
return (0);
}
-int
+static int
pfkey_sa_remove(int af, union ldpd_addr *src, union ldpd_addr *dst,
uint32_t *spi)
{
@@ -375,7 +375,7 @@ pfkey_sa_remove(int af, union ldpd_addr *src, union ldpd_addr *dst,
return (0);
}
-int
+static int
pfkey_md5sig_establish(struct nbr *nbr, struct nbr_params *nbrp)
{
sleep(1);
@@ -395,7 +395,7 @@ pfkey_md5sig_establish(struct nbr *nbr, struct nbr_params *nbrp)
return (0);
}
-int
+static int
pfkey_md5sig_remove(struct nbr *nbr)
{
if (nbr->auth.spi_out)
@@ -457,13 +457,13 @@ pfkey_remove(struct nbr *nbr)
}
int
-pfkey_init(struct ldpd_sysdep *sysdep)
+pfkey_init(void)
{
if ((fd = socket(PF_KEY, SOCK_RAW | SOCK_CLOEXEC | SOCK_NONBLOCK,
PF_KEY_V2)) == -1) {
if (errno == EPROTONOSUPPORT) {
log_warnx("PF_KEY not available");
- sysdep->no_pfkey = 1;
+ sysdep.no_pfkey = 1;
return (-1);
} else
fatal("pfkey setup failed");
diff --git a/usr.sbin/ldpd/printconf.c b/usr.sbin/ldpd/printconf.c
index f1adc0ec9e1..c57baa3f358 100644
--- a/usr.sbin/ldpd/printconf.c
+++ b/usr.sbin/ldpd/printconf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: printconf.c,v 1.22 2016/05/23 18:58:48 renato Exp $ */
+/* $OpenBSD: printconf.c,v 1.23 2016/05/23 19:09:25 renato Exp $ */
/*
* Copyright (c) 2004, 2005, 2008 Esben Norby <norby@openbsd.org>
@@ -29,15 +29,15 @@
#include "ldpe.h"
#include "log.h"
-void print_mainconf(struct ldpd_conf *);
-void print_af(int, struct ldpd_conf *, struct ldpd_af_conf *);
-void print_iface(struct iface *, struct iface_af *);
-void print_tnbr(struct tnbr *);
-void print_nbrp(struct nbr_params *);
-void print_l2vpn(struct l2vpn *);
-void print_pw(struct l2vpn_pw *);
+static void print_mainconf(struct ldpd_conf *);
+static void print_af(int, struct ldpd_conf *, struct ldpd_af_conf *);
+static void print_iface(struct iface *, struct iface_af *);
+static void print_tnbr(struct tnbr *);
+static void print_nbrp(struct nbr_params *);
+static void print_l2vpn(struct l2vpn *);
+static void print_pw(struct l2vpn_pw *);
-void
+static void
print_mainconf(struct ldpd_conf *conf)
{
printf("router-id %s\n", inet_ntoa(conf->rtr_id));
@@ -58,7 +58,7 @@ print_mainconf(struct ldpd_conf *conf)
printf("ds-cisco-interop no\n");
}
-void
+static void
print_af(int af, struct ldpd_conf *conf, struct ldpd_af_conf *af_conf)
{
struct iface *iface;
@@ -93,7 +93,7 @@ print_af(int af, struct ldpd_conf *conf, struct ldpd_af_conf *af_conf)
printf("}\n");
}
-void
+static void
print_iface(struct iface *iface, struct iface_af *ia)
{
printf("\tinterface %s {\n", iface->name);
@@ -102,7 +102,7 @@ print_iface(struct iface *iface, struct iface_af *ia)
printf("\t}\n");
}
-void
+static void
print_tnbr(struct tnbr *tnbr)
{
printf("\n\ttargeted-neighbor %s {\n", log_addr(tnbr->af, &tnbr->addr));
@@ -111,7 +111,7 @@ print_tnbr(struct tnbr *tnbr)
printf("\t}\n");
}
-void
+static void
print_nbrp(struct nbr_params *nbrp)
{
printf("\nneighbor %s {\n", inet_ntoa(nbrp->lsr_id));
@@ -125,7 +125,7 @@ print_nbrp(struct nbr_params *nbrp)
printf("}\n");
}
-void
+static void
print_l2vpn(struct l2vpn *l2vpn)
{
struct l2vpn_if *lif;
@@ -149,7 +149,7 @@ print_l2vpn(struct l2vpn *l2vpn)
printf("}\n");
}
-void
+static void
print_pw(struct l2vpn_pw *pw)
{
printf("\tpseudowire %s {\n", pw->ifname);
diff --git a/usr.sbin/ldpd/socket.c b/usr.sbin/ldpd/socket.c
index 89b94fd7b72..231bee08856 100644
--- a/usr.sbin/ldpd/socket.c
+++ b/usr.sbin/ldpd/socket.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: socket.c,v 1.6 2016/05/23 18:58:48 renato Exp $ */
+/* $OpenBSD: socket.c,v 1.7 2016/05/23 19:09:25 renato Exp $ */
/*
* Copyright (c) 2016 Renato Westphal <renato@openbsd.org>
@@ -31,9 +31,6 @@
#include "ldpe.h"
#include "log.h"
-extern struct ldpd_conf *ldpd_conf;
-extern struct ldpd_sysdep sysdep;
-
int
ldp_create_socket(int af, enum socket_type type)
{