From ef2f4422e971722f7d603412bd69fc07a5987157 Mon Sep 17 00:00:00 2001 From: Katerina Kubecova Date: Tue, 20 Aug 2024 12:18:20 +0200 Subject: [PATCH] bmp at the moment we gave up sending routes --- proto/bgp/attrs.c | 1 + proto/bgp/bgp.h | 2 ++ proto/bgp/packets.c | 19 ++++++++++++++++--- proto/bmp/bmp.c | 7 ++++--- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/proto/bgp/attrs.c b/proto/bgp/attrs.c index bf8cbf07..4cc5431b 100644 --- a/proto/bgp/attrs.c +++ b/proto/bgp/attrs.c @@ -80,6 +80,7 @@ static union bgp_attr_desc bgp_attr_table[]; static inline const union bgp_attr_desc *bgp_find_attr_desc(eattr *a) { const struct ea_class *class = ea_class_find(a->id); + //log("ea %x class %s", a, class->name); if ((class < &bgp_attr_table[0].class) || (class >= &bgp_attr_table[BGP_ATTR_MAX].class)) return NULL; diff --git a/proto/bgp/bgp.h b/proto/bgp/bgp.h index 2e2b65c0..b5251352 100644 --- a/proto/bgp/bgp.h +++ b/proto/bgp/bgp.h @@ -448,6 +448,8 @@ struct bgp_ptx_private { slab *prefix_slab; /* Slab holding prefix nodes */ slab *bucket_slab; /* Slab holding buckets to send */ + + char bmp; /* This is a fake ptx for BMP encoding */ }; typedef union bgp_ptx { diff --git a/proto/bgp/packets.c b/proto/bgp/packets.c index ceb7d7d8..82c1230e 100644 --- a/proto/bgp/packets.c +++ b/proto/bgp/packets.c @@ -2332,10 +2332,12 @@ bgp_create_ip_reach(struct bgp_write_state *s, struct bgp_bucket *buck, byte *bu return buf+4+la+lr; } + static byte * bgp_create_mp_reach(struct bgp_write_state *s, struct bgp_bucket *buck, byte *buf, byte *end) { - ASSERT_DIE(s->ptx->withdraw_bucket != buck); + log("in reach check there is no next hop %i", s->mp_next_hop); + ASSERT_DIE((s->ptx->bmp) || (s->ptx->withdraw_bucket != buck)); /* * 2 B IPv4 Withdrawn Routes Length (zero) @@ -2374,6 +2376,7 @@ bgp_create_mp_reach(struct bgp_write_state *s, struct bgp_bucket *buck, byte *bu } /* Encode the next hop */ + log("before next hop fn check there is no next hop %i", s->mp_next_hop); lh = bgp_encode_next_hop(s, s->mp_next_hop, pos+1); *pos = lh; pos += 1+lh; @@ -2420,6 +2423,7 @@ bgp_create_ip_unreach(struct bgp_write_state *s, struct bgp_bucket *buck, byte * return buf+4+len; } + static byte * bgp_create_mp_unreach(struct bgp_write_state *s, struct bgp_bucket *buck, byte *buf, byte *end) { @@ -2469,14 +2473,23 @@ bgp_create_update_bmp(ea_list *channel_ea, struct bgp_proto *bgp_p, byte *buf, s struct bgp_caps *peer = bgp_p->conn->remote_caps; const struct bgp_af_caps *rem = bgp_find_af_caps(peer, c->afi); + struct bgp_ptx_private ptx = { + .bmp = 1, + .c = c, + }; + struct bgp_write_state s = { .proto = bgp_p, + .ptx = &ptx, .pool = tmp_linpool, .mp_reach = (c->afi != BGP_AF_IPV4) || rem->ext_next_hop, .as4_session = 1, .add_path = c->add_path_rx, .mpls = c->desc->mpls, //this is problem, but we can have proto. What about find correct channel in proto? TODO + .ignore_non_bgp_attrs = 1, // TODO this is... maybe logical, but the eattr, which forced me to write this, was nexthop. }; + log("check there is no next hop %i, channel fce %i", s.mp_next_hop, c->desc->encode_next_hop); + log("desc %x, bgp_af_desc bgp_af_table %x", c->desc, bgp_af_table); if (!update) { @@ -2513,13 +2526,13 @@ bgp_bmp_encode_rte(ea_list *c, struct bgp_proto *bgp_p, byte *buf, const net_add ea_list *attrs = new ? new->attrs : NULL; uint ea_size = new ? (sizeof(ea_list) + attrs->count * sizeof(eattr)) : 0; - uint bucket_size = sizeof(struct bgp_bucket) + ea_size; uint prefix_size = sizeof(struct bgp_prefix) + n->length; struct lp_state *tmpp = lp_save(tmp_linpool); /* Temporary bucket */ - struct bgp_bucket *b = tmp_allocz(bucket_size); + struct bgp_bucket *b = tmp_allocz(sizeof(struct bgp_bucket)); + b->attrs = tmp_allocz(ea_size); b->bmp = 1; init_list(&b->prefixes); diff --git a/proto/bmp/bmp.c b/proto/bmp/bmp.c index 6d3fd8a4..ddd6fa14 100644 --- a/proto/bmp/bmp.c +++ b/proto/bmp/bmp.c @@ -1047,10 +1047,11 @@ static void bmp_rt_notify(struct proto *P, struct channel *c, const net_addr *net, struct rte *new, const struct rte *old) { - struct bmp_proto *p = (void *) P; + return; //TODO The next code is complete mess. It counts with both v2 and v3 functions, does respect only some changes in structs (and retype v3 structs with (void *) just because it was possible in v2), contains forgotten hacks how to make it compilable, uses journal eatters where they (at first or second glance) looked useful and do strange things in general. + struct bmp_proto *p = SKIP_BACK(struct bmp_proto, p, P); - struct bgp_channel *src = (void *) (new ?: old)->sender; - struct bgp_proto *bgp = (void *) src->c.proto; + struct bgp_channel *src = SKIP_BACK(struct bgp_channel, c.in_req, (new ?: old)->sender->req); + struct bgp_proto *bgp = SKIP_BACK(struct bgp_proto, p, src->c.proto); bool policy = (c->table == src->c.table); /*