summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaria Matejka <mq@ucw.cz>2022-04-20 10:25:14 +0200
committerMaria Matejka <mq@ucw.cz>2022-05-04 15:39:21 +0200
commitd8661a4397e4576ac404661b192dd99d928e7890 (patch)
treee158c76950fc1909c3a6d97f7eec44aecab03278
parent17f91f9e6e70f7e3f29502e854823c0d48571eaa (diff)
Joined the RTA igp_metric and EA igp_metric attributes
-rw-r--r--lib/route.h7
-rw-r--r--nest/rt-attr.c2
-rw-r--r--nest/rt-table.c6
-rw-r--r--proto/bgp/attrs.c16
-rw-r--r--proto/bgp/packets.c2
5 files changed, 15 insertions, 18 deletions
diff --git a/lib/route.h b/lib/route.h
index f24fd555..3b368696 100644
--- a/lib/route.h
+++ b/lib/route.h
@@ -85,7 +85,6 @@ typedef struct rta {
struct ea_list *eattrs; /* Extended Attribute chain */
struct hostentry *hostentry; /* Hostentry for recursive next-hops */
ip_addr from; /* Advertising router */
- u32 igp_metric; /* IGP metric to next hop (for iBGP routes) */
u16 cached:1; /* Are attributes cached? */
u16 source:7; /* Route source (RTS_...) */
u16 scope:4; /* Route scope (SCOPE_... -- see ip.h) */
@@ -118,10 +117,6 @@ typedef struct rta {
#define RTD_PROHIBIT 4 /* Administratively prohibited */
#define RTD_MAX 5
-#define IGP_METRIC_UNKNOWN 0x80000000 /* Default igp_metric used when no other
- protocol-specific metric is availabe */
-
-
extern const char * rta_dest_names[RTD_MAX];
static inline const char *rta_dest_name(uint n)
@@ -186,6 +181,8 @@ struct ea_class_ref {
struct ea_class *class;
};
+#define IGP_METRIC_UNKNOWN 0x80000000 /* Default igp_metric used when no other
+ protocol-specific metric is availabe */
extern struct ea_class ea_gen_igp_metric;
void ea_register_init(struct ea_class *);
diff --git a/nest/rt-attr.c b/nest/rt-attr.c
index a763db4d..6bb27623 100644
--- a/nest/rt-attr.c
+++ b/nest/rt-attr.c
@@ -1225,7 +1225,6 @@ rta_hash(rta *a)
#define BMIX(f) mem_hash_mix_num(&h, a->f);
MIX(hostentry);
MIX(from);
- MIX(igp_metric);
BMIX(source);
BMIX(scope);
BMIX(dest);
@@ -1241,7 +1240,6 @@ rta_same(rta *x, rta *y)
return (x->source == y->source &&
x->scope == y->scope &&
x->dest == y->dest &&
- x->igp_metric == y->igp_metric &&
ipa_equal(x->from, y->from) &&
x->hostentry == y->hostentry &&
nexthop_same(&(x->nh), &(y->nh)) &&
diff --git a/nest/rt-table.c b/nest/rt-table.c
index af59d63b..01194e02 100644
--- a/nest/rt-table.c
+++ b/nest/rt-table.c
@@ -2386,7 +2386,8 @@ rta_apply_hostentry(rta *a, struct hostentry *he, mpls_label_stack *mls)
{
a->hostentry = he;
a->dest = he->dest;
- a->igp_metric = he->igp_metric;
+
+ ea_set_attr_u32(&a->eattrs, &ea_gen_igp_metric, 0, he->igp_metric);
if (a->dest != RTD_UNICAST)
{
@@ -2483,7 +2484,8 @@ rta_next_hop_outdated(rta *a)
if (!he->src)
return a->dest != RTD_UNREACHABLE;
- return (a->dest != he->dest) || (a->igp_metric != he->igp_metric) ||
+ return (a->dest != he->dest) ||
+ (ea_get_int(a->eattrs, &ea_gen_igp_metric, IGP_METRIC_UNKNOWN) != he->igp_metric) ||
(!he->nexthop_linkable) || !nexthop_same(&(a->nh), &(he->src->nh));
}
diff --git a/proto/bgp/attrs.c b/proto/bgp/attrs.c
index 72a4f68a..597cf96c 100644
--- a/proto/bgp/attrs.c
+++ b/proto/bgp/attrs.c
@@ -383,7 +383,7 @@ bgp_total_aigp_metric_(rte *e, u64 *metric, const struct adata **ad)
return 0;
u64 aigp = get_u64(b + 3);
- u64 step = e->attrs->igp_metric;
+ u64 step = rt_get_igp_metric(e);
if (!rte_resolvable(e) || (step >= IGP_METRIC_UNKNOWN))
step = BGP_AIGP_MAX;
@@ -2046,8 +2046,8 @@ bgp_rte_better(rte *new, rte *old)
return 1;
/* RFC 4271 9.1.2.2. e) Compare IGP metrics */
- n = new_bgp->cf->igp_metric ? new->attrs->igp_metric : 0;
- o = old_bgp->cf->igp_metric ? old->attrs->igp_metric : 0;
+ n = new_bgp->cf->igp_metric ? rt_get_igp_metric(new) : 0;
+ o = old_bgp->cf->igp_metric ? rt_get_igp_metric(old) : 0;
if (n < o)
return 1;
if (n > o)
@@ -2155,8 +2155,8 @@ bgp_rte_mergable(rte *pri, rte *sec)
return 0;
/* RFC 4271 9.1.2.2. e) Compare IGP metrics */
- p = pri_bgp->cf->igp_metric ? pri->attrs->igp_metric : 0;
- s = sec_bgp->cf->igp_metric ? sec->attrs->igp_metric : 0;
+ p = pri_bgp->cf->igp_metric ? rt_get_igp_metric(pri) : 0;
+ s = sec_bgp->cf->igp_metric ? rt_get_igp_metric(sec) : 0;
if (p != s)
return 0;
@@ -2394,14 +2394,14 @@ bgp_get_route_info(rte *e, byte *buf)
{
buf += bsprintf(buf, "/%lu", metric);
}
- else if (e->attrs->igp_metric)
+ else if (metric = rt_get_igp_metric(e))
{
if (!rte_resolvable(e))
buf += bsprintf(buf, "/-");
- else if (e->attrs->igp_metric >= IGP_METRIC_UNKNOWN)
+ else if (metric >= IGP_METRIC_UNKNOWN)
buf += bsprintf(buf, "/?");
else
- buf += bsprintf(buf, "/%d", e->attrs->igp_metric);
+ buf += bsprintf(buf, "/%d", metric);
}
buf += bsprintf(buf, ") [");
diff --git a/proto/bgp/packets.c b/proto/bgp/packets.c
index a18ff373..5c9bb8ba 100644
--- a/proto/bgp/packets.c
+++ b/proto/bgp/packets.c
@@ -969,7 +969,7 @@ bgp_apply_next_hop(struct bgp_parse_state *s, rta *a, ip_addr gw, ip_addr ll)
a->dest = RTD_UNICAST;
a->nh.gw = nbr->addr;
a->nh.iface = nbr->iface;
- a->igp_metric = c->cf->cost;
+ ea_set_attr_u32(&a->eattrs, &ea_gen_igp_metric, 0, c->cf->cost);
}
else /* GW_RECURSIVE */
{