]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Filter: Add MPLS label route attribute
authorTrisha Biswas <tbiswas@fastly.com>
Mon, 17 May 2021 15:50:04 +0000 (17:50 +0200)
committerOndrej Zajicek (work) <santiago@crfreenet.org>
Mon, 17 May 2021 15:50:04 +0000 (17:50 +0200)
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.

doc/bird.sgml
filter/config.Y
filter/data.h
filter/f-inst.c
lib/ip.h

index c4d2c49b51546c03e70bcb280fc18ace5c6668bf..51a92ce948e0382c8a8e55b05e56ef7b39f21b55 100644 (file)
@@ -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
index 5cd52e40e4411d0236f430d8fcd525726b5f1aa3..7820e719d65298e2a16c07203a8e706ff9c50794 100644 (file)
@@ -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:
index 61cdb43e27296c232a09ef152d4286e576a943e8..d296776d934d3cca124eb92e0ced1db83cbd9b16 100644 (file)
@@ -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) */
index 1378fe4a499f360463b1a7697937b216e6c7a789..b876a937226583aa6ce58b436489399c3026c5c7 100644 (file)
       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);
          rta->nh.iface = n->iface;
          rta->nh.next = NULL;
          rta->hostentry = NULL;
+         rta->nh.labels = 0;
        }
        break;
 
          rta->nh.iface = NULL;
          rta->nh.next = NULL;
          rta->hostentry = NULL;
+         rta->nh.labels = 0;
        }
        break;
 
          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;
 
index f3b1cc31f99372df073ebf3f81b43f0713e939a7..5b179acbc94294514f16bd3c93690de7b59d9593 100644 (file)
--- 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 */