From patchwork Mon Dec 16 17:21:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guillaume Nault X-Patchwork-Id: 13910117 X-Patchwork-Delegate: kuba@kernel.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 0FCEA20627A for ; Mon, 16 Dec 2024 17:21:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734369712; cv=none; b=hO9fBrYjtWD4PWD5hOgRuw0d4RymyDaRnhsK+SU251CeJheywNIUS7nh8TDMIvwQVoiLngPh42ow/usghcxiyYq2o1poqMF28vozThQVVnX1kejre565YA3nwkvt9NTYzhI6kAsyPwSe/cmLZv33sF2VXNbqtbYMTzC7NPLnYxE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734369712; c=relaxed/simple; bh=iei1+wYHEYge/vk8H7BY/Bl0sc/gBOefFk5SR5ZC/F8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=WKDlOguylAMLzw7tcqd7iIaK8RtuF2gFmKJW/Zvzob9BkcA5+ugtkR+SVD6ajmq9XxhgSpmdHyAGDqtucOO1mCPxftt1B3Gxz37GonHzLPQpYpJyi/WygWDXmWJt0rlxdw5e+vobhDAU8QkQy7y2LijqEWUFtF4axjPXq7i0oio= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=GtbhF7Bo; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="GtbhF7Bo" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734369710; 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=st1qL1MqDdDk9pBBznT0qGID2b000DxTi0tlDFIqdJg=; b=GtbhF7BobXtGdB+tvUok7K+XXXU0K1WkZKhMrihPSi6z77PJVhgjA4ysbzZXEL/FFSqRFA /2qhR6GtpirIdz7K5iAl/VohYbpFKoRTjsTvEVTaMl8NtBuM7cHLNawUEsmUGZ3nYHRnVe AGhVHw2V8YwRUIFvCGrPycvS9hGGmtk= 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-30-BlppPgzCPd6cZuJN6zrzGQ-1; Mon, 16 Dec 2024 12:21:48 -0500 X-MC-Unique: BlppPgzCPd6cZuJN6zrzGQ-1 X-Mimecast-MFC-AGG-ID: BlppPgzCPd6cZuJN6zrzGQ Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-3862c67763dso1762970f8f.3 for ; Mon, 16 Dec 2024 09:21:47 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734369706; x=1734974506; 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=st1qL1MqDdDk9pBBznT0qGID2b000DxTi0tlDFIqdJg=; b=sBigfD6IYOPAJs+b8AjYZMFDbZOYnL0fFhy3n7CxJrVp/AKVGP2qDgAgcStu7ydjiW 84UiOXxHgEfQwvU4cIIVat8o3emRurvlmsfvnynSHATpNldoTb+T+PRi0uDNI9UxIbyY FGdnU5118OB05jfAQNX9Bzm6HYpklX1yUtaFUPt+eddliP2CfVYGwQTAchduuex9UZcV 92UNCTjivsrNam8ELvbzWo3Ehdpr8r+dI8JAXXl5nDV/2I1+gG6iolEWIrraGgFE68FH 7Nf+lCrdoeiKtBfZmEPQuqGx6LM10VGpIX0uP3uHcdSXCsZO33F2IlU/d5o5gWfj7iWc MRfA== X-Gm-Message-State: AOJu0Yx3Sk0ZgqmuSo9h2eCRdPw+h13OTTzngZ4nQjmpwu1Lh578uy2S zC1exkxE07FVOc45FAXvgKp4S+m+itEvvDZaYg9RJawJqTW8OAbJ40SA+R1VlQrn2ykrXR32IgY tyB2aPxk8b0cr7ZxQmVXj6NH7AeZHAzGYoOhGmCec11s44cO9LwjNGA== X-Gm-Gg: ASbGncu8pbfAAFgDbvFNgwGEanKq83b2pv+gviTegitjR0k4Ypwl6nkaJ4TIKT/kDMT VaXxAhJsROP0hyB2rf0U5slYhS3VECq1r6dXnlyAAj/SIxmwNBwX/Mfkyq3Y6BdPhi3vMFvwrna 5mh8Zd0q8Mg1X9Wuees1+0mAU1iWQcDxRpAz3rDIxad+f6tdEcTBr7R+j60r5g+Il3n7oiiBOcE k5Uz3mFRND+k4h+cesQwqUnexSDftDpKwgHmHZ6YigfRWDJDMGF9Ug/a2wLc7T6S7p0M7dA3wNo EvCQFhF3IYOK7QYw/XWGNymzjdESc7BXCLzH X-Received: by 2002:a05:6000:2ab:b0:386:4a24:18f2 with SMTP id ffacd0b85a97d-38880ad9d20mr11101036f8f.25.1734369706557; Mon, 16 Dec 2024 09:21:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IEEVQNXQ3WNimF5b16gdSfFpjS7TwXA7eERR1NwldtHUOfUppNT2eNYNx8OFuLIIntFHCsWkA== X-Received: by 2002:a05:6000:2ab:b0:386:4a24:18f2 with SMTP id ffacd0b85a97d-38880ad9d20mr11101013f8f.25.1734369706238; Mon, 16 Dec 2024 09:21:46 -0800 (PST) Received: from debian (2a01cb058d23d600c2f0ae4aed6d33eb.ipv6.abo.wanadoo.fr. [2a01:cb05:8d23:d600:c2f0:ae4a:ed6d:33eb]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-388c8047089sm8830458f8f.85.2024.12.16.09.21.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Dec 2024 09:21:45 -0800 (PST) Date: Mon, 16 Dec 2024 18:21:44 +0100 From: Guillaume Nault To: David Miller , Jakub Kicinski , Paolo Abeni , Eric Dumazet Cc: netdev@vger.kernel.org, Simon Horman , David Ahern , James Chapman , Tom Parkin Subject: [PATCH net-next 1/5] ipv4: Define inet_sk_init_flowi4() and use it in inet_sk_rebuild_header(). 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-Patchwork-Delegate: kuba@kernel.org IPv4 code commonly has to initialise a flowi4 structure from an IPv4 socket. This requires looking at potential IPv4 options to set the proper destination address, call flowi4_init_output() with the correct set of parameters and run the sk_classify_flow security hook. Instead of reimplementing these operations in different parts of the stack, let's define inet_sk_init_flowi4() which does all these operations. The first user is inet_sk_rebuild_header(), where inet_sk_init_flowi4() replaces ip_route_output_ports(). Unlike ip_route_output_ports(), which sets the flowi4 structure and performs the route lookup in one go, inet_sk_init_flowi4() only initialises the flow. The route lookup is then done by ip_route_output_flow(). Decoupling flow initialisation from route lookup makes this new interface applicable more broadly as it will allow some users to overwrite specific struct flowi4 members before the route lookup. Signed-off-by: Guillaume Nault --- include/net/route.h | 28 ++++++++++++++++++++++++++++ net/ipv4/af_inet.c | 14 ++------------ 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/include/net/route.h b/include/net/route.h index 84cb1e04f5cd..95805dd4ac13 100644 --- a/include/net/route.h +++ b/include/net/route.h @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -129,6 +130,33 @@ struct in_device; int ip_rt_init(void); void rt_cache_flush(struct net *net); void rt_flush_dev(struct net_device *dev); + +static inline void inet_sk_init_flowi4(const struct inet_sock *inet, + struct flowi4 *fl4) +{ + const struct ip_options_rcu *ip4_opt; + const struct sock *sk; + __be32 daddr; + + rcu_read_lock(); + ip4_opt = rcu_dereference(inet->inet_opt); + + /* Source routing option overrides the socket destination address */ + if (ip4_opt && ip4_opt->opt.srr) + daddr = ip4_opt->opt.faddr; + else + daddr = inet->inet_daddr; + rcu_read_unlock(); + + sk = &inet->sk; + flowi4_init_output(fl4, sk->sk_bound_dev_if, READ_ONCE(sk->sk_mark), + ip_sock_rt_tos(sk), ip_sock_rt_scope(sk), + sk->sk_protocol, inet_sk_flowi_flags(sk), daddr, + inet->inet_saddr, inet->inet_dport, + inet->inet_sport, sk->sk_uid); + security_sk_classify_flow(sk, flowi4_to_flowi_common(fl4)); +} + struct rtable *ip_route_output_key_hash(struct net *net, struct flowi4 *flp, const struct sk_buff *skb); struct rtable *ip_route_output_key_hash_rcu(struct net *net, struct flowi4 *flp, diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c index 8095e82de808..21f46ee7b6e9 100644 --- a/net/ipv4/af_inet.c +++ b/net/ipv4/af_inet.c @@ -1309,8 +1309,6 @@ int inet_sk_rebuild_header(struct sock *sk) { struct rtable *rt = dst_rtable(__sk_dst_check(sk, 0)); struct inet_sock *inet = inet_sk(sk); - __be32 daddr; - struct ip_options_rcu *inet_opt; struct flowi4 *fl4; int err; @@ -1319,17 +1317,9 @@ int inet_sk_rebuild_header(struct sock *sk) return 0; /* Reroute. */ - rcu_read_lock(); - inet_opt = rcu_dereference(inet->inet_opt); - daddr = inet->inet_daddr; - if (inet_opt && inet_opt->opt.srr) - daddr = inet_opt->opt.faddr; - rcu_read_unlock(); fl4 = &inet->cork.fl.u.ip4; - rt = ip_route_output_ports(sock_net(sk), fl4, sk, daddr, inet->inet_saddr, - inet->inet_dport, inet->inet_sport, - sk->sk_protocol, ip_sock_rt_tos(sk), - sk->sk_bound_dev_if); + inet_sk_init_flowi4(inet, fl4); + rt = ip_route_output_flow(sock_net(sk), fl4, sk); if (!IS_ERR(rt)) { err = 0; sk_setup_caps(sk, &rt->dst); From patchwork Mon Dec 16 17:21:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guillaume Nault X-Patchwork-Id: 13910118 X-Patchwork-Delegate: kuba@kernel.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 40F4F206270 for ; Mon, 16 Dec 2024 17:21:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734369713; cv=none; b=o9ePkZb4C0ZLguNJ3EepKjGByjwDj/AvWwJ3oOzUj2lTusm4SRXeWBLvWT3ngJBasj9GoziM3AVxJJH9Vp5Xp6I4CzEEG8lojxomS3uVOMC/cCr59O4BXh6FuJwXNHdaxP1WtYaEuvXPmUiS8cpfUmGlmSYM05yJHKaJUIKsUwE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734369713; c=relaxed/simple; bh=0T3m7DWtj2xPvjHBKs0WgTrAxHby7T18hSfCHbMu3Ys=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=s0fbsbcGV/uprFQCRwFTW9N7eQ7w9bbrZf3UmB+xxZlO07rPudcwjaKK2aq9SJJVqtnb8AcR6Zd+DB1rIQCsSxjVT26SQgWjPZdKJecS2jIxkXRruqiGKvx8EWYdjjrMLWap+yiUwU7x8I44W02ZGiavHmrkfdIqe1j2FXUbalk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=HLQOMkb8; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="HLQOMkb8" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734369711; 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=MSVrmH0+RECg5FGtjBvpruW9G5NzkpNGEwyNMXfXPww=; b=HLQOMkb85Czlr5cYGM2YOqjnbN4VVLoKdJJ/hV7ODgIoPKVMQDc41UnlJ0jsdd7UBIZo+k qRT5lrehP/yGYoIu7QxDF6ApRhcNH0TKEX77nAapopRPSPOv+vfvsX5J7v+86G6K7ztWkI VZwpX5aDeGJYD9HxGfhyDC2kU74LdYw= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-393-NFL8K8rBMWWIkGxrlW--iQ-1; Mon, 16 Dec 2024 12:21:50 -0500 X-MC-Unique: NFL8K8rBMWWIkGxrlW--iQ-1 X-Mimecast-MFC-AGG-ID: NFL8K8rBMWWIkGxrlW--iQ Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-385e2579507so1872727f8f.1 for ; Mon, 16 Dec 2024 09:21:49 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734369709; x=1734974509; 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=MSVrmH0+RECg5FGtjBvpruW9G5NzkpNGEwyNMXfXPww=; b=tTqi2SnDvr1ZuN7QcIFvU9+eUmHxwPOCiLdmAw1A/qcr7Fcj3xt6hskPWNo1jRrxNB SdIgr7cQz9uAcGutDLThV322nWQG4r6s+G8e3QBW4MBXMRniUlAz2SF2TjF0PCZBkTv3 fdie4n3BH94NXEcxpojt0ielxukFK2HCjv325Vnk3VgHqw6ELVjQVzxkmpcQ4KGM11UF KV6bBF0Q1z5r3UNirhiJFH9kDlm/Uh7TO5S/Vm9bY6SriMf2hKxXWaadmfSJN0kYEbQp 8fstqYdMQ8OkDqASGQAeLfrXbbDVpUK/0+sOw7L7w1oO5Me9z+ZRXQ2Z970fhZj6Mzqt +zFg== X-Gm-Message-State: AOJu0YwUeDJ+EiR2W92Z99ghyRIKEDfgABbNH+XQFqQ1Tig9649TZlLD oytMnN1Gy5UalxWi3kx5SftJWkFHAm/cMWi8CEKAZvINJL0eGFVkyYe4Q3nWI3H28X/efcG9FDr fC6hmypi6XFCtz9YRv6FqybfC44+CzsbDwiEGjB5ruHucgrua35wIVA== X-Gm-Gg: ASbGnculGzbtGkF2EHueeXWcf2GRYGfvbyZpbOHh9t4nv3LfstnnUP+0tLRkRen22iX 9X9ap6yul+sJDC1DUGL5QvW3Z1Oy6nw8uy7xBmyi2BZ7k+Lo6Q4X7q0e4aeKgYdXfYrDJuFMytk qiMKzBIHW6hl1/gmtkIDH8Pd6lQnL5dmqp6wQ04MrI/eQtwhVIOdt7Q/dnBvknoABL/rtS8edpW QBSQml36Zll24fkTF7ImNzcXrKbwLpqGfnpreJOKCD4zfP1xvlA4BtRjHBjKOyufOtQfeOUCOsh rNAc16DO3o8YHZs80KNUrqnTBMQB4E6EsFCX X-Received: by 2002:a05:6000:2a3:b0:385:f1f2:13ee with SMTP id ffacd0b85a97d-3888e0b8b9fmr12230044f8f.46.1734369708919; Mon, 16 Dec 2024 09:21:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IGzTz63J/CTegK/9PB6VbZ0qf4PcDor8ZwlrYNwxZIwwMD5hacbGegNHaBIEbBz/84mEzh5+g== X-Received: by 2002:a05:6000:2a3:b0:385:f1f2:13ee with SMTP id ffacd0b85a97d-3888e0b8b9fmr12230023f8f.46.1734369708558; Mon, 16 Dec 2024 09:21:48 -0800 (PST) Received: from debian (2a01cb058d23d600c2f0ae4aed6d33eb.ipv6.abo.wanadoo.fr. [2a01:cb05:8d23:d600:c2f0:ae4a:ed6d:33eb]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-388c806115asm8618604f8f.107.2024.12.16.09.21.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Dec 2024 09:21:48 -0800 (PST) Date: Mon, 16 Dec 2024 18:21:46 +0100 From: Guillaume Nault To: David Miller , Jakub Kicinski , Paolo Abeni , Eric Dumazet Cc: netdev@vger.kernel.org, Simon Horman , David Ahern Subject: [PATCH net-next 2/5] ipv4: Use inet_sk_init_flowi4() in ip4_datagram_release_cb(). Message-ID: <9c326b8d9e919478f7952b21473d31da07eba2dd.1734357769.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-Patchwork-Delegate: kuba@kernel.org Use inet_sk_init_flowi4() to automatically initialise the flowi4 structure in ip4_datagram_release_cb() instead of passing parameters manually to ip_route_output_ports(). Signed-off-by: Guillaume Nault --- net/ipv4/datagram.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/net/ipv4/datagram.c b/net/ipv4/datagram.c index 4aca1f05edd3..4b5bc6eb52e7 100644 --- a/net/ipv4/datagram.c +++ b/net/ipv4/datagram.c @@ -102,8 +102,6 @@ EXPORT_SYMBOL(ip4_datagram_connect); void ip4_datagram_release_cb(struct sock *sk) { const struct inet_sock *inet = inet_sk(sk); - const struct ip_options_rcu *inet_opt; - __be32 daddr = inet->inet_daddr; struct dst_entry *dst; struct flowi4 fl4; struct rtable *rt; @@ -115,14 +113,9 @@ void ip4_datagram_release_cb(struct sock *sk) rcu_read_unlock(); return; } - inet_opt = rcu_dereference(inet->inet_opt); - if (inet_opt && inet_opt->opt.srr) - daddr = inet_opt->opt.faddr; - rt = ip_route_output_ports(sock_net(sk), &fl4, sk, daddr, - inet->inet_saddr, inet->inet_dport, - inet->inet_sport, sk->sk_protocol, - ip_sock_rt_tos(sk), sk->sk_bound_dev_if); + inet_sk_init_flowi4(inet, &fl4); + rt = ip_route_output_flow(sock_net(sk), &fl4, sk); dst = !IS_ERR(rt) ? &rt->dst : NULL; sk_dst_set(sk, dst); From patchwork Mon Dec 16 17:21:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guillaume Nault X-Patchwork-Id: 13910119 X-Patchwork-Delegate: kuba@kernel.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 1E8DF207667 for ; Mon, 16 Dec 2024 17:21:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734369716; cv=none; b=Tw/TAFgRI91pDrOANejAfaYVFMJx8OAeBTB1DSWR/4ArxwP03nd+BkJZwyAYaBW4pGvgOwwBrHQ3uEQOq2qG7xMgb0sO5wQGnKF5XG2KTuXRsjfoQ/y6ShzI7GgtCyJIOIK0TtInD2Fz+B1Fg4/6VvuK51RTpcpqcmzLb3B5yiM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734369716; c=relaxed/simple; bh=GhsKH1lism3koNZhDFr7+JzBW+W5F30SqsWHWUbO9tk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=KSxPy41ro/zG1RJEhp91NPeYdU/e3XyzU4Q648Bm+EaRmOmyafmghjQAa7tNYISo7IGzGovAtv79y2gfl8lOShDPwaKvo5zX0FDKb5IdpFPKgz+qCaT3IYDPmMSVX/J/0Avs5eEO3lU4PFyNyRc2J0Q/qZaud17e3G44qdG6OFo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=e8ycj1vY; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="e8ycj1vY" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734369714; 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=HbhLu1AxpDq3DtGf4C1YXvVtju21BTD9BNimj8/xtAE=; b=e8ycj1vYUddZS5DKi4IkFUzWG0LpDbe0NA/5Pfs1TaNCSDwsbMaqIfFu3JWYT/yOOaZJe6 At6BiM/JwwfuiQXGDZJAvGKKGbJHwoUKbJGEcAHva5TEnzt6FiQVJtiWosfbKw0SFpaIxa YkAcBvaQorXnr6YILiCwhhOLHk1qYJU= 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-37-F2LYWsYPNjqPYXTT7yMzmQ-1; Mon, 16 Dec 2024 12:21:53 -0500 X-MC-Unique: F2LYWsYPNjqPYXTT7yMzmQ-1 X-Mimecast-MFC-AGG-ID: F2LYWsYPNjqPYXTT7yMzmQ Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-43631d8d9c7so16318265e9.1 for ; Mon, 16 Dec 2024 09:21:52 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734369711; x=1734974511; 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=HbhLu1AxpDq3DtGf4C1YXvVtju21BTD9BNimj8/xtAE=; b=ZnYXZRlJcg5o86ieMnLG5cr93l2Ucj9wSIw14M2u3Rg2Ufufu1k1vxQbKaxeBtPqLD tlEnawnNWT/Tgs7qV5Yee6pE4M3q3gS5uH/iRm1RnzGb1ITkqRVpw1se59y/rxTMAZys TF1w0SH1sUUhPEAQLgONEiCCmMPsmb4xKi8Xq6NVeJBEwqbuNfRwKOflLlMwcSYVZ6jU TIM+ZR5buVh+iyufeSlIm+zmORpHNbYFKGSuk2yjxhr5IVG9gLn/Y2kUi/MqEPv1BI2L 9lm48WOLS3mISATYohH5vvYqs5hd9gdAON9xSeWUDAQehBhZ/N1LIL9sv5aL77rLPqtB O3mg== X-Gm-Message-State: AOJu0YwdDQW8GS//goOtxtkViyY+NTOliS4BCcR+RZNPSgqf1eb0a2FF zI4Cm+YVoOVbFO7ZE45bAUS6dTr5zzKRUOrZk5ogjLkYpiS5bapsgDY2Ari1cjLXxLr22dv/pRh hsR8tYQrSbXJd7fb+lREAl0tpIifJ98GIcXEpkzQGLH8613e4DETAmEQyzZYtFA== X-Gm-Gg: ASbGncuticJXwpVse3rx4vrSdc/0455ikaRx53hqmG60z6owE6l+8jR2PV40zJTunda 520yY1P6hv9Mnp2wNmvsdnqh0lt6u/g1IDx48WPqA+IRBlEG5gNudVONmgV4J+X6V25uK5Bcuzm Nw3H6kpblC+WBZR9qqiYtVWumH9QQlF6DqC7Hpr4Fef/QsV3sx6nMYyZa/+ZykPdBokikYIyOSf 8DaSrtlhQJbDecNrWVghtaHUyqP+lMH4nC+3JJrTb0ojr171dCbnT6BBjavBaqMzsooxDQ7U1AN /uTszHnWYAMTsIS2ZlMJ5HOlJnh1LRNPMR/c X-Received: by 2002:a05:600c:3c82:b0:42c:b8c9:16c8 with SMTP id 5b1f17b1804b1-4364817be68mr1254395e9.10.1734369711504; Mon, 16 Dec 2024 09:21:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IEY243qtVuKB/yoZ4aeiqUHkfPxokTsjrRcmk6PVSbj+8NggExIj/qcilEU8d1BrIZNEDDuLw== X-Received: by 2002:a05:600c:3c82:b0:42c:b8c9:16c8 with SMTP id 5b1f17b1804b1-4364817be68mr1254145e9.10.1734369711170; Mon, 16 Dec 2024 09:21:51 -0800 (PST) Received: from debian (2a01cb058d23d600c2f0ae4aed6d33eb.ipv6.abo.wanadoo.fr. [2a01:cb05:8d23:d600:c2f0:ae4a:ed6d:33eb]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-388c801a8b0sm8619473f8f.53.2024.12.16.09.21.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Dec 2024 09:21:50 -0800 (PST) Date: Mon, 16 Dec 2024 18:21:48 +0100 From: Guillaume Nault To: David Miller , Jakub Kicinski , Paolo Abeni , Eric Dumazet Cc: netdev@vger.kernel.org, Simon Horman , David Ahern Subject: [PATCH net-next 3/5] ipv4: Use inet_sk_init_flowi4() in inet_csk_rebuild_route(). 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-Patchwork-Delegate: kuba@kernel.org Use inet_sk_init_flowi4() to automatically initialise the flowi4 structure in inet_csk_rebuild_route() instead of passing parameters manually to ip_route_output_ports(). Signed-off-by: Guillaume Nault --- net/ipv4/inet_connection_sock.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c index 6872b5aff73e..e4decfb270fa 100644 --- a/net/ipv4/inet_connection_sock.c +++ b/net/ipv4/inet_connection_sock.c @@ -1561,20 +1561,13 @@ EXPORT_SYMBOL_GPL(inet_csk_addr2sockaddr); static struct dst_entry *inet_csk_rebuild_route(struct sock *sk, struct flowi *fl) { const struct inet_sock *inet = inet_sk(sk); - const struct ip_options_rcu *inet_opt; - __be32 daddr = inet->inet_daddr; struct flowi4 *fl4; struct rtable *rt; rcu_read_lock(); - inet_opt = rcu_dereference(inet->inet_opt); - if (inet_opt && inet_opt->opt.srr) - daddr = inet_opt->opt.faddr; fl4 = &fl->u.ip4; - rt = ip_route_output_ports(sock_net(sk), fl4, sk, daddr, - inet->inet_saddr, inet->inet_dport, - inet->inet_sport, sk->sk_protocol, - ip_sock_rt_tos(sk), sk->sk_bound_dev_if); + inet_sk_init_flowi4(inet, fl4); + rt = ip_route_output_flow(sock_net(sk), fl4, sk); if (IS_ERR(rt)) rt = NULL; if (rt) From patchwork Mon Dec 16 17:21:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guillaume Nault X-Patchwork-Id: 13910120 X-Patchwork-Delegate: kuba@kernel.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 99BE82066DB for ; Mon, 16 Dec 2024 17:21:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734369719; cv=none; b=h2c7eCv0fZ1BeF1m2NxvZ4VoUTuL+uWZXaL3t62WFx813jzWe5WizYkMAN7UD3RKUkLhusE9LpcFt/qaxkYFtB99az/tr1WPnBVF7SLeqIRdW6rFbApBOdML6cD1lRuCaQZiWWAdT2nMYlT2U6en3YFRfmsCOq4tyMjP4A9UJ7s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734369719; c=relaxed/simple; bh=R2spen+iGC3vfSQMtgj4oTZLwFwgxCKaBg/gCbssdrU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=O56vwL0V4/wOU439Yle4f/t04B1ZheJLQH5V2b9D25vw8E5QN4P3uaw1yaUfuDEj+t6jdTzCctkIANDOc4s4+i+Q1QL6apqqcXEI28GqDl76sXGGXaD1CKH4wmGRMgUB9hfAhrnTMLsAIyLW7L2z2JkNzGYjVWcaxBtbToMzwsk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=B6ZUcFRU; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="B6ZUcFRU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734369716; 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=k67C8teWCVR8gnbKmWvcLA6Fxm1e2FNSeXMozgh6UQg=; b=B6ZUcFRUpE6saqw9WA+tuxjc61+VmvVeZF8yq+gSnOjUFselxJttDmfOwkwOs2Ign5qKFK aAW4C4Umsby6JuXHha/AMYK/OuiDdkjIRQ7RXHViHiO6CAr9CnzRxu2ytt1JTqqZP1xxIa RVv7hRDcO3tC+zRgsNBo1NfRIcdMgZQ= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-351-cLJ4MRcjOVSrum8pCm3QmQ-1; Mon, 16 Dec 2024 12:21:55 -0500 X-MC-Unique: cLJ4MRcjOVSrum8pCm3QmQ-1 X-Mimecast-MFC-AGG-ID: cLJ4MRcjOVSrum8pCm3QmQ Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-385e27c5949so2664698f8f.3 for ; Mon, 16 Dec 2024 09:21:55 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734369714; x=1734974514; 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=k67C8teWCVR8gnbKmWvcLA6Fxm1e2FNSeXMozgh6UQg=; b=P+j0GDz0rYVAuU0GJhYnvN3ohOCH/QWjsOuecASmqh1+bnpvhWMsP9PuiFGMCIhNVl 1VQykBn5NNDAU1c6H4VvQz3tlBwKJI1pbVt2zT7cIPFijpbBfTEsMFKJCE7Oy8PTrwLW hXd8iyYIyUqJw7lrtX3vI2v4vQsd/DSNCuVC3525Dv+BB7ncLslc8+hKWbAwfq5Q6Boz +gRggFid0t6mkUuC98k1VSLzdViEYkvRodliURrFGloj0DyTZUbeWrT7LNDugk0hdMvC 83Qete84CXX9zs7R7Nh1EqyxxcWz4HA/c4ikF4nbdyLgaDT7kdSv9LiW5moSk/ppi4El UuhA== X-Gm-Message-State: AOJu0Yx+IzJAzRa9b8N50YksN1QjliighR2pnPgc8N7mbwQGVTJNT9g5 TNp0+zRN+tp2F0KjHuOZ7mfUY5j7YF4qUGRg9wGDha7+GjmvNElRC6i59xRRPW4NPMvVV1cSJS7 MGCQV6V1To4wb1QK50fFqfPQKrUldL4ok77bHw8Gmxr64olN2xDf0YQ== X-Gm-Gg: ASbGncu2y8OrinNrCEQAN2ZZ8R2fCu8lrXffbMQbRJjqkS3NUffVEZcDdjx7drmSfWZ lJtsqpEAM+JCKdcYNu8yUdlEXJXi1cOhfC8s3jToYg8j/sW/K0nARzg6Whjwj8tUg3JNw7nS9Qv dTsYdKzLUh/rkX0cQ1NG+HKMQwaDsFmenmOjz7wgf0C3UfBpJ6WKB8NGDz7AP0cbX2dR9kp/vI0 D4tY3QEksLvNlBbwg9R5TOfMP7y9FIt1qSsnOqC9MppQ1JI1IAX4m5oncw79dDQdVcNU1Eqak5w yhWHRRlTJAL+XWAspUnVdJvmNgvuI+grUg9j X-Received: by 2002:a05:6000:4711:b0:386:2d40:a192 with SMTP id ffacd0b85a97d-3888e0bc2c8mr9352554f8f.34.1734369714035; Mon, 16 Dec 2024 09:21:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IGVFRO2dZZXsUxoaGTNCXW+ZDpU0UFQkfPrntK3b55WAGSYVzKubarCRoKaOOULAbag+4/SfA== X-Received: by 2002:a05:6000:4711:b0:386:2d40:a192 with SMTP id ffacd0b85a97d-3888e0bc2c8mr9352534f8f.34.1734369713649; Mon, 16 Dec 2024 09:21:53 -0800 (PST) Received: from debian (2a01cb058d23d600c2f0ae4aed6d33eb.ipv6.abo.wanadoo.fr. [2a01:cb05:8d23:d600:c2f0:ae4a:ed6d:33eb]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-388c8012029sm8659729f8f.12.2024.12.16.09.21.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Dec 2024 09:21:53 -0800 (PST) Date: Mon, 16 Dec 2024 18:21:51 +0100 From: Guillaume Nault To: David Miller , Jakub Kicinski , Paolo Abeni , Eric Dumazet Cc: netdev@vger.kernel.org, Simon Horman , David Ahern Subject: [PATCH net-next 4/5] ipv4: Use inet_sk_init_flowi4() in __ip_queue_xmit(). Message-ID: <37e64ffbd9adac187b14aa9097b095f5c86e85be.1734357769.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-Patchwork-Delegate: kuba@kernel.org Use inet_sk_init_flowi4() to automatically initialise the flowi4 structure in __ip_queue_xmit() instead of passing parameters manually to ip_route_output_ports(). Override ->flowi4_tos with the value passed as parameter since that's required by SCTP. Signed-off-by: Guillaume Nault --- net/ipv4/ip_output.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c index a59204a8d850..ce3b65d75bae 100644 --- a/net/ipv4/ip_output.c +++ b/net/ipv4/ip_output.c @@ -478,24 +478,16 @@ int __ip_queue_xmit(struct sock *sk, struct sk_buff *skb, struct flowi *fl, /* Make sure we can route this packet. */ rt = dst_rtable(__sk_dst_check(sk, 0)); if (!rt) { - __be32 daddr; + inet_sk_init_flowi4(inet, fl4); - /* Use correct destination address if we have options. */ - daddr = inet->inet_daddr; - if (inet_opt && inet_opt->opt.srr) - daddr = inet_opt->opt.faddr; + /* sctp_v4_xmit() uses its own DSCP value */ + fl4->flowi4_tos = tos & INET_DSCP_MASK; /* If this fails, retransmit mechanism of transport layer will * keep trying until route appears or the connection times * itself out. */ - rt = ip_route_output_ports(net, fl4, sk, - daddr, inet->inet_saddr, - inet->inet_dport, - inet->inet_sport, - sk->sk_protocol, - tos & INET_DSCP_MASK, - sk->sk_bound_dev_if); + rt = ip_route_output_flow(net, fl4, sk); if (IS_ERR(rt)) goto no_route; sk_setup_caps(sk, &rt->dst); From patchwork Mon Dec 16 17:21:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guillaume Nault X-Patchwork-Id: 13910121 X-Patchwork-Delegate: kuba@kernel.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 8E008207A06 for ; Mon, 16 Dec 2024 17:22:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734369722; cv=none; b=r6NGS/LvRJZCJbPc6dMk/4yxaDgvR2ilwekCzJ05W845eKsE+RPGNfjvfhytb0VlrD/1fDiE14eCxhYUUzMlBQj+EvHIFFN28wKWuCsY4WpIbL7ruh2+S6BMJ56EdFdpIR1WIo3NouqmK4Vp3ltDBQIrDX0hVXrt9hXONVKHBbw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734369722; c=relaxed/simple; bh=XDP3jNGk4IlqPce1sZpdzKDCFB9RnX198fmPU9Uz2rU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=N1pH/5/wGpikjFz14XoeEwYagDvBVshYhMn+UyBSTvWpPedQ/rxaqrz5JcGI/g7TTM7csVAXVCNMZXiyuXgtSfNNLBKgBlD0UYrqsWUSWEvnUjBrllWSOySAwBk2a8QafrT+cRFMKmme7JqgUz2V4lyp1mLJsOkHrb92XRojNI0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=USmtJiTG; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="USmtJiTG" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734369719; 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=S6bSLiIp/vbLDm7mgursV5kX1ogUS6QQZu/74jt6OZY=; b=USmtJiTGG3scAu5cTEXGNwJuEA9DavebPnWLK4+j6evHAtmIIC0W/wvkWWXxmR8wv8ldGO nXwCCs7QfWjpCzXqwfJJgeCyC9SfMbih7b8uExy4Is5NTTW0fo949AgThKdyOjR30mw4oQ EvNf1MooV77+Dhv/b2C4fj/rxgRK4Wc= 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-622-HkhMpShEMvCkjxgAgFck6g-1; Mon, 16 Dec 2024 12:21:58 -0500 X-MC-Unique: HkhMpShEMvCkjxgAgFck6g-1 X-Mimecast-MFC-AGG-ID: HkhMpShEMvCkjxgAgFck6g Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-385d52591d6so2214342f8f.1 for ; Mon, 16 Dec 2024 09:21:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734369717; x=1734974517; 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=S6bSLiIp/vbLDm7mgursV5kX1ogUS6QQZu/74jt6OZY=; b=HBxJdQq/BFXIdFKSCGQlWfgzZWN8xCPjXMuxgqNatdT0RL1l1RfU4tSOxS8Kj68gz7 dHkFpOyFHAyB/qochcalQOXB33b7uveKdmxVlo5RELYh/MKa/KTm4Te0L3p/vA1GvlDq aIoGFOjq2K2CTsQwawgnxNeu6mfhbyP2yvAb6Ra8j+Uda7UsqhY8PONIsOWU2Pr3E/RC Wri5MgVBI+NKEYS0YIpUuilPamSA1as1ndBvAIO7+01i64cJ4A/puEoHjDT2Jc8Pp96G BZZNRuwzQ53u0LaOrf+wgiVlqUH7X6ti8T0pxiPtSnrRJeqnMSgofsluPdtXfZC63Zyd yozQ== X-Gm-Message-State: AOJu0Yxu+zboi+MidYmIhULL+NRp4RtyzLem2nQOFf+KIGSARVI+kGvY ym3zbEIwTCggV2T4EIYojyIpT1RNlMIQ8MjIHEqDoJr7+QmFDCMFpgjBQPjF5hjoMlhWMVpWCqN /rmZtg9Qs+kiXTCjmy2UeGMt9/8Kk+LeytMYkYNTfTXHzOvRn0gnh/Q== X-Gm-Gg: ASbGncvDK8arpXRSyF3m8TJ2d/D9gPu9DCefk1RmvDPbC2fgU9p4sVG8i2Cnqoil7ht pACzz8SzqjKe6GGlVr5QZMLqrFu5hUHz9jb8m1cdP+gLalsMw32BQvdNzhtDoyduMmVQ5OuIMxD QKr/kVAXT8gCAVVhiRk7hHqC+MTKR7eKMIpf2AXw4oSgxrshdFWgaju3eMZroDdI4wamQoBFaUn NqiyVUGGCuTruIWCyjEOS34r3gqybu74+HENll06s3NggVu4D4QNKew46b1Oxzaml638nYQm93W fpsw6XsYNFgw/YK2mPud8Ez1D/D7sOJRyFLy X-Received: by 2002:a05:6000:4023:b0:385:ea40:b46b with SMTP id ffacd0b85a97d-388db2267b4mr162112f8f.4.1734369717210; Mon, 16 Dec 2024 09:21:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IE7T2hOhSkRKpZXQFy4BxA9gOjhvTh0GbDcbXVeqLcVwuXZnsGRyjCJCXTwm60dbXUW47fahg== X-Received: by 2002:a05:6000:4023:b0:385:ea40:b46b with SMTP id ffacd0b85a97d-388db2267b4mr162090f8f.4.1734369716882; Mon, 16 Dec 2024 09:21:56 -0800 (PST) Received: from debian (2a01cb058d23d600c2f0ae4aed6d33eb.ipv6.abo.wanadoo.fr. [2a01:cb05:8d23:d600:c2f0:ae4a:ed6d:33eb]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-388c801223dsm8841875f8f.3.2024.12.16.09.21.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Dec 2024 09:21:56 -0800 (PST) Date: Mon, 16 Dec 2024 18:21:54 +0100 From: Guillaume Nault To: David Miller , Jakub Kicinski , Paolo Abeni , Eric Dumazet Cc: netdev@vger.kernel.org, Simon Horman , David Ahern , James Chapman , Tom Parkin Subject: [PATCH net-next 5/5] l2tp: Use inet_sk_init_flowi4() in l2tp_ip_sendmsg(). Message-ID: <2ff22a3560c5050228928456662b80b9c84a8fe4.1734357769.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-Patchwork-Delegate: kuba@kernel.org Use inet_sk_init_flowi4() to automatically initialise the flowi4 structure in l2tp_ip_sendmsg() instead of passing parameters manually to ip_route_output_ports(). Override ->daddr with the value passed in the msghdr structure if provided. Signed-off-by: Guillaume Nault Reviewed-by: James Chapman --- net/l2tp/l2tp_ip.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c index 4bc24fddfd52..29795d2839e8 100644 --- a/net/l2tp/l2tp_ip.c +++ b/net/l2tp/l2tp_ip.c @@ -425,7 +425,6 @@ static int l2tp_ip_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) int rc; struct inet_sock *inet = inet_sk(sk); struct rtable *rt = NULL; - struct flowi4 *fl4; int connected = 0; __be32 daddr; @@ -455,7 +454,6 @@ static int l2tp_ip_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) if (sk->sk_state != TCP_ESTABLISHED) goto out; - daddr = inet->inet_daddr; connected = 1; } @@ -482,29 +480,24 @@ static int l2tp_ip_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) goto error; } - fl4 = &inet->cork.fl.u.ip4; if (connected) rt = dst_rtable(__sk_dst_check(sk, 0)); rcu_read_lock(); if (!rt) { - const struct ip_options_rcu *inet_opt; + struct flowi4 *fl4 = &inet->cork.fl.u.ip4; - inet_opt = rcu_dereference(inet->inet_opt); + inet_sk_init_flowi4(inet, fl4); - /* Use correct destination address if we have options. */ - if (inet_opt && inet_opt->opt.srr) - daddr = inet_opt->opt.faddr; + /* Overwrite ->daddr if msg->msg_name was provided */ + if (!connected) + fl4->daddr = daddr; /* If this fails, retransmit mechanism of transport layer will * keep trying until route appears or the connection times * itself out. */ - rt = ip_route_output_ports(sock_net(sk), fl4, sk, - daddr, inet->inet_saddr, - inet->inet_dport, inet->inet_sport, - sk->sk_protocol, ip_sock_rt_tos(sk), - sk->sk_bound_dev_if); + rt = ip_route_output_flow(sock_net(sk), fl4, sk); if (IS_ERR(rt)) goto no_route; if (connected) {