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

Protocols use EA_LITERAL_* to set attributes

This commit is contained in:
Maria Matejka 2022-04-10 19:31:50 +02:00
parent ef4313e166
commit c1194ab7ed
5 changed files with 47 additions and 71 deletions

View File

@ -225,9 +225,14 @@ struct ea_one_attr_list {
EA_LITERAL_GENERIC(_id, _type, _flags, .u.i = _val); \ EA_LITERAL_GENERIC(_id, _type, _flags, .u.i = _val); \
}) })
#define EA_LITERAL_ADATA(_id, _type, _flags, _buf, _len) ({ \ #define EA_LITERAL_STORE_ADATA(_id, _type, _flags, _buf, _len) ({ \
ASSERT_DIE(!(_type & EAF_EMBEDDED)); \ ASSERT_DIE(!(_type & EAF_EMBEDDED)); \
EA_LITERAL_GENERIC(_id, _type, _flags, .u.ad = tmp_store_adata(_buf, _len)); \ EA_LITERAL_GENERIC(_id, _type, _flags, .u.ad = tmp_store_adata((_buf), (_len))); \
})
#define EA_LITERAL_DIRECT_ADATA(_id, _type, _flags, _adata) ({ \
ASSERT_DIE(!(_type & EAF_EMBEDDED)); \
EA_LITERAL_GENERIC(_id, _type, _flags, .u.ad = _adata); \
}) })
#define EA_LITERAL_GENERIC(_id, _type, _flags, ...) \ #define EA_LITERAL_GENERIC(_id, _type, _flags, ...) \
@ -261,7 +266,7 @@ ea_set_attr_u32(ea_list **to, uint id, uint flags, uint type, u32 data)
static inline void static inline void
ea_set_attr_data(ea_list **to, uint id, uint flags, uint type, void *data, uint len) ea_set_attr_data(ea_list **to, uint id, uint flags, uint type, void *data, uint len)
{ ea_set_attr(to, EA_LITERAL_ADATA(id, type, flags, data, len)); } { ea_set_attr(to, EA_LITERAL_STORE_ADATA(id, type, flags, data, len)); }
#define NEXTHOP_MAX_SIZE (sizeof(struct nexthop) + sizeof(u32)*MPLS_MAX_LABEL_STACK) #define NEXTHOP_MAX_SIZE (sizeof(struct nexthop) + sizeof(u32)*MPLS_MAX_LABEL_STACK)

View File

@ -640,6 +640,18 @@ babel_announce_rte(struct babel_proto *p, struct babel_entry *e)
if (r) if (r)
{ {
struct {
ea_list l;
eattr a[3];
} eattrs = {
.l.count = 3,
.a = {
EA_LITERAL_EMBEDDED(EA_BABEL_METRIC, T_INT, 0, r->metric),
EA_LITERAL_STORE_ADATA(EA_BABEL_ROUTER_ID, T_OPAQUE, 0, &r->router_id, sizeof(r->router_id)),
EA_LITERAL_EMBEDDED(EA_BABEL_SEQNO, T_INT, 0, r->seqno),
}
};
rta a0 = { rta a0 = {
.source = RTS_BABEL, .source = RTS_BABEL,
.scope = SCOPE_UNIVERSE, .scope = SCOPE_UNIVERSE,
@ -648,29 +660,7 @@ babel_announce_rte(struct babel_proto *p, struct babel_entry *e)
.from = r->neigh->addr, .from = r->neigh->addr,
.nh.gw = r->next_hop, .nh.gw = r->next_hop,
.nh.iface = r->neigh->ifa->iface, .nh.iface = r->neigh->ifa->iface,
.eattrs = alloca(sizeof(ea_list) + 3*sizeof(eattr)), .eattrs = &eattrs.l,
};
*a0.eattrs = (ea_list) { .count = 3 };
a0.eattrs->attrs[0] = (eattr) {
.id = EA_BABEL_METRIC,
.type = T_INT,
.u.data = r->metric,
};
struct adata *ad = alloca(sizeof(struct adata) + sizeof(u64));
ad->length = sizeof(u64);
memcpy(ad->data, &(r->router_id), sizeof(u64));
a0.eattrs->attrs[1] = (eattr) {
.id = EA_BABEL_ROUTER_ID,
.type = T_OPAQUE,
.u.ptr = ad,
};
a0.eattrs->attrs[2] = (eattr) {
.id = EA_BABEL_SEQNO,
.type = T_INT,
.u.data = r->seqno,
}; };
/* /*

View File

@ -94,13 +94,12 @@ void bgp_set_attr_u32(ea_list **to, uint code, uint flags, u32 val)
void bgp_set_attr_ptr(ea_list **to, uint code, uint flags, const struct adata *ad) void bgp_set_attr_ptr(ea_list **to, uint code, uint flags, const struct adata *ad)
{ {
ASSERT(bgp_attr_known(code)); ASSERT(bgp_attr_known(code));
ASSERT_DIE(!(bgp_attr_table[code].type & EAF_EMBEDDED));
ea_set_attr(to, EA_LITERAL_GENERIC( ea_set_attr(to, EA_LITERAL_DIRECT_ADATA(
EA_CODE(PROTOCOL_BGP, code), EA_CODE(PROTOCOL_BGP, code),
bgp_attr_table[code].type, bgp_attr_table[code].type,
flags & ~BAF_EXT_LEN, flags & ~BAF_EXT_LEN,
.u.ad = ad ad
)); ));
} }
@ -109,7 +108,7 @@ bgp_set_attr_data(ea_list **to, uint code, uint flags, void *data, uint len)
{ {
ASSERT(bgp_attr_known(code)); ASSERT(bgp_attr_known(code));
ea_set_attr(to, EA_LITERAL_ADATA( ea_set_attr(to, EA_LITERAL_STORE_ADATA(
EA_CODE(PROTOCOL_BGP, code), EA_CODE(PROTOCOL_BGP, code),
bgp_attr_table[code].type, bgp_attr_table[code].type,
flags & ~BAF_EXT_LEN, flags & ~BAF_EXT_LEN,

View File

@ -2062,39 +2062,33 @@ again1:
if (reload || ort_changed(nf, &a0)) if (reload || ort_changed(nf, &a0))
{ {
a0.eattrs = alloca(sizeof(ea_list) + 4 * sizeof(eattr));
memset(a0.eattrs, 0, sizeof(ea_list));
nf->old_metric1 = nf->n.metric1; nf->old_metric1 = nf->n.metric1;
nf->old_metric2 = nf->n.metric2; nf->old_metric2 = nf->n.metric2;
nf->old_tag = nf->n.tag; nf->old_tag = nf->n.tag;
nf->old_rid = nf->n.rid; nf->old_rid = nf->n.rid;
a0.eattrs->attrs[a0.eattrs->count++] = (eattr) { struct {
.id = EA_OSPF_METRIC1, ea_list l;
.type = T_INT, eattr a[4];
.u.data = nf->n.metric1, } eattrs;
};
eattrs.l = (ea_list) {};
eattrs.a[eattrs.l.count++] =
EA_LITERAL_EMBEDDED(EA_OSPF_METRIC1, T_INT, 0, nf->n.metric1);
if (nf->n.type == RTS_OSPF_EXT2) if (nf->n.type == RTS_OSPF_EXT2)
a0.eattrs->attrs[a0.eattrs->count++] = (eattr) { eattrs.a[eattrs.l.count++] =
.id = EA_OSPF_METRIC2, EA_LITERAL_EMBEDDED(EA_OSPF_METRIC2, T_INT, 0, nf->n.metric2);
.type = T_INT,
.u.data = nf->n.metric2,
};
if ((nf->n.type == RTS_OSPF_EXT1) || (nf->n.type == RTS_OSPF_EXT2)) if ((nf->n.type == RTS_OSPF_EXT1) || (nf->n.type == RTS_OSPF_EXT2))
a0.eattrs->attrs[a0.eattrs->count++] = (eattr) { eattrs.a[eattrs.l.count++] =
.id = EA_OSPF_TAG, EA_LITERAL_EMBEDDED(EA_OSPF_TAG, T_INT, 0, nf->n.tag);
.type = T_INT,
.u.data = nf->n.tag,
};
a0.eattrs->attrs[a0.eattrs->count++] = (eattr) { eattrs.a[eattrs.l.count++] =
.id = EA_OSPF_ROUTER_ID, EA_LITERAL_EMBEDDED(EA_OSPF_ROUTER_ID, T_QUAD, 0, nf->n.rid);
.type = T_QUAD,
.u.data = nf->n.rid, a0.eattrs = &eattrs.l;
};
rta *a = rta_lookup(&a0); rta *a = rta_lookup(&a0);
rte *e = rte_get_temp(a, p->p.main_source); rte *e = rte_get_temp(a, p->p.main_source);

View File

@ -195,26 +195,14 @@ rip_announce_rte(struct rip_proto *p, struct rip_entry *en)
struct { struct {
ea_list l; ea_list l;
eattr e[3]; eattr a[3];
struct rip_iface_adata riad; struct rip_iface_adata riad;
} ea_block = { } ea_block = {
.l = { .count = 3, }, .l.count = 3,
.e = { .a = {
{ EA_LITERAL_EMBEDDED(EA_RIP_METRIC, T_INT, 0, rt_metric),
.id = EA_RIP_METRIC, EA_LITERAL_EMBEDDED(EA_RIP_TAG, T_INT, 0, rt_tag),
.type = T_INT, EA_LITERAL_DIRECT_ADATA(EA_RIP_FROM, T_IFACE, 0, &ea_block.riad.ad),
.u.data = rt_metric,
},
{
.id = EA_RIP_TAG,
.type = T_INT,
.u.data = rt_tag,
},
{
.id = EA_RIP_FROM,
.type = T_IFACE,
.u.ptr = &ea_block.riad.ad,
}
}, },
.riad = { .riad = {
.ad = { .length = sizeof(struct rip_iface_adata) - sizeof(struct adata) }, .ad = { .length = sizeof(struct rip_iface_adata) - sizeof(struct adata) },