Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp990285rwd; Tue, 13 Jun 2023 03:20:18 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6+WzC8GNQuXIuasR1r0YNMowduJfURheWsKscJKhO9OCK14VbnO57Pue8lnixziFtONbc3 X-Received: by 2002:a67:f9cc:0:b0:42e:6748:13dc with SMTP id c12-20020a67f9cc000000b0042e674813dcmr5509078vsq.0.1686651618103; Tue, 13 Jun 2023 03:20:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686651618; cv=none; d=google.com; s=arc-20160816; b=PAiw7ys2XNkeUGVdClAfGKVY/gikHJNHUNG6Y5v2LcQHMR9ywHFwu0dCJesaV7juvm DD6L9pZgDebslPKhUpt21oG+IyK1eUh/UojZ6eHQvEAwc0AzDmjMXtfXYnimdCjNQQc7 8bfi+dZhxHw5Pg2FjI/VlMDWfAr9tKpOvFsIzI3ziaXITP7NSgtEtBuqa1gd5GZZkROH vTChOq+omSf+LJ1fGYZEx9I5JW88XcpokKM4eYak5aHSVbEezHPC+3TIVPhTASvg9FNX H1RGAFnEIxrVqhvU0bftm0aGDiFUV5c4dRQamWj2rzSZGtLCxIwulmCoNKmWSThrljVD 5vEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=N3EvG4bx9yG1/mYfSmQ2wVSFlKC8qVb7fVvvw4JD6B4=; b=qy72AFxtPsjVwVS0EMB+eTrytYWxR1CgNVM1TRVqnQPSnXco1VSnHPlKd7d5QS6iZH N5Typ7fcGF0VJUI9xlxLqW5JDpynsCTrB+eXPZQhMBaI8ESjan1QQCgkm3/KKmKM6CMS 4cDXwfC12FnfYNmsskjPKkyXZsBdJENDxjL6h0PrWqNhBPdF11hfGuFcJN2/cpRkeTPM DMP/MUrhv5Wg6loa2Al8T+TUBkQOHiFfw5xma8qK28gUOxD97vQ/Blxy8kR5CMoV64xt cSSWyIKKba8X2cx97cfLkAL/y2BV3rtFopn9mDhTEq6wyoEDsGuFA9H+3/zDMXx21DYt Z1Sg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@isovalent.com header.s=google header.b=ZwkkaG+O; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=isovalent.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x5-20020a63b205000000b00541710a9d44si4295238pge.114.2023.06.13.03.20.05; Tue, 13 Jun 2023 03:20:18 -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; dkim=pass header.i=@isovalent.com header.s=google header.b=ZwkkaG+O; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=isovalent.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241295AbjFMKPH (ORCPT + 99 others); Tue, 13 Jun 2023 06:15:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240769AbjFMKPD (ORCPT ); Tue, 13 Jun 2023 06:15:03 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43EA1191 for ; Tue, 13 Jun 2023 03:15:01 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-30fb4b3e62fso1799202f8f.2 for ; Tue, 13 Jun 2023 03:15:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=isovalent.com; s=google; t=1686651300; x=1689243300; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=N3EvG4bx9yG1/mYfSmQ2wVSFlKC8qVb7fVvvw4JD6B4=; b=ZwkkaG+OH1ROkfG388rA4GSxE3tRek8+cyoHh2MJgcvz2mk2IIL3ESQ2hSDn6ca/O2 SkS2DBksghbdul4Z1P9u+Q0dIqth+CI4OeQPmteCYer8Yy7xEDKTuewozg8tgtmxSjbM aqykQ7nKfPKjWgIg/Y7xOzLdvGjgrx6izjf5zR1YKL1kgvOjVacQ89s1y3fYFpwC4E83 ZBAfsI+HVWWtDZYh9ZWjJdue4ZTc45zbq23tLj5aK1OdtbsLwBrLFVA8yDyHAloDQc+Z 5zUE/zD+NiVdf3TtZ4kJ3jo2xItT32asLxkWtTxXMANgWS1pgF5FZg61dtzE86kvh3Tg e9vA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686651300; x=1689243300; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=N3EvG4bx9yG1/mYfSmQ2wVSFlKC8qVb7fVvvw4JD6B4=; b=M2q45UkbSi93EYsKXR1TBD+IbcRfLI/UJrCw6uPT4NiV/NKazt6t6EgFWNGdB0jv6O abZDFMws8Gd9eSgDQzYcBDLPkYjC88lN+UAUOZ1XEO2j23548uzhRj3kkLCAqHZsvPR6 gLIajG0Xx4CPdVhcclgxXwAiyHxaXd5TmpztWjIA8IJ74+BZKYb18hzAy+D12RgglX1R DVWtX6piCZ2LdYPR0z9uMeFp9W+ADXfXNnGfNwkOk2d+dV6lS6Y0uROtGKEjuhC410gM MhaeZ4RfsG854z7Pwp8D0qx4GwIsEcvlJE21THhR9g439ea6ScOWaG7TabZ+5HIElZH/ 4POQ== X-Gm-Message-State: AC+VfDzeHENU8CPY/1pJy4HCqXhXVzx4wV7SySBAH2KLnfZLo+AzkZrH 5bw73jrmMl/Ne07gYLiJUpB6qQ== X-Received: by 2002:a05:6000:6:b0:30f:bb0c:d19d with SMTP id h6-20020a056000000600b0030fbb0cd19dmr5111857wrx.64.1686651299704; Tue, 13 Jun 2023 03:14:59 -0700 (PDT) Received: from [192.168.133.193] ([5.148.46.226]) by smtp.gmail.com with ESMTPSA id k15-20020a5d6e8f000000b0030e6096afb6sm15075020wrz.12.2023.06.13.03.14.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jun 2023 03:14:59 -0700 (PDT) From: Lorenz Bauer Date: Tue, 13 Jun 2023 11:14:56 +0100 Subject: [PATCH bpf-next v2 1/6] net: export inet_lookup_reuseport and inet6_lookup_reuseport MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230613-so-reuseport-v2-1-b7c69a342613@isovalent.com> References: <20230613-so-reuseport-v2-0-b7c69a342613@isovalent.com> In-Reply-To: <20230613-so-reuseport-v2-0-b7c69a342613@isovalent.com> To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , David Ahern , Willem de Bruijn , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Joe Stringer , Mykola Lysenko , Shuah Khan , Kuniyuki Iwashima Cc: Hemanth Malla , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, Lorenz Bauer X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 Rename the existing reuseport helpers for IPv4 and IPv6 so that they can be invoked in the follow up commit. Export them so that DCCP which may be built as a module can access them. No change in functionality. Signed-off-by: Lorenz Bauer --- include/net/inet6_hashtables.h | 7 +++++++ include/net/inet_hashtables.h | 5 +++++ net/ipv4/inet_hashtables.c | 15 ++++++++------- net/ipv6/inet6_hashtables.c | 19 ++++++++++--------- 4 files changed, 30 insertions(+), 16 deletions(-) diff --git a/include/net/inet6_hashtables.h b/include/net/inet6_hashtables.h index 56f1286583d3..032ddab48f8f 100644 --- a/include/net/inet6_hashtables.h +++ b/include/net/inet6_hashtables.h @@ -48,6 +48,13 @@ struct sock *__inet6_lookup_established(struct net *net, const u16 hnum, const int dif, const int sdif); +struct sock *inet6_lookup_reuseport(struct net *net, struct sock *sk, + struct sk_buff *skb, int doff, + const struct in6_addr *saddr, + __be16 sport, + const struct in6_addr *daddr, + unsigned short hnum); + struct sock *inet6_lookup_listener(struct net *net, struct inet_hashinfo *hashinfo, struct sk_buff *skb, int doff, diff --git a/include/net/inet_hashtables.h b/include/net/inet_hashtables.h index 99bd823e97f6..8734f3488f5d 100644 --- a/include/net/inet_hashtables.h +++ b/include/net/inet_hashtables.h @@ -379,6 +379,11 @@ struct sock *__inet_lookup_established(struct net *net, const __be32 daddr, const u16 hnum, const int dif, const int sdif); +struct sock *inet_lookup_reuseport(struct net *net, struct sock *sk, + struct sk_buff *skb, int doff, + __be32 saddr, __be16 sport, + __be32 daddr, unsigned short hnum); + static inline struct sock * inet_lookup_established(struct net *net, struct inet_hashinfo *hashinfo, const __be32 saddr, const __be16 sport, diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c index e7391bf310a7..920131e4a65d 100644 --- a/net/ipv4/inet_hashtables.c +++ b/net/ipv4/inet_hashtables.c @@ -332,10 +332,10 @@ static inline int compute_score(struct sock *sk, struct net *net, return score; } -static inline struct sock *lookup_reuseport(struct net *net, struct sock *sk, - struct sk_buff *skb, int doff, - __be32 saddr, __be16 sport, - __be32 daddr, unsigned short hnum) +struct sock *inet_lookup_reuseport(struct net *net, struct sock *sk, + struct sk_buff *skb, int doff, + __be32 saddr, __be16 sport, + __be32 daddr, unsigned short hnum) { struct sock *reuse_sk = NULL; u32 phash; @@ -346,6 +346,7 @@ static inline struct sock *lookup_reuseport(struct net *net, struct sock *sk, } return reuse_sk; } +EXPORT_SYMBOL_GPL(inet_lookup_reuseport); /* * Here are some nice properties to exploit here. The BSD API @@ -369,8 +370,8 @@ static struct sock *inet_lhash2_lookup(struct net *net, sk_nulls_for_each_rcu(sk, node, &ilb2->nulls_head) { score = compute_score(sk, net, hnum, daddr, dif, sdif); if (score > hiscore) { - result = lookup_reuseport(net, sk, skb, doff, - saddr, sport, daddr, hnum); + result = inet_lookup_reuseport(net, sk, skb, doff, + saddr, sport, daddr, hnum); if (result) return result; @@ -399,7 +400,7 @@ static inline struct sock *inet_lookup_run_bpf(struct net *net, if (no_reuseport || IS_ERR_OR_NULL(sk)) return sk; - reuse_sk = lookup_reuseport(net, sk, skb, doff, saddr, sport, daddr, hnum); + reuse_sk = inet_lookup_reuseport(net, sk, skb, doff, saddr, sport, daddr, hnum); if (reuse_sk) sk = reuse_sk; return sk; diff --git a/net/ipv6/inet6_hashtables.c b/net/ipv6/inet6_hashtables.c index b64b49012655..b7c56867314e 100644 --- a/net/ipv6/inet6_hashtables.c +++ b/net/ipv6/inet6_hashtables.c @@ -111,12 +111,12 @@ static inline int compute_score(struct sock *sk, struct net *net, return score; } -static inline struct sock *lookup_reuseport(struct net *net, struct sock *sk, - struct sk_buff *skb, int doff, - const struct in6_addr *saddr, - __be16 sport, - const struct in6_addr *daddr, - unsigned short hnum) +struct sock *inet6_lookup_reuseport(struct net *net, struct sock *sk, + struct sk_buff *skb, int doff, + const struct in6_addr *saddr, + __be16 sport, + const struct in6_addr *daddr, + unsigned short hnum) { struct sock *reuse_sk = NULL; u32 phash; @@ -127,6 +127,7 @@ static inline struct sock *lookup_reuseport(struct net *net, struct sock *sk, } return reuse_sk; } +EXPORT_SYMBOL_GPL(inet6_lookup_reuseport); /* called with rcu_read_lock() */ static struct sock *inet6_lhash2_lookup(struct net *net, @@ -143,8 +144,8 @@ static struct sock *inet6_lhash2_lookup(struct net *net, sk_nulls_for_each_rcu(sk, node, &ilb2->nulls_head) { score = compute_score(sk, net, hnum, daddr, dif, sdif); if (score > hiscore) { - result = lookup_reuseport(net, sk, skb, doff, - saddr, sport, daddr, hnum); + result = inet6_lookup_reuseport(net, sk, skb, doff, + saddr, sport, daddr, hnum); if (result) return result; @@ -175,7 +176,7 @@ static inline struct sock *inet6_lookup_run_bpf(struct net *net, if (no_reuseport || IS_ERR_OR_NULL(sk)) return sk; - reuse_sk = lookup_reuseport(net, sk, skb, doff, saddr, sport, daddr, hnum); + reuse_sk = inet6_lookup_reuseport(net, sk, skb, doff, saddr, sport, daddr, hnum); if (reuse_sk) sk = reuse_sk; return sk; -- 2.40.1