0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-12-22 09:41:54 +00:00

Preexport callback now takes the channel instead of protocol as argument

Passing protocol to preexport was in fact a historical relic from the
old times when channels weren't a thing. Refactoring that to match
current extensibility needs.
This commit is contained in:
Maria Matejka 2022-06-27 19:04:22 +02:00
parent b867c798c3
commit beb5f78ada
11 changed files with 23 additions and 22 deletions

View File

@ -217,7 +217,7 @@ struct proto {
void (*neigh_notify)(struct neighbor *neigh); void (*neigh_notify)(struct neighbor *neigh);
void (*make_tmp_attrs)(struct rte *rt, struct linpool *pool); void (*make_tmp_attrs)(struct rte *rt, struct linpool *pool);
void (*store_tmp_attrs)(struct rte *rt, struct linpool *pool); void (*store_tmp_attrs)(struct rte *rt, struct linpool *pool);
int (*preexport)(struct proto *, struct rte **rt, struct linpool *pool); int (*preexport)(struct channel *, struct rte **rt, struct linpool *pool);
void (*reload_routes)(struct channel *); void (*reload_routes)(struct channel *);
void (*feed_begin)(struct channel *, int initial); void (*feed_begin)(struct channel *, int initial);
void (*feed_end)(struct channel *); void (*feed_end)(struct channel *);

View File

@ -357,7 +357,7 @@ rte *rte_find(net *net, struct rte_src *src);
rte *rte_get_temp(struct rta *); rte *rte_get_temp(struct rta *);
void rte_update2(struct channel *c, const net_addr *n, rte *new, struct rte_src *src); void rte_update2(struct channel *c, const net_addr *n, rte *new, struct rte_src *src);
/* rte_update() moved to protocol.h to avoid dependency conflicts */ /* rte_update() moved to protocol.h to avoid dependency conflicts */
int rt_examine(rtable *t, net_addr *a, struct proto *p, const struct filter *filter); int rt_examine(rtable *t, net_addr *a, struct channel *c, const struct filter *filter);
rte *rt_export_merged(struct channel *c, net *net, rte **rt_free, linpool *pool, int silent); rte *rt_export_merged(struct channel *c, net *net, rte **rt_free, linpool *pool, int silent);
void rt_refresh_begin(rtable *t, struct channel *c); void rt_refresh_begin(rtable *t, struct channel *c);
void rt_refresh_end(rtable *t, struct channel *c); void rt_refresh_end(rtable *t, struct channel *c);

View File

@ -154,7 +154,7 @@ rt_show_net(struct cli *c, net *n, struct rt_show_data *d)
else if (d->export_mode) else if (d->export_mode)
{ {
struct proto *ep = ec->proto; struct proto *ep = ec->proto;
int ic = ep->preexport ? ep->preexport(ep, &e, c->show_pool) : 0; int ic = ep->preexport ? ep->preexport(ec, &e, c->show_pool) : 0;
if (ec->ra_mode == RA_OPTIMAL || ec->ra_mode == RA_MERGED) if (ec->ra_mode == RA_OPTIMAL || ec->ra_mode == RA_MERGED)
pass = 1; pass = 1;

View File

@ -870,7 +870,7 @@ export_filter_(struct channel *c, rte *rt0, rte **rt_free, linpool *pool, int si
rt = rt0; rt = rt0;
*rt_free = NULL; *rt_free = NULL;
v = p->preexport ? p->preexport(p, &rt, pool) : 0; v = p->preexport ? p->preexport(c, &rt, pool) : 0;
if (v < 0) if (v < 0)
{ {
if (silent) if (silent)
@ -1883,8 +1883,9 @@ rte_modify(rte *old)
/* Check rtable for best route to given net whether it would be exported do p */ /* Check rtable for best route to given net whether it would be exported do p */
int int
rt_examine(rtable *t, net_addr *a, struct proto *p, const struct filter *filter) rt_examine(rtable *t, net_addr *a, struct channel *c, const struct filter *filter)
{ {
struct proto *p = c->proto;
net *n = net_find(t, a); net *n = net_find(t, a);
rte *rt = n ? n->routes : NULL; rte *rt = n ? n->routes : NULL;
@ -1894,7 +1895,7 @@ rt_examine(rtable *t, net_addr *a, struct proto *p, const struct filter *filter)
rte_update_lock(); rte_update_lock();
/* Rest is stripped down export_filter() */ /* Rest is stripped down export_filter() */
int v = p->preexport ? p->preexport(p, &rt, rte_update_pool) : 0; int v = p->preexport ? p->preexport(c, &rt, rte_update_pool) : 0;
if (v == RIC_PROCESS) if (v == RIC_PROCESS)
{ {
rte_make_tmp_attrs(&rt, rte_update_pool, NULL); rte_make_tmp_attrs(&rt, rte_update_pool, NULL);

View File

@ -2230,12 +2230,12 @@ babel_kick_timer(struct babel_proto *p)
static int static int
babel_preexport(struct proto *P, struct rte **new, struct linpool *pool UNUSED) babel_preexport(struct channel *C, struct rte **new, struct linpool *pool UNUSED)
{ {
struct rta *a = (*new)->attrs; struct rta *a = (*new)->attrs;
/* Reject our own unreachable routes */ /* Reject our own unreachable routes */
if ((a->dest == RTD_UNREACHABLE) && (a->src->proto == P)) if ((a->dest == RTD_UNREACHABLE) && (a->src->proto == C->proto))
return -1; return -1;
return 0; return 0;

View File

@ -1669,11 +1669,11 @@ bgp_free_prefix(struct bgp_channel *c, struct bgp_prefix *px)
*/ */
int int
bgp_preexport(struct proto *P, rte **new, struct linpool *pool UNUSED) bgp_preexport(struct channel *C, rte **new, struct linpool *pool UNUSED)
{ {
rte *e = *new; rte *e = *new;
struct proto *SRC = e->attrs->src->proto; struct proto *SRC = e->attrs->src->proto;
struct bgp_proto *p = (struct bgp_proto *) P; struct bgp_proto *p = (struct bgp_proto *) C->proto;
struct bgp_proto *src = (SRC->proto == &proto_bgp) ? (struct bgp_proto *) SRC : NULL; struct bgp_proto *src = (SRC->proto == &proto_bgp) ? (struct bgp_proto *) SRC : NULL;
/* Reject our routes */ /* Reject our routes */

View File

@ -589,7 +589,7 @@ int bgp_rte_mergable(rte *pri, rte *sec);
int bgp_rte_recalculate(rtable *table, net *net, rte *new, rte *old, rte *old_best); int bgp_rte_recalculate(rtable *table, net *net, rte *new, rte *old, rte *old_best);
struct rte *bgp_rte_modify_stale(struct rte *r, struct linpool *pool); struct rte *bgp_rte_modify_stale(struct rte *r, struct linpool *pool);
void bgp_rt_notify(struct proto *P, struct channel *C, net *n, rte *new, rte *old); void bgp_rt_notify(struct proto *P, struct channel *C, net *n, rte *new, rte *old);
int bgp_preexport(struct proto *, struct rte **, struct linpool *); int bgp_preexport(struct channel *, struct rte **, struct linpool *);
int bgp_get_attr(const struct eattr *e, byte *buf, int buflen); int bgp_get_attr(const struct eattr *e, byte *buf, int buflen);
void bgp_get_route_info(struct rte *, byte *buf); void bgp_get_route_info(struct rte *, byte *buf);
int bgp_total_aigp_metric_(rte *e, u64 *metric, const struct adata **ad); int bgp_total_aigp_metric_(rte *e, u64 *metric, const struct adata **ad);

View File

@ -107,7 +107,7 @@
#include <stdlib.h> #include <stdlib.h>
#include "ospf.h" #include "ospf.h"
static int ospf_preexport(struct proto *P, rte **new, struct linpool *pool); static int ospf_preexport(struct channel *C, rte **new, struct linpool *pool);
static void ospf_make_tmp_attrs(struct rte *rt, struct linpool *pool); static void ospf_make_tmp_attrs(struct rte *rt, struct linpool *pool);
static void ospf_store_tmp_attrs(struct rte *rt, struct linpool *pool); static void ospf_store_tmp_attrs(struct rte *rt, struct linpool *pool);
static void ospf_reload_routes(struct channel *C); static void ospf_reload_routes(struct channel *C);
@ -484,14 +484,14 @@ ospf_disp(timer * timer)
* import to the filters. * import to the filters.
*/ */
static int static int
ospf_preexport(struct proto *P, rte **new, struct linpool *pool UNUSED) ospf_preexport(struct channel *C, rte **new, struct linpool *pool UNUSED)
{ {
struct ospf_proto *p = (struct ospf_proto *) P; struct ospf_proto *p = (struct ospf_proto *) C->proto;
struct ospf_area *oa = ospf_main_area(p); struct ospf_area *oa = ospf_main_area(p);
rte *e = *new; rte *e = *new;
/* Reject our own routes */ /* Reject our own routes */
if (e->attrs->src->proto == P) if (e->attrs->src->proto == &p->p)
return -1; return -1;
/* Do not export routes to stub areas */ /* Do not export routes to stub areas */

View File

@ -101,11 +101,11 @@ pipe_rt_notify(struct proto *P, struct channel *src_ch, net *n, rte *new, rte *o
} }
static int static int
pipe_preexport(struct proto *P, rte **ee, struct linpool *p UNUSED) pipe_preexport(struct channel *C, rte **ee, struct linpool *p UNUSED)
{ {
struct proto *pp = (*ee)->sender->proto; struct proto *pp = (*ee)->sender->proto;
if (pp == P) if (pp == C->proto)
return -1; /* Avoid local loops automatically */ return -1; /* Avoid local loops automatically */
return 0; return 0;

View File

@ -391,10 +391,10 @@ radv_net_match_trigger(struct radv_config *cf, net *n)
} }
int int
radv_preexport(struct proto *P, rte **new, struct linpool *pool UNUSED) radv_preexport(struct channel *C, rte **new, struct linpool *pool UNUSED)
{ {
// struct radv_proto *p = (struct radv_proto *) P; // struct radv_proto *p = (struct radv_proto *) P;
struct radv_config *cf = (struct radv_config *) (P->cf); struct radv_config *cf = (struct radv_config *) (C->proto->cf);
if (radv_net_match_trigger(cf, (*new)->net)) if (radv_net_match_trigger(cf, (*new)->net))
return RIC_PROCESS; return RIC_PROCESS;
@ -555,7 +555,7 @@ radv_check_active(struct radv_proto *p)
return 1; return 1;
struct channel *c = p->p.main_channel; struct channel *c = p->p.main_channel;
return rt_examine(c->table, &cf->trigger, &p->p, c->out_filter); return rt_examine(c->table, &cf->trigger, c, c->out_filter);
} }
static void static void

View File

@ -903,12 +903,12 @@ krt_store_tmp_attrs(struct rte *rt, struct linpool *pool)
} }
static int static int
krt_preexport(struct proto *P, rte **new, struct linpool *pool UNUSED) krt_preexport(struct channel *C, rte **new, struct linpool *pool UNUSED)
{ {
// struct krt_proto *p = (struct krt_proto *) P; // struct krt_proto *p = (struct krt_proto *) P;
rte *e = *new; rte *e = *new;
if (e->attrs->src->proto == P) if (e->attrs->src->proto == C->proto)
return -1; return -1;
if (!krt_capable(e)) if (!krt_capable(e))