Skip to contentSkip to conversation

expr: nth: match every n packets

PATCH Superseded Laura Garcia Liebana 1 participant 1 message Jul 26, 2016 netfilter

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 expr: nth: match every n packets

Support for the nft nth expression within libnftnl.

---
 include/libnftnl/expr.h             |  10 ++
 include/linux/netfilter/nf_tables.h |  14 +++
 src/Makefile.am                     |   1 +
 src/expr/nth.c                      | 239 ++++++++++++++++++++++++++++++++++++
 src/expr_ops.c                      |   2 +
 5 files changed, 266 insertions(+)
 create mode 100644 src/expr/nth.c
include/libnftnl/expr.h +10 -0
index 17f60bd..6d245cd 100644
@@ -49,6 +49,11 @@ enum {
 };
 
 enum {
+	NFTNL_EXPR_NTH_DREG	= NFTNL_EXPR_BASE,
+	NFTNL_EXPR_NTH_DATA,
+};
+
+enum {
 	NFTNL_EXPR_META_KEY	= NFTNL_EXPR_BASE,
 	NFTNL_EXPR_META_DREG,
 	NFTNL_EXPR_META_SREG,
@@ -235,6 +240,11 @@ enum {
 };
 
 enum {
+	NFT_EXPR_NTH_DREG	= NFT_RULE_EXPR_ATTR_BASE,
+	NFT_EXPR_NTH_DATA,
+};
+
+enum {
 	NFT_EXPR_META_KEY	= NFT_RULE_EXPR_ATTR_BASE,
 	NFT_EXPR_META_DREG,
 	NFT_EXPR_META_SREG,
include/linux/netfilter/nf_tables.h +14 -0
index 01751fa..f90ef48 100644
@@ -667,6 +667,20 @@ enum nft_exthdr_attributes {
 #define NFTA_EXTHDR_MAX		(__NFTA_EXTHDR_MAX - 1)
 
 /**
+ * enum nft_nth_attributes - nf_tables nth expression attributes
+ *
+ * @NFTA_NTH_DREG: destination register (NLA_U32)
+ * @NFTA_NTH_DATA: data input (NLA_NESTED)
+ */
+enum nft_nth_attributes {
+	NFTA_NTH_UNSPEC,
+	NFTA_NTH_DREG,
+	NFTA_NTH_DATA,
+	__NFTA_NTH_MAX
+};
+#define NFTA_NTH_MAX		(__NFTA_NTH_MAX - 1)
+
+/**
  * enum nft_meta_keys - nf_tables meta expression keys
  *
  * @NFT_META_LEN: packet length (skb->len)
src/Makefile.am +1 -0
index 7e580e4..69b61ef 100644
@@ -38,6 +38,7 @@ libnftnl_la_SOURCES = utils.c		\
 		      expr/immediate.c	\
 		      expr/match.c	\
 		      expr/meta.c	\
+		      expr/nth.c	\
 		      expr/nat.c	\
 		      expr/payload.c	\
 		      expr/queue.c	\
src/expr/nth.c new file +239 -0

239 lines not on this page · raw message

src/expr_ops.c +2 -0
index ae515af..928bb5e 100644
@@ -19,6 +19,7 @@ extern struct expr_ops expr_ops_lookup;
 extern struct expr_ops expr_ops_masq;
 extern struct expr_ops expr_ops_match;
 extern struct expr_ops expr_ops_meta;
+extern struct expr_ops expr_ops_nth;
 extern struct expr_ops expr_ops_nat;
 extern struct expr_ops expr_ops_payload;
 extern struct expr_ops expr_ops_redir;
@@ -43,6 +44,7 @@ static struct expr_ops *expr_ops[] = {
 	&expr_ops_masq,
 	&expr_ops_match,
 	&expr_ops_meta,
+	&expr_ops_nth,
 	&expr_ops_nat,
 	&expr_ops_payload,
 	&expr_ops_redir,
Signature · 1 line
2.8.1