Re: [PATCH nft 2/3] src: do not print unnecessary space for the synproxy object

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Jul 4, 2025 at 7:40 PM Zhongqiu Duan <dzq.aishenghu0@xxxxxxxxx> wrote:
>
> If timestamp is not enabled in the synproxy object, an additional space
> will be print before the sack-perm flag.
>
> Before this patch:
>
> table inet t {
>         synproxy s {
>                 mss 1460
>                 wscale 8
>                  sack-perm
>         }
> }
>
> After this patch:
>
> table inet t {
>         synproxy s {
>                 mss 1460
>                 wscale 8
>                 sack-perm
>         }
> }
>
> Signed-off-by: Zhongqiu Duan <dzq.aishenghu0@xxxxxxxxx>
> ---
>  src/rule.c                             | 4 +++-
>  tests/shell/testcases/json/single_flag | 4 ++--
>  2 files changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/src/rule.c b/src/rule.c
> index c0f7570e233c..af3dd39c69d0 100644
> --- a/src/rule.c
> +++ b/src/rule.c
> @@ -1951,7 +1951,9 @@ static void obj_print_data(const struct obj *obj,
>                 }
>                 if (flags & (NF_SYNPROXY_OPT_TIMESTAMP | NF_SYNPROXY_OPT_SACK_PERM)) {
>                         nft_print(octx, "%s%s%s", opts->nl, opts->tab, opts->tab);
> -                       nft_print(octx, "%s %s", ts_str, sack_str);
> +                       nft_print(octx, "%s%s%s", ts_str,
> +                                 flags & NF_SYNPROXY_OPT_TIMESTAMP ? " " : "",
> +                                 sack_str);
>                 }
>                 nft_print(octx, "%s", opts->stmt_separator);
>                 }

Emmm, this will add an additional space after the timestamp if the timestamp
is set but sack-perm does not.

It could be:
---
diff --git a/src/rule.c b/src/rule.c
index c0f7570e233c..3761e05a22e3 100644
--- a/src/rule.c
+++ b/src/rule.c
@@ -1950,8 +1950,10 @@ static void obj_print_data(const struct obj *obj,
                        nft_print(octx, "wscale %u", obj->synproxy.wscale);
                }
                if (flags & (NF_SYNPROXY_OPT_TIMESTAMP |
NF_SYNPROXY_OPT_SACK_PERM)) {
+                       bool space = ((flags & NF_SYNPROXY_OPT_TIMESTAMP) &&
+                                     (flags & NF_SYNPROXY_OPT_SACK_PERM));
                        nft_print(octx, "%s%s%s", opts->nl, opts->tab,
opts->tab);
-                       nft_print(octx, "%s %s", ts_str, sack_str);
+                       nft_print(octx, "%s%s%s", ts_str, space ? " "
: "", sack_str);

                }
                nft_print(octx, "%s", opts->stmt_separator);
                }

> diff --git a/tests/shell/testcases/json/single_flag b/tests/shell/testcases/json/single_flag
> index f0a608ad8412..b8fd96170a33 100755
> --- a/tests/shell/testcases/json/single_flag
> +++ b/tests/shell/testcases/json/single_flag
> @@ -157,13 +157,13 @@ STD_SYNPROXY_OBJ_1="table ip t {
>         synproxy s {
>                 mss 1280
>                 wscale 64
> -                sack-perm
> +               sack-perm
>         }
>  }"
>  JSON_SYNPROXY_OBJ_1='{"nftables": [{"table": {"family": "ip", "name": "t", "handle": 0}}, {"synproxy": {"family": "ip", "name": "s", "table": "t", "handle": 0, "mss": 1280, "wscale": 64, "flags": "sack-perm"}}]}'
>  JSON_SYNPROXY_OBJ_1_EQUIV=$(sed 's/\("flags":\) \([^}]*\)/\1 [\2]/' <<< "$JSON_SYNPROXY_OBJ_1")
>
> -STD_SYNPROXY_OBJ_2=$(sed 's/ \(sack-perm\)/timestamp \1/' <<< "$STD_SYNPROXY_OBJ_1")
> +STD_SYNPROXY_OBJ_2=$(sed 's/\(sack-perm\)/timestamp \1/' <<< "$STD_SYNPROXY_OBJ_1")
>  JSON_SYNPROXY_OBJ_2=$(sed 's/\("flags":\) \("sack-perm"\)/\1 ["timestamp", \2]/' <<< "$JSON_SYNPROXY_OBJ_1")
>
>  back_n_forth "$STD_SYNPROXY_OBJ_1" "$JSON_SYNPROXY_OBJ_1"
> --
> 2.43.0
>





[Index of Archives]     [Netfitler Users]     [Berkeley Packet Filter]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux