Re: [nf PATCH v3 1/2] netfilter: nf_tables: Fix entries val in rule reset audit log

2023-09-13 Thread Phil Sutter
On Wed, Sep 13, 2023 at 09:31:46PM +0200, Florian Westphal wrote: > Phil Sutter wrote: > > The value in idx and the number of rules handled in that particular > > __nf_tables_dump_rules() call is not identical. The former is a cursor > > to pick up from if multiple netlink me

[nf PATCH v3 1/2] netfilter: nf_tables: Fix entries val in rule reset audit log

2023-09-13 Thread Phil Sutter
fer exhaustion: Any rules previously dumped into that skb would evade audit logging otherwise. Fixes: 9b5ba5c9c5109 ("netfilter: nf_tables: Unbreak audit log reset") Signed-off-by: Phil Sutter --- Changes since v2: - Restore per-chain logging as requested. Changes since v1: - Use max_t() to

[nf PATCH v3 0/2] nf_tables: follow-up on audit fix, add selftest

2023-09-13 Thread Phil Sutter
Patch f1 fixes/improves Pablo's fix for the bug I built into nf_tables' audit support code. Patch 2 adds a selftest for the audit notifications in nf_tables. I consider it mature enough to submit it as non-RFC now. Larger changes in both patches, details in each patch. Phil

[nf PATCH v3 2/2] selftests: netfilter: Test nf_tables audit logging

2023-09-13 Thread Phil Sutter
Compare NETFILTER_CFG type audit logs emitted from kernel upon ruleset modifications against expected output. Signed-off-by: Phil Sutter --- Changes since v1: - Implement a custom log reader which turns audit logging on/off as needed, drop auditd dependency. - Record required CONFIG_AUDIT in

Re: [iptables PATCH] nft: Use ARRAY_SIZE() macro in nft_strerror()

2019-10-23 Thread Phil Sutter
Hi Pablo, On Wed, Oct 23, 2019 at 01:23:11PM +0200, Pablo Neira Ayuso wrote: > On Wed, Oct 23, 2019 at 01:20:24PM +0200, Pablo Neira Ayuso wrote: > > On Fri, Oct 18, 2019 at 05:51:14PM +0200, Phil Sutter wrote: > > > Variable 'table' is an array of type struc

[nft PATCH] Revert "main: Fix for misleading error with negative chain priority"

2019-10-23 Thread Phil Sutter
n. Signed-off-by: Phil Sutter --- src/main.c | 2 +- tests/shell/testcases/chains/0039negative_priority_0 | 8 2 files changed, 1 insertion(+), 9 deletions(-) delete mode 100755 tests/shell/testcases/chains/0039negative_priority_0 diff --git a/sr

[iptables PATCH] xtables-restore: Unbreak *tables-restore

2019-10-22 Thread Phil Sutter
it. Fixes: 3dc433b55bbfa ("xtables-restore: Fix --table parameter check") Signed-off-by: Phil Sutter --- iptables/ip6tables.c | 6 ++ iptables/iptables.c | 4 +++- .../ipt-restore/0009-table-name-comment_0 | 21 +

[nft PATCH] main: Fix for misleading error with negative chain priority

2019-10-21 Thread Phil Sutter
ot collate arguments but just stop after the first non-option, leaving the rest for manual handling. In fact, this is just what nft desires: mixing options with nft syntax leads to confusive command lines anyway. Signed-off-by: Phil Sutter --- src/main.c | 2

Re: [PATCH nft] main: misleading error reporting in chain definitions

2019-10-21 Thread Phil Sutter
Hi Pablo, On Mon, Oct 21, 2019 at 05:38:35PM +0200, Pablo Neira Ayuso wrote: > # nft add chain x y { type filter hook input priority -30\; } > nft: invalid option -- '3' > > Fix this by restricting getopt_long() to the first curly brace. Wouldn't it suffice to set the first char of OPTSTRING t

[nft PATCH] parser_json: Fix checking of parse_policy() return code

2019-10-21 Thread Phil Sutter
The function was changed to return an expression or NULL but error checking wasn't adjusted while doing so. Fixes: dba4a9b4b5fe2 ("src: allow variable in chain policy") Signed-off-by: Phil Sutter --- src/parser_json.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) d

[nft PATCH] tproxy: Add missing error checking when parsing from netlink

2019-10-21 Thread Phil Sutter
netlink_get_register() may return NULL and every other caller checks that. Assuming this situation is not expected, just jump to 'err' label without queueing an explicit error message. Fixes: 2be1d52644cf7 ("src: Add tproxy support") Signed-off-by: Phil Sutter --- src/netli

[iptables PATCH v2] xtables-restore: Fix --table parameter check

2019-10-21 Thread Phil Sutter
ing a table parameter and error out if it's not the first one. Fixes: f8e5ebc5986bf ("iptables: Fix crash on malformed iptables-restore") Signed-off-by: Phil Sutter --- Changes since v1: Completely rewritten: While simplifying v1 code, I noticed that even valid --table options ma

Re: [iptables PATCH] xtables-restore: Fix --table parameter check

2019-10-19 Thread Phil Sutter
Hi, On Fri, Oct 18, 2019 at 10:58:08PM +0200, Florian Westphal wrote: > Phil Sutter wrote: > > > How did you generate it? The added code is pure voodoo magic to me, > > > so I wonder if we can just remove the 'test for -t in iptables-restore > > > files'

[iptables PATCH 1/2] iptables-xml: Use add_param_to_argv()

2019-10-18 Thread Phil Sutter
Extend the shared argv parser by storing whether a given argument was quoted or not, then use it in iptables-xml. One remaining extra bit is extraction of chain name in -A commands, do that afterwards in a loop. Signed-off-by: Phil Sutter --- iptables/iptables-xml.c | 78

[iptables PATCH 2/2] xshared: Introduce struct argv_store

2019-10-18 Thread Phil Sutter
Make add_argv() and related routines reentrant by introducing a data structure to hold the stored arguments. Signed-off-by: Phil Sutter --- iptables/iptables-restore.c | 28 +++--- iptables/iptables-xml.c | 30 --- iptables/xshared.c | 76

[iptables PATCH] nft: Use ARRAY_SIZE() macro in nft_strerror()

2019-10-18 Thread Phil Sutter
Variable 'table' is an array of type struct table_struct, so this is a classical use-case for ARRAY_SIZE() macro. Signed-off-by: Phil Sutter --- iptables/nft.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iptables/nft.c b/iptables/nft.c index 89b1c7a808f57..3c2

Re: [iptables PATCH] xtables-restore: Fix --table parameter check

2019-10-18 Thread Phil Sutter
Hi Florian, On Fri, Oct 18, 2019 at 04:05:08PM +0200, Florian Westphal wrote: > Phil Sutter wrote: > > Xtables-restore tries to reject rule commands in input which contain a > > --table parameter (since it is adding this itself based on the previous > > table line)

Re: [iptables PATCH] xtables-restore: Fix --table parameter check

2019-10-18 Thread Phil Sutter
Hi, On Fri, Sep 20, 2019 at 05:49:20PM +0200, Phil Sutter wrote: > Xtables-restore tries to reject rule commands in input which contain a > --table parameter (since it is adding this itself based on the previous > table line). Sadly getopt_long's flexibility makes it hard to ge

Re: [iptables PATCH 6/8] xtables-restore: Drop pointless newargc reset

2019-10-18 Thread Phil Sutter
Hi, On Fri, Oct 18, 2019 at 10:30:56AM +0200, Pablo Neira Ayuso wrote: > On Fri, Oct 18, 2019 at 12:48:34AM +0200, Phil Sutter wrote: > > This was overlooked when merging argv-related code: newargc is > > initialized at declaration and reset in free_argv() again. > > >

Re: [iptables PATCH 3/8] xtables-restore: Introduce rule counter tokenizer function

2019-10-18 Thread Phil Sutter
Hi Pablo, On Fri, Oct 18, 2019 at 10:11:24AM +0200, Pablo Neira Ayuso wrote: > On Fri, Oct 18, 2019 at 12:48:31AM +0200, Phil Sutter wrote: > > The same piece of code appears three times, introduce a function to take > > care of tokenizing and error reporting. > > > &

[iptables PATCH 0/8] A bit of *tables-restore review fallout

2019-10-17 Thread Phil Sutter
Preparing for upcoming xtables-restore performance improvements I noticed a few things to smooth out. Patches in this series are not functionally related. Phil Sutter (8): xtables-restore: Treat struct nft_xt_restore_parse as const xtables-restore: Use xt_params->program_name xtab

[iptables PATCH 3/8] xtables-restore: Introduce rule counter tokenizer function

2019-10-17 Thread Phil Sutter
(). Signed-off-by: Phil Sutter --- iptables/iptables-restore.c | 35 ++ iptables/iptables-xml.c | 31 +--- .../ipt-restore/0008-restore-counters_0 | 22 +++ iptables/xshared.c| 37

[iptables PATCH 5/8] iptables-restore: Constify struct iptables_restore_cb

2019-10-17 Thread Phil Sutter
Just like with xtables-restore, these callbacks don't change at run-time. Signed-off-by: Phil Sutter --- iptables/iptables-restore.c | 9 + 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/iptables/iptables-restore.c b/iptables/iptables-restore.c index 3655b3e8

[iptables PATCH 8/8] xtables-restore: Drop chain_list callback

2019-10-17 Thread Phil Sutter
Since commit 0baa08fed43fa ("xtables: unify user chain add/flush for restore case") it is not used anymore, so just drop it. Signed-off-by: Phil Sutter --- iptables/nft-shared.h | 2 -- iptables/xtables-restore.c | 15 --- 2 files changed, 17 deletions(-) di

[iptables PATCH 1/8] xtables-restore: Treat struct nft_xt_restore_parse as const

2019-10-17 Thread Phil Sutter
This structure contains restore parser configuration, parser is not supposed to alter it. Suggested-by: Pablo Neira Ayuso Signed-off-by: Phil Sutter --- iptables/nft-shared.h | 2 +- iptables/xtables-restore.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/iptables

[iptables PATCH 7/8] xtables-restore: Drop local xtc_ops instance

2019-10-17 Thread Phil Sutter
It is merely used to hold nft_strerror() pointer but using that function in turn does not provide any benefit as it falls back to plain strerror() if nft_fn is not initialized. Signed-off-by: Phil Sutter --- iptables/xtables-restore.c | 9 ++--- 1 file changed, 2 insertions(+), 7 deletions

[iptables PATCH 6/8] xtables-restore: Drop pointless newargc reset

2019-10-17 Thread Phil Sutter
This was overlooked when merging argv-related code: newargc is initialized at declaration and reset in free_argv() again. Fixes: a2ed880a19d08 ("xshared: Consolidate argv construction routines") Signed-off-by: Phil Sutter --- iptables/xtables-restore.c | 3 --- 1 file changed, 3

[iptables PATCH 4/8] xtables-restore: Constify struct nft_xt_restore_cb

2019-10-17 Thread Phil Sutter
There is no need for dynamic callback mangling, so make all instances static const. Signed-off-by: Phil Sutter --- iptables/nft-shared.h| 2 +- iptables/xtables-restore.c | 8 iptables/xtables-translate.c | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a

[iptables PATCH 2/8] xtables-restore: Use xt_params->program_name

2019-10-17 Thread Phil Sutter
newargv[0] is used exclusively in debug output. Signed-off-by: Phil Sutter --- iptables/nft-shared.h| 3 +-- iptables/xtables-restore.c | 11 +-- iptables/xtables-translate.c | 2 +- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/iptables/nft-shared.h b/ipta

Re: [PATCH nft,v2] src: restore --echo with anonymous sets

2019-10-17 Thread Phil Sutter
old cache logic from the monitor code that has been replaced > by 01e5c6f0ed03 ("src: add cache level flags"). > > Signed-off-by: Pablo Neira Ayuso Acked-by: Phil Sutter Thanks, Phil

Re: [iptables PATCH v4 0/8] Improve iptables-nft performance with large rulesets

2019-10-17 Thread Phil Sutter
On Thu, Oct 17, 2019 at 12:08:16PM +0200, Pablo Neira Ayuso wrote: > On Thu, Oct 17, 2019 at 11:03:32AM +0200, Pablo Neira Ayuso wrote: > > On Tue, Oct 15, 2019 at 01:41:44PM +0200, Phil Sutter wrote: > > > Fourth try at caching optimizations implementation. > > &

Re: [PATCH nft] src: restore --echo with anonymous sets

2019-10-17 Thread Phil Sutter
Hi Pablo, On Thu, Oct 17, 2019 at 03:34:55PM +0200, Pablo Neira Ayuso wrote: > If --echo is passed, then the cache already contains the commands that > have been sent to the kernel. However, anonymous sets are an exception > since the cache needs to be updated in this case. > > Remove the old cac

Re: [nft PATCH 2/4] Revert "monitor: fix double cache update with --echo"

2019-10-17 Thread Phil Sutter
On Thu, Oct 17, 2019 at 01:29:17PM +0200, Pablo Neira Ayuso wrote: > On Thu, Oct 17, 2019 at 12:36:49PM +0200, Phil Sutter wrote: > > Hi Pablo, > > > > On Thu, Oct 17, 2019 at 11:07:38AM +0200, Pablo Neira Ayuso wrote: > > > On Thu, Oct 17, 2019 at 10:55:49AM

Re: [nft PATCH 4/4] rule: Fix for single line ct timeout printing

2019-10-17 Thread Phil Sutter
On Thu, Oct 17, 2019 at 01:14:37PM +0200, Pablo Neira Ayuso wrote: > On Thu, Oct 17, 2019 at 01:03:22AM +0200, Phil Sutter wrote: > > Commit 43ae7a48ae3de ("rule: do not print semicolon in ct timeout") > > removed an extra semicolon at end of line, but thereby broke si

Re: [nft PATCH 2/4] Revert "monitor: fix double cache update with --echo"

2019-10-17 Thread Phil Sutter
Hi, On Thu, Oct 17, 2019 at 01:09:57PM +0200, Pablo Neira Ayuso wrote: > On Thu, Oct 17, 2019 at 12:36:49PM +0200, Phil Sutter wrote: > > Hi Pablo, > > > > On Thu, Oct 17, 2019 at 11:07:38AM +0200, Pablo Neira Ayuso wrote: > > > On Thu, Oct 17, 2019 at 10:55:49AM

Re: [iptables PATCH v4 0/8] Improve iptables-nft performance with large rulesets

2019-10-17 Thread Phil Sutter
Hi, On Thu, Oct 17, 2019 at 11:03:32AM +0200, Pablo Neira Ayuso wrote: > On Tue, Oct 15, 2019 at 01:41:44PM +0200, Phil Sutter wrote: > > Fourth try at caching optimizations implementation. > > > > Changes since v3: > > > > * Rebase onto current master after p

Re: [nft PATCH 2/4] Revert "monitor: fix double cache update with --echo"

2019-10-17 Thread Phil Sutter
Hi Pablo, On Thu, Oct 17, 2019 at 11:07:38AM +0200, Pablo Neira Ayuso wrote: > On Thu, Oct 17, 2019 at 10:55:49AM +0200, Pablo Neira Ayuso wrote: > > On Thu, Oct 17, 2019 at 01:03:20AM +0200, Phil Sutter wrote: > > > This reverts commit 9b032cd6477b847f48dc8454f0e73935e9f48754.

[nft PATCH 4/4] rule: Fix for single line ct timeout printing

2019-10-16 Thread Phil Sutter
8ae3de ("rule: do not print semicolon in ct timeout") Signed-off-by: Phil Sutter --- src/rule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rule.c b/src/rule.c index 2d35bae44c9e5..3c7c8d63f8cdf 100644 --- a/src/rule.c +++ b/src/rule.c @@ -1869,7 +1869,7 @@ sta

[nft PATCH 1/4] monitor: Add missing newline to error message

2019-10-16 Thread Phil Sutter
These shouldn't happen in practice and printing to stderr is not the right thing either, but fix this anyway. Fixes: f9563c0feb24d ("src: add events reporting") Signed-off-by: Phil Sutter --- src/monitor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/

[nft PATCH 0/4] A bunch of fixes for --echo option

2019-10-16 Thread Phil Sutter
Echo/monitor testsuite failed for multiple reasons. With this series applied and a libnftnl with the recently submiited NFTA_CT_TIMEOUT_DATA parser fix in place, testsuite finally passes again. Phil Sutter (4): monitor: Add missing newline to error message Revert "monitor: fix double

[nft PATCH 2/4] Revert "monitor: fix double cache update with --echo"

2019-10-16 Thread Phil Sutter
anonymous set in cache (kernel doesn't (and shouldn't) dump SET_ID value) to update its name, just go with cache updates. Assuming that echo option is typically used for single commands, there is not much cache updating happening anyway. Signed-off-by: Phil Sutter --- src/monitor.c | 1

[nft PATCH 3/4] tests/monitor: Fix for changed ct timeout format

2019-10-16 Thread Phil Sutter
Commit a9b0c385a1d5e ("rule: print space between policy and timeout") changed spacing in ct timeout objects but missed to adjust related test case. Fixes: a9b0c385a1d5e ("rule: print space between policy and timeout") Signed-off-by: Phil Sutter --- tests/monitor/testcase

[libnftnl PATCH] obj/ct_timeout: Fix NFTA_CT_TIMEOUT_DATA parser

2019-10-16 Thread Phil Sutter
index 0 and the type value decrement is dropped there. Fixes: 0adceeab1597a ("src: add ct timeout support") Signed-off-by: Phil Sutter --- src/obj/ct_timeout.c | 8 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/obj/ct_timeout.c b/src/obj/ct_timeout.c inde

[libnftnl PATCH v2] set_elem: Validate nftnl_set_elem_set() parameters

2019-10-15 Thread Phil Sutter
; field in union nftnl_data_reg accordingly. Signed-off-by: Phil Sutter --- Changes since v1: - Change union nftnl_data_reg as outlined above. --- include/data_reg.h | 2 +- include/libnftnl/set.h | 2 ++ src/set_elem.c | 10 ++ 3 files changed, 13 insertions(+), 1 deletion(-)

Re: [libnftnl PATCH 5/6] obj/ct_timeout: Avoid array overrun in timeout_parse_attr_data()

2019-10-15 Thread Phil Sutter
On Tue, Oct 15, 2019 at 06:37:21PM +0200, Pablo Neira Ayuso wrote: > On Tue, Oct 15, 2019 at 06:35:29PM +0200, Phil Sutter wrote: > > On Tue, Oct 15, 2019 at 06:33:46PM +0200, Pablo Neira Ayuso wrote: > > > On Tue, Oct 15, 2019 at 06:21:30PM +0200, Phil Sutter

Re: [libnftnl PATCH 4/6] set: Don't bypass checks in nftnl_set_set_u{32,64}()

2019-10-15 Thread Phil Sutter
On Tue, Oct 15, 2019 at 06:32:39PM +0200, Pablo Neira Ayuso wrote: > On Tue, Oct 15, 2019 at 06:11:34PM +0200, Phil Sutter wrote: > > Hi, > > > > On Tue, Oct 15, 2019 at 05:53:46PM +0200, Pablo Neira Ayuso wrote: > > > On Tue, Oct 15, 2019 at 04:16:56PM +0200,

Re: [libnftnl PATCH 5/6] obj/ct_timeout: Avoid array overrun in timeout_parse_attr_data()

2019-10-15 Thread Phil Sutter
On Tue, Oct 15, 2019 at 06:33:46PM +0200, Pablo Neira Ayuso wrote: > On Tue, Oct 15, 2019 at 06:21:30PM +0200, Phil Sutter wrote: > > Hi, > > > > On Tue, Oct 15, 2019 at 05:57:16PM +0200, Pablo Neira Ayuso wrote: > > > On Tue, Oct 15, 2019 at 04:16:57PM +0200, Phil S

Re: [libnftnl PATCH 3/6] set_elem: Validate nftnl_set_elem_set() parameters

2019-10-15 Thread Phil Sutter
Hi, On Tue, Oct 15, 2019 at 06:09:13PM +0200, Pablo Neira Ayuso wrote: > On Tue, Oct 15, 2019 at 06:02:55PM +0200, Phil Sutter wrote: > > On Tue, Oct 15, 2019 at 05:52:44PM +0200, Pablo Neira Ayuso wrote: > > > On Tue, Oct 15, 2019 at 04:16:55PM +0200, Phil Sutter wrote: >

Re: [libnftnl PATCH 5/6] obj/ct_timeout: Avoid array overrun in timeout_parse_attr_data()

2019-10-15 Thread Phil Sutter
Hi, On Tue, Oct 15, 2019 at 05:57:16PM +0200, Pablo Neira Ayuso wrote: > On Tue, Oct 15, 2019 at 04:16:57PM +0200, Phil Sutter wrote: > > Array 'tb' has only 'attr_max' elements, the loop overstepped its > > boundary by one. Copy array_size() macro from include/

Re: [libnftnl PATCH 4/6] set: Don't bypass checks in nftnl_set_set_u{32,64}()

2019-10-15 Thread Phil Sutter
Hi, On Tue, Oct 15, 2019 at 05:53:46PM +0200, Pablo Neira Ayuso wrote: > On Tue, Oct 15, 2019 at 04:16:56PM +0200, Phil Sutter wrote: > > By calling nftnl_set_set(), any data size checks are effectively > > bypassed. Better call nftnl_set_set_data() directly, passing the re

Re: [libnftnl PATCH 3/6] set_elem: Validate nftnl_set_elem_set() parameters

2019-10-15 Thread Phil Sutter
On Tue, Oct 15, 2019 at 05:52:44PM +0200, Pablo Neira Ayuso wrote: > On Tue, Oct 15, 2019 at 04:16:55PM +0200, Phil Sutter wrote: [...] > > diff --git a/src/set_elem.c b/src/set_elem.c > > index 3794f12594079..4225a96ee5a0a 100644 > > --- a/src/set_elem.c > > +++ b/s

[libnftnl PATCH 6/6] obj/tunnel: Fix for undefined behaviour

2019-10-15 Thread Phil Sutter
Cppcheck complains: Shifting signed 32-bit value by 31 bits is undefined behaviour. Indeed, NFTNL_OBJ_TUNNEL_ERSPAN_V2_DIR enum value is 31. Make sure behaviour is as intended by shifting unsigned 1. Fixes: ea63a05272f54 ("obj: add tunnel support") Signed-off-by: Phil Sutter --

[nft PATCH] mnl: Don't use nftnl_set_set()

2019-10-15 Thread Phil Sutter
The function is unsafe to use as it effectively bypasses data length checks. Instead use nftnl_set_set_str() which at least asserts a const char pointer is passed. Signed-off-by: Phil Sutter --- src/mnl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mnl.c b/src/mnl.c

[libnftnl PATCH 2/6] set_elem: Fix return code of nftnl_set_elem_set()

2019-10-15 Thread Phil Sutter
The function returned -1 on success. Signed-off-by: Phil Sutter --- src/set_elem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/set_elem.c b/src/set_elem.c index 47965249691dd..3794f12594079 100644 --- a/src/set_elem.c +++ b/src/set_elem.c @@ -149,7 +149,7 @@ int

[libnftnl PATCH 4/6] set: Don't bypass checks in nftnl_set_set_u{32,64}()

2019-10-15 Thread Phil Sutter
By calling nftnl_set_set(), any data size checks are effectively bypassed. Better call nftnl_set_set_data() directly, passing the real size for validation. Signed-off-by: Phil Sutter --- src/set.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/set.c b/src/set.c

[libnftnl PATCH 0/6] A series of covscan-indicated fixes

2019-10-15 Thread Phil Sutter
Fix (potential) issues identified by Coverity tool. Phil Sutter (6): obj: ct_timeout: Check return code of mnl_attr_parse_nested() set_elem: Fix return code of nftnl_set_elem_set() set_elem: Validate nftnl_set_elem_set() parameters set: Don't bypass checks in nftnl_set_set_u{

[libnftnl PATCH 1/6] obj: ct_timeout: Check return code of mnl_attr_parse_nested()

2019-10-15 Thread Phil Sutter
Don't ignore nested attribute parsing errors, this may hide bugs in users' code. Fixes: 0adceeab1597a ("src: add ct timeout support") Signed-off-by: Phil Sutter --- src/obj/ct_timeout.c | 9 ++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/obj/ct

[libnftnl PATCH 5/6] obj/ct_timeout: Avoid array overrun in timeout_parse_attr_data()

2019-10-15 Thread Phil Sutter
Array 'tb' has only 'attr_max' elements, the loop overstepped its boundary by one. Copy array_size() macro from include/utils.h in nftables.git to make sure code does the right thing. Fixes: 0adceeab1597a ("src: add ct timeout support") Signed-off-by: Phil Sutter

[libnftnl PATCH 3/6] set_elem: Validate nftnl_set_elem_set() parameters

2019-10-15 Thread Phil Sutter
Copying from nftnl_table_set_data(), validate input to nftnl_set_elem_set() as well. Given that for some attributes the function assumes passed data size, this seems necessary. Signed-off-by: Phil Sutter --- include/libnftnl/set.h | 2 ++ src/set_elem.c | 10 ++ 2 files changed

[iptables PATCH v4 7/8] nft: Support nft_is_table_compatible() per chain

2019-10-15 Thread Phil Sutter
() which calls xtables_error() in case compatibility check fails. If a chain name was given, include that in error message. Signed-off-by: Phil Sutter --- iptables/nft.c | 32 iptables/nft.h | 5 - iptables/xtables-save.c | 2 +- 3 files changed

[iptables PATCH v4 3/8] nft-cache: Cover for multiple fetcher invocation

2019-10-15 Thread Phil Sutter
mpty chains, but causes no harm in that case, either. Signed-off-by: Phil Sutter --- iptables/nft-cache.c | 19 ++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/iptables/nft-cache.c b/iptables/nft-cache.c index 22468d70fec57..afb2126b51495 100644 --- a/iptables/

[iptables PATCH v4 8/8] nft: Optimize flushing all chains of a table

2019-10-15 Thread Phil Sutter
#x27;chain' function parameter which is not used at that point). Signed-off-by: Phil Sutter --- iptables/nft-cache.c | 22 +++--- iptables/nft-cache.h | 3 ++- iptables/nft.c | 32 ++-- 3 files changed, 39 insertions(+), 18 deletions(-)

[iptables PATCH v4 1/8] nft-cache: Introduce cache levels

2019-10-15 Thread Phil Sutter
parameter and raises cache completeness to that level. Signed-off-by: Phil Sutter --- Changes since v3: - Make sure cache stays consistent in __nft_build_cache() by extending cache only if kernel ruleset did not change since last call. --- iptables/nft-cache.c | 54

[iptables PATCH v4 0/8] Improve iptables-nft performance with large rulesets

2019-10-15 Thread Phil Sutter
Fourth try at caching optimizations implementation. Changes since v3: * Rebase onto current master after pushing the accepted initial three patches. * Avoid cache inconsistency in __nft_build_cache() if kernel ruleset changed since last call. Phil Sutter (8): nft-cache: Introduce cache

[iptables PATCH v4 4/8] nft-cache: Support partial cache per table

2019-10-15 Thread Phil Sutter
-off-by: Phil Sutter --- iptables/nft-cache.c | 82 ++-- 1 file changed, 57 insertions(+), 25 deletions(-) diff --git a/iptables/nft-cache.c b/iptables/nft-cache.c index afb2126b51495..822d6f20cf51c 100644 --- a/iptables/nft-cache.c +++ b/iptables/nft

[iptables PATCH v4 6/8] nft: Reduce cache overhead of nft_chain_builtin_init()

2019-10-15 Thread Phil Sutter
There is no need for a full chain cache, fetch only the few builtin chains that might need to be created. Signed-off-by: Phil Sutter --- iptables/nft.c | 9 + 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/iptables/nft.c b/iptables/nft.c index 775582aab7955..7e019d54ee475

[iptables PATCH v4 2/8] nft-cache: Fetch only chains in nft_chain_list_get()

2019-10-15 Thread Phil Sutter
The function is used to return the given table's chains, so fetching chain cache is enough. Add calls to nft_build_cache() in places where a rule cache is required. Signed-off-by: Phil Sutter --- iptables/nft-cache.c | 2 +- iptables/nft.c | 20 2 files change

[iptables PATCH v4 5/8] nft-cache: Support partial rule cache per chain

2019-10-15 Thread Phil Sutter
doesn't include chains already, it will fetch only the specified chain from kernel (if existing) and add that to table's chain list which is returned. This keeps operations for all chains of a table or a specific one within the same code path in nft.c. Signed-off-by: Phil Sutter --- ip

Re: First Contribution

2019-10-15 Thread Phil Sutter
Hi, On Mon, Oct 14, 2019 at 08:44:05PM +0530, UDAY MEWADA wrote: > My name is Uday Mewada, pursuing engineering in Computer Science. > > I'm looking forward to contributing to Netfilter. Can someone guide me > how to start contributing in it and what are the initial bugs where I > can start. You

Re: [iptables PATCH v3 04/11] nft-cache: Introduce cache levels

2019-10-11 Thread Phil Sutter
gt; approach, but it might work. You would need to invoke > xtables_restore_parse() twice. The problem with parsing twice is having to cache input which may be huge for xtables-restore. On Fri, Oct 11, 2019 at 12:20:52PM +0200, Pablo Neira Ayuso wrote: > On Fri, Oct 11, 2019 at 12:09:11AM +

Re: [iptables PATCH v3 04/11] nft-cache: Introduce cache levels

2019-10-10 Thread Phil Sutter
Hi Pablo, On Wed, Oct 09, 2019 at 12:29:01PM +0200, Pablo Neira Ayuso wrote: > On Wed, Oct 09, 2019 at 11:37:23AM +0200, Pablo Neira Ayuso wrote: > > Hi Phil, > > > > On Tue, Oct 08, 2019 at 06:14:40PM +0200, Phil Sutter wrote: > > > Replace the simple have_

[libnftnl PATCH v2] set: Export nftnl_set_list_lookup_byname()

2019-10-08 Thread Phil Sutter
Rename and optimize internal function nftnl_set_lookup() for external use. Just like with nftnl_chain_list, use a hash table for fast set name lookups. Signed-off-by: Phil Sutter --- Changes since v1: - Adjust LIBVERSION according to libtool documentation. --- Make_global.am | 2

Re: [PATCH nft] tests: shell: fix failed tests due to missing quotes

2019-10-08 Thread Phil Sutter
On Tue, Oct 08, 2019 at 08:06:32PM +0200, Eric Jallot wrote: > Add double quotes to protect newlines when using <<< redirection. > > See also commit b878cb7d83855. > > Signed-off-by: Eric Jallot Applied, thanks!

[iptables PATCH v3 06/11] nft-cache: Cover for multiple fetcher invocation

2019-10-08 Thread Phil Sutter
mpty chains, but causes no harm in that case, either. Signed-off-by: Phil Sutter --- iptables/nft-cache.c | 19 ++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/iptables/nft-cache.c b/iptables/nft-cache.c index 5f27aec6d9c30..a2cfb6ef6dbcf 100644 --- a/iptables/

[iptables PATCH v3 03/11] nft: Extract cache routines into nft-cache.c

2019-10-08 Thread Phil Sutter
The amount of code dealing with caching only is considerable and hence deserves an own source file. Signed-off-by: Phil Sutter --- iptables/Makefile.am | 2 +- iptables/nft-cache.c | 376 + iptables/nft-cache.h | 17 ++ iptables/nft.c

[iptables PATCH v3 01/11] nft: Pass nft_handle to flush_cache()

2019-10-08 Thread Phil Sutter
This allows to call nft_table_builtin_find() and hence removes the only real user of __nft_table_builtin_find(). Consequently remove the latter by integrating it into its sole caller. Signed-off-by: Phil Sutter --- iptables/nft.c | 28 +++- 1 file changed, 11 insertions

[iptables PATCH v3 11/11] nft: Optimize flushing all chains of a table

2019-10-08 Thread Phil Sutter
#x27;chain' function parameter which is not used at that point). Signed-off-by: Phil Sutter --- iptables/nft-cache.c | 22 +++--- iptables/nft-cache.h | 3 ++- iptables/nft.c | 32 ++-- 3 files changed, 39 insertions(+), 18 deletions(-)

[iptables PATCH v3 00/11] Improve iptables-nft performance with large rulesets

2019-10-08 Thread Phil Sutter
-restore performance. Phil Sutter (11): nft: Pass nft_handle to flush_cache() nft: Avoid nested cache fetching nft: Extract cache routines into nft-cache.c nft-cache: Introduce cache levels nft-cache: Fetch only chains in nft_chain_list_get() nft-cache: Cover for multiple fetcher invocation

[iptables PATCH v3 07/11] nft-cache: Support partial cache per table

2019-10-08 Thread Phil Sutter
-off-by: Phil Sutter --- iptables/nft-cache.c | 82 ++-- 1 file changed, 57 insertions(+), 25 deletions(-) diff --git a/iptables/nft-cache.c b/iptables/nft-cache.c index a2cfb6ef6dbcf..3cb397c805a9a 100644 --- a/iptables/nft-cache.c +++ b/iptables/nft

[iptables PATCH v3 08/11] nft-cache: Support partial rule cache per chain

2019-10-08 Thread Phil Sutter
doesn't include chains already, it will fetch only the specified chain from kernel (if existing) and add that to table's chain list which is returned. This keeps operations for all chains of a table or a specific one within the same code path in nft.c. Signed-off-by: Phil Sutter --- ip

[iptables PATCH v3 10/11] nft: Support nft_is_table_compatible() per chain

2019-10-08 Thread Phil Sutter
() which calls xtables_error() in case compatibility check fails. If a chain name was given, include that in error message. Signed-off-by: Phil Sutter --- iptables/nft.c | 32 iptables/nft.h | 5 - iptables/xtables-save.c | 2 +- 3 files changed

[iptables PATCH v3 05/11] nft-cache: Fetch only chains in nft_chain_list_get()

2019-10-08 Thread Phil Sutter
The function is used to return the given table's chains, so fetching chain cache is enough. Add calls to nft_build_cache() in places where a rule cache is required. Signed-off-by: Phil Sutter --- iptables/nft-cache.c | 2 +- iptables/nft.c | 20 2 files change

[iptables PATCH v3 09/11] nft: Reduce cache overhead of nft_chain_builtin_init()

2019-10-08 Thread Phil Sutter
There is no need for a full chain cache, fetch only the few builtin chains that might need to be created. Signed-off-by: Phil Sutter --- iptables/nft.c | 9 + 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/iptables/nft.c b/iptables/nft.c index 775582aab7955..7e019d54ee475

[iptables PATCH v3 04/11] nft-cache: Introduce cache levels

2019-10-08 Thread Phil Sutter
parameter and raises cache completeness to that level. Signed-off-by: Phil Sutter --- iptables/nft-cache.c | 51 +++- iptables/nft.h | 9 +++- 2 files changed, 44 insertions(+), 16 deletions(-) diff --git a/iptables/nft-cache.c b/iptables/nft-cache.c

[iptables PATCH v3 02/11] nft: Avoid nested cache fetching

2019-10-08 Thread Phil Sutter
Don't call fetch_table_cache() from within fetch_chain_cache() but instead from __nft_build_cache(). Since that is the only caller of fetch_chain_cache(), this change should not have any effect in practice. Signed-off-by: Phil Sutter --- iptables/nft.c | 3 +-- 1 file changed, 1 insertion(

[iptables PATCH v2 00/12] Implement among match support

2019-09-27 Thread Phil Sutter
ual among match implementation for ebtables-nft. Phil Sutter (12): nft: family_ops: Pass nft_handle to 'add' callback nft: family_ops: Pass nft_handle to 'rule_find' callback nft: family_ops: Pass nft_handle to 'print_rule' callback nft: family_ops: Pass nft_handle to

[iptables PATCH v2 09/12] nft: Bore up nft_parse_payload()

2019-09-27 Thread Phil Sutter
Allow for closer inspection by storing payload expression's base and length values. Also facilitate for two consecutive payload expressions as LHS of a (cmp/lookup) statement as used with concatenations. Signed-off-by: Phil Sutter --- iptables/nft-shared.c | 8 iptables/nft-sha

[iptables PATCH v2 12/12] nft: bridge: Rudimental among extension support

2019-09-27 Thread Phil Sutter
Support among match as far as possible given the limitations of nftables sets, namely limited to homogeneous MAC address only or MAC and IP address only matches. Signed-off-by: Phil Sutter --- Changes since v1: - Fix for overlong lines. - Use nftnl_set_list_lookup_byname() from libnftnl

[iptables PATCH v2 05/12] nft: Keep nft_handle pointer in nft_xt_ctx

2019-09-27 Thread Phil Sutter
Instead of carrying the family value, carry the handle (which contains the family value) and relieve expression parsers from having to call nft_family_ops_lookup(). Signed-off-by: Phil Sutter --- iptables/nft-shared.c | 40 ++-- iptables/nft-shared.h | 2

[iptables PATCH v2 01/12] nft: family_ops: Pass nft_handle to 'add' callback

2019-09-27 Thread Phil Sutter
In order for add_match() to create anonymous sets when converting xtables matches it needs access to nft handle. So pass it along from callers of family ops' add callback. Signed-off-by: Phil Sutter --- iptables/nft-arp.c| 2 +- iptables/nft-bridge.c | 5 +++-- iptables/nft-ipv4.c

[iptables PATCH v2 02/12] nft: family_ops: Pass nft_handle to 'rule_find' callback

2019-09-27 Thread Phil Sutter
In order to prepare for rules containing set references, nft handle has to be passed to nft_rule_to_iptables_command_state() in order to let it access the set in cache. Signed-off-by: Phil Sutter --- iptables/nft-arp.c| 4 ++-- iptables/nft-bridge.c | 4 ++-- iptables/nft-shared.c | 7

[iptables PATCH v2 10/12] nft: Embed rule's table name in nft_xt_ctx

2019-09-27 Thread Phil Sutter
Down to the point where expression parsing happens, the rule's table is not known anymore but relevant if set lookups are required. Signed-off-by: Phil Sutter --- iptables/nft-shared.c | 1 + iptables/nft-shared.h | 1 + 2 files changed, 2 insertions(+) diff --git a/iptables/nft-share

[iptables PATCH v2 08/12] nft: Support NFT_COMPAT_SET_ADD

2019-09-27 Thread Phil Sutter
Implement the required infrastructure to create sets as part of a batch job commit. Signed-off-by: Phil Sutter --- iptables/nft.c | 58 ++ 1 file changed, 58 insertions(+) diff --git a/iptables/nft.c b/iptables/nft.c index f46f13c2501e2

[iptables PATCH v2 11/12] nft: Support parsing lookup expression

2019-09-27 Thread Phil Sutter
Add required glue code to support family specific lookup expression parsers implemented as family_ops callback. Signed-off-by: Phil Sutter --- iptables/nft-shared.c | 9 + iptables/nft-shared.h | 2 ++ iptables/nft.c| 5 - 3 files changed, 15 insertions(+), 1 deletion

[iptables PATCH v2 07/12] nft: Fetch sets when updating rule cache

2019-09-27 Thread Phil Sutter
In order to support anonymous sets, cache them along with their elements. Signed-off-by: Phil Sutter --- Changes since v1: - Fix cache flushing: Since set fetching happens only if rules are fetched, too, set list may be NULL so call nftnl_set_list_free() and nftnl_set_list_foreach

[iptables PATCH v2 06/12] nft: Eliminate pointless calls to nft_family_ops_lookup()

2019-09-27 Thread Phil Sutter
If nft_handle is available, use its 'ops' field instead of performing a new lookup. For the same reason, there is no need to pass ops pointer to __nft_print_header(). Signed-off-by: Phil Sutter --- iptables/nft.c | 29 +++-- 1 file changed, 11 insertions(+), 18

[iptables PATCH v2 03/12] nft: family_ops: Pass nft_handle to 'print_rule' callback

2019-09-27 Thread Phil Sutter
Prepare for 'rule_to_cs' callback to receive nft_handle pointer so it is able to access cache for set lookups. Signed-off-by: Phil Sutter --- iptables/nft-arp.c| 3 ++- iptables/nft-bridge.c | 4 ++-- iptables/nft-ipv4.c | 4 ++-- iptables/nft-ipv6.c | 4 ++-- iptables/nf

[iptables PATCH v2 04/12] nft: family_ops: Pass nft_handle to 'rule_to_cs' callback

2019-09-27 Thread Phil Sutter
This is the actual callback used to parse nftables rules. Pass nft_handle to it so it can access the cache (and possible sets therein). Having to pass nft_handle to nft_rule_print_save() allows to simplify it a bit since no family ops lookup has to be done anymore. Signed-off-by: Phil Sutter

[iptables PATCH] iptables-test: Run tests in lexical order

2019-09-27 Thread Phil Sutter
To quickly see if a given test was run or not, sort the file list. Also filter non-test files right when preparing the list. Signed-off-by: Phil Sutter --- iptables-test.py | 8 ++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/iptables-test.py b/iptables-test.py index

[libnftnl PATCH] set: Export nftnl_set_list_lookup_byname()

2019-09-27 Thread Phil Sutter
Rename and optimize internal function nftnl_set_lookup() for external use. Just like with nftnl_chain_list, use a hash table for fast set name lookups. Signed-off-by: Phil Sutter --- include/libnftnl/set.h | 2 ++ include/set.h | 1 + src/libnftnl.map | 4 src/set.c

  1   2   3   4   5   6   7   8   9   10   >