]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
rule: Introduce rule_lookup_by_index()
authorPhil Sutter <phil@nwl.cc>
Fri, 7 Jun 2019 17:21:19 +0000 (19:21 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Fri, 7 Jun 2019 21:54:51 +0000 (23:54 +0200)
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 <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
include/rule.h
src/rule.c

index bf3f39636efb52fbc4b2fbfec43da466d997e793..87b440b63ba5c8cb2b6ad5adbe30d547352a59ac 100644 (file)
@@ -260,6 +260,8 @@ extern struct rule *rule_get(struct rule *rule);
 extern void rule_free(struct rule *rule);
 extern void rule_print(const struct rule *rule, struct output_ctx *octx);
 extern struct rule *rule_lookup(const struct chain *chain, uint64_t handle);
+extern struct rule *rule_lookup_by_index(const struct chain *chain,
+                                        uint64_t index);
 
 /**
  * struct set - nftables set
index e570238a40f5b666702e70b29976d0267b715f1d..20fe6f3758cbcc9560205c5a0b6f9d441d68d5cc 100644 (file)
@@ -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;