From 4cbbb0a31a45860cdc365e9fba9621c24bbaf8d8 Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Fri, 7 Jun 2019 19:21:19 +0200 Subject: rule: Introduce rule_lookup_by_index() In contrast to rule_lookup(), this function returns a chain's rule at a given index instead of by handle. Signed-off-by: Phil Sutter Signed-off-by: Pablo Neira Ayuso --- src/rule.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src') diff --git a/src/rule.c b/src/rule.c index e570238a..20fe6f37 100644 --- a/src/rule.c +++ b/src/rule.c @@ -641,6 +641,17 @@ struct rule *rule_lookup(const struct chain *chain, uint64_t handle) return NULL; } +struct rule *rule_lookup_by_index(const struct chain *chain, uint64_t index) +{ + struct rule *rule; + + list_for_each_entry(rule, &chain->rules, list) { + if (!--index) + return rule; + } + return NULL; +} + struct scope *scope_init(struct scope *scope, const struct scope *parent) { scope->parent = parent; -- cgit v1.2.3