From: Florent Bruneau Date: Wed, 17 Sep 2008 17:27:49 +0000 (+0200) Subject: Fix loop detection (we're on oriented graph). X-Git-Url: http://git.madism.org/?a=commitdiff_plain;h=b90060d134b09aff84d0bd1312850abb9fc6fb9e;p=apps%2Fpfixtools.git Fix loop detection (we're on oriented graph). Signed-off-by: Florent Bruneau --- diff --git a/postlicyd/filter.c b/postlicyd/filter.c index dea4436..de6ba03 100644 --- a/postlicyd/filter.c +++ b/postlicyd/filter.c @@ -56,8 +56,6 @@ filter_type_t filter_register(const char *type, filter_constructor_t constructor filter_token tok = filter_tokenize(type, m_strlen(type)); CHECK_FILTER(tok); - syslog(LOG_DEBUG, "filter type %s registered", type); - runners[tok] = runner; constructors[tok] = constructor; destructors[tok] = destructor; @@ -71,9 +69,6 @@ filter_result_t filter_hook_register(filter_type_t filter, CHECK_FILTER(filter); CHECK_HOOK(tok); - syslog(LOG_DEBUG, "hook %s registered for filter type %s", name, - ftokens[filter]); - hooks[filter][tok] = true; return tok; } @@ -85,9 +80,6 @@ filter_param_id_t filter_param_register(filter_type_t filter, CHECK_FILTER(filter); CHECK_PARAM(tok); - syslog(LOG_INFO, "param %s registered for filter type %s", name, - ftokens[filter]); - params[filter][tok] = true; return tok; } @@ -129,35 +121,30 @@ bool filter_update_references(filter_t *filter, A(filter_t) *filter_list) return true; } -static inline bool filter_check_loop(filter_t *filter, A(filter_t) *array, bool cleanup) +static inline bool filter_check_loop(filter_t *filter, A(filter_t) *array, int level) { - if (cleanup) { - foreach (filter_t *filter2, *array) { - filter2->seen = false; - }} - } else if (filter->seen) { - return false; - } - if (filter->safe) { + if (filter->last_seen == level) { return true; } - filter->seen = true; + filter->last_seen = level; foreach (filter_hook_t *hook, filter->hooks) { if (hook->postfix) { continue; } - if (!filter_check_loop(array_ptr(*array, hook->filter_id), array, false)) { + if (hook->filter_id == level) { + return false; + } + if (!filter_check_loop(array_ptr(*array, hook->filter_id), array, level)) { return false; } }} - filter->safe = true; return true; } bool filter_check_safety(A(filter_t) *array) { foreach (filter_t *filter, *array) { - if (!filter_check_loop(filter, array, true)) { + if (!filter_check_loop(filter, array, __Ai)) { syslog(LOG_ERR, "the filter tree contains a loop"); return false; } diff --git a/postlicyd/filter.h b/postlicyd/filter.h index f53b917..c950402 100644 --- a/postlicyd/filter.h +++ b/postlicyd/filter.h @@ -72,14 +72,13 @@ typedef struct filter_t { A(filter_param_t) params; - /* Internal: to check the filter tree structure. + /* Loop checking flags. */ - unsigned safe :1; - unsigned seen :1; + int last_seen; } filter_t; ARRAY(filter_t) -#define FILTER_INIT { NULL, FTK_UNKNOWN, ARRAY_INIT, NULL, ARRAY_INIT, false, false } +#define FILTER_INIT { NULL, FTK_UNKNOWN, ARRAY_INIT, NULL, ARRAY_INIT, -1 } #define CHECK_FILTER(Filter) \ assert(Filter != FTK_UNKNOWN && Filter != FTK_count \ && "Unknown filter type")