]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Static: Add MPLS support
authorOndrej Zajicek <santiago@crfreenet.org>
Thu, 15 Sep 2022 00:29:12 +0000 (02:29 +0200)
committerOndrej Zajicek <santiago@crfreenet.org>
Wed, 4 Oct 2023 11:01:21 +0000 (13:01 +0200)
When MPLS is active, static IP/VPN routes are automatically labeled
according to active label policy and corresponding MPLS routes are
automatically generated.

proto/static/config.Y
proto/static/static.c

index 9d26ee82bb8d96b22150afa3480f8e0b3cca4b1a..c8862171a37222b157ac4575476d843783a32e89 100644 (file)
@@ -63,6 +63,7 @@ static_proto:
    static_proto_start proto_name '{'
  | static_proto proto_item ';'
  | static_proto proto_channel ';' { this_proto->net_type = $2->net_type; }
+ | static_proto mpls_channel ';'
  | static_proto CHECK LINK bool ';' { STATIC_CFG->check_link = $4; }
  | static_proto IGP TABLE rtable ';' {
     if ($4->addr_type == NET_IP4)
index cf7a476843aca4d409863e54a42206e9f3a8405d..35aa91c70e13a67c95483b6709e6b2588bbbf6dc 100644 (file)
@@ -39,6 +39,7 @@
 #include "nest/iface.h"
 #include "nest/protocol.h"
 #include "nest/route.h"
+#include "nest/mpls.h"
 #include "nest/cli.h"
 #include "conf/conf.h"
 #include "filter/filter.h"
@@ -98,6 +99,22 @@ static_announce_rte(struct static_proto *p, struct static_route *r)
     rta_set_recursive_next_hop(p->p.main_channel->table, a, tab, r->via, IPA_NONE, r->mls);
   }
 
+  if (p->p.mpls_channel)
+  {
+    struct mpls_channel *mc = (void *) p->p.mpls_channel;
+
+    ea_list *ea = alloca(sizeof(ea_list) + sizeof(eattr));
+    *ea = (ea_list) { .flags = EALF_SORTED, .count = 1 };
+    ea->next = a->eattrs;
+    a->eattrs = ea;
+
+    ea->attrs[0] = (eattr) {
+      .id = EA_MPLS_POLICY,
+      .type = EAF_TYPE_INT,
+      .u.data = mc->label_policy,
+    };
+  }
+
   /* Already announced */
   if (r->state == SRS_CLEAN)
     return;
@@ -463,6 +480,8 @@ static_init(struct proto_config *CF)
 
   P->main_channel = proto_add_channel(P, proto_cf_main_channel(CF));
 
+  proto_configure_channel(P, &P->mpls_channel, proto_cf_mpls_channel(CF));
+
   P->neigh_notify = static_neigh_notify;
   P->reload_routes = static_reload_routes;
   P->rte_better = static_rte_better;
@@ -497,6 +516,8 @@ static_start(struct proto *P)
 
   BUFFER_INIT(p->marked, p->p.pool, 4);
 
+  proto_setup_mpls_map(P, RTS_STATIC, 1);
+
   /* We have to go UP before routes could be installed */
   proto_notify_state(P, PS_UP);
 
@@ -513,6 +534,8 @@ static_shutdown(struct proto *P)
   struct static_config *cf = (void *) P->cf;
   struct static_route *r;
 
+  proto_shutdown_mpls_map(P, 1);
+
   /* Just reset the flag, the routes will be flushed by the nest */
   WALK_LIST(r, cf->routes)
     static_reset_rte(p, r);
@@ -615,9 +638,12 @@ static_reconfigure(struct proto *P, struct proto_config *CF)
       (IGP_TABLE(o, ip6) != IGP_TABLE(n, ip6)))
     return 0;
 
-  if (!proto_configure_channel(P, &P->main_channel, proto_cf_main_channel(CF)))
+  if (!proto_configure_channel(P, &P->main_channel, proto_cf_main_channel(CF)) ||
+      !proto_configure_channel(P, &P->mpls_channel, proto_cf_mpls_channel(CF)))
     return 0;
 
+  proto_setup_mpls_map(P, RTS_STATIC, 1);
+
   p->p.cf = CF;
 
   /* Reset route lists in neighbor entries */