0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-11-08 12:18:42 +00:00

Moved advertising router info (FROM attribute) to eattrs

This commit is contained in:
Maria Matejka 2022-04-20 13:56:04 +02:00
parent 337c04c45e
commit 8ebac84bc8
10 changed files with 48 additions and 39 deletions

View File

@ -762,8 +762,7 @@ symbol_value: CF_SYM_KNOWN
;
static_attr:
FROM { $$ = f_new_static_attr(T_IP, SA_FROM, 0); }
| GW { $$ = f_new_static_attr(T_IP, SA_GW, 0); }
GW { $$ = f_new_static_attr(T_IP, SA_GW, 0); }
| NET { $$ = f_new_static_attr(T_NET, SA_NET, 1); }
| PROTO { $$ = f_new_static_attr(T_STRING, SA_PROTO, 1); }
| SOURCE { $$ = f_new_static_attr(T_ENUM_RTS, SA_SOURCE, 1); }

View File

@ -22,8 +22,7 @@ struct f_val {
#define fputip(a) ({ ip_addr *ax = falloc(sizeof(*ax)); *ax = (a); ax; })
enum f_sa_code {
SA_FROM = 1,
SA_GW,
SA_GW = 1,
SA_NET,
SA_PROTO,
SA_SOURCE,

View File

@ -533,7 +533,6 @@
switch (sa.sa_code)
{
case SA_FROM: RESULT(sa.type, ip, rta->from); break;
case SA_GW: RESULT(sa.type, ip, rta->nh.gw); break;
case SA_NET: RESULT(sa.type, net, (*fs->rte)->net->n.addr); break;
case SA_PROTO: RESULT(sa.type, s, (*fs->rte)->src->proto->name); break;
@ -563,10 +562,6 @@
switch (sa.sa_code)
{
case SA_FROM:
rta->from = v1.val.ip;
break;
case SA_GW:
{
ip_addr ip = v1.val.ip;

View File

@ -84,7 +84,6 @@ typedef struct rta {
u32 hash_key; /* Hash over important fields */
struct ea_list *eattrs; /* Extended Attribute chain */
struct hostentry *hostentry; /* Hostentry for recursive next-hops */
ip_addr from; /* Advertising router */
u16 cached:1; /* Are attributes cached? */
u16 source:7; /* Route source (RTS_...) */
u16 scope:4; /* Route scope (SCOPE_... -- see ip.h) */
@ -219,6 +218,13 @@ static inline eattr *ea_find_by_name(ea_list *l, const char *name)
(ea ? ea->u.data : (_def)); \
})
#define ea_get_ip(_l, _ident, _def) ({ \
struct ea_class *cls = ea_class_find((_ident)); \
ASSERT_DIE(cls->type == T_IP); \
const eattr *ea = ea_find((_l), cls->id); \
(ea ? *((const ip_addr *) ea->u.ptr->data) : (_def)); \
})
eattr *ea_walk(struct ea_walk_state *s, uint id, uint max);
void ea_dump(ea_list *);
int ea_same(ea_list *x, ea_list *y); /* Test whether two ea_lists are identical */
@ -300,6 +306,8 @@ u32 rt_get_igp_metric(rte *rt);
#define IGP_METRIC_UNKNOWN 0x80000000 /* Default igp_metric used when no other
protocol-specific metric is availabe */
/* From: Advertising router */
extern struct ea_class ea_gen_from;
/* Next hop structures */

View File

@ -70,6 +70,11 @@ struct ea_class ea_gen_preference = {
.type = T_INT,
};
struct ea_class ea_gen_from = {
.name = "from",
.type = T_IP,
};
const char * const rta_src_names[RTS_MAX] = {
[RTS_STATIC] = "static",
[RTS_INHERIT] = "inherit",
@ -1229,7 +1234,6 @@ rta_hash(rta *a)
#define MIX(f) mem_hash_mix(&h, &(a->f), sizeof(a->f));
#define BMIX(f) mem_hash_mix_num(&h, a->f);
MIX(hostentry);
MIX(from);
BMIX(source);
BMIX(scope);
BMIX(dest);
@ -1244,7 +1248,6 @@ rta_same(rta *x, rta *y)
return (x->source == y->source &&
x->scope == y->scope &&
x->dest == y->dest &&
ipa_equal(x->from, y->from) &&
x->hostentry == y->hostentry &&
nexthop_same(&(x->nh), &(y->nh)) &&
ea_same(x->eattrs, y->eattrs));
@ -1398,7 +1401,6 @@ rta_dump(rta *a)
rtd[a->dest], a->hash_key);
if (!a->cached)
debug(" !CACHED");
debug(" <-%I", a->from);
if (a->dest == RTD_UNICAST)
for (struct nexthop *nh = &(a->nh); nh; nh = nh->next)
{
@ -1475,6 +1477,7 @@ rta_init(void)
ea_register_init(&ea_gen_preference);
ea_register_init(&ea_gen_igp_metric);
ea_register_init(&ea_gen_from);
}
/*

View File

@ -48,8 +48,9 @@ rt_show_rte(struct cli *c, byte *ia, rte *e, struct rt_show_data *d, int primary
struct nexthop *nh;
tm_format_time(tm, &config->tf_route, e->lastmod);
if (ipa_nonzero(a->from) && !ipa_equal(a->from, a->nh.gw))
bsprintf(from, " from %I", a->from);
ip_addr a_from = ea_get_ip(a->eattrs, &ea_gen_from, IPA_NONE);
if (ipa_nonzero(a_from) && !ipa_equal(a_from, a->nh.gw))
bsprintf(from, " from %I", a_from);
else
from[0] = 0;

View File

@ -2596,7 +2596,10 @@ rt_flowspec_check(rtable *tab_ip, rtable *tab_flow, const net_addr *n, rta *a, i
u32 orig_b = ea_get_int(rb->attrs->eattrs, "bgp_originator_id", 0);
/* Originator is either ORIGINATOR_ID (if present), or BGP neighbor address (if not) */
if ((orig_a != orig_b) || (!orig_a && !orig_b && !ipa_equal(a->from, rb->attrs->from)))
if ((orig_a != orig_b) || (!orig_a && !orig_b && !ipa_equal(
ea_get_ip(a->eattrs, &ea_gen_from, IPA_NONE),
ea_get_ip(rb->attrs->eattrs, &ea_gen_from, IPA_NONE)
)))
return 0;

View File

@ -645,11 +645,12 @@ babel_announce_rte(struct babel_proto *p, struct babel_entry *e)
{
struct {
ea_list l;
eattr a[4];
eattr a[5];
} eattrs = {
.l.count = ARRAY_SIZE(eattrs.a),
.a = {
EA_LITERAL_EMBEDDED(&ea_gen_preference, 0, c->preference),
EA_LITERAL_STORE_ADATA(&ea_gen_from, 0, &r->neigh->addr, sizeof(r->neigh->addr)),
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),
@ -660,7 +661,6 @@ babel_announce_rte(struct babel_proto *p, struct babel_entry *e)
.source = RTS_BABEL,
.scope = SCOPE_UNIVERSE,
.dest = RTD_UNICAST,
.from = r->neigh->addr,
.nh.gw = r->next_hop,
.nh.iface = r->neigh->ifa->iface,
.eattrs = &eattrs.l,

View File

@ -2476,8 +2476,9 @@ bgp_decode_nlri(struct bgp_parse_state *s, u32 afi, byte *nlri, uint len, ea_lis
a->source = RTS_BGP;
a->scope = SCOPE_UNIVERSE;
a->from = s->proto->remote_ip;
a->eattrs = ea;
ea_set_attr_data(&a->eattrs, &ea_gen_from, 0, &s->proto->remote_ip, sizeof(ip_addr));
ea_set_attr_u32(&a->eattrs, &ea_gen_preference, 0, c->c.preference);
c->desc->decode_next_hop(s, nh, nh_len, a);

View File

@ -157,7 +157,18 @@ rip_announce_rte(struct rip_proto *p, struct rip_entry *en)
.dest = RTD_UNICAST,
};
u8 rt_metric = rt->metric;
struct {
ea_list l;
eattr a[2];
} ea_block = {
.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),
},
};
a0.eattrs = &ea_block.l;
u16 rt_tag = rt->tag;
if (p->ecmp)
@ -189,30 +200,19 @@ rip_announce_rte(struct rip_proto *p, struct rip_entry *en)
else
{
/* Unipath route */
a0.from = rt->from->nbr->addr;
a0.nh.gw = rt->next_hop;
a0.nh.iface = rt->from->ifa->iface;
ea_set_attr_data(&a0.eattrs, &ea_gen_from, 0, &rt->from->nbr->addr, sizeof(ip_addr));
}
struct {
ea_list l;
eattr a[4];
struct rip_iface_adata riad;
} ea_block = {
.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),
},
.riad = {
.ad = { .length = sizeof(struct rip_iface_adata) - sizeof(struct adata) },
.iface = a0.nh.iface,
},
};
ea_set_attr_u32(&a0.eattrs, &ea_rip_tag, 0, rt_tag);
a0.eattrs = &ea_block.l;
struct rip_iface_adata riad = {
.ad = { .length = sizeof(struct rip_iface_adata) - sizeof(struct adata) },
.iface = a0.nh.iface,
};
ea_set_attr(&a0.eattrs,
EA_LITERAL_DIRECT_ADATA(&ea_rip_from, 0, &riad.ad));
rta *a = rta_lookup(&a0);
rte *e = rte_get_temp(a, p->p.main_source);