diff options
Diffstat (limited to 'lib/tunnel_encaps.c')
-rw-r--r-- | lib/tunnel_encaps.c | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/lib/tunnel_encaps.c b/lib/tunnel_encaps.c index 43fcdbcb..c2b0f60d 100644 --- a/lib/tunnel_encaps.c +++ b/lib/tunnel_encaps.c @@ -1,14 +1,15 @@ #include "lib/tunnel_encaps.h" static -int decode_wireguard(const void *p, size_t sub_tlv_len, wg_key *pubkey, u16 *flags) +int decode_encap(const void *p, size_t sub_tlv_len, void *encap, size_t *encap_size, u16 *flags) { - if (sub_tlv_len != sizeof(wg_key)) { - log(L_TRACE "WG: wireguard len error %d", sub_tlv_len); + if (sub_tlv_len > *encap_size) { + log(L_TRACE "WG: encapsulation len error %d > %d", sub_tlv_len, *encap_size); return -1; } - memcpy(pubkey, p, sizeof(wg_key)); + memcpy(encap, p, sub_tlv_len); + *encap_size = sub_tlv_len; *flags |= FLAG_BGP_TUNNEL_ENCAP_A_SUB_TLV_ENCAP; return 0; } @@ -78,7 +79,7 @@ int decode_tunnel_ep(const void *p, size_t sub_tlv_len, u32 *as4, ip_addr *tunne } static -int decode_sub_tlv(const u8 *p, size_t len, wg_key *pubkey, +int decode_sub_tlv(const u8 *p, size_t len, void *encap, size_t *encap_size, u32 *tunnel_ep_as, ip_addr *tunnel_ep_addr, u32 *color, u16 *udp_dest_port, u16 *flags) { @@ -114,7 +115,7 @@ int decode_sub_tlv(const u8 *p, size_t len, wg_key *pubkey, switch (type) { case BGP_TUNNEL_ENCAP_A_SUB_TLV_ENCAP: - res = decode_wireguard(p, sub_tlv_len, pubkey, flags); + res = decode_encap(p, sub_tlv_len, encap, encap_size, flags); break; case BGP_TUNNEL_ENCAP_A_SUB_TLV_TUNNEL_EP: res = decode_tunnel_ep(p, sub_tlv_len, tunnel_ep_as, tunnel_ep_addr, flags); @@ -137,7 +138,7 @@ int decode_sub_tlv(const u8 *p, size_t len, wg_key *pubkey, return p - first + sub_tlv_len; } -int decode_tunnel_encap(const eattr *e, u16 wg_tunnel_type, wg_key *pubkey, u32 *as4, ip_addr *tunnel_ep, u32 *color, u16 *udp_port, u16 *flags) +int decode_tunnel_encap(const eattr *e, u16 wg_tunnel_type, void *encap, size_t *encap_size, u32 *as4, ip_addr *tunnel_ep, u32 *color, u16 *udp_port, u16 *flags) { const u8 *p = e->u.ptr->data; int len = e->u.ptr->length; @@ -166,7 +167,7 @@ int decode_tunnel_encap(const eattr *e, u16 wg_tunnel_type, wg_key *pubkey, u32 } for (const u8 *cur = p + 4; cur < p + 4 + value_length;) { - int res = decode_sub_tlv(cur, value_length, pubkey, as4, tunnel_ep, color, udp_port, flags); + int res = decode_sub_tlv(cur, value_length, encap, encap_size, as4, tunnel_ep, color, udp_port, flags); if (res < 0) { log(L_TRACE "WG: decode error %d", res); |