0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2025-01-03 15:41:54 +00:00

Merge commit 'cf07d8ad79273a3bbf0617c17e438602e4b64ece' into haugesund

This commit is contained in:
Maria Matejka 2022-05-30 16:52:38 +02:00
commit 8b4b7c6eae
4 changed files with 40 additions and 102 deletions

View File

@ -696,21 +696,13 @@
DYNAMIC_ATTR; DYNAMIC_ATTR;
ARG_TYPE(1, da.type); ARG_TYPE(1, da.type);
{ {
struct ea_list *l = tmp_alloc(sizeof(struct ea_list) + sizeof(eattr)); struct eattr *a;
l->next = NULL;
l->flags = EALF_SORTED;
l->count = 1;
l->attrs[0].id = da.ea_code;
l->attrs[0].flags = 0;
l->attrs[0].type = da.type;
l->attrs[0].originated = 1;
l->attrs[0].fresh = 1;
l->attrs[0].undef = 0;
if (da.type >= EAF_TYPE__MAX) if (da.type >= EAF_TYPE__MAX)
bug("Unsupported attribute type"); bug("Unsupported attribute type");
f_rta_cow(fs);
switch (da.type) { switch (da.type) {
case T_OPAQUE: case T_OPAQUE:
case T_IFACE: case T_IFACE:
@ -718,18 +710,18 @@
break; break;
case T_IP: case T_IP:
l->attrs[0].u.ptr = tmp_store_adata(&v1.val.ip, sizeof(ip_addr)); a = ea_set_attr(fs->eattrs,
EA_LITERAL_STORE_ADATA(da.ea_code, da.type, 0, &v1.val.ip, sizeof(ip_addr)));
break; break;
default: default:
l->attrs[0].u = v1.val.bval; a = ea_set_attr(fs->eattrs,
EA_LITERAL_GENERIC(da.ea_code, da.type, 0, .u = v1.val.bval));
break; break;
} }
f_rta_cow(fs); a->originated = 1;
l->next = *fs->eattrs; a->fresh = 1;
*fs->eattrs = l;
} }
} }

View File

@ -219,10 +219,7 @@ ea_list *ea_normalize(const ea_list *e);
uint ea_list_size(ea_list *); uint ea_list_size(ea_list *);
void ea_list_copy(ea_list *dest, ea_list *src, uint size); void ea_list_copy(ea_list *dest, ea_list *src, uint size);
struct ea_one_attr_list { #define EA_LOCAL_LIST(N) struct { ea_list l; eattr a[N]; }
ea_list l;
eattr a;
};
#define EA_LITERAL_EMBEDDED(_id, _type, _flags, _val) ({ \ #define EA_LITERAL_EMBEDDED(_id, _type, _flags, _val) ({ \
ASSERT_DIE(_type & EAF_EMBEDDED); \ ASSERT_DIE(_type & EAF_EMBEDDED); \
@ -245,16 +242,16 @@ struct ea_one_attr_list {
static inline eattr * static inline eattr *
ea_set_attr(ea_list **to, eattr a) ea_set_attr(ea_list **to, eattr a)
{ {
struct ea_one_attr_list *ea = tmp_alloc(sizeof(*ea)); EA_LOCAL_LIST(1) *ea = tmp_alloc(sizeof(*ea));
*ea = (struct ea_one_attr_list) { *ea = (typeof(*ea)) {
.l.flags = EALF_SORTED, .l.flags = EALF_SORTED,
.l.count = 1, .l.count = 1,
.l.next = *to, .l.next = *to,
.a = a, .a[0] = a,
}; };
*to = &ea->l; *to = &ea->l;
return &ea->a; return &ea->a[0];
} }
static inline void static inline void

View File

@ -580,15 +580,8 @@ krt_read_route(struct ks_msg *msg, struct krt_proto *p, int scan)
done:; done:;
rte e0 = { .attrs = &a, .net = net, }; rte e0 = { .attrs = &a, .net = net, };
ea_list *ea = alloca(sizeof(ea_list) + 1 * sizeof(eattr)); ea_set_attr(e0.attrs->eattrs,
*ea = (ea_list) { .count = 1, .next = e0.attrs->eattrs }; EA_LITERAL_EMBEDDED(EA_KRT_SOURCE, T_INT, 0, src2));
e0.attrs->eattrs = ea;
ea->attrs[0] = (eattr) {
.id = EA_KRT_SOURCE,
.type = T_INT,
.u.data = src2,
};
if (scan) if (scan)
krt_got_route(p, &e0, src); krt_got_route(p, &e0, src);

View File

@ -1582,20 +1582,21 @@ nl_announce_route(struct nl_parse_state *s)
.net = s->net, .net = s->net,
}; };
ea_list *ea = alloca(sizeof(ea_list) + 2 * sizeof(eattr)); EA_LOCAL_LIST(2) ea0 = {
*ea = (ea_list) { .count = 2, .next = e0.attrs->eattrs }; .l = { .count = 2, .next = e0.attrs->eattrs },
e0.attrs->eattrs = ea; .a[0] = (eattr) {
.id = EA_KRT_SOURCE,
.type = T_INT,
.u.data = s->krt_proto,
},
.a[1] = (eattr) {
.id = EA_KRT_METRIC,
.type = T_INT,
.u.data = s->krt_metric,
},
};
ea->attrs[0] = (eattr) { e0.attrs->eattrs = &ea0.l;
.id = EA_KRT_SOURCE,
.type = T_INT,
.u.data = s->krt_proto,
};
ea->attrs[1] = (eattr) {
.id = EA_KRT_METRIC,
.type = T_INT,
.u.data = s->krt_metric,
};
if (s->scan) if (s->scan)
krt_got_route(s->proto, &e0, s->krt_src); krt_got_route(s->proto, &e0, s->krt_src);
@ -1863,81 +1864,36 @@ nl_parse_route(struct nl_parse_state *s, struct nlmsghdr *h)
#endif #endif
if (i->rtm_scope != def_scope) if (i->rtm_scope != def_scope)
{ ea_set_attr(&ra->eattrs,
ea_list *ea = lp_alloc(s->pool, sizeof(ea_list) + sizeof(eattr)); EA_LITERAL_EMBEDDED(EA_KRT_SCOPE, T_INT, 0, i->rtm_scope));
ea->next = ra->eattrs;
ra->eattrs = ea;
ea->flags = EALF_SORTED;
ea->count = 1;
ea->attrs[0].id = EA_KRT_SCOPE;
ea->attrs[0].flags = 0;
ea->attrs[0].type = T_INT;
ea->attrs[0].u.data = i->rtm_scope;
}
if (a[RTA_PREFSRC]) if (a[RTA_PREFSRC])
{ {
ip_addr ps = rta_get_ipa(a[RTA_PREFSRC]); ip_addr ps = rta_get_ipa(a[RTA_PREFSRC]);
ea_list *ea = lp_alloc(s->pool, sizeof(ea_list) + sizeof(eattr)); ea_set_attr(&ra->eattrs,
ea->next = ra->eattrs; EA_LITERAL_STORE_ADATA(EA_KRT_PREFSRC, T_IP, 0, &ps, sizeof(ps)));
ra->eattrs = ea;
ea->flags = EALF_SORTED;
ea->count = 1;
ea->attrs[0].id = EA_KRT_PREFSRC;
ea->attrs[0].flags = 0;
ea->attrs[0].type = T_IP;
struct adata *ad = lp_alloc(s->pool, sizeof(struct adata) + sizeof(ps));
ad->length = sizeof(ps);
memcpy(ad->data, &ps, sizeof(ps));
ea->attrs[0].u.ptr = ad;
} }
/* Can be set per-route or per-nexthop */ /* Can be set per-route or per-nexthop */
if (s->rta_flow) if (s->rta_flow)
{ ea_set_attr(&ra->eattrs,
ea_list *ea = lp_alloc(s->pool, sizeof(ea_list) + sizeof(eattr)); EA_LITERAL_EMBEDDED(EA_KRT_REALM, T_INT, 0, s->rta_flow));
ea->next = ra->eattrs;
ra->eattrs = ea;
ea->flags = EALF_SORTED;
ea->count = 1;
ea->attrs[0].id = EA_KRT_REALM;
ea->attrs[0].flags = 0;
ea->attrs[0].type = T_INT;
ea->attrs[0].u.data = s->rta_flow;
}
if (a[RTA_METRICS]) if (a[RTA_METRICS])
{ {
u32 metrics[KRT_METRICS_MAX]; u32 metrics[KRT_METRICS_MAX];
ea_list *ea = lp_alloc(s->pool, sizeof(ea_list) + KRT_METRICS_MAX * sizeof(eattr));
int t, n = 0;
if (nl_parse_metrics(a[RTA_METRICS], metrics, ARRAY_SIZE(metrics)) < 0) if (nl_parse_metrics(a[RTA_METRICS], metrics, ARRAY_SIZE(metrics)) < 0)
{ {
log(L_ERR "KRT: Received route %N with strange RTA_METRICS attribute", net); log(L_ERR "KRT: Received route %N with strange RTA_METRICS attribute", net);
return; return;
} }
for (t = 1; t < KRT_METRICS_MAX; t++) for (int t = 1; t < KRT_METRICS_MAX; t++)
if (metrics[0] & (1 << t)) if (metrics[0] & (1 << t))
{ ea_set_attr(&ra->eattrs,
ea->attrs[n].id = EA_CODE(PROTOCOL_KERNEL, KRT_METRICS_OFFSET + t); EA_LITERAL_EMBEDDED(EA_CODE(PROTOCOL_KERNEL, KRT_METRICS_OFFSET + t),
ea->attrs[n].flags = 0; T_INT, 0, metrics[t]));
ea->attrs[n].type = T_INT;
ea->attrs[n].u.data = metrics[t];
n++;
}
if (n > 0)
{
ea->next = ra->eattrs;
ea->flags = EALF_SORTED;
ea->count = n;
ra->eattrs = ea;
}
} }
/* /*