summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/ldpd/Makefile2
-rw-r--r--usr.sbin/ldpd/accept.c2
-rw-r--r--usr.sbin/ldpd/address.c90
-rw-r--r--usr.sbin/ldpd/adjacency.c7
-rw-r--r--usr.sbin/ldpd/control.c4
-rw-r--r--usr.sbin/ldpd/control.h2
-rw-r--r--usr.sbin/ldpd/hello.c74
-rw-r--r--usr.sbin/ldpd/init.c40
-rw-r--r--usr.sbin/ldpd/interface.c249
-rw-r--r--usr.sbin/ldpd/keepalive.c11
-rw-r--r--usr.sbin/ldpd/kroute.c131
-rw-r--r--usr.sbin/ldpd/l2vpn.c43
-rw-r--r--usr.sbin/ldpd/labelmapping.c160
-rw-r--r--usr.sbin/ldpd/lde.c156
-rw-r--r--usr.sbin/ldpd/lde.h58
-rw-r--r--usr.sbin/ldpd/lde_lib.c41
-rw-r--r--usr.sbin/ldpd/ldp.h90
-rw-r--r--usr.sbin/ldpd/ldpd.82
-rw-r--r--usr.sbin/ldpd/ldpd.c99
-rw-r--r--usr.sbin/ldpd/ldpd.conf.510
-rw-r--r--usr.sbin/ldpd/ldpd.h223
-rw-r--r--usr.sbin/ldpd/ldpe.c172
-rw-r--r--usr.sbin/ldpd/ldpe.h95
-rw-r--r--usr.sbin/ldpd/log.c8
-rw-r--r--usr.sbin/ldpd/log.h8
-rw-r--r--usr.sbin/ldpd/neighbor.c28
-rw-r--r--usr.sbin/ldpd/notification.c40
-rw-r--r--usr.sbin/ldpd/packet.c117
-rw-r--r--usr.sbin/ldpd/parse.y78
-rw-r--r--usr.sbin/ldpd/pfkey.c62
-rw-r--r--usr.sbin/ldpd/printconf.c11
-rw-r--r--usr.sbin/ldpd/socket.c2
-rw-r--r--usr.sbin/ldpd/util.c2
33 files changed, 947 insertions, 1170 deletions
diff --git a/usr.sbin/ldpd/Makefile b/usr.sbin/ldpd/Makefile
index 74228b5a524..c8265fcde0a 100644
--- a/usr.sbin/ldpd/Makefile
+++ b/usr.sbin/ldpd/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.9 2016/05/23 17:00:40 renato Exp $
+# $OpenBSD: Makefile,v 1.10 2016/05/23 17:43:42 renato Exp $
PROG= ldpd
SRCS= accept.c adjacency.c address.c control.c hello.c init.c interface.c \
diff --git a/usr.sbin/ldpd/accept.c b/usr.sbin/ldpd/accept.c
index a117c1dc709..0f352c0d86a 100644
--- a/usr.sbin/ldpd/accept.c
+++ b/usr.sbin/ldpd/accept.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: accept.c,v 1.4 2016/05/23 15:14:07 renato Exp $ */
+/* $OpenBSD: accept.c,v 1.5 2016/05/23 17:43:42 renato Exp $ */
/*
* Copyright (c) 2012 Claudio Jeker <claudio@openbsd.org>
diff --git a/usr.sbin/ldpd/address.c b/usr.sbin/ldpd/address.c
index 209a894c6c6..e7c7e9e613f 100644
--- a/usr.sbin/ldpd/address.c
+++ b/usr.sbin/ldpd/address.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: address.c,v 1.20 2016/05/23 16:04:04 renato Exp $ */
+/* $OpenBSD: address.c,v 1.21 2016/05/23 17:43:42 renato Exp $ */
/*
* Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
@@ -38,52 +38,53 @@
extern struct ldpd_conf *leconf;
-void gen_address_list_tlv(struct ibuf *, struct if_addr *, u_int16_t);
+void gen_address_list_tlv(struct ibuf *, struct if_addr *, uint16_t);
void
-send_address(struct nbr *nbr, struct if_addr *if_addr)
+send_address(struct nbr *nbr, struct if_addr *if_addr, int withdraw)
{
struct ibuf *buf;
- u_int16_t size, iface_count = 0;
+ uint32_t msg_type;
+ uint16_t size;
+ int iface_count = 0;
- log_debug("%s: neighbor ID %s", __func__, inet_ntoa(nbr->id));
-
- if ((buf = ibuf_open(LDP_MAX_LEN)) == NULL)
- fatal(__func__);
+ if (!withdraw)
+ msg_type = MSG_TYPE_ADDR;
+ else
+ msg_type = MSG_TYPE_ADDRWITHDRAW;
- if (if_addr == NULL)
- LIST_FOREACH(if_addr, &leconf->addr_list, entry)
+ if (if_addr == NULL) {
+ LIST_FOREACH(if_addr, &global.addr_list, entry)
iface_count++;
- else
+ } else
iface_count = 1;
- size = LDP_HDR_SIZE + sizeof(struct ldp_msg) +
- sizeof(struct address_list_tlv) +
+ size = LDP_HDR_SIZE + LDP_MSG_SIZE + sizeof(struct address_list_tlv) +
iface_count * sizeof(struct in_addr);
- gen_ldp_hdr(buf, size);
+ if ((buf = ibuf_open(size)) == NULL)
+ fatal(__func__);
+ gen_ldp_hdr(buf, size);
size -= LDP_HDR_SIZE;
-
- gen_msg_tlv(buf, msg_type, size);
-
- size -= sizeof(struct ldp_msg);
-
+ gen_msg_hdr(buf, msg_type, size);
+ size -= LDP_MSG_SIZE;
gen_address_list_tlv(buf, if_addr, size);
evbuf_enqueue(&nbr->tcp->wbuf, buf);
+
nbr_fsm(nbr, NBR_EVT_PDU_SENT);
}
int
-recv_address(struct nbr *nbr, char *buf, u_int16_t len)
+recv_address(struct nbr *nbr, char *buf, uint16_t len)
{
struct ldp_msg addr;
struct address_list_tlv alt;
enum imsg_type type;
- bcopy(buf, &addr, sizeof(addr));
- log_debug("recv_address: neighbor ID %s%s", inet_ntoa(nbr->id),
+ memcpy(&addr, buf, sizeof(addr));
+ log_debug("%s: lsr-id %s%s", __func__, inet_ntoa(nbr->id),
ntohs(addr.type) == MSG_TYPE_ADDR ? "" : " address withdraw");
if (ntohs(addr.type) == MSG_TYPE_ADDR)
type = IMSG_ADDRESS_ADD;
@@ -98,7 +99,7 @@ recv_address(struct nbr *nbr, char *buf, u_int16_t len)
return (-1);
}
- bcopy(buf, &alt, sizeof(alt));
+ memcpy(&alt, buf, sizeof(alt));
if (ntohs(alt.length) != len - TLV_HDR_LEN) {
session_shutdown(nbr, S_BAD_TLV_LEN, addr.msgid, addr.type);
@@ -136,53 +137,22 @@ recv_address(struct nbr *nbr, char *buf, u_int16_t len)
}
void
-gen_address_list_tlv(struct ibuf *buf, struct if_addr *if_addr,
- u_int16_t size)
+gen_address_list_tlv(struct ibuf *buf, struct if_addr *if_addr, uint16_t size)
{
struct address_list_tlv alt;
- /* We want just the size of the value */
- size -= TLV_HDR_LEN;
- bzero(&alt, sizeof(alt));
+ memset(&alt, 0, sizeof(alt));
alt.type = TLV_TYPE_ADDRLIST;
- alt.length = htons(size);
+ alt.length = htons(size - TLV_HDR_LEN);
/* XXX: just ipv4 for now */
alt.family = htons(AF_IPV4);
ibuf_add(buf, &alt, sizeof(alt));
- if (if_addr == NULL)
- LIST_FOREACH(if_addr, &leconf->addr_list, entry)
+ if (if_addr == NULL) {
+ LIST_FOREACH(if_addr, &global.addr_list, entry)
ibuf_add(buf, &if_addr->addr, sizeof(if_addr->addr));
- else
+ } else
ibuf_add(buf, &if_addr->addr, sizeof(if_addr->addr));
}
-
-void
-send_address_withdraw(struct nbr *nbr, struct if_addr *if_addr)
-{
- struct ibuf *buf;
- u_int16_t size;
-
- log_debug("%s: neighbor ID %s", __func__, inet_ntoa(nbr->id));
-
- if ((buf = ibuf_open(LDP_MAX_LEN)) == NULL)
- fatal(__func__);
-
- size = LDP_HDR_SIZE + sizeof(struct ldp_msg) +
- sizeof(struct address_list_tlv) + sizeof(struct in_addr);
-
- gen_ldp_hdr(buf, size);
-
- size -= LDP_HDR_SIZE;
-
- gen_msg_tlv(buf, MSG_TYPE_ADDRWITHDRAW, size);
-
- size -= sizeof(struct ldp_msg);
-
- gen_address_list_tlv(buf, if_addr, size);
-
- evbuf_enqueue(&nbr->tcp->wbuf, buf);
- nbr_fsm(nbr, NBR_EVT_PDU_SENT);
-}
diff --git a/usr.sbin/ldpd/adjacency.c b/usr.sbin/ldpd/adjacency.c
index 44ee07f5f4e..a82393458ac 100644
--- a/usr.sbin/ldpd/adjacency.c
+++ b/usr.sbin/ldpd/adjacency.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: adjacency.c,v 1.13 2016/05/23 16:31:27 renato Exp $ */
+/* $OpenBSD: adjacency.c,v 1.14 2016/05/23 17:43:42 renato Exp $ */
/*
* Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
@@ -210,12 +210,12 @@ tnbr_check(struct tnbr *tnbr)
}
void
-tnbr_init(struct ldpd_conf *xconf, struct tnbr *tnbr)
+tnbr_init(struct tnbr *tnbr)
{
/* set event handlers for targeted neighbor */
evtimer_set(&tnbr->hello_timer, tnbr_hello_timer, tnbr);
- tnbr->discovery_fd = xconf->ldp_ediscovery_socket;
+ send_hello(HELLO_TARGETED, NULL, tnbr);
tnbr_start_hello_timer(tnbr);
}
@@ -227,7 +227,6 @@ tnbr_hello_timer(int fd, short event, void *arg)
{
struct tnbr *tnbr = arg;
- tnbr->discovery_fd = global.ldp_edisc_socket;
send_hello(HELLO_TARGETED, NULL, tnbr);
tnbr_start_hello_timer(tnbr);
}
diff --git a/usr.sbin/ldpd/control.c b/usr.sbin/ldpd/control.c
index e35c16d7789..7eb8ebe8397 100644
--- a/usr.sbin/ldpd/control.c
+++ b/usr.sbin/ldpd/control.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: control.c,v 1.22 2016/05/23 16:20:59 renato Exp $ */
+/* $OpenBSD: control.c,v 1.23 2016/05/23 17:43:42 renato Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -53,7 +53,7 @@ control_init(void)
return (-1);
}
- bzero(&sun, sizeof(sun));
+ memset(&sun, 0, sizeof(sun));
sun.sun_family = AF_UNIX;
strlcpy(sun.sun_path, LDPD_SOCKET, sizeof(sun.sun_path));
diff --git a/usr.sbin/ldpd/control.h b/usr.sbin/ldpd/control.h
index 5bd57c26c00..70d6ae855ec 100644
--- a/usr.sbin/ldpd/control.h
+++ b/usr.sbin/ldpd/control.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: control.h,v 1.4 2012/04/12 17:33:43 claudio Exp $ */
+/* $OpenBSD: control.h,v 1.5 2016/05/23 17:43:42 renato Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
diff --git a/usr.sbin/ldpd/hello.c b/usr.sbin/ldpd/hello.c
index 4d362839e54..3b0f5730f35 100644
--- a/usr.sbin/ldpd/hello.c
+++ b/usr.sbin/ldpd/hello.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: hello.c,v 1.36 2016/05/23 16:31:27 renato Exp $ */
+/* $OpenBSD: hello.c,v 1.37 2016/05/23 17:43:42 renato Exp $ */
/*
* Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
@@ -37,18 +37,18 @@
extern struct ldpd_conf *leconf;
-int tlv_decode_hello_prms(char *, u_int16_t, u_int16_t *, u_int16_t *);
-int tlv_decode_opt_hello_prms(char *, u_int16_t, struct in_addr *,
- u_int32_t *);
-int gen_hello_prms_tlv(struct ibuf *buf, u_int16_t, u_int16_t);
-int gen_opt4_hello_prms_tlv(struct ibuf *, u_int16_t, u_int32_t);
+int tlv_decode_hello_prms(char *, uint16_t, uint16_t *, uint16_t *);
+int tlv_decode_opt_hello_prms(char *, uint16_t, struct in_addr *,
+ uint32_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
send_hello(enum hello_type type, struct iface *iface, struct tnbr *tnbr)
{
struct sockaddr_in dst;
struct ibuf *buf;
- u_int16_t size, holdtime = 0, flags = 0;
+ uint16_t size, holdtime = 0, flags = 0;
int fd = 0;
dst.sin_port = htons(LDP_PORT);
@@ -93,30 +93,18 @@ send_hello(enum hello_type type, struct iface *iface, struct tnbr *tnbr)
}
void
-recv_hello(struct iface *iface, struct in_addr src, char *buf, u_int16_t len)
+recv_hello(struct in_addr lsr_id, struct ldp_msg *lm, struct in_addr src,
+ struct iface *iface, int multicast, char *buf, uint16_t len)
{
- struct ldp_msg hello;
- struct ldp_hdr ldp;
struct adj *adj;
struct nbr *nbr;
- struct in_addr lsr_id;
+ uint16_t holdtime, flags;
struct in_addr transport_addr;
- u_int32_t conf_number;
- u_int16_t holdtime, flags;
+ uint32_t conf_number;
int r;
struct hello_source source;
struct tnbr *tnbr = NULL;
- bcopy(buf, &ldp, sizeof(ldp));
- buf += LDP_HDR_SIZE;
- len -= LDP_HDR_SIZE;
-
- bcopy(buf, &hello, sizeof(hello));
- buf += sizeof(struct ldp_msg);
- len -= sizeof(struct ldp_msg);
-
- lsr_id.s_addr = ldp.lsr_id;
-
r = tlv_decode_hello_prms(buf, len, &holdtime, &flags);
if (r == -1) {
log_debug("%s: lsr-id %s: failed to decode params", __func__,
@@ -143,7 +131,7 @@ recv_hello(struct iface *iface, struct in_addr src, char *buf, u_int16_t len)
return;
}
- bzero(&source, sizeof(source));
+ memset(&source, 0, sizeof(source));
if (flags & TARGETED_HELLO) {
tnbr = tnbr_find(leconf, src);
@@ -161,7 +149,7 @@ recv_hello(struct iface *iface, struct in_addr src, char *buf, u_int16_t len)
tnbr = tnbr_new(leconf, src);
tnbr->flags |= F_TNBR_DYNAMIC;
- tnbr_init(leconf, tnbr);
+ tnbr_init(tnbr);
LIST_INSERT_HEAD(&leconf->tnbr_list, tnbr, entry);
}
@@ -239,11 +227,11 @@ recv_hello(struct iface *iface, struct in_addr src, char *buf, u_int16_t len)
}
int
-gen_hello_prms_tlv(struct ibuf *buf, u_int16_t holdtime, u_int16_t flags)
+gen_hello_prms_tlv(struct ibuf *buf, uint16_t holdtime, uint16_t flags)
{
struct hello_prms_tlv parms;
- bzero(&parms, sizeof(parms));
+ memset(&parms, 0, sizeof(parms));
parms.type = htons(TLV_TYPE_COMMONHELLO);
parms.length = htons(sizeof(parms.holdtime) + sizeof(parms.flags));
parms.holdtime = htons(holdtime);
@@ -253,11 +241,11 @@ gen_hello_prms_tlv(struct ibuf *buf, u_int16_t holdtime, u_int16_t flags)
}
int
-gen_opt4_hello_prms_tlv(struct ibuf *buf, u_int16_t type, u_int32_t value)
+gen_opt4_hello_prms_tlv(struct ibuf *buf, uint16_t type, uint32_t value)
{
struct hello_prms_opt4_tlv parms;
- bzero(&parms, sizeof(parms));
+ memset(&parms, 0, sizeof(parms));
parms.type = htons(type);
parms.length = htons(4);
parms.value = value;
@@ -266,14 +254,14 @@ gen_opt4_hello_prms_tlv(struct ibuf *buf, u_int16_t type, u_int32_t value)
}
int
-tlv_decode_hello_prms(char *buf, u_int16_t len, u_int16_t *holdtime,
- u_int16_t *flags)
+tlv_decode_hello_prms(char *buf, uint16_t len, uint16_t *holdtime,
+ uint16_t *flags)
{
struct hello_prms_tlv tlv;
if (len < sizeof(tlv))
return (-1);
- bcopy(buf, &tlv, sizeof(tlv));
+ memcpy(&tlv, buf, sizeof(tlv));
if (tlv.type != htons(TLV_TYPE_COMMONHELLO))
return (-1);
@@ -287,30 +275,30 @@ tlv_decode_hello_prms(char *buf, u_int16_t len, u_int16_t *holdtime,
}
int
-tlv_decode_opt_hello_prms(char *buf, u_int16_t len, struct in_addr *addr,
- u_int32_t *conf_number)
+tlv_decode_opt_hello_prms(char *buf, uint16_t len, struct in_addr *addr,
+ uint32_t *conf_number)
{
struct tlv tlv;
- int cons = 0;
- u_int16_t tlv_len;
+ uint16_t tlv_len;
+ int total = 0;
- bzero(addr, sizeof(*addr));
+ memset(addr, 0, sizeof(*addr));
*conf_number = 0;
while (len >= sizeof(tlv)) {
- bcopy(buf, &tlv, sizeof(tlv));
+ memcpy(&tlv, buf, sizeof(tlv));
tlv_len = ntohs(tlv.length);
switch (ntohs(tlv.type)) {
case TLV_TYPE_IPV4TRANSADDR:
- if (tlv_len != sizeof(u_int32_t))
+ if (tlv_len != sizeof(uint32_t))
return (-1);
- bcopy(buf + TLV_HDR_LEN, addr, sizeof(u_int32_t));
+ memcpy(addr, buf + TLV_HDR_LEN, sizeof(uint32_t));
break;
case TLV_TYPE_CONFIG:
- if (tlv_len != sizeof(u_int32_t))
+ if (tlv_len != sizeof(uint32_t))
return (-1);
- bcopy(buf + TLV_HDR_LEN, conf_number,
- sizeof(u_int32_t));
+ memcpy(conf_number, buf + TLV_HDR_LEN,
+ sizeof(uint32_t));
break;
default:
/* if unknown flag set, ignore TLV */
diff --git a/usr.sbin/ldpd/init.c b/usr.sbin/ldpd/init.c
index a4f6e1864cb..cad15769b03 100644
--- a/usr.sbin/ldpd/init.c
+++ b/usr.sbin/ldpd/init.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: init.c,v 1.23 2016/05/23 16:20:59 renato Exp $ */
+/* $OpenBSD: init.c,v 1.24 2016/05/23 17:43:42 renato Exp $ */
/*
* Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
@@ -38,14 +38,14 @@
extern struct ldpd_conf *leconf;
-int gen_init_prms_tlv(struct ibuf *, struct nbr *, u_int16_t);
-int tlv_decode_opt_init_prms(char *, u_int16_t);
+int gen_init_prms_tlv(struct ibuf *, struct nbr *, uint16_t);
+int tlv_decode_opt_init_prms(char *, uint16_t);
void
send_init(struct nbr *nbr)
{
struct ibuf *buf;
- u_int16_t size;
+ uint16_t size;
log_debug("%s: lsr-id %s", __func__, inet_ntoa(nbr->id));
@@ -63,7 +63,7 @@ send_init(struct nbr *nbr)
}
int
-recv_init(struct nbr *nbr, char *buf, u_int16_t len)
+recv_init(struct nbr *nbr, char *buf, uint16_t len)
{
struct ldp_msg init;
struct sess_prms_tlv sess;
@@ -71,16 +71,19 @@ recv_init(struct nbr *nbr, char *buf, u_int16_t len)
log_debug("%s: lsr-id %s", __func__, inet_ntoa(nbr->id));
- bcopy(buf, &init, sizeof(init));
-
- buf += sizeof(struct ldp_msg);
- len -= sizeof(struct ldp_msg);
+ memcpy(&init, buf, sizeof(init));
+ buf += LDP_MSG_SIZE;
+ len -= LDP_MSG_SIZE;
if (len < SESS_PRMS_SIZE) {
session_shutdown(nbr, S_BAD_MSG_LEN, init.msgid, init.type);
return (-1);
}
- bcopy(buf, &sess, sizeof(sess));
+ memcpy(&sess, buf, sizeof(sess));
+ if (ntohs(sess.keepalive_time) < MIN_KEEPALIVE) {
+ session_shutdown(nbr, S_KEEPALIVE_BAD, init.msgid, init.type);
+ return (-1);
+ }
if (ntohs(sess.length) != SESS_PRMS_SIZE - TLV_HDR_LEN) {
session_shutdown(nbr, S_BAD_TLV_LEN, init.msgid, init.type);
@@ -120,16 +123,13 @@ recv_init(struct nbr *nbr, char *buf, u_int16_t len)
}
int
-gen_init_prms_tlv(struct ibuf *buf, struct nbr *nbr, u_int16_t size)
+gen_init_prms_tlv(struct ibuf *buf, struct nbr *nbr, uint16_t size)
{
struct sess_prms_tlv parms;
- /* We want just the size of the value */
- size -= TLV_HDR_LEN;
-
- bzero(&parms, sizeof(parms));
+ memset(&parms, 0, sizeof(parms));
parms.type = htons(TLV_TYPE_COMMONSESSION);
- parms.length = htons(size);
+ parms.length = htons(size - TLV_HDR_LEN);
parms.proto_version = htons(LDP_VERSION);
parms.keepalive_time = htons(nbr_get_keepalive(nbr->raddr));
parms.reserved = 0;
@@ -142,14 +142,14 @@ gen_init_prms_tlv(struct ibuf *buf, struct nbr *nbr, u_int16_t size)
}
int
-tlv_decode_opt_init_prms(char *buf, u_int16_t len)
+tlv_decode_opt_init_prms(char *buf, uint16_t len)
{
struct tlv tlv;
- int cons = 0;
- u_int16_t tlv_len;
+ uint16_t tlv_len;
+ int total = 0;
while (len >= sizeof(tlv)) {
- bcopy(buf, &tlv, sizeof(tlv));
+ memcpy(&tlv, buf, sizeof(tlv));
tlv_len = ntohs(tlv.length);
switch (ntohs(tlv.type)) {
case TLV_TYPE_ATMSESSIONPAR:
diff --git a/usr.sbin/ldpd/interface.c b/usr.sbin/ldpd/interface.c
index d487beab151..2d3786460b8 100644
--- a/usr.sbin/ldpd/interface.c
+++ b/usr.sbin/ldpd/interface.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: interface.c,v 1.35 2016/05/23 17:00:40 renato Exp $ */
+/* $OpenBSD: interface.c,v 1.36 2016/05/23 17:43:42 renato Exp $ */
/*
* Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org>
@@ -95,16 +95,14 @@ if_del(struct iface *iface)
}
void
-if_init(struct ldpd_conf *xconf, struct iface *iface)
+if_init(struct iface *iface)
{
/* set event handlers for interface */
evtimer_set(&iface->hello_timer, if_hello_timer, iface);
-
- iface->discovery_fd = xconf->ldp_discovery_socket;
}
struct iface *
-if_lookup(struct ldpd_conf *xconf, u_short ifindex)
+if_lookup(struct ldpd_conf *xconf, unsigned short ifindex)
{
struct iface *iface;
@@ -330,168 +328,22 @@ if_to_ctl(struct iface *iface)
/* misc */
int
-if_set_mcast_ttl(int fd, u_int8_t ttl)
-{
- if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_TTL,
- (char *)&ttl, sizeof(ttl)) < 0) {
- log_warn("%s: error setting IP_MULTICAST_TTL to %d",
- __func__, ttl);
- return (-1);
- }
-
- return (0);
-}
-
-int
-if_set_tos(int fd, int tos)
-{
- if (setsockopt(fd, IPPROTO_IP, IP_TOS, (int *)&tos, sizeof(tos)) < 0) {
- log_warn("%s: error setting IP_TOS to 0x%x", __func__, tos);
- return (-1);
- }
-
- return (0);
-}
-
-int
-if_set_recvif(int fd, int enable)
-{
- if (setsockopt(fd, IPPROTO_IP, IP_RECVIF, &enable,
- sizeof(enable)) < 0) {
- log_warn("%s: error setting IP_RECVIF", __func__);
- return (-1);
- }
- return (0);
-}
-
-void
-if_set_recvbuf(int fd)
-{
- int bsize;
-
- bsize = 65535;
- while (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &bsize,
- sizeof(bsize)) == -1)
- bsize /= 2;
-}
-
-int
-if_set_reuse(int fd, int enable)
-{
- if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &enable,
- sizeof(int)) < 0) {
- log_warn("%s: error setting SO_REUSEADDR", __func__);
- return (-1);
- }
-
- return (0);
-}
-
-/*
- * only one JOIN or DROP per interface and address is allowed so we need
- * to keep track of what is added and removed.
- */
-struct if_group_count {
- LIST_ENTRY(if_group_count) entry;
- struct in_addr addr;
- unsigned int ifindex;
- int count;
-};
-
-LIST_HEAD(,if_group_count) ifglist = LIST_HEAD_INITIALIZER(ifglist);
-
-int
-if_set_mcast_ttl(int fd, uint8_t ttl)
-{
- if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_TTL,
- (char *)&ttl, sizeof(ttl)) < 0) {
- log_warn("%s: error setting IP_MULTICAST_TTL to %d",
- __func__, ttl);
- return (-1);
- }
-
- return (0);
-}
-
-int
-if_set_tos(int fd, int tos)
-{
- if (setsockopt(fd, IPPROTO_IP, IP_TOS, (int *)&tos, sizeof(tos)) < 0) {
- log_warn("%s: error setting IP_TOS to 0x%x", __func__, tos);
- return (-1);
- }
-
- return (0);
-}
-
-int
-if_set_recvif(int fd, int enable)
-{
- if (setsockopt(fd, IPPROTO_IP, IP_RECVIF, &enable,
- sizeof(enable)) < 0) {
- log_warn("%s: error setting IP_RECVIF", __func__);
- return (-1);
- }
- return (0);
-}
-
-void
-if_set_recvbuf(int fd)
-{
- int bsize;
-
- bsize = 65535;
- while (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &bsize,
- sizeof(bsize)) == -1)
- bsize /= 2;
-}
-
-int
-if_set_reuse(int fd, int enable)
-{
- if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &enable,
- sizeof(int)) < 0) {
- log_warn("%s: error setting SO_REUSEADDR", __func__);
- return (-1);
- }
-
- return (0);
-}
-
-int
if_join_group(struct iface *iface, struct in_addr *addr)
{
struct ip_mreq mreq;
- struct if_group_count *ifg;
struct if_addr *if_addr;
- LIST_FOREACH(ifg, &ifglist, entry)
- if (iface->ifindex == ifg->ifindex &&
- addr->s_addr == ifg->addr.s_addr)
- break;
- if (ifg == NULL) {
- if ((ifg = calloc(1, sizeof(*ifg))) == NULL)
- fatal(__func__);
- ifg->addr.s_addr = addr->s_addr;
- ifg->ifindex = iface->ifindex;
- LIST_INSERT_HEAD(&ifglist, ifg, entry);
- }
-
- if (ifg->count++ != 0)
- /* already joined */
- return (0);
+ log_debug("%s: interface %s addr %s", __func__, iface->name,
+ inet_ntoa(*addr));
if_addr = LIST_FIRST(&iface->addr_list);
mreq.imr_multiaddr.s_addr = addr->s_addr;
mreq.imr_interface.s_addr = if_addr->addr.s_addr;
- if (setsockopt(iface->discovery_fd, IPPROTO_IP,
- IP_ADD_MEMBERSHIP, (void *)&mreq, sizeof(mreq)) < 0) {
- log_warn("%s: error IP_ADD_MEMBERSHIP, "
- "interface %s address %s", __func__, iface->name,
- inet_ntoa(*addr));
- LIST_REMOVE(ifg, entry);
- free(ifg);
+ if (setsockopt(global.ldp_disc_socket, IPPROTO_IP, IP_ADD_MEMBERSHIP,
+ (void *)&mreq, sizeof(mreq)) < 0) {
+ log_warn("%s: error IP_ADD_MEMBERSHIP, interface %s address %s",
+ __func__, iface->name, inet_ntoa(*addr));
return (-1);
}
return (0);
@@ -501,23 +353,10 @@ int
if_leave_group(struct iface *iface, struct in_addr *addr)
{
struct ip_mreq mreq;
- struct if_group_count *ifg;
struct if_addr *if_addr;
- LIST_FOREACH(ifg, &ifglist, entry)
- if (iface->ifindex == ifg->ifindex &&
- addr->s_addr == ifg->addr.s_addr)
- break;
-
- /* if interface is not found just try to drop membership */
- if (ifg) {
- if (--ifg->count != 0)
- /* others still joined */
- return (0);
-
- LIST_REMOVE(ifg, entry);
- free(ifg);
- }
+ log_debug("%s: interface %s addr %s", __func__, iface->name,
+ inet_ntoa(*addr));
if_addr = LIST_FIRST(&iface->addr_list);
if (!if_addr)
@@ -526,8 +365,8 @@ if_leave_group(struct iface *iface, struct in_addr *addr)
mreq.imr_multiaddr.s_addr = addr->s_addr;
mreq.imr_interface.s_addr = if_addr->addr.s_addr;
- if (setsockopt(iface->discovery_fd, IPPROTO_IP,
- IP_DROP_MEMBERSHIP, (void *)&mreq, sizeof(mreq)) < 0) {
+ if (setsockopt(global.ldp_disc_socket, IPPROTO_IP, IP_DROP_MEMBERSHIP,
+ (void *)&mreq, sizeof(mreq)) < 0) {
log_warn("%s: error IP_DROP_MEMBERSHIP, interface %s "
"address %s", __func__, iface->name, inet_ntoa(*addr));
return (-1);
@@ -535,65 +374,3 @@ if_leave_group(struct iface *iface, struct in_addr *addr)
return (0);
}
-
-int
-if_set_mcast(struct iface *iface)
-{
- struct if_addr *if_addr;
-
- if_addr = LIST_FIRST(&iface->addr_list);
-
- if (setsockopt(global.ldp_disc_socket, IPPROTO_IP, IP_MULTICAST_IF,
- &if_addr->addr.s_addr, sizeof(if_addr->addr.s_addr)) < 0) {
- log_debug("%s: error setting IP_MULTICAST_IF, interface %s",
- __func__, iface->name);
- return (-1);
- }
-
- return (0);
-}
-
-int
-if_set_mcast_loop(int fd)
-{
- uint8_t loop = 0;
-
- if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP,
- (char *)&loop, sizeof(loop)) < 0) {
- log_warn("%s: error setting IP_MULTICAST_LOOP", __func__);
- return (-1);
- }
-
- return (0);
-}
-
-int
-if_set_mcast(struct iface *iface)
-{
- struct if_addr *if_addr;
-
- if_addr = LIST_FIRST(&iface->addr_list);
-
- if (setsockopt(global.ldp_disc_socket, IPPROTO_IP, IP_MULTICAST_IF,
- &if_addr->addr.s_addr, sizeof(if_addr->addr.s_addr)) < 0) {
- log_debug("%s: error setting IP_MULTICAST_IF, interface %s",
- __func__, iface->name);
- return (-1);
- }
-
- return (0);
-}
-
-int
-if_set_mcast_loop(int fd)
-{
- u_int8_t loop = 0;
-
- if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP,
- (char *)&loop, sizeof(loop)) < 0) {
- log_warn("%s: error setting IP_MULTICAST_LOOP", __func__);
- return (-1);
- }
-
- return (0);
-}
diff --git a/usr.sbin/ldpd/keepalive.c b/usr.sbin/ldpd/keepalive.c
index 2d231a71d21..65a0e224448 100644
--- a/usr.sbin/ldpd/keepalive.c
+++ b/usr.sbin/ldpd/keepalive.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: keepalive.c,v 1.14 2016/05/23 16:04:04 renato Exp $ */
+/* $OpenBSD: keepalive.c,v 1.15 2016/05/23 17:43:42 renato Exp $ */
/*
* Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
@@ -40,7 +40,7 @@ void
send_keepalive(struct nbr *nbr)
{
struct ibuf *buf;
- u_int16_t size;
+ uint16_t size;
size = LDP_HDR_SIZE + LDP_MSG_SIZE;
if ((buf = ibuf_open(size)) == NULL)
@@ -54,13 +54,12 @@ send_keepalive(struct nbr *nbr)
}
int
-recv_keepalive(struct nbr *nbr, char *buf, u_int16_t len)
+recv_keepalive(struct nbr *nbr, char *buf, uint16_t len)
{
struct ldp_msg ka;
- bcopy(buf, &ka, sizeof(ka));
-
- if (len != LDP_MSG_LEN) {
+ memcpy(&ka, buf, sizeof(ka));
+ if (len != LDP_MSG_SIZE) {
session_shutdown(nbr, S_BAD_MSG_LEN, ka.msgid, ka.type);
return (-1);
}
diff --git a/usr.sbin/ldpd/kroute.c b/usr.sbin/ldpd/kroute.c
index fb8fd54b1d9..b2744443121 100644
--- a/usr.sbin/ldpd/kroute.c
+++ b/usr.sbin/ldpd/kroute.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kroute.c,v 1.52 2016/05/23 16:20:59 renato Exp $ */
+/* $OpenBSD: kroute.c,v 1.53 2016/05/23 17:43:42 renato Exp $ */
/*
* Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
@@ -44,7 +44,7 @@
#include "log.h"
struct {
- u_int32_t rtseq;
+ uint32_t rtseq;
pid_t pid;
int fib_sync;
int fd;
@@ -61,14 +61,14 @@ struct kroute_node {
struct kroute_priority {
TAILQ_ENTRY(kroute_priority) entry;
struct kroute_prefix *kp; /* back pointer */
- u_int8_t priority;
+ uint8_t priority;
TAILQ_HEAD(, kroute_node) nexthops;
};
struct kroute_prefix {
RB_ENTRY(kroute_prefix) entry;
struct in_addr prefix;
- u_int8_t prefixlen;
+ uint8_t prefixlen;
TAILQ_HEAD(plist, kroute_priority) priorities;
};
@@ -90,37 +90,37 @@ void kr_redistribute(struct kroute_prefix *);
int kroute_compare(struct kroute_prefix *, struct kroute_prefix *);
int kif_compare(struct kif_node *, struct kif_node *);
-struct kroute_prefix *kroute_find(in_addr_t, u_int8_t);
-struct kroute_priority *kroute_find_prio(in_addr_t, u_int8_t, u_int8_t);
-struct kroute_node *kroute_find_gw(in_addr_t, u_int8_t, u_int8_t,
- struct in_addr);
+struct kroute_prefix *kroute_find(in_addr_t, uint8_t);
+struct kroute_priority *kroute_find_prio(in_addr_t, uint8_t, uint8_t);
+struct kroute_node *kroute_find_gw(in_addr_t, uint8_t, uint8_t,
+ struct in_addr);
int kroute_insert(struct kroute *);
int kroute_uninstall(struct kroute_node *);
int kroute_remove(struct kroute *);
void kroute_clear(void);
-struct kif_node *kif_find(u_short);
-struct kif_node *kif_insert(u_short);
+struct kif_node *kif_find(unsigned short);
+struct kif_node *kif_insert(unsigned short);
int kif_remove(struct kif_node *);
-void kif_clear(void);
-struct kif_node *kif_update(u_short, int, struct if_data *,
+struct kif_node *kif_update(unsigned short, int, struct if_data *,
struct sockaddr_dl *, int *);
struct kroute_priority *kroute_match(in_addr_t);
-u_int8_t prefixlen_classful(in_addr_t);
+uint8_t prefixlen_classful(in_addr_t);
void get_rtaddrs(int, struct sockaddr *, struct sockaddr **);
-void if_change(u_short, int, struct if_data *, struct sockaddr_dl *);
-void if_newaddr(u_short, struct sockaddr_in *, struct sockaddr_in *,
- struct sockaddr_in *);
-void if_deladdr(u_short, struct sockaddr_in *, struct sockaddr_in *,
- struct sockaddr_in *);
+void if_change(unsigned short, int, struct if_data *,
+ struct sockaddr_dl *);
+void if_newaddr(unsigned short, struct sockaddr_in *,
+ struct sockaddr_in *, struct sockaddr_in *);
+void if_deladdr(unsigned short, struct sockaddr_in *,
+ struct sockaddr_in *, struct sockaddr_in *);
void if_announce(void *);
-int send_rtmsg(int, int, struct kroute *, u_int32_t);
+int send_rtmsg(int, int, struct kroute *, uint32_t);
int dispatch_rtmsg(void);
int fetchtable(void);
-int fetchifs(u_short);
+int fetchifs(unsigned short);
int rtmsg_process(char *, size_t);
RB_HEAD(kroute_tree, kroute_prefix) krt;
@@ -342,7 +342,7 @@ kr_fib_decouple(void)
struct kroute_prefix *kp;
struct kroute_priority *kprio;
struct kroute_node *kn;
- u_int32_t rl;
+ uint32_t rl;
struct kif_node *kif;
if (kr_state.fib_sync == 0) /* already decoupled */
@@ -379,6 +379,28 @@ kr_fib_decouple(void)
log_info("kernel routing table decoupled");
}
+void
+kr_change_egress_label(int was_implicit)
+{
+ struct kroute_prefix *kp;
+ struct kroute_priority *kprio;
+ struct kroute_node *kn;
+
+ RB_FOREACH(kp, kroute_tree, &krt) {
+ TAILQ_FOREACH(kprio, &kp->priorities, entry) {
+ TAILQ_FOREACH(kn, &kprio->nexthops, entry) {
+ if (kn->r.local_label > MPLS_LABEL_RESERVED_MAX)
+ continue;
+
+ if (!was_implicit)
+ kn->r.local_label = MPLS_LABEL_IMPLNULL;
+ else
+ kn->r.local_label = MPLS_LABEL_IPV4NULL;
+ }
+ }
+ }
+}
+
/* ARGSUSED */
void
kr_dispatch_msg(int fd, short event, void *bula)
@@ -463,7 +485,7 @@ kr_redist_remove(struct kroute *kr)
int
kr_redist_eval(struct kroute *kr)
{
- u_int32_t a;
+ uint32_t a;
/* was the route redistributed? */
if (kr->flags & F_REDISTRIBUTED)
@@ -540,7 +562,7 @@ kif_compare(struct kif_node *a, struct kif_node *b)
/* tree management */
struct kroute_prefix *
-kroute_find(in_addr_t prefix, u_int8_t prefixlen)
+kroute_find(in_addr_t prefix, uint8_t prefixlen)
{
struct kroute_prefix s;
@@ -551,7 +573,7 @@ kroute_find(in_addr_t prefix, u_int8_t prefixlen)
}
struct kroute_priority *
-kroute_find_prio(in_addr_t prefix, u_int8_t prefixlen, u_int8_t prio)
+kroute_find_prio(in_addr_t prefix, uint8_t prefixlen, uint8_t prio)
{
struct kroute_prefix *kp;
struct kroute_priority *kprio;
@@ -571,7 +593,7 @@ kroute_find_prio(in_addr_t prefix, u_int8_t prefixlen, u_int8_t prio)
}
struct kroute_node *
-kroute_find_gw(in_addr_t prefix, u_int8_t prefixlen, u_int8_t prio,
+kroute_find_gw(in_addr_t prefix, uint8_t prefixlen, uint8_t prio,
struct in_addr nh)
{
struct kroute_priority *kprio;
@@ -718,11 +740,11 @@ kroute_clear(void)
}
struct kif_node *
-kif_find(u_short ifindex)
+kif_find(unsigned short ifindex)
{
struct kif_node s;
- bzero(&s, sizeof(s));
+ memset(&s, 0, sizeof(s));
s.k.ifindex = ifindex;
return (RB_FIND(kif_tree, &kit, &s));
@@ -741,7 +763,7 @@ kif_findname(char *ifname)
}
struct kif_node *
-kif_insert(u_short ifindex)
+kif_insert(unsigned short ifindex)
{
struct kif_node *kif;
@@ -785,7 +807,7 @@ kif_clear(void)
}
struct kif_node *
-kif_update(u_short ifindex, int flags, struct if_data *ifd,
+kif_update(unsigned short ifindex, int flags, struct if_data *ifd,
struct sockaddr_dl *sdl, int *link_old)
{
struct kif_node *kif;
@@ -836,7 +858,7 @@ kroute_match(in_addr_t key)
}
/* misc */
-u_int8_t
+uint8_t
prefixlen_classful(in_addr_t ina)
{
/* it hurt to write this. */
@@ -853,7 +875,7 @@ prefixlen_classful(in_addr_t ina)
return (8);
}
-u_int8_t
+uint8_t
mask2prefixlen(in_addr_t ina)
{
if (ina == 0)
@@ -863,7 +885,7 @@ mask2prefixlen(in_addr_t ina)
}
in_addr_t
-prefixlen2mask(u_int8_t prefixlen)
+prefixlen2mask(uint8_t prefixlen)
{
if (prefixlen == 0)
return (0);
@@ -890,7 +912,7 @@ get_rtaddrs(int addrs, struct sockaddr *sa, struct sockaddr **rti_info)
}
void
-if_change(u_short ifindex, int flags, struct if_data *ifd,
+if_change(unsigned short ifindex, int flags, struct if_data *ifd,
struct sockaddr_dl *sdl)
{
struct kif_node *kif;
@@ -924,12 +946,12 @@ if_change(u_short ifindex, int flags, struct if_data *ifd,
}
void
-if_newaddr(u_short ifindex, struct sockaddr_in *ifa, struct sockaddr_in *mask,
- struct sockaddr_in *brd)
+if_newaddr(unsigned short ifindex, struct sockaddr_in *ifa,
+ struct sockaddr_in *mask, struct sockaddr_in *brd)
{
struct kif_node *kif;
struct kif_addr *ka;
- u_int32_t a;
+ uint32_t a;
if (ifa == NULL || ifa->sin_family != AF_INET)
return;
@@ -964,8 +986,8 @@ if_newaddr(u_short ifindex, struct sockaddr_in *ifa, struct sockaddr_in *mask,
}
void
-if_deladdr(u_short ifindex, struct sockaddr_in *ifa, struct sockaddr_in *mask,
- struct sockaddr_in *brd)
+if_deladdr(unsigned short ifindex, struct sockaddr_in *ifa,
+ struct sockaddr_in *mask, struct sockaddr_in *brd)
{
struct kif_node *kif;
struct kif_addr *ka, *nka;
@@ -1016,7 +1038,7 @@ if_announce(void *msg)
/* rtsock */
int
-send_rtmsg(int fd, int action, struct kroute *kroute, u_int32_t family)
+send_rtmsg(int fd, int action, struct kroute *kroute, uint32_t family)
{
struct iovec iov[5];
struct rt_msghdr hdr;
@@ -1027,12 +1049,15 @@ send_rtmsg(int fd, int action, struct kroute *kroute, u_int32_t family)
if (kr_state.fib_sync == 0)
return (0);
- /* Implicit NULL label should not be added to the FIB */
- if (family == AF_MPLS && kroute->local_label == MPLS_LABEL_IMPLNULL)
+ /*
+ * Reserved labels (implicit and explicit NULL) should not be added
+ * to the FIB.
+ */
+ if (family == AF_MPLS && kroute->local_label < MPLS_LABEL_RESERVED_MAX)
return (0);
/* initialize header */
- bzero(&hdr, sizeof(hdr));
+ memset(&hdr, 0, sizeof(hdr));
hdr.rtm_version = RTM_VERSION;
hdr.rtm_type = action;
@@ -1047,7 +1072,7 @@ send_rtmsg(int fd, int action, struct kroute *kroute, u_int32_t family)
iov[iovcnt++].iov_len = sizeof(hdr);
if (family == AF_MPLS) {
- bzero(&label_in, sizeof(label_in));
+ memset(&label_in, 0, sizeof(label_in));
label_in.smpls_len = sizeof(label_in);
label_in.smpls_family = AF_MPLS;
label_in.smpls_label =
@@ -1060,7 +1085,7 @@ send_rtmsg(int fd, int action, struct kroute *kroute, u_int32_t family)
iov[iovcnt].iov_base = &label_in;
iov[iovcnt++].iov_len = sizeof(label_in);
} else {
- bzero(&dst, sizeof(dst));
+ memset(&dst, 0, sizeof(dst));
dst.sin_len = sizeof(dst);
dst.sin_family = AF_INET;
dst.sin_addr.s_addr = kroute->prefix.s_addr;
@@ -1072,7 +1097,7 @@ send_rtmsg(int fd, int action, struct kroute *kroute, u_int32_t family)
iov[iovcnt++].iov_len = sizeof(dst);
}
- bzero(&nexthop, sizeof(nexthop));
+ memset(&nexthop, 0, sizeof(nexthop));
nexthop.sin_len = sizeof(nexthop);
nexthop.sin_family = AF_INET;
nexthop.sin_addr.s_addr = kroute->nexthop.s_addr;
@@ -1085,7 +1110,7 @@ send_rtmsg(int fd, int action, struct kroute *kroute, u_int32_t family)
iov[iovcnt++].iov_len = sizeof(nexthop);
if (family == AF_INET) {
- bzero(&mask, sizeof(mask));
+ memset(&mask, 0, sizeof(mask));
mask.sin_len = sizeof(mask);
mask.sin_family = AF_INET;
mask.sin_addr.s_addr = prefixlen2mask(kroute->prefixlen);
@@ -1099,7 +1124,7 @@ send_rtmsg(int fd, int action, struct kroute *kroute, u_int32_t family)
/* If action is RTM_DELETE we have to get rid of MPLS infos */
if (kroute->remote_label != NO_LABEL && action != RTM_DELETE) {
- bzero(&label_out, sizeof(label_out));
+ memset(&label_out, 0, sizeof(label_out));
label_out.smpls_len = sizeof(label_out);
label_out.smpls_family = AF_MPLS;
label_out.smpls_label =
@@ -1184,7 +1209,7 @@ fetchtable(void)
}
int
-fetchifs(u_short ifindex)
+fetchifs(unsigned short ifindex)
{
size_t len;
int mib[6];
@@ -1251,16 +1276,16 @@ rtmsg_process(char *buf, size_t len)
struct kroute_node *kn;
struct kroute kr;
struct in_addr prefix, nexthop;
- u_int8_t prefixlen, prio;
+ uint8_t prefixlen, prio;
int flags;
- u_short ifindex = 0;
+ unsigned short ifindex = 0;
size_t offset;
char *next;
for (offset = 0; offset < len; offset += rtm->rtm_msglen) {
next = buf + offset;
rtm = (struct rt_msghdr *)next;
- if (len < offset + sizeof(u_short) ||
+ if (len < offset + sizeof(unsigned short) ||
len < offset + rtm->rtm_msglen)
fatalx("rtmsg_process: partial rtm in buffer");
if (rtm->rtm_version != RTM_VERSION)
@@ -1460,7 +1485,7 @@ kmpw_set(struct kpw *kpw)
kif = kif_find(kpw->ifindex);
if (kif == NULL) {
- log_warn("%s: failed to find mpw by index (%u)", __func__,
+ log_warnx("%s: failed to find mpw by index (%u)", __func__,
kpw->ifindex);
return;
}
@@ -1485,7 +1510,7 @@ kmpw_unset(struct kpw *kpw)
}
if (kif->kpw == NULL) {
- log_warn("%s: %s is not set", __func__, kif->k.ifname);
+ log_warnx("%s: %s is not set", __func__, kif->k.ifname);
return;
}
diff --git a/usr.sbin/ldpd/l2vpn.c b/usr.sbin/ldpd/l2vpn.c
index b6186eb52f1..397c209036e 100644
--- a/usr.sbin/ldpd/l2vpn.c
+++ b/usr.sbin/ldpd/l2vpn.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: l2vpn.c,v 1.8 2016/05/23 16:54:22 renato Exp $ */
+/* $OpenBSD: l2vpn.c,v 1.9 2016/05/23 17:43:42 renato Exp $ */
/*
* Copyright (c) 2015 Renato Westphal <renato@openbsd.org>
@@ -177,7 +177,7 @@ l2vpn_pw_del(struct l2vpn_pw *pw)
void
l2vpn_pw_fec(struct l2vpn_pw *pw, struct fec *fec)
{
- bzero(fec, sizeof(*fec));
+ memset(fec, 0, sizeof(*fec));
fec->type = FEC_TYPE_PWID;
fec->u.pwid.type = pw->l2vpn->pw_type;
fec->u.pwid.pwid = pw->pwid;
@@ -215,7 +215,7 @@ l2vpn_pw_ok(struct l2vpn_pw *pw, struct fec_nh *fnh)
return (0);
/* check for a working lsp to the nexthop */
- bzero(&fec, sizeof(fec));
+ memset(&fec, 0, sizeof(fec));
fec.type = FEC_TYPE_IPV4;
fec.u.ipv4.prefix = pw->lsr_id;
fec.u.ipv4.prefixlen = 32;
@@ -253,25 +253,25 @@ l2vpn_pw_negotiate(struct lde_nbr *ln, struct fec_node *fn, struct map *map)
/* RFC4447 - Section 6.2: control word negotiation */
if (fec_find(&ln->sent_map, &fn->fec)) {
if ((map->flags & F_MAP_PW_CWORD) &&
- !(pw->flags & F_PW_CONTROLWORD_CONF)) {
+ !(pw->flags & F_PW_CWORD_CONF)) {
/* ignore the received label mapping */
return (1);
} else if (!(map->flags & F_MAP_PW_CWORD) &&
- (pw->flags & F_PW_CONTROLWORD_CONF)) {
+ (pw->flags & F_PW_CWORD_CONF)) {
/* TODO append a "Wrong C-bit" status code */
- lde_send_labelwithdraw(ln, fn);
+ lde_send_labelwithdraw(ln, fn, NO_LABEL);
- pw->flags &= ~F_PW_CONTROLWORD;
+ pw->flags &= ~F_PW_CWORD;
lde_send_labelmapping(ln, fn, 1);
}
} else if (map->flags & F_MAP_PW_CWORD) {
- if (pw->flags & F_PW_CONTROLWORD_CONF)
- pw->flags |= F_PW_CONTROLWORD;
+ if (pw->flags & F_PW_CWORD_CONF)
+ pw->flags |= F_PW_CWORD;
else
/* act as if no label mapping had been received */
return (1);
} else
- pw->flags &= ~F_PW_CONTROLWORD;
+ pw->flags &= ~F_PW_CWORD;
/* RFC4447 - Section 5.4.3: pseudowire status negotiation */
if (fec_find(&ln->recv_map, &fn->fec) == NULL &&
@@ -282,11 +282,11 @@ l2vpn_pw_negotiate(struct lde_nbr *ln, struct fec_node *fn, struct map *map)
}
void
-l2vpn_send_pw_status(u_int32_t peerid, u_int32_t status, struct fec *fec)
+l2vpn_send_pw_status(uint32_t peerid, uint32_t status, struct fec *fec)
{
struct notify_msg nm;
- bzero(&nm, sizeof(nm));
+ memset(&nm, 0, sizeof(nm));
nm.status = S_PW_STATUS;
nm.pw_status = status;
@@ -375,7 +375,7 @@ l2vpn_pw_ctl(pid_t pid)
LIST_FOREACH(l2vpn, &ldeconf->l2vpn_list, entry)
LIST_FOREACH(pw, &l2vpn->pw_list, entry) {
- bzero(&pwctl, sizeof(pwctl));
+ memset(&pwctl, 0, sizeof(pwctl));
strlcpy(pwctl.ifname, pw->ifname,
sizeof(pwctl.ifname));
pwctl.pwid = pw->pwid;
@@ -405,17 +405,12 @@ l2vpn_binding_ctl(pid_t pid)
LIST_EMPTY(&fn->downstream))
continue;
- fnh = fec_nh_find(fn, f->u.pwid.nexthop);
- if (fnh != NULL)
- pw = (struct l2vpn_pw *) fnh->data;
- else
- pw = NULL;
-
- bzero(&pwctl, sizeof(pwctl));
+ memset(&pwctl, 0, sizeof(pwctl));
pwctl.type = f->u.pwid.type;
pwctl.pwid = f->u.pwid.pwid;
- pwctl.nexthop = f->u.pwid.nexthop;
+ pwctl.lsr_id = f->u.pwid.lsr_id;
+ pw = (struct l2vpn_pw *) fn->data;
if (pw) {
pwctl.local_label = fn->local_label;
pwctl.local_gid = 0;
@@ -469,9 +464,9 @@ ldpe_l2vpn_pw_init(struct l2vpn_pw *pw)
{
struct tnbr *tnbr;
- tnbr = tnbr_find(leconf, pw->addr);
- if (tnbr->discovery_fd == 0)
- tnbr_init(leconf, tnbr);
+ tnbr = tnbr_find(leconf, pw->lsr_id);
+ if (!event_initialized(&tnbr->hello_timer))
+ tnbr_init(tnbr);
}
void
diff --git a/usr.sbin/ldpd/labelmapping.c b/usr.sbin/ldpd/labelmapping.c
index 3f7684363fe..57bcd288945 100644
--- a/usr.sbin/ldpd/labelmapping.c
+++ b/usr.sbin/ldpd/labelmapping.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: labelmapping.c,v 1.40 2016/05/23 16:43:57 renato Exp $ */
+/* $OpenBSD: labelmapping.c,v 1.41 2016/05/23 17:43:42 renato Exp $ */
/*
* Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
@@ -38,14 +38,14 @@
#include "log.h"
#include "ldpe.h"
-void gen_label_tlv(struct ibuf *, u_int32_t);
-void gen_reqid_tlv(struct ibuf *, u_int32_t);
+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 *, u_int16_t,
- u_int32_t *);
+int tlv_decode_label(struct nbr *, struct ldp_msg *, char *, uint16_t,
+ uint32_t *);
static void
-enqueue_pdu(struct nbr *nbr, struct ibuf *buf, u_int16_t size)
+enqueue_pdu(struct nbr *nbr, struct ibuf *buf, uint16_t size)
{
struct ldp_hdr *ldp_hdr;
@@ -56,11 +56,11 @@ enqueue_pdu(struct nbr *nbr, struct ibuf *buf, u_int16_t size)
/* Generic function that handles all Label Message types */
void
-send_labelmessage(struct nbr *nbr, u_int16_t type, struct mapping_head *mh)
+send_labelmessage(struct nbr *nbr, uint16_t type, struct mapping_head *mh)
{
struct ibuf *buf = NULL;
struct mapping_entry *me;
- u_int16_t tlv_size, size = 0;
+ uint16_t msg_size, size = 0;
int first = 1;
/* nothing to send */
@@ -70,7 +70,8 @@ send_labelmessage(struct nbr *nbr, u_int16_t type, struct mapping_head *mh)
while ((me = TAILQ_FIRST(mh)) != NULL) {
/* generate pdu */
if (first) {
- if ((buf = ibuf_open(LDP_MAX_LEN)) == NULL)
+ if ((buf = ibuf_open(nbr->max_pdu_len +
+ LDP_HDR_DEAD_LEN)) == NULL)
fatal(__func__);
/* real size will be set up later */
@@ -81,44 +82,44 @@ send_labelmessage(struct nbr *nbr, u_int16_t type, struct mapping_head *mh)
}
/* calculate size */
- tlv_size = LDP_MSG_LEN + TLV_HDR_LEN;
+ msg_size = LDP_MSG_SIZE + TLV_HDR_LEN;
switch (me->map.type) {
- case FEC_WILDCARD:
- tlv_size += FEC_ELM_WCARD_LEN;
+ case MAP_TYPE_WILDCARD:
+ msg_size += FEC_ELM_WCARD_LEN;
break;
- case FEC_PREFIX:
- tlv_size += FEC_ELM_PREFIX_MIN_LEN +
+ case MAP_TYPE_PREFIX:
+ msg_size += FEC_ELM_PREFIX_MIN_LEN +
PREFIX_SIZE(me->map.fec.ipv4.prefixlen);
break;
- case FEC_PWID:
- tlv_size += FEC_PWID_ELM_MIN_LEN;
+ case MAP_TYPE_PWID:
+ msg_size += FEC_PWID_ELM_MIN_LEN;
if (me->map.flags & F_MAP_PW_ID)
- tlv_size += sizeof(u_int32_t);
+ msg_size += sizeof(uint32_t);
if (me->map.flags & F_MAP_PW_IFMTU)
- tlv_size += FEC_SUBTLV_IFMTU_LEN;
+ msg_size += FEC_SUBTLV_IFMTU_LEN;
if (me->map.flags & F_MAP_PW_STATUS)
- tlv_size += PW_STATUS_TLV_LEN;
+ msg_size += PW_STATUS_TLV_LEN;
break;
}
if (me->map.label != NO_LABEL)
- tlv_size += LABEL_TLV_LEN;
+ msg_size += LABEL_TLV_LEN;
if (me->map.flags & F_MAP_REQ_ID)
- tlv_size += REQID_TLV_LEN;
+ msg_size += REQID_TLV_LEN;
/* maximum pdu length exceeded, we need a new ldp pdu */
- if (size + tlv_size > LDP_MAX_LEN) {
+ if (size + msg_size > nbr->max_pdu_len) {
enqueue_pdu(nbr, buf, size);
first = 1;
continue;
}
- size += tlv_size;
+ size += msg_size;
/* append message and tlvs */
- gen_msg_tlv(buf, type, tlv_size);
+ gen_msg_hdr(buf, type, msg_size);
gen_fec_tlv(buf, &me->map);
if (me->map.label != NO_LABEL)
gen_label_tlv(buf, me->map.label);
@@ -138,22 +139,21 @@ send_labelmessage(struct nbr *nbr, u_int16_t type, struct mapping_head *mh)
/* Generic function that handles all Label Message types */
int
-recv_labelmessage(struct nbr *nbr, char *buf, u_int16_t len, u_int16_t type)
+recv_labelmessage(struct nbr *nbr, char *buf, uint16_t len, uint16_t type)
{
- struct ldp_msg lm;
- struct tlv ft;
- u_int32_t label = NO_LABEL, reqid = 0;
- u_int32_t pw_status = 0;
- u_int8_t flags = 0;
- int feclen, lbllen, tlen;
- struct mapping_entry *me;
- struct mapping_head mh;
- struct map map;
-
- bcopy(buf, &lm, sizeof(lm));
+ struct ldp_msg lm;
+ struct tlv ft;
+ uint32_t label = NO_LABEL, reqid = 0;
+ uint32_t pw_status = 0;
+ uint8_t flags = 0;
+ int feclen, lbllen, tlen;
+ struct mapping_entry *me;
+ struct mapping_head mh;
+ struct map map;
- buf += sizeof(struct ldp_msg);
- len -= sizeof(struct ldp_msg);
+ memcpy(&lm, buf, sizeof(lm));
+ buf += LDP_MSG_SIZE;
+ len -= LDP_MSG_SIZE;
/* FEC TLV */
if (len < sizeof(ft)) {
@@ -161,7 +161,7 @@ recv_labelmessage(struct nbr *nbr, char *buf, u_int16_t len, u_int16_t type)
return (-1);
}
- bcopy(buf, &ft, sizeof(ft));
+ memcpy(&ft, buf, sizeof(ft));
if (ntohs(ft.type) != TLV_TYPE_FEC) {
send_notification_nbr(nbr, S_MISS_MSG, lm.msgid, lm.type);
return (-1);
@@ -241,7 +241,7 @@ recv_labelmessage(struct nbr *nbr, char *buf, u_int16_t len, u_int16_t type)
/* Optional Parameters */
while (len > 0) {
struct tlv tlv;
- u_int32_t reqbuf, labelbuf, statusbuf;
+ uint32_t reqbuf, labelbuf, statusbuf;
if (len < sizeof(tlv)) {
session_shutdown(nbr, S_BAD_TLV_LEN, lm.msgid,
@@ -249,8 +249,8 @@ recv_labelmessage(struct nbr *nbr, char *buf, u_int16_t len, u_int16_t type)
goto err;
}
- bcopy(buf, &tlv, sizeof(tlv));
- if (ntohs(tlv.length) > len - TLV_HDR_LEN) {
+ memcpy(&tlv, buf, sizeof(tlv));
+ if (ntohs(tlv.length) != len - TLV_HDR_LEN) {
session_shutdown(nbr, S_BAD_TLV_LEN, lm.msgid,
lm.type);
goto err;
@@ -404,7 +404,7 @@ err:
/* Other TLV related functions */
void
-gen_label_tlv(struct ibuf *buf, u_int32_t label)
+gen_label_tlv(struct ibuf *buf, uint32_t label)
{
struct label_tlv lt;
@@ -417,7 +417,7 @@ gen_label_tlv(struct ibuf *buf, u_int32_t label)
int
tlv_decode_label(struct nbr *nbr, struct ldp_msg *lm, char *buf,
- u_int16_t len, u_int32_t *label)
+ uint16_t len, uint32_t *label)
{
struct label_tlv lt;
@@ -425,7 +425,7 @@ tlv_decode_label(struct nbr *nbr, struct ldp_msg *lm, char *buf,
session_shutdown(nbr, S_BAD_TLV_LEN, lm->msgid, lm->type);
return (-1);
}
- bcopy(buf, &lt, sizeof(lt));
+ memcpy(&lt, buf, sizeof(lt));
if (!(ntohs(lt.type) & TLV_TYPE_GENERICLABEL)) {
send_notification_nbr(nbr, S_MISS_MSG, lm->msgid, lm->type);
@@ -462,7 +462,7 @@ tlv_decode_label(struct nbr *nbr, struct ldp_msg *lm, char *buf,
}
void
-gen_reqid_tlv(struct ibuf *buf, u_int32_t reqid)
+gen_reqid_tlv(struct ibuf *buf, uint32_t reqid)
{
struct reqid_tlv rt;
@@ -474,7 +474,7 @@ gen_reqid_tlv(struct ibuf *buf, u_int32_t reqid)
}
void
-gen_pw_status_tlv(struct ibuf *buf, u_int32_t status)
+gen_pw_status_tlv(struct ibuf *buf, uint32_t status)
{
struct pw_status_tlv st;
@@ -489,19 +489,19 @@ void
gen_fec_tlv(struct ibuf *buf, struct map *map)
{
struct tlv ft;
- u_int16_t family, len, pw_type, ifmtu;
- u_int8_t pw_len = 0;
- u_int32_t group_id, pwid;
+ uint16_t family, len, pw_type, ifmtu;
+ uint8_t pw_len = 0;
+ uint32_t group_id, pwid;
ft.type = htons(TLV_TYPE_FEC);
switch (map->type) {
- case FEC_WILDCARD:
- ft.length = htons(sizeof(u_int8_t));
+ case MAP_TYPE_WILDCARD:
+ ft.length = htons(sizeof(uint8_t));
ibuf_add(buf, &ft, sizeof(ft));
ibuf_add(buf, &map->type, sizeof(map->type));
break;
- case FEC_PREFIX:
+ case MAP_TYPE_PREFIX:
len = PREFIX_SIZE(map->fec.ipv4.prefixlen);
ft.length = htons(sizeof(map->type) + sizeof(family) +
sizeof(map->fec.ipv4.prefixlen) + len);
@@ -517,7 +517,7 @@ gen_fec_tlv(struct ibuf *buf, struct map *map)
break;
case MAP_TYPE_PWID:
if (map->flags & F_MAP_PW_ID)
- pw_len += sizeof(u_int32_t);
+ pw_len += sizeof(uint32_t);
if (map->flags & F_MAP_PW_IFMTU)
pw_len += FEC_SUBTLV_IFMTU_LEN;
@@ -526,28 +526,28 @@ gen_fec_tlv(struct ibuf *buf, struct map *map)
ft.length = htons(len);
ibuf_add(buf, &ft, sizeof(ft));
- ibuf_add(buf, &map->type, sizeof(u_int8_t));
+ ibuf_add(buf, &map->type, sizeof(uint8_t));
pw_type = map->fec.pwid.type;
if (map->flags & F_MAP_PW_CWORD)
pw_type |= CONTROL_WORD_FLAG;
pw_type = htons(pw_type);
- ibuf_add(buf, &pw_type, sizeof(u_int16_t));
- ibuf_add(buf, &pw_len, sizeof(u_int8_t));
+ ibuf_add(buf, &pw_type, sizeof(uint16_t));
+ ibuf_add(buf, &pw_len, sizeof(uint8_t));
group_id = htonl(map->fec.pwid.group_id);
- ibuf_add(buf, &group_id, sizeof(u_int32_t));
+ ibuf_add(buf, &group_id, sizeof(uint32_t));
if (map->flags & F_MAP_PW_ID) {
pwid = htonl(map->fec.pwid.pwid);
- ibuf_add(buf, &pwid, sizeof(u_int32_t));
+ ibuf_add(buf, &pwid, sizeof(uint32_t));
}
if (map->flags & F_MAP_PW_IFMTU) {
struct subtlv stlv;
stlv.type = SUBTLV_IFMTU;
stlv.length = FEC_SUBTLV_IFMTU_LEN;
- ibuf_add(buf, &stlv, sizeof(u_int16_t));
+ ibuf_add(buf, &stlv, sizeof(uint16_t));
ifmtu = htons(map->fec.pwid.ifmtu);
- ibuf_add(buf, &ifmtu, sizeof(u_int16_t));
+ ibuf_add(buf, &ifmtu, sizeof(uint16_t));
}
break;
default:
@@ -557,13 +557,13 @@ gen_fec_tlv(struct ibuf *buf, struct map *map)
int
tlv_decode_fec_elm(struct nbr *nbr, struct ldp_msg *lm, char *buf,
- u_int16_t len, struct map *map)
+ uint16_t len, struct map *map)
{
- u_int16_t family, off = 0;
- u_int8_t pw_len;
+ uint16_t family, off = 0;
+ uint8_t pw_len;
map->type = *buf;
- off += sizeof(u_int8_t);
+ off += sizeof(uint8_t);
switch (map->type) {
case MAP_TYPE_WILDCARD:
@@ -583,7 +583,7 @@ tlv_decode_fec_elm(struct nbr *nbr, struct ldp_msg *lm, char *buf,
}
/* Address Family */
- bcopy(buf + off, &family, sizeof(family));
+ memcpy(&family, buf + off, sizeof(family));
off += sizeof(family);
if (family != htons(AF_IPV4)) {
@@ -594,7 +594,7 @@ tlv_decode_fec_elm(struct nbr *nbr, struct ldp_msg *lm, char *buf,
/* PreLen */
map->fec.ipv4.prefixlen = buf[off];
- off += sizeof(u_int8_t);
+ off += sizeof(uint8_t);
if (len < off + PREFIX_SIZE(map->fec.ipv4.prefixlen)) {
session_shutdown(nbr, S_BAD_TLV_LEN, lm->msgid,
@@ -604,7 +604,7 @@ tlv_decode_fec_elm(struct nbr *nbr, struct ldp_msg *lm, char *buf,
/* Prefix */
map->fec.ipv4.prefix.s_addr = 0;
- bcopy(buf + off, &map->fec.ipv4.prefix,
+ memcpy(&map->fec.ipv4.prefix, buf + off,
PREFIX_SIZE(map->fec.ipv4.prefixlen));
return (off + PREFIX_SIZE(map->fec.ipv4.prefixlen));
@@ -616,17 +616,17 @@ tlv_decode_fec_elm(struct nbr *nbr, struct ldp_msg *lm, char *buf,
}
/* PW type */
- bcopy(buf + off, &map->fec.pwid.type, sizeof(u_int16_t));
+ memcpy(&map->fec.pwid.type, buf + off, sizeof(uint16_t));
map->fec.pwid.type = ntohs(map->fec.pwid.type);
if (map->fec.pwid.type & CONTROL_WORD_FLAG) {
map->flags |= F_MAP_PW_CWORD;
map->fec.pwid.type &= ~CONTROL_WORD_FLAG;
}
- off += sizeof(u_int16_t);
+ off += sizeof(uint16_t);
/* PW info Length */
pw_len = buf[off];
- off += sizeof(u_int8_t);
+ off += sizeof(uint8_t);
if (len != FEC_PWID_ELM_MIN_LEN + pw_len) {
session_shutdown(nbr, S_BAD_TLV_LEN, lm->msgid,
@@ -635,25 +635,25 @@ tlv_decode_fec_elm(struct nbr *nbr, struct ldp_msg *lm, char *buf,
}
/* Group ID */
- bcopy(buf + off, &map->fec.pwid.group_id, sizeof(u_int32_t));
+ memcpy(&map->fec.pwid.group_id, buf + off, sizeof(uint32_t));
map->fec.pwid.group_id = ntohl(map->fec.pwid.group_id);
- off += sizeof(u_int32_t);
+ off += sizeof(uint32_t);
/* PW ID */
if (pw_len == 0)
return (off);
- if (pw_len < sizeof(u_int32_t)) {
+ if (pw_len < sizeof(uint32_t)) {
session_shutdown(nbr, S_BAD_TLV_LEN, lm->msgid,
lm->type);
return (-1);
}
- bcopy(buf + off, &map->fec.pwid.pwid, sizeof(u_int32_t));
+ memcpy(&map->fec.pwid.pwid, buf + off, sizeof(uint32_t));
map->fec.pwid.pwid = ntohl(map->fec.pwid.pwid);
map->flags |= F_MAP_PW_ID;
- off += sizeof(u_int32_t);
- pw_len -= sizeof(u_int32_t);
+ off += sizeof(uint32_t);
+ pw_len -= sizeof(uint32_t);
/* Optional Interface Parameter Sub-TLVs */
while (pw_len > 0) {
@@ -665,7 +665,7 @@ tlv_decode_fec_elm(struct nbr *nbr, struct ldp_msg *lm, char *buf,
return (-1);
}
- bcopy(buf + off, &stlv, sizeof(stlv));
+ memcpy(&stlv, buf + off, sizeof(stlv));
off += SUBTLV_HDR_LEN;
pw_len -= SUBTLV_HDR_LEN;
@@ -676,8 +676,8 @@ tlv_decode_fec_elm(struct nbr *nbr, struct ldp_msg *lm, char *buf,
lm->msgid, lm->type);
return (-1);
}
- bcopy(buf + off, &map->fec.pwid.ifmtu,
- sizeof(u_int16_t));
+ memcpy(&map->fec.pwid.ifmtu, buf + off,
+ sizeof(uint16_t));
map->fec.pwid.ifmtu = ntohs(map->fec.pwid.ifmtu);
map->flags |= F_MAP_PW_IFMTU;
break;
diff --git a/usr.sbin/ldpd/lde.c b/usr.sbin/ldpd/lde.c
index fb1dbe9cf7b..6a86748e2b4 100644
--- a/usr.sbin/ldpd/lde.c
+++ b/usr.sbin/ldpd/lde.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: lde.c,v 1.48 2016/05/23 16:54:22 renato Exp $ */
+/* $OpenBSD: lde.c,v 1.49 2016/05/23 17:43:42 renato Exp $ */
/*
* Copyright (c) 2004, 2005 Claudio Jeker <claudio@openbsd.org>
@@ -44,8 +44,8 @@ void lde_shutdown(void);
void lde_dispatch_imsg(int, short, void *);
void lde_dispatch_parent(int, short, void *);
-struct lde_nbr *lde_nbr_find(u_int32_t);
-struct lde_nbr *lde_nbr_new(u_int32_t, struct in_addr *);
+struct lde_nbr *lde_nbr_find(uint32_t);
+struct lde_nbr *lde_nbr_new(uint32_t, struct in_addr *);
void lde_nbr_del(struct lde_nbr *);
void lde_nbr_clear(void);
@@ -56,6 +56,14 @@ 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);
+
/* ARGSUSED */
void
lde_sig_handler(int sig, short event, void *arg)
@@ -152,7 +160,7 @@ lde(struct ldpd_conf *xconf, int pipe_parent2lde[2], int pipe_ldpe2lde[2],
event_add(&iev_main->ev, NULL);
gettimeofday(&now, NULL);
- ldeconf->uptime = now.tv_sec;
+ global.uptime = now.tv_sec;
/* initialize l2vpns */
LIST_FOREACH(l2vpn, &ldeconf->l2vpn_list, entry)
@@ -185,14 +193,14 @@ lde_shutdown(void)
/* imesg */
int
-lde_imsg_compose_parent(int type, pid_t pid, void *data, u_int16_t datalen)
+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));
}
int
-lde_imsg_compose_ldpe(int type, u_int32_t peerid, pid_t pid, void *data,
- u_int16_t datalen)
+lde_imsg_compose_ldpe(int type, uint32_t peerid, pid_t pid, void *data,
+ uint16_t datalen)
{
return (imsg_compose_event(iev_ldpe, type, peerid, pid,
-1, data, datalen));
@@ -233,14 +241,14 @@ lde_dispatch_imsg(int fd, short event, void *bula)
switch (imsg.hdr.type) {
case IMSG_LABEL_MAPPING_FULL:
- nbr = lde_nbr_find(imsg.hdr.peerid);
- if (nbr == NULL) {
+ ln = lde_nbr_find(imsg.hdr.peerid);
+ if (ln == NULL) {
log_debug("%s: cannot find lde neighbor",
__func__);
- return;
+ break;
}
- fec_snap(nbr);
+ fec_snap(ln);
break;
case IMSG_LABEL_MAPPING:
case IMSG_LABEL_REQUEST:
@@ -255,7 +263,7 @@ lde_dispatch_imsg(int fd, short event, void *bula)
if (ln == NULL) {
log_debug("%s: cannot find lde neighbor",
__func__);
- return;
+ break;
}
switch (imsg.hdr.type) {
@@ -287,14 +295,14 @@ lde_dispatch_imsg(int fd, short event, void *bula)
fatalx("lde_dispatch_imsg: wrong imsg len");
memcpy(&addr, imsg.data, sizeof(addr));
- nbr = lde_nbr_find(imsg.hdr.peerid);
- if (nbr == NULL) {
+ ln = lde_nbr_find(imsg.hdr.peerid);
+ if (ln == NULL) {
log_debug("%s: cannot find lde neighbor",
__func__);
- return;
+ break;
}
- if (lde_address_add(nbr, &addr) < 0) {
+ if (lde_address_add(ln, &addr) < 0) {
log_debug("%s: cannot add address %s, it "
"already exists", __func__,
inet_ntoa(addr));
@@ -306,14 +314,14 @@ lde_dispatch_imsg(int fd, short event, void *bula)
fatalx("lde_dispatch_imsg: wrong imsg len");
memcpy(&addr, imsg.data, sizeof(addr));
- nbr = lde_nbr_find(imsg.hdr.peerid);
- if (nbr == NULL) {
+ ln = lde_nbr_find(imsg.hdr.peerid);
+ if (ln == NULL) {
log_debug("%s: cannot find lde neighbor",
__func__);
- return;
+ break;
}
- if (lde_address_del(nbr, &addr) < 0) {
+ if (lde_address_del(ln, &addr) < 0) {
log_debug("%s: cannot delete address %s, it "
"does not exist", __func__,
inet_ntoa(addr));
@@ -329,7 +337,7 @@ lde_dispatch_imsg(int fd, short event, void *bula)
if (ln == NULL) {
log_debug("%s: cannot find lde neighbor",
__func__);
- return;
+ break;
}
switch (nm.status) {
@@ -462,7 +470,6 @@ lde_dispatch_parent(int fd, short event, void *bula)
memcpy(nconf, imsg.data, sizeof(struct ldpd_conf));
LIST_INIT(&nconf->iface_list);
- LIST_INIT(&nconf->addr_list);
LIST_INIT(&nconf->tnbr_list);
LIST_INIT(&nconf->nbrp_list);
LIST_INIT(&nconf->l2vpn_list);
@@ -537,10 +544,10 @@ lde_dispatch_parent(int fd, short event, void *bula)
}
}
-u_int32_t
+uint32_t
lde_assign_label(void)
{
- static u_int32_t label = MPLS_LABEL_RESERVED_MAX;
+ static uint32_t label = MPLS_LABEL_RESERVED_MAX;
/* XXX some checks needed */
label++;
@@ -556,7 +563,7 @@ lde_send_change_klabel(struct fec_node *fn, struct fec_nh *fnh)
switch (fn->fec.type) {
case FEC_TYPE_IPV4:
- bzero(&kr, sizeof(kr));
+ memset(&kr, 0, sizeof(kr));
kr.prefix.s_addr = fn->fec.u.ipv4.prefix.s_addr;
kr.prefixlen = fn->fec.u.ipv4.prefixlen;
kr.local_label = fn->local_label;
@@ -578,7 +585,7 @@ lde_send_change_klabel(struct fec_node *fn, struct fec_nh *fnh)
pw = (struct l2vpn_pw *) fn->data;
pw->flags |= F_PW_STATUS_UP;
- bzero(&kpw, sizeof(kpw));
+ memset(&kpw, 0, sizeof(kpw));
kpw.ifindex = pw->ifindex;
kpw.pw_type = fn->fec.u.pwid.type;
kpw.nexthop.s_addr = fnh->nexthop.s_addr;
@@ -601,7 +608,7 @@ lde_send_delete_klabel(struct fec_node *fn, struct fec_nh *fnh)
switch (fn->fec.type) {
case FEC_TYPE_IPV4:
- bzero(&kr, sizeof(kr));
+ memset(&kr, 0, sizeof(kr));
kr.prefix.s_addr = fn->fec.u.ipv4.prefix.s_addr;
kr.prefixlen = fn->fec.u.ipv4.prefixlen;
kr.local_label = fn->local_label;
@@ -620,7 +627,7 @@ lde_send_delete_klabel(struct fec_node *fn, struct fec_nh *fnh)
return;
pw->flags &= ~F_PW_STATUS_UP;
- bzero(&kpw, sizeof(kpw));
+ memset(&kpw, 0, sizeof(kpw));
kpw.ifindex = pw->ifindex;
kpw.pw_type = fn->fec.u.pwid.type;
kpw.nexthop.s_addr = fnh->nexthop.s_addr;
@@ -637,7 +644,7 @@ lde_send_delete_klabel(struct fec_node *fn, struct fec_nh *fnh)
void
lde_fec2map(struct fec *fec, struct map *map)
{
- bzero(map, sizeof(*map));
+ memset(map, 0, sizeof(*map));
switch (fec->type) {
case FEC_TYPE_IPV4:
@@ -658,7 +665,7 @@ lde_fec2map(struct fec *fec, struct map *map)
void
lde_map2fec(struct map *map, struct in_addr lsr_id, struct fec *fec)
{
- bzero(fec, sizeof(*fec));
+ memset(fec, 0, sizeof(*fec));
switch (map->type) {
case MAP_TYPE_PREFIX:
@@ -689,9 +696,7 @@ lde_send_labelmapping(struct lde_nbr *ln, struct fec_node *fn, int single)
* ldpd).
*/
- bzero(&map, sizeof(map));
lde_fec2map(&fn->fec, &map);
-
if (fn->fec.type == FEC_TYPE_PWID) {
pw = (struct l2vpn_pw *) fn->data;
if (pw == NULL || pw->lsr_id.s_addr != ln->id.s_addr)
@@ -736,34 +741,29 @@ lde_send_labelmapping(struct lde_nbr *ln, struct fec_node *fn, int single)
}
void
-lde_send_labelwithdraw(struct lde_nbr *ln, struct fec_node *fn)
+lde_send_labelwithdraw(struct lde_nbr *ln, struct fec_node *fn, uint32_t label)
{
struct lde_wdraw *lw;
struct map map;
struct fec *f;
- struct fec_nh *fnh = NULL;
struct l2vpn_pw *pw;
- if (fn->fec.type == FEC_TYPE_PWID) {
- fnh = fec_nh_find(fn, ln->id);
- if (fnh == NULL)
- /* not the other end of the pseudowire */
- return;
- }
-
- bzero(&map, sizeof(map));
if (fn) {
lde_fec2map(&fn->fec, &map);
map.label = fn->local_label;
-
if (fn->fec.type == FEC_TYPE_PWID) {
- pw = (struct l2vpn_pw *) fnh->data;
+ pw = (struct l2vpn_pw *) fn->data;
+ if (pw == NULL || pw->lsr_id.s_addr != ln->id.s_addr)
+ /* not the remote end of the pseudowire */
+ return;
+
if (pw->flags & F_PW_CWORD)
map.flags |= F_MAP_PW_CWORD;
}
} else {
- map.type = FEC_WILDCARD;
- map.label = NO_LABEL;
+ memset(&map, 0, sizeof(map));
+ map.type = MAP_TYPE_WILDCARD;
+ map.label = label;
}
/* SWd.1: send label withdraw. */
@@ -791,30 +791,35 @@ lde_send_labelwithdraw(struct lde_nbr *ln, struct fec_node *fn)
}
void
-lde_send_labelrelease(struct lde_nbr *ln, struct fec_node *fn, u_int32_t label)
+lde_send_labelwithdraw_all(struct fec_node *fn, uint32_t label)
+{
+ struct lde_nbr *ln;
+
+ RB_FOREACH(ln, nbr_tree, &lde_nbrs)
+ lde_send_labelwithdraw(ln, fn, label);
+}
+
+void
+lde_send_labelrelease(struct lde_nbr *ln, struct fec_node *fn, uint32_t label)
{
struct map map;
- struct fec_nh *fnh = NULL;
struct l2vpn_pw *pw;
- if (fn->fec.type == FEC_TYPE_PWID) {
- fnh = fec_nh_find(fn, ln->id);
- if (fnh == NULL)
- /* not the other end of the pseudowire */
- return;
- }
-
- bzero(&map, sizeof(map));
if (fn) {
lde_fec2map(&fn->fec, &map);
-
if (fn->fec.type == FEC_TYPE_PWID) {
- pw = (struct l2vpn_pw *) fnh->data;
+ pw = (struct l2vpn_pw *) fn->data;
+ if (pw == NULL || pw->lsr_id.s_addr != ln->id.s_addr)
+ /* not the remote end of the pseudowire */
+ return;
+
if (pw->flags & F_PW_CWORD)
map.flags |= F_MAP_PW_CWORD;
}
- } else
- map.type = FEC_WILDCARD;
+ } else {
+ memset(&map, 0, sizeof(map));
+ map.type = MAP_TYPE_WILDCARD;
+ }
map.label = label;
lde_imsg_compose_ldpe(IMSG_RELEASE_ADD, ln->peerid, 0,
@@ -823,30 +828,21 @@ lde_send_labelrelease(struct lde_nbr *ln, struct fec_node *fn, u_int32_t label)
}
void
-lde_send_notification(u_int32_t peerid, u_int32_t code, u_int32_t msgid,
- u_int32_t type)
+lde_send_notification(uint32_t peerid, uint32_t code, uint32_t msgid,
+ uint16_t type)
{
struct notify_msg nm;
- bzero(&nm, sizeof(nm));
-
- /* Every field is in host byte order, to keep things clear */
+ memset(&nm, 0, sizeof(nm));
nm.status = code;
- nm.messageid = ntohl(msgid);
+ /* 'msgid' and 'type' should be in network byte order */
+ nm.messageid = msgid;
nm.type = type;
lde_imsg_compose_ldpe(IMSG_NOTIFICATION_SEND, peerid, 0,
&nm, sizeof(nm));
}
-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);
-
static __inline int
lde_nbr_compare(struct lde_nbr *a, struct lde_nbr *b)
{
@@ -854,17 +850,7 @@ lde_nbr_compare(struct lde_nbr *a, struct lde_nbr *b)
}
struct lde_nbr *
-lde_nbr_find(u_int32_t peerid)
-{
- struct lde_nbr n;
-
- n.peerid = peerid;
-
- return (RB_FIND(nbr_tree, &lde_nbrs, &n));
-}
-
-struct lde_nbr *
-lde_nbr_new(u_int32_t peerid, struct in_addr *id)
+lde_nbr_new(uint32_t peerid, struct in_addr *id)
{
struct lde_nbr *ln;
diff --git a/usr.sbin/ldpd/lde.h b/usr.sbin/ldpd/lde.h
index 36dbbf040ab..4054635d2fa 100644
--- a/usr.sbin/ldpd/lde.h
+++ b/usr.sbin/ldpd/lde.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: lde.h,v 1.31 2016/05/23 16:33:32 renato Exp $ */
+/* $OpenBSD: lde.h,v 1.32 2016/05/23 17:43:42 renato Exp $ */
/*
* Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org>
@@ -39,12 +39,12 @@ struct fec {
union {
struct {
struct in_addr prefix;
- u_int8_t prefixlen;
+ uint8_t prefixlen;
} ipv4;
struct {
- u_int16_t type;
- u_int32_t pwid;
- struct in_addr nexthop;
+ uint16_t type;
+ uint32_t pwid;
+ struct in_addr lsr_id;
} pwid;
} u;
};
@@ -54,7 +54,7 @@ extern struct fec_tree ft;
/* request entries */
struct lde_req {
struct fec fec;
- u_int32_t msgid;
+ uint32_t msgid;
};
/* mapping entries */
@@ -68,7 +68,7 @@ struct lde_map {
/* withdraw entries */
struct lde_wdraw {
struct fec fec;
- u_int32_t label;
+ uint32_t label;
};
/* Addresses belonging to neighbor */
@@ -89,49 +89,50 @@ struct lde_nbr {
struct fec_tree sent_wdraw;
TAILQ_HEAD(, lde_addr) addr_list;
- u_int32_t peerid;
+ uint32_t peerid;
};
struct fec_nh {
- LIST_ENTRY(fec_nh) entry;
-
- struct in_addr nexthop;
- u_int32_t remote_label;
- void *data; /* fec specific data */
+ LIST_ENTRY(fec_nh) entry;
+ struct in_addr nexthop;
+ uint32_t remote_label;
};
struct fec_node {
- struct fec fec;
+ struct fec fec;
- LIST_HEAD(, fec_nh) nexthops; /* fib nexthops */
- LIST_HEAD(, lde_map) downstream; /* recv mappings */
- LIST_HEAD(, lde_map) upstream; /* sent mappings */
+ LIST_HEAD(, fec_nh) nexthops; /* fib nexthops */
+ LIST_HEAD(, lde_map) downstream; /* recv mappings */
+ LIST_HEAD(, lde_map) upstream; /* sent mappings */
- u_int32_t local_label;
+ uint32_t local_label;
+ void *data; /* fec specific data */
};
/* lde.c */
pid_t lde(struct ldpd_conf *, int [2], int [2], int [2]);
-int lde_imsg_compose_parent(int, pid_t, void *, u_int16_t);
-int lde_imsg_compose_ldpe(int, u_int32_t, pid_t, void *, u_int16_t);
-u_int32_t lde_assign_label(void);
+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 *);
-void lde_send_labelrelease(struct lde_nbr *, struct fec_node *, u_int32_t);
-void lde_send_notification(u_int32_t, u_int32_t, u_int32_t, u_int32_t);
-
+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(struct in_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_wdraw *lde_wdraw_add(struct lde_nbr *, struct fec_node *);
void lde_wdraw_del(struct lde_nbr *, struct lde_wdraw *);
-struct lde_nbr *lde_find_address(struct in_addr);
+void lde_change_egress_label(int);
int lde_address_add(struct lde_nbr *, struct in_addr *);
struct lde_addr *lde_address_find(struct lde_nbr *, struct in_addr *);
@@ -149,6 +150,7 @@ void fec_snap(struct lde_nbr *);
void fec_tree_clear(void);
struct fec_nh *fec_nh_find(struct fec_node *, struct in_addr);
+uint32_t egress_label(enum fec_type);
void lde_kernel_insert(struct fec *, struct in_addr, int, void *);
void lde_kernel_remove(struct fec *, struct in_addr);
void lde_check_mapping(struct map *, struct lde_nbr *);
@@ -174,8 +176,8 @@ 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 *,
- struct map *);
-void l2vpn_send_pw_status(u_int32_t, u_int32_t, struct fec *);
+ struct map *);
+void l2vpn_send_pw_status(uint32_t, uint32_t, struct fec *);
void l2vpn_recv_pw_status(struct lde_nbr *, struct notify_msg *);
void l2vpn_sync_pws(struct in_addr);
void l2vpn_pw_ctl(pid_t);
diff --git a/usr.sbin/ldpd/lde_lib.c b/usr.sbin/ldpd/lde_lib.c
index 7b6520c12a7..49fcde639fd 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.48 2016/05/23 16:54:22 renato Exp $ */
+/* $OpenBSD: lde_lib.c,v 1.49 2016/05/23 17:43:42 renato Exp $ */
/*
* Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
@@ -289,6 +289,22 @@ fec_nh_del(struct fec_nh *fnh)
free(fnh);
}
+uint32_t
+egress_label(enum fec_type fec_type)
+{
+ if (!(ldeconf->flags & F_LDPD_EXPNULL))
+ return (MPLS_LABEL_IMPLNULL);
+
+ switch (fec_type) {
+ case FEC_TYPE_IPV4:
+ return (MPLS_LABEL_IPV4NULL);
+ default:
+ log_warnx("%s: unexpected fec type", __func__);
+ }
+
+ return (NO_LABEL);
+}
+
void
lde_kernel_insert(struct fec *fec, struct in_addr nexthop, int connected,
void *data)
@@ -314,24 +330,22 @@ lde_kernel_insert(struct fec *fec, struct in_addr nexthop, int connected,
if (LIST_EMPTY(&fn->nexthops)) {
if (fn->local_label == NO_LABEL) {
if (connected)
- fn->local_label = MPLS_LABEL_IMPLNULL;
+ fn->local_label = egress_label(fn->fec.type);
else
fn->local_label = lde_assign_label();
} else {
/* Handle local label changes */
if (connected &&
- fn->local_label != MPLS_LABEL_IMPLNULL) {
+ fn->local_label < MPLS_LABEL_RESERVED_MAX) {
/* explicit withdraw of the previous label */
- RB_FOREACH(ln, nbr_tree, &lde_nbrs)
- lde_send_labelwithdraw(ln, fn);
- fn->local_label = MPLS_LABEL_IMPLNULL;
+ lde_send_labelwithdraw_all(fn, NO_LABEL);
+ fn->local_label = egress_label(fn->fec.type);
}
if (!connected &&
- fn->local_label == MPLS_LABEL_IMPLNULL) {
+ fn->local_label < MPLS_LABEL_RESERVED_MAX) {
/* explicit withdraw of the previous label */
- RB_FOREACH(ln, nbr_tree, &lde_nbrs)
- lde_send_labelwithdraw(ln, fn);
+ lde_send_labelwithdraw_all(fn, NO_LABEL);
fn->local_label = lde_assign_label();
}
}
@@ -370,7 +384,6 @@ lde_kernel_remove(struct fec *fec, struct in_addr nexthop)
{
struct fec_node *fn;
struct fec_nh *fnh;
- struct lde_nbr *ln;
log_debug("lde remove fec %s nexthop %s",
log_fec(fec), inet_ntoa(nexthop));
@@ -387,9 +400,11 @@ lde_kernel_remove(struct fec *fec, struct in_addr nexthop)
lde_send_delete_klabel(fn, fnh);
fec_nh_del(fnh);
- if (LIST_EMPTY(&fn->nexthops))
- RB_FOREACH(ln, nbr_tree, &lde_nbrs)
- lde_send_labelwithdraw(ln, fn);
+ if (LIST_EMPTY(&fn->nexthops)) {
+ lde_send_labelwithdraw_all(fn, NO_LABEL);
+ if (fn->fec.type == FEC_TYPE_PWID)
+ fn->data = NULL;
+ }
}
void
diff --git a/usr.sbin/ldpd/ldp.h b/usr.sbin/ldpd/ldp.h
index e72b8fa31eb..505e6952989 100644
--- a/usr.sbin/ldpd/ldp.h
+++ b/usr.sbin/ldpd/ldp.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ldp.h,v 1.25 2016/05/23 16:33:32 renato Exp $ */
+/* $OpenBSD: ldp.h,v 1.26 2016/05/23 17:43:42 renato Exp $ */
/*
* Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
@@ -96,10 +96,10 @@
/* LDP header */
struct ldp_hdr {
- u_int16_t version;
- u_int16_t length;
- u_int32_t lsr_id;
- u_int16_t lspace_id;
+ uint16_t version;
+ uint16_t length;
+ uint32_t lsr_id;
+ uint16_t lspace_id;
} __packed;
#define LDP_HDR_SIZE 10 /* actual size of the LDP header */
@@ -108,15 +108,15 @@ struct ldp_hdr {
/* TLV record */
struct tlv {
- u_int16_t type;
- u_int16_t length;
+ uint16_t type;
+ uint16_t length;
};
#define TLV_HDR_LEN 4
struct ldp_msg {
- u_int16_t type;
- u_int16_t length;
- u_int32_t msgid;
+ uint16_t type;
+ uint16_t length;
+ uint32_t msgid;
/* Mandatory Parameters */
/* Optional Parameters */
} __packed;
@@ -129,19 +129,19 @@ struct ldp_msg {
#define FORWARD_FLAG 0xc000
struct hello_prms_tlv {
- u_int16_t type;
- u_int16_t length;
- u_int16_t holdtime;
- u_int16_t flags;
+ uint16_t type;
+ uint16_t length;
+ uint16_t holdtime;
+ uint16_t flags;
};
#define TARGETED_HELLO 0x8000
#define REQUEST_TARG_HELLO 0x4000
struct hello_prms_opt4_tlv {
- u_int16_t type;
- u_int16_t length;
- u_int32_t value;
+ uint16_t type;
+ uint16_t length;
+ uint32_t value;
};
@@ -182,25 +182,25 @@ struct hello_prms_opt4_tlv {
#define S_WITHDRAW_MTHD 0x0000002B
struct sess_prms_tlv {
- u_int16_t type;
- u_int16_t length;
- u_int16_t proto_version;
- u_int16_t keepalive_time;
- u_int8_t reserved;
- u_int8_t pvlim;
- u_int16_t max_pdu_len;
- u_int32_t lsr_id;
- u_int16_t lspace_id;
+ uint16_t type;
+ uint16_t length;
+ uint16_t proto_version;
+ uint16_t keepalive_time;
+ uint8_t reserved;
+ uint8_t pvlim;
+ uint16_t max_pdu_len;
+ uint32_t lsr_id;
+ uint16_t lspace_id;
} __packed;
#define SESS_PRMS_SIZE 18
struct status_tlv {
- u_int16_t type;
- u_int16_t length;
- u_int32_t status_code;
- u_int32_t msg_id;
- u_int16_t msg_type;
+ uint16_t type;
+ uint16_t length;
+ uint32_t status_code;
+ uint32_t msg_id;
+ uint16_t msg_type;
} __packed;
#define STATUS_SIZE 14
@@ -211,9 +211,9 @@ struct status_tlv {
#define AF_IPV6 0x2
struct address_list_tlv {
- u_int16_t type;
- u_int16_t length;
- u_int16_t family;
+ uint16_t type;
+ uint16_t length;
+ uint16_t family;
/* address entries */
} __packed;
@@ -233,8 +233,8 @@ struct address_list_tlv {
/* RFC 4447 Sub-TLV record */
struct subtlv {
- u_int8_t type;
- u_int8_t length;
+ uint8_t type;
+ uint8_t length;
};
#define SUBTLV_HDR_LEN 2
@@ -245,25 +245,25 @@ struct subtlv {
#define FEC_SUBTLV_VLANID_LEN 4
struct label_tlv {
- u_int16_t type;
- u_int16_t length;
- u_int32_t label;
+ uint16_t type;
+ uint16_t length;
+ uint32_t label;
};
#define LABEL_TLV_LEN 8
struct reqid_tlv {
- u_int16_t type;
- u_int16_t length;
- u_int32_t reqid;
+ uint16_t type;
+ uint16_t length;
+ uint32_t reqid;
};
#define REQID_TLV_LEN 8
struct pw_status_tlv {
- u_int16_t type;
- u_int16_t length;
- u_int32_t value;
+ uint16_t type;
+ uint16_t length;
+ uint32_t value;
};
#define PW_STATUS_TLV_LEN 8
diff --git a/usr.sbin/ldpd/ldpd.8 b/usr.sbin/ldpd/ldpd.8
index 5f8b55e1daa..501b933f955 100644
--- a/usr.sbin/ldpd/ldpd.8
+++ b/usr.sbin/ldpd/ldpd.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: ldpd.8,v 1.12 2016/05/23 15:05:58 renato Exp $
+.\" $OpenBSD: ldpd.8,v 1.13 2016/05/23 17:43:42 renato Exp $
.\"
.\" Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
.\" Copyright (c) 2004, 2005, 2006 Esben Norby <norby@openbsd.org>
diff --git a/usr.sbin/ldpd/ldpd.c b/usr.sbin/ldpd/ldpd.c
index a5c0b67a946..dbf786da94f 100644
--- a/usr.sbin/ldpd/ldpd.c
+++ b/usr.sbin/ldpd/ldpd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ldpd.c,v 1.36 2016/05/23 16:54:22 renato Exp $ */
+/* $OpenBSD: ldpd.c,v 1.37 2016/05/23 17:43:42 renato Exp $ */
/*
* Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org>
@@ -54,9 +54,14 @@ 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);
int ldp_reload(void);
-int ldp_sendboth(enum imsg_type, void *, u_int16_t);
-void merge_l2vpns(struct ldpd_conf *, struct l2vpn *, struct l2vpn *);
+void merge_global(struct ldpd_conf *, struct ldpd_conf *);
+void merge_ifaces(struct ldpd_conf *, struct ldpd_conf *);
+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];
@@ -119,11 +124,13 @@ usage(void)
exit(1);
}
+struct ldpd_global global;
+
int
main(int argc, char *argv[])
{
struct event ev_sigint, ev_sigterm, ev_sigchld, ev_sighup;
- int ch, opts = 0;
+ int ch;
int debug = 0;
conffile = CONF_FILE;
@@ -146,12 +153,12 @@ main(int argc, char *argv[])
conffile = optarg;
break;
case 'n':
- opts |= LDPD_OPT_NOACTION;
+ global.cmd_opts |= LDPD_OPT_NOACTION;
break;
case 'v':
- if (opts & LDPD_OPT_VERBOSE)
- opts |= LDPD_OPT_VERBOSE2;
- opts |= LDPD_OPT_VERBOSE;
+ if (global.cmd_opts & LDPD_OPT_VERBOSE)
+ global.cmd_opts |= LDPD_OPT_VERBOSE2;
+ global.cmd_opts |= LDPD_OPT_VERBOSE;
break;
default:
usage();
@@ -163,14 +170,17 @@ main(int argc, char *argv[])
kif_init();
/* parse config file */
- if ((ldpd_conf = parse_config(conffile, opts)) == NULL )
+ if ((ldpd_conf = parse_config(conffile)) == NULL ) {
+ kif_clear();
exit(1);
+ }
- if (ldpd_conf->opts & LDPD_OPT_NOACTION) {
- if (ldpd_conf->opts & LDPD_OPT_VERBOSE)
+ if (global.cmd_opts & LDPD_OPT_NOACTION) {
+ if (global.cmd_opts & LDPD_OPT_VERBOSE)
print_config(ldpd_conf);
else
fprintf(stderr, "configuration OK\n");
+ kif_clear();
exit(0);
}
@@ -183,7 +193,7 @@ main(int argc, char *argv[])
errx(1, "unknown user %s", LDPD_USER);
log_init(debug);
- log_verbose(opts & (LDPD_OPT_VERBOSE | LDPD_OPT_VERBOSE2));
+ log_verbose(global.cmd_opts & (LDPD_OPT_VERBOSE | LDPD_OPT_VERBOSE2));
if (!debug)
daemon(1, 0);
@@ -466,7 +476,7 @@ main_dispatch_lde(int fd, short event, void *bula)
}
void
-main_imsg_compose_ldpe(int type, pid_t pid, void *data, u_int16_t datalen)
+main_imsg_compose_ldpe(int type, pid_t pid, void *data, uint16_t datalen)
{
if (iev_ldpe == NULL)
return;
@@ -474,7 +484,7 @@ main_imsg_compose_ldpe(int type, pid_t pid, void *data, u_int16_t datalen)
}
void
-main_imsg_compose_lde(int type, pid_t pid, void *data, u_int16_t datalen)
+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);
}
@@ -502,8 +512,8 @@ imsg_event_add(struct imsgev *iev)
}
int
-imsg_compose_event(struct imsgev *iev, u_int16_t type,
- u_int32_t peerid, pid_t pid, int fd, void *data, u_int16_t datalen)
+imsg_compose_event(struct imsgev *iev, uint16_t type, uint32_t peerid,
+ pid_t pid, int fd, void *data, uint16_t datalen)
{
int ret;
@@ -555,7 +565,7 @@ ldp_reload(void)
struct l2vpn_pw *pw;
struct ldpd_conf *xconf;
- if ((xconf = parse_config(conffile, ldpd_conf->opts)) == NULL)
+ if ((xconf = parse_config(conffile)) == NULL)
return (-1);
if (main_imsg_compose_both(IMSG_RECONF_CONF, xconf,
@@ -605,33 +615,54 @@ ldp_reload(void)
return (0);
}
-int
-ldp_sendboth(enum imsg_type type, void *buf, u_int16_t len)
+void
+merge_config(struct ldpd_conf *conf, struct ldpd_conf *xconf)
{
- if (imsg_compose_event(iev_ldpe, type, 0, 0, -1, buf, len) == -1)
- return (-1);
- if (imsg_compose_event(iev_lde, type, 0, 0, -1, buf, len) == -1)
- return (-1);
- return (0);
+ merge_global(conf, xconf);
+ merge_ifaces(conf, xconf);
+ merge_tnbrs(conf, xconf);
+ merge_nbrps(conf, xconf);
+ merge_l2vpns(conf, xconf);
+ free(xconf);
}
void
-merge_config(struct ldpd_conf *conf, struct ldpd_conf *xconf)
+merge_global(struct ldpd_conf *conf, struct ldpd_conf *xconf)
{
- struct iface *iface, *itmp, *xi;
- struct tnbr *tnbr, *ttmp, *xt;
- struct nbr_params *nbrp, *ntmp, *xn;
- struct l2vpn *l2vpn, *ltmp, *xl;
- struct nbr *nbr;
+ int egress_label_changed = 0;
/* change of rtr_id needs a restart */
- conf->flags = xconf->flags;
conf->keepalive = xconf->keepalive;
conf->thello_holdtime = xconf->thello_holdtime;
conf->thello_interval = xconf->thello_interval;
conf->trans_addr.s_addr = xconf->trans_addr.s_addr;
- /* merge interfaces */
+ /* update flags */
+ if ((conf->flags & F_LDPD_EXPNULL) !=
+ (xconf->flags & F_LDPD_EXPNULL))
+ egress_label_changed = 1;
+
+ conf->flags = xconf->flags;
+
+ if (egress_label_changed) {
+ switch (ldpd_process) {
+ case PROC_LDE_ENGINE:
+ lde_change_egress_label(conf->flags & F_LDPD_EXPNULL);
+ break;
+ case PROC_MAIN:
+ kr_change_egress_label(conf->flags & F_LDPD_EXPNULL);
+ break;
+ default:
+ break;
+ }
+ }
+}
+
+void
+merge_ifaces(struct ldpd_conf *conf, struct ldpd_conf *xconf)
+{
+ struct iface *iface, *itmp, *xi;
+
LIST_FOREACH_SAFE(iface, &conf->iface_list, entry, itmp) {
/* find deleted interfaces */
if ((xi = if_lookup(xconf, iface->ifindex)) == NULL) {
@@ -648,7 +679,7 @@ merge_config(struct ldpd_conf *conf, struct ldpd_conf *xconf)
LIST_REMOVE(xi, entry);
LIST_INSERT_HEAD(&conf->iface_list, xi, entry);
if (ldpd_process == PROC_LDP_ENGINE)
- if_init(conf, xi);
+ if_init(xi);
continue;
}
@@ -687,7 +718,7 @@ merge_tnbrs(struct ldpd_conf *conf, struct ldpd_conf *xconf)
LIST_REMOVE(xt, entry);
LIST_INSERT_HEAD(&conf->tnbr_list, xt, entry);
if (ldpd_process == PROC_LDP_ENGINE)
- tnbr_init(conf, xt);
+ tnbr_init(xt);
continue;
}
diff --git a/usr.sbin/ldpd/ldpd.conf.5 b/usr.sbin/ldpd/ldpd.conf.5
index 6011d4b4312..b65e1deed66 100644
--- a/usr.sbin/ldpd/ldpd.conf.5
+++ b/usr.sbin/ldpd/ldpd.conf.5
@@ -1,4 +1,4 @@
-.\" $OpenBSD: ldpd.conf.5,v 1.24 2016/05/23 16:18:51 renato Exp $
+.\" $OpenBSD: ldpd.conf.5,v 1.25 2016/05/23 17:43:42 renato Exp $
.\"
.\" Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
.\" Copyright (c) 2005, 2006 Esben Norby <norby@openbsd.org>
@@ -67,14 +67,14 @@ macros can be defined that will later be expanded in context.
Macro names must start with a letter, digit, or underscore,
and may contain any of those characters.
Macro names may not be reserved words (for example,
-.Ic cost ) .
+.Ic password ) .
Macros are not expanded inside quotes.
.Pp
For example:
.Bd -literal -offset indent
-hi="2"
-interface em0 {
- cost $hi
+secret="openbsd"
+neighbor 10.0.1.5 {
+ password $secret
}
.Ed
.Sh GLOBAL CONFIGURATION
diff --git a/usr.sbin/ldpd/ldpd.h b/usr.sbin/ldpd/ldpd.h
index e7070c58f70..d948c2fd60c 100644
--- a/usr.sbin/ldpd/ldpd.h
+++ b/usr.sbin/ldpd/ldpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ldpd.h,v 1.64 2016/05/23 17:00:40 renato Exp $ */
+/* $OpenBSD: ldpd.h,v 1.65 2016/05/23 17:43:42 renato Exp $ */
/*
* Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
@@ -37,6 +37,10 @@
#define LDPD_SOCKET "/var/run/ldpd.sock"
#define LDPD_USER "_ldpd"
+#define LDPD_OPT_VERBOSE 0x00000001
+#define LDPD_OPT_VERBOSE2 0x00000002
+#define LDPD_OPT_NOACTION 0x00000004
+
#define TCP_MD5_KEY_LEN 80
#define L2VPN_NAME_LEN 32
@@ -44,9 +48,6 @@
#define MAX_RTSOCK_BUF 128 * 1024
#define LDP_BACKLOG 128
-#define LDPD_FLAG_NO_FIB_UPDATE 0x0001
-#define LDPD_FLAG_TH_ACCEPT 0x0002
-
#define F_LDPD_INSERTED 0x0001
#define F_CONNECTED 0x0002
#define F_STATIC 0x0004
@@ -169,24 +170,24 @@ enum nbr_action {
TAILQ_HEAD(mapping_head, mapping_entry);
struct map {
- u_int8_t type;
- u_int32_t messageid;
+ uint8_t type;
+ uint32_t messageid;
union map_fec {
struct {
struct in_addr prefix;
- u_int8_t prefixlen;
+ uint8_t prefixlen;
} ipv4;
struct {
- u_int16_t type;
- u_int32_t pwid;
- u_int32_t group_id;
- u_int16_t ifmtu;
+ uint16_t type;
+ uint32_t pwid;
+ uint32_t group_id;
+ uint16_t ifmtu;
} pwid;
} fec;
- u_int32_t label;
- u_int32_t requestid;
- u_int32_t pw_status;
- u_int8_t flags;
+ uint32_t label;
+ uint32_t requestid;
+ uint32_t pw_status;
+ uint8_t flags;
};
#define F_MAP_REQ_ID 0x01 /* optional request message id present */
#define F_MAP_PW_CWORD 0x02 /* pseudowire control word */
@@ -195,12 +196,12 @@ struct map {
#define F_MAP_PW_STATUS 0x10 /* pseudowire status */
struct notify_msg {
- u_int32_t messageid;
- u_int32_t status;
- u_int32_t type;
- u_int32_t pw_status;
+ uint32_t status;
+ uint32_t messageid; /* network byte order */
+ uint16_t type; /* network byte order */
+ uint32_t pw_status;
struct map fec;
- u_int8_t flags;
+ uint8_t flags;
};
#define F_NOTIF_PW_STATUS 0x01 /* pseudowire status tlv present */
#define F_NOTIF_FEC 0x02 /* fec tlv present */
@@ -224,12 +225,12 @@ struct iface {
time_t uptime;
unsigned int ifindex;
int state;
- u_int16_t hello_holdtime;
- u_int16_t hello_interval;
- u_int16_t flags;
+ uint16_t hello_holdtime;
+ uint16_t hello_interval;
+ uint16_t flags;
enum iface_type type;
- u_int8_t if_type;
- u_int8_t linkstate;
+ uint8_t if_type;
+ uint8_t linkstate;
};
/* source of targeted hellos */
@@ -239,10 +240,10 @@ struct tnbr {
struct adj *adj;
struct in_addr addr;
- u_int16_t hello_holdtime;
- u_int16_t hello_interval;
- u_int16_t pw_count;
- u_int8_t flags;
+ uint16_t hello_holdtime;
+ uint16_t hello_interval;
+ uint16_t pw_count;
+ uint8_t flags;
};
#define F_TNBR_CONFIGURED 0x01
#define F_TNBR_DYNAMIC 0x02
@@ -255,34 +256,37 @@ enum auth_method {
/* neighbor specific parameters */
struct nbr_params {
LIST_ENTRY(nbr_params) entry;
- struct in_addr addr;
+ struct in_addr lsr_id;
+ uint16_t keepalive;
struct {
enum auth_method method;
char md5key[TCP_MD5_KEY_LEN];
- u_int8_t md5key_len;
+ uint8_t md5key_len;
} auth;
+ uint8_t flags;
};
+#define F_NBRP_KEEPALIVE 0x01
struct l2vpn_if {
LIST_ENTRY(l2vpn_if) entry;
struct l2vpn *l2vpn;
char ifname[IF_NAMESIZE];
unsigned int ifindex;
- u_int16_t flags;
- u_int8_t link_state;
+ uint16_t flags;
+ uint8_t link_state;
};
struct l2vpn_pw {
LIST_ENTRY(l2vpn_pw) entry;
struct l2vpn *l2vpn;
- struct in_addr addr;
- u_int32_t pwid;
+ struct in_addr lsr_id;
+ uint32_t pwid;
char ifname[IF_NAMESIZE];
unsigned int ifindex;
- u_int32_t remote_group;
- u_int16_t remote_mtu;
- u_int32_t remote_status;
- u_int8_t flags;
+ uint32_t remote_group;
+ uint16_t remote_mtu;
+ uint32_t remote_status;
+ uint8_t flags;
};
#define F_PW_STATUSTLV_CONF 0x01 /* status tlv configured */
#define F_PW_STATUSTLV 0x02 /* status tlv negotiated */
@@ -317,51 +321,57 @@ enum hello_type {
};
struct ldpd_conf {
- struct in_addr rtr_id;
- LIST_HEAD(, iface) iface_list;
- struct if_addr_head addr_list;
- LIST_HEAD(, tnbr) tnbr_list;
- LIST_HEAD(, nbr_params) nbrp_list;
- LIST_HEAD(, l2vpn) l2vpn_list;
-
- u_int32_t opts;
-#define LDPD_OPT_VERBOSE 0x00000001
-#define LDPD_OPT_VERBOSE2 0x00000002
-#define LDPD_OPT_NOACTION 0x00000004
- time_t uptime;
- int pfkeysock;
- int ldp_discovery_socket;
- int ldp_ediscovery_socket;
- int ldp_session_socket;
- int flags;
- u_int16_t keepalive;
- u_int16_t thello_holdtime;
- u_int16_t thello_interval;
+ struct in_addr rtr_id;
+ struct in_addr trans_addr;
+ LIST_HEAD(, iface) iface_list;
+ LIST_HEAD(, tnbr) tnbr_list;
+ LIST_HEAD(, nbr_params) nbrp_list;
+ LIST_HEAD(, l2vpn) l2vpn_list;
+ uint16_t keepalive;
+ uint16_t thello_holdtime;
+ uint16_t thello_interval;
+ int flags;
+};
+#define F_LDPD_NO_FIB_UPDATE 0x0001
+#define F_LDPD_TH_ACCEPT 0x0002
+#define F_LDPD_EXPNULL 0x0004
+
+struct ldpd_global {
+ int cmd_opts;
+ time_t uptime;
+ int pfkeysock;
+ int ldp_disc_socket;
+ int ldp_edisc_socket;
+ int ldp_session_socket;
+ struct if_addr_head addr_list;
+ TAILQ_HEAD(, pending_conn) pending_conns;
};
+extern struct ldpd_global global;
+
/* kroute */
struct kroute {
- struct in_addr prefix;
- struct in_addr nexthop;
- u_int32_t local_label;
- u_int32_t remote_label;
- u_int16_t flags;
- u_short ifindex;
- u_int8_t prefixlen;
- u_int8_t priority;
+ struct in_addr prefix;
+ struct in_addr nexthop;
+ uint32_t local_label;
+ uint32_t remote_label;
+ uint16_t flags;
+ unsigned short ifindex;
+ uint8_t prefixlen;
+ uint8_t priority;
};
struct kpw {
- u_short ifindex;
+ unsigned short ifindex;
int pw_type;
struct in_addr nexthop;
- u_int32_t local_label;
- u_int32_t remote_label;
- u_int8_t flags;
+ uint32_t local_label;
+ uint32_t remote_label;
+ uint8_t flags;
};
struct kaddr {
- u_short ifindex;
+ unsigned short ifindex;
struct in_addr addr;
struct in_addr mask;
struct in_addr dstbrd;
@@ -369,12 +379,12 @@ struct kaddr {
struct kif {
char ifname[IF_NAMESIZE];
- u_int64_t baudrate;
+ uint64_t baudrate;
int flags;
int mtu;
- u_short ifindex;
- u_int8_t if_type;
- u_int8_t link_state;
+ unsigned short ifindex;
+ uint8_t if_type;
+ uint8_t link_state;
};
/* control data structures */
@@ -383,13 +393,13 @@ struct ctl_iface {
time_t uptime;
unsigned int ifindex;
int state;
- u_int16_t adj_cnt;
- u_int16_t flags;
- u_int16_t hello_holdtime;
- u_int16_t hello_interval;
+ uint16_t adj_cnt;
+ uint16_t flags;
+ uint16_t hello_holdtime;
+ uint16_t hello_interval;
enum iface_type type;
- u_int8_t linkstate;
- u_int8_t if_type;
+ uint8_t linkstate;
+ uint8_t if_type;
};
struct ctl_adj {
@@ -397,7 +407,7 @@ struct ctl_adj {
enum hello_type type;
char ifname[IF_NAMESIZE];
struct in_addr src_addr;
- u_int16_t holdtime;
+ uint16_t holdtime;
};
struct ctl_nbr {
@@ -409,30 +419,30 @@ struct ctl_nbr {
struct ctl_rt {
struct in_addr prefix;
- u_int8_t prefixlen;
+ uint8_t prefixlen;
struct in_addr nexthop;
- u_int32_t local_label;
- u_int32_t remote_label;
- u_int8_t flags;
- u_int8_t in_use;
+ uint32_t local_label;
+ uint32_t remote_label;
+ uint8_t flags;
+ uint8_t in_use;
};
struct ctl_pw {
- u_int16_t type;
+ uint16_t type;
char ifname[IF_NAMESIZE];
- u_int32_t pwid;
- struct in_addr nexthop;
- u_int32_t local_label;
- u_int32_t local_gid;
- u_int16_t local_ifmtu;
- u_int32_t remote_label;
- u_int32_t remote_gid;
- u_int16_t remote_ifmtu;
- u_int32_t status;
+ uint32_t pwid;
+ struct in_addr lsr_id;
+ uint32_t local_label;
+ uint32_t local_gid;
+ uint16_t local_ifmtu;
+ uint32_t remote_label;
+ uint32_t remote_gid;
+ uint16_t remote_ifmtu;
+ uint32_t status;
};
/* parse.y */
-struct ldpd_conf *parse_config(char *, int);
+struct ldpd_conf *parse_config(char *);
int cmdline_symset(char *);
/* kroute.c */
@@ -445,12 +455,13 @@ void kif_clear(void);
void kr_shutdown(void);
void kr_fib_couple(void);
void kr_fib_decouple(void);
+void kr_change_egress_label(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 *);
-u_int8_t mask2prefixlen(in_addr_t);
-in_addr_t prefixlen2mask(u_int8_t);
+uint8_t mask2prefixlen(in_addr_t);
+in_addr_t prefixlen2mask(uint8_t);
void kmpw_set(struct kpw *);
void kmpw_unset(struct kpw *);
void kmpw_install(const char *, struct kpw *);
@@ -460,18 +471,18 @@ void kmpw_uninstall(const char *, struct kpw *);
const char *nbr_state_name(int);
const char *if_state_name(int);
const char *if_type_name(enum iface_type);
-const char *notification_name(u_int32_t);
+const char *notification_name(uint32_t);
/* util.c */
int bad_ip_addr(struct in_addr);
/* ldpd.c */
-void main_imsg_compose_ldpe(int, pid_t, void *, u_int16_t);
-void main_imsg_compose_lde(int, pid_t, void *, u_int16_t);
+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 *, u_int16_t, u_int32_t, pid_t,
- int, void *, u_int16_t);
+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 *);
diff --git a/usr.sbin/ldpd/ldpe.c b/usr.sbin/ldpd/ldpe.c
index 1faeee41e3e..9b47ece2c04 100644
--- a/usr.sbin/ldpd/ldpe.c
+++ b/usr.sbin/ldpd/ldpe.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ldpe.c,v 1.48 2016/05/23 15:51:36 renato Exp $ */
+/* $OpenBSD: ldpe.c,v 1.49 2016/05/23 17:43:42 renato Exp $ */
/*
* Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org>
@@ -99,85 +99,84 @@ ldpe(struct ldpd_conf *xconf, int pipe_parent2ldpe[2], int pipe_ldpe2lde[2],
if (control_init() == -1)
fatalx("control socket setup failed");
- leconf->pfkeysock = pfkey_init(&sysdep);
+ LIST_INIT(&global.addr_list);
+ TAILQ_INIT(&global.pending_conns);
+ global.pfkeysock = pfkey_init(&sysdep);
/* create the discovery UDP socket */
- disc_addr.sin_family = AF_INET;
- disc_addr.sin_port = htons(LDP_PORT);
- disc_addr.sin_addr.s_addr = INADDR_ANY;
-
- if ((xconf->ldp_discovery_socket = socket(AF_INET,
+ if ((global.ldp_disc_socket = socket(AF_INET,
SOCK_DGRAM | SOCK_NONBLOCK | SOCK_CLOEXEC,
IPPROTO_UDP)) == -1)
fatal("error creating discovery socket");
- if (if_set_reuse(xconf->ldp_discovery_socket, 1) == -1)
- fatal("if_set_reuse");
+ if (sock_set_reuse(global.ldp_disc_socket, 1) == -1)
+ fatal("sock_set_reuse");
- if (bind(xconf->ldp_discovery_socket, (struct sockaddr *)&disc_addr,
+ disc_addr.sin_family = AF_INET;
+ disc_addr.sin_port = htons(LDP_PORT);
+ disc_addr.sin_addr.s_addr = INADDR_ANY;
+ if (bind(global.ldp_disc_socket, (struct sockaddr *)&disc_addr,
sizeof(disc_addr)) == -1)
fatal("error binding discovery socket");
/* set some defaults */
- if (if_set_mcast_ttl(xconf->ldp_discovery_socket,
+ if (sock_set_ipv4_mcast_ttl(global.ldp_disc_socket,
IP_DEFAULT_MULTICAST_TTL) == -1)
- fatal("if_set_mcast_ttl");
- if (if_set_mcast_loop(xconf->ldp_discovery_socket) == -1)
- fatal("if_set_mcast_loop");
- if (if_set_tos(xconf->ldp_discovery_socket,
+ fatal("sock_set_ipv4_mcast_ttl");
+ if (sock_set_ipv4_mcast_loop(global.ldp_disc_socket) == -1)
+ fatal("sock_set_ipv4_mcast_loop");
+ if (sock_set_ipv4_tos(global.ldp_disc_socket,
IPTOS_PREC_INTERNETCONTROL) == -1)
- fatal("if_set_tos");
- if (if_set_recvif(xconf->ldp_discovery_socket, 1) == -1)
- fatal("if_set_recvif");
- if_set_recvbuf(xconf->ldp_discovery_socket);
+ fatal("sock_set_ipv4_tos");
+ if (sock_set_ipv4_recvif(global.ldp_disc_socket, 1) == -1)
+ fatal("sock_set_ipv4_recvif");
+ sock_set_recvbuf(global.ldp_disc_socket);
/* create the extended discovery UDP socket */
- disc_addr.sin_family = AF_INET;
- disc_addr.sin_port = htons(LDP_PORT);
- disc_addr.sin_addr.s_addr = xconf->trans_addr.s_addr;
-
- if ((xconf->ldp_ediscovery_socket = socket(AF_INET,
+ if ((global.ldp_edisc_socket = socket(AF_INET,
SOCK_DGRAM | SOCK_NONBLOCK | SOCK_CLOEXEC,
IPPROTO_UDP)) == -1)
fatal("error creating extended discovery socket");
- if (if_set_reuse(xconf->ldp_ediscovery_socket, 1) == -1)
- fatal("if_set_reuse");
+ if (sock_set_reuse(global.ldp_edisc_socket, 1) == -1)
+ fatal("sock_set_reuse");
- if (bind(xconf->ldp_ediscovery_socket, (struct sockaddr *)&disc_addr,
+ disc_addr.sin_family = AF_INET;
+ disc_addr.sin_port = htons(LDP_PORT);
+ disc_addr.sin_addr.s_addr = xconf->trans_addr.s_addr;
+ if (bind(global.ldp_edisc_socket, (struct sockaddr *)&disc_addr,
sizeof(disc_addr)) == -1)
fatal("error binding extended discovery socket");
/* set some defaults */
- if (if_set_tos(xconf->ldp_ediscovery_socket,
+ if (sock_set_ipv4_tos(global.ldp_edisc_socket,
IPTOS_PREC_INTERNETCONTROL) == -1)
- fatal("if_set_tos");
- if (if_set_recvif(xconf->ldp_ediscovery_socket, 1) == -1)
- fatal("if_set_recvif");
- if_set_recvbuf(xconf->ldp_ediscovery_socket);
+ fatal("sock_set_ipv4_tos");
+ if (sock_set_ipv4_recvif(global.ldp_edisc_socket, 1) == -1)
+ fatal("sock_set_ipv4_recvif");
+ sock_set_recvbuf(global.ldp_edisc_socket);
/* create the session TCP socket */
- sess_addr.sin_family = AF_INET;
- sess_addr.sin_port = htons(LDP_PORT);
- sess_addr.sin_addr.s_addr = INADDR_ANY;
-
- if ((xconf->ldp_session_socket = socket(AF_INET,
+ if ((global.ldp_session_socket = socket(AF_INET,
SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC,
IPPROTO_TCP)) == -1)
fatal("error creating session socket");
- if (if_set_reuse(xconf->ldp_session_socket, 1) == -1)
- fatal("if_set_reuse");
+ if (sock_set_reuse(global.ldp_session_socket, 1) == -1)
+ fatal("sock_set_reuse");
- if (bind(xconf->ldp_session_socket, (struct sockaddr *)&sess_addr,
+ sess_addr.sin_family = AF_INET;
+ sess_addr.sin_port = htons(LDP_PORT);
+ sess_addr.sin_addr = xconf->trans_addr;
+ if (bind(global.ldp_session_socket, (struct sockaddr *)&sess_addr,
sizeof(sess_addr)) == -1)
fatal("error binding session socket");
- if (listen(xconf->ldp_session_socket, LDP_BACKLOG) == -1)
+ if (listen(global.ldp_session_socket, LDP_BACKLOG) == -1)
fatal("error in listen on session socket");
opt = 1;
- if (setsockopt(xconf->ldp_session_socket, IPPROTO_TCP, TCP_MD5SIG,
+ if (setsockopt(global.ldp_session_socket, IPPROTO_TCP, TCP_MD5SIG,
&opt, sizeof(opt)) == -1) {
if (errno == ENOPROTOOPT) { /* system w/o md5sig */
log_warnx("md5sig not available, disabling");
@@ -187,9 +186,9 @@ ldpe(struct ldpd_conf *xconf, int pipe_parent2ldpe[2], int pipe_ldpe2lde[2],
}
/* set some defaults */
- if (if_set_tos(xconf->ldp_session_socket,
+ if (sock_set_ipv4_tos(global.ldp_session_socket,
IPTOS_PREC_INTERNETCONTROL) == -1)
- fatal("if_set_tos");
+ fatal("sock_set_ipv4_tos");
if ((pw = getpwnam(LDPD_USER)) == NULL)
fatal("getpwnam");
@@ -243,19 +242,19 @@ ldpe(struct ldpd_conf *xconf, int pipe_parent2ldpe[2], int pipe_ldpe2lde[2],
iev_main->handler, iev_main);
event_add(&iev_main->ev, NULL);
- event_set(&pfkey_ev, leconf->pfkeysock, EV_READ | EV_PERSIST,
+ event_set(&pfkey_ev, global.pfkeysock, EV_READ | EV_PERSIST,
ldpe_dispatch_pfkey, NULL);
event_add(&pfkey_ev, NULL);
- event_set(&disc_ev, leconf->ldp_discovery_socket,
- EV_READ|EV_PERSIST, disc_recv_packet, NULL);
+ event_set(&disc_ev, global.ldp_disc_socket, EV_READ|EV_PERSIST,
+ disc_recv_packet, NULL);
event_add(&disc_ev, NULL);
- event_set(&edisc_ev, leconf->ldp_ediscovery_socket,
- EV_READ|EV_PERSIST, disc_recv_packet, NULL);
+ event_set(&edisc_ev, global.ldp_edisc_socket, EV_READ|EV_PERSIST,
+ disc_recv_packet, NULL);
event_add(&edisc_ev, NULL);
- accept_add(leconf->ldp_session_socket, session_accept, NULL);
+ accept_add(global.ldp_session_socket, session_accept, NULL);
/* listen on ldpd control socket */
TAILQ_INIT(&ctl_conns);
control_listen();
@@ -265,11 +264,11 @@ ldpe(struct ldpd_conf *xconf, int pipe_parent2ldpe[2], int pipe_ldpe2lde[2],
/* initialize interfaces */
LIST_FOREACH(iface, &leconf->iface_list, entry)
- if_init(xconf, iface);
+ if_init(iface);
/* start configured targeted neighbors */
LIST_FOREACH(tnbr, &leconf->tnbr_list, entry)
- tnbr_init(xconf, tnbr);
+ tnbr_init(tnbr);
event_dispatch();
@@ -289,14 +288,14 @@ ldpe_shutdown(void)
event_del(&pfkey_ev);
event_del(&disc_ev);
event_del(&edisc_ev);
- accept_del(leconf->ldp_session_socket);
- close(leconf->pfkeysock);
- close(leconf->ldp_discovery_socket);
- close(leconf->ldp_ediscovery_socket);
- close(leconf->ldp_session_socket);
+ accept_del(global.ldp_session_socket);
+ close(global.pfkeysock);
+ close(global.ldp_disc_socket);
+ close(global.ldp_edisc_socket);
+ close(global.ldp_session_socket);
/* remove addresses from global list */
- while ((if_addr = LIST_FIRST(&leconf->addr_list)) != NULL) {
+ while ((if_addr = LIST_FIRST(&global.addr_list)) != NULL) {
LIST_REMOVE(if_addr, entry);
free(if_addr);
}
@@ -316,14 +315,14 @@ ldpe_shutdown(void)
/* imesg */
int
-ldpe_imsg_compose_parent(int type, pid_t pid, void *data, u_int16_t datalen)
+ldpe_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));
}
int
-ldpe_imsg_compose_lde(int type, u_int32_t peerid, pid_t pid,
- void *data, u_int16_t datalen)
+ldpe_imsg_compose_lde(int type, uint32_t peerid, pid_t pid, void *data,
+ uint16_t datalen)
{
return (imsg_compose_event(iev_lde, type, peerid, pid, -1,
data, datalen));
@@ -384,55 +383,15 @@ ldpe_dispatch_main(int fd, short event, void *bula)
if (imsg.hdr.len != IMSG_HEADER_SIZE +
sizeof(struct kaddr))
fatalx("NEWADDR imsg with wrong len");
- ka = imsg.data;
-
- if (if_addr_lookup(&leconf->addr_list, ka) == NULL) {
- if_addr = if_addr_new(ka);
-
- LIST_INSERT_HEAD(&leconf->addr_list, if_addr,
- entry);
- RB_FOREACH(nbr, nbr_id_head, &nbrs_by_id) {
- if (nbr->state != NBR_STA_OPER)
- continue;
- send_address(nbr, if_addr);
- }
- }
- iface = if_lookup(leconf, ka->ifindex);
- if (iface &&
- if_addr_lookup(&iface->addr_list, ka) == NULL) {
- if_addr = if_addr_new(ka);
- LIST_INSERT_HEAD(&iface->addr_list, if_addr,
- entry);
- if_update(iface);
- }
+ if_addr_add(imsg.data);
break;
case IMSG_DELADDR:
if (imsg.hdr.len != IMSG_HEADER_SIZE +
sizeof(struct kaddr))
fatalx("DELADDR imsg with wrong len");
- ka = imsg.data;
-
- iface = if_lookup(leconf, ka->ifindex);
- if (iface) {
- if_addr = if_addr_lookup(&iface->addr_list, ka);
- if (if_addr) {
- LIST_REMOVE(if_addr, entry);
- free(if_addr);
- if_update(iface);
- }
- }
- if_addr = if_addr_lookup(&leconf->addr_list, ka);
- if (if_addr) {
- RB_FOREACH(nbr, nbr_id_head, &nbrs_by_id) {
- if (nbr->state != NBR_STA_OPER)
- continue;
- send_address_withdraw(nbr, if_addr);
- }
- LIST_REMOVE(if_addr, entry);
- free(if_addr);
- }
+ if_addr_del(imsg.data);
break;
case IMSG_RECONF_CONF:
if ((nconf = malloc(sizeof(struct ldpd_conf))) ==
@@ -441,7 +400,6 @@ ldpe_dispatch_main(int fd, short event, void *bula)
memcpy(nconf, imsg.data, sizeof(struct ldpd_conf));
LIST_INIT(&nconf->iface_list);
- LIST_INIT(&nconf->addr_list);
LIST_INIT(&nconf->tnbr_list);
LIST_INIT(&nconf->nbrp_list);
LIST_INIT(&nconf->l2vpn_list);
@@ -667,12 +625,6 @@ ldpe_dispatch_pfkey(int fd, short event, void *bula)
}
}
-u_int32_t
-ldpe_router_id(void)
-{
- return (leconf->rtr_id.s_addr);
-}
-
void
ldpe_iface_ctl(struct ctl_conn *c, unsigned int idx)
{
diff --git a/usr.sbin/ldpd/ldpe.h b/usr.sbin/ldpd/ldpe.h
index 5127be36d6c..a29545efe13 100644
--- a/usr.sbin/ldpd/ldpe.h
+++ b/usr.sbin/ldpd/ldpe.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ldpe.h,v 1.46 2016/05/23 16:16:44 renato Exp $ */
+/* $OpenBSD: ldpe.h,v 1.47 2016/05/23 17:43:42 renato Exp $ */
/*
* Copyright (c) 2004, 2005, 2008 Esben Norby <norby@openbsd.org>
@@ -45,7 +45,7 @@ struct adj {
struct nbr *nbr;
struct hello_source source;
struct event inactivity_timer;
- u_int16_t holdtime;
+ uint16_t holdtime;
struct in_addr addr;
};
@@ -78,18 +78,18 @@ struct nbr {
struct in_addr id; /* lsr id */
time_t uptime;
- u_int32_t peerid; /* unique ID in DB */
+ uint32_t peerid; /* unique ID in DB */
int fd;
int state;
int idtimer_cnt;
- u_int16_t keepalive;
+ uint16_t keepalive;
+ uint16_t max_pdu_len;
struct {
- u_int8_t established;
- struct in_addr local_addr;
- u_int32_t spi_in;
- u_int32_t spi_out;
+ uint8_t established;
+ uint32_t spi_in;
+ uint32_t spi_out;
enum auth_method method;
char md5key[TCP_MD5_KEY_LEN];
} auth;
@@ -109,8 +109,8 @@ struct mapping_entry {
};
struct ldpd_sysdep {
- u_int8_t no_pfkey;
- u_int8_t no_md5sig;
+ uint8_t no_pfkey;
+ uint8_t no_md5sig;
};
/* accept.c */
@@ -122,49 +122,50 @@ void accept_unpause(void);
/* hello.c */
int send_hello(enum hello_type, struct iface *, struct tnbr *);
-void recv_hello(struct iface *, struct in_addr, char *, u_int16_t);
+void recv_hello(struct in_addr, struct ldp_msg *, struct in_addr,
+ struct iface *, int, char *, uint16_t);
/* init.c */
void send_init(struct nbr *);
-int recv_init(struct nbr *, char *, u_int16_t);
+int recv_init(struct nbr *, char *, uint16_t);
/* keepalive.c */
void send_keepalive(struct nbr *);
-int recv_keepalive(struct nbr *, char *, u_int16_t);
+int recv_keepalive(struct nbr *, char *, uint16_t);
/* notification.c */
-void send_notification_nbr(struct nbr *, u_int32_t, u_int32_t, u_int32_t);
-void send_notification(u_int32_t, struct tcp_conn *, u_int32_t,
- u_int32_t);
+void send_notification_nbr(struct nbr *, uint32_t, uint32_t, uint32_t);
+void send_notification(uint32_t, struct tcp_conn *, uint32_t,
+ uint32_t);
void send_notification_full(struct tcp_conn *, struct notify_msg *);
-int recv_notification(struct nbr *, char *, u_int16_t);
+int recv_notification(struct nbr *, char *, uint16_t);
/* address.c */
-void send_address(struct nbr *, struct if_addr *);
-int recv_address(struct nbr *, char *, u_int16_t);
-void send_address_withdraw(struct nbr *, struct if_addr *);
+void send_address(struct nbr *, struct if_addr *, int);
+int recv_address(struct nbr *, char *, uint16_t);
/* labelmapping.c */
#define PREFIX_SIZE(x) (((x) + 7) / 8)
-void send_labelmessage(struct nbr *, u_int16_t, struct mapping_head *);
-int recv_labelmessage(struct nbr *, char *, u_int16_t, u_int16_t);
+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 *, u_int32_t);
+void gen_pw_status_tlv(struct ibuf *, uint32_t);
int tlv_decode_fec_elm(struct nbr *, struct ldp_msg *, char *,
- u_int16_t, struct map *);
+ uint16_t, struct map *);
/* ldpe.c */
pid_t ldpe(struct ldpd_conf *, int[2], int[2], int[2]);
void ldpe_dispatch_main(int, short, void *);
void ldpe_dispatch_lde(int, short, void *);
void ldpe_dispatch_pfkey(int, short, void *);
-int ldpe_imsg_compose_parent(int, pid_t, void *, u_int16_t);
-int ldpe_imsg_compose_lde(int, u_int32_t, pid_t, void *,
- u_int16_t);
-u_int32_t ldpe_router_id(void);
+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_iface_ctl(struct ctl_conn *, unsigned int);
+void ldpe_adj_ctl(struct ctl_conn *);
+void ldpe_nbr_ctl(struct ctl_conn *);
void mapping_list_add(struct mapping_head *, struct map *);
void mapping_list_clr(struct mapping_head *);
-void ldpe_iface_ctl(struct ctl_conn *, unsigned int);
/* interface.c */
int if_start(struct iface *);
@@ -173,8 +174,8 @@ int if_update(struct iface *);
struct iface *if_new(struct kif *);
void if_del(struct iface *);
-void if_init(struct ldpd_conf *, struct iface *);
-struct iface *if_lookup(struct ldpd_conf *, u_short);
+void if_init(struct iface *);
+struct iface *if_lookup(struct ldpd_conf *, unsigned short);
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 *);
@@ -184,13 +185,6 @@ struct ctl_iface *if_to_ctl(struct iface *);
int if_join_group(struct iface *, struct in_addr *);
int if_leave_group(struct iface *, struct in_addr *);
-int if_set_mcast(struct iface *);
-int if_set_recvif(int, int);
-void if_set_recvbuf(int);
-int if_set_mcast_loop(int);
-int if_set_mcast_ttl(int, u_int8_t);
-int if_set_tos(int, int);
-int if_set_reuse(int, int);
/* adjacency.c */
struct adj *adj_new(struct nbr *, struct hello_source *, struct in_addr);
@@ -201,7 +195,7 @@ void adj_stop_itimer(struct adj *);
struct tnbr *tnbr_new(struct ldpd_conf *, struct in_addr);
void tnbr_del(struct tnbr *);
struct tnbr *tnbr_check(struct tnbr *);
-void tnbr_init(struct ldpd_conf *, struct tnbr *);
+void tnbr_init(struct tnbr *);
struct tnbr *tnbr_find(struct ldpd_conf *, struct in_addr);
struct ctl_adj *adj_to_ctl(struct adj *);
@@ -211,8 +205,9 @@ struct nbr *nbr_new(struct in_addr, struct in_addr);
void nbr_del(struct nbr *);
void nbr_update_peerid(struct nbr *);
-struct nbr *nbr_find_ldpid(u_int32_t);
-struct nbr *nbr_find_peerid(u_int32_t);
+struct nbr *nbr_find_ldpid(uint32_t);
+struct nbr *nbr_find_addr(struct in_addr);
+struct nbr *nbr_find_peerid(uint32_t);
int nbr_fsm(struct nbr *, enum nbr_event);
int nbr_session_active_role(struct nbr *);
@@ -244,19 +239,23 @@ extern struct nbr_pid_head nbrs_by_pid;
RB_PROTOTYPE(nbr_pid_head, nbr, pid_tree, nbr_pid_compare)
/* packet.c */
-int gen_ldp_hdr(struct ibuf *, u_int16_t);
-int gen_msg_tlv(struct ibuf *, u_int32_t, u_int16_t);
+int gen_ldp_hdr(struct ibuf *, uint16_t);
+int gen_msg_hdr(struct ibuf *, uint32_t, uint16_t);
int send_packet(int, struct iface *, void *, size_t, struct sockaddr_in *);
void disc_recv_packet(int, short, void *);
void session_accept(int, short, void *);
-
-struct tcp_conn *tcp_new(int, struct nbr *);
-void tcp_close(struct tcp_conn *);
-
+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 *, u_int32_t, u_int32_t, u_int32_t);
+void session_shutdown(struct nbr *, uint32_t, uint32_t, uint32_t);
+
+struct tcp_conn *tcp_new(int, struct nbr *);
+void tcp_close(struct tcp_conn *);
+struct pending_conn *pending_conn_new(int, struct in_addr);
+void pending_conn_del(struct pending_conn *);
+struct pending_conn *pending_conn_find(struct in_addr);
+void pending_conn_timeout(int, short, void *);
char *pkt_ptr; /* packet buffer */
diff --git a/usr.sbin/ldpd/log.c b/usr.sbin/ldpd/log.c
index 488d70dd30f..0992ab0f3dd 100644
--- a/usr.sbin/ldpd/log.c
+++ b/usr.sbin/ldpd/log.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: log.c,v 1.21 2016/05/23 16:54:22 renato Exp $ */
+/* $OpenBSD: log.c,v 1.22 2016/05/23 17:43:42 renato Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -221,7 +221,7 @@ if_type_name(enum iface_type type)
}
const char *
-notification_name(u_int32_t status)
+notification_name(uint32_t status)
{
static char buf[16];
@@ -301,7 +301,7 @@ notification_name(u_int32_t status)
}
const char *
-pw_type_name(u_int16_t pw_type)
+pw_type_name(uint16_t pw_type)
{
static char buf[64];
@@ -413,7 +413,7 @@ static char *msgtypes[] = {
};
void
-log_rtmsg(u_char rtm_type)
+log_rtmsg(unsigned char rtm_type)
{
if (!(verbose & LDPD_OPT_VERBOSE2))
return;
diff --git a/usr.sbin/ldpd/log.h b/usr.sbin/ldpd/log.h
index 452fb986bc3..0f32221ac5b 100644
--- a/usr.sbin/ldpd/log.h
+++ b/usr.sbin/ldpd/log.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: log.h,v 1.6 2015/07/21 04:52:29 renato Exp $ */
+/* $OpenBSD: log.h,v 1.7 2016/05/23 17:43:42 renato Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -31,10 +31,12 @@ void log_info(const char *, ...);
void log_debug(const char *, ...);
void fatal(const char *) __dead;
void fatalx(const char *) __dead;
-const char *pw_type_name(u_int16_t);
+const char *pw_type_name(uint16_t);
const char *log_map(struct map *);
struct fec;
const char *log_fec(struct fec *);
-void log_rtmsg(u_char);
+void log_rtmsg(unsigned char);
+struct hello_source;
+char *log_hello_src(const struct hello_source *);
#endif /* _LOG_H_ */
diff --git a/usr.sbin/ldpd/neighbor.c b/usr.sbin/ldpd/neighbor.c
index 3fdc30b90e6..6b7477b7279 100644
--- a/usr.sbin/ldpd/neighbor.c
+++ b/usr.sbin/ldpd/neighbor.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: neighbor.c,v 1.64 2016/05/23 16:58:31 renato Exp $ */
+/* $OpenBSD: neighbor.c,v 1.65 2016/05/23 17:43:42 renato Exp $ */
/*
* Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
@@ -84,7 +84,7 @@ 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);
-u_int32_t peercnt = 1;
+uint32_t peercnt = 1;
extern struct ldpd_conf *leconf;
extern struct ldpd_sysdep sysdep;
@@ -313,19 +313,27 @@ nbr_update_peerid(struct nbr *nbr)
}
struct nbr *
-nbr_find_peerid(u_int32_t peerid)
+nbr_find_ldpid(uint32_t lsr_id)
{
struct nbr n;
- n.peerid = peerid;
- return (RB_FIND(nbr_pid_head, &nbrs_by_pid, &n));
+ n.id.s_addr = lsr_id;
+ return (RB_FIND(nbr_id_head, &nbrs_by_id, &n));
}
struct nbr *
-nbr_find_ldpid(u_int32_t rtr_id)
+nbr_find_addr(struct in_addr addr)
{
struct nbr n;
- n.id.s_addr = rtr_id;
- return (RB_FIND(nbr_id_head, &nbrs_by_id, &n));
+ n.raddr = addr;
+ return (RB_FIND(nbr_addr_head, &nbrs_by_addr, &n));
+}
+
+struct nbr *
+nbr_find_peerid(uint32_t peerid)
+{
+ struct nbr n;
+ n.peerid = peerid;
+ return (RB_FIND(nbr_pid_head, &nbrs_by_pid, &n));
}
int
@@ -523,7 +531,7 @@ nbr_establish_connection(struct nbr *nbr)
}
}
- bzero(&local_sa, sizeof(local_sa));
+ memset(&local_sa, 0, sizeof(local_sa));
local_sa.sin_family = AF_INET;
local_sa.sin_port = htons(0);
local_sa.sin_addr.s_addr = nbr->laddr.s_addr;
@@ -536,7 +544,7 @@ nbr_establish_connection(struct nbr *nbr)
return (-1);
}
- bzero(&remote_sa, sizeof(remote_sa));
+ memset(&remote_sa, 0, sizeof(remote_sa));
remote_sa.sin_family = AF_INET;
remote_sa.sin_port = htons(LDP_PORT);
remote_sa.sin_addr.s_addr = nbr->raddr.s_addr;
diff --git a/usr.sbin/ldpd/notification.c b/usr.sbin/ldpd/notification.c
index 5ee15ea8f2e..30651896fd4 100644
--- a/usr.sbin/ldpd/notification.c
+++ b/usr.sbin/ldpd/notification.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: notification.c,v 1.27 2016/05/23 16:54:22 renato Exp $ */
+/* $OpenBSD: notification.c,v 1.28 2016/05/23 17:43:42 renato Exp $ */
/*
* Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
@@ -36,13 +36,13 @@
#include "log.h"
#include "ldpe.h"
-int gen_status_tlv(struct ibuf *, u_int32_t, u_int32_t, u_int32_t);
+int gen_status_tlv(struct ibuf *, uint32_t, uint32_t, uint32_t);
void
send_notification_full(struct tcp_conn *tcp, struct notify_msg *nm)
{
struct ibuf *buf;
- u_int16_t size;
+ uint16_t size;
/* calculate size */
size = LDP_HDR_SIZE + LDP_MSG_SIZE + STATUS_SIZE;
@@ -54,7 +54,7 @@ send_notification_full(struct tcp_conn *tcp, struct notify_msg *nm)
case MAP_TYPE_PWID:
size += FEC_PWID_ELM_MIN_LEN;
if (nm->fec.flags & F_MAP_PW_ID)
- size += sizeof(u_int32_t);
+ size += sizeof(uint32_t);
break;
}
}
@@ -77,12 +77,12 @@ send_notification_full(struct tcp_conn *tcp, struct notify_msg *nm)
/* send a notification without optional tlvs */
void
-send_notification(u_int32_t status, struct tcp_conn *tcp, u_int32_t msgid,
- u_int32_t type)
+send_notification(uint32_t status, struct tcp_conn *tcp, uint32_t msgid,
+ uint32_t type)
{
struct notify_msg nm;
- bzero(&nm, sizeof(nm));
+ memset(&nm, 0, sizeof(nm));
nm.status = status;
nm.messageid = msgid;
nm.type = type;
@@ -91,8 +91,8 @@ send_notification(u_int32_t status, struct tcp_conn *tcp, u_int32_t msgid,
}
void
-send_notification_nbr(struct nbr *nbr, u_int32_t status, u_int32_t msgid,
- u_int32_t type)
+send_notification_nbr(struct nbr *nbr, uint32_t status, uint32_t msgid,
+ uint32_t type)
{
log_debug("%s: lsr-id %s, status %s", __func__, inet_ntoa(nbr->id),
notification_name(status));
@@ -102,23 +102,22 @@ send_notification_nbr(struct nbr *nbr, u_int32_t status, u_int32_t msgid,
}
int
-recv_notification(struct nbr *nbr, char *buf, u_int16_t len)
+recv_notification(struct nbr *nbr, char *buf, uint16_t len)
{
struct ldp_msg not;
struct status_tlv st;
struct notify_msg nm;
int tlen;
- bcopy(buf, &not, sizeof(not));
-
- buf += sizeof(struct ldp_msg);
- len -= sizeof(struct ldp_msg);
+ memcpy(&not, buf, sizeof(not));
+ buf += LDP_MSG_SIZE;
+ len -= LDP_MSG_SIZE;
if (len < STATUS_SIZE) {
session_shutdown(nbr, S_BAD_MSG_LEN, not.msgid, not.type);
return (-1);
}
- bcopy(buf, &st, sizeof(st));
+ memcpy(&st, buf, sizeof(st));
if (ntohs(st.length) > STATUS_SIZE - TLV_HDR_LEN ||
ntohs(st.length) > len - TLV_HDR_LEN) {
@@ -128,7 +127,7 @@ recv_notification(struct nbr *nbr, char *buf, u_int16_t len)
buf += STATUS_SIZE;
len -= STATUS_SIZE;
- bzero(&nm, sizeof(nm));
+ memset(&nm, 0, sizeof(nm));
nm.status = ntohl(st.status_code);
/* Optional Parameters */
@@ -141,7 +140,7 @@ recv_notification(struct nbr *nbr, char *buf, u_int16_t len)
return (-1);
}
- bcopy(buf, &tlv, sizeof(tlv));
+ memcpy(&tlv, buf, sizeof(tlv));
if (ntohs(tlv.length) > len - TLV_HDR_LEN) {
session_shutdown(nbr, S_BAD_TLV_LEN, not.msgid,
not.type);
@@ -163,7 +162,7 @@ recv_notification(struct nbr *nbr, char *buf, u_int16_t len)
return (-1);
}
- nm.pw_status = ntohl(*(u_int32_t *)buf);
+ nm.pw_status = ntohl(*(uint32_t *)buf);
nm.flags |= F_NOTIF_PW_STATUS;
break;
case TLV_TYPE_FEC:
@@ -237,12 +236,11 @@ recv_notification(struct nbr *nbr, char *buf, u_int16_t len)
}
int
-gen_status_tlv(struct ibuf *buf, u_int32_t status, u_int32_t msgid,
- u_int32_t type)
+gen_status_tlv(struct ibuf *buf, uint32_t status, uint32_t msgid, uint32_t type)
{
struct status_tlv st;
- bzero(&st, sizeof(st));
+ memset(&st, 0, sizeof(st));
st.type = htons(TLV_TYPE_STATUS);
st.length = htons(STATUS_TLV_LEN);
diff --git a/usr.sbin/ldpd/packet.c b/usr.sbin/ldpd/packet.c
index 03503f4c7f1..878c59d4cd0 100644
--- a/usr.sbin/ldpd/packet.c
+++ b/usr.sbin/ldpd/packet.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: packet.c,v 1.53 2016/05/23 17:00:40 renato Exp $ */
+/* $OpenBSD: packet.c,v 1.54 2016/05/23 17:43:42 renato Exp $ */
/*
* Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
@@ -48,11 +48,11 @@ ssize_t session_get_pdu(struct ibuf_read *, char **);
static int msgcnt = 0;
int
-gen_ldp_hdr(struct ibuf *buf, u_int16_t size)
+gen_ldp_hdr(struct ibuf *buf, uint16_t size)
{
struct ldp_hdr ldp_hdr;
- bzero(&ldp_hdr, sizeof(ldp_hdr));
+ memset(&ldp_hdr, 0, sizeof(ldp_hdr));
ldp_hdr.version = htons(LDP_VERSION);
/* exclude the 'Version' and 'PDU Length' fields from the total */
ldp_hdr.length = htons(size - LDP_HDR_DEAD_LEN);
@@ -63,16 +63,14 @@ gen_ldp_hdr(struct ibuf *buf, u_int16_t size)
}
int
-gen_msg_tlv(struct ibuf *buf, u_int32_t type, u_int16_t size)
+gen_msg_hdr(struct ibuf *buf, uint32_t type, uint16_t size)
{
struct ldp_msg msg;
- /* We want just the size of the value */
- size -= TLV_HDR_LEN;
-
- bzero(&msg, sizeof(msg));
+ memset(&msg, 0, sizeof(msg));
msg.type = htons(type);
- msg.length = htons(size);
+ /* exclude the 'Type' and 'Length' fields from the total */
+ msg.length = htons(size - LDP_MSG_DEAD_LEN);
if (type != MSG_TYPE_HELLO)
msg.msgid = htonl(++msgcnt);
@@ -107,26 +105,30 @@ void
disc_recv_packet(int fd, short event, void *bula)
{
union {
- struct cmsghdr hdr;
+ struct cmsghdr hdr;
char buf[CMSG_SPACE(sizeof(struct sockaddr_dl))];
} cmsgbuf;
struct sockaddr_in src;
struct msghdr msg;
struct iovec iov;
- struct ldp_hdr ldp_hdr;
- struct ldp_msg ldp_msg;
- struct iface *iface = NULL;
char *buf;
struct cmsghdr *cmsg;
ssize_t r;
- u_int16_t len;
+ int multicast;
unsigned int ifindex = 0;
+ struct iface *iface;
+ uint16_t len;
+ struct ldp_hdr ldp_hdr;
+ uint16_t pdu_len;
+ struct ldp_msg ldp_msg;
+ uint16_t msg_len;
+ struct in_addr lsr_id;
if (event != EV_READ)
return;
/* setup buffer */
- bzero(&msg, sizeof(msg));
+ memset(&msg, 0, sizeof(msg));
iov.iov_base = buf = pkt_ptr;
iov.iov_len = IBUF_READ_SIZE;
msg.msg_name = &src;
@@ -160,49 +162,66 @@ disc_recv_packet(int fd, short event, void *bula)
}
}
- len = (u_int16_t)r;
-
/* find a matching interface */
- if ((fd == leconf->ldp_discovery_socket) &&
- (iface = disc_find_iface(ifindex, src.sin_addr)) == NULL) {
- log_debug("disc_recv_packet: cannot find a matching subnet "
- "on interface index %d for %s", ifindex,
+ iface = disc_find_iface(ifindex, src.sin_addr, multicast);
+ if (iface == NULL)
+ return;
+
+ /* check packet size */
+ len = (uint16_t)r;
+ if (len < (LDP_HDR_SIZE + LDP_MSG_SIZE) || len > LDP_MAX_LEN) {
+ log_debug("%s: bad packet size, source %s", __func__,
inet_ntoa(src.sin_addr));
return;
}
/* LDP header sanity checks */
- if (len < LDP_HDR_SIZE || len > LDP_MAX_LEN) {
- log_debug("disc_recv_packet: bad packet size");
+ memcpy(&ldp_hdr, buf, sizeof(ldp_hdr));
+ if (ntohs(ldp_hdr.version) != LDP_VERSION) {
+ log_debug("%s: invalid LDP version %d, source %s", __func__,
+ ntohs(ldp_hdr.version), inet_ntoa(src.sin_addr));
return;
}
- bcopy(buf, &ldp_hdr, sizeof(ldp_hdr));
-
- if (ntohs(ldp_hdr.version) != LDP_VERSION) {
- log_debug("dsc_recv_packet: invalid LDP version %d",
- ldp_hdr.version);
+ if (ntohs(ldp_hdr.lspace_id) != 0) {
+ log_debug("%s: invalid label space %u, source %s", __func__,
+ ntohs(ldp_hdr.lspace_id), inet_ntoa(src.sin_addr));
return;
}
-
- if (ntohs(ldp_hdr.length) >
- len - sizeof(ldp_hdr.version) - sizeof(ldp_hdr.length)) {
- log_debug("disc_recv_packet: invalid LDP packet length %u",
- ntohs(ldp_hdr.length));
+ /* check "PDU Length" field */
+ pdu_len = ntohs(ldp_hdr.length);
+ if ((pdu_len < (LDP_HDR_PDU_LEN + LDP_MSG_SIZE)) ||
+ (pdu_len > (len - LDP_HDR_DEAD_LEN))) {
+ log_debug("%s: invalid LDP packet length %u, source %s",
+ __func__, ntohs(ldp_hdr.length), inet_ntoa(src.sin_addr));
return;
}
+ buf += LDP_HDR_SIZE;
+ len -= LDP_HDR_SIZE;
- if (len < LDP_HDR_SIZE + LDP_MSG_LEN) {
- log_debug("disc_recv_packet: invalid LDP packet length %d",
- ntohs(ldp_hdr.length));
+ lsr_id.s_addr = ldp_hdr.lsr_id;
+
+ /*
+ * For UDP, we process only the first message of each packet. This does
+ * not impose any restrictions since LDP uses UDP only for sending Hello
+ * packets.
+ */
+ memcpy(&ldp_msg, buf, sizeof(ldp_msg));
+
+ /* check "Message Length" field */
+ msg_len = ntohs(ldp_msg.length);
+ if (msg_len < LDP_MSG_LEN || ((msg_len + LDP_MSG_DEAD_LEN) > pdu_len)) {
+ log_debug("%s: invalid LDP message length %u, source %s",
+ __func__, ntohs(ldp_msg.length), inet_ntoa(src.sin_addr));
return;
}
-
- bcopy(buf + LDP_HDR_SIZE, &ldp_msg, sizeof(ldp_msg));
+ buf += LDP_MSG_SIZE;
+ len -= LDP_MSG_SIZE;
/* switch LDP packet type */
switch (ntohs(ldp_msg.type)) {
case MSG_TYPE_HELLO:
- recv_hello(iface, src.sin_addr, buf, len);
+ recv_hello(lsr_id, &ldp_msg, src.sin_addr, iface, multicast,
+ buf, len);
break;
default:
log_debug("%s: unknown LDP packet type, source %s", __func__,
@@ -349,8 +368,8 @@ session_read(int fd, short event, void *arg)
struct ldp_msg *ldp_msg;
char *buf, *pdu;
ssize_t n, len;
- int msg_size;
- u_int16_t pdu_len;
+ uint16_t pdu_len, msg_len, msg_size, max_pdu_len;
+ int ret;
if (event != EV_READ)
return;
@@ -413,20 +432,20 @@ session_read(int fd, short event, void *arg)
if (nbr->state == NBR_STA_OPER)
nbr_fsm(nbr, NBR_EVT_PDU_RCVD);
- while (len >= LDP_MSG_LEN) {
- u_int16_t type;
+ while (len >= LDP_MSG_SIZE) {
+ uint16_t type;
ldp_msg = (struct ldp_msg *)pdu;
type = ntohs(ldp_msg->type);
-
- pdu_len = ntohs(ldp_msg->length) + TLV_HDR_LEN;
- if (pdu_len > len ||
- pdu_len < LDP_MSG_LEN - TLV_HDR_LEN) {
+ msg_len = ntohs(ldp_msg->length);
+ msg_size = msg_len + LDP_MSG_DEAD_LEN;
+ if (msg_len < LDP_MSG_LEN || msg_size > pdu_len) {
session_shutdown(nbr, S_BAD_TLV_LEN,
ldp_msg->msgid, ldp_msg->type);
free(buf);
return;
}
+ pdu_len -= msg_size;
/* check for error conditions earlier */
switch (type) {
@@ -547,8 +566,8 @@ session_write(int fd, short event, void *arg)
}
void
-session_shutdown(struct nbr *nbr, u_int32_t status, u_int32_t msgid,
- u_int32_t type)
+session_shutdown(struct nbr *nbr, uint32_t status, uint32_t msgid,
+ uint32_t type)
{
if (nbr->tcp == NULL)
return;
diff --git a/usr.sbin/ldpd/parse.y b/usr.sbin/ldpd/parse.y
index a60d43c6a96..a53b9a88868 100644
--- a/usr.sbin/ldpd/parse.y
+++ b/usr.sbin/ldpd/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.43 2016/05/23 16:54:22 renato Exp $ */
+/* $OpenBSD: parse.y,v 1.44 2016/05/23 17:43:42 renato Exp $ */
/*
* Copyright (c) 2004, 2005, 2008 Esben Norby <norby@openbsd.org>
@@ -80,7 +80,7 @@ int symset(const char *, const char *, int);
char *symget(const char *);
void clear_config(struct ldpd_conf *xconf);
-u_int32_t get_rtr_id(void);
+uint32_t get_rtr_id(void);
int host(const char *, struct in_addr *, struct in_addr *);
static struct ldpd_conf *conf;
@@ -93,11 +93,11 @@ struct l2vpn *l2vpn = NULL;
struct l2vpn_pw *pw = NULL;
struct config_defaults {
- u_int16_t lhello_holdtime;
- u_int16_t lhello_interval;
- u_int16_t thello_holdtime;
- u_int16_t thello_interval;
- u_int8_t pwflags;
+ uint16_t lhello_holdtime;
+ uint16_t lhello_interval;
+ uint16_t thello_holdtime;
+ uint16_t thello_interval;
+ uint8_t pwflags;
};
struct config_defaults globaldefs;
@@ -123,7 +123,7 @@ typedef struct {
%}
-%token INTERFACE TNEIGHBOR ROUTERID FIBUPDATE
+%token INTERFACE TNEIGHBOR ROUTERID FIBUPDATE EXPNULL
%token LHELLOHOLDTIME LHELLOINTERVAL
%token THELLOHOLDTIME THELLOINTERVAL
%token THELLOACCEPT
@@ -197,7 +197,7 @@ pw_type : ETHERNET { $$ = PW_TYPE_ETHERNET; }
;
varset : STRING '=' string {
- if (conf->opts & LDPD_OPT_VERBOSE)
+ if (global.cmd_opts & LDPD_OPT_VERBOSE)
printf("%s = \"%s\"\n", $1, $3);
if (symset($1, $3, 0) == -1)
fatal("cannot store variable");
@@ -220,15 +220,21 @@ conf_main : ROUTERID STRING {
}
| FIBUPDATE yesno {
if ($2 == 0)
- conf->flags |= LDPD_FLAG_NO_FIB_UPDATE;
+ conf->flags |= F_LDPD_NO_FIB_UPDATE;
else
- conf->flags &= ~LDPD_FLAG_NO_FIB_UPDATE;
+ conf->flags &= ~F_LDPD_NO_FIB_UPDATE;
}
| THELLOACCEPT yesno {
if ($2 == 0)
- conf->flags &= ~LDPD_FLAG_TH_ACCEPT;
+ conf->flags &= ~F_LDPD_TH_ACCEPT;
else
- conf->flags |= LDPD_FLAG_TH_ACCEPT;
+ conf->flags |= F_LDPD_TH_ACCEPT;
+ }
+ | EXPNULL yesno {
+ if ($2 == 0)
+ conf->flags &= ~F_LDPD_EXPNULL;
+ else
+ conf->flags |= F_LDPD_EXPNULL;
}
| KEEPALIVE NUMBER {
if ($2 < MIN_KEEPALIVE || $2 > MAX_KEEPALIVE) {
@@ -694,6 +700,7 @@ lookup(char *s)
{"control-word", CONTROLWORD},
{"ethernet", ETHERNET},
{"ethernet-tagged", ETHERNETTAGGED},
+ {"explicit-null", EXPNULL},
{"fib-update", FIBUPDATE},
{"include", INCLUDE},
{"interface", INTERFACE},
@@ -732,10 +739,10 @@ lookup(char *s)
#define MAXPUSHBACK 128
-u_char *parsebuf;
-int parseindex;
-u_char pushback_buffer[MAXPUSHBACK];
-int pushback_index = 0;
+unsigned char *parsebuf;
+int parseindex;
+unsigned char pushback_buffer[MAXPUSHBACK];
+int pushback_index = 0;
int
lgetc(int quotec)
@@ -827,10 +834,10 @@ findeol(void)
int
yylex(void)
{
- u_char buf[8096];
- u_char *p, *val;
- int quotec, next, c;
- int token;
+ unsigned char buf[8096];
+ unsigned char *p, *val;
+ int quotec, next, c;
+ int token;
top:
p = buf;
@@ -1041,16 +1048,15 @@ popfile(void)
}
struct ldpd_conf *
-parse_config(char *filename, int opts)
+parse_config(char *filename)
{
struct sym *sym, *next;
if ((conf = calloc(1, sizeof(struct ldpd_conf))) == NULL)
- fatal("parse_config");
- conf->opts = opts;
+ fatal(__func__);
conf->keepalive = DEFAULT_KEEPALIVE;
- bzero(&globaldefs, sizeof(globaldefs));
+ memset(&globaldefs, 0, sizeof(globaldefs));
defs = &globaldefs;
defs->lhello_holdtime = LINK_DFLT_HOLDTIME;
defs->lhello_interval = DEFAULT_HELLO_INTERVAL;
@@ -1063,14 +1069,14 @@ parse_config(char *filename, int opts)
defs->pwflags |= F_PW_CWORD_CONF;
defs->pwflags |= F_PW_CWORD;
- if ((file = pushfile(filename, !(conf->opts & LDPD_OPT_NOACTION))) == NULL) {
+ if ((file = pushfile(filename,
+ !(global.cmd_opts & LDPD_OPT_NOACTION))) == NULL) {
free(conf);
return (NULL);
}
topfile = file;
LIST_INIT(&conf->iface_list);
- LIST_INIT(&conf->addr_list);
LIST_INIT(&conf->tnbr_list);
LIST_INIT(&conf->nbrp_list);
LIST_INIT(&conf->l2vpn_list);
@@ -1082,7 +1088,7 @@ parse_config(char *filename, int opts)
/* Free macros and check which have not been used. */
for (sym = TAILQ_FIRST(&symhead); sym != NULL; sym = next) {
next = TAILQ_NEXT(sym, entry);
- if ((conf->opts & LDPD_OPT_VERBOSE2) && !sym->used)
+ if ((global.cmd_opts & LDPD_OPT_VERBOSE2) && !sym->used)
fprintf(stderr, "warning: macro '%s' not "
"used\n", sym->nam);
if (!sym->persist) {
@@ -1181,16 +1187,6 @@ symget(const char *nam)
return (NULL);
}
-int
-bad_ip_addr(struct in_addr addr)
-{
- u_int32_t a = ntohl(addr.s_addr);
-
- return (((a >> IN_CLASSA_NSHIFT) == 0)
- || ((a >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET)
- || IN_MULTICAST(a) || IN_BADCLASS(a));
-}
-
struct iface *
conf_get_if(struct kif *kif)
{
@@ -1340,11 +1336,11 @@ clear_config(struct ldpd_conf *xconf)
free(xconf);
}
-u_int32_t
+uint32_t
get_rtr_id(void)
{
struct ifaddrs *ifap, *ifa;
- u_int32_t ip = 0, cur, localnet;
+ uint32_t ip = 0, cur, localnet;
localnet = htonl(INADDR_LOOPBACK & IN_CLASSA_NET);
@@ -1376,7 +1372,7 @@ host(const char *s, struct in_addr *addr, struct in_addr *mask)
struct in_addr ina;
int bits = 32;
- bzero(&ina, sizeof(struct in_addr));
+ memset(&ina, 0, sizeof(struct in_addr));
if (strrchr(s, '/') != NULL) {
if ((bits = inet_net_pton(AF_INET, s, &ina, sizeof(ina))) == -1)
return (0);
diff --git a/usr.sbin/ldpd/pfkey.c b/usr.sbin/ldpd/pfkey.c
index 30d79173188..b36f7c2cf06 100644
--- a/usr.sbin/ldpd/pfkey.c
+++ b/usr.sbin/ldpd/pfkey.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pfkey.c,v 1.5 2016/05/23 16:25:11 renato Exp $ */
+/* $OpenBSD: pfkey.c,v 1.6 2016/05/23 17:43:42 renato Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -33,22 +33,22 @@
#include "ldpe.h"
#include "log.h"
-#define PFKEY2_CHUNK sizeof(u_int64_t)
+#define PFKEY2_CHUNK sizeof(uint64_t)
#define ROUNDUP(x) (((x) + (PFKEY2_CHUNK - 1)) & ~(PFKEY2_CHUNK - 1))
#define IOV_CNT 20
-static u_int32_t sadb_msg_seq = 0;
-static u_int32_t pid = 0; /* should pid_t but pfkey needs u_int32_t */
-static int fd;
+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, u_int32_t *);
+int pfkey_reply(int, uint32_t *);
int pfkey_send(int, uint8_t, uint8_t, uint8_t,
struct in_addr *, struct in_addr *,
- u_int32_t, uint8_t, int, char *, uint8_t, int, char *,
+ uint32_t, uint8_t, int, char *, uint8_t, int, char *,
uint16_t, uint16_t);
-int pfkey_sa_add(struct in_addr *, struct in_addr *, u_int8_t, char *,
- u_int32_t *);
-int pfkey_sa_remove(struct in_addr *, struct in_addr *, u_int32_t *);
+int pfkey_sa_add(struct in_addr *, struct in_addr *, uint8_t, char *,
+ uint32_t *);
+int pfkey_sa_remove(struct in_addr *, struct in_addr *, uint32_t *);
int pfkey_md5sig_establish(struct nbr *, struct nbr_params *nbrp);
int pfkey_md5sig_remove(struct nbr *);
@@ -59,7 +59,7 @@ addr2sa(struct in_addr *addr)
static struct sockaddr_storage ss;
struct sockaddr_in *sa_in = (struct sockaddr_in *)&ss;
- bzero(&ss, sizeof(ss));
+ memset(&ss, 0, sizeof(ss));
sa_in->sin_family = AF_INET;
sa_in->sin_len = sizeof(struct sockaddr_in);
sa_in->sin_addr.s_addr = addr->s_addr;
@@ -70,7 +70,7 @@ addr2sa(struct in_addr *addr)
int
pfkey_send(int sd, uint8_t satype, uint8_t mtype, uint8_t dir,
- struct in_addr *src, struct in_addr *dst, u_int32_t spi,
+ struct in_addr *src, struct in_addr *dst, uint32_t spi,
uint8_t aalg, int alen, char *akey, uint8_t ealg, int elen, char *ekey,
uint16_t sport, uint16_t dport)
{
@@ -90,23 +90,23 @@ pfkey_send(int sd, uint8_t satype, uint8_t mtype, uint8_t dir,
pid = getpid();
/* we need clean sockaddr... no ports set */
- bzero(&ssrc, sizeof(ssrc));
- bzero(&smask, sizeof(smask));
+ memset(&ssrc, 0, sizeof(ssrc));
+ memset(&smask, 0, sizeof(smask));
if ((saptr = addr2sa(src)))
memcpy(&ssrc, saptr, sizeof(ssrc));
memset(&((struct sockaddr_in *)&smask)->sin_addr, 0xff, 32/8);
smask.ss_family = ssrc.ss_family;
smask.ss_len = ssrc.ss_len;
- bzero(&sdst, sizeof(sdst));
- bzero(&dmask, sizeof(dmask));
+ memset(&sdst, 0, sizeof(sdst));
+ memset(&dmask, 0, sizeof(dmask));
if ((saptr = addr2sa(dst)))
memcpy(&sdst, saptr, sizeof(sdst));
memset(&((struct sockaddr_in *)&dmask)->sin_addr, 0xff, 32/8);
dmask.ss_family = sdst.ss_family;
dmask.ss_len = sdst.ss_len;
- bzero(&smsg, sizeof(smsg));
+ memset(&smsg, 0, sizeof(smsg));
smsg.sadb_msg_version = PF_KEY_V2;
smsg.sadb_msg_seq = ++sadb_msg_seq;
smsg.sadb_msg_pid = pid;
@@ -116,7 +116,7 @@ pfkey_send(int sd, uint8_t satype, uint8_t mtype, uint8_t dir,
switch (mtype) {
case SADB_GETSPI:
- bzero(&sa_spirange, sizeof(sa_spirange));
+ memset(&sa_spirange, 0, sizeof(sa_spirange));
sa_spirange.sadb_spirange_exttype = SADB_EXT_SPIRANGE;
sa_spirange.sadb_spirange_len = sizeof(sa_spirange) / 8;
sa_spirange.sadb_spirange_min = 0x100;
@@ -126,7 +126,7 @@ pfkey_send(int sd, uint8_t satype, uint8_t mtype, uint8_t dir,
case SADB_ADD:
case SADB_UPDATE:
case SADB_DELETE:
- bzero(&sa, sizeof(sa));
+ memset(&sa, 0, sizeof(sa));
sa.sadb_sa_exttype = SADB_EXT_SA;
sa.sadb_sa_len = sizeof(sa) / 8;
sa.sadb_sa_replay = 0;
@@ -135,11 +135,11 @@ pfkey_send(int sd, uint8_t satype, uint8_t mtype, uint8_t dir,
break;
}
- bzero(&sa_src, sizeof(sa_src));
+ memset(&sa_src, 0, sizeof(sa_src));
sa_src.sadb_address_exttype = SADB_EXT_ADDRESS_SRC;
sa_src.sadb_address_len = (sizeof(sa_src) + ROUNDUP(ssrc.ss_len)) / 8;
- bzero(&sa_dst, sizeof(sa_dst));
+ memset(&sa_dst, 0, sizeof(sa_dst));
sa_dst.sadb_address_exttype = SADB_EXT_ADDRESS_DST;
sa_dst.sadb_address_len = (sizeof(sa_dst) + ROUNDUP(sdst.ss_len)) / 8;
@@ -149,13 +149,13 @@ pfkey_send(int sd, uint8_t satype, uint8_t mtype, uint8_t dir,
switch (mtype) {
case SADB_ADD:
case SADB_UPDATE:
- bzero(&sa_akey, sizeof(sa_akey));
+ memset(&sa_akey, 0, sizeof(sa_akey));
sa_akey.sadb_key_exttype = SADB_EXT_KEY_AUTH;
sa_akey.sadb_key_len = (sizeof(sa_akey) +
((alen + 7) / 8) * 8) / 8;
sa_akey.sadb_key_bits = 8 * alen;
- bzero(&sa_ekey, sizeof(sa_ekey));
+ memset(&sa_ekey, 0, sizeof(sa_ekey));
sa_ekey.sadb_key_exttype = SADB_EXT_KEY_ENCRYPT;
sa_ekey.sadb_key_len = (sizeof(sa_ekey) +
((elen + 7) / 8) * 8) / 8;
@@ -263,7 +263,7 @@ pfkey_read(int sd, struct sadb_msg *h)
if (hdr.sadb_msg_seq == sadb_msg_seq &&
hdr.sadb_msg_pid == pid) {
if (h)
- bcopy(&hdr, h, sizeof(hdr));
+ memcpy(h, &hdr, sizeof(hdr));
return (0);
}
@@ -279,12 +279,12 @@ pfkey_read(int sd, struct sadb_msg *h)
}
int
-pfkey_reply(int sd, u_int32_t *spip)
+pfkey_reply(int sd, uint32_t *spip)
{
struct sadb_msg hdr, *msg;
struct sadb_ext *ext;
struct sadb_sa *sa;
- u_int8_t *data;
+ uint8_t *data;
ssize_t len;
int rv;
@@ -324,9 +324,9 @@ pfkey_reply(int sd, u_int32_t *spip)
msg = (struct sadb_msg *)data;
for (ext = (struct sadb_ext *)(msg + 1);
- (size_t)((u_int8_t *)ext - (u_int8_t *)msg) <
+ (size_t)((uint8_t *)ext - (uint8_t *)msg) <
msg->sadb_msg_len * PFKEY2_CHUNK;
- ext = (struct sadb_ext *)((u_int8_t *)ext +
+ ext = (struct sadb_ext *)((uint8_t *)ext +
ext->sadb_ext_len * PFKEY2_CHUNK)) {
if (ext->sadb_ext_type == SADB_EXT_SA) {
sa = (struct sadb_sa *) ext;
@@ -341,8 +341,8 @@ pfkey_reply(int sd, u_int32_t *spip)
}
int
-pfkey_sa_add(struct in_addr *src, struct in_addr *dst, u_int8_t keylen,
- char *key, u_int32_t *spi)
+pfkey_sa_add(struct in_addr *src, struct in_addr *dst, uint8_t keylen,
+ char *key, uint32_t *spi)
{
if (pfkey_send(fd, SADB_X_SATYPE_TCPSIGNATURE, SADB_GETSPI, 0,
src, dst, 0, 0, 0, NULL, 0, 0, NULL, 0, 0) < 0)
@@ -358,7 +358,7 @@ pfkey_sa_add(struct in_addr *src, struct in_addr *dst, u_int8_t keylen,
}
int
-pfkey_sa_remove(struct in_addr *src, struct in_addr *dst, u_int32_t *spi)
+pfkey_sa_remove(struct in_addr *src, struct in_addr *dst, uint32_t *spi)
{
if (pfkey_send(fd, SADB_X_SATYPE_TCPSIGNATURE, SADB_DELETE, 0,
src, dst, *spi, 0, 0, NULL, 0, 0, NULL, 0, 0) < 0)
diff --git a/usr.sbin/ldpd/printconf.c b/usr.sbin/ldpd/printconf.c
index daf3d3c719a..a1e163dfc81 100644
--- a/usr.sbin/ldpd/printconf.c
+++ b/usr.sbin/ldpd/printconf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: printconf.c,v 1.18 2016/05/23 16:54:22 renato Exp $ */
+/* $OpenBSD: printconf.c,v 1.19 2016/05/23 17:43:42 renato Exp $ */
/*
* Copyright (c) 2004, 2005, 2008 Esben Norby <norby@openbsd.org>
@@ -40,16 +40,21 @@ print_mainconf(struct ldpd_conf *conf)
{
printf("router-id %s\n\n", inet_ntoa(conf->rtr_id));
- if (conf->flags & LDPD_FLAG_NO_FIB_UPDATE)
+ if (conf->flags & F_LDPD_NO_FIB_UPDATE)
printf("fib-update no\n");
else
printf("fib-update yes\n");
- if (conf->flags & LDPD_FLAG_TH_ACCEPT)
+ if (conf->flags & F_LDPD_TH_ACCEPT)
printf("targeted-hello-accept yes\n");
else
printf("targeted-hello-accept no\n");
+ if (conf->flags & F_LDPD_EXPNULL)
+ printf("explicit-null yes\n");
+ else
+ printf("explicit-null no\n");
+
printf("keepalive %u\n", conf->keepalive);
printf("transport-address %s\n", inet_ntoa(conf->trans_addr));
}
diff --git a/usr.sbin/ldpd/socket.c b/usr.sbin/ldpd/socket.c
index 6c587cbb3d5..054d3ada62c 100644
--- a/usr.sbin/ldpd/socket.c
+++ b/usr.sbin/ldpd/socket.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: socket.c,v 1.1 2016/05/23 17:00:40 renato Exp $ */
+/* $OpenBSD: socket.c,v 1.2 2016/05/23 17:43:42 renato Exp $ */
/*
* Copyright (c) 2016 Renato Westphal <renato@openbsd.org>
diff --git a/usr.sbin/ldpd/util.c b/usr.sbin/ldpd/util.c
index 9cc5c461107..6e93e2579a8 100644
--- a/usr.sbin/ldpd/util.c
+++ b/usr.sbin/ldpd/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.1 2016/05/23 16:08:18 renato Exp $ */
+/* $OpenBSD: util.c,v 1.2 2016/05/23 17:43:42 renato Exp $ */
/*
* Copyright (c) 2015 Renato Westphal <renato@openbsd.org>