diff options
author | Maria Matejka <mq@ucw.cz> | 2022-05-15 15:53:35 +0200 |
---|---|---|
committer | Maria Matejka <mq@ucw.cz> | 2022-05-26 14:53:09 +0200 |
commit | 4fe9881d625f10e44109a649e369a413bd98de71 (patch) | |
tree | ec9b7c5c5e59eba5684fc9df5b41c1ef20e14e05 /proto | |
parent | f15f2fcee7eeb5a100bd204a0e67018e25953420 (diff) |
Moved hostentry to eattr
Diffstat (limited to 'proto')
-rw-r--r-- | proto/bgp/bgp.h | 1 | ||||
-rw-r--r-- | proto/bgp/packets.c | 47 | ||||
-rw-r--r-- | proto/pipe/pipe.c | 3 | ||||
-rw-r--r-- | proto/static/static.c | 8 |
4 files changed, 23 insertions, 36 deletions
diff --git a/proto/bgp/bgp.h b/proto/bgp/bgp.h index e04e3bd0..6abb7870 100644 --- a/proto/bgp/bgp.h +++ b/proto/bgp/bgp.h @@ -456,7 +456,6 @@ struct bgp_parse_state { uint err_subcode; jmp_buf err_jmpbuf; - struct hostentry *hostentry; adata *mpls_labels; /* Cached state for bgp_rte_update() */ diff --git a/proto/bgp/packets.c b/proto/bgp/packets.c index fd0a1be4..b07320aa 100644 --- a/proto/bgp/packets.c +++ b/proto/bgp/packets.c @@ -986,27 +986,24 @@ bgp_apply_next_hop(struct bgp_parse_state *s, rta *a, ip_addr gw, ip_addr ll) WITHDRAW(BAD_NEXT_HOP " - zero address"); rtable *tab = ipa_is_ip4(gw) ? c->igp_table_ip4 : c->igp_table_ip6; - s->hostentry = rt_get_hostentry(tab, gw, ll, c->c.table); - - if (!s->mpls) - rta_apply_hostentry(a, s->hostentry); - - /* With MPLS, hostentry is applied later in bgp_apply_mpls_labels() */ + if (s->mpls) + { + u32 labels[BGP_MPLS_MAX]; + ea_set_hostentry(&a->eattrs, c->c.table, tab, gw, ll, BGP_MPLS_MAX, labels); + } + else + ea_set_hostentry(&a->eattrs, c->c.table, tab, gw, ll, 0, NULL); } } static void -bgp_apply_mpls_labels(struct bgp_parse_state *s, rta *a) +bgp_apply_mpls_labels(struct bgp_parse_state *s, rta *a, u32 lnum, u32 labels[lnum]) { - u32 *labels = (u32 *) s->mpls_labels->data; - u32 lnum = s->mpls_labels->length / sizeof(u32); - if (lnum > MPLS_MAX_LABEL_STACK) { REPORT("Too many MPLS labels ($u)", lnum); a->dest = RTD_UNREACHABLE; - a->hostentry = NULL; ea_unset_attr(&a->eattrs, 0, &ea_gen_nexthop); return; } @@ -1029,7 +1026,13 @@ bgp_apply_mpls_labels(struct bgp_parse_state *s, rta *a) nh.nhad.ad.length = sizeof nh.nhad + lnum * sizeof(u32); } else /* GW_RECURSIVE */ - rta_apply_hostentry(a, s->hostentry); + { + eattr *e = ea_find(a->eattrs, &ea_gen_hostentry); + ASSERT_DIE(e); + struct hostentry_adata *head = (void *) e->u.ptr; + memcpy(&head->labels, labels, lnum * sizeof(u32)); + head->ad.length = (void *)(&head->labels[lnum]) - (void *) head->ad.data; + } } static void @@ -1445,12 +1448,7 @@ bgp_encode_mpls_labels(struct bgp_write_state *s UNUSED, const adata *mpls, byte static void bgp_decode_mpls_labels(struct bgp_parse_state *s, byte **pos, uint *len, uint *pxlen, rta *a) { - struct { - struct adata ad; - u32 labels[BGP_MPLS_MAX]; - } labels_adata; - - u32 *labels = labels_adata.labels; + u32 labels[BGP_MPLS_MAX]; u32 label; uint lnum = 0; @@ -1473,19 +1471,8 @@ bgp_decode_mpls_labels(struct bgp_parse_state *s, byte **pos, uint *len, uint *p if (!a) return; - labels_adata.ad.length = lnum * sizeof(u32); - - /* Attach MPLS attribute unless we already have one */ - if (!s->mpls_labels) - ea_set_attr(&(a->eattrs), - EA_LITERAL_DIRECT_ADATA(&ea_mpls_labels, 0, - (s->mpls_labels = tmp_store_adata(labels, BGP_MPLS_MAX * sizeof(u32))))); - else - /* Overwrite data in the attribute */ - memcpy(s->mpls_labels, &labels_adata, sizeof labels_adata); - /* Update next hop entry in rta */ - bgp_apply_mpls_labels(s, a); + bgp_apply_mpls_labels(s, a, lnum, labels); /* Attributes were changed, invalidate cached entry */ rta_free(s->cached_rta); diff --git a/proto/pipe/pipe.c b/proto/pipe/pipe.c index 7a39beff..e458a238 100644 --- a/proto/pipe/pipe.c +++ b/proto/pipe/pipe.c @@ -75,7 +75,8 @@ pipe_rt_notify(struct proto *P, struct channel *src_ch, net *n, rte *new, rte *o memcpy(a, new->attrs, rta_size(new->attrs)); a->cached = 0; - a->hostentry = NULL; + ea_unset_attr(&a->eattrs, 0, &ea_gen_hostentry); + e = rte_get_temp(a, src); e->pflags = new->pflags; diff --git a/proto/static/static.c b/proto/static/static.c index 2e4a46a6..5102617f 100644 --- a/proto/static/static.c +++ b/proto/static/static.c @@ -100,11 +100,11 @@ static_announce_rte(struct static_proto *p, struct static_route *r) if (r->dest == RTDX_RECURSIVE) { rtable *tab = ipa_is_ip4(r->via) ? p->igp_table_ip4 : p->igp_table_ip6; - if (r->mls) - ea_set_attr(&a->eattrs, - EA_LITERAL_DIRECT_ADATA(&ea_mpls_labels, 0, r->mls)); + u32 *labels = r->mls ? (void *) r->mls->data : NULL; + u32 lnum = r->mls ? r->mls->length / sizeof(u32) : 0; - rta_set_recursive_next_hop(p->p.main_channel->table, a, tab, r->via, IPA_NONE); + ea_set_hostentry(&a->eattrs, p->p.main_channel->table, tab, + r->via, IPA_NONE, lnum, labels); } /* Already announced */ |