summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikael Magnusson <mikma@users.sourceforge.net>2018-09-04 18:32:42 +0000
committerMikael Magnusson <mikma@users.sourceforge.net>2021-11-06 00:07:40 +0100
commit7eb6a44491501e3f403fde2e26affb673f5b5b11 (patch)
treeb35f07c8781be6e21c8023fc30bd603bb90fd3cf
parent2304b9ba639ce05449a0ec74e04f9ab76bcaa253 (diff)
BGP: Tunnel Encapsulation attribute
Refer to RFC 9012, The BGP Tunnel Encapsulation Attribute. Improve format function DOC Minor fix Fix debug
-rw-r--r--proto/bgp/attrs.c43
-rw-r--r--proto/bgp/bgp.h1
-rw-r--r--proto/bgp/config.Y4
3 files changed, 47 insertions, 1 deletions
diff --git a/proto/bgp/attrs.c b/proto/bgp/attrs.c
index 24ba00ba..1cf3cd77 100644
--- a/proto/bgp/attrs.c
+++ b/proto/bgp/attrs.c
@@ -21,6 +21,7 @@
#include "lib/resource.h"
#include "lib/string.h"
#include "lib/unaligned.h"
+#include "lib/tunnel_encaps.h"
#include "bgp.h"
@@ -894,6 +895,39 @@ 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 UNUSED, eattr *a)
+{
+ if (a->u.ptr->length == 0)
+ UNSET(a);
+
+ /*
+ * TODO: In situations where a tunnel could be encoded using a barebones TLV,
+ * it MUST be encoded using the corresponding Encapsulation Extended
+ * Community. (RFC9012 section 4.1)
+ */
+}
+
+static void
+bgp_decode_tunnel_encap(struct bgp_parse_state *s, uint code UNUSED, uint flags, byte *data, uint len, ea_list **to)
+{
+ 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)
+{
+ 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(const eattr *a, byte *buf, uint size)
+{
+ int l = format_tunnel_encap(a->u.ptr, buf, size);
+ if (l > 0)
+ ADVANCE(buf, size, l);
+}
+
+static void
bgp_export_mpls_label_stack(struct bgp_export_state *s, eattr *a)
{
net_addr *n = s->route->net->n.addr;
@@ -1106,6 +1140,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,
diff --git a/proto/bgp/bgp.h b/proto/bgp/bgp.h
index cca4b448..679d6bfe 100644
--- a/proto/bgp/bgp.h
+++ b/proto/bgp/bgp.h
@@ -652,6 +652,7 @@ void bgp_update_next_hop(struct bgp_export_state *s, eattr *a, ea_list **to);
#define BA_EXT_COMMUNITY 0x10 /* RFC 4360 */
#define BA_AS4_PATH 0x11 /* RFC 6793 */
#define BA_AS4_AGGREGATOR 0x12 /* RFC 6793 */
+#define BA_TUNNEL_ENCAP 0x17 /* RFC 9012 */
#define BA_AIGP 0x1a /* RFC 7311 */
#define BA_LARGE_COMMUNITY 0x20 /* RFC 8092 */
diff --git a/proto/bgp/config.Y b/proto/bgp/config.Y
index 2dfbdca9..542665b7 100644
--- a/proto/bgp/config.Y
+++ b/proto/bgp/config.Y
@@ -31,7 +31,7 @@ CF_KEYWORDS(BGP, LOCAL, NEIGHBOR, AS, HOLD, TIME, CONNECT, RETRY, KEEPALIVE,
STRICT, BIND, CONFEDERATION, MEMBER, MULTICAST, FLOW4, FLOW6, LONG,
LIVED, STALE, IMPORT, IBGP, EBGP, MANDATORY, INTERNAL, EXTERNAL, SETS,
DYNAMIC, RANGE, NAME, DIGITS, BGP_AIGP, AIGP, ORIGINATE, COST, ENFORCE,
- FIRST)
+ FIRST, BGP_TUNNEL_ENCAP)
%type <i> bgp_nh
%type <i32> bgp_afi
@@ -327,6 +327,8 @@ dynamic_attr: BGP_AIGP
{ $$ = f_new_dynamic_attr(EAF_TYPE_OPAQUE, T_ENUM_EMPTY, EA_CODE(PROTOCOL_BGP, BA_AIGP)); } ;
dynamic_attr: BGP_LARGE_COMMUNITY
{ $$ = f_new_dynamic_attr(EAF_TYPE_LC_SET, T_LCLIST, EA_CODE(PROTOCOL_BGP, BA_LARGE_COMMUNITY)); } ;
+dynamic_attr: BGP_TUNNEL_ENCAP
+ { $$ = f_new_dynamic_attr(EAF_TYPE_TUNNEL_ENCAP, T_TLVLIST, EA_CODE(PROTOCOL_BGP, BA_TUNNEL_ENCAP)); } ;