netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH nf-next,v2] netfilter: nf_tables: add last expression
@ 2021-06-07 10:07 Pablo Neira Ayuso
  2021-06-07 16:10 ` kernel test robot
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Pablo Neira Ayuso @ 2021-06-07 10:07 UTC (permalink / raw)
  To: netfilter-devel

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

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
v2: no Kconfig, make it built-in per Florian.
    fix incorrect documentation
    remove #include seqlock.h

 include/uapi/linux/netfilter/nf_tables.h | 13 ++++
 net/netfilter/Makefile                   |  2 +-
 net/netfilter/nft_last.c                 | 93 ++++++++++++++++++++++++
 3 files changed, 107 insertions(+), 1 deletion(-)
 create mode 100644 net/netfilter/nft_last.c

diff --git a/include/uapi/linux/netfilter/nf_tables.h b/include/uapi/linux/netfilter/nf_tables.h
index 19715e2679d1..5beb5a807687 100644
--- a/include/uapi/linux/netfilter/nf_tables.h
+++ b/include/uapi/linux/netfilter/nf_tables.h
@@ -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: milliseconds since last update (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
  *
diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
index e80e010354b1..f321ee469ca4 100644
--- a/net/netfilter/Makefile
+++ b/net/netfilter/Makefile
@@ -73,7 +73,7 @@ obj-$(CONFIG_NF_DUP_NETDEV)	+= nf_dup_netdev.o
 nf_tables-objs := nf_tables_core.o nf_tables_api.o nft_chain_filter.o \
 		  nf_tables_trace.o nft_immediate.o nft_cmp.o nft_range.o \
 		  nft_bitwise.o nft_byteorder.o nft_payload.o nft_lookup.o \
-		  nft_dynset.o nft_meta.o nft_rt.o nft_exthdr.o \
+		  nft_dynset.o nft_meta.o nft_rt.o nft_exthdr.o nft_last.o \
 		  nft_chain_route.o nf_tables_offload.o \
 		  nft_set_hash.o nft_set_bitmap.o nft_set_rbtree.o \
 		  nft_set_pipapo.o
diff --git a/net/netfilter/nft_last.c b/net/netfilter/nft_last.c
new file mode 100644
index 000000000000..2ab4b030dcf9
--- /dev/null
+++ b/net/netfilter/nft_last.c
@@ -0,0 +1,93 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/netlink.h>
+#include <linux/netfilter.h>
+#include <linux/netfilter/nf_tables.h>
+#include <net/netfilter/nf_tables.h>
+
+struct nft_last_priv {
+	unsigned long last_jiffies;
+};
+
+static const struct nla_policy nft_last_policy[NFTA_LAST_MAX + 1] = {
+	[NFTA_LAST_MSECS] = { .type = NLA_U64 },
+};
+
+static int nft_last_init(const struct nft_ctx *ctx, const struct nft_expr *expr,
+			 const struct nlattr * const tb[])
+{
+	struct nft_last_priv *priv = nft_expr_priv(expr);
+	u64 last;
+	int err;
+
+	if (tb[NFTA_LAST_MSECS]) {
+		err = nf_msecs_to_jiffies64(tb[NFTA_LAST_MSECS], &last);
+		if (err < 0)
+			return err;
+
+		priv->last_jiffies = (unsigned long)last;
+	}
+
+	return 0;
+}
+
+static void nft_last_eval(const struct nft_expr *expr,
+			  struct nft_regs *regs, const struct nft_pktinfo *pkt)
+{
+	struct nft_last_priv *priv = nft_expr_priv(expr);
+
+	priv->last_jiffies = jiffies;
+}
+
+static int nft_last_dump(struct sk_buff *skb, const struct nft_expr *expr)
+{
+	struct nft_last_priv *priv = nft_expr_priv(expr);
+
+	if (nla_put_be64(skb, NFTA_LAST_MSECS,
+			 nf_jiffies64_to_msecs(priv->last_jiffies),
+			 NFTA_LAST_PAD))
+		goto nla_put_failure;
+
+	return 0;
+
+nla_put_failure:
+	return -1;
+}
+
+static struct nft_expr_type nft_last_type;
+static const struct nft_expr_ops nft_last_ops = {
+	.type		= &nft_last_type,
+	.size		= NFT_EXPR_SIZE(sizeof(struct nft_last_priv)),
+	.eval		= nft_last_eval,
+	.init		= nft_last_init,
+	.dump		= nft_last_dump,
+};
+
+static struct nft_expr_type nft_last_type __read_mostly = {
+	.name		= "last",
+	.ops		= &nft_last_ops,
+	.policy		= nft_last_policy,
+	.maxattr	= NFTA_LAST_MAX,
+	.flags		= NFT_EXPR_STATEFUL,
+	.owner		= THIS_MODULE,
+};
+
+static int __init nft_last_module_init(void)
+{
+	return nft_register_expr(&nft_last_type);
+}
+
+static void __exit nft_last_module_exit(void)
+{
+	nft_unregister_expr(&nft_last_type);
+}
+
+module_init(nft_last_module_init);
+module_exit(nft_last_module_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Pablo Neira Ayuso <pablo@netfilter.org>");
+MODULE_ALIAS_NFT_EXPR("last");
+MODULE_DESCRIPTION("nftables last expression support");
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH nf-next,v2] netfilter: nf_tables: add last expression
  2021-06-07 10:07 [PATCH nf-next,v2] netfilter: nf_tables: add last expression Pablo Neira Ayuso
@ 2021-06-07 16:10 ` kernel test robot
  2021-06-07 18:49 ` kernel test robot
  2021-06-07 20:39 ` kernel test robot
  2 siblings, 0 replies; 4+ messages in thread
From: kernel test robot @ 2021-06-07 16:10 UTC (permalink / raw)
  To: Pablo Neira Ayuso, netfilter-devel; +Cc: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 2029 bytes --]

Hi Pablo,

I love your patch! Yet something to improve:

[auto build test ERROR on nf/master]
[also build test ERROR on nf-next/master v5.13-rc5 next-20210607]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Pablo-Neira-Ayuso/netfilter-nf_tables-add-last-expression/20210607-180754
base:   https://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git master
config: nios2-randconfig-c023-20210607 (attached as .config)
compiler: nios2-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/b2cb4b60adb3205aad6e4a0637fff3220420dcf0
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Pablo-Neira-Ayuso/netfilter-nf_tables-add-last-expression/20210607-180754
        git checkout b2cb4b60adb3205aad6e4a0637fff3220420dcf0
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=nios2 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   nios2-linux-ld: net/netfilter/nft_last.o: in function `nft_last_module_init':
>> nft_last.c:(.init.text+0x0): multiple definition of `init_module'; net/netfilter/nf_tables_api.o:nf_tables_api.c:(.init.text+0x0): first defined here
   nios2-linux-ld: net/netfilter/nft_last.o: in function `nft_last_module_exit':
>> nft_last.c:(.exit.text+0x0): multiple definition of `cleanup_module'; net/netfilter/nf_tables_api.o:nf_tables_api.c:(.exit.text+0x0): first defined here

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 34965 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH nf-next,v2] netfilter: nf_tables: add last expression
  2021-06-07 10:07 [PATCH nf-next,v2] netfilter: nf_tables: add last expression Pablo Neira Ayuso
  2021-06-07 16:10 ` kernel test robot
@ 2021-06-07 18:49 ` kernel test robot
  2021-06-07 20:39 ` kernel test robot
  2 siblings, 0 replies; 4+ messages in thread
From: kernel test robot @ 2021-06-07 18:49 UTC (permalink / raw)
  To: Pablo Neira Ayuso, netfilter-devel; +Cc: kbuild-all, clang-built-linux

[-- Attachment #1: Type: text/plain, Size: 2035 bytes --]

Hi Pablo,

I love your patch! Yet something to improve:

[auto build test ERROR on nf/master]
[also build test ERROR on nf-next/master v5.13-rc5 next-20210607]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Pablo-Neira-Ayuso/netfilter-nf_tables-add-last-expression/20210607-180754
base:   https://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git master
config: x86_64-randconfig-a006-20210607 (attached as .config)
compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project ae973380c5f6be77ce395022be40350942260be9)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install x86_64 cross compiling tool for clang build
        # apt-get install binutils-x86-64-linux-gnu
        # https://github.com/0day-ci/linux/commit/b2cb4b60adb3205aad6e4a0637fff3220420dcf0
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Pablo-Neira-Ayuso/netfilter-nf_tables-add-last-expression/20210607-180754
        git checkout b2cb4b60adb3205aad6e4a0637fff3220420dcf0
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

>> ld.lld: error: duplicate symbol: cleanup_module
   >>> defined at nf_tables_api.c:9761 (net/netfilter/nf_tables_api.c:9761)
   >>> net/netfilter/nf_tables_api.o:(cleanup_module)
   >>> defined at nft_last.c:83 (net/netfilter/nft_last.c:83)
   >>> net/netfilter/nft_last.o:(.exit.text+0x0)

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 38014 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH nf-next,v2] netfilter: nf_tables: add last expression
  2021-06-07 10:07 [PATCH nf-next,v2] netfilter: nf_tables: add last expression Pablo Neira Ayuso
  2021-06-07 16:10 ` kernel test robot
  2021-06-07 18:49 ` kernel test robot
@ 2021-06-07 20:39 ` kernel test robot
  2 siblings, 0 replies; 4+ messages in thread
From: kernel test robot @ 2021-06-07 20:39 UTC (permalink / raw)
  To: Pablo Neira Ayuso, netfilter-devel; +Cc: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 2110 bytes --]

Hi Pablo,

I love your patch! Yet something to improve:

[auto build test ERROR on nf/master]
[also build test ERROR on nf-next/master v5.13-rc5 next-20210607]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Pablo-Neira-Ayuso/netfilter-nf_tables-add-last-expression/20210607-180754
base:   https://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git master
config: x86_64-rhel-8.3-kselftests (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce (this is a W=1 build):
        # https://github.com/0day-ci/linux/commit/b2cb4b60adb3205aad6e4a0637fff3220420dcf0
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Pablo-Neira-Ayuso/netfilter-nf_tables-add-last-expression/20210607-180754
        git checkout b2cb4b60adb3205aad6e4a0637fff3220420dcf0
        # save the attached .config to linux build tree
        make W=1 ARCH=x86_64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   ld: net/netfilter/nft_last.o: in function `nft_last_module_init':
>> net/netfilter/nft_last.c:78: multiple definition of `init_module'; net/netfilter/nf_tables_api.o:net/netfilter/nf_tables_api.c:9703: first defined here
   ld: net/netfilter/nft_last.o: in function `nft_last_module_exit':
>> net/netfilter/nft_last.c:84: multiple definition of `cleanup_module'; net/netfilter/nf_tables_api.o:net/netfilter/nf_tables_api.c:9762: first defined here


vim +78 net/netfilter/nft_last.c

    76	
    77	static int __init nft_last_module_init(void)
  > 78	{
    79		return nft_register_expr(&nft_last_type);
    80	}
    81	
    82	static void __exit nft_last_module_exit(void)
    83	{
  > 84		nft_unregister_expr(&nft_last_type);
    85	}
    86	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 41786 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-06-07 20:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-06-07 10:07 [PATCH nf-next,v2] netfilter: nf_tables: add last expression Pablo Neira Ayuso
2021-06-07 16:10 ` kernel test robot
2021-06-07 18:49 ` kernel test robot
2021-06-07 20:39 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).