summaryrefslogtreecommitdiff
path: root/proto
diff options
context:
space:
mode:
authorMaria Matejka <mq@ucw.cz>2022-04-20 12:24:26 +0200
committerMaria Matejka <mq@ucw.cz>2022-05-04 15:39:21 +0200
commit337c04c45e1472d6d9b531a3c55f1f2d30ebf308 (patch)
tree7526f6f33a6a57404ed9b15588b1a3fc3eb40182 /proto
parentd8661a4397e4576ac404661b192dd99d928e7890 (diff)
Moved route preference to eattrs
Diffstat (limited to 'proto')
-rw-r--r--proto/babel/babel.c12
-rw-r--r--proto/bgp/attrs.c6
-rw-r--r--proto/bgp/packets.c2
-rw-r--r--proto/ospf/ospf.c2
-rw-r--r--proto/ospf/rt.c6
-rw-r--r--proto/perf/perf.c3
-rw-r--r--proto/rip/rip.c8
-rw-r--r--proto/rpki/rpki.c3
-rw-r--r--proto/static/static.c7
9 files changed, 28 insertions, 21 deletions
diff --git a/proto/babel/babel.c b/proto/babel/babel.c
index 97dca4ac..afd0b1e1 100644
--- a/proto/babel/babel.c
+++ b/proto/babel/babel.c
@@ -645,10 +645,11 @@ babel_announce_rte(struct babel_proto *p, struct babel_entry *e)
{
struct {
ea_list l;
- eattr a[3];
+ eattr a[4];
} eattrs = {
- .l.count = 3,
+ .l.count = ARRAY_SIZE(eattrs.a),
.a = {
+ EA_LITERAL_EMBEDDED(&ea_gen_preference, 0, c->preference),
EA_LITERAL_EMBEDDED(&ea_babel_metric, 0, r->metric),
EA_LITERAL_STORE_ADATA(&ea_babel_router_id, 0, &r->router_id, sizeof(r->router_id)),
EA_LITERAL_EMBEDDED(&ea_babel_seqno, 0, r->seqno),
@@ -659,7 +660,6 @@ babel_announce_rte(struct babel_proto *p, struct babel_entry *e)
.source = RTS_BABEL,
.scope = SCOPE_UNIVERSE,
.dest = RTD_UNICAST,
- .pref = c->preference,
.from = r->neigh->addr,
.nh.gw = r->next_hop,
.nh.iface = r->neigh->ifa->iface,
@@ -687,9 +687,10 @@ babel_announce_rte(struct babel_proto *p, struct babel_entry *e)
.source = RTS_BABEL,
.scope = SCOPE_UNIVERSE,
.dest = RTD_UNREACHABLE,
- .pref = 1,
};
+ ea_set_attr_u32(&a0.eattrs, &ea_gen_preference, 0, 1);
+
rta *a = rta_lookup(&a0);
rte *rte = rte_get_temp(a, p->p.main_source);
rte->pflags = 0;
@@ -2025,7 +2026,8 @@ babel_get_route_info(rte *rte, byte *buf)
if (e)
memcpy(&rid, e->u.ptr->data, sizeof(u64));
- buf += bsprintf(buf, " (%d/%d) [%lR]", rte->attrs->pref,
+ buf += bsprintf(buf, " (%d/%d) [%lR]",
+ rt_get_preference(rte),
ea_get_int(rte->attrs->eattrs, &ea_babel_metric, BABEL_INFINITY), rid);
}
diff --git a/proto/bgp/attrs.c b/proto/bgp/attrs.c
index 597cf96c..097ba9a2 100644
--- a/proto/bgp/attrs.c
+++ b/proto/bgp/attrs.c
@@ -2169,7 +2169,7 @@ bgp_rte_mergable(rte *pri, rte *sec)
static inline int
same_group(rte *r, u32 lpref, u32 lasn)
{
- return (r->attrs->pref == lpref) && (bgp_get_neighbor(r) == lasn);
+ return (rt_get_preference(r) == lpref) && (bgp_get_neighbor(r) == lasn);
}
static inline int
@@ -2184,7 +2184,7 @@ bgp_rte_recalculate(rtable *table, net *net, rte *new, rte *old, rte *old_best)
{
rte *r, *s;
rte *key = new ? new : old;
- u32 lpref = key->attrs->pref;
+ u32 lpref = rt_get_preference(key);
u32 lasn = bgp_get_neighbor(key);
int old_suppressed = old ? !!(old->pflags & BGP_REF_SUPPRESSED) : 0;
@@ -2381,7 +2381,7 @@ bgp_get_route_info(rte *e, byte *buf)
eattr *o = ea_find(e->attrs->eattrs, BGP_EA_ID(BA_ORIGIN));
u32 origas;
- buf += bsprintf(buf, " (%d", e->attrs->pref);
+ buf += bsprintf(buf, " (%d", rt_get_preference(e));
if (e->pflags & BGP_REF_SUPPRESSED)
buf += bsprintf(buf, "-");
diff --git a/proto/bgp/packets.c b/proto/bgp/packets.c
index 5c9bb8ba..45a4b1de 100644
--- a/proto/bgp/packets.c
+++ b/proto/bgp/packets.c
@@ -2478,7 +2478,7 @@ bgp_decode_nlri(struct bgp_parse_state *s, u32 afi, byte *nlri, uint len, ea_lis
a->scope = SCOPE_UNIVERSE;
a->from = s->proto->remote_ip;
a->eattrs = ea;
- a->pref = c->c.preference;
+ ea_set_attr_u32(&a->eattrs, &ea_gen_preference, 0, c->c.preference);
c->desc->decode_next_hop(s, nh, nh_len, a);
bgp_finish_attrs(s, a);
diff --git a/proto/ospf/ospf.c b/proto/ospf/ospf.c
index 66d0eba6..427c2c86 100644
--- a/proto/ospf/ospf.c
+++ b/proto/ospf/ospf.c
@@ -588,7 +588,7 @@ ospf_get_route_info(rte * rte, byte * buf)
}
buf += bsprintf(buf, " %s", type);
- buf += bsprintf(buf, " (%d/%d", rte->attrs->pref, ea_get_int(rte->attrs->eattrs, &ea_ospf_metric1, LSINFINITY));
+ buf += bsprintf(buf, " (%d/%d", rt_get_preference(rte), ea_get_int(rte->attrs->eattrs, &ea_ospf_metric1, LSINFINITY));
if (rte->attrs->source == RTS_OSPF_EXT2)
buf += bsprintf(buf, "/%d", ea_get_int(rte->attrs->eattrs, &ea_ospf_metric2, LSINFINITY));
buf += bsprintf(buf, ")");
diff --git a/proto/ospf/rt.c b/proto/ospf/rt.c
index 55bad599..3d8cf22c 100644
--- a/proto/ospf/rt.c
+++ b/proto/ospf/rt.c
@@ -2057,7 +2057,6 @@ again1:
.scope = SCOPE_UNIVERSE,
.dest = RTD_UNICAST,
.nh = *(nf->n.nhs),
- .pref = p->p.main_channel->preference,
};
if (reload || ort_changed(nf, &a0))
@@ -2069,12 +2068,15 @@ again1:
struct {
ea_list l;
- eattr a[4];
+ eattr a[5];
} eattrs;
eattrs.l = (ea_list) {};
eattrs.a[eattrs.l.count++] =
+ EA_LITERAL_EMBEDDED(&ea_gen_preference, 0, p->p.main_channel->preference);
+
+ eattrs.a[eattrs.l.count++] =
EA_LITERAL_EMBEDDED(&ea_ospf_metric1, 0, nf->n.metric1);
if (nf->n.type == RTS_OSPF_EXT2)
diff --git a/proto/perf/perf.c b/proto/perf/perf.c
index 2978100b..7b18866c 100644
--- a/proto/perf/perf.c
+++ b/proto/perf/perf.c
@@ -146,12 +146,13 @@ perf_loop(void *data)
.source = RTS_PERF,
.scope = SCOPE_UNIVERSE,
.dest = RTD_UNICAST,
- .pref = p->p.main_channel->preference,
.nh.iface = p->ifa->iface,
.nh.gw = gw,
.nh.weight = 1,
};
+ ea_set_attr_u32(&a0.eattrs, &ea_gen_preference, 0, p->p.main_channel->preference);
+
p->data[i].a = rta_lookup(&a0);
}
else
diff --git a/proto/rip/rip.c b/proto/rip/rip.c
index 52a3bd2c..244bcd0a 100644
--- a/proto/rip/rip.c
+++ b/proto/rip/rip.c
@@ -152,7 +152,6 @@ rip_announce_rte(struct rip_proto *p, struct rip_entry *en)
{
/* Update */
rta a0 = {
- .pref = p->p.main_channel->preference,
.source = RTS_RIP,
.scope = SCOPE_UNIVERSE,
.dest = RTD_UNICAST,
@@ -197,11 +196,12 @@ rip_announce_rte(struct rip_proto *p, struct rip_entry *en)
struct {
ea_list l;
- eattr a[3];
+ eattr a[4];
struct rip_iface_adata riad;
} ea_block = {
- .l.count = 3,
+ .l.count = ARRAY_SIZE(ea_block.a),
.a = {
+ EA_LITERAL_EMBEDDED(&ea_gen_preference, 0, p->p.main_channel->preference),
EA_LITERAL_EMBEDDED(&ea_rip_metric, 0, rt_metric),
EA_LITERAL_EMBEDDED(&ea_rip_tag, 0, rt_tag),
EA_LITERAL_DIRECT_ADATA(&ea_rip_from, 0, &ea_block.riad.ad),
@@ -1210,7 +1210,7 @@ rip_get_route_info(rte *rte, byte *buf)
u32 rt_metric = ea_get_int(rte->attrs->eattrs, &ea_rip_metric, p->infinity);
u32 rt_tag = ea_get_int(rte->attrs->eattrs, &ea_rip_tag, 0);
- buf += bsprintf(buf, " (%d/%d)", rte->attrs->pref, rt_metric);
+ buf += bsprintf(buf, " (%d/%d)", rt_get_preference(rte), rt_metric);
if (rt_tag)
bsprintf(buf, " [%04x]", rt_tag);
diff --git a/proto/rpki/rpki.c b/proto/rpki/rpki.c
index d4e95a83..710764e2 100644
--- a/proto/rpki/rpki.c
+++ b/proto/rpki/rpki.c
@@ -121,12 +121,13 @@ rpki_table_add_roa(struct rpki_cache *cache, struct channel *channel, const net_
struct rpki_proto *p = cache->p;
rta a0 = {
- .pref = channel->preference,
.source = RTS_RPKI,
.scope = SCOPE_UNIVERSE,
.dest = RTD_NONE,
};
+ ea_set_attr_u32(&a0.eattrs, &ea_gen_preference, 0, channel->preference);
+
rta *a = rta_lookup(&a0);
rte *e = rte_get_temp(a, p->p.main_source);
diff --git a/proto/static/static.c b/proto/static/static.c
index 090ec875..d4b1c5f3 100644
--- a/proto/static/static.c
+++ b/proto/static/static.c
@@ -58,7 +58,7 @@ static_announce_rte(struct static_proto *p, struct static_route *r)
a->source = RTS_STATIC;
a->scope = SCOPE_UNIVERSE;
a->dest = r->dest;
- a->pref = p->p.main_channel->preference;
+ ea_set_attr_u32(&a->eattrs, &ea_gen_preference, 0, p->p.main_channel->preference);
if (r->dest == RTD_UNICAST)
{
@@ -712,10 +712,11 @@ static void
static_get_route_info(rte *rte, byte *buf)
{
eattr *a = ea_find(rte->attrs->eattrs, &ea_gen_igp_metric);
+ u32 pref = rt_get_preference(rte);
if (a)
- buf += bsprintf(buf, " (%d/%u)", rte->attrs->pref, a->u.data);
+ buf += bsprintf(buf, " (%d/%u)", pref, a->u.data);
else
- buf += bsprintf(buf, " (%d)", rte->attrs->pref);
+ buf += bsprintf(buf, " (%d)", pref);
}
static void