@@ -29,6 +29,14 @@
#include <libnftnl/set.h>
#include <libnftnl/expr.h>
+struct nftnl_expr_iter {
+ const struct nftnl_rule *r;
+ struct nftnl_expr *cur;
+};
+
+static void nftnl_expr_iter_init(const struct nftnl_rule *r,
+ struct nftnl_expr_iter *iter);
+
struct nftnl_rule {
struct list_head head;
@@ -1025,10 +1033,16 @@ int nftnl_expr_foreach(struct nftnl_rule *r,
}
EXPORT_SYMBOL_ALIAS(nftnl_expr_foreach, nft_rule_expr_foreach);
-struct nftnl_expr_iter {
- const struct nftnl_rule *r;
- struct nftnl_expr *cur;
-};
+static void nftnl_expr_iter_init(const struct nftnl_rule *r,
+ struct nftnl_expr_iter *iter)
+{
+ iter->r = r;
+ if (list_empty(&r->expr_list))
+ iter->cur = NULL;
+ else
+ iter->cur = list_entry(r->expr_list.next, struct nftnl_expr,
+ head);
+}
struct nftnl_expr_iter *nftnl_expr_iter_create(const struct nftnl_rule *r)
{
@@ -1037,13 +1051,7 @@ struct nftnl_expr_iter *nftnl_expr_iter_create(const struct nftnl_rule *r)
iter = calloc(1, sizeof(struct nftnl_expr_iter));
if (iter == NULL)
return NULL;
-
- iter->r = r;
- if (list_empty(&r->expr_list))
- iter->cur = NULL;
- else
- iter->cur = list_entry(r->expr_list.next, struct nftnl_expr,
- head);
+ nftnl_expr_iter_init(r, iter);
return iter;
}
Introduce nftnl_expr_iter_init() to allow stack allocated iterators for internal use. Signed-off-by: Carlos Falgueras García <carlosfg@riseup.net> --- src/rule.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-)