mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2025-01-15 13:31:54 +00:00
more minor fices
This commit is contained in:
parent
cc9a1e2215
commit
6c8e059935
@ -698,8 +698,7 @@ static inline struct bgp_proto *bgp_rte_proto(const rte *rte)
|
|||||||
SKIP_BACK(struct bgp_proto, p.sources, rte->src->owner) : NULL;
|
SKIP_BACK(struct bgp_proto, p.sources, rte->src->owner) : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
byte * bgp_bmp_encode_rte(ea_list *c, struct bgp_proto *bgp_p, byte *buf, const net_addr *n,
|
byte * bgp_bmp_encode_rte(ea_list *c, struct bgp_proto *bgp_p, byte *buf, const struct rte *new);
|
||||||
const struct rte *new, const struct rte_src *src);
|
|
||||||
|
|
||||||
#define BGP_AIGP_METRIC 1
|
#define BGP_AIGP_METRIC 1
|
||||||
#define BGP_AIGP_MAX U64(0xffffffffffffffff)
|
#define BGP_AIGP_MAX U64(0xffffffffffffffff)
|
||||||
|
@ -2526,15 +2526,13 @@ bgp_bmp_prepare_bgp_hdr(byte *buf, const u16 msg_size, const u8 msg_type)
|
|||||||
}
|
}
|
||||||
|
|
||||||
byte *
|
byte *
|
||||||
bgp_bmp_encode_rte(ea_list *c, struct bgp_proto *bgp_p, byte *buf, const net_addr *n,
|
bgp_bmp_encode_rte(ea_list *c, struct bgp_proto *bgp_p, byte *buf, const struct rte *new)
|
||||||
const struct rte *new, const struct rte_src *src)
|
|
||||||
{
|
{
|
||||||
// struct bgp_proto *p = (void *) c->c.proto;
|
// struct bgp_proto *p = (void *) c->c.proto;
|
||||||
byte *pkt = buf + BGP_HEADER_LENGTH;
|
byte *pkt = buf + BGP_HEADER_LENGTH;
|
||||||
|
|
||||||
ea_list *attrs = new ? new->attrs : NULL;
|
uint ea_size = new->attrs ? (sizeof(ea_list) + new->attrs->count * sizeof(eattr)) : 0;
|
||||||
uint ea_size = new ? (sizeof(ea_list) + attrs->count * sizeof(eattr)) : 0;
|
uint prefix_size = sizeof(struct bgp_prefix) + new->net->length;
|
||||||
uint prefix_size = sizeof(struct bgp_prefix) + n->length;
|
|
||||||
|
|
||||||
struct lp_state *tmpp = lp_save(tmp_linpool);
|
struct lp_state *tmpp = lp_save(tmp_linpool);
|
||||||
|
|
||||||
@ -2543,17 +2541,17 @@ bgp_bmp_encode_rte(ea_list *c, struct bgp_proto *bgp_p, byte *buf, const net_add
|
|||||||
b->bmp = 1;
|
b->bmp = 1;
|
||||||
init_list(&b->prefixes);
|
init_list(&b->prefixes);
|
||||||
|
|
||||||
if (attrs)
|
if (new->attrs)
|
||||||
memcpy(b->eattrs, attrs, ea_size);
|
memcpy(b->eattrs, new->attrs, ea_size);
|
||||||
|
|
||||||
/* Temporary prefix */
|
/* Temporary prefix */
|
||||||
struct bgp_prefix *px = tmp_allocz(prefix_size);
|
struct bgp_prefix *px = tmp_allocz(prefix_size);
|
||||||
px->src = tmp_allocz(sizeof(struct rte_src));
|
px->src = tmp_allocz(sizeof(struct rte_src));
|
||||||
memcpy(px->src, src, sizeof(struct rte_src));
|
memcpy(px->src, new->src, sizeof(struct rte_src));
|
||||||
px->ni = NET_TO_INDEX(n);
|
px->ni = NET_TO_INDEX(new->net);
|
||||||
add_tail(&b->prefixes, &px->buck_node); // why was there _xx ?
|
add_tail(&b->prefixes, &px->buck_node); // why was there _xx ?
|
||||||
|
|
||||||
byte *end = bgp_create_update_bmp(c, bgp_p, pkt, b, !!new);
|
byte *end = bgp_create_update_bmp(c, bgp_p, pkt, b, !!new->attrs);
|
||||||
|
|
||||||
if (end)
|
if (end)
|
||||||
bgp_bmp_prepare_bgp_hdr(buf, end - buf, PKT_UPDATE);
|
bgp_bmp_prepare_bgp_hdr(buf, end - buf, PKT_UPDATE);
|
||||||
|
150
proto/bmp/bmp.c
150
proto/bmp/bmp.c
@ -218,7 +218,7 @@ static void bmp_connected(struct birdsock *sk);
|
|||||||
static void bmp_sock_err(sock *sk, int err);
|
static void bmp_sock_err(sock *sk, int err);
|
||||||
static void bmp_close_socket(struct bmp_proto *p);
|
static void bmp_close_socket(struct bmp_proto *p);
|
||||||
static void bmp_check_routes(void *bt_);
|
static void bmp_check_routes(void *bt_);
|
||||||
static void bmp_do_pre_policy(void *bt_);
|
static void bmp_feed_end(struct rt_export_request *req);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
bmp_send_peer_up_notif_msg(struct bmp_proto *p, ea_list *bgp,
|
bmp_send_peer_up_notif_msg(struct bmp_proto *p, ea_list *bgp,
|
||||||
@ -509,33 +509,6 @@ const struct channel_class channel_bmp = {
|
|||||||
|
|
||||||
static struct bmp_table *
|
static struct bmp_table *
|
||||||
bmp_add_table(struct bmp_proto *p, rtable *tab)
|
bmp_add_table(struct bmp_proto *p, rtable *tab)
|
||||||
{
|
|
||||||
struct bmp_table *bt = mb_allocz(p->p.pool, sizeof(struct bmp_table));
|
|
||||||
log("adding table %x", bt);
|
|
||||||
bt->table = tab;
|
|
||||||
rt_lock_table(bt->table);
|
|
||||||
|
|
||||||
HASH_INSERT(p->table_map, HASH_TABLE, bt);
|
|
||||||
|
|
||||||
struct channel_config cc = {
|
|
||||||
.name = "monitor",
|
|
||||||
//.channel = &channel_basic,
|
|
||||||
.table = tab->config,
|
|
||||||
.in_filter = FILTER_REJECT,
|
|
||||||
.net_type = tab->addr_type,
|
|
||||||
.ra_mode = RA_ANY,
|
|
||||||
//.bmp_hack = 1,
|
|
||||||
.class = &channel_bmp,
|
|
||||||
};
|
|
||||||
|
|
||||||
bt->channel = proto_add_channel(&p->p, &cc);
|
|
||||||
channel_set_state(bt->channel, CS_UP);
|
|
||||||
|
|
||||||
return bt;
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct bmp_table *
|
|
||||||
bmp_add_table_exp_req(struct bmp_proto *p, rtable *tab)
|
|
||||||
{
|
{
|
||||||
struct bmp_table *bt = mb_allocz(p->p.pool, sizeof(struct bmp_table));
|
struct bmp_table *bt = mb_allocz(p->p.pool, sizeof(struct bmp_table));
|
||||||
log("adding table %x", bt);
|
log("adding table %x", bt);
|
||||||
@ -557,13 +530,9 @@ bmp_add_table_exp_req(struct bmp_proto *p, rtable *tab)
|
|||||||
.event = &bt->event,
|
.event = &bt->event,
|
||||||
},
|
},
|
||||||
.pool = p->p.pool,
|
.pool = p->p.pool,
|
||||||
//.feeder.prefilter = {
|
|
||||||
// .mode = c->out_subprefix ? TE_ADDR_IN : TE_ADDR_NONE,
|
|
||||||
// .addr = c->out_subprefix,
|
|
||||||
//},
|
|
||||||
.trace_routes = p->p.debug,
|
.trace_routes = p->p.debug,
|
||||||
//.dump = channel_dump_export_req,
|
//.dump = channel_dump_export_req, TODO: this will crash on `dump tables` from CLI
|
||||||
//.fed = channel_export_fed,
|
.fed = bmp_feed_end,
|
||||||
};
|
};
|
||||||
rt_export_subscribe(tab, all, &bt->out_req);//}
|
rt_export_subscribe(tab, all, &bt->out_req);//}
|
||||||
return bt;
|
return bt;
|
||||||
@ -622,7 +591,7 @@ struct bmp_table *bmp_get_table(struct bmp_proto *p, rtable *tab)
|
|||||||
atomic_int i = bt->uc;
|
atomic_int i = bt->uc;
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
{
|
{
|
||||||
struct bmp_table *new = bmp_add_table_exp_req(p, tab);
|
struct bmp_table *new = bmp_add_table(p, tab);
|
||||||
bmp_lock_table(p, new);
|
bmp_lock_table(p, new);
|
||||||
return new;
|
return new;
|
||||||
}
|
}
|
||||||
@ -630,7 +599,7 @@ struct bmp_table *bmp_get_table(struct bmp_proto *p, rtable *tab)
|
|||||||
return bt;
|
return bt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
struct bmp_table *new = bmp_add_table_exp_req(p, tab);
|
struct bmp_table *new = bmp_add_table(p, tab);
|
||||||
bmp_lock_table(p, new);
|
bmp_lock_table(p, new);
|
||||||
return new;
|
return new;
|
||||||
}
|
}
|
||||||
@ -967,20 +936,20 @@ bmp_route_monitor_put_update(struct bmp_proto *p, struct bmp_stream *bs, const b
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
bmp_route_monitor_notify(struct bmp_proto *p, struct bgp_proto *bgp_p, struct bmp_stream *bs,
|
bmp_route_monitor_notify(struct bmp_proto *p, struct bgp_proto *bgp_p, struct bmp_stream *bs, const struct rte *new)
|
||||||
const net_addr *n, const struct rte *new, const struct rte_src *src)
|
|
||||||
{
|
{
|
||||||
log("notified");
|
log("notified");
|
||||||
|
bmp_route_monitor_end_of_rib(p, bs);
|
||||||
byte buf[BGP_MAX_EXT_MSG_LENGTH];
|
byte buf[BGP_MAX_EXT_MSG_LENGTH];
|
||||||
byte *end = bgp_bmp_encode_rte(bs->sender, bgp_p, buf, n, new, src);
|
byte *end = bgp_bmp_encode_rte(bs->sender, bgp_p, buf, new);
|
||||||
|
|
||||||
btime delta_t = new ? current_time() - new->lastmod : 0;
|
btime delta_t = new->attrs ? current_time() - new->lastmod : 0;
|
||||||
btime timestamp = current_real_time() - delta_t;
|
btime timestamp = current_real_time() - delta_t;
|
||||||
|
|
||||||
if (end)
|
if (end)
|
||||||
bmp_route_monitor_put_update(p, bs, buf, end - buf, timestamp);
|
bmp_route_monitor_put_update(p, bs, buf, end - buf, timestamp);
|
||||||
else
|
else
|
||||||
log(L_WARN "%s: Cannot encode update for %N", p->p.name, n);
|
log(L_WARN "%s: Cannot encode update for %N", p->p.name, new->net);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -1172,72 +1141,6 @@ bmp_preexport(struct channel *C UNUSED, rte *e)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
bmp_rt_notify(struct proto *P, struct channel *c, const net_addr *net,
|
|
||||||
struct rte *new, const struct rte *old)
|
|
||||||
{
|
|
||||||
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 = 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);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* We assume that we receive peer_up before the first route and peer_down
|
|
||||||
* synchronously with BGP session close. So if bmp_stream exists, the related
|
|
||||||
* BGP session is up and could be accessed. That may not be true in
|
|
||||||
* multithreaded setup.
|
|
||||||
*/
|
|
||||||
|
|
||||||
struct bmp_stream *bs = bmp_find_stream(p, bgp, src->afi, policy);
|
|
||||||
if (!bs)
|
|
||||||
{
|
|
||||||
log("bmp stream not found in p %i", p);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
log("bmp stream found");
|
|
||||||
bmp_route_monitor_notify(p, bgp, bs, net, new, (new ?: old)->src);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*static void
|
|
||||||
bmp_do_pre_policy(void *bt_)
|
|
||||||
{
|
|
||||||
log("do pre policy");
|
|
||||||
struct bmp_table *bt = (struct bmp_table *)bt_;
|
|
||||||
struct bmp_proto *p = bt->p;
|
|
||||||
|
|
||||||
RT_FEED_WALK(&bt->in_req, f)
|
|
||||||
{
|
|
||||||
bool seen = 0;
|
|
||||||
log("count rout %i", f->count_routes);
|
|
||||||
for (uint i = 0; i < f->count_routes; i++)
|
|
||||||
{
|
|
||||||
rte *r = &f->block[i];
|
|
||||||
|
|
||||||
if (r->flags & REF_OBSOLETE)
|
|
||||||
break;
|
|
||||||
|
|
||||||
rte new = rte_init_from(r);
|
|
||||||
|
|
||||||
// Strip the later attribute layers
|
|
||||||
new.attrs = ea_strip_to(new.attrs, BIT32_ALL(EALS_PREIMPORT));
|
|
||||||
struct proto *rte_proto = (struct proto*) SKIP_BACK(struct proto, sources, new.src->owner);
|
|
||||||
if (rte_proto->proto != &proto_bgp || !bgp_next_hop_present(new))
|
|
||||||
break;
|
|
||||||
struct bgp_proto *bgp = (struct bgp_proto *) rte_proto;
|
|
||||||
struct bgp_channel *bc = (struct bgp_channel *) SKIP_BACK(struct channel, in_req, new.sender->req);
|
|
||||||
struct bgp_channel *src = SKIP_BACK(struct bgp_channel, c.in_req, new.sender->req);
|
|
||||||
bool policy = (bc->c.table == src->c.table); //TODO?
|
|
||||||
struct bmp_stream *bs = bmp_find_stream(p, bgp, src->afi, policy);
|
|
||||||
|
|
||||||
bmp_route_monitor_notify(p, bgp, bs, new.net, &new, new.src);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
int
|
int
|
||||||
bgp_next_hop_present(const rte *n)
|
bgp_next_hop_present(const rte *n)
|
||||||
{
|
{
|
||||||
@ -1256,16 +1159,15 @@ bgp_next_hop_present(const rte *n)
|
|||||||
static void
|
static void
|
||||||
solve_for_post_and_pre(struct bmp_proto *p, const rte *new, const rte *old)
|
solve_for_post_and_pre(struct bmp_proto *p, const rte *new, const rte *old)
|
||||||
{
|
{
|
||||||
struct proto *rte_proto = (struct proto*) SKIP_BACK(struct proto, sources, new->src->owner);
|
rte loc = *(new ?: old);
|
||||||
|
|
||||||
|
struct proto *rte_proto = (struct proto*) SKIP_BACK(struct proto, sources, loc.src->owner);
|
||||||
struct bgp_proto *bgp = (struct bgp_proto *) rte_proto;
|
struct bgp_proto *bgp = (struct bgp_proto *) rte_proto;
|
||||||
struct bgp_channel *src_ch = SKIP_BACK(struct bgp_channel, c.in_req, new->sender->req);
|
struct bgp_channel *src_ch = SKIP_BACK(struct bgp_channel, c.in_req, loc.sender->req);
|
||||||
ASSERT_DIE(src_ch->c.proto == rte_proto); /* No pipes supported for now */
|
ASSERT_DIE(src_ch->c.proto == rte_proto); /* No pipes supported for now */
|
||||||
|
|
||||||
log("solve_for_post_and_pre %s", rte_proto->name);
|
log("solve_for_post_and_pre %s", rte_proto->name);
|
||||||
|
|
||||||
const net_addr *net = (new ?: old)->net;
|
|
||||||
struct rte_src *src = (new ?: old)->src;
|
|
||||||
|
|
||||||
/* Ignore non-BGP routes */
|
/* Ignore non-BGP routes */
|
||||||
if (rte_proto->proto != &proto_bgp)
|
if (rte_proto->proto != &proto_bgp)
|
||||||
return;
|
return;
|
||||||
@ -1277,6 +1179,8 @@ solve_for_post_and_pre(struct bmp_proto *p, const rte *new, const rte *old)
|
|||||||
ea_list *new_attrs = new ? ea_strip_to(new->attrs, BIT32_ALL(EALS_PREIMPORT)) : NULL;
|
ea_list *new_attrs = new ? ea_strip_to(new->attrs, BIT32_ALL(EALS_PREIMPORT)) : NULL;
|
||||||
ea_list *old_attrs = old ? ea_strip_to(old->attrs, BIT32_ALL(EALS_PREIMPORT)) : NULL;
|
ea_list *old_attrs = old ? ea_strip_to(old->attrs, BIT32_ALL(EALS_PREIMPORT)) : NULL;
|
||||||
|
|
||||||
|
loc.attrs = new_attrs;
|
||||||
|
|
||||||
if (new_attrs != old_attrs)
|
if (new_attrs != old_attrs)
|
||||||
{
|
{
|
||||||
/* The attributes are actually different, announce the change */
|
/* The attributes are actually different, announce the change */
|
||||||
@ -1290,7 +1194,7 @@ solve_for_post_and_pre(struct bmp_proto *p, const rte *new, const rte *old)
|
|||||||
if (bmp_find_peer(p, proto_state_table->attrs[bgp->p.id]) == NULL)
|
if (bmp_find_peer(p, proto_state_table->attrs[bgp->p.id]) == NULL)
|
||||||
bug("not implemented");
|
bug("not implemented");
|
||||||
|
|
||||||
bmp_route_monitor_notify(p, bgp, bs, net, new, src);
|
bmp_route_monitor_notify(p, bgp, bs, &loc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1302,6 +1206,8 @@ solve_for_post_and_pre(struct bmp_proto *p, const rte *new, const rte *old)
|
|||||||
ea_list *new_attrs = new ? ea_normalize(new->attrs, 0) : NULL;
|
ea_list *new_attrs = new ? ea_normalize(new->attrs, 0) : NULL;
|
||||||
ea_list *old_attrs = old ? ea_normalize(old->attrs, 0) : NULL;
|
ea_list *old_attrs = old ? ea_normalize(old->attrs, 0) : NULL;
|
||||||
|
|
||||||
|
loc.attrs = new_attrs;
|
||||||
|
|
||||||
/* TODO: filter only BGP-relevant attributes */
|
/* TODO: filter only BGP-relevant attributes */
|
||||||
|
|
||||||
if ((new_attrs != old_attrs) || ea_same(new_attrs, old_attrs))
|
if ((new_attrs != old_attrs) || ea_same(new_attrs, old_attrs))
|
||||||
@ -1314,7 +1220,7 @@ solve_for_post_and_pre(struct bmp_proto *p, const rte *new, const rte *old)
|
|||||||
if (bmp_find_peer(p, proto_state_table->attrs[bgp->p.id]) == NULL)
|
if (bmp_find_peer(p, proto_state_table->attrs[bgp->p.id]) == NULL)
|
||||||
bug("not implemented");
|
bug("not implemented");
|
||||||
|
|
||||||
bmp_route_monitor_notify(p, bgp, bs, net, new, src);
|
bmp_route_monitor_notify(p, bgp, bs, &loc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1355,22 +1261,18 @@ bmp_check_routes(void *bt_)
|
|||||||
log("export update");
|
log("export update");
|
||||||
|
|
||||||
solve_for_post_and_pre(p, u->update->new, u->update->old);
|
solve_for_post_and_pre(p, u->update->new, u->update->old);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log("end of notify fce");
|
log("end of notify fce");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
bmp_feed_end(struct channel *c)
|
bmp_feed_end(struct rt_export_request *req)
|
||||||
{
|
{
|
||||||
struct bmp_proto *p = (void *) c->proto;
|
SKIP_BACK_DECLARE(struct bmp_table, bt, out_req, req);
|
||||||
|
|
||||||
struct bmp_table *bt = bmp_find_table(p, c->table);
|
struct bmp_proto *p = bt->p;
|
||||||
if (!bt)
|
|
||||||
{
|
|
||||||
log("bmp table not found");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
log("bmp table found");
|
log("bmp table found");
|
||||||
/*
|
/*
|
||||||
@ -1648,10 +1550,6 @@ bmp_init(struct proto_config *CF)
|
|||||||
if (!bgp_next_hop_ea_class)
|
if (!bgp_next_hop_ea_class)
|
||||||
bgp_next_hop_ea_class = ea_class_find_by_name("bgp_next_hop");
|
bgp_next_hop_ea_class = ea_class_find_by_name("bgp_next_hop");
|
||||||
|
|
||||||
P->rt_notify = bmp_rt_notify;
|
|
||||||
P->preexport = bmp_preexport;
|
|
||||||
//P->feed_end = bmp_feed_end; I am confused. It looks like feed_end and bmp_feed_end exist only here
|
|
||||||
|
|
||||||
p->cf = cf;
|
p->cf = cf;
|
||||||
p->local_addr = cf->local_addr;
|
p->local_addr = cf->local_addr;
|
||||||
p->station_ip = cf->station_ip;
|
p->station_ip = cf->station_ip;
|
||||||
|
Loading…
Reference in New Issue
Block a user