Skip to contentSkip to conversation

expr: Introduce nftnl_expr_fprintf()

PATCH Superseded Phil Sutter 2 participants 9 messages Oct 4, 2017 – Oct 17, 2017 netfilter

lore
Share & tools
lore

Phil Sutter

author reviewer
#0 lore raw

PATCH 1/1 expr: Introduce nftnl_expr_fprintf()

Implement expression printing into a FILE pointer analogous to nftnl_rule_fprintf().

---
 include/libnftnl/expr.h |  1 +
 src/expr.c              | 14 ++++++++++++++
 2 files changed, 15 insertions(+)
include/libnftnl/expr.h +1 -0
index 76f28fee7b5f7..f37f50963d6c3 100644
@@ -39,6 +39,7 @@ const char *nftnl_expr_get_str(const struct nftnl_expr *expr, uint16_t type);
 bool nftnl_expr_cmp(const struct nftnl_expr *e1, const struct nftnl_expr *e2);
 
 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);
 
 enum {
 	NFTNL_EXPR_PAYLOAD_DREG	= NFTNL_EXPR_BASE,
src/expr.c +14 -0
index c5fcf06492ae2..1eae70787209d 100644
@@ -293,3 +293,17 @@ int nftnl_expr_snprintf(char *buf, size_t size, const struct nftnl_expr *expr,
 	return offset;
 }
 EXPORT_SYMBOL(nftnl_expr_snprintf);
+
+static int nftnl_expr_do_snprintf(char *buf, size_t size, const void *e,
+				  uint32_t cmd, uint32_t type, uint32_t flags)
+{
+	return nftnl_expr_snprintf(buf, size, e, type, flags);
+}
+
+int nftnl_expr_fprintf(FILE *fp, const struct nftnl_expr *expr, uint32_t type,
+		       uint32_t flags)
+{
+	return nftnl_fprintf(fp, expr, NFTNL_CMD_UNSPEC, type, flags,
+			     nftnl_expr_do_snprintf);
+}
+EXPORT_SYMBOL(nftnl_expr_fprintf);
Signature · 1 line
2.13.1
#1 lore raw

Hi Phil,

Quoted 2 lines · Phil Sutter

Implement expression printing into a FILE pointer analogous to nftnl_rule_fprintf().

src/libnftnl.map needs to be updated. I can do it here myself, no problem, or feel free to send v2, as you prefer.

Quoted 43 lines
---
 include/libnftnl/expr.h |  1 +
 src/expr.c              | 14 ++++++++++++++
 2 files changed, 15 insertions(+)
include/libnftnl/expr.h +1 -0
index 76f28fee7b5f7..f37f50963d6c3 100644
@@ -39,6 +39,7 @@ const char *nftnl_expr_get_str(const struct nftnl_expr *expr, uint16_t type);
 bool nftnl_expr_cmp(const struct nftnl_expr *e1, const struct nftnl_expr *e2);
 
 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);
 
 enum {
 	NFTNL_EXPR_PAYLOAD_DREG	= NFTNL_EXPR_BASE,
src/expr.c +14 -0
index c5fcf06492ae2..1eae70787209d 100644
@@ -293,3 +293,17 @@ int nftnl_expr_snprintf(char *buf, size_t size, const struct nftnl_expr *expr,
 	return offset;
 }
 EXPORT_SYMBOL(nftnl_expr_snprintf);
+
+static int nftnl_expr_do_snprintf(char *buf, size_t size, const void *e,
+				  uint32_t cmd, uint32_t type, uint32_t flags)
+{
+	return nftnl_expr_snprintf(buf, size, e, type, flags);
+}
+
+int nftnl_expr_fprintf(FILE *fp, const struct nftnl_expr *expr, uint32_t type,
+		       uint32_t flags)
+{
+	return nftnl_fprintf(fp, expr, NFTNL_CMD_UNSPEC, type, flags,
+			     nftnl_expr_do_snprintf);
+}
+EXPORT_SYMBOL(nftnl_expr_fprintf);
Signature · 1 line
2.13.1
author reviewer
#2 lore raw

PATCH v2 1/1 expr: Introduce nftnl_expr_fprintf()

Implement expression printing into a FILE pointer analogous to nftnl_rule_fprintf().

---
Changes since v1:
- Update src/libnftnl.map

---
 include/libnftnl/expr.h |  1 +
 src/expr.c              | 14 ++++++++++++++
 src/libnftnl.map        |  1 +
 3 files changed, 16 insertions(+)
include/libnftnl/expr.h +1 -0
index 76f28fee7b5f7..f37f50963d6c3 100644
@@ -39,6 +39,7 @@ const char *nftnl_expr_get_str(const struct nftnl_expr *expr, uint16_t type);
 bool nftnl_expr_cmp(const struct nftnl_expr *e1, const struct nftnl_expr *e2);
 
 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);
 
 enum {
 	NFTNL_EXPR_PAYLOAD_DREG	= NFTNL_EXPR_BASE,
src/expr.c +14 -0
index c5fcf06492ae2..1eae70787209d 100644
@@ -293,3 +293,17 @@ int nftnl_expr_snprintf(char *buf, size_t size, const struct nftnl_expr *expr,
 	return offset;
 }
 EXPORT_SYMBOL(nftnl_expr_snprintf);
+
+static int nftnl_expr_do_snprintf(char *buf, size_t size, const void *e,
+				  uint32_t cmd, uint32_t type, uint32_t flags)
+{
+	return nftnl_expr_snprintf(buf, size, e, type, flags);
+}
+
+int nftnl_expr_fprintf(FILE *fp, const struct nftnl_expr *expr, uint32_t type,
+		       uint32_t flags)
+{
+	return nftnl_fprintf(fp, expr, NFTNL_CMD_UNSPEC, type, flags,
+			     nftnl_expr_do_snprintf);
+}
+EXPORT_SYMBOL(nftnl_expr_fprintf);
src/libnftnl.map +1 -0
index 1892c983eb504..a01a6599a9750 100644
@@ -103,6 +103,7 @@ global:
   nftnl_expr_get_u64;
   nftnl_expr_get_str;
   nftnl_expr_snprintf;
+  nftnl_expr_fprintf;
   nftnl_expr_free;
 
   nftnl_rule_list_alloc;
Signature · 1 line
2.13.1
#3 lore raw
Quoted 7 lines · Phil Sutter

Implement expression printing into a FILE pointer analogous to nftnl_rule_fprintf().

---
Changes since v1:
- Update src/libnftnl.map

Thanks Phil.

I think we need to collapse this change to your patch.

src/libnftnl.map +4 -1
index a01a6599a975..74f33c438a16 100644
@@ -103,7 +103,6 @@ global:
   nftnl_expr_get_u64;
   nftnl_expr_get_str;
   nftnl_expr_snprintf;
-  nftnl_expr_fprintf;
   nftnl_expr_free;
 
   nftnl_rule_list_alloc;
@@ -308,3 +307,7 @@ global:
 
 local: *;
 };
+
+LIBNFTNL_6 {
+  nftnl_expr_fprintf;
+} LIBMNL_5;
author reviewer
#4 lore raw
Quoted 4 lines · Pablo Neira Ayuso
Quoted 3 lines · Phil Sutter

Implement expression printing into a FILE pointer analogous to nftnl_rule_fprintf().

Quoted 8 lines
Quoted 4 lines

---
Changes since v1:
- Update src/libnftnl.map

Thanks Phil.

I think we need to collapse this change to your patch.

Ah, so that is because LIBNFTNL_5 is already released in 1.0.8, right?

Do I have to adjust the respective nftables patch for backwards compatibility? If so, in which way?

Thanks, Phil

PS: V3 follows in a few seconds.

author reviewer
#5 lore raw
In reply to Pablo Neira Ayuso

Hi,

Actually, I don't quite get the suggested change:

src/libnftnl.map global: · line 313

Quoted 8 lines · Pablo Neira Ayuso
src/libnftnl.map +4 -0
@@ -308,3 +307,7 @@ global:
 
 local: *;
 };
+
+LIBNFTNL_6 {
+  nftnl_expr_fprintf;
+} LIBMNL_5;

Why LIBMNL_5? Shouldn't this be LIBNFTNL_5?

Cheers, Phil

#6 lore raw
Quoted 7 lines · Phil Sutter

Hi,

Actually, I don't quite get the suggested change:

Quoted 2 lines · Pablo Neira Ayuso
(quoted diff) +0 -0
@@ -308,3 +307,7 @@ global:
 
Quoted 8 lines

src/libnftnl.map global: · line 313

Quoted 6 lines
src/libnftnl.map +4 -0
 local: *;
 };
+
+LIBNFTNL_6 {
+  nftnl_expr_fprintf;
+} LIBMNL_5;

Why LIBMNL_5? Shouldn't this be LIBNFTNL_5?

Oh right :-)

Neurons rollerskating here, sorry.

author reviewer
#7 lore raw

PATCH v3 1/1 expr: Introduce nftnl_expr_fprintf()

Implement expression printing into a FILE pointer analogous to nftnl_rule_fprintf().

---
Changes since v2:
- Fix src/libnftnl.map update.

Changes since v1:
- Update src/libnftnl.map.

---
 include/libnftnl/expr.h |  1 +
 src/expr.c              | 14 ++++++++++++++
 src/libnftnl.map        |  4 ++++
 3 files changed, 19 insertions(+)
include/libnftnl/expr.h +1 -0
index 76f28fee7b5f7..f37f50963d6c3 100644
@@ -39,6 +39,7 @@ const char *nftnl_expr_get_str(const struct nftnl_expr *expr, uint16_t type);
 bool nftnl_expr_cmp(const struct nftnl_expr *e1, const struct nftnl_expr *e2);
 
 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);
 
 enum {
 	NFTNL_EXPR_PAYLOAD_DREG	= NFTNL_EXPR_BASE,
src/expr.c +14 -0
index c5fcf06492ae2..1eae70787209d 100644
@@ -293,3 +293,17 @@ int nftnl_expr_snprintf(char *buf, size_t size, const struct nftnl_expr *expr,
 	return offset;
 }
 EXPORT_SYMBOL(nftnl_expr_snprintf);
+
+static int nftnl_expr_do_snprintf(char *buf, size_t size, const void *e,
+				  uint32_t cmd, uint32_t type, uint32_t flags)
+{
+	return nftnl_expr_snprintf(buf, size, e, type, flags);
+}
+
+int nftnl_expr_fprintf(FILE *fp, const struct nftnl_expr *expr, uint32_t type,
+		       uint32_t flags)
+{
+	return nftnl_fprintf(fp, expr, NFTNL_CMD_UNSPEC, type, flags,
+			     nftnl_expr_do_snprintf);
+}
+EXPORT_SYMBOL(nftnl_expr_fprintf);
src/libnftnl.map +4 -0
index 1892c983eb504..d59e80269604c 100644
@@ -307,3 +307,7 @@ global:
 
 local: *;
 };
+
+LIBNFTNL_6 {
+  nftnl_expr_fprintf;
+} LIBNFTNL_5;
Signature · 1 line
2.13.1
maintainer Applied
#8 lore raw
Quoted 2 lines · Phil Sutter

Implement expression printing into a FILE pointer analogous to nftnl_rule_fprintf().

Applied, thanks Phil!