Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp990281rwd; Tue, 13 Jun 2023 03:20:18 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ47WTpN92vsy7wb3oBweJ9JeI7G2wfYS9XunAdm2NizYNVOq9S+zhx3LGVJ8BvrdXtorDsE X-Received: by 2002:a05:6808:300f:b0:39e:6c93:3d2d with SMTP id ay15-20020a056808300f00b0039e6c933d2dmr200671oib.30.1686651617933; Tue, 13 Jun 2023 03:20:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686651617; cv=none; d=google.com; s=arc-20160816; b=X7abYuEQg26Wn6wFd+vrYTM6fMStybomHu69sYtEygw0GLaAvQPdOZeRKwwfo3RoEW e4qiM3y7DIyg32/J66wEuxrA/obDz4y1DCutDm8o1X+e2dsgbgek8sL6F8+mGow8ZNGR zooRrHCdGkjwnujIV9+QDP6YMeX4HCDcf1AKRTJeSRrOLBJVPO+bTgQ7Bpc+1AzywB1T DuDkisK4IaNzw//NK+U2c2Pwbffd4zEmpEvNYwR6+owzB1BWI40rJ8pnBACfbqEOkKBU xz/ar0RtaWuuUSd+psY1Uaae3x7Qbweak884q5YOrGdYTQvQCxSOnWh+H86jiCbdZHcv dDUg== 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=72bcXZ+J6bNWWGqskqAX/uK8x0vlcNvpBj1vGVpBWRk=; b=tusRTKpcSkrTT4k7OpzYYWC+g5qlmHuG6bklMttXC9o2iY8ZLXXptoZrYjo2ujsd/Z ME6R2SXmfC1YS+dNSflo3PlZT1xuMMaNvkne2Ealftj+UZOZ7UzMry/VJaYaKZI1Kgas fm/WT3l9WOnzcIugtpowsXI43S/sV2JuRFaGWffA5ul8lSqL5h6JpyZVf1etrAaJgVIy ElXkg6H0+ukOYA7BenAD7oakFf5Gyk1oxAxvZSDV7mesXhwJYTDgBu4tdCp74GC877Bd Jk90IYG+f8IVl418xta7f223fIE5E4PDoFkxnFs6tiafocJ95QjHQ+dhdHzcasZ8YHUA 5WaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@isovalent.com header.s=google header.b=c5uzEOJd; 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 v135-20020a63618d000000b0054f993d039bsi2590237pgb.490.2023.06.13.03.20.05; Tue, 13 Jun 2023 03:20:17 -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=c5uzEOJd; 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 S241562AbjFMKPM (ORCPT + 99 others); Tue, 13 Jun 2023 06:15:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240952AbjFMKPE (ORCPT ); Tue, 13 Jun 2023 06:15:04 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6CCED19B for ; Tue, 13 Jun 2023 03:15:02 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-30af159b433so5095184f8f.3 for ; Tue, 13 Jun 2023 03:15:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=isovalent.com; s=google; t=1686651301; x=1689243301; 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=72bcXZ+J6bNWWGqskqAX/uK8x0vlcNvpBj1vGVpBWRk=; b=c5uzEOJd5Q25WT9kSnvSeOMmE49QWmK3kgo7GNYndpP9Ta0GdnL6Z6cNiM+yrPbtQN pAIrsQhGIqaBJDxAxA5OjUzKq2RkeqIATkw2ixir3BvqDmgAIURnEF5egFs1uc3hhUXf phrc+DShXzZYll8zGFXC9W44aIm/JjqwgqOhFYBCVMMmyXPd9M6q2vWlUXVaGYMeHv5p 19jDzi3vToRiMlBiNgPxBVfOsNdd7iyLF7CqdeXezxP+1cwujDHs/KcBgyCdtQr+aBdt 2zM7L1yp5FlesbzZFlrPo9F5Y7KR+30khTKiDZTIi19OoZ5s97rIb9NXvnfJEnvzV1Vc +jLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686651301; x=1689243301; 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=72bcXZ+J6bNWWGqskqAX/uK8x0vlcNvpBj1vGVpBWRk=; b=lCT7mqgG4ZUR2X41k2RPKBmNk9/VGzIx3N1n9uvDrzBOkBAxKKnl6uwm+7PyKNA7MW PlbbG+t7uJn/A0hxcUvyw6rcVkrO5ABqmUlc1SuUDSQqGf+kPuIeYYHuO2GqkgcfwieA us8S0qiCeLthy1qJzYswgGD/AC1BxKoTgZge5KamNlBGg4wNO6P0GdILB4iYCGNykU3Q nggYgvYGlwW2E2AWMWsvanZPhJUP9mwf42BnjmF+Y7zAEu++8m+NO49Cd3vc6r+qd74S bZvcScho9tMlZrGTMyXHb/WLqqBZZU/tpT+HzWXa695l+e1XYjlyOscfhmiJ3CPAmkux zslQ== X-Gm-Message-State: AC+VfDwP1OC+LxfWSr/ABSGdItITFbtdIGmmlWKFJFY5tTUP5STLRobF iygHFGvQUHcWDcLD0NGJRAAXWg== X-Received: by 2002:a5d:4b84:0:b0:30e:5578:280c with SMTP id b4-20020a5d4b84000000b0030e5578280cmr8010143wrt.67.1686651300905; Tue, 13 Jun 2023 03:15:00 -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.15.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jun 2023 03:15:00 -0700 (PDT) From: Lorenz Bauer Date: Tue, 13 Jun 2023 11:14:57 +0100 Subject: [PATCH bpf-next v2 2/6] net: document inet[6]_lookup_reuseport sk_state requirements MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230613-so-reuseport-v2-2-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 The current implementation was extracted from inet[6]_lhash2_lookup in commit 80b373f74f9e ("inet: Extract helper for selecting socket from reuseport group") and commit 5df6531292b5 ("inet6: Extract helper for selecting socket from reuseport group"). In the original context, sk is always in TCP_LISTEN state and so did not have a separate check. Add documentation that specifies which sk_state are valid to pass to the function. Signed-off-by: Lorenz Bauer --- net/ipv4/inet_hashtables.c | 14 ++++++++++++++ net/ipv6/inet6_hashtables.c | 14 ++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c index 920131e4a65d..91f9210d4e83 100644 --- a/net/ipv4/inet_hashtables.c +++ b/net/ipv4/inet_hashtables.c @@ -332,6 +332,20 @@ static inline int compute_score(struct sock *sk, struct net *net, return score; } +/** + * inet_lookup_reuseport() - execute reuseport logic on AF_INET socket if necessary. + * @net: network namespace. + * @sk: AF_INET socket, must be in TCP_LISTEN state for TCP or TCP_CLOSE for UDP. + * @skb: context for a potential SK_REUSEPORT program. + * @doff: header offset. + * @saddr: source address. + * @sport: source port. + * @daddr: destination address. + * @hnum: destination port in host byte order. + * + * Return: NULL if sk doesn't have SO_REUSEPORT set, otherwise a pointer to + * the selected sock or an error. + */ struct sock *inet_lookup_reuseport(struct net *net, struct sock *sk, struct sk_buff *skb, int doff, __be32 saddr, __be16 sport, diff --git a/net/ipv6/inet6_hashtables.c b/net/ipv6/inet6_hashtables.c index b7c56867314e..208998694ae3 100644 --- a/net/ipv6/inet6_hashtables.c +++ b/net/ipv6/inet6_hashtables.c @@ -111,6 +111,20 @@ static inline int compute_score(struct sock *sk, struct net *net, return score; } +/** + * inet6_lookup_reuseport() - execute reuseport logic on AF_INET6 socket if necessary. + * @net: network namespace. + * @sk: AF_INET6 socket, must be in TCP_LISTEN state for TCP or TCP_CLOSE for UDP. + * @skb: context for a potential SK_REUSEPORT program. + * @doff: header offset. + * @saddr: source address. + * @sport: source port. + * @daddr: destination address. + * @hnum: destination port in host byte order. + * + * Return: NULL if sk doesn't have SO_REUSEPORT set, otherwise a pointer to + * the selected sock or an error. + */ struct sock *inet6_lookup_reuseport(struct net *net, struct sock *sk, struct sk_buff *skb, int doff, const struct in6_addr *saddr, -- 2.40.1