Skip to contentSkip to conversation

netfilter: nf_tables: add last expression

PATCH Superseded Pablo Neira Ayuso 2 participants 3 messages Jun 3, 2021 – Jun 4, 2021

Subsystems (2)

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 1/1 netfilter: nf_tables: add last expression

Add a new optional expression that allows you to know when last match on a given rule / set element.

---
 include/uapi/linux/netfilter/nf_tables.h | 13 ++++
 net/netfilter/Kconfig                    |  6 ++
 net/netfilter/Makefile                   |  1 +
 net/netfilter/nft_last.c                 | 94 ++++++++++++++++++++++++
 4 files changed, 114 insertions(+)
 create mode 100644 net/netfilter/nft_last.c
include/uapi/linux/netfilter/nf_tables.h +13 -0
index 19715e2679d1..1c5814e3b2b2 100644
@@ -1195,6 +1195,19 @@ enum nft_counter_attributes {
 };
 #define NFTA_COUNTER_MAX	(__NFTA_COUNTER_MAX - 1)
 
+/**
+ * enum nft_last_attributes - nf_tables last expression netlink attributes
+ *
+ * @NFTA_LAST_MSECS: number of bytes (NLA_U64)
+ */
+enum nft_last_attributes {
+	NFTA_LAST_UNSPEC,
+	NFTA_LAST_MSECS,
+	NFTA_LAST_PAD,
+	__NFTA_LAST_MAX
+};
+#define NFTA_LAST_MAX	(__NFTA_LAST_MAX - 1)
+
 /**
  * enum nft_log_attributes - nf_tables log expression netlink attributes
  *
net/netfilter/Kconfig +6 -0
index 172d74560632..cf113cbfb69e 100644
@@ -509,6 +509,12 @@ config NFT_CONNLIMIT
 	  This option adds the "connlimit" expression that you can use to
 	  ratelimit rule matchings per connections.
 
+config NFT_LAST
+	tristate "Netfilter nf_tables last module"
+	help
+	  This option adds the "last" expression that you can use to know
+	  when this rule has matched last time.
+
 config NFT_LOG
 	tristate "Netfilter nf_tables log module"
 	help
net/netfilter/Makefile +1 -0
index e80e010354b1..60204c6542e7 100644
@@ -100,6 +100,7 @@ obj-$(CONFIG_NFT_REJECT_INET)	+= nft_reject_inet.o
 obj-$(CONFIG_NFT_REJECT_NETDEV)	+= nft_reject_netdev.o
 obj-$(CONFIG_NFT_TUNNEL)	+= nft_tunnel.o
 obj-$(CONFIG_NFT_COUNTER)	+= nft_counter.o
+obj-$(CONFIG_NFT_LAST)		+= nft_last.o
 obj-$(CONFIG_NFT_LOG)		+= nft_log.o
 obj-$(CONFIG_NFT_MASQ)		+= nft_masq.o
 obj-$(CONFIG_NFT_REDIR)		+= nft_redir.o
net/netfilter/nft_last.c new file +94 -0

94 lines not on this page · raw message

Signature · 1 line
2.20.1
maintainer
#1 lore raw
Quoted 2 lines · Pablo Neira Ayuso

Add a new optional expression that allows you to know when last match on a given rule / set element.

I think this is small enough to build this into nf_tables itself rather than a module.

author maintainer
#2 lore raw
Quoted 6 lines · Florian Westphal
Quoted 2 lines · Pablo Neira Ayuso

Add a new optional expression that allows you to know when last match on a given rule / set element.

I think this is small enough to build this into nf_tables itself rather than a module.

I'll make it built-in.