Re: [PATCH nf-next v2 1/1] netfilter: nf_tables: Eliminate duplicated codes in nf_tables_table_enable

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

 



On Thu, Jan 19, 2017 at 7:18 PM,  <fgao@xxxxxxxxxx> wrote:
> From: Feng <fgao@xxxxxxxxxx>
>
> When something failed in nf_tables_table_enable, it would unregister
> the chains. But the rollback codes are same as nf_tables_table_disable
> almostly, except there is one counter check.
> Now create one wrapper function to eliminate the duplicated codes.
>
> Signed-off-by: Feng <fgao@xxxxxxxxxx>
> ---
>  v2: Use cnt "0" as unlimited rules counter, per Pablo;
>  v1: Initial version;
>
>  net/netfilter/nf_tables_api.c | 47 ++++++++++++++++++++++---------------------
>  1 file changed, 24 insertions(+), 23 deletions(-)
>
> diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
> index a019a87..c87f8d0 100644
> --- a/net/netfilter/nf_tables_api.c
> +++ b/net/netfilter/nf_tables_api.c
> @@ -576,6 +576,27 @@ static int nf_tables_gettable(struct net *net, struct sock *nlsk,
>         return err;
>  }
>
> +static void _nf_tables_table_disable(struct net *net,
> +                                    const struct nft_af_info *afi,
> +                                    struct nft_table *table,
> +                                    u32 cnt)
> +{
> +       struct nft_chain *chain;
> +
> +       list_for_each_entry(chain, &table->chains, list) {
> +               if (!nft_is_active_next(net, chain))
> +                       continue;
> +               if (!(chain->flags & NFT_BASE_CHAIN))
> +                       continue;
> +
> +               if (cnt && --cnt == 0)
> +                       break;
> +
> +               nf_unregister_net_hooks(net, nft_base_chain(chain)->ops,
> +                                       afi->nops);
> +       }
> +}
> +
>  static int nf_tables_table_enable(struct net *net,
>                                   const struct nft_af_info *afi,
>                                   struct nft_table *table)
> @@ -598,18 +619,8 @@ static int nf_tables_table_enable(struct net *net,
>         }
>         return 0;
>  err:
> -       list_for_each_entry(chain, &table->chains, list) {
> -               if (!nft_is_active_next(net, chain))
> -                       continue;
> -               if (!(chain->flags & NFT_BASE_CHAIN))
> -                       continue;
> -
> -               if (i-- <= 0)
> -                       break;
> -
> -               nf_unregister_net_hooks(net, nft_base_chain(chain)->ops,
> -                                       afi->nops);
> -       }
> +       if (i)
> +               _nf_tables_table_disable(net, afi, table, i);
>         return err;
>  }
>
> @@ -617,17 +628,7 @@ static void nf_tables_table_disable(struct net *net,
>                                     const struct nft_af_info *afi,
>                                     struct nft_table *table)
>  {
> -       struct nft_chain *chain;
> -
> -       list_for_each_entry(chain, &table->chains, list) {
> -               if (!nft_is_active_next(net, chain))
> -                       continue;
> -               if (!(chain->flags & NFT_BASE_CHAIN))
> -                       continue;
> -
> -               nf_unregister_net_hooks(net, nft_base_chain(chain)->ops,
> -                                       afi->nops);
> -       }
> +       _nf_tables_table_disable(net, afi, table, 0);
>  }
>
>  static int nf_tables_updtable(struct nft_ctx *ctx)
> --
> 1.9.1
>
>

Hi Pablo,

Please ignore this patch.
In v2 patch, I copied your recommend codes "if (cnt && --cnt == 0)".
Today I think it is not right to use "--cnt", it should use "cnt--".
Because when the cnt is 1, the "--cnt" would break directly.
So I send the v3 patch.

Regards
Feng
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Netfitler Users]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux