From patchwork Mon May 22 14:37:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guillaume Nault X-Patchwork-Id: 13250699 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 406FA13AED for ; Mon, 22 May 2023 14:38:05 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD099FD for ; Mon, 22 May 2023 07:38:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684766282; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=D6kaQkoC5xbaGSYGFWfGaRKHibSjXH75c8Xt2vBJoCo=; b=NGpcKC0Os4G6jXRd1xdWhghbPeXo4NWedcQR1+Ah4GuWKzEdl58IQHM+1OJxaaAwf9TrCZ NMVwKPH3VTY2QtSIRSXn8vbL+DxH4ecmS22kasjUwyettpOt5g9jtg0mDayWMoTiXp9WWe nzNQxEWIv2Wo4bWIvODej4P+1Bn8ORY= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-404-zN5PAhdyNxKiFupbh7L3nA-1; Mon, 22 May 2023 10:38:01 -0400 X-MC-Unique: zN5PAhdyNxKiFupbh7L3nA-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-3f603b8eb61so7459445e9.0 for ; Mon, 22 May 2023 07:38:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684766280; x=1687358280; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=D6kaQkoC5xbaGSYGFWfGaRKHibSjXH75c8Xt2vBJoCo=; b=Zix8cGJ5j5voMZadPNQsDYVVKNNpkE4Qm7fEt4bim6mbdGtehoO2WnS1xE6dPPK3dX ubfGj6vrSwI1DmNATNJYxX3uUmDrcmD3medXFXtrMpNcaw1O6TOSY8GIF/WcHOYMcU5i IXwsZrmwmf2sXw/oynweXHIfrZaL9pUdDuxSyUb+R250SauLSHNPpKl5FLDS/L0vshr7 LBP6xrnPRlGF1Skg4SuOzYEVRr48fu1BrDmni5u01Xk02UzJbzOtpGOqeJR2wS5sL7lQ G7ASBzNk6dCoPBd9rtJCZ5bMpXWppU2aIhnAYEBLeM97rQ2K9FMHbsSqF23lqzpXKWjt aTQg== X-Gm-Message-State: AC+VfDyA1V5Vg4P4puoShM+PBK7NPBlfhnsdctoxZvFV3im+7tiC8Dir BzC9YWTUAeln1ApfVF3suad2qTIitp3SuClgGUK/KWmwn4nqGea9iW6sZzJheuI4nCEpKcTeW4x R4CU3k89HQaSFFExY X-Received: by 2002:a1c:f217:0:b0:3f4:2c71:b9ad with SMTP id s23-20020a1cf217000000b003f42c71b9admr7913770wmc.30.1684766279986; Mon, 22 May 2023 07:37:59 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7tUxgI+k4KN8exRUNaiAtiHrDM8MXbZm9wXnlswS65TKF4Cqr3iz34qwgRX7zVKKENNHFh4Q== X-Received: by 2002:a1c:f217:0:b0:3f4:2c71:b9ad with SMTP id s23-20020a1cf217000000b003f42c71b9admr7913755wmc.30.1684766279715; Mon, 22 May 2023 07:37:59 -0700 (PDT) Received: from debian (2a01cb058d652b001c6f8f132b579d2b.ipv6.abo.wanadoo.fr. [2a01:cb05:8d65:2b00:1c6f:8f13:2b57:9d2b]) by smtp.gmail.com with ESMTPSA id i10-20020adfe48a000000b002fed865c55esm7887282wrm.56.2023.05.22.07.37.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 May 2023 07:37:59 -0700 (PDT) Date: Mon, 22 May 2023 16:37:57 +0200 From: Guillaume Nault To: David Miller , Jakub Kicinski , Paolo Abeni , Eric Dumazet Cc: netdev@vger.kernel.org, David Ahern , Willem de Bruijn Subject: [PATCH net-next 1/3] ping: Stop using RTO_ONLINK. Message-ID: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,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 X-Patchwork-Delegate: kuba@kernel.org Define a new helper to figure out the correct route scope to use on TX, depending on socket configuration, ancillary data and send flags. Use this new helper to properly initialise the scope in flowi4_init_output(), instead of overriding tos with the RTO_ONLINK flag. The objective is to eventually remove RTO_ONLINK, which will allow converting .flowi4_tos to dscp_t. Signed-off-by: Guillaume Nault Reviewed-by: David Ahern --- include/net/ip.h | 13 +++++++++++++ net/ipv4/ping.c | 15 +++++---------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/include/net/ip.h b/include/net/ip.h index c3fffaa92d6e..6e262efa0d55 100644 --- a/include/net/ip.h +++ b/include/net/ip.h @@ -242,6 +242,19 @@ static inline struct sk_buff *ip_finish_skb(struct sock *sk, struct flowi4 *fl4) return __ip_make_skb(sk, fl4, &sk->sk_write_queue, &inet_sk(sk)->cork.base); } +/* Get the route scope that should be used when sending a packet. */ +static inline u8 ip_sendmsg_scope(const struct inet_sock *inet, + const struct ipcm_cookie *ipc, + const struct msghdr *msg) +{ + if (sock_flag(&inet->sk, SOCK_LOCALROUTE) || + msg->msg_flags & MSG_DONTROUTE || + (ipc->opt && ipc->opt->opt.is_strictroute)) + return RT_SCOPE_LINK; + + return RT_SCOPE_UNIVERSE; +} + static inline __u8 get_rttos(struct ipcm_cookie* ipc, struct inet_sock *inet) { return (ipc->tos != -1) ? RT_TOS(ipc->tos) : RT_TOS(inet->tos); diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c index 3793c81bda8a..25dd78cee179 100644 --- a/net/ipv4/ping.c +++ b/net/ipv4/ping.c @@ -705,7 +705,7 @@ static int ping_v4_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) struct ip_options_data opt_copy; int free = 0; __be32 saddr, daddr, faddr; - u8 tos; + u8 tos, scope; int err; pr_debug("ping_v4_sendmsg(sk=%p,sk->num=%u)\n", inet, inet->inet_num); @@ -769,11 +769,7 @@ static int ping_v4_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) faddr = ipc.opt->opt.faddr; } tos = get_rttos(&ipc, inet); - if (sock_flag(sk, SOCK_LOCALROUTE) || - (msg->msg_flags & MSG_DONTROUTE) || - (ipc.opt && ipc.opt->opt.is_strictroute)) { - tos |= RTO_ONLINK; - } + scope = ip_sendmsg_scope(inet, &ipc, msg); if (ipv4_is_multicast(daddr)) { if (!ipc.oif || netif_index_is_l3_master(sock_net(sk), ipc.oif)) @@ -783,10 +779,9 @@ static int ping_v4_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) } else if (!ipc.oif) ipc.oif = inet->uc_index; - flowi4_init_output(&fl4, ipc.oif, ipc.sockc.mark, tos, - RT_SCOPE_UNIVERSE, sk->sk_protocol, - inet_sk_flowi_flags(sk), faddr, saddr, 0, 0, - sk->sk_uid); + flowi4_init_output(&fl4, ipc.oif, ipc.sockc.mark, tos, scope, + sk->sk_protocol, inet_sk_flowi_flags(sk), faddr, + saddr, 0, 0, sk->sk_uid); fl4.fl4_icmp_type = user_icmph.type; fl4.fl4_icmp_code = user_icmph.code; From patchwork Mon May 22 14:38:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guillaume Nault X-Patchwork-Id: 13250700 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6E40E14278 for ; Mon, 22 May 2023 14:38:10 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A27E3B0 for ; Mon, 22 May 2023 07:38:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684766287; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=RTuSciyWmk8llf+V0Iz0G5RL536uKsfx/ZPPSBh7olQ=; b=M1dROke7N2LsRDJCnuAiW6Cdtqwle4RbLzPnhkY+HT/NAnrrSGZPlOeRdBr53Bq9WEopqI fhqrY51WZgLXTHzM3wAZ8EJBu26KgKyvRvGR9NDvTrOChhOX7eNngp42Fqg+mP4N7Z3U1R yqz8ZNTcUbIgyV87NbnipYir3R9GMGg= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-610-5zN8m7UANXugsx5VwCno-g-1; Mon, 22 May 2023 10:38:06 -0400 X-MC-Unique: 5zN8m7UANXugsx5VwCno-g-1 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-3f453ff4cdfso21620585e9.2 for ; Mon, 22 May 2023 07:38:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684766285; x=1687358285; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=RTuSciyWmk8llf+V0Iz0G5RL536uKsfx/ZPPSBh7olQ=; b=SYdyXCzPNtK3h+6XtpvrDVPCayUZSd+XljrIohOL60qUtrzFB8Z0R1AXfSnQoaLOQG PxuHkzQMMzpnTb0zV7LS9FKWjCEZRrPoMRJEbWsaTJmaG8kmIW0Sga2pf4msA/L+SouI BNUJL4ERDonirxQ02cJQ6qwvb3TF3RCRk/7UWCPTdQUPHF9N93UDjLvl1rOX2mX+bP8Q Bq2WngRiVMJEZUnGHwABeQcwRQNIPgGu2wSt7mDU7pWAFU6utQixNsUUGYYIEvMOnxOX TlQa9BUa6fwvW5gLwxfQakoOt8BhqGIRN5a50I8+BFbJrggPgy6BZuZS7k4UKHWTF/hm BDsg== X-Gm-Message-State: AC+VfDyLhhPLWn36jwEts9niuWOrV/krvWjaQEby1KUuP6HKPs+NQ38R FfYtPBrIVl0yLAUfE/Nx7RvDuPGdXckwRZcg3tMlznp/cVLU1tNSKgoot/Y9UGanyyDFR1ze2eB ZTXd9W7/ktqbVkHHX X-Received: by 2002:a05:600c:2148:b0:3f4:26d4:91b0 with SMTP id v8-20020a05600c214800b003f426d491b0mr6291023wml.40.1684766285131; Mon, 22 May 2023 07:38:05 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6I/94VDheuFkH1c4Hn8HWC3aXUJUHHYieGf/ecS/F0U9Nux8wN8953Fcag9c/8Ie5tFNBkjA== X-Received: by 2002:a05:600c:2148:b0:3f4:26d4:91b0 with SMTP id v8-20020a05600c214800b003f426d491b0mr6291005wml.40.1684766284786; Mon, 22 May 2023 07:38:04 -0700 (PDT) Received: from debian (2a01cb058d652b001c6f8f132b579d2b.ipv6.abo.wanadoo.fr. [2a01:cb05:8d65:2b00:1c6f:8f13:2b57:9d2b]) by smtp.gmail.com with ESMTPSA id x11-20020a05600c21cb00b003f427db0015sm8588952wmj.38.2023.05.22.07.38.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 May 2023 07:38:04 -0700 (PDT) Date: Mon, 22 May 2023 16:38:02 +0200 From: Guillaume Nault To: David Miller , Jakub Kicinski , Paolo Abeni , Eric Dumazet Cc: netdev@vger.kernel.org, David Ahern , Willem de Bruijn Subject: [PATCH net-next 2/3] raw: Stop using RTO_ONLINK. Message-ID: <6ca7a70859803ff272cc965409856de354fa4e6c.1684764727.git.gnault@redhat.com> References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,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 X-Patchwork-Delegate: kuba@kernel.org Use ip_sendmsg_scope() to properly initialise the scope in flowi4_init_output(), instead of overriding tos with the RTO_ONLINK flag. The objective is to eventually remove RTO_ONLINK, which will allow converting .flowi4_tos to dscp_t. The MSG_DONTROUTE and SOCK_LOCALROUTE cases were already handled by raw_sendmsg() (SOCK_LOCALROUTE was handled by the RT_CONN_FLAGS*() macros called by get_rtconn_flags()). However, opt.is_strictroute wasn't taken into account. Therefore, a side effect of this patch is to now honour opt.is_strictroute, and thus align raw_sendmsg() with ping_v4_sendmsg() and udp_sendmsg(). Since raw_sendmsg() was the only user of get_rtconn_flags(), we can now remove this function. Signed-off-by: Guillaume Nault Reviewed-by: David Ahern --- include/net/ip.h | 5 ----- net/ipv4/raw.c | 10 ++++------ 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/include/net/ip.h b/include/net/ip.h index 6e262efa0d55..fab910be252c 100644 --- a/include/net/ip.h +++ b/include/net/ip.h @@ -260,11 +260,6 @@ static inline __u8 get_rttos(struct ipcm_cookie* ipc, struct inet_sock *inet) return (ipc->tos != -1) ? RT_TOS(ipc->tos) : RT_TOS(inet->tos); } -static inline __u8 get_rtconn_flags(struct ipcm_cookie* ipc, struct sock* sk) -{ - return (ipc->tos != -1) ? RT_CONN_FLAGS_TOS(sk, ipc->tos) : RT_CONN_FLAGS(sk); -} - /* datagram.c */ int __ip4_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len); int ip4_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len); diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c index ff712bf2a98d..8b7b5c842bdd 100644 --- a/net/ipv4/raw.c +++ b/net/ipv4/raw.c @@ -476,10 +476,10 @@ static int raw_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) struct ipcm_cookie ipc; struct rtable *rt = NULL; struct flowi4 fl4; + u8 tos, scope; int free = 0; __be32 daddr; __be32 saddr; - u8 tos; int err; struct ip_options_data opt_copy; struct raw_frag_vec rfv; @@ -572,9 +572,8 @@ static int raw_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) daddr = ipc.opt->opt.faddr; } } - tos = get_rtconn_flags(&ipc, sk); - if (msg->msg_flags & MSG_DONTROUTE) - tos |= RTO_ONLINK; + tos = get_rttos(&ipc, inet); + scope = ip_sendmsg_scope(inet, &ipc, msg); if (ipv4_is_multicast(daddr)) { if (!ipc.oif || netif_index_is_l3_master(sock_net(sk), ipc.oif)) @@ -597,8 +596,7 @@ static int raw_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) } } - flowi4_init_output(&fl4, ipc.oif, ipc.sockc.mark, tos, - RT_SCOPE_UNIVERSE, + flowi4_init_output(&fl4, ipc.oif, ipc.sockc.mark, tos, scope, hdrincl ? IPPROTO_RAW : sk->sk_protocol, inet_sk_flowi_flags(sk) | (hdrincl ? FLOWI_FLAG_KNOWN_NH : 0), From patchwork Mon May 22 14:38:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guillaume Nault X-Patchwork-Id: 13250701 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D918714278 for ; Mon, 22 May 2023 14:38:14 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B942F4 for ; Mon, 22 May 2023 07:38:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684766292; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=CKRD9+9UtmyjsQhADPVn0alMuxSJCeFi3wku7C3YHJs=; b=NngFiXCvGmGzWrJCuZwT2Vn6pobTO5wmod4Nay7H1tJLhc7MYpidd+Nhc09PKMOUEx9UQo grinfK1kXILoK/fu1usUZtpK0jNjtV7xMwj9XYh8ecGoZ83q4Ty427IB96Fw/nUpU6UcHT vtkSz/IwpZPJC7cGkWJaBo+tIEhLZ18= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-180-bSK7c7msP_el4UTffV2Qfw-1; Mon, 22 May 2023 10:38:11 -0400 X-MC-Unique: bSK7c7msP_el4UTffV2Qfw-1 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-30953bcb997so1233708f8f.2 for ; Mon, 22 May 2023 07:38:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684766289; x=1687358289; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=CKRD9+9UtmyjsQhADPVn0alMuxSJCeFi3wku7C3YHJs=; b=ACX3LdUr9LgINT+WXeH6I0i0PvPTpbZQ8wFTAZOPfOgRtb7+pekc4TgP3T3rNQ9LOZ rdgS/B5fg6c7ZFhKtQEkQnm1IOWlsB5dsoPaWugJTDKM+E7TNBUkw2f90gev+LiQmmM3 tayQkPhWD+kD0DenKGKfGbcB2fY2SxPRklH/KLWusyn94Foh2JxfQLJ7dKVD9U9/htej BC5lCJTp9gFMH/VIeOrnLUwjf20MSBc/yVQ0UWbRfBXhxfhOHgNj3ELT6oFEX69NS515 zGfqbTbA7dPsPcUZKlEgM/tno24FiR6TA5pDlIU9Vb0lUlqcwvY1mcl3MHGG41ie2ka4 vzIg== X-Gm-Message-State: AC+VfDwXg2PwBsL/B1NCVIZS2J14ofqYBN/RMshYsD3hCrLojUgVHaeC JSbI0aXb5gGSRh1Gx/h3ZLOaaTEXI25kZF9C/QipUsElo9ylqrN/vfBrYoVWQ67w3Hj2CA1PoJe 90fQDELIwskbNCsp2OxK3N3q7 X-Received: by 2002:adf:e8ce:0:b0:309:50e7:7d0 with SMTP id k14-20020adfe8ce000000b0030950e707d0mr6982192wrn.31.1684766289453; Mon, 22 May 2023 07:38:09 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6v/wN27J0lhtqEjlrhqIxd6gqles27SwZjQ9Uz9n3r+yWZla5iP8r9raykGCTtsaBwIi9USA== X-Received: by 2002:adf:e8ce:0:b0:309:50e7:7d0 with SMTP id k14-20020adfe8ce000000b0030950e707d0mr6982181wrn.31.1684766289290; Mon, 22 May 2023 07:38:09 -0700 (PDT) Received: from debian (2a01cb058d652b001c6f8f132b579d2b.ipv6.abo.wanadoo.fr. [2a01:cb05:8d65:2b00:1c6f:8f13:2b57:9d2b]) by smtp.gmail.com with ESMTPSA id c11-20020adfe74b000000b00306281cfa59sm7994843wrn.47.2023.05.22.07.38.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 May 2023 07:38:08 -0700 (PDT) Date: Mon, 22 May 2023 16:38:07 +0200 From: Guillaume Nault To: David Miller , Jakub Kicinski , Paolo Abeni , Eric Dumazet Cc: netdev@vger.kernel.org, David Ahern , Willem de Bruijn Subject: [PATCH net-next 3/3] udp: Stop using RTO_ONLINK. Message-ID: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,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 X-Patchwork-Delegate: kuba@kernel.org Use ip_sendmsg_scope() to properly initialise the scope in flowi4_init_output(), instead of overriding tos with the RTO_ONLINK flag. The objective is to eventually remove RTO_ONLINK, which will allow converting .flowi4_tos to dscp_t. Now that the scope is determined by ip_sendmsg_scope(), we need to check its result to set the 'connected' variable. Signed-off-by: Guillaume Nault Reviewed-by: David Ahern --- net/ipv4/udp.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c index aa32afd871ee..64750baa55d6 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c @@ -1062,8 +1062,8 @@ int udp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) int free = 0; int connected = 0; __be32 daddr, faddr, saddr; + u8 tos, scope; __be16 dport; - u8 tos; int err, is_udplite = IS_UDPLITE(sk); int corkreq = READ_ONCE(up->corkflag) || msg->msg_flags&MSG_MORE; int (*getfrag)(void *, char *, int, int, int, struct sk_buff *); @@ -1183,12 +1183,9 @@ int udp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) connected = 0; } tos = get_rttos(&ipc, inet); - if (sock_flag(sk, SOCK_LOCALROUTE) || - (msg->msg_flags & MSG_DONTROUTE) || - (ipc.opt && ipc.opt->opt.is_strictroute)) { - tos |= RTO_ONLINK; + scope = ip_sendmsg_scope(inet, &ipc, msg); + if (scope == RT_SCOPE_LINK) connected = 0; - } if (ipv4_is_multicast(daddr)) { if (!ipc.oif || netif_index_is_l3_master(sock_net(sk), ipc.oif)) @@ -1221,11 +1218,9 @@ int udp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) fl4 = &fl4_stack; - flowi4_init_output(fl4, ipc.oif, ipc.sockc.mark, tos, - RT_SCOPE_UNIVERSE, sk->sk_protocol, - flow_flags, - faddr, saddr, dport, inet->inet_sport, - sk->sk_uid); + flowi4_init_output(fl4, ipc.oif, ipc.sockc.mark, tos, scope, + sk->sk_protocol, flow_flags, faddr, saddr, + dport, inet->inet_sport, sk->sk_uid); security_sk_classify_flow(sk, flowi4_to_flowi_common(fl4)); rt = ip_route_output_flow(net, fl4, sk);