netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Florian Westphal <fw@strlen.de>
To: Daniel Xu <dxu@dxuuu.xyz>
Cc: daniel@iogearbox.net, kadlec@netfilter.org, ast@kernel.org,
	pablo@netfilter.org, kuba@kernel.org, davem@davemloft.net,
	andrii@kernel.org, edumazet@google.com, pabeni@redhat.com,
	fw@strlen.de, alexei.starovoitov@gmail.com, martin.lau@linux.dev,
	song@kernel.org, yhs@fb.com, john.fastabend@gmail.com,
	kpsingh@kernel.org, sdf@google.com, haoluo@google.com,
	jolsa@kernel.org, bpf@vger.kernel.org,
	linux-kernel@vger.kernel.org, netfilter-devel@vger.kernel.org,
	coreteam@netfilter.org, netdev@vger.kernel.org,
	dsahern@kernel.org
Subject: Re: [PATCH bpf-next v5 2/5] netfilter: bpf: Support BPF_F_NETFILTER_IP_DEFRAG in netfilter link
Date: Fri, 21 Jul 2023 01:19:04 +0200	[thread overview]
Message-ID: <20230720231904.GA31372@breakpoint.cc> (raw)
In-Reply-To: <690a1b09db84547b0f0c73654df3f4950f1262b7.1689884827.git.dxu@dxuuu.xyz>

Daniel Xu <dxu@dxuuu.xyz> wrote:
> +	const struct nf_defrag_hook __maybe_unused *hook;
> +
> +	switch (link->hook_ops.pf) {
> +#if IS_ENABLED(CONFIG_NF_DEFRAG_IPV4)
> +	case NFPROTO_IPV4:
> +		hook = get_proto_defrag_hook(link, nf_defrag_v4_hook, "nf_defrag_ipv4");
> +		if (IS_ERR(hook))
> +			return PTR_ERR(hook);
> +
> +		link->defrag_hook = hook;
> +		return 0;
> +#endif
> +#if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
> +	case NFPROTO_IPV6:
> +		hook = get_proto_defrag_hook(link, nf_defrag_v6_hook, "nf_defrag_ipv6");
> +		if (IS_ERR(hook))
> +			return PTR_ERR(hook);
> +
> +		link->defrag_hook = hook;
> +		return 0;
> +#endif
> +	default:
> +		return -EAFNOSUPPORT;
> +	}
> +}
> +
> +static void bpf_nf_disable_defrag(struct bpf_nf_link *link)
> +{
> +	const struct nf_defrag_hook *hook = link->defrag_hook;
> +
> +	if (!hook)
> +		return;
> +	hook->disable(link->net);
> +	module_put(hook->owner);
> +}
> +
>  static void bpf_nf_link_release(struct bpf_link *link)
>  {
>  	struct bpf_nf_link *nf_link = container_of(link, struct bpf_nf_link, link);
> @@ -37,6 +119,8 @@ static void bpf_nf_link_release(struct bpf_link *link)
>  	 */
>  	if (!cmpxchg(&nf_link->dead, 0, 1))
>  		nf_unregister_net_hook(nf_link->net, &nf_link->hook_ops);
> +
> +	bpf_nf_disable_defrag(nf_link);
>  }

I suspect this needs to be within the cmpxchg() branch to avoid
multiple ->disable() calls.

> +	if (attr->link_create.netfilter.flags & BPF_F_NETFILTER_IP_DEFRAG) {
> +		err = bpf_nf_enable_defrag(link);
> +		if (err) {
> +			bpf_link_cleanup(&link_primer);
> +			return err;
> +		}
> +	}
> +
>  	err = nf_register_net_hook(net, &link->hook_ops);
>  	if (err) {
		bpf_nf_disable_defrag(link);

Other than those nits this lgtm, thanks!

  reply	other threads:[~2023-07-20 23:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-20 20:57 [PATCH bpf-next v5 0/5] Support defragmenting IPv(4|6) packets in BPF Daniel Xu
2023-07-20 20:57 ` [PATCH bpf-next v5 1/5] netfilter: defrag: Add glue hooks for enabling/disabling defrag Daniel Xu
2023-07-20 20:57 ` [PATCH bpf-next v5 2/5] netfilter: bpf: Support BPF_F_NETFILTER_IP_DEFRAG in netfilter link Daniel Xu
2023-07-20 23:19   ` Florian Westphal [this message]
2023-07-21 20:03     ` Daniel Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230720231904.GA31372@breakpoint.cc \
    --to=fw@strlen.de \
    --cc=alexei.starovoitov@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=coreteam@netfilter.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=dxu@dxuuu.xyz \
    --cc=edumazet@google.com \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kadlec@netfilter.org \
    --cc=kpsingh@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=pablo@netfilter.org \
    --cc=sdf@google.com \
    --cc=song@kernel.org \
    --cc=yhs@fb.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).