Skip to contentSkip to conversation

src: add flowtable support

PATCH New Pablo Neira Ayuso 1 participant 2 messages Jan 23, 2018 netfilter

lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 1/2 src: add flowtable support

This patch allows you to add, delete and list flowtable through the existing netlink interface.

---
 examples/Makefile.am                |  12 +
 examples/nft-flowtable-add.c        | 136 +++++++
 examples/nft-flowtable-del.c        | 122 ++++++
 examples/nft-flowtable-get.c        | 121 ++++++
 include/libnftnl/Makefile.am        |   1 +
 include/libnftnl/flowtable.h        |  81 ++++
 include/linux/netfilter/nf_tables.h |  53 +++
 src/Makefile.am                     |   1 +
 src/flowtable.c                     | 793 ++++++++++++++++++++++++++++++++++++
 src/libnftnl.map                    |  31 ++
 10 files changed, 1351 insertions(+)
 create mode 100644 examples/nft-flowtable-add.c
 create mode 100644 examples/nft-flowtable-del.c
 create mode 100644 examples/nft-flowtable-get.c
 create mode 100644 include/libnftnl/flowtable.h
 create mode 100644 src/flowtable.c
examples/Makefile.am +12 -0
index 48bc7a16c9c6..c0d84ebbcbff 100644
@@ -25,6 +25,9 @@ check_PROGRAMS = nft-table-add		\
 		 nft-obj-add		\
 		 nft-obj-get		\
 		 nft-obj-del		\
+		 nft-flowtable-add	\
+		 nft-flowtable-del	\
+		 nft-flowtable-get	\
 		 nft-ruleset-get	\
 		 nft-ruleset-parse-file	\
 		 nft-compat-get
@@ -104,6 +107,15 @@ nft_obj_del_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS}
 nft_obj_get_SOURCES = nft-obj-get.c
 nft_obj_get_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS}
 
+nft_flowtable_add_SOURCES = nft-flowtable-add.c
+nft_flowtable_add_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS}
+
+nft_flowtable_del_SOURCES = nft-flowtable-del.c
+nft_flowtable_del_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS}
+
+nft_flowtable_get_SOURCES = nft-flowtable-get.c
+nft_flowtable_get_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS}
+
 nft_ruleset_get_SOURCES = nft-ruleset-get.c
 nft_ruleset_get_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS}
 
examples/nft-flowtable-add.c new file +136 -0

136 lines not on this page · raw message

examples/nft-flowtable-del.c new file +122 -0

122 lines not on this page · raw message

examples/nft-flowtable-get.c new file +121 -0

121 lines not on this page · raw message

include/libnftnl/Makefile.am +1 -0
index 6dc7b2b38590..d846a574f438 100644
@@ -6,6 +6,7 @@ pkginclude_HEADERS = batch.h		\
 		     rule.h		\
 		     expr.h		\
 		     set.h		\
+		     flowtable.h	\
 		     ruleset.h		\
 		     common.h		\
 		     udata.h		\
include/libnftnl/flowtable.h new file +81 -0

81 lines not on this page · raw message

include/linux/netfilter/nf_tables.h +53 -0

71 lines not on this page · raw message

src/Makefile.am +1 -0
index 59ddf6a249a2..7708c279c9da 100644
@@ -8,6 +8,7 @@ libnftnl_la_LDFLAGS = -Wl,--version-script=$(srcdir)/libnftnl.map	\
 libnftnl_la_SOURCES = utils.c		\
 		      batch.c		\
 		      buffer.c		\
+		      flowtable.c	\
 		      common.c		\
 		      gen.c		\
 		      table.c		\
src/flowtable.c new file +793 -0

793 lines not on this page · raw message

src/libnftnl.map +31 -0
index d59e80269604..cfe74e2aebfc 100644
@@ -311,3 +311,34 @@ local: *;
 LIBNFTNL_6 {
   nftnl_expr_fprintf;
 } LIBNFTNL_5;
+
+LIBNFTNL_7 {
+  nftnl_flowtable_alloc;
+  nftnl_flowtable_free;
+  nftnl_flowtable_is_set;
+  nftnl_flowtable_unset;
+  nftnl_flowtable_set;
+  nftnl_flowtable_set_u32;
+  nftnl_flowtable_set_s32;
+  nftnl_flowtable_set_array;
+  nftnl_flowtable_set_str;
+  nftnl_flowtable_get;
+  nftnl_flowtable_get_u32;
+  nftnl_flowtable_get_s32;
+  nftnl_flowtable_get_array;
+  nftnl_flowtable_get_str;
+  nftnl_flowtable_parse;
+  nftnl_flowtable_parse_file;
+  nftnl_flowtable_snprintf;
+  nftnl_flowtable_fprintf;
+  nftnl_flowtable_nlmsg_build_payload;
+  nftnl_flowtable_nlmsg_parse;
+  nftnl_flowtable_list_alloc;
+  nftnl_flowtable_list_free;
+  nftnl_flowtable_list_is_empty;
+  nftnl_flowtable_list_add;
+  nftnl_flowtable_list_add_tail;
+  nftnl_flowtable_list_del;
+  nftnl_flowtable_list_foreach;
+
+} LIBNFTNL_6;
Signature · 1 line
2.11.0
author maintainer
#1 lore raw

PATCH 2/2 expr: add flow offload expression

This patch adds the new "flow_offload" expression to select what flows are offloaded to an existing flowtable.

---
 include/libnftnl/expr.h             |   4 +
 include/linux/netfilter/nf_tables.h |  11 +++
 src/Makefile.am                     |   1 +
 src/expr/flow_offload.c             | 184 ++++++++++++++++++++++++++++++++++++
 src/expr_ops.c                      |   2 +
 5 files changed, 202 insertions(+)
 create mode 100644 src/expr/flow_offload.c
include/libnftnl/expr.h +4 -0
index f37f50963d6c..76df94276c46 100644
@@ -221,6 +221,10 @@ enum {
 };
 
 enum {
+	NFTNL_EXPR_FLOW_TABLE_NAME = NFTNL_EXPR_BASE,
+};
+
+enum {
 	NFTNL_EXPR_FWD_SREG_DEV = NFTNL_EXPR_BASE,
 };
 
include/linux/netfilter/nf_tables.h +11 -0
index c525e67a665d..2edccfee9506 100644
@@ -952,6 +952,17 @@ enum nft_ct_attributes {
 };
 #define NFTA_CT_MAX		(__NFTA_CT_MAX - 1)
 
+/**
+ * enum nft_flow_attributes - ct offload expression attributes
+ * @NFTA_FLOW_TABLE_NAME: flow table name (NLA_STRING)
+ */
+enum nft_offload_attributes {
+	NFTA_FLOW_UNSPEC,
+	NFTA_FLOW_TABLE_NAME,
+	__NFTA_FLOW_MAX,
+};
+#define NFTA_FLOW_MAX		(__NFTA_FLOW_MAX - 1)
+
 enum nft_limit_type {
 	NFT_LIMIT_PKTS,
 	NFT_LIMIT_PKT_BYTES
src/Makefile.am +1 -0
index 7708c279c9da..578b7d36d8a9 100644
@@ -32,6 +32,7 @@ libnftnl_la_SOURCES = utils.c		\
 		      expr/data_reg.c	\
 		      expr/dup.c	\
 		      expr/exthdr.c	\
+		      expr/flow_offload.c \
 		      expr/fib.c	\
 		      expr/fwd.c	\
 		      expr/limit.c	\
src/expr/flow_offload.c new file +184 -0

184 lines not on this page · raw message

src/expr_ops.c +2 -0
index 7a0e1e3d0a26..041bd357d370 100644
@@ -33,6 +33,7 @@ extern struct expr_ops expr_ops_target;
 extern struct expr_ops expr_ops_dynset;
 extern struct expr_ops expr_ops_hash;
 extern struct expr_ops expr_ops_fib;
+extern struct expr_ops expr_ops_flow;
 
 static struct expr_ops expr_ops_notrack = {
 	.name	= "notrack",
@@ -69,6 +70,7 @@ static struct expr_ops *expr_ops[] = {
 	&expr_ops_hash,
 	&expr_ops_fib,
 	&expr_ops_objref,
+	&expr_ops_flow,
 	NULL,
 };
 
Signature · 1 line
2.11.0