0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-11-09 12:48:43 +00:00

Propagated const through route feed routines

This commit is contained in:
Maria Matejka 2023-03-30 11:37:16 +02:00
parent 3a53a12af4
commit 98f69aa419
11 changed files with 57 additions and 57 deletions

View File

@ -41,10 +41,10 @@ typedef struct rte {
#define REF_PENDING 32 /* Route has not propagated completely yet */
/* Route is valid for propagation (may depend on other flags in the future), accepts NULL */
static inline int rte_is_valid(rte *r) { return r && !(r->flags & REF_FILTERED); }
static inline int rte_is_valid(const rte *r) { return r && !(r->flags & REF_FILTERED); }
/* Route just has REF_FILTERED flag */
static inline int rte_is_filtered(rte *r) { return !!(r->flags & REF_FILTERED); }
static inline int rte_is_filtered(const rte *r) { return !!(r->flags & REF_FILTERED); }
/* Strip the route of the table-specific values */
static inline rte rte_init_from(const rte *r)
@ -65,9 +65,9 @@ struct rte_src {
};
struct rte_owner_class {
void (*get_route_info)(struct rte *, byte *buf); /* Get route information (for `show route' command) */
int (*rte_better)(struct rte *, struct rte *);
int (*rte_mergable)(struct rte *, struct rte *);
void (*get_route_info)(const rte *, byte *buf); /* Get route information (for `show route' command) */
int (*rte_better)(const rte *, const rte *);
int (*rte_mergable)(const rte *, const rte *);
u32 (*rte_igp_metric)(const rte *);
};
@ -430,7 +430,7 @@ ea_copy_attr(ea_list **to, ea_list *from, const struct ea_class *def)
/* Preference: first-order comparison */
extern struct ea_class ea_gen_preference;
static inline u32 rt_get_preference(rte *rt)
static inline u32 rt_get_preference(const rte *rt)
{ return ea_get_int(rt->attrs, &ea_gen_preference, 0); }
/* IGP metric: second-order comparison */

View File

@ -40,7 +40,7 @@ rt_show_rte(struct cli *c, byte *ia, rte *e, struct rt_show_data *d, int primary
byte tm[TM_DATETIME_BUFFER_SIZE], info[256];
ea_list *a = e->attrs;
int sync_error = d->tab->kernel ? krt_get_sync_error(d->tab->kernel, e) : 0;
void (*get_route_info)(struct rte *, byte *buf);
void (*get_route_info)(const rte *, byte *buf);
eattr *nhea = net_type_match(e->net, NB_DEST) ?
ea_find(a, &ea_gen_nexthop) : NULL;
struct nexthop_adata *nhad = nhea ? (struct nexthop_adata *) nhea->u.ptr : NULL;
@ -93,7 +93,7 @@ rt_show_rte(struct cli *c, byte *ia, rte *e, struct rt_show_data *d, int primary
}
static void
rt_show_net(struct rt_show_data *d, const net_addr *n, rte **feed, uint count)
rt_show_net(struct rt_show_data *d, const net_addr *n, const rte **feed, uint count)
{
struct cli *c = d->cli;
byte ia[NET_MAX_TEXT_LENGTH+1];
@ -211,7 +211,7 @@ rt_show_net(struct rt_show_data *d, const net_addr *n, rte **feed, uint count)
static void
rt_show_net_export_bulk(struct rt_export_request *req, const net_addr *n,
struct rt_pending_export *rpe UNUSED, rte **feed, uint count)
struct rt_pending_export *rpe UNUSED, const rte **feed, uint count)
{
struct rt_show_data *d = SKIP_BACK(struct rt_show_data, req, req);
return rt_show_net(d, n, feed, count);

View File

@ -670,9 +670,9 @@ rte_free(struct rte_storage *e)
}
static int /* Actually better or at least as good as */
rte_better(rte *new, rte *old)
rte_better(const rte *new, const rte *old)
{
int (*better)(rte *, rte *);
int (*better)(const rte *, const rte *);
if (!rte_is_valid(old))
return 1;
@ -701,9 +701,9 @@ rte_better(rte *new, rte *old)
}
static int
rte_mergable(rte *pri, rte *sec)
rte_mergable(const rte *pri, const rte *sec)
{
int (*mergable)(rte *, rte *);
int (*mergable)(const rte *, const rte *);
if (!rte_is_valid(pri) || !rte_is_valid(sec))
return 0;
@ -771,7 +771,7 @@ rte_feed_count(net *n)
}
static void
rte_feed_obtain(net *n, struct rte **feed, uint count)
rte_feed_obtain(net *n, const rte **feed, uint count)
{
uint i = 0;
for (struct rte_storage *e = n->routes; e; e = e->next)
@ -921,7 +921,7 @@ channel_rpe_mark_seen(struct rt_export_request *req, struct rt_pending_export *r
void
rt_notify_accepted(struct rt_export_request *req, const net_addr *n, struct rt_pending_export *first,
struct rte **feed, uint count)
const rte **feed, uint count)
{
struct channel *c = SKIP_BACK(struct channel, out_req, req);
@ -985,13 +985,13 @@ done:
}
rte *
rt_export_merged(struct channel *c, struct rte **feed, uint count, linpool *pool, int silent)
rt_export_merged(struct channel *c, const rte **feed, uint count, linpool *pool, int silent)
{
_Thread_local static rte rloc;
// struct proto *p = c->proto;
struct nexthop_adata *nhs = NULL;
rte *best0 = feed[0];
const rte *best0 = feed[0];
rte *best = NULL;
if (!rte_is_valid(best0))
@ -1048,7 +1048,7 @@ rt_export_merged(struct channel *c, struct rte **feed, uint count, linpool *pool
void
rt_notify_merged(struct rt_export_request *req, const net_addr *n, struct rt_pending_export *first,
struct rte **feed, uint count)
const rte **feed, uint count)
{
struct channel *c = SKIP_BACK(struct channel, out_req, req);
@ -1063,7 +1063,7 @@ rt_notify_merged(struct rt_export_request *req, const net_addr *n, struct rt_pen
return;
#endif
rte *old_best = NULL;
const rte *old_best = NULL;
/* Find old best route */
for (uint i = 0; i < count; i++)
if (bmap_test(&c->export_map, feed[i]->id))
@ -1140,7 +1140,7 @@ rt_notify_any(struct rt_export_request *req, const net_addr *net, struct rt_pend
}
void
rt_feed_any(struct rt_export_request *req, const net_addr *net, struct rt_pending_export *rpe UNUSED, rte **feed, uint count)
rt_feed_any(struct rt_export_request *req, const net_addr *net, struct rt_pending_export *rpe UNUSED, const rte **feed, uint count)
{
struct channel *c = SKIP_BACK(struct channel, out_req, req);
@ -1223,7 +1223,7 @@ rte_export(struct rt_table_export_hook *th, struct rt_pending_export *rpe)
net *net = SKIP_BACK(struct network, n.addr, (net_addr (*)[0]) n);
RT_LOCK(tab);
uint count = rte_feed_count(net);
rte **feed = NULL;
const rte **feed = NULL;
if (count)
{
feed = alloca(count * sizeof(rte *));
@ -4204,7 +4204,7 @@ typedef struct {
union {
struct rt_pending_export *rpe;
struct {
rte **feed;
const rte **feed;
uint *start;
};
};
@ -4257,7 +4257,7 @@ rt_process_feed(struct rt_table_export_hook *c, rt_feed_block *b)
b->start[b->pos] = b->cnt;
for (uint p = 0; p < b->pos; p++)
{
rte **feed = &b->feed[b->start[p]];
const rte **feed = &b->feed[b->start[p]];
c->h.req->export_bulk(c->h.req, feed[0]->net, NULL, feed, b->start[p+1] - b->start[p]);
}
}
@ -4403,7 +4403,7 @@ rt_feed_for(void *data)
* Import table
*/
void channel_reload_export_bulk(struct rt_export_request *req, const net_addr *net, struct rt_pending_export *rpe UNUSED, rte **feed, uint count)
void channel_reload_export_bulk(struct rt_export_request *req, const net_addr *net, struct rt_pending_export *rpe UNUSED, const rte **feed, uint count)
{
struct channel *c = SKIP_BACK(struct channel, reload_req, req);

View File

@ -303,7 +303,7 @@ struct rt_export_request {
* and for RA_ANY, both are set to accomodate for feeding all routes but receiving single changes
*/
void (*export_one)(struct rt_export_request *req, const net_addr *net, struct rt_pending_export *rpe);
void (*export_bulk)(struct rt_export_request *req, const net_addr *net, struct rt_pending_export *rpe, rte **feed, uint count);
void (*export_bulk)(struct rt_export_request *req, const net_addr *net, struct rt_pending_export *rpe, const rte **feed, uint count);
void (*dump_req)(struct rt_export_request *req);
void (*log_state_change)(struct rt_export_request *req, u8);
@ -444,13 +444,13 @@ void rt_exporter_init(struct rt_exporter *re);
int channel_preimport(struct rt_import_request *req, rte *new, rte *old);
void channel_reload_export_bulk(struct rt_export_request *req, const net_addr *net, struct rt_pending_export *rpe, rte **feed, uint count);
void channel_reload_export_bulk(struct rt_export_request *req, const net_addr *net, struct rt_pending_export *rpe, const rte **feed, uint count);
void rt_notify_optimal(struct rt_export_request *req, const net_addr *net, struct rt_pending_export *rpe);
void rt_notify_any(struct rt_export_request *req, const net_addr *net, struct rt_pending_export *rpe);
void rt_feed_any(struct rt_export_request *req, const net_addr *net, struct rt_pending_export *rpe, rte **feed, uint count);
void rt_notify_accepted(struct rt_export_request *req, const net_addr *net, struct rt_pending_export *rpe, rte **feed, uint count);
void rt_notify_merged(struct rt_export_request *req, const net_addr *net, struct rt_pending_export *rpe, rte **feed, uint count);
void rt_feed_any(struct rt_export_request *req, const net_addr *net, struct rt_pending_export *rpe, const rte **feed, uint count);
void rt_notify_accepted(struct rt_export_request *req, const net_addr *net, struct rt_pending_export *rpe, const rte **feed, uint count);
void rt_notify_merged(struct rt_export_request *req, const net_addr *net, struct rt_pending_export *rpe, const rte **feed, uint count);
@ -576,7 +576,7 @@ static inline net *net_find_valid(struct rtable_private *tab, const net_addr *ad
static inline net *net_get(struct rtable_private *tab, const net_addr *addr) { return (net *) fib_get(&tab->fib, addr); }
net *net_route(struct rtable_private *tab, const net_addr *n);
int rt_examine(rtable *t, net_addr *a, struct channel *c, const struct filter *filter);
rte *rt_export_merged(struct channel *c, rte ** feed, uint count, linpool *pool, int silent);
rte *rt_export_merged(struct channel *c, const rte ** feed, uint count, linpool *pool, int silent);
void rt_refresh_begin(struct rt_import_request *);
void rt_refresh_end(struct rt_import_request *);
void rt_modify_stale(rtable *t, struct rt_import_request *);

View File

@ -2068,7 +2068,7 @@ babel_dump(struct proto *P)
}
static void
babel_get_route_info(rte *rte, byte *buf)
babel_get_route_info(const rte *rte, byte *buf)
{
u64 rid = 0;
eattr *e = ea_find(rte->attrs, &ea_babel_router_id);
@ -2388,7 +2388,7 @@ babel_rt_notify(struct proto *P, struct channel *c UNUSED, const net_addr *net,
}
static int
babel_rte_better(struct rte *new, struct rte *old)
babel_rte_better(const rte *new, const rte *old)
{
uint new_metric = ea_get_int(new->attrs, &ea_babel_metric, BABEL_INFINITY);
uint old_metric = ea_get_int(old->attrs, &ea_babel_metric, BABEL_INFINITY);

View File

@ -1958,7 +1958,7 @@ bgp_out_table_feed(void *data)
if (hook->h.req->export_bulk)
{
rte *feed = &es.rte;
const rte *feed = &es.rte;
hook->h.req->export_bulk(hook->h.req, n->net, &rpe, &feed, 1);
}
else if (hook->h.req->export_one)
@ -2273,7 +2273,7 @@ bgp_rt_notify(struct proto *P, struct channel *C, const net_addr *n, rte *new, c
static inline u32
bgp_get_neighbor(rte *r)
bgp_get_neighbor(const rte *r)
{
eattr *e = ea_find(r->attrs, BGP_EA_ID(BA_AS_PATH));
u32 as;
@ -2287,14 +2287,14 @@ bgp_get_neighbor(rte *r)
}
static inline int
rte_stale(rte *r)
rte_stale(const rte *r)
{
eattr *a = ea_find(r->attrs, BGP_EA_ID(BA_COMMUNITY));
return a && int_set_contains(a->u.ptr, BGP_COMM_LLGR_STALE);
}
int
bgp_rte_better(rte *new, rte *old)
bgp_rte_better(const rte *new, const rte *old)
{
struct bgp_proto *new_bgp = bgp_rte_proto(new);
struct bgp_proto *old_bgp = bgp_rte_proto(old);
@ -2439,7 +2439,7 @@ bgp_rte_better(rte *new, rte *old)
int
bgp_rte_mergable(rte *pri, rte *sec)
bgp_rte_mergable(const rte *pri, const rte *sec)
{
struct bgp_proto *pri_bgp = bgp_rte_proto(pri);
struct bgp_proto *sec_bgp = bgp_rte_proto(sec);
@ -2657,7 +2657,7 @@ bgp_rte_recalculate(struct rtable_private *table, net *net, rte *new, rte *old,
}
void
bgp_rte_modify_stale(struct rt_export_request *req, const net_addr *n, struct rt_pending_export *rpe UNUSED, rte **feed, uint count)
bgp_rte_modify_stale(struct rt_export_request *req, const net_addr *n, struct rt_pending_export *rpe UNUSED, const rte **feed, uint count)
{
struct bgp_channel *c = SKIP_BACK(struct bgp_channel, stale_feed, req);
struct rt_import_hook *irh = c->c.in_req.hook;
@ -2665,7 +2665,7 @@ bgp_rte_modify_stale(struct rt_export_request *req, const net_addr *n, struct rt
/* Find our routes among others */
for (uint i=0; i<count; i++)
{
rte *r = feed[i];
const rte *r = feed[i];
if (
!rte_is_valid(r) || /* Not a valid route */
@ -2755,7 +2755,7 @@ bgp_process_as4_attrs(ea_list **attrs, struct linpool *pool)
}
void
bgp_get_route_info(rte *e, byte *buf)
bgp_get_route_info(const rte *e, byte *buf)
{
eattr *p = ea_find(e->attrs, BGP_EA_ID(BA_AS_PATH));
eattr *o = ea_find(e->attrs, BGP_EA_ID(BA_ORIGIN));

View File

@ -615,17 +615,17 @@ int bgp_done_bucket(struct bgp_channel *c, struct bgp_bucket *b);
void bgp_done_prefix(struct bgp_channel *c, struct bgp_prefix *px, struct bgp_bucket *buck);
int bgp_rte_better(struct rte *, struct rte *);
int bgp_rte_mergable(rte *pri, rte *sec);
int bgp_rte_better(const rte *, const rte *);
int bgp_rte_mergable(const rte *pri, const rte *sec);
int bgp_rte_recalculate(struct rtable_private *table, net *net, rte *new, rte *old, rte *old_best);
void bgp_rte_modify_stale(struct rt_export_request *req, const net_addr *n, struct rt_pending_export *rpe UNUSED, rte **feed, uint count);
void bgp_rte_modify_stale(struct rt_export_request *req, const net_addr *n, struct rt_pending_export *rpe UNUSED, const rte **feed, uint count);
u32 bgp_rte_igp_metric(const rte *);
void bgp_rt_notify(struct proto *P, struct channel *C, const net_addr *n, rte *new, const rte *old);
int bgp_preexport(struct channel *, struct rte *);
void bgp_get_route_info(struct rte *, byte *);
void bgp_get_route_info(const rte *, byte *);
int bgp_total_aigp_metric_(const rte *e, u64 *metric, const struct adata **ad);
static inline struct bgp_proto *bgp_rte_proto(struct rte *rte)
static inline struct bgp_proto *bgp_rte_proto(const rte *rte)
{
return (rte->src->owner->class == &bgp_rte_owner_class) ?
SKIP_BACK(struct bgp_proto, p.sources, rte->src->owner) : NULL;

View File

@ -110,7 +110,7 @@
static int ospf_preexport(struct channel *C, rte *new);
static void ospf_reload_routes(struct channel *C);
static int ospf_rte_better(struct rte *new, struct rte *old);
static int ospf_rte_better(const rte *new, const rte *old);
static u32 ospf_rte_igp_metric(const rte *rt);
static void ospf_disp(timer *timer);
@ -385,7 +385,7 @@ ospf_init(struct proto_config *CF)
/* If new is better return 1 */
static int
ospf_rte_better(struct rte *new, struct rte *old)
ospf_rte_better(const rte *new, const rte *old)
{
u32 new_metric1 = ea_get_int(new->attrs, &ea_ospf_metric1, LSINFINITY);
@ -570,7 +570,7 @@ ospf_get_status(struct proto *P, byte * buf)
}
static void
ospf_get_route_info(rte * rte, byte * buf)
ospf_get_route_info(const rte * rte, byte * buf)
{
char *type = "<bug>";

View File

@ -1119,7 +1119,7 @@ rip_reload_routes(struct channel *C)
static struct rte_owner_class rip_rte_owner_class;
static inline struct rip_proto *
rip_rte_proto(struct rte *rte)
rip_rte_proto(const rte *rte)
{
return (rte->src->owner->class == &rip_rte_owner_class) ?
SKIP_BACK(struct rip_proto, p.sources, rte->src->owner) : NULL;
@ -1132,7 +1132,7 @@ rip_rte_igp_metric(const rte *rt)
}
static int
rip_rte_better(struct rte *new, struct rte *old)
rip_rte_better(const rte *new, const rte *old)
{
return rip_rte_igp_metric(new) < rip_rte_igp_metric(old);
}
@ -1231,7 +1231,7 @@ rip_reconfigure(struct proto *P, struct proto_config *CF)
}
static void
rip_get_route_info(rte *rte, byte *buf)
rip_get_route_info(const rte *rte, byte *buf)
{
struct rip_proto *p = rip_rte_proto(rte);
u32 rt_metric = ea_get_int(rte->attrs, &ea_rip_metric, p->infinity);

View File

@ -406,7 +406,7 @@ static_reload_routes(struct channel *C)
}
static int
static_rte_better(rte *new, rte *old)
static_rte_better(const rte *new, const rte *old)
{
u32 n = ea_get_int(new->attrs, &ea_gen_igp_metric, IGP_METRIC_UNKNOWN);
u32 o = ea_get_int(old->attrs, &ea_gen_igp_metric, IGP_METRIC_UNKNOWN);
@ -414,7 +414,7 @@ static_rte_better(rte *new, rte *old)
}
static int
static_rte_mergable(rte *pri, rte *sec)
static_rte_mergable(const rte *pri, const rte *sec)
{
u32 a = ea_get_int(pri->attrs, &ea_gen_igp_metric, IGP_METRIC_UNKNOWN);
u32 b = ea_get_int(sec->attrs, &ea_gen_igp_metric, IGP_METRIC_UNKNOWN);
@ -709,7 +709,7 @@ static_copy_config(struct proto_config *dest, struct proto_config *src)
}
static void
static_get_route_info(rte *rte, byte *buf)
static_get_route_info(const rte *rte, byte *buf)
{
eattr *a = ea_find(rte->attrs, &ea_gen_igp_metric);
u32 pref = rt_get_preference(rte);

View File

@ -355,7 +355,7 @@ rte_feed_count(net *n)
}
static void
rte_feed_obtain(net *n, rte **feed, uint count)
rte_feed_obtain(net *n, const rte **feed, uint count)
{
uint i = 0;
for (struct rte_storage *e = n->routes; e; e = e->next)
@ -386,7 +386,7 @@ krt_export_net(struct krt_proto *p, net *net)
if (!count)
return NULL;
rte **feed = alloca(count * sizeof(rte *));
const rte **feed = alloca(count * sizeof(rte *));
rte_feed_obtain(net, feed, count);
return rt_export_merged(c, feed, count, krt_filter_lp, 1);
}
@ -793,7 +793,7 @@ krt_feed_end(struct channel *C)
}
static int
krt_rte_better(rte *new, rte *old)
krt_rte_better(const rte *new, const rte *old)
{
u32 n = ea_get_int(new->attrs, &ea_krt_metric, IGP_METRIC_UNKNOWN);
u32 o = ea_get_int(old->attrs, &ea_krt_metric, IGP_METRIC_UNKNOWN);