summaryrefslogtreecommitdiff
path: root/proto/static
diff options
context:
space:
mode:
authorOndrej Zajicek <santiago@crfreenet.org>2022-09-15 02:29:12 +0200
committerOndrej Zajicek <santiago@crfreenet.org>2023-10-04 13:01:21 +0200
commit15c86ed061d3dbc7e4ef863e396cda5ec3ed0d4c (patch)
tree2ceceb99ac0fe6789cdfffc23977d0b8ac39edc6 /proto/static
parent333ddd4f981b90d5d3dff166b6abf9bf40bede9f (diff)
Static: Add MPLS support
When MPLS is active, static IP/VPN routes are automatically labeled according to active label policy and corresponding MPLS routes are automatically generated.
Diffstat (limited to 'proto/static')
-rw-r--r--proto/static/config.Y1
-rw-r--r--proto/static/static.c28
2 files changed, 28 insertions, 1 deletions
diff --git a/proto/static/config.Y b/proto/static/config.Y
index 9d26ee82..c8862171 100644
--- a/proto/static/config.Y
+++ b/proto/static/config.Y
@@ -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)
diff --git a/proto/static/static.c b/proto/static/static.c
index cf7a4768..35aa91c7 100644
--- a/proto/static/static.c
+++ b/proto/static/static.c
@@ -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 */