A bunch of fixes for echo output
Phil Sutter
reviewercover A bunch of fixes for echo output
This series addresses the shortcomings of my echo option implementation pointed out by Pablo. In addition to that, I figured that test suites for monitor and echo are pretty similar so I merged both into one.
Phil Sutter (4):
mnl: Drop --echo support for non-batch calls
netlink: Fix segfault when using --echo flag
echo: Fix for added delays in rule updates
tests: Merge monitor and echo test suites
include/netlink.h | 5 +- src/evaluate.c | 9 ---- src/mnl.c | 23 +-------- src/netlink.c | 26 +++++++--- src/rule.c | 26 ++++++++-- tests/echo/run-tests.sh | 45 ---------------- tests/echo/testcases/simple.t | 12 ----- tests/monitor/run-tests.sh | 107 +++++++++++++++++++++++++++------------ tests/monitor/testcases/simple.t | 20 ++++++++ 9 files changed, 138 insertions(+), 135 deletions(-) delete mode 100755 tests/echo/run-tests.sh delete mode 100644 tests/echo/testcases/simple.t create mode 100644 tests/monitor/testcases/simple.t
Signature · 1 line
2.13.1
Phil Sutter
reviewerPATCH 1/4 mnl: Drop --echo support for non-batch calls
Echo support in nft_mnl_talk() was broken: nft_mnl_talk_cb() passed cbdata->data as second parameter to netlink_echo_callback() which expected it to be of type struct netlink_ctx while in fact it was whatever callers of nft_mnl_talk() passed as callback data (in most cases a NULL pointer).
I didn't notice this because I didn't test for kernels without support for transactions. This has been added to nftables in kernel version 3.16 back in 2014. Since then, user space which doesn't support it can't even add a table anymore. So adding this new feature to the old code path is really not feasible, therefore drop this broken attempt at supporting it.
--- src/mnl.c | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-)
src/mnl.c +1 -22
@@ -67,32 +67,11 @@ out:return ret; } -struct nft_mnl_talk_cb_data { -int (*cb)(const struct nlmsghdr *nlh,void *data); -void *data; -}; - -static int nft_mnl_talk_cb (const struct nlmsghdr *nlh,void *data) -{ -struct nft_mnl_talk_cb_data *cbdata = data; -int rc; - -if (cbdata->cb) - rc = cbdata->cb (nlh, cbdata->data); -if (rc) -return rc; -return netlink_echo_callback (nlh, cbdata->data); -} -static int nft_mnl_talk (struct mnl_socket *nf_sock,const void *data,unsigned int len,int (*cb)(const struct nlmsghdr *nlh,void *data),void *cb_data) {uint32_t portid =mnl_socket_get_portid (nf_sock); -struct nft_mnl_talk_cb_data tcb_data = { - .cb = cb, - .data = cb_data, - };#ifdef DEBUG if (debug_level &DEBUG_MNL )
@@ -102,7 +81,7 @@ nft_mnl_talk(struct mnl_socket *nf_sock, const void *data, unsigned int len,if (mnl_socket_sendto (nf_sock, data, len) <0 )return -1 ; -return nft_mnl_recv (nf_sock, seq, portid, &nft_mnl_talk_cb, &tcb_data); +return nft_mnl_recv (nf_sock, seq, portid, cb, cb_data); }/*
Signature · 1 line
2.13.1
Re: [nft PATCH 1/4] mnl: Drop --echo support for non-batch calls
Quoted 5 lines · Phil Sutter
Echo support in
nft_mnl_talk()was broken:nft_mnl_talk_cb()passedcbdata->dataas second parameter tonetlink_echo_callback()which expected it to be of type structnetlink_ctxwhile in fact it was whatever callers ofnft_mnl_talk()passed as callback data (in most cases a NULL pointer).
Applied, thanks.
Quoted 6 lines
I didn't notice this because I didn't test for kernels without support for transactions. This has been added to nftables in kernel version 3.16 back in 2014. Since then, user space which doesn't support it can't even add a table anymore. So adding this new feature to the old code path is really not feasible, therefore drop this broken attempt at supporting it.
We fixed this problem with nft and 3.16 IIRC. So at least the very basic featureset still available there works fine.
Phil Sutter
reviewerRe: [nft PATCH 1/4] mnl: Drop --echo support for non-batch calls
Hi,
Quoted 1 line · Pablo Neira Ayuso
On Tue, Aug 15, 2017 at 01:43:02AM +0200, Phil Sutter wrote:
[...]
Quoted 9 lines
Quoted 6 lines
I didn't notice this because I didn't test for kernels without support for transactions. This has been added to nftables in kernel version 3.16 back in 2014. Since then, user space which doesn't support it can't even add a table anymore. So adding this new feature to the old code path is really not feasible, therefore drop this broken attempt at supporting it.
We fixed this problem with nft and 3.16 IIRC. So at least the very basic featureset still available there works fine.
I was speaking of the other way around, namely old user space with kernel >= 3.16 (that's what I simulated by forcing batch_supported to false).
Given that kernel user API isn't completely compatible, do you see a chance to drop the non-batch code from user space at some point?
Cheers, Phil
Pablo Neira Ayuso
maintainerRe: [nft PATCH 1/4] mnl: Drop --echo support for non-batch calls
Quoted 15 lines · Phil Sutter
Hi,
Quoted 1 line · Pablo Neira Ayuso
On Tue, Aug 15, 2017 at 01:43:02AM +0200, Phil Sutter wrote:
[...]
Quoted 9 lines
Quoted 6 lines
I didn't notice this because I didn't test for kernels without support for transactions. This has been added to nftables in kernel version 3.16 back in 2014. Since then, user space which doesn't support it can't even add a table anymore. So adding this new feature to the old code path is really not feasible, therefore drop this broken attempt at supporting it.
We fixed this problem with nft and 3.16 IIRC. So at least the very basic featureset still available there works fine.
Quoted 6 lines
I was speaking of the other way around, namely old user space with kernel >= 3.16 (that's what I simulated by forcing
batch_supportedto false).Given that kernel user API isn't completely compatible, do you see a chance to drop the non-batch code from user space at some point?
Yes, as soon as 3.16 becomes unsupported we can let that code sink I would suggest.
Phil Sutter
reviewerPATCH 2/4 netlink: Fix segfault when using --echo flag
In reply to Phil SutterCommit 07b45939972eb ("src: introduce struct nft_cache") added cache pointer to struct netlink_mon_handler and the code assumes it is never NULL. Therefore initialize it in the dummy version of netlink_mon_handler in netlink_echo_callback().
--- src/netlink.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
src/netlink.c +3 -1
@@ -3075,12 +3075,14 @@ static int netlink_events_cb(const struct nlmsghdr *nlh, void *data)int netlink_echo_callback (const struct nlmsghdr *nlh,void *data) { +struct netlink_ctx *ctx = data;struct netlink_mon_handler echo_monh = { .format =NFTNL_OUTPUT_DEFAULT , - .ctx = data, + .ctx = ctx, .loc = &netlink_location, .monitor_flags =0xffffffff , .cache_needed = true, + .cache = ctx->cache, };if (!echo_monh.ctx->octx->echo)
Signature · 1 line
2.13.1
Pablo Neira Ayuso
maintainerRe: [nft PATCH 2/4] netlink: Fix segfault when using --echo flag
Quoted 4 lines · Phil Sutter
Commit
07b45939972eb("src: introduce structnft_cache") added cache pointer to structnetlink_mon_handlerand the code assumes it is never NULL. Therefore initialize it in the dummy version ofnetlink_mon_handlerinnetlink_echo_callback().
Also applied, thanks.
Phil Sutter
reviewerPATCH 3/4 echo: Fix for added delays in rule updates
In reply to Phil SutterThe added cache update upon every command dealing with rules was a bummer. Instead, perform the needed cache update only if echo option was set.
Initially, I tried to perform the cache update from within netlink_echo_callback(), but that turned into a mess since the shared socket between cache_init() and mnl_batch_talk() would receive unexpected new input. So instead update the cache from do_command_add(), netlink_replace_rule_batch() and do_comand_insert() so it completes before mnl_batch_talk() starts listening.
--- include/netlink.h | 5 +---- src/evaluate.c | 9 --------- src/netlink.c | 22 +++++++++++++++------- src/rule.c | 26 ++++++++++++++++++++++---- 4 files changed, 38 insertions(+), 24 deletions(-)
include/netlink.h +1 -4
@@ -119,10 +119,7 @@ extern int netlink_add_rule_batch(struct netlink_ctx *ctx,extern int netlink_del_rule_batch (struct netlink_ctx *ctx,const struct handle *h,const struct location *loc); -extern int netlink_replace_rule_batch (struct netlink_ctx *ctx, -const struct handle *h, -const struct rule *rule, -const struct location *loc); +extern int netlink_replace_rule_batch (struct netlink_ctx *ctx,struct cmd *cmd); extern int netlink_add_chain(struct netlink_ctx *ctx, const struct handle *h, const struct location *loc,
src/evaluate.c +0 -9
@@ -2965,10 +2965,6 @@ static int cmd_evaluate_add(struct eval_ctx *ctx, struct cmd *cmd)handle_merge (&cmd->set->handle, &cmd->handle);return set_evaluate (ctx, cmd->set);case CMD_OBJ_RULE : - ret =cache_update (ctx->nf_sock, ctx->cache, cmd->op, - ctx->msgs); -if (ret <0 ) -return ret;handle_merge (&cmd->rule->handle, &cmd->handle);return rule_evaluate (ctx, cmd->rule);case CMD_OBJ_CHAIN :
@@ -2983,11 +2979,6 @@ static int cmd_evaluate_add(struct eval_ctx *ctx, struct cmd *cmd)case CMD_OBJ_COUNTER :case CMD_OBJ_QUOTA :case CMD_OBJ_CT_HELPER : - ret =cache_update (ctx->nf_sock, ctx->cache, cmd->op, - ctx->msgs); -if (ret <0 ) -return ret; -return 0 ;default :BUG ("invalid command object type %u\n" , cmd->obj);
src/netlink.c +15 -7
@@ -459,20 +459,28 @@ int netlink_add_rule_batch(struct netlink_ctx *ctx,return err; } -int netlink_replace_rule_batch (struct netlink_ctx *ctx,const struct handle *h, -const struct rule *rule, -const struct location *loc) +int netlink_replace_rule_batch (struct netlink_ctx *ctx,struct cmd *cmd) {struct nftnl_rule *nlr; -int err, flags = ctx->octx->echo ?NLM_F_ECHO :0 ; +int err, flags =0 ; - nlr =alloc_nftnl_rule (&rule->handle); -netlink_linearize_rule (ctx, nlr, rule); +if (ctx->octx->echo) { + err =cache_update (ctx->nf_sock, ctx->cache, + cmd->obj, ctx->msgs); +if (err <0 ) +return err; + + flags |=NLM_F_ECHO ; + } + + nlr =alloc_nftnl_rule (&cmd->rule->handle); +netlink_linearize_rule (ctx, nlr, cmd->rule); err =mnl_nft_rule_batch_replace (nlr, ctx->batch, flags, ctx->seqnum);nftnl_rule_free (nlr);if (err <0 ) -netlink_io_error (ctx, loc,"Could not replace rule to batch: %s" , +netlink_io_error (ctx, &cmd->location, +"Could not replace rule to batch: %s" ,strerror (errno));return err; }
src/rule.c +22 -4
@@ -1017,8 +1017,16 @@ static int do_command_add(struct netlink_ctx *ctx, struct cmd *cmd, bool excl) {uint32_t flags = excl ?NLM_F_EXCL :0 ; -if (ctx->octx->echo) +if (ctx->octx->echo) { +int rc; + + rc =cache_update (ctx->nf_sock, ctx->cache, + cmd->obj, ctx->msgs); +if (rc <0 ) +return rc; + flags |=NLM_F_ECHO ; + }switch (cmd->obj) {case CMD_OBJ_TABLE :
@@ -1048,8 +1056,7 @@ static int do_command_replace(struct netlink_ctx *ctx, struct cmd *cmd) {switch (cmd->obj) {case CMD_OBJ_RULE : -return netlink_replace_rule_batch (ctx, &cmd->handle, cmd->rule, - &cmd->location); +return netlink_replace_rule_batch (ctx, cmd);default :BUG ("invalid command object type %u\n" , cmd->obj); }
@@ -1058,7 +1065,18 @@ static int do_command_replace(struct netlink_ctx *ctx, struct cmd *cmd)static int do_command_insert (struct netlink_ctx *ctx,struct cmd *cmd) { -uint32_t flags = ctx->octx->echo ?NLM_F_ECHO :0 ; +uint32_t flags =0 ; + +if (ctx->octx->echo) { +int rc; + + rc =cache_update (ctx->nf_sock, ctx->cache, + cmd->obj, ctx->msgs); +if (rc <0 ) +return rc; + + flags |=NLM_F_ECHO ; + }switch (cmd->obj) {case CMD_OBJ_RULE :
Signature · 1 line
2.13.1
Pablo Neira Ayuso
maintainerRe: [nft PATCH 3/4] echo: Fix for added delays in rule updates
Quoted 24 lines · Phil Sutter
The added cache update upon every command dealing with rules was a bummer. Instead, perform the needed cache update only if echo option was set.
Initially, I tried to perform the cache update from within
netlink_echo_callback(), but that turned into a mess since the shared socket betweencache_init()andmnl_batch_talk()would receive unexpected new input. So instead update the cache fromdo_command_add(),netlink_replace_rule_batch()anddo_comand_insert()so it completes beforemnl_batch_talk()starts listening.Signed-off-by Phil Sutter <[email protected]>--- include/netlink.h | 5 +---- src/evaluate.c | 9 --------- src/netlink.c | 22 +++++++++++++++------- src/rule.c | 26 ++++++++++++++++++++++---- 4 files changed, 38 insertions(+), 24 deletions(-)include/netlink.h +0
-0
include/netlink.h extern int netlink_add_rule_batch(struct netlink_ctx *ctx, · line 122
Quoted 8 lines
include/netlink.h +1
-4@@ -119,10 +119,7 @@ extern int netlink_add_rule_batch(struct netlink_ctx *ctx,extern int netlink_del_rule_batch (struct netlink_ctx *ctx,const struct handle *h,const struct location *loc); -extern int netlink_replace_rule_batch (struct netlink_ctx *ctx, -const struct handle *h, -const struct rule *rule, -const struct location *loc); +extern int netlink_replace_rule_batch (struct netlink_ctx *ctx,struct cmd *cmd);
This patch comes with an interesting cleanup, that is that you just pass struct cmd as function parameter.
Probably we can do this everywhere in the netlink.c code? I wonder if it's better just to fix this without changing the function footprint. Then, work a cleanup patch to update all netlink_* functions to pass struct cmd as parameter.
So we leave everything looking consistent.
Quoted 74 lines
include/netlink.h +0
-0extern int netlink_add_chain(struct netlink_ctx *ctx, const struct handle *h, const struct location *loc,src/evaluate.c +0
-9@@ -2965,10 +2965,6 @@ static int cmd_evaluate_add(struct eval_ctx *ctx, struct cmd *cmd)handle_merge (&cmd->set->handle, &cmd->handle);return set_evaluate (ctx, cmd->set);case CMD_OBJ_RULE : - ret =cache_update (ctx->nf_sock, ctx->cache, cmd->op, - ctx->msgs); -if (ret <0 ) -return ret;handle_merge (&cmd->rule->handle, &cmd->handle);return rule_evaluate (ctx, cmd->rule);case CMD_OBJ_CHAIN :@@ -2983,11 +2979,6 @@ static int cmd_evaluate_add(struct eval_ctx *ctx, struct cmd *cmd)case CMD_OBJ_COUNTER :case CMD_OBJ_QUOTA :case CMD_OBJ_CT_HELPER : - ret =cache_update (ctx->nf_sock, ctx->cache, cmd->op, - ctx->msgs); -if (ret <0 ) -return ret; -return 0 ;default :BUG ("invalid command object type %u\n" , cmd->obj);src/netlink.c +15
-7@@ -459,20 +459,28 @@ int netlink_add_rule_batch(struct netlink_ctx *ctx,return err; } -int netlink_replace_rule_batch (struct netlink_ctx *ctx,const struct handle *h, -const struct rule *rule, -const struct location *loc) +int netlink_replace_rule_batch (struct netlink_ctx *ctx,struct cmd *cmd) {struct nftnl_rule *nlr; -int err, flags = ctx->octx->echo ?NLM_F_ECHO :0 ; +int err, flags =0 ; - nlr =alloc_nftnl_rule (&rule->handle); -netlink_linearize_rule (ctx, nlr, rule); +if (ctx->octx->echo) { + err =cache_update (ctx->nf_sock, ctx->cache, + cmd->obj, ctx->msgs); +if (err <0 ) +return err; + + flags |=NLM_F_ECHO ; + } + + nlr =alloc_nftnl_rule (&cmd->rule->handle); +netlink_linearize_rule (ctx, nlr, cmd->rule); err =mnl_nft_rule_batch_replace (nlr, ctx->batch, flags, ctx->seqnum);nftnl_rule_free (nlr);if (err <0 ) -netlink_io_error (ctx, loc,"Could not replace rule to batch: %s" , +netlink_io_error (ctx, &cmd->location, +"Could not replace rule to batch: %s" ,strerror (errno));return err; }src/rule.c +0
-0
src/rule.c static int do_command_add(struct netlink_ctx *ctx, struct cmd *cmd, bool excl) · line 1021
Quoted 6 lines
src/rule.c +2
-1@@ -1017,8 +1017,16 @@ static int do_command_add(struct netlink_ctx *ctx, struct cmd *cmd, bool excl) {uint32_t flags = excl ?NLM_F_EXCL :0 ; -if (ctx->octx->echo) +if (ctx->octx->echo) { +int rc;
Another nitpick: We seem to use 'int ret' everywhere in the code. So probably for consistency, use this name here too.
Quoted 44 lines
src/rule.c +20
-3+ + rc =cache_update (ctx->nf_sock, ctx->cache, + cmd->obj, ctx->msgs); +if (rc <0 ) +return rc; + flags |=NLM_F_ECHO ; + }switch (cmd->obj) {case CMD_OBJ_TABLE :@@ -1048,8 +1056,7 @@ static int do_command_replace(struct netlink_ctx *ctx, struct cmd *cmd) {switch (cmd->obj) {case CMD_OBJ_RULE : -return netlink_replace_rule_batch (ctx, &cmd->handle, cmd->rule, - &cmd->location); +return netlink_replace_rule_batch (ctx, cmd);default :BUG ("invalid command object type %u\n" , cmd->obj); }@@ -1058,7 +1065,18 @@ static int do_command_replace(struct netlink_ctx *ctx, struct cmd *cmd)static int do_command_insert (struct netlink_ctx *ctx,struct cmd *cmd) { -uint32_t flags = ctx->octx->echo ?NLM_F_ECHO :0 ; +uint32_t flags =0 ; + +if (ctx->octx->echo) { +int rc; + + rc =cache_update (ctx->nf_sock, ctx->cache, + cmd->obj, ctx->msgs); +if (rc <0 ) +return rc; + + flags |=NLM_F_ECHO ; + }switch (cmd->obj) {case CMD_OBJ_RULE :Signature · 1 line
2.13.1
Phil Sutter
reviewerRe: [nft PATCH 3/4] echo: Fix for added delays in rule updates
Hi,
Quoted 1 line · Pablo Neira Ayuso
On Tue, Aug 15, 2017 at 01:43:04AM +0200, Phil Sutter wrote:
[...]
Quoted 17 lines
include/netlink.h extern int netlink_add_rule_batch(struct netlink_ctx *ctx, · line 122
Quoted 13 lines
include/netlink.h +1
-4@@ -119,10 +119,7 @@ extern int netlink_add_rule_batch(struct netlink_ctx *ctx,extern int netlink_del_rule_batch (struct netlink_ctx *ctx,const struct handle *h,const struct location *loc); -extern int netlink_replace_rule_batch (struct netlink_ctx *ctx, -const struct handle *h, -const struct rule *rule, -const struct location *loc); +extern int netlink_replace_rule_batch (struct netlink_ctx *ctx,struct cmd *cmd);This patch comes with an interesting cleanup, that is that you just pass struct cmd as function parameter.
Quoted 6 lines
Probably we can do this everywhere in the
netlink.ccode? I wonder if it's better just to fix this without changing the function footprint. Then, work a cleanup patch to update all netlink_* functions to pass struct cmd as parameter.So we leave everything looking consistent.
This change was necessary in order to pass the required parameters to cache_update(). Doing without, I would have to pass nf_sock, cache, obj and msgs fields additionally, and the number of parameters was already quite big.
I would instead suggest to follow-up with a patch applying the change to all other functions as well, though I'm not sure whether Eric might make a voodoo doll which looks like me if I submit that now.
[...]
Quoted 8 lines
Quoted 8 lines
src/rule.c +0
-0@@ -1017,8 +1017,16 @@ static int do_command_add(struct netlink_ctx *ctx, struct cmd *cmd, bool excl) {uint32_t flags = excl ?NLM_F_EXCL :0 ;
Quoted 6 lines
src/rule.c static int do_command_add(struct netlink_ctx *ctx, struct cmd *cmd, bool excl) · line 1021
Quoted 3 lines
src/rule.c +2
-1-if (ctx->octx->echo) +if (ctx->octx->echo) { +int rc;Another nitpick: We seem to use 'int ret' everywhere in the code. So probably for consistency, use this name here too.
You mean if 'int err' is not used? But OK, in src/rule.c we have at least three cases of 'return ret' and only two of 'return rc' (from my patch) so I'll change that.
Cheers, Phil
Phil Sutter
reviewerRe: [nft PATCH 3/4] echo: Fix for added delays in rule updates
Quoted 25 lines · Phil Sutter
Quoted 1 line · Pablo Neira Ayuso
On Tue, Aug 15, 2017 at 01:43:04AM +0200, Phil Sutter wrote:
[...]
Quoted 22 lines
include/netlink.h extern int netlink_add_rule_batch(struct netlink_ctx *ctx, · line 122
Quoted 13 lines
include/netlink.h +1
-4@@ -119,10 +119,7 @@ extern int netlink_add_rule_batch(struct netlink_ctx *ctx,extern int netlink_del_rule_batch (struct netlink_ctx *ctx,const struct handle *h,const struct location *loc); -extern int netlink_replace_rule_batch (struct netlink_ctx *ctx, -const struct handle *h, -const struct rule *rule, -const struct location *loc); +extern int netlink_replace_rule_batch (struct netlink_ctx *ctx,struct cmd *cmd);This patch comes with an interesting cleanup, that is that you just pass struct cmd as function parameter.
Probably we can do this everywhere in the
netlink.ccode? I wonder if it's better just to fix this without changing the function footprint. Then, work a cleanup patch to update all netlink_* functions to pass struct cmd as parameter.
Quoted 6 lines
Quoted 1 line
So we leave everything looking consistent.
This change was necessary in order to pass the required parameters to
cache_update(). Doing without, I would have to passnf_sock, cache, obj and msgs fields additionally, and the number of parameters was already quite big.
ENOCOFFEE: Actually I only use obj field of struct cmd, and that should be optional since I can also just use CMD_INVALID instead - so I'll drop the signature changes in v2.
Thanks, Phil
Pablo Neira Ayuso
maintainerRe: [nft PATCH 3/4] echo: Fix for added delays in rule updates
Quoted 28 lines · Phil Sutter
Quoted 27 lines · Phil Sutter
Quoted 1 line · Pablo Neira Ayuso
On Tue, Aug 15, 2017 at 01:43:04AM +0200, Phil Sutter wrote:
[...]
Quoted 23 lines
include/netlink.h extern int netlink_add_rule_batch(struct netlink_ctx *ctx, · line 122
Quoted 13 lines
include/netlink.h +1
-4@@ -119,10 +119,7 @@ extern int netlink_add_rule_batch(struct netlink_ctx *ctx,extern int netlink_del_rule_batch (struct netlink_ctx *ctx,const struct handle *h,const struct location *loc); -extern int netlink_replace_rule_batch (struct netlink_ctx *ctx, -const struct handle *h, -const struct rule *rule, -const struct location *loc); +extern int netlink_replace_rule_batch (struct netlink_ctx *ctx,struct cmd *cmd);This patch comes with an interesting cleanup, that is that you just pass struct cmd as function parameter.
Probably we can do this everywhere in the
netlink.ccode? I wonder if it's better just to fix this without changing the function footprint. Then, work a cleanup patch to update all netlink_* functions to pass struct cmd as parameter.So we leave everything looking consistent.
Quoted 8 lines
Quoted 4 lines
This change was necessary in order to pass the required parameters to
cache_update(). Doing without, I would have to passnf_sock, cache, obj and msgs fields additionally, and the number of parameters was already quite big.ENOCOFFEE: Actually I only use obj field of struct cmd, and that should be optional since I can also just use
CMD_INVALIDinstead - so I'll drop the signature changes in v2.
That's good, Eric won't do any voodoo toll with you then.
Phil Sutter
reviewerPATCH 4/4 tests: Merge monitor and echo test suites
In reply to Phil SutterThe two test suites were pretty similar already, and since echo output is supposed to be identical to monitor output apart from delete commands, they can be merged together with litte effort.
--- tests/echo/run-tests.sh | 45 ---------------- tests/echo/testcases/simple.t | 12 ----- tests/monitor/run-tests.sh | 107 +++++++++++++++++++++++++++------------ tests/monitor/testcases/simple.t | 20 ++++++++ 4 files changed, 96 insertions(+), 88 deletions(-) delete mode 100755 tests/echo/run-tests.sh delete mode 100644 tests/echo/testcases/simple.t create mode 100644 tests/monitor/testcases/simple.t
tests/echo/run-tests.sh deleted +0 -45
@@ -1,45 +0,0 @@ -#!/bin/bash - -cd $(dirname $0) -nft=../../src/nft -nft_opts="-nn -a --echo" -debug=false - -debug_echo() { - $debug || return - - echo "$@" -} - -trap "$nft flush ruleset" EXIT - -for testcase in testcases/*.t; do - echo "running tests from file $(basename $testcase)" - # files are like this: - # - # <input command>[;;<output regexp>] - - $nft flush ruleset - - while read line; do - [[ -z "$line" || "$line" == "#"* ]] && continue - - # XXX: this only works if there is no semicolon in output - input="${line%;;*}" - output="${line##*;;}" - - [[ -z $output ]] && output="$input" - - debug_echo "calling '$nft $nft_opts $input'" - cmd_out=$($nft $nft_opts $input) - # strip trailing whitespace (happens when adding a named set) - cmd_out="${cmd_out% }" - debug_echo "got output '$cmd_out'" - [[ $cmd_out == $output ]] || { - echo "Warning: Output differs:" - echo "# nft $nft_opts $input" - echo "- $output" - echo "+ $cmd_out" - } - done <$testcase -done
tests/echo/testcases/simple.t deleted +0 -12
@@ -1,12 +0,0 @@ -add table ip t -add chain ip t c - -# note the added handle output -add rule ip t c accept;;add rule ip t c accept # handle * -add rule ip t c tcp dport { 22, 80, 443 } accept;;add rule ip t c tcp dport { 22, 80, 443 } accept # handle * - -add set ip t ipset { type ipv4_addr; } -add element ip t ipset { 192.168.0.1 } - -# counter output comes with statistics -add counter ip t cnt;;add counter ip t cnt *
tests/monitor/run-tests.sh +76 -31
137 lines not on this page · raw message
tests/monitor/testcases/simple.t new file +20 -0
@@ -0,0 +1,20 @@ +# first the setup +I add table ip t +I add chain ip t c +O - + +I add rule ip t c accept +O - + +I add rule ip t c tcp dport { 22, 80, 443 } accept +O - + +I insert rule ip t c counter accept +O add rule ip t c counter packets 0 bytes 0 accept + +I replace rule ip t c handle 2 accept comment "foo bar" +O delete rule ip t c handle 2 +O add rule ip t c accept comment "foo bar" + +I add counter ip t cnt +O add counter ip t cnt { packets 0 bytes 0 }
Signature · 1 line
2.13.1
Re: [nft PATCH 4/4] tests: Merge monitor and echo test suites
Quoted 3 lines · Phil Sutter
The two test suites were pretty similar already, and since echo output is supposed to be identical to monitor output apart from delete commands, they can be merged together with litte effort.
Applied, thanks Phil.