Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1129852pxa; Wed, 5 Aug 2020 23:42:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJymBw3HaLIqake1j29kLhfke/zT0V+pnLLU49bMR84GifhqwFly9Tw8MiN+vWNKfYibrqqv X-Received: by 2002:a17:906:c7d4:: with SMTP id dc20mr3007171ejb.283.1596696126970; Wed, 05 Aug 2020 23:42:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596696126; cv=none; d=google.com; s=arc-20160816; b=J/pAZyV+ZycW8CO1R0dadsl2bOi+oBhMF5kwg4/xn4F5d0E9XLs8oOU2CYttselDpY p/K7Hg/bUgejWRppzgHj5LOXaPJfMFqZVk1i6/ZfX5dl7ZVFNa4iUEo+aKzcdVzwHhLM xPnyA7IGm7tvrQcnjrRwtOlKCzAToqRtLgVM+TDFLTPgUkGElt9WhBRYJlvhqg8tt9GY vFFOnKjyz77nCUfkd50g9+C6oF7Dd25bS6RZPDf09nyJMfVYgh4n4NOnIYX/199t5VIO LAXtgcZGJ339Jde6YBzBuhep1uMY10hsm+60+66b2lpT/KPU92CzQOwLtn7Ppq8wW4GR v/lQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=jDUym0vWEpZIcMhWfa/K7V4V+Szd7ch6LROXk73w6hQ=; b=D42WfbUmH4mRSpuUhRRR/fKfVW4lse87Mb7fca/Z96rm3DB3iRXIT/hj+4jl8MPEzY R3mVbMd+RnOmlY51kG/WO//UjEHeG3H+1I4mvNihPrNERhFmsDSVLrGHxjZLuMUQylP2 gCRxsABLFJI+yClH2tRFzwVVW6y9Y6Fo7b6KW+PBTQpBaSN933J0mCE38CDIwFSN19YC rcD55aM42LuWB9CdMSU2t0LtFwSkLlyW0PAqnIW2UUWh6vbW7Fp7ND19a+fjTQlTte6f RgtL5K3xN6uaoNJ1icguz8Nr48IJxK8NcP3CiVpnYvzTikAQXrGVYa+QQtA7+8hi+wz4 Bkdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@tessares-net.20150623.gappssmtp.com header.s=20150623 header.b=pqZPBAHq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gz9si2803056ejb.81.2020.08.05.23.41.44; Wed, 05 Aug 2020 23:42:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@tessares-net.20150623.gappssmtp.com header.s=20150623 header.b=pqZPBAHq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728378AbgHFGl3 (ORCPT + 99 others); Thu, 6 Aug 2020 02:41:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728278AbgHFGlT (ORCPT ); Thu, 6 Aug 2020 02:41:19 -0400 Received: from mail-ed1-x544.google.com (mail-ed1-x544.google.com [IPv6:2a00:1450:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD861C061757 for ; Wed, 5 Aug 2020 23:41:17 -0700 (PDT) Received: by mail-ed1-x544.google.com with SMTP id df16so17972370edb.9 for ; Wed, 05 Aug 2020 23:41:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tessares-net.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version; bh=jDUym0vWEpZIcMhWfa/K7V4V+Szd7ch6LROXk73w6hQ=; b=pqZPBAHqzO9t39KetthMni+h5xvguVJURtACJeU+jpTCCm8WNXLISsTFl6IJU4UsE8 IbGeGSfmTWa1ToeEM++ZFsGIz1zqBibaFyf0DLIZEnWfotWrOzcsFsofSH3JMTnajWPn v/IveldnQcEILJKt1tGvQNAuRILTDZs1731GsXtJjthZvgnwc7QhM+xbI2rlCUimaBVW 7USUMuOKkdQUGkeix6iSCVqDSTigP0hrf/NV0j1FsSt3ZA7zd75Ua9L5fNMbgHSitm6t l0P+qIibDQ55U0eXJ9ec0jNQQGAC78pKeh3Oc/ZC+Oy0wugXcpaZmsYaN4DTIZY32HGl ZMHg== 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; bh=jDUym0vWEpZIcMhWfa/K7V4V+Szd7ch6LROXk73w6hQ=; b=LRgjWdiysGrrI4sSzr3sPMGSIkj6xj0Jnyx3ntBAiBOah+3nMiw0XwodaKM9AXRr0N tQrewjnVcR7nR/jShhHBG6PaGBFNr4yPLliRaT0WTr1ISLRXCBQVQfMaHU1fzcNYXWZS Ad8DdDnu7koJ/r1j8TIqIBkLjzXdSmBS7vzN9Fq62vUJ+hejPRvb8taj8ySNOo069dVw cVgWifLqCQftNYhdJOFPpUB2ikeLSZBs/gJiOwNdgoErfrlS6/qXmURnGQa3fbw6gMqW j1rFSfdHDVeKTUV2RheF1mlR309EYc80KKsNsB0mnp/gevszXUeNxHIVsAT8brJ4ArMo Sekg== X-Gm-Message-State: AOAM533In1KnZQdEHwGA6M0kVFSInKw+N8C+rZr0aH7HvmobssgjtQt8 20MKTCRcAOCN+q6M9mYDj7fjNNwN6EjMVL7HAjKDuLfJ2tcID1M387kdYCZFLnNkFpNvB0I5+Pi rBUo3EPejoGF8zLDFVg== X-Received: by 2002:a50:fc0e:: with SMTP id i14mr2610860edr.346.1596696076367; Wed, 05 Aug 2020 23:41:16 -0700 (PDT) Received: from tim.froidcoeur.net (ptr-7tznw15pracyli75x11.18120a2.ip6.access.telenet.be. [2a02:1811:50e:f0f0:d05d:939:f42b:f575]) by smtp.gmail.com with ESMTPSA id h18sm2880984edw.56.2020.08.05.23.41.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Aug 2020 23:41:15 -0700 (PDT) From: Tim Froidcoeur To: "David S. Miller" , Jakub Kicinski , Alexey Kuznetsov , Hideaki YOSHIFUJI , Patrick McHardy , KOVACS Krisztian Cc: Tim Froidcoeur , Matthieu Baerts , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net 1/2] net: refactor bind_bucket fastreuse into helper Date: Thu, 6 Aug 2020 08:41:07 +0200 Message-Id: <20200806064109.183059-2-tim.froidcoeur@tessares.net> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200806064109.183059-1-tim.froidcoeur@tessares.net> References: <20200806064109.183059-1-tim.froidcoeur@tessares.net> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Refactor the fastreuse update code in inet_csk_get_port into a small helper function that can be called from other places. Acked-by: Matthieu Baerts Signed-off-by: Tim Froidcoeur --- include/net/inet_connection_sock.h | 4 ++ net/ipv4/inet_connection_sock.c | 99 ++++++++++++++++-------------- 2 files changed, 58 insertions(+), 45 deletions(-) diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h index e5b388f5fa20..1d59bf55bb4d 100644 --- a/include/net/inet_connection_sock.h +++ b/include/net/inet_connection_sock.h @@ -316,6 +316,10 @@ int inet_csk_compat_getsockopt(struct sock *sk, int level, int optname, int inet_csk_compat_setsockopt(struct sock *sk, int level, int optname, char __user *optval, unsigned int optlen); +/* update the fast reuse flag when adding a socket */ +void inet_csk_update_fastreuse(struct inet_bind_bucket *tb, + struct sock *sk); + struct dst_entry *inet_csk_update_pmtu(struct sock *sk, u32 mtu); #define TCP_PINGPONG_THRESH 3 diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c index afaf582a5aa9..3b46b1f6086e 100644 --- a/net/ipv4/inet_connection_sock.c +++ b/net/ipv4/inet_connection_sock.c @@ -266,7 +266,7 @@ inet_csk_find_open_port(struct sock *sk, struct inet_bind_bucket **tb_ret, int * static inline int sk_reuseport_match(struct inet_bind_bucket *tb, struct sock *sk) { - kuid_t uid = sock_i_uid(sk); + kuid_t uid = sock_i_uid((struct sock *)sk); if (tb->fastreuseport <= 0) return 0; @@ -296,6 +296,57 @@ static inline int sk_reuseport_match(struct inet_bind_bucket *tb, ipv6_only_sock(sk), true, false); } +void inet_csk_update_fastreuse(struct inet_bind_bucket *tb, + struct sock *sk) +{ + kuid_t uid = sock_i_uid((struct sock *)sk); + bool reuse = sk->sk_reuse && sk->sk_state != TCP_LISTEN; + + if (hlist_empty(&tb->owners)) { + tb->fastreuse = reuse; + if (sk->sk_reuseport) { + tb->fastreuseport = FASTREUSEPORT_ANY; + tb->fastuid = uid; + tb->fast_rcv_saddr = sk->sk_rcv_saddr; + tb->fast_ipv6_only = ipv6_only_sock(sk); + tb->fast_sk_family = sk->sk_family; +#if IS_ENABLED(CONFIG_IPV6) + tb->fast_v6_rcv_saddr = sk->sk_v6_rcv_saddr; +#endif + } else { + tb->fastreuseport = 0; + } + } else { + if (!reuse) + tb->fastreuse = 0; + if (sk->sk_reuseport) { + /* We didn't match or we don't have fastreuseport set on + * the tb, but we have sk_reuseport set on this socket + * and we know that there are no bind conflicts with + * this socket in this tb, so reset our tb's reuseport + * settings so that any subsequent sockets that match + * our current socket will be put on the fast path. + * + * If we reset we need to set FASTREUSEPORT_STRICT so we + * do extra checking for all subsequent sk_reuseport + * socks. + */ + if (!sk_reuseport_match(tb, sk)) { + tb->fastreuseport = FASTREUSEPORT_STRICT; + tb->fastuid = uid; + tb->fast_rcv_saddr = sk->sk_rcv_saddr; + tb->fast_ipv6_only = ipv6_only_sock(sk); + tb->fast_sk_family = sk->sk_family; +#if IS_ENABLED(CONFIG_IPV6) + tb->fast_v6_rcv_saddr = sk->sk_v6_rcv_saddr; +#endif + } + } else { + tb->fastreuseport = 0; + } + } +} + /* Obtain a reference to a local port for the given sock, * if snum is zero it means select any available local port. * We try to allocate an odd port (and leave even ports for connect()) @@ -308,7 +359,6 @@ int inet_csk_get_port(struct sock *sk, unsigned short snum) struct inet_bind_hashbucket *head; struct net *net = sock_net(sk); struct inet_bind_bucket *tb = NULL; - kuid_t uid = sock_i_uid(sk); int l3mdev; l3mdev = inet_sk_bound_l3mdev(sk); @@ -345,49 +395,8 @@ int inet_csk_get_port(struct sock *sk, unsigned short snum) goto fail_unlock; } success: - if (hlist_empty(&tb->owners)) { - tb->fastreuse = reuse; - if (sk->sk_reuseport) { - tb->fastreuseport = FASTREUSEPORT_ANY; - tb->fastuid = uid; - tb->fast_rcv_saddr = sk->sk_rcv_saddr; - tb->fast_ipv6_only = ipv6_only_sock(sk); - tb->fast_sk_family = sk->sk_family; -#if IS_ENABLED(CONFIG_IPV6) - tb->fast_v6_rcv_saddr = sk->sk_v6_rcv_saddr; -#endif - } else { - tb->fastreuseport = 0; - } - } else { - if (!reuse) - tb->fastreuse = 0; - if (sk->sk_reuseport) { - /* We didn't match or we don't have fastreuseport set on - * the tb, but we have sk_reuseport set on this socket - * and we know that there are no bind conflicts with - * this socket in this tb, so reset our tb's reuseport - * settings so that any subsequent sockets that match - * our current socket will be put on the fast path. - * - * If we reset we need to set FASTREUSEPORT_STRICT so we - * do extra checking for all subsequent sk_reuseport - * socks. - */ - if (!sk_reuseport_match(tb, sk)) { - tb->fastreuseport = FASTREUSEPORT_STRICT; - tb->fastuid = uid; - tb->fast_rcv_saddr = sk->sk_rcv_saddr; - tb->fast_ipv6_only = ipv6_only_sock(sk); - tb->fast_sk_family = sk->sk_family; -#if IS_ENABLED(CONFIG_IPV6) - tb->fast_v6_rcv_saddr = sk->sk_v6_rcv_saddr; -#endif - } - } else { - tb->fastreuseport = 0; - } - } + inet_csk_update_fastreuse(tb, sk); + if (!inet_csk(sk)->icsk_bind_hash) inet_bind_hash(sk, tb, port); WARN_ON(inet_csk(sk)->icsk_bind_hash != tb); -- 2.25.1 -- Disclaimer: https://www.tessares.net/mail-disclaimer/