netfilter: nf_tables: add math expression support
Subsystems (2)
PATCH v5 1/1 netfilter: nf_tables: add math expression support
Historically, users have requested support for increasing and decreasing TTL value in nftables in order to migrate from iptables.
Following the nftables spirit of flexible and multipurpose expressions, this patch introduces "nft_math" expression. This expression allows to increase and decrease values stored in the register.
The math expression intends to be flexible enough in case it needs to be extended in the future, e.g implement non-contiguous bitfields operations. But for now, non-contiguous payloads are not supported.
When loading a u8 or u16 payload into a register we don't know if the value is stored at least significant byte or most significant byte. In order to handle such cases, introduce a bitmask indicating what is the target bit and also use it to handle limits to prevent overflow or underflow. Keep in mind that math expression expects that the sreg and dreg are in host byteorder, so the user must use nft_byteorder expressions as needed.
This implementation comes with a libnftnl patch that allows the user to generate the following example bytecodes:
- Bytecode to increase the TTL of a packet
table filter inet flags 0 use 1 handle 1
inet filter input use 1 type filter hook input prio 0 policy accept packets 0 bytes 0 flags 1 inet filter input 4
[ payload load 2b @ network header + 8 => reg 1 ]
[ math mask 0x000000ff reg 1 + 1 => 1]
[ payload write reg 1 => 2b @ network header + 8 csum_type 1 csum_off 10 csum_flags 0x0 ]
- Bytecode to decrease the TTL of a packet
table filter inet flags 0 use 1 handle 1
inet filter input use 1 type filter hook input prio 0 policy accept packets 0 bytes 0 flags 1 inet filter input 4
[ payload load 2b @ network header + 8 => reg 1 ]
[ math mask 0x000000ff reg 1 - 1 => 1]
[ payload write reg 1 => 2b @ network header + 8 csum_type 1 csum_off 10 csum_flags 0x0 ]
- Bytecode to increase the meta mark of a packet
table mangle inet flags 0 use 1 handle 6
inet mangle output use 1 type filter hook output prio 0 policy accept packets 0 bytes 0 flags 1 inet mangle output 2
[ meta load mark => reg 1 ]
[ math mask 0xffffffff reg 1 + 1 => 1]
[ meta set mark with reg 1 ]
---
v2: dropped the byteorder netlink attribute, added bitmask to handle LSB/MSB when dealing with u8 and u16, simplified eval logic. I've kept nft_math as module, IMHO it would be too much to make it built-in.
v3: fixed checkpatch warnings, improved Kconfig description and fixed a wrong EINVAL return.
v4: removed NFTA_MATH_LEN as discussed with Phil, added a non-contiguous bitmask check
v5: fixed check on op max value, fixed byteorder inconsistency now NLA_U32 for both BITMASK and OP attributes
--- include/uapi/linux/netfilter/nf_tables.h | 25 ++++ net/netfilter/Kconfig | 9 ++ net/netfilter/Makefile | 1 + net/netfilter/nft_math.c | 157 +++++++++++++++++++++++ 4 files changed, 192 insertions(+) create mode 100644 net/netfilter/nft_math.c
include/uapi/linux/netfilter/nf_tables.h +25 -0
@@ -2019,4 +2019,29 @@ enum nft_tunnel_attributes { };#define NFTA_TUNNEL_MAX (__NFTA_TUNNEL_MAX - 1) +/** +* enum nft_math_attributes - nftables math expression netlink attributes +* +* @NFTA_MATH_SREG: source register (NLA_U32: nft_registers) +* @NFTA_MATH_DREG: destination register (NLA_U32: nft_registers) +* @NFTA_MATH_OP: operation to be performed (NLA_U32) +* @NFTA_MATH_BITMASK: bitmask to be applied on the operation (NLA_U32) +*/ +enum nft_math_attributes { +NFTA_MATH_UNSPEC , +NFTA_MATH_SREG , +NFTA_MATH_DREG , +NFTA_MATH_OP , +NFTA_MATH_BITMASK , + __NFTA_MATH_MAX, +}; +#define NFTA_MATH_MAX (__NFTA_MATH_MAX - 1) + +enum nft_math_op { +NFT_MATH_OP_INC , +NFT_MATH_OP_DEC , + __NFT_MATH_OP_MAX, +}; +#define NFT_MATH_OP_MAX (__NFT_MATH_OP_MAX - 1) +#endif /* _LINUX_NF_TABLES_H */
net/netfilter/Kconfig +9 -0
@@ -667,6 +667,15 @@ config NFT_SYNPROXY server. This allows to avoid conntrack and server resource usage during SYN-flood attacks. +config NFT_MATH + tristate "Netfilter nf_tables math expression support" + depends on NETFILTER_ADVANCED + help + This option enables support for the nftables math expression. + It allows arithmetic operations to be performed on nft registers + content, such as incrementing or decrementing values. Math + expressions can be used in nftables rules to modify packet fields. + if NF_TABLES_NETDEV config NF_DUP_NETDEV
net/netfilter/Makefile +1 -0
@@ -131,6 +131,7 @@ obj-$(CONFIG_NFT_OSF) += nft_osf.o obj-$(CONFIG_NFT_TPROXY) += nft_tproxy.o obj-$(CONFIG_NFT_XFRM) += nft_xfrm.o obj-$(CONFIG_NFT_SYNPROXY) += nft_synproxy.o +obj-$(CONFIG_NFT_MATH) += nft_math.o obj-$(CONFIG_NFT_NAT) += nft_chain_nat.o
net/netfilter/nft_math.c new file +157 -0
157 lines not on this page · raw message
Signature · 1 line
2.53.0
kernel test robot
build botkernel test robot noticed the following build errors:
Hi Fernando,
kernel test robot noticed the following build errors:
[auto build test ERROR on nf-next/master]
url: https://github.com/intel-lab-lkp/linux/commits/Fernando-Fernandez-Mancera/netfilter-nf_tables-add-math-expression-support/20260424-055358 base: https://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf-next.git master patch link: https://lore.kernel.org/r/20260421155859.7049-2-fmancera%40suse.de patch subject: [PATCH nf-next v5] netfilter: nf_tables: add math expression support config: nios2-allmodconfig (https://download.01.org/0day-ci/archive/20260426/[email protected]/config) compiler: nios2-linux-gcc (GCC) 11.5.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260426/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All error/warnings (new ones prefixed by >>):
net/netfilter/nft_math.c: In function 'nft_math_eval_bitmask':
net/netfilter/nft_math.c:49:17: error: implicit declaration of function 'DEBUG_NET_WARN_ONCE'; did you mean 'DEBUG_NET_WARN_ON_ONCE'? [-Werror=implicit-function-declaration]
49 | DEBUG_NET_WARN_ONCE(true, "unknown operation path in nft_math");
| ^~~~~~~~~~~~~~~~~~~
| DEBUG_NET_WARN_ON_ONCE
net/netfilter/nft_math.c: In function 'nft_math_init':
net/netfilter/nft_math.c:95:39: error: passing argument 1 of 'nft_parse_register_load' from incompatible pointer type [-Werror=incompatible-pointer-types]
95 | err = nft_parse_register_load(ctx, tb[NFTA_MATH_SREG], &priv->sreg,
| ^~~
| |
| const struct nft_ctx *
In file included from net/netfilter/nft_math.c:4:
include/net/netfilter/nf_tables.h:235:50: note: expected 'const struct nlattr *' but argument is of type 'const struct nft_ctx *'
235 | int nft_parse_register_load(const struct nlattr *attr, u8 *sreg, u32 len);
| ~~~~~~~~~~~~~~~~~~~~~^~~~
net/netfilter/nft_math.c:95:46: error: passing argument 2 of 'nft_parse_register_load' from incompatible pointer type [-Werror=incompatible-pointer-types]
95 | err = nft_parse_register_load(ctx, tb[NFTA_MATH_SREG], &priv->sreg,
| ~~^~~~~~~~~~~~~~~~
| |
| const struct nlattr *
In file included from net/netfilter/nft_math.c:4:
include/net/netfilter/nf_tables.h:235:60: note: expected 'u8 *' {aka 'unsigned char *'} but argument is of type 'const struct nlattr *'
235 | int nft_parse_register_load(const struct nlattr *attr, u8 *sreg, u32 len);
| ~~~~^~~~
>> net/netfilter/nft_math.c:95:64: warning: passing argument 3 of 'nft_parse_register_load' makes integer from pointer without a cast [-Wint-conversion]
95 | err = nft_parse_register_load(ctx, tb[NFTA_MATH_SREG], &priv->sreg,
| ^~~~~~~~~~~
| |
| u8 * {aka unsigned char *}
In file included from net/netfilter/nft_math.c:4:
include/net/netfilter/nf_tables.h:235:70: note: expected 'u32' {aka 'unsigned int'} but argument is of type 'u8 *' {aka 'unsigned char *'}
235 | int nft_parse_register_load(const struct nlattr *attr, u8 *sreg, u32 len);
| ~~~~^~~
>> net/netfilter/nft_math.c:95:15: error: too many arguments to function 'nft_parse_register_load'
95 | err = nft_parse_register_load(ctx, tb[NFTA_MATH_SREG], &priv->sreg,
| ^~~~~~~~~~~~~~~~~~~~~~~
In file included from net/netfilter/nft_math.c:4:
include/net/netfilter/nf_tables.h:235:5: note: declared here
235 | int nft_parse_register_load(const struct nlattr *attr, u8 *sreg, u32 len);
| ^~~~~~~~~~~~~~~~~~~~~~~ net/netfilter/nft_math.c: At top level:
net/netfilter/nft_math.c:129:27: error: initialization of 'int (*)(struct sk_buff *, const struct nft_expr *)' from incompatible pointer type 'int (*)(struct sk_buff *, const struct nft_expr *, bool)' {aka 'int (*)(struct sk_buff *, const struct nft_expr *, _Bool)'} [-Werror=incompatible-pointer-types]
129 | .dump = nft_math_dump,
| ^~~~~~~~~~~~~
net/netfilter/nft_math.c:129:27: note: (near initialization for 'nft_math_op.dump')
cc1: some warnings being treated as errors
vim +/nft_parse_register_load +95 net/netfilter/nft_math.c
65
66 static int nft_math_init(const struct nft_ctx *ctx,
67 const struct nft_expr *expr,
68 const struct nlattr * const tb[])
69 {
70 struct nft_math *priv = nft_expr_priv(expr);
71 u32 bitmask_check;
72 int err;
73 u32 op;
74
75 if (!tb[NFTA_MATH_SREG] ||
76 !tb[NFTA_MATH_DREG] ||
77 !tb[NFTA_MATH_BITMASK] ||
78 !tb[NFTA_MATH_OP])
79 return -EINVAL;
80
81 op = nla_get_u32(tb[NFTA_MATH_OP]);
82 if (op > NFT_MATH_OP_MAX)
83 return -EOPNOTSUPP;
84 priv->op = op;
85
86 priv->bitmask = nla_get_u32(tb[NFTA_MATH_BITMASK]);
87 if (!priv->bitmask)
88 return -EINVAL;
89
90 /* check if the bitmask is contiguous, otherwise reject it */
91 bitmask_check = priv->bitmask + (priv->bitmask & -priv->bitmask);
92 if (bitmask_check & (bitmask_check - 1))
93 return -EINVAL;
94
> 95 err = nft_parse_register_load(ctx, tb[NFTA_MATH_SREG], &priv->sreg,
96 sizeof(u32));
97 if (err < 0)
98 return err;
99 100 return nft_parse_register_store(ctx, tb[NFTA_MATH_DREG],
101 &priv->dreg, NULL, NFT_DATA_VALUE,
102 sizeof(u32));
103 }
104
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Quoted 14 lines · kernel test robot
Hi Fernando,
kernel test robot noticed the following build errors:
[auto build test ERROR on nf-next/master]
url: https://github.com/intel-lab-lkp/linux/commits/Fernando-Fernandez-Mancera/netfilter-nf_tables-add-math-expression-support/20260424-055358 base: https://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf-next.git master patch link: https://lore.kernel.org/r/20260421155859.7049-2-fmancera%40suse.de patch subject: [PATCH nf-next v5] netfilter: nf_tables: add math expression support config: nios2-allmodconfig (https://download.01.org/0day-ci/archive/20260426/[email protected]/config) compiler: nios2-linux-gcc (GCC) 11.5.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260426/[email protected]/reproduce)
Quoted 5 lines
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
I am completely lost here. How is this happening? I do not see any of these errors locally with W=1.
Quoted 13 lines
All error/warnings (new ones prefixed by >>):
net/netfilter/nft_math.c: In function 'nft_math_eval_bitmask':
net/netfilter/nft_math.c:49:17: error: implicit declaration of function 'DEBUG_NET_WARN_ONCE'; did you mean 'DEBUG_NET_WARN_ON_ONCE'? [-Werror=implicit-function-declaration]
49 |DEBUG_NET_WARN_ONCE(true, "unknown operation path in nft_math");
| ^~~~~~~~~~~~~~~~~~~
|DEBUG_NET_WARN_ON_ONCE
net/netfilter/nft_math.c: In function 'nft_math_init':
net/netfilter/nft_math.c:95:39: error: passing argument 1 of 'nft_parse_register_load' from incompatible pointer type [-Werror=incompatible-pointer-types]
95 | err = nft_parse_register_load(ctx, tb[NFTA_MATH_SREG],&priv->sreg,
| ^~~
| |
| const structnft_ctx*
What? But I see:
int nft_parse_register_load(const struct nft_ctx *ctx,
const struct nlattr *attr, u8 *sreg, u32 len);
Is this a bogus report?
Quoted 80 lines
In file included from
net/netfilter/nft_math.c:4:
include/net/netfilter/nf_tables.h:235:50: note: expected 'const struct nlattr *' but argument is of type 'const structnft_ctx*'
235 | intnft_parse_register_load(const struct nlattr *attr, u8 *sreg, u32 len);
| ~~~~~~~~~~~~~~~~~~~~~^~~~
net/netfilter/nft_math.c:95:46: error: passing argument 2 of 'nft_parse_register_load' from incompatible pointer type [-Werror=incompatible-pointer-types]
95 | err = nft_parse_register_load(ctx, tb[NFTA_MATH_SREG],&priv->sreg,
| ~~^~~~~~~~~~~~~~~~
| |
| const struct nlattr *
In file included fromnet/netfilter/nft_math.c:4:
include/net/netfilter/nf_tables.h:235:60: note: expected 'u8 *' {aka 'unsigned char *'} but argument is of type 'const struct nlattr *'
235 | intnft_parse_register_load(const struct nlattr *attr, u8 *sreg, u32 len);
| ~~~~^~~~Quoted 1 line
Quoted 1 line
net/netfilter/nft_math.c:95:64: warning: passing argument 3 of 'nft_parse_register_load' makes integer from pointer without a cast [-Wint-conversion]95 | err = nft_parse_register_load(ctx, tb[NFTA_MATH_SREG], &priv->sreg, | ^~~~~~~~~~~ | | | u8 * {aka unsigned char *} In file included from net/netfilter/nft_math.c:4: include/net/netfilter/nf_tables.h:235:70: note: expected 'u32' {aka 'unsigned int'} but argument is of type 'u8 *' {aka 'unsigned char *'} 235 | int nft_parse_register_load(const struct nlattr *attr, u8 *sreg, u32 len); | ~~~~^~~Quoted 1 line
Quoted 1 line
net/netfilter/nft_math.c:95:15: error: too many arguments to function 'nft_parse_register_load'95 | err = nft_parse_register_load(ctx, tb[NFTA_MATH_SREG],
&priv->sreg,
| ^~~~~~~~~~~~~~~~~~~~~~~
In file included fromnet/netfilter/nft_math.c:4:
include/net/netfilter/nf_tables.h:235:5: note: declared here
235 | intnft_parse_register_load(const struct nlattr *attr, u8 *sreg, u32 len);
| ^~~~~~~~~~~~~~~~~~~~~~~
net/netfilter/nft_math.c: At top level:
net/netfilter/nft_math.c:129:27: error: initialization of 'int (*)(structsk_buff*, const structnft_expr*)' from incompatible pointer type 'int (*)(structsk_buff*, const structnft_expr*, bool)' {aka 'int (*)(structsk_buff*, const structnft_expr*,_Bool)'} [-Werror=incompatible-pointer-types]
129 | .dump =nft_math_dump,
| ^~~~~~~~~~~~~
net/netfilter/nft_math.c:129:27: note: (near initialization for 'nft_math_op.dump')
cc1: some warnings being treated as errorsvim +/nft_parse_register_load +95
net/netfilter/nft_math.c65 66 static int nft_math_init(const struct nft_ctx *ctx, 67 const struct nft_expr *expr, 68 const struct nlattr * const tb[]) 69 { 70 struct nft_math *priv = nft_expr_priv(expr); 71 u32 bitmask_check; 72 int err; 73 u32 op; 74 75 if (!tb[NFTA_MATH_SREG] || 76 !tb[NFTA_MATH_DREG] || 77 !tb[NFTA_MATH_BITMASK] || 78 !tb[NFTA_MATH_OP]) 79 return -EINVAL; 80 81 op = nla_get_u32(tb[NFTA_MATH_OP]); 82 if (op > NFT_MATH_OP_MAX) 83 return -EOPNOTSUPP; 84 priv->op = op; 85 86 priv->bitmask = nla_get_u32(tb[NFTA_MATH_BITMASK]); 87 if (!priv->bitmask) 88 return -EINVAL; 89 90 /* check if the bitmask is contiguous, otherwise reject it */ 91 bitmask_check = priv->bitmask + (priv->bitmask & -priv->bitmask); 92 if (bitmask_check & (bitmask_check - 1)) 93 return -EINVAL; 94Quoted 1 line
95 err = nft_parse_register_load(ctx, tb[NFTA_MATH_SREG],
&priv->sreg,96 sizeof(u32)); 97 if (err < 0) 98 return err; 99 100 return nft_parse_register_store(ctx, tb[NFTA_MATH_DREG], 101 &priv->dreg, NULL, NFT_DATA_VALUE, 102 sizeof(u32)); 103 } 104
Florian Westphal
maintainerQuoted 9 lines · Fernando Fernandez Mancera
Quoted 8 lines · kernel test robot
Hi Fernando,
kernel test robot noticed the following build errors:
[auto build test ERROR on nf-next/master]
url: https://github.com/intel-lab-lkp/linux/commits/Fernando-Fernandez-Mancera/netfilter-nf_tables-add-math-expression-support/20260424-055358 base: https://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf-next.git master
~~~~~~
Quoted 6 lines
Quoted 3 lines
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/I am completely lost here. How is this happening? I do not see any of these errors locally with W=1.
Sure, you use main, not master. I'll remove master from the repository, hopefully that will stop future reports like this.
Quoted 6 lines
What? But I see:
int nft_parse_register_load(const struct
nft_ctx*ctx,const struct nlattr *attr, u8 *sreg, u32 len);Is this a bogus report?
Yes, wrong branch.
Quoted 17 lines · Florian Westphal
Quoted 9 lines · Fernando Fernandez Mancera
Quoted 8 lines · kernel test robot
Hi Fernando,
kernel test robot noticed the following build errors:
[auto build test ERROR on nf-next/master]
url: https://github.com/intel-lab-lkp/linux/commits/Fernando-Fernandez-Mancera/netfilter-nf_tables-add-math-expression-support/20260424-055358 base: https://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf-next.git master~~~~~~Quoted 4 lines
Quoted 3 lines
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
Quoted 5 lines
Quoted 2 lines
I am completely lost here. How is this happening? I do not see any of these errors locally with W=1.
Sure, you use main, not master. I'll remove master from the repository, hopefully that will stop future reports like this.
Sorry for the wrong report, this is the issue of the bot, the base candidate is configured as master. Now i have corrected it to be main branch.
Quoted 10 lines
Quoted 7 lines
What? But I see:
int nft_parse_register_load(const struct
nft_ctx*ctx,const struct nlattr *attr, u8 *sreg, u32 len);Is this a bogus report?
Yes, wrong branch.
kernel test robot
build botkernel test robot noticed the following build errors:
Hi Fernando,
kernel test robot noticed the following build errors:
[auto build test ERROR on nf-next/master]
url: https://github.com/intel-lab-lkp/linux/commits/Fernando-Fernandez-Mancera/netfilter-nf_tables-add-math-expression-support/20260424-055358 base: https://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf-next.git master patch link: https://lore.kernel.org/r/20260421155859.7049-2-fmancera%40suse.de patch subject: [PATCH nf-next v5] netfilter: nf_tables: add math expression support config: m68k-allmodconfig (https://download.01.org/0day-ci/archive/20260505/[email protected]/config) compiler: m68k-linux-gcc (GCC) 15.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260505/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
net/netfilter/nft_math.c: In function 'nft_math_eval_bitmask':
>> net/netfilter/nft_math.c:49:17: error: implicit declaration of function 'DEBUG_NET_WARN_ONCE'; did you mean 'DEBUG_NET_WARN_ON_ONCE'? [-Wimplicit-function-declaration]
49 | DEBUG_NET_WARN_ONCE(true, "unknown operation path in nft_math");
| ^~~~~~~~~~~~~~~~~~~
| DEBUG_NET_WARN_ON_ONCE
net/netfilter/nft_math.c: In function 'nft_math_init':
>> net/netfilter/nft_math.c:95:39: error: passing argument 1 of 'nft_parse_register_load' from incompatible pointer type [-Wincompatible-pointer-types]
95 | err = nft_parse_register_load(ctx, tb[NFTA_MATH_SREG], &priv->sreg,
| ^~~
| |
| const struct nft_ctx *
In file included from net/netfilter/nft_math.c:4:
include/net/netfilter/nf_tables.h:235:50: note: expected 'const struct nlattr *' but argument is of type 'const struct nft_ctx *'
235 | int nft_parse_register_load(const struct nlattr *attr, u8 *sreg, u32 len);
| ~~~~~~~~~~~~~~~~~~~~~^~~~
net/netfilter/nft_math.c:95:46: error: passing argument 2 of 'nft_parse_register_load' from incompatible pointer type [-Wincompatible-pointer-types]
95 | err = nft_parse_register_load(ctx, tb[NFTA_MATH_SREG], &priv->sreg,
| ~~^~~~~~~~~~~~~~~~
| |
| const struct nlattr *
include/net/netfilter/nf_tables.h:235:60: note: expected 'u8 *' {aka 'unsigned char *'} but argument is of type 'const struct nlattr *'
235 | int nft_parse_register_load(const struct nlattr *attr, u8 *sreg, u32 len);
| ~~~~^~~~
>> net/netfilter/nft_math.c:95:64: error: passing argument 3 of 'nft_parse_register_load' makes integer from pointer without a cast [-Wint-conversion]
95 | err = nft_parse_register_load(ctx, tb[NFTA_MATH_SREG], &priv->sreg,
| ^~~~~~~~~~~
| |
| u8 * {aka unsigned char *}
include/net/netfilter/nf_tables.h:235:70: note: expected 'u32' {aka 'unsigned int'} but argument is of type 'u8 *' {aka 'unsigned char *'}
235 | int nft_parse_register_load(const struct nlattr *attr, u8 *sreg, u32 len);
| ~~~~^~~
>> net/netfilter/nft_math.c:95:15: error: too many arguments to function 'nft_parse_register_load'; expected 3, have 4
95 | err = nft_parse_register_load(ctx, tb[NFTA_MATH_SREG], &priv->sreg,
| ^~~~~~~~~~~~~~~~~~~~~~~
96 | sizeof(u32));
| ~~~~~~~~~~~
include/net/netfilter/nf_tables.h:235:5: note: declared here
235 | int nft_parse_register_load(const struct nlattr *attr, u8 *sreg, u32 len);
| ^~~~~~~~~~~~~~~~~~~~~~~
net/netfilter/nft_math.c: At top level:
>> net/netfilter/nft_math.c:129:27: error: initialization of 'int (*)(struct sk_buff *, const struct nft_expr *)' from incompatible pointer type 'int (*)(struct sk_buff *, const struct nft_expr *, bool)' {aka 'int (*)(struct sk_buff *, const struct nft_expr *, _Bool)'} [-Wincompatible-pointer-types] 129 | .dump = nft_math_dump,
| ^~~~~~~~~~~~~
net/netfilter/nft_math.c:129:27: note: (near initialization for 'nft_math_op.dump') net/netfilter/nft_math.c:105:12: note: 'nft_math_dump' declared here
105 | static int nft_math_dump(struct sk_buff *skb,
| ^~~~~~~~~~~~~
vim +49 net/netfilter/nft_math.c
19
20 static void nft_math_eval_bitmask(u32 *src, u32 *dst,
21 const struct nft_math *priv)
22 {
23 u32 target, keep, bit_unit;
24
25 target = *src & priv->bitmask;
26 keep = *src & ~priv->bitmask;
27 bit_unit = priv->bitmask & -priv->bitmask;
28
29 switch (priv->op) {
30 case NFT_MATH_OP_INC:
31 if (target == priv->bitmask) {
32 *dst = *src;
33 break;
34 }
35
36 target = target + bit_unit;
37 *dst = target | keep;
38 break;
39 case NFT_MATH_OP_DEC:
40 if (!target) {
41 *dst = *src;
42 break;
43 }
44
45 target = target - bit_unit;
46 *dst = target | keep;
47 break;
48 default:
> 49 DEBUG_NET_WARN_ONCE(true, "unknown operation path in nft_math");
50 *dst = *src;
51 break;
52 }
53 }
54
55 static void nft_math_eval(const struct nft_expr *expr,
56 struct nft_regs *regs,
57 const struct nft_pktinfo *pkt)
58 {
59 const struct nft_math *priv = nft_expr_priv(expr);
60 u32 *src = ®s->data[priv->sreg];
61 u32 *dst = ®s->data[priv->dreg];
62
63 nft_math_eval_bitmask(src, dst, priv);
64 }
65
66 static int nft_math_init(const struct nft_ctx *ctx,
67 const struct nft_expr *expr,
68 const struct nlattr * const tb[])
69 {
70 struct nft_math *priv = nft_expr_priv(expr);
71 u32 bitmask_check;
72 int err;
73 u32 op;
74
75 if (!tb[NFTA_MATH_SREG] ||
76 !tb[NFTA_MATH_DREG] ||
77 !tb[NFTA_MATH_BITMASK] ||
78 !tb[NFTA_MATH_OP])
79 return -EINVAL;
80
81 op = nla_get_u32(tb[NFTA_MATH_OP]);
82 if (op > NFT_MATH_OP_MAX)
83 return -EOPNOTSUPP;
84 priv->op = op;
85
86 priv->bitmask = nla_get_u32(tb[NFTA_MATH_BITMASK]);
87 if (!priv->bitmask)
88 return -EINVAL;
89
90 /* check if the bitmask is contiguous, otherwise reject it */
91 bitmask_check = priv->bitmask + (priv->bitmask & -priv->bitmask);
92 if (bitmask_check & (bitmask_check - 1))
93 return -EINVAL;
94
> 95 err = nft_parse_register_load(ctx, tb[NFTA_MATH_SREG], &priv->sreg,
96 sizeof(u32));
97 if (err < 0)
98 return err;
99
100 return nft_parse_register_store(ctx, tb[NFTA_MATH_DREG],
101 &priv->dreg, NULL, NFT_DATA_VALUE,
102 sizeof(u32));
103 }
104
105 static int nft_math_dump(struct sk_buff *skb,
106 const struct nft_expr *expr, bool reset)
107 {
108 const struct nft_math *priv = nft_expr_priv(expr);
109
110 if (nft_dump_register(skb, NFTA_MATH_SREG, priv->sreg))
111 goto nla_put_failure;
112 if (nft_dump_register(skb, NFTA_MATH_DREG, priv->dreg))
113 goto nla_put_failure;
114 if (nla_put_u32(skb, NFTA_MATH_BITMASK, priv->bitmask))
115 goto nla_put_failure;
116 if (nla_put_u32(skb, NFTA_MATH_OP, priv->op))
117 goto nla_put_failure;
118 return 0;
119
120 nla_put_failure:
121 return -1;
122 }
123
124 static struct nft_expr_type nft_math_type;
125 static const struct nft_expr_ops nft_math_op = {
126 .eval = nft_math_eval,
127 .size = NFT_EXPR_SIZE(sizeof(struct nft_math)),
128 .init = nft_math_init,
> 129 .dump = nft_math_dump, 130 .type = &nft_math_type,
131 };
132
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki