summaryrefslogtreecommitdiffstats
path: root/usr.sbin/ldpd/labelmapping.c
diff options
context:
space:
mode:
authorrenato <renato@openbsd.org>2016-08-08 16:45:51 +0000
committerrenato <renato@openbsd.org>2016-08-08 16:45:51 +0000
commit00f5e67face1b66f4db4de03839ed1775951758e (patch)
tree5db523b3546e245b7d7ce0db2780a668b3f8de7c /usr.sbin/ldpd/labelmapping.c
parentFixup incorrect format specification bugs spotted by jsg@ (diff)
downloadwireguard-openbsd-00f5e67face1b66f4db4de03839ed1775951758e.tar.xz
wireguard-openbsd-00f5e67face1b66f4db4de03839ed1775951758e.zip
Normalize the received prefixes.
We need to use ldp_applymask() to normalize the received prefixes. Example: 10.1.1.0/16 -> 10.1.0.0/16. Additionally, stop using IANA's AF numbers in map->fec.prefix.af and use AF_INET/AF_INET6 instead. This makes the code much simpler, use AF_IPV[46] only when necessary (decoding/encoding prefixes). ok claudio@
Diffstat (limited to 'usr.sbin/ldpd/labelmapping.c')
-rw-r--r--usr.sbin/ldpd/labelmapping.c35
1 files changed, 27 insertions, 8 deletions
diff --git a/usr.sbin/ldpd/labelmapping.c b/usr.sbin/ldpd/labelmapping.c
index f8261e6d6d8..5ed9800f2d8 100644
--- a/usr.sbin/ldpd/labelmapping.c
+++ b/usr.sbin/ldpd/labelmapping.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: labelmapping.c,v 1.58 2016/07/16 19:20:16 renato Exp $ */
+/* $OpenBSD: labelmapping.c,v 1.59 2016/08/08 16:45:51 renato Exp $ */
/*
* Copyright (c) 2014, 2015 Renato Westphal <renato@openbsd.org>
@@ -356,7 +356,7 @@ recv_labelmessage(struct nbr *nbr, char *buf, uint16_t len, uint16_t type)
switch (me->map.type) {
case MAP_TYPE_PREFIX:
switch (me->map.fec.prefix.af) {
- case AF_IPV4:
+ case AF_INET:
if (label == MPLS_LABEL_IPV6NULL) {
session_shutdown(nbr, S_BAD_TLV_VAL,
msg.id, msg.type);
@@ -365,7 +365,7 @@ recv_labelmessage(struct nbr *nbr, char *buf, uint16_t len, uint16_t type)
if (!nbr->v4_enabled)
goto next;
break;
- case AF_IPV6:
+ case AF_INET6:
if (label == MPLS_LABEL_IPV4NULL) {
session_shutdown(nbr, S_BAD_TLV_VAL,
msg.id, msg.type);
@@ -547,9 +547,18 @@ gen_fec_tlv(struct ibuf *buf, struct map *map)
ft.length = htons(sizeof(map->type) + sizeof(family) +
sizeof(map->fec.prefix.prefixlen) + len);
err |= ibuf_add(buf, &ft, sizeof(ft));
-
err |= ibuf_add(buf, &map->type, sizeof(map->type));
- family = htons(map->fec.prefix.af);
+ switch (map->fec.prefix.af) {
+ case AF_INET:
+ family = htons(AF_IPV4);
+ break;
+ case AF_INET6:
+ family = htons(AF_IPV6);
+ break;
+ default:
+ fatalx("gen_fec_tlv: unknown af");
+ break;
+ }
err |= ibuf_add(buf, &family, sizeof(family));
err |= ibuf_add(buf, &map->fec.prefix.prefixlen,
sizeof(map->fec.prefix.prefixlen));
@@ -628,10 +637,16 @@ tlv_decode_fec_elm(struct nbr *nbr, struct ldp_msg *msg, char *buf,
/* Address Family */
memcpy(&map->fec.prefix.af, buf + off,
sizeof(map->fec.prefix.af));
- map->fec.prefix.af = ntohs(map->fec.prefix.af);
off += sizeof(map->fec.prefix.af);
- if (map->fec.prefix.af != AF_IPV4 &&
- map->fec.prefix.af != AF_IPV6) {
+ map->fec.prefix.af = ntohs(map->fec.prefix.af);
+ switch (map->fec.prefix.af) {
+ case AF_IPV4:
+ map->fec.prefix.af = AF_INET;
+ break;
+ case AF_IPV6:
+ map->fec.prefix.af = AF_INET6;
+ break;
+ default:
send_notification_nbr(nbr, S_UNSUP_ADDR, msg->id,
msg->type);
return (-1);
@@ -652,6 +667,10 @@ tlv_decode_fec_elm(struct nbr *nbr, struct ldp_msg *msg, char *buf,
memcpy(&map->fec.prefix.prefix, buf + off,
PREFIX_SIZE(map->fec.prefix.prefixlen));
+ /* Just in case... */
+ ldp_applymask(map->fec.prefix.af, &map->fec.prefix.prefix,
+ &map->fec.prefix.prefix, map->fec.prefix.prefixlen);
+
return (off + PREFIX_SIZE(map->fec.prefix.prefixlen));
case MAP_TYPE_PWID:
if (len < FEC_PWID_ELM_MIN_LEN) {