netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/4, libnftnl] rule: Implement internal expression iterator
@ 2016-08-08 11:17 Carlos Falgueras García
  2016-08-08 11:17 ` [PATCH 2/4, libnfntl] Implement rule comparison Carlos Falgueras García
                   ` (4 more replies)
  0 siblings, 5 replies; 32+ messages in thread
From: Carlos Falgueras García @ 2016-08-08 11:17 UTC (permalink / raw)
  To: netfilter-devel; +Cc: pablo

With 'nftnl_expr_iter_init' we can create an expression iterator without
dynamic memory allocation.

Signed-off-by: Carlos Falgueras García <carlosfg@riseup.net>
---
 include/internal.h |  1 +
 include/rule.h     | 15 +++++++++++++++
 src/rule.c         | 23 ++++++++++++-----------
 3 files changed, 28 insertions(+), 11 deletions(-)
 create mode 100644 include/rule.h

diff --git a/include/internal.h b/include/internal.h
index c74e2bf..f1b6511 100644
--- a/include/internal.h
+++ b/include/internal.h
@@ -12,6 +12,7 @@
 #include "set.h"
 #include "set_elem.h"
 #include "expr.h"
+#include "rule.h"
 #include "expr_ops.h"
 #include "buffer.h"
 
diff --git a/include/rule.h b/include/rule.h
new file mode 100644
index 0000000..e2ea578
--- /dev/null
+++ b/include/rule.h
@@ -0,0 +1,15 @@
+#ifndef _LIBNFTNL_RULE_INTERNAL_H_
+#define _LIBNFTNL_RULE_INTERNAL_H_
+
+#include <libnftnl/rule.h>
+#include <libnftnl/expr.h>
+
+struct nftnl_expr_iter {
+	const struct nftnl_rule	*r;
+	struct nftnl_expr	*cur;
+};
+
+void nftnl_expr_iter_init(const struct nftnl_rule *r,
+			  struct nftnl_expr_iter *iter);
+
+#endif
diff --git a/src/rule.c b/src/rule.c
index a0edca7..0cfddf2 100644
--- a/src/rule.c
+++ b/src/rule.c
@@ -1025,10 +1025,17 @@ int nftnl_expr_foreach(struct nftnl_rule *r,
 }
 EXPORT_SYMBOL_ALIAS(nftnl_expr_foreach, nft_rule_expr_foreach);
 
-struct nftnl_expr_iter {
-	struct nftnl_rule		*r;
-	struct nftnl_expr	*cur;
-};
+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);
+}
+EXPORT_SYMBOL(nftnl_expr_iter_init);
 
 struct nftnl_expr_iter *nftnl_expr_iter_create(struct nftnl_rule *r)
 {
@@ -1037,13 +1044,7 @@ struct nftnl_expr_iter *nftnl_expr_iter_create(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;
 }
-- 
2.8.3


^ permalink raw reply related	[flat|nested] 32+ messages in thread

end of thread, other threads:[~2016-08-12 12:11 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-08 11:17 [PATCH 1/4, libnftnl] rule: Implement internal expression iterator Carlos Falgueras García
2016-08-08 11:17 ` [PATCH 2/4, libnfntl] Implement rule comparison Carlos Falgueras García
2016-08-08 11:32   ` Pablo Neira Ayuso
2016-08-08 11:49     ` Carlos Falgueras García
2016-08-12  0:17   ` Pablo Neira Ayuso
2016-08-08 11:17 ` [PATCH 3/4, nft] Simplify parser rule_spec tree Carlos Falgueras García
2016-08-08 11:17 ` [PATCH 4/4, nft] Implement deleting rule by description Carlos Falgueras García
2016-08-08 11:25 ` [PATCH 1/4, libnftnl] rule: Implement internal expression iterator Pablo Neira Ayuso
2016-08-08 11:49   ` Carlos Falgueras García
2016-08-08 12:42 ` [PATCH 1/5, V2, libnftnl] rule: Add const modifier to rule field of " Carlos Falgueras García
2016-08-08 12:42   ` [PATCH 2/5, V2, libnftnl] rule: Implement internal " Carlos Falgueras García
2016-08-08 12:42   ` [PATCH 3/5, V2, libnftnl] Implement rule comparison Carlos Falgueras García
2016-08-08 14:50     ` Pablo Neira Ayuso
2016-08-08 12:42   ` [PATCH 4/5, V2, nft] Simplify parser rule_spec tree Carlos Falgueras García
2016-08-08 14:54     ` Pablo Neira Ayuso
2016-08-08 17:02       ` Carlos Falgueras García
2016-08-08 12:42   ` [PATCH 5/5, V2, nft] Implement deleting rule by description Carlos Falgueras García
2016-08-08 14:46     ` Pablo Neira Ayuso
2016-08-08 14:48   ` [PATCH 1/5, V2, libnftnl] rule: Add const modifier to rule field of expression iterator Pablo Neira Ayuso
2016-08-08 18:10     ` [PATCH] rule: Constify rule iterators Carlos Falgueras García
2016-08-09  7:17       ` Pablo Neira Ayuso
2016-08-09 11:42         ` [PATCH, v2] Constify iterators Carlos Falgueras García
2016-08-10  8:30           ` Pablo Neira Ayuso
2016-08-10  9:48     ` [PATCH 1/4, V3, libnftnl] rule: Implement internal expression iterator Carlos Falgueras García
2016-08-10  9:48       ` [PATCH 2/4, V3, libnftnl] Implement rule comparison Carlos Falgueras García
2016-08-10 11:35         ` Pablo Neira Ayuso
2016-08-10  9:48       ` [PATCH 3/4, V3, nft] Simplify parser rule_spec tree Carlos Falgueras García
2016-08-12 12:11         ` Pablo Neira Ayuso
2016-08-10  9:48       ` [PATCH 4/4, V3, nft] Implement deleting rule by description Carlos Falgueras García
2016-08-10 11:41       ` [PATCH 1/4, V3, libnftnl] rule: Implement internal expression iterator Pablo Neira Ayuso
2016-08-10 11:56         ` Carlos Falgueras García
2016-08-10 12:08           ` Pablo Neira Ayuso

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).