summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrisha Biswas <tbiswas@fastly.com>2021-05-17 17:50:04 +0200
committerOndrej Zajicek (work) <santiago@crfreenet.org>2021-05-17 17:50:04 +0200
commite5468d16855600aeb8172e29936789c46ea58da0 (patch)
tree0480a2e2124bfe69a72cdaa6e82a6bb0a76d63af
parentd114959e3aeef872441dccea34552047380af742 (diff)
Filter: Add MPLS label route attribute
Add support to set or read outgoing MPLS labels using filters. Currently this supports the addition of one label per route for the first next hop. Minor changes by committer.
-rw-r--r--doc/bird.sgml9
-rw-r--r--filter/config.Y3
-rw-r--r--filter/data.h1
-rw-r--r--filter/f-inst.c19
-rw-r--r--lib/ip.h2
5 files changed, 33 insertions, 1 deletions
diff --git a/doc/bird.sgml b/doc/bird.sgml
index c4d2c49b..51a92ce9 100644
--- a/doc/bird.sgml
+++ b/doc/bird.sgml
@@ -1716,6 +1716,15 @@ Common route attributes are:
are merged to one ECMP route during export to the Kernel protocol
(with active <ref id="krt-merge-paths" name="marge paths"> option).
+ <tag><label id="rta-gw-mpls"><m/int/ gw_mpls</tag>
+ Outgoing MPLS label attached to route (i.e., incoming MPLS label on the
+ next hop router for this label-switched path). Reading returns the label
+ value and setting it sets it to the start of the label stack. Setting
+ implicit-NULL label (3) disables the MPLS label stack. Only the first
+ next hop and only one label in the label stack supported right now. This
+ is experimental option, will be likely changed in the future to handle
+ full MPLS label stack.
+
<tag><label id="rta-igp-metric"><m/int/ igp_metric</tag>
The optional attribute that can be used to specify a distance to the
network for routes that do not have a native protocol metric attribute
diff --git a/filter/config.Y b/filter/config.Y
index 5cd52e40..7820e719 100644
--- a/filter/config.Y
+++ b/filter/config.Y
@@ -278,7 +278,7 @@ CF_KEYWORDS(FUNCTION, PRINT, PRINTN, UNSET, RETURN,
SET, STRING, BGPMASK, BGPPATH, CLIST, ECLIST, LCLIST,
IF, THEN, ELSE, CASE,
TRUE, FALSE, RT, RO, UNKNOWN, GENERIC,
- FROM, GW, NET, MASK, PROTO, SOURCE, SCOPE, DEST, IFNAME, IFINDEX, WEIGHT,
+ FROM, GW, NET, MASK, PROTO, SOURCE, SCOPE, DEST, IFNAME, IFINDEX, WEIGHT, GW_MPLS,
PREFERENCE,
ROA_CHECK, ASN, SRC, DST,
IS_V4, IS_V6,
@@ -751,6 +751,7 @@ static_attr:
| IFNAME { $$ = f_new_static_attr(T_STRING, SA_IFNAME, 0); }
| IFINDEX { $$ = f_new_static_attr(T_INT, SA_IFINDEX, 1); }
| WEIGHT { $$ = f_new_static_attr(T_INT, SA_WEIGHT, 0); }
+ | GW_MPLS { $$ = f_new_static_attr(T_INT, SA_GW_MPLS, 0); }
;
term:
diff --git a/filter/data.h b/filter/data.h
index 61cdb43e..d296776d 100644
--- a/filter/data.h
+++ b/filter/data.h
@@ -100,6 +100,7 @@ enum f_sa_code {
SA_IFNAME,
SA_IFINDEX,
SA_WEIGHT,
+ SA_GW_MPLS,
} PACKED;
/* Static attribute definition (members of struct rta) */
diff --git a/filter/f-inst.c b/filter/f-inst.c
index 1378fe4a..b876a937 100644
--- a/filter/f-inst.c
+++ b/filter/f-inst.c
@@ -533,6 +533,7 @@
case SA_IFNAME: RESULT(sa.f_type, s, rta->nh.iface ? rta->nh.iface->name : ""); break;
case SA_IFINDEX: RESULT(sa.f_type, i, rta->nh.iface ? rta->nh.iface->index : 0); break;
case SA_WEIGHT: RESULT(sa.f_type, i, rta->nh.weight + 1); break;
+ case SA_GW_MPLS: RESULT(sa.f_type, i, rta->nh.labels ? rta->nh.label[0] : MPLS_NULL); break;
default:
bug("Invalid static attribute access (%u/%u)", sa.f_type, sa.sa_code);
@@ -569,6 +570,7 @@
rta->nh.iface = n->iface;
rta->nh.next = NULL;
rta->hostentry = NULL;
+ rta->nh.labels = 0;
}
break;
@@ -587,6 +589,7 @@
rta->nh.iface = NULL;
rta->nh.next = NULL;
rta->hostentry = NULL;
+ rta->nh.labels = 0;
}
break;
@@ -601,6 +604,22 @@
rta->nh.iface = ifa;
rta->nh.next = NULL;
rta->hostentry = NULL;
+ rta->nh.labels = 0;
+ }
+ break;
+
+ case SA_GW_MPLS:
+ {
+ if (v1.val.i >= 0x100000)
+ runtime( "Invalid MPLS label" );
+
+ if (v1.val.i != MPLS_NULL)
+ {
+ rta->nh.label[0] = v1.val.i;
+ rta->nh.labels = 1;
+ }
+ else
+ rta->nh.labels = 0;
}
break;
diff --git a/lib/ip.h b/lib/ip.h
index f3b1cc31..5b179acb 100644
--- a/lib/ip.h
+++ b/lib/ip.h
@@ -47,6 +47,8 @@
#define IP6_HEADER_LENGTH 40
#define UDP_HEADER_LENGTH 8
+#define MPLS_NULL 3
+
/* IANA Address Family Numbers */
/* https://www.iana.org/assignments/address-family-numbers/address-family-numbers.xhtml */