summaryrefslogtreecommitdiff
path: root/nest
diff options
context:
space:
mode:
authorMaria Matejka <mq@ucw.cz>2021-03-20 23:18:34 +0100
committerMaria Matejka <mq@ucw.cz>2021-10-13 19:09:04 +0200
commitd471d5fc7ce587ed836ca7fa10a79331bc181d45 (patch)
tree557c529dde26bf83da31b5ddcacd5d842d9421bd /nest
parent5cff1d5f022755df61af6fc21cc4f2e5d384404e (diff)
IGP metric getter refactoring to protocol callback
Direct protocol hooks for IGP metric inside nest/rt-table.c make the protocol API unnecessarily complex. Instead, we use a proper callback.
Diffstat (limited to 'nest')
-rw-r--r--nest/protocol.h1
-rw-r--r--nest/rt-table.c36
2 files changed, 5 insertions, 32 deletions
diff --git a/nest/protocol.h b/nest/protocol.h
index 6ee97b7c..62fd2b66 100644
--- a/nest/protocol.h
+++ b/nest/protocol.h
@@ -241,6 +241,7 @@ struct proto {
struct rte * (*rte_modify)(struct rte *, struct linpool *);
void (*rte_insert)(struct network *, struct rte *);
void (*rte_remove)(struct network *, struct rte *);
+ u32 (*rte_igp_metric)(struct rte *);
/* Hic sunt protocol-specific data */
};
diff --git a/nest/rt-table.c b/nest/rt-table.c
index a869bb18..844c7a68 100644
--- a/nest/rt-table.c
+++ b/nest/rt-table.c
@@ -45,10 +45,6 @@
#include "lib/string.h"
#include "lib/alloca.h"
-#ifdef CONFIG_BGP
-#include "proto/bgp/bgp.h"
-#endif
-
pool *rt_table_pool;
static slab *rte_slab;
@@ -3022,36 +3018,12 @@ rt_get_igp_metric(rte *rt)
if (ea)
return ea->u.data;
- rta *a = rt->attrs;
-
-#ifdef CONFIG_OSPF
- if ((a->source == RTS_OSPF) ||
- (a->source == RTS_OSPF_IA) ||
- (a->source == RTS_OSPF_EXT1))
- return rt->u.ospf.metric1;
-#endif
-
-#ifdef CONFIG_RIP
- if (a->source == RTS_RIP)
- return rt->u.rip.metric;
-#endif
-
-#ifdef CONFIG_BGP
- if (a->source == RTS_BGP)
- {
- u64 metric = bgp_total_aigp_metric(rt);
- return (u32) MIN(metric, (u64) IGP_METRIC_UNKNOWN);
- }
-#endif
-
-#ifdef CONFIG_BABEL
- if (a->source == RTS_BABEL)
- return rt->u.babel.metric;
-#endif
-
- if (a->source == RTS_DEVICE)
+ if (rt->attrs->source == RTS_DEVICE)
return 0;
+ if (rt->src->proto->rte_igp_metric)
+ return rt->src->proto->rte_igp_metric(rt);
+
return IGP_METRIC_UNKNOWN;
}