From 938742decc6e1d6d3a0375dd012b75172e747bbc Mon Sep 17 00:00:00 2001 From: Maria Matejka Date: Mon, 30 May 2022 12:03:03 +0200 Subject: Squashing the route attribute structure into one level. For now, all route attributes are stored as eattrs in ea_list. This should make route manipulation easier and it also allows for a layered approach of route attributes where updates from filters will be stored as an overlay over the previous version. --- filter/filter.c | 41 +++++++---------------------------------- 1 file changed, 7 insertions(+), 34 deletions(-) (limited to 'filter/filter.c') diff --git a/filter/filter.c b/filter/filter.c index 9bedb938..ff6a3419 100644 --- a/filter/filter.c +++ b/filter/filter.c @@ -76,9 +76,6 @@ struct filter_state { /* The route we are processing. This may be NULL to indicate no route available. */ struct rte **rte; - /* The old rta to be freed after filters are done. */ - struct rta *old_rta; - /* Cached pointer to ea_list */ struct ea_list **eattrs; @@ -99,7 +96,7 @@ void (*bt_assert_hook)(int result, const struct f_line_item *assert); static inline void f_cache_eattrs(struct filter_state *fs) { - fs->eattrs = &((*fs->rte)->attrs->eattrs); + fs->eattrs = &((*fs->rte)->attrs); } static inline void f_rte_cow(struct filter_state *fs) @@ -110,33 +107,6 @@ static inline void f_rte_cow(struct filter_state *fs) *fs->rte = rte_cow(*fs->rte); } -/* - * rta_cow - prepare rta for modification by filter - */ -static void -f_rta_cow(struct filter_state *fs) -{ - if (!rta_is_cached((*fs->rte)->attrs)) - return; - - /* Prepare to modify rte */ - f_rte_cow(fs); - - /* Store old rta to free it later, it stores reference from rte_cow() */ - fs->old_rta = (*fs->rte)->attrs; - - /* - * Get shallow copy of rta. Fields eattrs and nexthops of rta are shared - * with fs->old_rta (they will be copied when the cached rta will be obtained - * at the end of f_run()), also the lock of hostentry is inherited (we - * suppose hostentry is not changed by filters). - */ - (*fs->rte)->attrs = rta_do_cow((*fs->rte)->attrs, tmp_linpool); - - /* Re-cache the ea_list */ - f_cache_eattrs(fs); -} - static struct tbf rl_runtime_err = TBF_DEFAULT_LOG_LIMITS; /** @@ -289,7 +259,7 @@ f_run(const struct filter *filter, struct rte **rte, int flags) /* Run the interpreter itself */ enum filter_return fret = interpret(&filter_state, filter->root, NULL); - if (filter_state.old_rta) { + if (filter_state.eattrs && !ea_is_cached(*filter_state.eattrs)) { /* * Cached rta was modified and filter_state->rte contains now an uncached one, * sharing some part with the cached one. The cached rta should @@ -302,6 +272,10 @@ f_run(const struct filter *filter, struct rte **rte, int flags) * This is not the problem if rte was COW, because original rte * also holds the same rta. */ + ea_list *cached = *filter_state.eattrs; + while (cached && !ea_is_cached(cached)) + cached = cached->next; + if (!rte_cow) { /* Cache the new attrs */ (*filter_state.rte)->attrs = rta_lookup((*filter_state.rte)->attrs); @@ -311,8 +285,7 @@ f_run(const struct filter *filter, struct rte **rte, int flags) } /* Uncache the old attrs and drop the pointer as it is invalid now. */ - rta_free(filter_state.old_rta); - filter_state.old_rta = NULL; + rta_free(cached); } /* Process the filter output, log it and return */ -- cgit v1.2.3