diff options
author | Mikael Magnusson <mikma@users.sourceforge.net> | 2018-09-04 18:32:42 +0000 |
---|---|---|
committer | Mikael Magnusson <mikma@users.sourceforge.net> | 2020-05-08 18:52:55 +0200 |
commit | 54695136df632371e317f66374a4bd9d2accef8c (patch) | |
tree | 7b27f3f9520f95768655485debc07cb1b1fe2de1 /proto/bgp/attrs.c | |
parent | f271a1914e812f983e9d02178446c9351e586b9e (diff) |
BGP: Tunnel Encapsulation attribute
Refer to draft-ietf-idr-tunnel-encaps-13
Diffstat (limited to 'proto/bgp/attrs.c')
-rw-r--r-- | proto/bgp/attrs.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/proto/bgp/attrs.c b/proto/bgp/attrs.c index 4710bfba..dec58cbd 100644 --- a/proto/bgp/attrs.c +++ b/proto/bgp/attrs.c @@ -863,6 +863,54 @@ bgp_decode_large_community(struct bgp_parse_state *s, uint code UNUSED, uint fla } static void +bgp_export_tunnel_encap(struct bgp_export_state *s, eattr *a) +{ + REPORT("bgp_export_tunnel_encap"); + if (a->u.ptr->length == 0) + UNSET(a); + + // a->u.ptr = lc_set_sort(s->pool, a->u.ptr); +} + +static void +bgp_decode_tunnel_encap(struct bgp_parse_state *s, uint code UNUSED, uint flags, byte *data, uint len, ea_list **to) +{ + REPORT("bgp_decode_tunnel_encap %d", len); + bgp_set_attr_data(to, s->pool, BA_TUNNEL_ENCAP, flags, data, len); +} + +static int +bgp_encode_tunnel_encap(struct bgp_write_state *s UNUSED, eattr *a, byte *buf, uint size) +{ + REPORT("bgp_encode_tunnel_encap %d", size); + return bgp_put_attr(buf, size, EA_ID(a->id), a->flags, a->u.ptr->data, a->u.ptr->length); +} + +static void +bgp_format_tunnel_encap(eattr *a, byte *buf, uint size) +{ + char *pos = buf; + + if (a->u.ptr->length == 0) + { + bsprintf(pos, ""); + return; + } + + for (uint i = 0; i < a->u.ptr->length; i++) + { + if (size < 4) + { + bsprintf(pos, "..."); + return; + } + + uint l = bsprintf(pos, "%02x ", a->u.ptr->data[i]); + ADVANCE(pos, size, l); + } +} + +static void bgp_export_mpls_label_stack(struct bgp_export_state *s, eattr *a) { net_addr *n = s->route->net->n.addr; @@ -934,6 +982,7 @@ bgp_format_mpls_label_stack(const eattr *a, byte *buf, uint size) static inline void bgp_decode_unknown(struct bgp_parse_state *s, uint code, uint flags, byte *data, uint len, ea_list **to) { + REPORT("unknown %x %x", code, flags); /* Cannot use bgp_set_attr_data() as it works on known attributes only */ ea_set_attr_data(to, s->pool, EA_CODE(PROTOCOL_BGP, code), flags, EAF_TYPE_OPAQUE, data, len); } @@ -1075,6 +1124,15 @@ static const struct bgp_attr_desc bgp_attr_table[] = { .encode = bgp_encode_u32s, .decode = bgp_decode_large_community, }, + [BA_TUNNEL_ENCAP] = { + .name = "tunnel_encap", + .type = EAF_TYPE_TUNNEL_ENCAP, + .flags = BAF_OPTIONAL | BAF_TRANSITIVE, + .export = bgp_export_tunnel_encap, + .encode = bgp_encode_tunnel_encap, + .decode = bgp_decode_tunnel_encap, + .format = bgp_format_tunnel_encap, + }, [BA_MPLS_LABEL_STACK] = { .name = "mpls_label_stack", .type = EAF_TYPE_INT_SET, |