[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230627111248.GH3207@breakpoint.cc>
Date: Tue, 27 Jun 2023 13:12:48 +0200
From: Florian Westphal <fw@...len.de>
To: Daniel Xu <dxu@...uu.xyz>
Cc: daniel@...earbox.net, edumazet@...gle.com, kuba@...nel.org,
fw@...len.de, pabeni@...hat.com, pablo@...filter.org,
andrii@...nel.org, davem@...emloft.net, ast@...nel.org,
kadlec@...filter.org, martin.lau@...ux.dev, song@...nel.org,
yhs@...com, john.fastabend@...il.com, kpsingh@...nel.org,
sdf@...gle.com, haoluo@...gle.com, jolsa@...nel.org,
bpf@...r.kernel.org, linux-kernel@...r.kernel.org,
netfilter-devel@...r.kernel.org, coreteam@...filter.org,
netdev@...r.kernel.org, dsahern@...nel.org
Subject: Re: [PATCH bpf-next 4/7] netfilter: bpf: Support
BPF_F_NETFILTER_IP_DEFRAG in netfilter link
Daniel Xu <dxu@...uu.xyz> wrote:
> +static int bpf_nf_enable_defrag(struct bpf_nf_link *link)
> +{
> + int err;
> +
> + switch (link->hook_ops.pf) {
> +#if IS_ENABLED(CONFIG_NF_DEFRAG_IPV4)
> + case NFPROTO_IPV4:
> + const struct nf_defrag_v4_hook *v4_hook;
> +
> + err = request_module("nf_defrag_ipv4");
> + if (err)
> + return err;
> +
> + rcu_read_lock();
> + v4_hook = rcu_dereference(nf_defrag_v4_hook);
> + err = v4_hook->enable(link->net);
> + rcu_read_unlock();
I'd reverse this, first try rcu_dereference(), then modprobe
if thats returned NULL.
> +static void bpf_nf_disable_defrag(struct bpf_nf_link *link)
> +{
> + switch (link->hook_ops.pf) {
> +#if IS_ENABLED(CONFIG_NF_DEFRAG_IPV4)
> + case NFPROTO_IPV4:
> + const struct nf_defrag_v4_hook *v4_hook;
> +
> + rcu_read_lock();
> + v4_hook = rcu_dereference(nf_defrag_v4_hook);
> + v4_hook->disable(link->net);
> + rcu_read_unlock();
if (v4_hook)
v4_hook->disable()
Else we get trouble on manual 'rmmod'.
> + /* make sure conntrack confirm is always last */
> + prio = attr->link_create.netfilter.priority;
> + if (prio == NF_IP_PRI_FIRST)
> + return -ERANGE; /* sabotage_in and other warts */
> + else if (prio == NF_IP_PRI_LAST)
> + return -ERANGE; /* e.g. conntrack confirm */
> + else if ((attr->link_create.netfilter.flags & BPF_F_NETFILTER_IP_DEFRAG) &&
> + (prio > NF_IP_PRI_FIRST && prio <= NF_IP_PRI_CONNTRACK_DEFRAG))
> + return -ERANGE; /* cannot use defrag if prog runs before nf_defrag */
You could elide the (prio > NF_IP_PRI_FIRST, its already handled by
first conditional. Otherwise this looks good to me.
Powered by blists - more mailing lists