netfilter: nf_tables: add last expression
Subsystems (2)
Pablo Neira Ayuso
maintainerPATCH v4 1/1 netfilter: nf_tables: add last expression
Add a new optional expression that tells you when last matching on a given rule / set element element has happened.
---
- add NFTA_LAST_SET that specifies if the timestamp has been updated
- provide delta between jiffies and last timestamp to userspace
- allow to restore last timestamp
include/net/netfilter/nf_tables_core.h | 1 + include/uapi/linux/netfilter/nf_tables.h | 15 +++++ net/netfilter/Makefile | 2 +- net/netfilter/nf_tables_core.c | 1 + net/netfilter/nft_last.c | 84 ++++++++++++++++++++++++ 5 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 net/netfilter/nft_last.c
include/net/netfilter/nf_tables_core.h +1 -0
@@ -16,6 +16,7 @@ extern struct nft_expr_type nft_range_type;extern struct nft_expr_type nft_meta_type;extern struct nft_expr_type nft_rt_type;extern struct nft_expr_type nft_exthdr_type; +extern struct nft_expr_type nft_last_type;#ifdef CONFIG_NETWORK_SECMARK extern struct nft_object_type nft_secmark_obj_type;
include/uapi/linux/netfilter/nf_tables.h +15 -0
@@ -1195,6 +1195,21 @@ enum nft_counter_attributes { };#define NFTA_COUNTER_MAX (__NFTA_COUNTER_MAX - 1) +/** +* enum nft_last_attributes - nf_tables last expression netlink attributes +* +* @NFTA_LAST_SET: last update has been set, zero means never updated (NLA_U32) +* @NFTA_LAST_MSECS: milliseconds since last update (NLA_U64) +*/ +enum nft_last_attributes { +NFTA_LAST_UNSPEC , +NFTA_LAST_SET , +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/Makefile +1 -1
@@ -74,7 +74,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
net/netfilter/nf_tables_core.c +1 -0
@@ -268,6 +268,7 @@ static struct nft_expr_type *nft_basic_types[] = { &nft_meta_type, &nft_rt_type, &nft_exthdr_type, + &nft_last_type, }; static struct nft_object_type *nft_basic_objects[] = {
net/netfilter/nft_last.c new file +84 -0
84 lines not on this page · raw message
Signature · 1 line
2.30.2
kernel test robot
build botI love your patch! Perhaps something to improve:
Hi Pablo,
I love your patch! Perhaps something to improve:
[auto build test WARNING on nf/master]
[also build test WARNING on nf-next/master v5.13-rc6 next-20210616] [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/20210617-021223 base: https://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git master config: i386-randconfig-s001-20210615 (attached as .config) compiler: gcc-9 (Debian 9.3.0-22) 9.3.0 reproduce: # apt-get install sparse # sparse version: v0.6.3-341-g8af24329-dirty # https://github.com/0day-ci/linux/commit/12cfd8daf813a3f62294bdbe915c1d2cd6946a30 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/20210617-021223 git checkout 12cfd8daf813a3f62294bdbe915c1d2cd6946a30 # save the attached .config to linux build tree make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' W=1 ARCH=i386
If you fix the issue, kindly add following tag as appropriate
sparse warnings: (new ones prefixed by >>)
>> net/netfilter/nft_last.c:59:46: sparse: sparse: incorrect type in argument 3 (different base types) @@ expected restricted __be32 [usertype] value @@ got restricted __be16 [usertype] @@
net/netfilter/nft_last.c:59:46: sparse: expected restricted __be32 [usertype] value
net/netfilter/nft_last.c:59:46: sparse: got restricted __be16 [usertype]
vim +59 net/netfilter/nft_last.c
48
49 static int nft_last_dump(struct sk_buff *skb, const struct nft_expr *expr)
50 {
51 struct nft_last_priv *priv = nft_expr_priv(expr);
52 __be64 msecs;
53
54 if (priv->last_set)
55 msecs = nf_jiffies64_to_msecs(jiffies - priv->last_jiffies);
56 else
57 msecs = 0;
58
> 59 if (nla_put_be32(skb, NFTA_LAST_SET, htons(priv->last_set)) ||
60 nla_put_be64(skb, NFTA_LAST_MSECS, msecs, NFTA_LAST_PAD))
61 goto nla_put_failure;
62
63 return 0;
64
65 nla_put_failure:
66 return -1;
67 }
68 ---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org