From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 39821C433E8 for ; Mon, 13 Jul 2020 17:47:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1C76920773 for ; Mon, 13 Jul 2020 17:47:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=cloudflare.com header.i=@cloudflare.com header.b="LXhwG2An" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730386AbgGMRrH (ORCPT ); Mon, 13 Jul 2020 13:47:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730297AbgGMRrD (ORCPT ); Mon, 13 Jul 2020 13:47:03 -0400 Received: from mail-lf1-x144.google.com (mail-lf1-x144.google.com [IPv6:2a00:1450:4864:20::144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7EE6AC061794 for ; Mon, 13 Jul 2020 10:47:03 -0700 (PDT) Received: by mail-lf1-x144.google.com with SMTP id y13so9600668lfe.9 for ; Mon, 13 Jul 2020 10:47:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jDSEEbaluBZs+0tECJKbkPZc+3U6GYzy2UWo7TMx4PQ=; b=LXhwG2Ana8/kJY+LED0FuwqzhBaLI5+UE19TVBMjlpjp33lylKcgcw7e1tCm3DQS3R XaMWDl0XAvahKKP/DUAKFxb/Ez/cIjRpkDBBXtcYC21XlLRnPB7fJZS42HNNQEgXaf/q rPyc5a813qGJ6VEPTkfrBdrR83VMXwJb0pxzc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jDSEEbaluBZs+0tECJKbkPZc+3U6GYzy2UWo7TMx4PQ=; b=nr43s5b5zcv+y6TUEV8fda/i5fzKCZ4KpZeefN8dCw46qx8b8Y03OTgEK/OPubwwnl 2BgY4v+apFpBcQ9TeaYkn9+98aOsr7YAH/lsNOvQUhUtM+bo2hl189wUCjcQKb+t7nUA aZY5SJAISl++Z5mMU91yRhk/a9R6jkh+/+vZI3fOsz7xcxmW+JI24uzHjL858pwf3GrW BohEzGY6Hpzo9/AjFAZrZpIJJGlQf3mVnXw6dVcbu7CkhUTg/JkS1pVl1Fyf2XrcfG45 A5JXtnRRBX+RPVMIkt867DUzmmG59RbgQyQMhf+UJhYLLKydFPABdfUIZTwez/69YJld RStw== X-Gm-Message-State: AOAM530b96PeSue2o/gtRWdjsrJqqIQo+uWgO4mqSYKJD7tAxwsSGGic aqXuxZ9CeUt7YEI/2WraHj+KsN4w3EHnvA== X-Google-Smtp-Source: ABdhPJytKuI10VUN5tx6g67NHROdnxuFoPpXxDYHGu+GqkdsG0zOStJQNKfZ1eHGJXHGQEit/WlQ5w== X-Received: by 2002:a19:c886:: with SMTP id y128mr170168lff.98.1594662421680; Mon, 13 Jul 2020 10:47:01 -0700 (PDT) Received: from cloudflare.com ([2a02:a310:c262:aa00:b35e:8938:2c2a:ba8b]) by smtp.gmail.com with ESMTPSA id b11sm4736057lfa.50.2020.07.13.10.47.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jul 2020 10:47:01 -0700 (PDT) From: Jakub Sitnicki To: bpf@vger.kernel.org Cc: netdev@vger.kernel.org, kernel-team@cloudflare.com, Alexei Starovoitov , Daniel Borkmann , "David S. Miller" , Jakub Kicinski Subject: [PATCH bpf-next v4 03/16] inet: Extract helper for selecting socket from reuseport group Date: Mon, 13 Jul 2020 19:46:41 +0200 Message-Id: <20200713174654.642628-4-jakub@cloudflare.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20200713174654.642628-1-jakub@cloudflare.com> References: <20200713174654.642628-1-jakub@cloudflare.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: bpf-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org Prepare for calling into reuseport from __inet_lookup_listener as well. Signed-off-by: Jakub Sitnicki --- net/ipv4/inet_hashtables.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c index 2bbaaf0c7176..ab64834837c8 100644 --- a/net/ipv4/inet_hashtables.c +++ b/net/ipv4/inet_hashtables.c @@ -246,6 +246,21 @@ 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 *reuse_sk = NULL; + u32 phash; + + if (sk->sk_reuseport) { + phash = inet_ehashfn(net, daddr, hnum, saddr, sport); + reuse_sk = reuseport_select_sock(sk, phash, skb, doff); + } + return reuse_sk; +} + /* * Here are some nice properties to exploit here. The BSD API * does not allow a listening sock to specify the remote port nor the @@ -265,21 +280,17 @@ static struct sock *inet_lhash2_lookup(struct net *net, struct inet_connection_sock *icsk; struct sock *sk, *result = NULL; int score, hiscore = 0; - u32 phash = 0; inet_lhash2_for_each_icsk_rcu(icsk, &ilb2->head) { sk = (struct sock *)icsk; score = compute_score(sk, net, hnum, daddr, dif, sdif, exact_dif); if (score > hiscore) { - if (sk->sk_reuseport) { - phash = inet_ehashfn(net, daddr, hnum, - saddr, sport); - result = reuseport_select_sock(sk, phash, - skb, doff); - if (result) - return result; - } + result = lookup_reuseport(net, sk, skb, doff, + saddr, sport, daddr, hnum); + if (result) + return result; + result = sk; hiscore = score; } -- 2.25.4