@@ -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,
@@ -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
@@ -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;
+}
@@ -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;
@@ -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);
}
@@ -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;
+}
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@strlen.de> --- 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(+)