Skip to contentSkip to conversation

add ct expectation support

PATCH Superseded Stéphane Veyret 2 participants 7 messages May 31, 2019 – Jun 19, 2019 netfilter

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v4 cover add ct expectation support

Please find here the second part of the ct expectation support. When needed, please ask me for the third part: nft patch.

Stéphane Veyret (2):
src: add ct expectation support
examples: add ct expectation examples

 examples/Makefile.am                   |  16 ++
 examples/nft-ct-expectation-add.c      | 153 ++++++++++++++++++
 examples/nft-ct-expectation-del.c      | 126 +++++++++++++++
 examples/nft-ct-expectation-get.c      | 142 +++++++++++++++++
 examples/nft-rule-ct-expectation-add.c | 163 +++++++++++++++++++
 include/libnftnl/object.h              |   8 +
 include/linux/netfilter/nf_tables.h    |  14 +-
 include/obj.h                          |   8 +
 src/Makefile.am                        |   1 +
 src/obj/ct_expect.c                    | 213 +++++++++++++++++++++++++
 src/object.c                           |   1 +
 11 files changed, 844 insertions(+), 1 deletion(-)
 create mode 100644 examples/nft-ct-expectation-add.c
 create mode 100644 examples/nft-ct-expectation-del.c
 create mode 100644 examples/nft-ct-expectation-get.c
 create mode 100644 examples/nft-rule-ct-expectation-add.c
 create mode 100644 src/obj/ct_expect.c
Signature · 1 line
2.21.0
#1 lore raw

PATCH v4 1/2 src: add ct expectation support

Add support for ct expectation objects, used to define specific expectations.

---
 include/libnftnl/object.h           |   8 ++
 include/linux/netfilter/nf_tables.h |  14 +-
 include/obj.h                       |   8 ++
 src/Makefile.am                     |   1 +
 src/obj/ct_expect.c                 | 213 ++++++++++++++++++++++++++++
 src/object.c                        |   1 +
 6 files changed, 244 insertions(+), 1 deletion(-)
 create mode 100644 src/obj/ct_expect.c
include/libnftnl/object.h +8 -0
index 4ce2230..cce0713 100644
@@ -70,6 +70,14 @@ enum {
 	NFTNL_OBJ_CT_TIMEOUT_ARRAY,
 };
 
+enum {
+	NFTNL_OBJ_CT_EXPECT_L3PROTO	= NFTNL_OBJ_BASE,
+	NFTNL_OBJ_CT_EXPECT_L4PROTO,
+	NFTNL_OBJ_CT_EXPECT_DPORT,
+	NFTNL_OBJ_CT_EXPECT_TIMEOUT,
+	NFTNL_OBJ_CT_EXPECT_SIZE,
+};
+
 enum {
 	NFTNL_OBJ_LIMIT_RATE	= NFTNL_OBJ_BASE,
 	NFTNL_OBJ_LIMIT_UNIT,
include/linux/netfilter/nf_tables.h +13 -1
index fd38cdc..7eb8a5b 100644
@@ -1429,6 +1429,17 @@ enum nft_ct_timeout_attributes {
 };
 #define NFTA_CT_TIMEOUT_MAX	(__NFTA_CT_TIMEOUT_MAX - 1)
 
+enum nft_ct_expectation_attributes {
+	NFTA_CT_EXPECT_UNSPEC,
+	NFTA_CT_EXPECT_L3PROTO,
+	NFTA_CT_EXPECT_L4PROTO,
+	NFTA_CT_EXPECT_DPORT,
+	NFTA_CT_EXPECT_TIMEOUT,
+	NFTA_CT_EXPECT_SIZE,
+	__NFTA_CT_EXPECT_MAX,
+};
+#define NFTA_CT_EXPECT_MAX	(__NFTA_CT_EXPECT_MAX - 1)
+
 #define NFT_OBJECT_UNSPEC	0
 #define NFT_OBJECT_COUNTER	1
 #define NFT_OBJECT_QUOTA	2
@@ -1438,7 +1449,8 @@ enum nft_ct_timeout_attributes {
 #define NFT_OBJECT_TUNNEL	6
 #define NFT_OBJECT_CT_TIMEOUT	7
 #define NFT_OBJECT_SECMARK	8
-#define __NFT_OBJECT_MAX	9
+#define NFT_OBJECT_CT_EXPECT	9
+#define __NFT_OBJECT_MAX	10
 #define NFT_OBJECT_MAX		(__NFT_OBJECT_MAX - 1)
 
 /**
include/obj.h +8 -0
index 35b5c40..9394d79 100644
@@ -42,6 +42,13 @@ struct nftnl_obj {
 			uint8_t 	l4proto;
 			uint32_t	timeout[NFTNL_CTTIMEOUT_ARRAY_MAX];
 		} ct_timeout;
+		struct nftnl_obj_ct_expect {
+			uint16_t	l3proto;
+			uint16_t	dport;
+			uint8_t		l4proto;
+			uint8_t		size;
+			uint32_t	timeout;
+		} ct_expect;
 		struct nftnl_obj_limit {
 			uint64_t	rate;
 			uint64_t	unit;
@@ -99,6 +106,7 @@ extern struct obj_ops obj_ops_counter;
 extern struct obj_ops obj_ops_quota;
 extern struct obj_ops obj_ops_ct_helper;
 extern struct obj_ops obj_ops_ct_timeout;
+extern struct obj_ops obj_ops_ct_expect;
 extern struct obj_ops obj_ops_limit;
 extern struct obj_ops obj_ops_tunnel;
 extern struct obj_ops obj_ops_secmark;
src/Makefile.am +1 -0
index 2d5873f..8f9c022 100644
@@ -65,4 +65,5 @@ libnftnl_la_SOURCES = utils.c		\
 		      obj/limit.c	\
 		      obj/ct_timeout.c 	\
 		      obj/secmark.c	\
+		      obj/ct_expect.c 	\
 		      libnftnl.map
src/obj/ct_expect.c new file +213 -0

213 lines not on this page · raw message

src/object.c +1 -0
index 5c8d183..d8c87ee 100644
@@ -33,6 +33,7 @@ static struct obj_ops *obj_ops[__NFT_OBJECT_MAX] = {
 	[NFT_OBJECT_TUNNEL]	= &obj_ops_tunnel,
 	[NFT_OBJECT_CT_TIMEOUT] = &obj_ops_ct_timeout,
 	[NFT_OBJECT_SECMARK]	= &obj_ops_secmark,
+	[NFT_OBJECT_CT_EXPECT]	= &obj_ops_ct_expect,
 };
 
 static struct obj_ops *nftnl_obj_ops_lookup(uint32_t type)
Signature · 1 line
2.21.0
#2 lore raw

PATCH v4 2/2 examples: add ct expectation examples

In reply to Stéphane Veyret

Add examples for ct expectations.

Add, list and delete ct expectation objects from specified table. Add expectation object to rule.

---
 examples/Makefile.am                   |  16 +++
 examples/nft-ct-expectation-add.c      | 153 +++++++++++++++++++++++
 examples/nft-ct-expectation-del.c      | 126 +++++++++++++++++++
 examples/nft-ct-expectation-get.c      | 142 +++++++++++++++++++++
 examples/nft-rule-ct-expectation-add.c | 163 +++++++++++++++++++++++++
 5 files changed, 600 insertions(+)
 create mode 100644 examples/nft-ct-expectation-add.c
 create mode 100644 examples/nft-ct-expectation-del.c
 create mode 100644 examples/nft-ct-expectation-get.c
 create mode 100644 examples/nft-rule-ct-expectation-add.c
examples/Makefile.am +16 -0
index d044b90..db9164d 100644
@@ -29,10 +29,14 @@ check_PROGRAMS = nft-table-add		\
 		 nft-flowtable-get	\
 		 nft-ruleset-get	\
 		 nft-compat-get 	\
+		 nft-ct-expectation-add \
+		 nft-ct-expectation-del \
+		 nft-ct-expectation-get \
 		 nft-ct-helper-add	\
 		 nft-ct-helper-get	\
 		 nft-ct-helper-del	\
 		 nft-rule-ct-helper-add \
+		 nft-rule-ct-expectation-add \
 		 nft-rule-ct-timeout-add
 
 nft_table_add_SOURCES = nft-table-add.c
@@ -122,6 +126,15 @@ nft_ruleset_get_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS}
 nft_compat_get_SOURCES = nft-compat-get.c
 nft_compat_get_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS}
 
+nft_ct_expectation_add_SOURCES = nft-ct-expectation-add.c
+nft_ct_expectation_add_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS}
+
+nft_ct_expectation_del_SOURCES = nft-ct-expectation-del.c
+nft_ct_expectation_del_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS}
+
+nft_ct_expectation_get_SOURCES = nft-ct-expectation-get.c
+nft_ct_expectation_get_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS}
+
 nft_ct_helper_add_SOURCES = nft-ct-helper-add.c
 nft_ct_helper_add_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS}
 
@@ -134,5 +147,8 @@ nft_ct_helper_del_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS}
 nft_rule_ct_helper_add_SOURCES = nft-rule-ct-helper-add.c
 nft_rule_ct_helper_add_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS}
 
+nft_rule_ct_expectation_add_SOURCES = nft-rule-ct-expectation-add.c
+nft_rule_ct_expectation_add_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS}
+
 nft_rule_ct_timeout_add_SOURCES = nft-rule-ct-timeout-add.c
 nft_rule_ct_timeout_add_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS}
examples/nft-ct-expectation-add.c new file +153 -0

153 lines not on this page · raw message

examples/nft-ct-expectation-del.c new file +126 -0

126 lines not on this page · raw message

examples/nft-ct-expectation-get.c new file +142 -0

142 lines not on this page · raw message

examples/nft-rule-ct-expectation-add.c new file +163 -0

163 lines not on this page · raw message

Signature · 1 line
2.21.0
#3 lore raw
In reply to Stéphane Veyret

Hi Pablo,

Is this enough for you to test the “netfilter: nft_ct: add ct expectations support” patch or would you like me to also send the nft patch ?

Quoted 26 lines · Stéphane Veyret

Please find here the second part of the ct expectation support. When needed, please ask me for the third part: nft patch.

Stéphane Veyret (2):
src: add ct expectation support
examples: add ct expectation examples

 examples/Makefile.am                   |  16 ++
 examples/nft-ct-expectation-add.c      | 153 ++++++++++++++++++
 examples/nft-ct-expectation-del.c      | 126 +++++++++++++++
 examples/nft-ct-expectation-get.c      | 142 +++++++++++++++++
 examples/nft-rule-ct-expectation-add.c | 163 +++++++++++++++++++
 include/libnftnl/object.h              |   8 +
 include/linux/netfilter/nf_tables.h    |  14 +-
 include/obj.h                          |   8 +
 src/Makefile.am                        |   1 +
 src/obj/ct_expect.c                    | 213 +++++++++++++++++++++++++
 src/object.c                           |   1 +
 11 files changed, 844 insertions(+), 1 deletion(-)
 create mode 100644 examples/nft-ct-expectation-add.c
 create mode 100644 examples/nft-ct-expectation-del.c
 create mode 100644 examples/nft-ct-expectation-get.c
 create mode 100644 examples/nft-rule-ct-expectation-add.c
 create mode 100644 src/obj/ct_expect.c
Quoted 3 lines

--
2.21.0

Stéphane Veyret

#4 lore raw
Quoted 5 lines · Stéphane Veyret

Hi Pablo,

Is this enough for you to test the “netfilter: nft_ct: add ct expectations support” patch or would you like me to also send the nft patch ?

Please, submit this too, thanks.

#5 lore raw
Quoted 5 lines · Pablo Neira Ayuso
Quoted 3 lines

Is this enough for you to test the “netfilter: nft_ct: add ct expectations support” patch or would you like me to also send the nft patch ?

Please, submit this too, thanks.

Done… :-)

Signature · 1 line
Stéphane Veyret
#6 lore raw
In reply to Stéphane Veyret
Quoted 2 lines · Stéphane Veyret

Please find here the second part of the ct expectation support. When needed, please ask me for the third part: nft patch.

Series for libnftnl applied, thanks Stephane.