Skip to contentSkip to conversation

src: add range expression

PATCH New Pablo Neira Ayuso 1 participant 1 message Oct 13, 2016 netfilter

lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 1/1 src: add range expression

Add range expression available that is scheduled for linux kernel 4.9. This range expression allows us to check if a given value placed in a register is within/outside a specified interval.

---
 include/libnftnl/expr.h             |   7 +
 include/linux/netfilter/nf_tables.h |  29 ++++
 src/Makefile.am                     |   1 +
 src/expr/range.c                    | 288 ++++++++++++++++++++++++++++++++++++
 src/expr_ops.c                      |   2 +
 tests/Makefile.am                   |   4 +
 tests/nft-expr_range-test.c         | 109 ++++++++++++++
 tests/test-script.sh                |   1 +
 8 files changed, 441 insertions(+)
 create mode 100644 src/expr/range.c
 create mode 100644 tests/nft-expr_range-test.c
include/libnftnl/expr.h +7 -0
index 4ce2592b1b50..edf86a966fc0 100644
@@ -70,6 +70,13 @@ enum {
 };
 
 enum {
+	NFTNL_EXPR_RANGE_SREG	= NFTNL_EXPR_BASE,
+	NFTNL_EXPR_RANGE_OP,
+	NFTNL_EXPR_RANGE_FROM_DATA,
+	NFTNL_EXPR_RANGE_TO_DATA,
+};
+
+enum {
 	NFTNL_EXPR_IMM_DREG	= NFTNL_EXPR_BASE,
 	NFTNL_EXPR_IMM_DATA,
 	NFTNL_EXPR_IMM_VERDICT,
include/linux/netfilter/nf_tables.h +29 -0
index 681082e68130..30e3b21418c5 100644
@@ -546,6 +546,35 @@ enum nft_cmp_attributes {
 };
 #define NFTA_CMP_MAX		(__NFTA_CMP_MAX - 1)
 
+/**
+ * enum nft_range_ops - nf_tables range operator
+ *
+ * @NFT_RANGE_EQ: equal
+ * @NFT_RANGE_NEQ: not equal
+ */
+enum nft_range_ops {
+	NFT_RANGE_EQ,
+	NFT_RANGE_NEQ,
+};
+
+/**
+ * enum nft_range_attributes - nf_tables range expression netlink attributes
+ *
+ * @NFTA_RANGE_SREG: source register of data to compare (NLA_U32: nft_registers)
+ * @NFTA_RANGE_OP: cmp operation (NLA_U32: nft_cmp_ops)
+ * @NFTA_RANGE_FROM_DATA: data range from (NLA_NESTED: nft_data_attributes)
+ * @NFTA_RANGE_TO_DATA: data range to (NLA_NESTED: nft_data_attributes)
+ */
+enum nft_range_attributes {
+	NFTA_RANGE_UNSPEC,
+	NFTA_RANGE_SREG,
+	NFTA_RANGE_OP,
+	NFTA_RANGE_FROM_DATA,
+	NFTA_RANGE_TO_DATA,
+	__NFTA_RANGE_MAX
+};
+#define NFTA_RANGE_MAX         (__NFTA_RANGE_MAX - 1)
+
 enum nft_lookup_flags {
 	NFT_LOOKUP_F_INV = (1 << 0),
 };
src/Makefile.am +1 -0
index 4ab8fcaff5ce..eac7a5678009 100644
@@ -24,6 +24,7 @@ libnftnl_la_SOURCES = utils.c		\
 		      expr/bitwise.c	\
 		      expr/byteorder.c	\
 		      expr/cmp.c	\
+		      expr/range.c	\
 		      expr/counter.c	\
 		      expr/ct.c		\
 		      expr/data_reg.c	\
src/expr/range.c new file +288 -0

288 lines not on this page · raw message

src/expr_ops.c +2 -0
index 2a047d2bd18e..55748d64989a 100644
@@ -22,6 +22,7 @@ extern struct expr_ops expr_ops_meta;
 extern struct expr_ops expr_ops_ng;
 extern struct expr_ops expr_ops_nat;
 extern struct expr_ops expr_ops_payload;
+extern struct expr_ops expr_ops_range;
 extern struct expr_ops expr_ops_redir;
 extern struct expr_ops expr_ops_reject;
 extern struct expr_ops expr_ops_queue;
@@ -49,6 +50,7 @@ static struct expr_ops *expr_ops[] = {
 	&expr_ops_ng,
 	&expr_ops_nat,
 	&expr_ops_payload,
+	&expr_ops_range,
 	&expr_ops_redir,
 	&expr_ops_reject,
 	&expr_ops_queue,
tests/Makefile.am +4 -0
index 99d29746e179..d51895974406 100644
@@ -27,6 +27,7 @@ check_PROGRAMS = 	nft-parsing-test		\
 			nft-expr_nat-test		\
 			nft-expr_payload-test		\
 			nft-expr_queue-test		\
+			nft-expr_range-test             \
 			nft-expr_quota-test		\
 			nft-expr_redir-test		\
 			nft-expr_reject-test		\
@@ -108,6 +109,9 @@ nft_expr_queue_test_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS}
 nft_expr_quota_test_SOURCES = nft-expr_quota-test.c
 nft_expr_quota_test_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS}
 
+nft_expr_range_test_SOURCES = nft-expr_range-test.c
+nft_expr_range_test_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS}
+
 nft_expr_reject_test_SOURCES = nft-expr_reject-test.c
 nft_expr_reject_test_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS}
 
tests/nft-expr_range-test.c new file +109 -0

109 lines not on this page · raw message

tests/test-script.sh +1 -0
index 1c93e93df71c..3244f802e1cb 100755
@@ -16,6 +16,7 @@
 ./nft-expr_meta-test
 ./nft-expr_numgen-test
 ./nft-expr_queue-test
+./nft-expr_range-test
 ./nft-expr_redir-test
 ./nft-expr_nat-test
 ./nft-expr_payload-test
Signature · 1 line
2.1.4