summaryrefslogtreecommitdiff
path: root/proto/static/static.c
diff options
context:
space:
mode:
authorOndrej Zajicek <santiago@crfreenet.org>2015-07-20 11:12:02 +0200
committerOndrej Zajicek <santiago@crfreenet.org>2015-07-20 17:11:10 +0200
commit1321e12ac460bd542d3946a0c4a4dacd71157cfa (patch)
tree7f9470375fdc8fb4bf8c4b76140c6e4686d7e079 /proto/static/static.c
parentffa398b8d8bac4cf6368fe700466cad4ff12fee8 (diff)
Static: Allows to specify attributes for static routes
The patch adds suport for specifying route attributes together with static routes, e.g.: route 10.1.1.0/24 via 10.0.0.1 { krt_advmss = 1200; ospf_metric1 = 100; };
Diffstat (limited to 'proto/static/static.c')
-rw-r--r--proto/static/static.c30
1 files changed, 25 insertions, 5 deletions
diff --git a/proto/static/static.c b/proto/static/static.c
index e7e7ab15..57c44885 100644
--- a/proto/static/static.c
+++ b/proto/static/static.c
@@ -42,11 +42,14 @@
#include "nest/route.h"
#include "nest/cli.h"
#include "conf/conf.h"
+#include "filter/filter.h"
#include "lib/string.h"
#include "lib/alloca.h"
#include "static.h"
+static linpool *static_lp;
+
static inline rtable *
p_igp_table(struct proto *p)
{
@@ -54,12 +57,11 @@ p_igp_table(struct proto *p)
return cf->igp_table ? cf->igp_table->table : p->table;
}
-
static void
static_install(struct proto *p, struct static_route *r, struct iface *ifa)
{
net *n;
- rta a, *aa;
+ rta a;
rte *e;
if (r->installed > 0)
@@ -108,13 +110,21 @@ static_install(struct proto *p, struct static_route *r, struct iface *ifa)
if (r->dest == RTDX_RECURSIVE)
rta_set_recursive_next_hop(p->table, &a, p_igp_table(p), &r->via, &r->via);
- aa = rta_lookup(&a);
+ /* We skip rta_lookup() here */
+
n = net_get(p->table, r->net, r->masklen);
- e = rte_get_temp(aa);
+ e = rte_get_temp(&a);
e->net = n;
e->pflags = 0;
+
+ if (r->cmds)
+ f_eval_rte(r->cmds, &e, static_lp);
+
rte_update(p, n, e);
r->installed = 1;
+
+ if (r->cmds)
+ lp_flush(static_lp);
}
static void
@@ -220,6 +230,9 @@ static_start(struct proto *p)
DBG("Static: take off!\n");
+ if (!static_lp)
+ static_lp = lp_new(&root_pool, 1008);
+
if (cf->igp_table)
rt_lock_table(cf->igp_table->table);
@@ -413,6 +426,13 @@ static_same_dest(struct static_route *x, struct static_route *y)
}
}
+static inline int
+static_same_rte(struct static_route *x, struct static_route *y)
+{
+ return static_same_dest(x, y) && i_same(x->cmds, y->cmds);
+}
+
+
static void
static_match(struct proto *p, struct static_route *r, struct static_config *n)
{
@@ -441,7 +461,7 @@ static_match(struct proto *p, struct static_route *r, struct static_config *n)
found:
/* If destination is different, force reinstall */
- if ((r->installed > 0) && !static_same_dest(r, t))
+ if ((r->installed > 0) && !static_same_rte(r, t))
t->installed = -1;
else
t->installed = r->installed;