diff options
author | 2011-01-10 11:58:39 +0000 | |
---|---|---|
committer | 2011-01-10 11:58:39 +0000 | |
commit | 4bde5742321c4885c9ddf74ef1b49b3902f86401 (patch) | |
tree | 9409ac45805fdbc1175432685a12c9df37c5d017 | |
parent | Rename struct fec_tlv to struct tlv since it is just the generic (diff) | |
download | wireguard-openbsd-4bde5742321c4885c9ddf74ef1b49b3902f86401.tar.xz wireguard-openbsd-4bde5742321c4885c9ddf74ef1b49b3902f86401.zip |
Better optional parameter parsing. Ignore unknown TLVs that have
the U flag set. Kill struct hello_opt_parms_tlv since it is now
unused.
-rw-r--r-- | usr.sbin/ldpd/hello.c | 33 | ||||
-rw-r--r-- | usr.sbin/ldpd/ldp.h | 8 |
2 files changed, 20 insertions, 21 deletions
diff --git a/usr.sbin/ldpd/hello.c b/usr.sbin/ldpd/hello.c index a0d81d01259..ef9e3e3d94d 100644 --- a/usr.sbin/ldpd/hello.c +++ b/usr.sbin/ldpd/hello.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hello.c,v 1.8 2011/01/08 14:50:29 claudio Exp $ */ +/* $OpenBSD: hello.c,v 1.9 2011/01/10 11:58:39 claudio Exp $ */ /* * Copyright (c) 2009 Michele Marchetto <michele@openbsd.org> @@ -202,32 +202,37 @@ int tlv_decode_opt_hello_prms(char *buf, u_int16_t len, struct in_addr *addr, u_int32_t *conf_number) { - struct hello_opt_parms_tlv tlv; - int cons = 0; + struct tlv tlv; + int cons = 0; + u_int16_t tlv_len; bzero(addr, sizeof(*addr)); *conf_number = 0; while (len >= sizeof(tlv)) { bcopy(buf, &tlv, sizeof(tlv)); - - if (ntohs(tlv.length) < sizeof(u_int32_t)) - return (-1); - + tlv_len = ntohs(tlv.length); switch (ntohs(tlv.type)) { case TLV_TYPE_IPV4TRANSADDR: - addr->s_addr = tlv.value; + if (tlv_len < sizeof(u_int32_t)) + return (-1); + bcopy(buf + TLV_HDR_LEN, addr, sizeof(u_int32_t)); break; case TLV_TYPE_CONFIG: - *conf_number = ntohl(tlv.value); + if (tlv_len < sizeof(u_int32_t)) + return (-1); + bcopy(buf + TLV_HDR_LEN, conf_number, + sizeof(u_int32_t)); break; default: - return (-1); + /* if unknown flag set, ignore TLV */ + if (!(ntohs(tlv.type) & UNKNOWN_FLAG)) + return (-1); + break; } - - len -= sizeof(tlv); - buf += sizeof(tlv); - cons += sizeof(tlv); + buf += TLV_HDR_LEN + tlv_len; + len -= TLV_HDR_LEN + tlv_len; + cons += TLV_HDR_LEN + tlv_len; } return (cons); diff --git a/usr.sbin/ldpd/ldp.h b/usr.sbin/ldpd/ldp.h index 5a944bf426f..62e1f667be3 100644 --- a/usr.sbin/ldpd/ldp.h +++ b/usr.sbin/ldpd/ldp.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ldp.h,v 1.8 2011/01/10 11:52:04 claudio Exp $ */ +/* $OpenBSD: ldp.h,v 1.9 2011/01/10 11:58:39 claudio Exp $ */ /* * Copyright (c) 2009 Michele Marchetto <michele@openbsd.org> @@ -221,12 +221,6 @@ struct reqid_tlv { #define REQID_TLV_LEN 8 -struct hello_opt_parms_tlv { - u_int16_t type; - u_int16_t length; - u_int32_t value; -}; - #define NO_LABEL UINT_MAX #endif /* !_LDP_H_ */ |