[PATCH libnftnl 3/5] libnftnl: add api to query dissection state

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Allow to check if the set / expression was decoded as-expected.

These two functions return false in case libnftl had to ignore
new attributes that it did not expect.

Signed-off-by: Florian Westphal <fw@xxxxxxxxx>
---
 include/libnftnl/expr.h | 2 ++
 include/libnftnl/set.h  | 1 +
 src/expr.c              | 6 ++++++
 src/libnftnl.map        | 5 +++++
 src/rule.c              | 5 +++++
 src/set.c               | 6 ++++++
 6 files changed, 25 insertions(+)

diff --git a/include/libnftnl/expr.h b/include/libnftnl/expr.h
index fba121062244..d938475394ec 100644
--- a/include/libnftnl/expr.h
+++ b/include/libnftnl/expr.h
@@ -47,6 +47,8 @@ int nftnl_expr_expr_foreach(const struct nftnl_expr *e,
 int nftnl_expr_snprintf(char *buf, size_t buflen, const struct nftnl_expr *expr, uint32_t type, uint32_t flags);
 int nftnl_expr_fprintf(FILE *fp, const struct nftnl_expr *expr, uint32_t type, uint32_t flags);
 
+bool nftnl_expr_complete(const struct nftnl_expr *expr);
+
 enum {
 	NFTNL_EXPR_PAYLOAD_DREG	= NFTNL_EXPR_BASE,
 	NFTNL_EXPR_PAYLOAD_BASE,
diff --git a/include/libnftnl/set.h b/include/libnftnl/set.h
index e2e5795aa9b4..2e624c3e7e66 100644
--- a/include/libnftnl/set.h
+++ b/include/libnftnl/set.h
@@ -171,6 +171,7 @@ void nftnl_set_elems_iter_destroy(struct nftnl_set_elems_iter *iter);
 int nftnl_set_elems_nlmsg_build_payload_iter(struct nlmsghdr *nlh,
 					   struct nftnl_set_elems_iter *iter);
 
+bool nftnl_set_complete(const struct nftnl_set *set);
 #ifdef __cplusplus
 } /* extern "C" */
 #endif
diff --git a/src/expr.c b/src/expr.c
index 4e32189c6e8d..99078dcd058e 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -311,3 +311,9 @@ int nftnl_expr_fprintf(FILE *fp, const struct nftnl_expr *expr, uint32_t type,
 	return nftnl_fprintf(fp, expr, NFTNL_CMD_UNSPEC, type, flags,
 			     nftnl_expr_do_snprintf);
 }
+
+EXPORT_SYMBOL(nftnl_expr_complete);
+bool nftnl_expr_complete(const struct nftnl_expr *expr)
+{
+	return !expr->incomplete;
+}
diff --git a/src/libnftnl.map b/src/libnftnl.map
index 8fffff19eb2e..90eb4a92fca4 100644
--- a/src/libnftnl.map
+++ b/src/libnftnl.map
@@ -383,3 +383,8 @@ LIBNFTNL_16 {
 LIBNFTNL_17 {
   nftnl_set_elem_nlmsg_build;
 } LIBNFTNL_16;
+
+LIBNFTNL_18 {
+  nftnl_set_complete;
+  nftnl_expr_complete;
+} LIBNFTNL_17;
diff --git a/src/rule.c b/src/rule.c
index c22918a8f352..aa969ad5f876 100644
--- a/src/rule.c
+++ b/src/rule.c
@@ -582,6 +582,11 @@ static int nftnl_rule_snprintf_default(char *buf, size_t remain,
 					     type, flags);
 		SNPRINTF_BUFFER_SIZE(ret, remain, offset);
 
+		if (!nftnl_expr_complete(expr)) {
+			ret = snprintf(buf + offset, remain, "[incomplete]");
+			SNPRINTF_BUFFER_SIZE(ret, remain, offset);
+		}
+
 		ret = snprintf(buf + offset, remain, "]");
 		SNPRINTF_BUFFER_SIZE(ret, remain, offset);
 	}
diff --git a/src/set.c b/src/set.c
index 75ad64e03850..40f5e1a955fd 100644
--- a/src/set.c
+++ b/src/set.c
@@ -1051,3 +1051,9 @@ int nftnl_set_lookup_id(struct nftnl_expr *e,
 	*set_id = nftnl_set_get_u32(s, NFTNL_SET_ID);
 	return 1;
 }
+
+EXPORT_SYMBOL(nftnl_set_complete);
+bool nftnl_set_complete(const struct nftnl_set *set)
+{
+	return !set->incomplete;
+}
-- 
2.45.2





[Index of Archives]     [Netfitler Users]     [Berkeley Packet Filter]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux