From patchwork Tue Oct 1 19:28:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guillaume Nault X-Patchwork-Id: 13818683 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 9D0701CCEC2 for ; Tue, 1 Oct 2024 19:28:44 +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=1727810926; cv=none; b=X6katzoaZDfDlnh1GenIyvOHM2yYcqDhCXqlVcj/jvUb0/4+WXswP9VxDqk4Md1BK4jxIlCMaMdE/oSxm/nKHgVMTRmfhmdjjTBkE2qdP+90al7vo8YiHYredLVVvIf8DOKiNqoo9+hugqX4ZcaSYPVpeNA8gCHT67/asRS0Bgc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727810926; c=relaxed/simple; bh=kQwKxUoxM616c6GXhLfMK+mkQQO3M0IdyU7HOIN6IWw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=AiUafTPNMjlpAQcOVaZjHEMbAnxplLU2wDhR5fWpivmtjKFFakLGb+UM5TaMi+mkAPUEtQZ6qXi6MIc/D9zCo673JJHhvGPNrt8m4tXlFN6pBhMlnXuZielYo8qzhI2xA13gDy2LVGWFdiZ8BDGuP8VjNQf+drDTBF4PRMqXRAI= 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=hi2pL8Nk; 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="hi2pL8Nk" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727810923; 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=vYljn/550Gg8n8QqqWO/ld0tGv+QhqLsSOmFpWNXCNE=; b=hi2pL8NkEJUTWzR1DLMWpP2qJoE2+C89rBZWyNOOrmoF5RF8dxfViRhr+eo8ANEQMdmXp6 G0c+8UXHnqRNooKZlaUZIdgmFcTgONeCw8wEpqlp2V0R+u7Knki+iJCNp1xiBZ+gufl6UW UW3gWGupXNTYHuV+HFEhk3dVR/kVNGQ= 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-668-LxJSGBfOMKWOem3QJBIXZQ-1; Tue, 01 Oct 2024 15:28:41 -0400 X-MC-Unique: LxJSGBfOMKWOem3QJBIXZQ-1 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-37cdbe8a6e8so1832982f8f.0 for ; Tue, 01 Oct 2024 12:28:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727810920; x=1728415720; 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=vYljn/550Gg8n8QqqWO/ld0tGv+QhqLsSOmFpWNXCNE=; b=OfaeGtyIoU5W1hKHZSJ1xdmqlhb5yuajxLgdIJ4gyYSYDvoR8XYfR8eCHyPNBC8Vvy FfqdjhdXEWYTOlUhsBGHnWWD1/VE81BBuB+z8pvgX9jlthaMgphMsPW/qbyVJ8xS/IsU UT1WKgSGuAnBCgHQBEluBssVB8qrIwmA3LoA7YEOfU549BsSiHzqXT1uGcufPe8AD+J3 TXUP7VA+d3kuXfZKRhyg8onUMUnPmaUdPpNbnP2rpFvcPZwwhZiWLMdcGMGnbzByxifG 76ilXET1o4MpDUj9f8MPX4hv+I11B4GhiiGBxRzX9sczoZO43FdHOx8Kj8bdl2BS+sYJ 1Y5g== X-Gm-Message-State: AOJu0YwxGPaaL5dAeo4LACJ+jXhCLD4qLcmfGRyafknhgOmuouNJqLtd HDmiBu+qqsLJL4FEgNXmAcY0TgCX5Cko1qV6No74MdmWW1zuXbdFQF4bVgxXOXLbfLKGarghnKR ke33lLEihtC4QXIQgRVWS5SbojtwbdLqt2+5zkQPCDv6RBMlAC2tcMA== X-Received: by 2002:adf:ee88:0:b0:37c:d225:6d33 with SMTP id ffacd0b85a97d-37cfba16c85mr436994f8f.55.1727810920045; Tue, 01 Oct 2024 12:28:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGn+cYLFsJtUVtZRvFLQCORYSOkPunpra//+FR74VtQlk+TDuulie4IGHA9coNXaMwR1IXZwA== X-Received: by 2002:adf:ee88:0:b0:37c:d225:6d33 with SMTP id ffacd0b85a97d-37cfba16c85mr436988f8f.55.1727810919579; Tue, 01 Oct 2024 12:28:39 -0700 (PDT) Received: from debian (2a01cb058d23d60018ec485714c2d3db.ipv6.abo.wanadoo.fr. [2a01:cb05:8d23:d600:18ec:4857:14c2:d3db]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37cd5730e6fsm12466925f8f.83.2024.10.01.12.28.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Oct 2024 12:28:38 -0700 (PDT) Date: Tue, 1 Oct 2024 21:28:37 +0200 From: Guillaume Nault To: David Miller , Jakub Kicinski , Paolo Abeni , Eric Dumazet Cc: netdev@vger.kernel.org, David Ahern , Ido Schimmel Subject: [PATCH net-next 1/5] ipv4: Convert icmp_route_lookup() to dscp_t. Message-ID: <294fead85c6035bcdc5fcf9a6bb4ce8798c45ba1.1727807926.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 Pass a dscp_t variable to icmp_route_lookup(), instead of a plain u8, to prevent accidental setting of ECN bits in ->flowi4_tos. Rename that variable ("tos" -> "dscp") to make the intent clear. While there, reorganise the function parameters to fill up horizontal space. Signed-off-by: Guillaume Nault --- net/ipv4/icmp.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c index e1384e7331d8..7d7b25ed8d21 100644 --- a/net/ipv4/icmp.c +++ b/net/ipv4/icmp.c @@ -478,13 +478,11 @@ static struct net_device *icmp_get_route_lookup_dev(struct sk_buff *skb) return route_lookup_dev; } -static struct rtable *icmp_route_lookup(struct net *net, - struct flowi4 *fl4, +static struct rtable *icmp_route_lookup(struct net *net, struct flowi4 *fl4, struct sk_buff *skb_in, - const struct iphdr *iph, - __be32 saddr, u8 tos, u32 mark, - int type, int code, - struct icmp_bxm *param) + const struct iphdr *iph, __be32 saddr, + dscp_t dscp, u32 mark, int type, + int code, struct icmp_bxm *param) { struct net_device *route_lookup_dev; struct dst_entry *dst, *dst2; @@ -498,7 +496,7 @@ static struct rtable *icmp_route_lookup(struct net *net, fl4->saddr = saddr; fl4->flowi4_mark = mark; fl4->flowi4_uid = sock_net_uid(net, NULL); - fl4->flowi4_tos = tos & INET_DSCP_MASK; + fl4->flowi4_tos = inet_dscp_to_dsfield(dscp); fl4->flowi4_proto = IPPROTO_ICMP; fl4->fl4_icmp_type = type; fl4->fl4_icmp_code = code; @@ -547,7 +545,7 @@ static struct rtable *icmp_route_lookup(struct net *net, orefdst = skb_in->_skb_refdst; /* save old refdst */ skb_dst_set(skb_in, NULL); err = ip_route_input(skb_in, fl4_dec.daddr, fl4_dec.saddr, - tos, rt2->dst.dev); + inet_dscp_to_dsfield(dscp), rt2->dst.dev); dst_release(&rt2->dst); rt2 = skb_rtable(skb_in); @@ -741,8 +739,9 @@ void __icmp_send(struct sk_buff *skb_in, int type, int code, __be32 info, ipc.opt = &icmp_param.replyopts.opt; ipc.sockc.mark = mark; - rt = icmp_route_lookup(net, &fl4, skb_in, iph, saddr, tos, mark, - type, code, &icmp_param); + rt = icmp_route_lookup(net, &fl4, skb_in, iph, saddr, + inet_dsfield_to_dscp(tos), mark, type, code, + &icmp_param); if (IS_ERR(rt)) goto out_unlock; From patchwork Tue Oct 1 19:28:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guillaume Nault X-Patchwork-Id: 13818684 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 A68541CCED6 for ; Tue, 1 Oct 2024 19:28:49 +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=1727810931; cv=none; b=D5Z9Ph/iR9ouw7JKYsond3Ph/ZJ0rsw4cLACwW6H6WplSjDvbDlVly6lDYPKqZDd7dqre5V9ujBAtv79h8+EZM3Qc5DqtH03Tj8Zyky/yklkrdGJoga53+vdPnYtaWyPAYk81H39QQM6mLJDaI1PJxoSl5rO3D85iu+XfffyxEQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727810931; c=relaxed/simple; bh=+0gYVfyR9pwbtvRRh9ROzfojRXx/b6obcAx02HET/GI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=gvEUyTLz473Eg/QzD6OsEEgXkqduWu1knKE+LTyJ3n44IwhHIe9AxFapIwTiXThfYOwNYhzztuOfuK9RMHbdaswIwLdCU8Gg/E9IDmDvdU9L9pO8abI0bFvWyFQVDLjXTT54X+ITLRnU+oz8DaU1afSv1JV8eQhpxniiiHrWvD4= 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=gPCNE6pE; 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="gPCNE6pE" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727810928; 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=zLubyNTF/pi6Ylzz/fx+UId8xxksWjasnX80u+XOEXc=; b=gPCNE6pE3DKoyuvuPfAYuQaFPfYhqy6j4cATPi2TcYQqNfTz7/cIFjT7Sf8pJYz2bs8zGJ Kn7id9mOmzvVvXrCSU5oXzI6jqgqF0SpdCTWHGkZjYSIEBp5h1dbxHfweloXYWD4I1UC3k o/qMFGJ6x4y59HKs4ekQQRoC01kwX/M= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-31-oCGb7TjDO-q8J0QuAO5lvQ-1; Tue, 01 Oct 2024 15:28:47 -0400 X-MC-Unique: oCGb7TjDO-q8J0QuAO5lvQ-1 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-37cc63b1ec3so3194849f8f.1 for ; Tue, 01 Oct 2024 12:28:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727810926; x=1728415726; 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=zLubyNTF/pi6Ylzz/fx+UId8xxksWjasnX80u+XOEXc=; b=c8ZWsQOahhEEsiAdHsl9G3iwY2zG0kViS0zjkJJymWV4r65fnGPkYMUTSlqOryCUb/ naaj3IpANKI4dXSZf6gg4L0jnXtl3C/dNPsTjTEgkRGdwypt4A7PAWgM9dpCn0y5divQ dnldt3oPy4eHwmovxyqq0ShGKPJU9G+D5OqeJTS3LyyQxBN5btVGKNW3AmdUxmHkJ/01 UJdylRQxv+F1ocTKSTcZMzjhRgBhm7IiaX2dxqpbivt/1faTA5VIkYJwPK9jzyjJEfj5 Mhczwp5DHK7r22YAP3sxWBMmGI/AanFPoTct0yGTBJHjUZZ7vjq9s0P1i8hZy7IBTmlm FOmw== X-Gm-Message-State: AOJu0Yz4NhiTTQ/6b7BAcVpd2e7HlxTdT5sy4CkZvEHo3iF4N+2ig7Nh HTgW61Y+XCI5vGbZt8rlLTx7KTl7v9FgNCDN0sO/89KW9be3x9t5ZdhCnrfW9RznV79EJ9Sg94I 1lqE1O7zfXy2jTKTY08CFMho9kzga+x1/jILWUgIwVs6mUva5NaBDAQ== X-Received: by 2002:a5d:514f:0:b0:368:3731:1613 with SMTP id ffacd0b85a97d-37cfb8c84f4mr424877f8f.13.1727810926373; Tue, 01 Oct 2024 12:28:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHgJ8fovF/Hq1ET7Gd/j+D2ZZYTtTe+i7blbcwbWq6Hv9MO+C293jwX92LmdYi5OMFk0LbGKg== X-Received: by 2002:a5d:514f:0:b0:368:3731:1613 with SMTP id ffacd0b85a97d-37cfb8c84f4mr424861f8f.13.1727810925969; Tue, 01 Oct 2024 12:28:45 -0700 (PDT) Received: from debian (2a01cb058d23d60018ec485714c2d3db.ipv6.abo.wanadoo.fr. [2a01:cb05:8d23:d600:18ec:4857:14c2:d3db]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37cd565e881sm12458524f8f.44.2024.10.01.12.28.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Oct 2024 12:28:45 -0700 (PDT) Date: Tue, 1 Oct 2024 21:28:43 +0200 From: Guillaume Nault To: David Miller , Jakub Kicinski , Paolo Abeni , Eric Dumazet Cc: netdev@vger.kernel.org, David Ahern , Ido Schimmel , Pablo Neira Ayuso , Jozsef Kadlecsik , Roopa Prabhu , Nikolay Aleksandrov Subject: [PATCH net-next 2/5] ipv4: Convert ip_route_input() to dscp_t. 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 Pass a dscp_t variable to ip_route_input(), instead of a plain u8, to prevent accidental setting of ECN bits in ->flowi4_tos. Callers of ip_route_input() to consider are: * input_action_end_dx4_finish() and input_action_end_dt4() in net/ipv6/seg6_local.c. These functions set the tos parameter to 0, which is already a valid dscp_t value, so they don't need to be adjusted for the new prototype. * icmp_route_lookup(), which already has a dscp_t variable to pass as parameter. We just need to remove the inet_dscp_to_dsfield() conversion. * br_nf_pre_routing_finish(), ip_options_rcv_srr() and ip4ip6_err(), which get the DSCP directly from IPv4 headers. Define a helper to read the .tos field of struct iphdr as dscp_t, so that these function don't have to do the conversion manually. While there, declare *iph as const in br_nf_pre_routing_finish(), declare its local variables in reverse-christmas-tree order and move the "err = ip_route_input()" assignment out of the conditional to avoid checkpatch warning. Signed-off-by: Guillaume Nault --- include/net/ip.h | 5 +++++ include/net/route.h | 5 +++-- net/bridge/br_netfilter_hooks.c | 8 +++++--- net/ipv4/icmp.c | 2 +- net/ipv4/ip_options.c | 3 ++- net/ipv6/ip6_tunnel.c | 4 ++-- 6 files changed, 18 insertions(+), 9 deletions(-) diff --git a/include/net/ip.h b/include/net/ip.h index d92d3bc3ec0e..bab084df1567 100644 --- a/include/net/ip.h +++ b/include/net/ip.h @@ -424,6 +424,11 @@ int ip_decrease_ttl(struct iphdr *iph) return --iph->ttl; } +static inline dscp_t ip4h_dscp(const struct iphdr *ip4h) +{ + return inet_dsfield_to_dscp(ip4h->tos); +} + static inline int ip_mtu_locked(const struct dst_entry *dst) { const struct rtable *rt = dst_rtable(dst); diff --git a/include/net/route.h b/include/net/route.h index 1789f1e6640b..03dd28cf4bc4 100644 --- a/include/net/route.h +++ b/include/net/route.h @@ -208,12 +208,13 @@ int ip_route_use_hint(struct sk_buff *skb, __be32 dst, __be32 src, const struct sk_buff *hint); static inline int ip_route_input(struct sk_buff *skb, __be32 dst, __be32 src, - u8 tos, struct net_device *devin) + dscp_t dscp, struct net_device *devin) { int err; rcu_read_lock(); - err = ip_route_input_noref(skb, dst, src, tos, devin); + err = ip_route_input_noref(skb, dst, src, inet_dscp_to_dsfield(dscp), + devin); if (!err) { skb_dst_force(skb); if (!skb_dst(skb)) diff --git a/net/bridge/br_netfilter_hooks.c b/net/bridge/br_netfilter_hooks.c index 0e8bc0ea6175..c6bab2b5e834 100644 --- a/net/bridge/br_netfilter_hooks.c +++ b/net/bridge/br_netfilter_hooks.c @@ -369,9 +369,9 @@ br_nf_ipv4_daddr_was_changed(const struct sk_buff *skb, */ static int br_nf_pre_routing_finish(struct net *net, struct sock *sk, struct sk_buff *skb) { - struct net_device *dev = skb->dev, *br_indev; - struct iphdr *iph = ip_hdr(skb); struct nf_bridge_info *nf_bridge = nf_bridge_info_get(skb); + struct net_device *dev = skb->dev, *br_indev; + const struct iphdr *iph = ip_hdr(skb); struct rtable *rt; int err; @@ -389,7 +389,9 @@ static int br_nf_pre_routing_finish(struct net *net, struct sock *sk, struct sk_ } nf_bridge->in_prerouting = 0; if (br_nf_ipv4_daddr_was_changed(skb, nf_bridge)) { - if ((err = ip_route_input(skb, iph->daddr, iph->saddr, iph->tos, dev))) { + err = ip_route_input(skb, iph->daddr, iph->saddr, + ip4h_dscp(iph), dev); + if (err) { struct in_device *in_dev = __in_dev_get_rcu(dev); /* If err equals -EHOSTUNREACH the error is due to a diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c index 7d7b25ed8d21..23664434922e 100644 --- a/net/ipv4/icmp.c +++ b/net/ipv4/icmp.c @@ -545,7 +545,7 @@ static struct rtable *icmp_route_lookup(struct net *net, struct flowi4 *fl4, orefdst = skb_in->_skb_refdst; /* save old refdst */ skb_dst_set(skb_in, NULL); err = ip_route_input(skb_in, fl4_dec.daddr, fl4_dec.saddr, - inet_dscp_to_dsfield(dscp), rt2->dst.dev); + dscp, rt2->dst.dev); dst_release(&rt2->dst); rt2 = skb_rtable(skb_in); diff --git a/net/ipv4/ip_options.c b/net/ipv4/ip_options.c index a9e22a098872..b4c59708fc09 100644 --- a/net/ipv4/ip_options.c +++ b/net/ipv4/ip_options.c @@ -617,7 +617,8 @@ int ip_options_rcv_srr(struct sk_buff *skb, struct net_device *dev) orefdst = skb->_skb_refdst; skb_dst_set(skb, NULL); - err = ip_route_input(skb, nexthop, iph->saddr, iph->tos, dev); + err = ip_route_input(skb, nexthop, iph->saddr, ip4h_dscp(iph), + dev); rt2 = skb_rtable(skb); if (err || (rt2->rt_type != RTN_UNICAST && rt2->rt_type != RTN_LOCAL)) { skb_dst_drop(skb); diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c index b60e13c42bca..48fd53b98972 100644 --- a/net/ipv6/ip6_tunnel.c +++ b/net/ipv6/ip6_tunnel.c @@ -630,8 +630,8 @@ ip4ip6_err(struct sk_buff *skb, struct inet6_skb_parm *opt, } skb_dst_set(skb2, &rt->dst); } else { - if (ip_route_input(skb2, eiph->daddr, eiph->saddr, eiph->tos, - skb2->dev) || + if (ip_route_input(skb2, eiph->daddr, eiph->saddr, + ip4h_dscp(eiph), skb2->dev) || skb_dst(skb2)->dev->type != ARPHRD_TUNNEL6) goto out; } From patchwork Tue Oct 1 19:28:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guillaume Nault X-Patchwork-Id: 13818687 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 DEB461CDA0E for ; Tue, 1 Oct 2024 19:29:30 +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=1727810972; cv=none; b=WG+ZbE1c3B8aA9PdXBYQXCcXiu9wmL1vLHRQ3Xr2bYwWcKObUgmju+yp6H4XYHNB32lIU4lrQd8vRDi3c+jyiAfesqI2L+4Kl4V9MPu8SJbKC5uBJLGZohTX7IRmfqH9OgrCRmkt/uCxguR4l5k38FAGfjA1ykfNW/EZW0Xuukc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727810972; c=relaxed/simple; bh=hSw+93w3Fj9oy/ZX89Ko8Yg0Vd4Hq9fxS/Hq7Q8zphg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=EBr3tgbUD5bqZMmOYweNVwqzJjm+5E8A02C/LlVYWlK8LaGOMkmXCU8dQV1lzH7zvp8/SehwbvO/UqDTwmwwUM7AALDdqNwcGEu9KjNhkzbDtTAkA9+iXsK3uQI+uacVBj3XWgC0ZPtw80QlHyLYBTs4hX3uhnpidhPCTjazZjc= 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=M6owxyXV; 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="M6owxyXV" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727810970; 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=Q0cOw8V7kfpFsFykV7cij29Zj7Dz1qG6ze+YIlFK/6k=; b=M6owxyXVy0nvPnjQLkUxyfkP8ZNz2NSu8FufllciOJsKRpqdwS8KsS8u33qmLIS7P0ztgn ZnA5E91rfBtryNAnT3kbS4m0lJJz8zO7UE67Yvbtr5oiApuOl/jw4W7R/cPjWeLyn7kw89 ZXPioL2AZ9rg7+jEq5DxIIVm+76mzzM= 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-284-2GblzXogNpW92hCduuodmg-1; Tue, 01 Oct 2024 15:28:57 -0400 X-MC-Unique: 2GblzXogNpW92hCduuodmg-1 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-42cb479fab2so489565e9.1 for ; Tue, 01 Oct 2024 12:28:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727810932; x=1728415732; 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=Q0cOw8V7kfpFsFykV7cij29Zj7Dz1qG6ze+YIlFK/6k=; b=KH9k3nDPcoxxjubQ5Hhn4TJdNu/nAyE227D6gXMYjtOK5T4RZ/SeFw8xZ3cKsAqUVj WE94dDU7FCL7SqadPh1Z4V/gGZxZMMR0tuAc6LeuonPt6mSBpTwr9PYLOayr4pti7lE5 kg+gYCDMkKeSwTYEoow0z9P1GbUc3FfXJMAjLeu7hUeYySlcn7/eVhNjdcm+ky9a8AvK gnrlFbxlOYuO/JL5WVJLv4YkUocke+Z4gmaTCP1NgNpBusz4zsOqRz9eGmyMgYdpwyN6 qr5T8Oi9KdFFT/4y2xPXkyTuxkmEbDiWoucZBq6rQXh230nxCCFy35eonRQiHn7KeNaS znYw== X-Gm-Message-State: AOJu0YwlYH42K/kIOFmO+SAqVRneTcgdBgzis5k4OEVL2q02p0h7fPmw cay9eHlgdFHGTDVsSSv74hJBfM6sluU5siyXVyx0nDmwMmJs9ASu/udqupb7oFJVHYFQpz7TJNY 8Grkix62zdKWCpKJrnbaJ4T/78FJGaZ+UZgBRNL+R6vcO1IwO4qarRg== X-Received: by 2002:a05:600c:c11:b0:42c:ba81:117c with SMTP id 5b1f17b1804b1-42f776dfabfmr4191865e9.6.1727810932367; Tue, 01 Oct 2024 12:28:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHOie0bGOglplFLNnsPS4f+J346loIxXphx9UwSm5oGJlIatkgBve7KcDdVeL0DZ7vjeNzKxg== X-Received: by 2002:a05:600c:c11:b0:42c:ba81:117c with SMTP id 5b1f17b1804b1-42f776dfabfmr4191745e9.6.1727810931944; Tue, 01 Oct 2024 12:28:51 -0700 (PDT) Received: from debian (2a01cb058d23d60018ec485714c2d3db.ipv6.abo.wanadoo.fr. [2a01:cb05:8d23:d600:18ec:4857:14c2:d3db]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42e969ddfc9sm188700575e9.5.2024.10.01.12.28.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Oct 2024 12:28:51 -0700 (PDT) Date: Tue, 1 Oct 2024 21:28:49 +0200 From: Guillaume Nault To: David Miller , Jakub Kicinski , Paolo Abeni , Eric Dumazet Cc: netdev@vger.kernel.org, David Ahern , Ido Schimmel , Steffen Klassert , Herbert Xu Subject: [PATCH net-next 3/5] ipv4: Convert ip_route_input_noref() to dscp_t. 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 Pass a dscp_t variable to ip_route_input_noref(), instead of a plain u8, to prevent accidental setting of ECN bits in ->flowi4_tos. Callers of ip_route_input_noref() to consider are: * arp_process() in net/ipv4/arp.c. This function sets the tos parameter to 0, which is already a valid dscp_t value, so it doesn't need to be adjusted for the new prototype. * ip_route_input(), which already has a dscp_t variable to pass as parameter. We just need to remove the inet_dscp_to_dsfield() conversion. * ipvlan_l3_rcv(), bpf_lwt_input_reroute(), ip_expire(), ip_rcv_finish_core(), xfrm4_rcv_encap_finish() and xfrm4_rcv_encap(), which get the DSCP directly from IPv4 headers and can simply use the ip4h_dscp() helper. While there, declare the IPv4 header pointers as const in ipvlan_l3_rcv() and bpf_lwt_input_reroute(). Also, modify the declaration of ip_route_input_noref() in include/net/route.h so that it matches the prototype of its implementation in net/ipv4/route.c. Signed-off-by: Guillaume Nault --- drivers/net/ipvlan/ipvlan_l3s.c | 6 ++++-- include/net/route.h | 7 +++---- net/core/lwt_bpf.c | 5 +++-- net/ipv4/ip_fragment.c | 4 ++-- net/ipv4/ip_input.c | 2 +- net/ipv4/route.c | 6 +++--- net/ipv4/xfrm4_input.c | 2 +- net/ipv4/xfrm4_protocol.c | 2 +- 8 files changed, 18 insertions(+), 16 deletions(-) diff --git a/drivers/net/ipvlan/ipvlan_l3s.c b/drivers/net/ipvlan/ipvlan_l3s.c index d5b05e803219..b4ef386bdb1b 100644 --- a/drivers/net/ipvlan/ipvlan_l3s.c +++ b/drivers/net/ipvlan/ipvlan_l3s.c @@ -2,6 +2,8 @@ /* Copyright (c) 2014 Mahesh Bandewar */ +#include + #include "ipvlan.h" static unsigned int ipvlan_netid __read_mostly; @@ -48,11 +50,11 @@ static struct sk_buff *ipvlan_l3_rcv(struct net_device *dev, switch (proto) { case AF_INET: { - struct iphdr *ip4h = ip_hdr(skb); + const struct iphdr *ip4h = ip_hdr(skb); int err; err = ip_route_input_noref(skb, ip4h->daddr, ip4h->saddr, - ip4h->tos, sdev); + ip4h_dscp(ip4h), sdev); if (unlikely(err)) goto out; break; diff --git a/include/net/route.h b/include/net/route.h index 03dd28cf4bc4..5e4374d66927 100644 --- a/include/net/route.h +++ b/include/net/route.h @@ -201,8 +201,8 @@ static inline struct rtable *ip_route_output_gre(struct net *net, struct flowi4 int ip_mc_validate_source(struct sk_buff *skb, __be32 daddr, __be32 saddr, u8 tos, struct net_device *dev, struct in_device *in_dev, u32 *itag); -int ip_route_input_noref(struct sk_buff *skb, __be32 dst, __be32 src, - u8 tos, struct net_device *devin); +int ip_route_input_noref(struct sk_buff *skb, __be32 daddr, __be32 saddr, + dscp_t dscp, struct net_device *dev); int ip_route_use_hint(struct sk_buff *skb, __be32 dst, __be32 src, u8 tos, struct net_device *devin, const struct sk_buff *hint); @@ -213,8 +213,7 @@ static inline int ip_route_input(struct sk_buff *skb, __be32 dst, __be32 src, int err; rcu_read_lock(); - err = ip_route_input_noref(skb, dst, src, inet_dscp_to_dsfield(dscp), - devin); + err = ip_route_input_noref(skb, dst, src, dscp, devin); if (!err) { skb_dst_force(skb); if (!skb_dst(skb)) diff --git a/net/core/lwt_bpf.c b/net/core/lwt_bpf.c index 1a14f915b7a4..e0ca24a58810 100644 --- a/net/core/lwt_bpf.c +++ b/net/core/lwt_bpf.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -91,12 +92,12 @@ static int bpf_lwt_input_reroute(struct sk_buff *skb) if (skb->protocol == htons(ETH_P_IP)) { struct net_device *dev = skb_dst(skb)->dev; - struct iphdr *iph = ip_hdr(skb); + const struct iphdr *iph = ip_hdr(skb); dev_hold(dev); skb_dst_drop(skb); err = ip_route_input_noref(skb, iph->daddr, iph->saddr, - iph->tos, dev); + ip4h_dscp(iph), dev); dev_put(dev); } else if (skb->protocol == htons(ETH_P_IPV6)) { skb_dst_drop(skb); diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c index a92664a5ef2e..48e2810f1f27 100644 --- a/net/ipv4/ip_fragment.c +++ b/net/ipv4/ip_fragment.c @@ -175,8 +175,8 @@ static void ip_expire(struct timer_list *t) /* skb has no dst, perform route lookup again */ iph = ip_hdr(head); - err = ip_route_input_noref(head, iph->daddr, iph->saddr, - iph->tos, head->dev); + err = ip_route_input_noref(head, iph->daddr, iph->saddr, ip4h_dscp(iph), + head->dev); if (err) goto out; diff --git a/net/ipv4/ip_input.c b/net/ipv4/ip_input.c index b6e7d4921309..c0a2490eb7c1 100644 --- a/net/ipv4/ip_input.c +++ b/net/ipv4/ip_input.c @@ -363,7 +363,7 @@ static int ip_rcv_finish_core(struct net *net, struct sock *sk, */ if (!skb_valid_dst(skb)) { err = ip_route_input_noref(skb, iph->daddr, iph->saddr, - iph->tos, dev); + ip4h_dscp(iph), dev); if (unlikely(err)) goto drop_error; } else { diff --git a/net/ipv4/route.c b/net/ipv4/route.c index 723ac9181558..00bfc0a11f64 100644 --- a/net/ipv4/route.c +++ b/net/ipv4/route.c @@ -2465,14 +2465,14 @@ static int ip_route_input_rcu(struct sk_buff *skb, __be32 daddr, __be32 saddr, } int ip_route_input_noref(struct sk_buff *skb, __be32 daddr, __be32 saddr, - u8 tos, struct net_device *dev) + dscp_t dscp, struct net_device *dev) { struct fib_result res; int err; - tos &= INET_DSCP_MASK; rcu_read_lock(); - err = ip_route_input_rcu(skb, daddr, saddr, tos, dev, &res); + err = ip_route_input_rcu(skb, daddr, saddr, inet_dscp_to_dsfield(dscp), + dev, &res); rcu_read_unlock(); return err; diff --git a/net/ipv4/xfrm4_input.c b/net/ipv4/xfrm4_input.c index a620618cc568..b5b06323cfd9 100644 --- a/net/ipv4/xfrm4_input.c +++ b/net/ipv4/xfrm4_input.c @@ -33,7 +33,7 @@ static inline int xfrm4_rcv_encap_finish(struct net *net, struct sock *sk, const struct iphdr *iph = ip_hdr(skb); if (ip_route_input_noref(skb, iph->daddr, iph->saddr, - iph->tos, skb->dev)) + ip4h_dscp(iph), skb->dev)) goto drop; } diff --git a/net/ipv4/xfrm4_protocol.c b/net/ipv4/xfrm4_protocol.c index b146ce88c5d0..4ee624d8e66f 100644 --- a/net/ipv4/xfrm4_protocol.c +++ b/net/ipv4/xfrm4_protocol.c @@ -76,7 +76,7 @@ int xfrm4_rcv_encap(struct sk_buff *skb, int nexthdr, __be32 spi, const struct iphdr *iph = ip_hdr(skb); if (ip_route_input_noref(skb, iph->daddr, iph->saddr, - iph->tos, skb->dev)) + ip4h_dscp(iph), skb->dev)) goto drop; } From patchwork Tue Oct 1 19:28:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guillaume Nault X-Patchwork-Id: 13818685 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 C0B471CCED6 for ; Tue, 1 Oct 2024 19:29:03 +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=1727810945; cv=none; b=j3DWAcEId6oA7YNXDIERvAluyW+pHg3ba4SGJ1MyNXIZADVh1S+JXSwf7pxj/Fa+FzODQQ76lTlRe8HUFtGOACcFiJHrWgYB4mKWjvzbPxhZB3hmw7zYfxC44o9Df77/ROWfvEvRGa+/KyoXlHo/wnvFs4J4lEeFJYWoAH/a8sE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727810945; c=relaxed/simple; bh=e1R2AqnpJKiftjb+lYf3kS0dQNuVwRKIfQHug1zc3jA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=fYAhjFQXKPRZTm0ykyKO/9BzpYsQ5/63X8gD0Bh6l44NLsMoq1uADqkz9bUAnIJq3LmM0uhw8APBmAz8ZYRpOq6kj19wQ06reCtxVwx6/jq/440341zU/vZEh1v756eAzEmWHRlXeZ8Um22XTUN/r1Kj7EglXkH5g7dv7yrr8/A= 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=PLeFT7Bm; 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="PLeFT7Bm" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727810942; 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=GjL7CwM6ypjXJpV7gAAATjLEUIaRsTObcktuGB/hzyM=; b=PLeFT7Bmy88g2TTZ58BAnrne/T+5KRyR0sWeioz8OEUBK75eVBVxBN5Hhw5Bz4RuUcuouc SKJfxUOQRT4Ua76ts9c7oTepZ4EugJDgPup9yGSSHVY8zcRLXEBZTgZfKLly58rQ5fSPNQ k7VYrRckCllVk9CdvFcz2mVB9g5U/18= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-32-Hzin7B2POo2f-IudbsemGQ-1; Tue, 01 Oct 2024 15:28:59 -0400 X-MC-Unique: Hzin7B2POo2f-IudbsemGQ-1 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-42caf073db8so48618355e9.3 for ; Tue, 01 Oct 2024 12:28:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727810938; x=1728415738; 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=GjL7CwM6ypjXJpV7gAAATjLEUIaRsTObcktuGB/hzyM=; b=HHHmXfqvZxmJGIgRUOuMGQ3MZz4NV2z+I9IYFrb5GPwGksx56H1PaUkQuBEvrIdW5e UMaffM9POUvixiwbEMgaG3IRuiPX1xGpslZ6z+pkGvQVT3pTdCoOul/eAXFpTWQKHaO0 qgc/WzLUgijF7/2eoI9bxm7knEwlMudTi+qy6RyicIxAhLKesnxp872/aj+YKxQRNh19 Lh7c9sQ6rOOsqN2Hu/mz9LD0qPVj6K4trv4DFBwijY2k2ChQLPxoPM7WCQLHS356qTJU 61zMRoVUt9hxCd611poL1UnY4ewVRS0l3luwz+3IHoV1yNOhgnvHjSjNs6Vt8gxtE7T/ 5GEw== X-Gm-Message-State: AOJu0YxdVQsfMJ8ZCS0CZKoG1kqigelNNPWWW9bUmxl8bNaUQlm3Yzql 14EIyQQNg4r31Y9JyFpPvWdj+QYnopW2D8ITDkhD8taXziWyRE3kvia10Ippr18194wWMUF5jPQ nmEEi/Q/7zFqmMRnyfATjbnBg6sqqa6QeUQz+wSfqow9IJV9Z4UD/5Q== X-Received: by 2002:a05:600c:1c81:b0:42c:b23f:7ba5 with SMTP id 5b1f17b1804b1-42f777b6d2fmr4369345e9.10.1727810938143; Tue, 01 Oct 2024 12:28:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEfMz8VPhRfkBGR6aYm+OyZu3gTFPLQZUyrIOSbXfKB9nIGF0xcfYwwpjBTdRkm5mmMXApTHA== X-Received: by 2002:a05:600c:1c81:b0:42c:b23f:7ba5 with SMTP id 5b1f17b1804b1-42f777b6d2fmr4369205e9.10.1727810937668; Tue, 01 Oct 2024 12:28:57 -0700 (PDT) Received: from debian (2a01cb058d23d60018ec485714c2d3db.ipv6.abo.wanadoo.fr. [2a01:cb05:8d23:d600:18ec:4857:14c2:d3db]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37cd57423afsm12490327f8f.90.2024.10.01.12.28.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Oct 2024 12:28:57 -0700 (PDT) Date: Tue, 1 Oct 2024 21:28:55 +0200 From: Guillaume Nault To: David Miller , Jakub Kicinski , Paolo Abeni , Eric Dumazet Cc: netdev@vger.kernel.org, David Ahern , Ido Schimmel Subject: [PATCH net-next 4/5] ipv4: Convert ip_route_input_rcu() to dscp_t. 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 Pass a dscp_t variable to ip_route_input_rcu(), instead of a plain u8, to prevent accidental setting of ECN bits in ->flowi4_tos. Callers of ip_route_input_rcu() to consider are: * ip_route_input_noref(), which already has a dscp_t variable to pass as parameter. We just need to remove the inet_dscp_to_dsfield() conversion. * inet_rtm_getroute(), which receives a u8 from user space and needs to convert it with inet_dsfield_to_dscp(). Signed-off-by: Guillaume Nault --- net/ipv4/route.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/net/ipv4/route.c b/net/ipv4/route.c index 00bfc0a11f64..a693b57b4111 100644 --- a/net/ipv4/route.c +++ b/net/ipv4/route.c @@ -2415,7 +2415,8 @@ out: return err; /* called with rcu_read_lock held */ static int ip_route_input_rcu(struct sk_buff *skb, __be32 daddr, __be32 saddr, - u8 tos, struct net_device *dev, struct fib_result *res) + dscp_t dscp, struct net_device *dev, + struct fib_result *res) { /* Multicast recognition logic is moved from route cache to here. * The problem was that too many Ethernet cards have broken/missing @@ -2456,12 +2457,14 @@ static int ip_route_input_rcu(struct sk_buff *skb, __be32 daddr, __be32 saddr, #endif ) { err = ip_route_input_mc(skb, daddr, saddr, - tos, dev, our); + inet_dscp_to_dsfield(dscp), + dev, our); } return err; } - return ip_route_input_slow(skb, daddr, saddr, tos, dev, res); + return ip_route_input_slow(skb, daddr, saddr, + inet_dscp_to_dsfield(dscp), dev, res); } int ip_route_input_noref(struct sk_buff *skb, __be32 daddr, __be32 saddr, @@ -2471,8 +2474,7 @@ int ip_route_input_noref(struct sk_buff *skb, __be32 daddr, __be32 saddr, int err; rcu_read_lock(); - err = ip_route_input_rcu(skb, daddr, saddr, inet_dscp_to_dsfield(dscp), - dev, &res); + err = ip_route_input_rcu(skb, daddr, saddr, dscp, dev, &res); rcu_read_unlock(); return err; @@ -3286,8 +3288,8 @@ static int inet_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh, skb->dev = dev; skb->mark = mark; err = ip_route_input_rcu(skb, dst, src, - rtm->rtm_tos & INET_DSCP_MASK, dev, - &res); + inet_dsfield_to_dscp(rtm->rtm_tos), + dev, &res); rt = skb_rtable(skb); if (err == 0 && rt->dst.error) From patchwork Tue Oct 1 19:29:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guillaume Nault X-Patchwork-Id: 13818686 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 221501CB30F for ; Tue, 1 Oct 2024 19:29:11 +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=1727810953; cv=none; b=HfOBPRbnrRDp+AVEtEVia1Hds+b4bQ8EZUlTCQZWu7LWnjrjou5T04G9IBmCtNFzyLkzyBwHs8eznIKnLKt0Q8edpG2ZCMmb/V20HPeDPgdDwol+Gw5fclB76g6rX1DWJt221bUVezvowOyfYhfv1ml14ZtNmL4p+OeW/HFqaeM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727810953; c=relaxed/simple; bh=mbVxVUGGVRmGPGK3ra1hAXno2TTsqq9/DKY9s81E1QY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=stnIS69gCkgmlH5LsakGcXxdtihFEtHBndg6taB70zDT3fvY6YSKI7GdDl+0yesXrlnB61WVG1lmDL7JwKXoe8gfmEI7I0TZY+s3aeWNUCHTy6k0vZgvyiTEI4xyMjWsTS+JrtfQjama61LktnxU/vwzEWBtOzDyU6MTYXAuuBQ= 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=cA5pbxQt; 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="cA5pbxQt" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727810951; 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=SyiAPzLiuXxL95Kto4qHwRPzad81VI7XfdIz5OkYFCc=; b=cA5pbxQtszlUTlBJb3NIwNlxhZ3Dr1D6CrsCqOZL5L2sW6RN4njLS6VsWgG687KYiZfhKG e5aP0BpDRYphs1fuo7Kvunem3ynrsNbNVzTF8FFYK5/CCc3k6Liy64IO0FiXFoh2AT7zfc ExEPQqWZbeAb8ibHbGdpHpYd+2niQQA= 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-369-SrkwAJfbNRiNBAEslshIzA-1; Tue, 01 Oct 2024 15:29:07 -0400 X-MC-Unique: SrkwAJfbNRiNBAEslshIzA-1 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-37cc4f28e88so4035653f8f.3 for ; Tue, 01 Oct 2024 12:29:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727810945; x=1728415745; 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=SyiAPzLiuXxL95Kto4qHwRPzad81VI7XfdIz5OkYFCc=; b=A5BmKvid94z/LoHs+HSPnKYLrE8b/UXSodhpuxVbpUaxJhv8/qNgylb/60cCsyGIkI r7LDrzXTEqIUBy9gNj5fMOwh15m3jUeHzjX8L2pqPuop4isXQESsHlJ1xzFKpl4XKBHu Mh0qbkVeSN8ivtcuFfSqNmV1nXu3MnrGjdpoCPiRr3J5xu2jVRJJPOEfir7nSAs+0pD7 ndFLprAzdNlOFaoJY5GHkeAAuPtn3V4TNPSTrIzLtZ+iepmoLAC7b7l59yTXN4aY7xaH 2AxTE/DUoqd3nUtjm7TJ7XfwAZEDwbJA8vBg7Vd22pjQhja0eH6OfFm+Nku+WukE5NpU YRFQ== X-Gm-Message-State: AOJu0YwC8rziM//YOYsV38DvEXj0BlRfHsvtLpgVsRyu4PsJ5Il5r7yK jEsNrXWxpycD+k0Zm25bZ86obMrtvoRB5OLVgo+3uvqvKirZT1+QHMJN75q6wnbdzf57GOk0cmf MecWSuoWs7Fn7dXCCB6wjHQXNgfOs9Lp6XSM53IBtF9aD5Oc5hqE/Cg== X-Received: by 2002:adf:ce8f:0:b0:37c:f96c:a089 with SMTP id ffacd0b85a97d-37cfb9d4298mr567899f8f.31.1727810945081; Tue, 01 Oct 2024 12:29:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IERJmiyrozH+Bi2MfXZyLkSTTnnu9kljcmVjn1ZLByaAOqzg/ofAz1u7oNbbYaTY9QpC1pqCw== X-Received: by 2002:adf:ce8f:0:b0:37c:f96c:a089 with SMTP id ffacd0b85a97d-37cfb9d4298mr567887f8f.31.1727810944753; Tue, 01 Oct 2024 12:29:04 -0700 (PDT) Received: from debian (2a01cb058d23d60018ec485714c2d3db.ipv6.abo.wanadoo.fr. [2a01:cb05:8d23:d600:18ec:4857:14c2:d3db]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37cd572fbebsm12477751f8f.72.2024.10.01.12.29.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Oct 2024 12:29:04 -0700 (PDT) Date: Tue, 1 Oct 2024 21:29:01 +0200 From: Guillaume Nault To: David Miller , Jakub Kicinski , Paolo Abeni , Eric Dumazet Cc: netdev@vger.kernel.org, David Ahern , Ido Schimmel Subject: [PATCH net-next 5/5] ipv4: Convert ip_route_input_slow() to dscp_t. 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 Pass a dscp_t variable to ip_route_input_slow(), instead of a plain u8, to prevent accidental setting of ECN bits in ->flowi4_tos. Only ip_route_input_rcu() actually calls ip_route_input_slow(). Since it already has a dscp_t variable to pass as parameter, we only need to remove the inet_dscp_to_dsfield() conversion. Signed-off-by: Guillaume Nault --- net/ipv4/route.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/net/ipv4/route.c b/net/ipv4/route.c index a693b57b4111..6e1cd0065b87 100644 --- a/net/ipv4/route.c +++ b/net/ipv4/route.c @@ -2201,7 +2201,7 @@ static struct net_device *ip_rt_get_dev(struct net *net, */ static int ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr, - u8 tos, struct net_device *dev, + dscp_t dscp, struct net_device *dev, struct fib_result *res) { struct in_device *in_dev = __in_dev_get_rcu(dev); @@ -2266,7 +2266,7 @@ static int ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr, fl4.flowi4_oif = 0; fl4.flowi4_iif = dev->ifindex; fl4.flowi4_mark = skb->mark; - fl4.flowi4_tos = tos; + fl4.flowi4_tos = inet_dscp_to_dsfield(dscp); fl4.flowi4_scope = RT_SCOPE_UNIVERSE; fl4.flowi4_flags = 0; fl4.daddr = daddr; @@ -2299,8 +2299,9 @@ static int ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr, } if (res->type == RTN_LOCAL) { - err = fib_validate_source(skb, saddr, daddr, tos, - 0, dev, in_dev, &itag); + err = fib_validate_source(skb, saddr, daddr, + inet_dscp_to_dsfield(dscp), 0, dev, + in_dev, &itag); if (err < 0) goto martian_source; goto local_input; @@ -2314,7 +2315,8 @@ static int ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr, goto martian_destination; make_route: - err = ip_mkroute_input(skb, res, in_dev, daddr, saddr, tos, flkeys); + err = ip_mkroute_input(skb, res, in_dev, daddr, saddr, + inet_dscp_to_dsfield(dscp), flkeys); out: return err; brd_input: @@ -2322,7 +2324,8 @@ out: return err; goto e_inval; if (!ipv4_is_zeronet(saddr)) { - err = fib_validate_source(skb, saddr, 0, tos, 0, dev, + err = fib_validate_source(skb, saddr, 0, + inet_dscp_to_dsfield(dscp), 0, dev, in_dev, &itag); if (err < 0) goto martian_source; @@ -2463,8 +2466,7 @@ static int ip_route_input_rcu(struct sk_buff *skb, __be32 daddr, __be32 saddr, return err; } - return ip_route_input_slow(skb, daddr, saddr, - inet_dscp_to_dsfield(dscp), dev, res); + return ip_route_input_slow(skb, daddr, saddr, dscp, dev, res); } int ip_route_input_noref(struct sk_buff *skb, __be32 daddr, __be32 saddr,