Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp10188524rwp; Thu, 20 Jul 2023 16:27:49 -0700 (PDT) X-Google-Smtp-Source: APBJJlFFn+WEutQ3SFGZ5BQXQ+Ltl3KuaNKtIRzoS1VYfRhDHQI5OlfuLj4fCXJn0/Te/M9wjScD X-Received: by 2002:a17:907:78d7:b0:993:e752:1a71 with SMTP id kv23-20020a17090778d700b00993e7521a71mr212184ejc.9.1689895669581; Thu, 20 Jul 2023 16:27:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689895669; cv=none; d=google.com; s=arc-20160816; b=pXVzoLbcaxUEM4qyDNRHVO8GHcER4ntqKCwvv8br9Ww9Y/nNj666U9iXk38R/MHmHu IvNZsLZeReJV0rn2aw6ZlcbcEBPycO20pcqOTxbaaoi5ezV9y1NJl4HSO0lpFCUMROFm Px+Y2Ynd1reygeVLLrRu8t9pSry8tLOO0C9yxYnR9KBu8voySRtlFsmfqqaPGd2GiXd7 5i4cYjJsam7M8mhi6zqknIz4bIQ5tfO+BPKK0mz3H9S9f+1cS3A277yL9vknV84dfZ3A KIrO4uHWDowLzOuhXNsfDi6m/BHVwTMwS3hOMGb7oyVVNfq5kDLLPl6ChA7U7ZReQJDz 99hA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=fZ5yGzpRmb5LqzJneVlVIGFK+J6B6Q4EGCmVAyOP4RY=; fh=2u3C8vtF7YONlykTwzjnB8mTQ8mbenXDzWkkQDZcMj8=; b=mPnfVGbbGm9wL8RkxWAE1+oT8C4c6sFiysFMx60JjzQ2FxLPoMNp0oKAgN36cUcMZN ChOyuRvop2/35MxiTJdCpUNIePdHYV2RCO9+sut0wS3SUy5/S2Nz4whu61gEY333Adbs XoTNoswVFZlsNWJ5NNe5bn7tRrprhU8pH9zsMxfOHpV64Dg4as728tguRdLp/uyCmZTa 0UauN/b0MG2tRU0FEBkB0DhyTIvNVWbc6/N9Cqq+VJEkfI/W9qXxfUN+/ny7jdZLr5lc pStStGh/WwLz7dSNA+sSsbEtP6IP5WiUcLvr1z+NYGyeosHnzboM9UcKpimBT3eYW/cY gWSQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t23-20020a17090616d700b0098e1908d573si1385657ejd.325.2023.07.20.16.27.25; Thu, 20 Jul 2023 16:27:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229808AbjGTXT2 (ORCPT + 99 others); Thu, 20 Jul 2023 19:19:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229824AbjGTXT0 (ORCPT ); Thu, 20 Jul 2023 19:19:26 -0400 Received: from Chamillionaire.breakpoint.cc (Chamillionaire.breakpoint.cc [IPv6:2a0a:51c0:0:237:300::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C874B2713; Thu, 20 Jul 2023 16:19:19 -0700 (PDT) Received: from fw by Chamillionaire.breakpoint.cc with local (Exim 4.92) (envelope-from ) id 1qMcvI-0003Fw-2U; Fri, 21 Jul 2023 01:19:04 +0200 Date: Fri, 21 Jul 2023 01:19:04 +0200 From: Florian Westphal To: Daniel Xu 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 Message-ID: <20230720231904.GA31372@breakpoint.cc> References: <690a1b09db84547b0f0c73654df3f4950f1262b7.1689884827.git.dxu@dxuuu.xyz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <690a1b09db84547b0f0c73654df3f4950f1262b7.1689884827.git.dxu@dxuuu.xyz> User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Daniel Xu 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!