From nobody Mon Nov 25 06:40:24 2024 Received: from mail-pg1-f196.google.com (mail-pg1-f196.google.com [209.85.215.196]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D9C561CC88D; Wed, 30 Oct 2024 01:43:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.196 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730252618; cv=none; b=hnjGh0KkZng3DJtyMaE162mF1+FwqizPIMpR1AQvFHxMe3oLm2ZeSFKMOGZr+TIQ5O6TovZ4B+vltk4iDKCYm5BjnSSk9ODRcYjMzDWPj72JTQ9AjTBfr85gw/jU0ToTAEhADykgzsX/fooyFemjjZQr0JiCa95LjbGHDZ7MWg8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730252618; c=relaxed/simple; bh=Dxf+YjSfF9s66wnRYYKzNGRdTBF+f3o1p3CcPZ9IKMU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ifiV+r7DWf05/zL6gzQFZZTfHDXbeHpdpyknGl3xnVXOSNbIRDcZn+l0doweyDSqUp8Q7Xb2OXUYQZ87MDbx+l00ipTKK25+SlAQyMAzDtAFOts6/o3n4Ty+zdxY9ww2rJJSbeSE/Yb65ER9rckl10HLvbm4m8lEZZNOW2WbEX0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ZzJyIoF9; arc=none smtp.client-ip=209.85.215.196 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZzJyIoF9" Received: by mail-pg1-f196.google.com with SMTP id 41be03b00d2f7-7ea7ad1e01fso325672a12.0; Tue, 29 Oct 2024 18:43:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730252615; x=1730857415; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nHha3jxrqpGXunHNpntG6RFQwcyCzV6dVXG5YPCOYY8=; b=ZzJyIoF99+/D2An+E4//AvB33QqV8aAY0wvdSFborjak+7tA62x1s6JRuZC54tFDRA 3ahuc9mYqNY/8O5/1DrOzFPLgeP+DnlVQOztM0nLmiFhhr3XZoUDex/XP5ecw4kW89yL 1xInJzwegIjScj/lrXy5d9IB/p+hikYa0uQoApZlCVLYKRsEjZqfspdKmaHhOiHO8ZtI 9hg6RtUPMxfwJHmP8FkmipvSOTCoyio/qFrpifU7btNP0AiUebZsfbHpdM41VOUl+AYW RzhOytnWRjM/DQae7qyGkVWx/vc7D9ZPww1Ql4C4TmMqLWYORBQJQ9dc08CWjFUayZqj HKJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730252615; x=1730857415; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nHha3jxrqpGXunHNpntG6RFQwcyCzV6dVXG5YPCOYY8=; b=vT8caD1ok1saEAJCPeYBrwHnJ2tbKK8ldWZ/14mknVH7Kgb59PoIMUUKlRudTCoMSz rdoGszCmG2aWgmQWMSSRSPj4vObSsVMXlEl3ueKilG/J/xc8OuuhPe/dgKzBuunr+VT8 VLJc6EtyAmsbH0WoAUtK3s/PVnzzzyFdFOkz40oPI3ybwmdizDg9puJRFZO33v4nacx8 YKi45AaESAU+YXH2uVaUQN/cFvXw6C51Xg4I98PiR3FxfBkppfwBxbpPwhlfuU4+OETq o552hJohHaYzEVRycZrlyPJaznJmqZi+mtNOwe9JBlrWmwGon6tZghzsWzvdH/KZYjgf rkrg== X-Forwarded-Encrypted: i=1; AJvYcCUdK43nYGrT/mNHJ5l3ntzddOq4mbmptetNVa/9PvQvSqRTWUP0vWDHbCKTyL4hAhShCSs=@vger.kernel.org, AJvYcCUfmDnnKpScAmkXyg9uej6rEIVc1uK7OPMhgdytVNPf+xDu7azTInEvoJmovps38SG0gDs6TyXc@vger.kernel.org, AJvYcCWfWmiqdtgAgRrLZw6ykov4YESiBdh1tY1tXP5aTL90iuUbkmW/gyUJ8GCyPPuntrF9EMjUOnvWd6iQCixP@vger.kernel.org, AJvYcCXBTMLbOCcIplNfDALisdZJlIkpIXcVVSfWfnzIH0gUSA+R9l9H/AsJ9QCOYMmVb0+W4ERNeC5FGsdLgQ/H0ywg@vger.kernel.org X-Gm-Message-State: AOJu0YxbIrWc2BeRJbqk5w69VRtGav73d6fp1cbwipNIGjxJCuH+izI6 lbicpstjEy0H6OKYC7Qbn4LoqewC2vmaI6o8cKDMVpt1aKAqnCKX0hHR7jZC X-Google-Smtp-Source: AGHT+IFJJUSCB//39VAXd17haAZ2/OpwKzfzvKZ8vtIdhSrK7HsIGTHuQWmpfO3gxw0dkEqo9pfwwg== X-Received: by 2002:a05:6a21:33a4:b0:1d9:e5af:a600 with SMTP id adf61e73a8af0-1db7fe09c92mr1060617637.10.1730252615119; Tue, 29 Oct 2024 18:43:35 -0700 (PDT) Received: from localhost.localdomain ([43.129.25.208]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7edc866906dsm8138407a12.10.2024.10.29.18.43.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2024 18:43:34 -0700 (PDT) From: Menglong Dong X-Google-Original-From: Menglong Dong To: pabeni@redhat.com Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, horms@kernel.org, dsahern@kernel.org, pablo@netfilter.org, kadlec@netfilter.org, roopa@nvidia.com, razor@blackwall.org, gnault@redhat.com, bigeasy@linutronix.de, hawk@kernel.org, idosch@nvidia.com, dongml2@chinatelecom.cn, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, bridge@lists.linux.dev, bpf@vger.kernel.org Subject: [PATCH RESEND net-next v4 7/9] net: ip: make ip_route_input() return drop reasons Date: Wed, 30 Oct 2024 09:41:43 +0800 Message-Id: <20241030014145.1409628-8-dongml2@chinatelecom.cn> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241030014145.1409628-1-dongml2@chinatelecom.cn> References: <20241030014145.1409628-1-dongml2@chinatelecom.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In this commit, we make ip_route_input() return skb drop reasons that come from ip_route_input_noref(). Meanwhile, adjust all the call to it. Signed-off-by: Menglong Dong --- v4: - replace the variable "err" with "reason" for the return value of ip_route_input() --- include/net/route.h | 7 ++++--- net/bridge/br_netfilter_hooks.c | 11 ++++++----- net/ipv4/icmp.c | 2 +- net/ipv4/ip_options.c | 2 +- net/ipv6/seg6_local.c | 14 +++++++------- 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/include/net/route.h b/include/net/route.h index 11674f7c6be6..f4ab5412c9c9 100644 --- a/include/net/route.h +++ b/include/net/route.h @@ -210,8 +210,9 @@ int ip_route_use_hint(struct sk_buff *skb, __be32 daddr= , __be32 saddr, dscp_t dscp, struct net_device *dev, const struct sk_buff *hint); =20 -static inline int ip_route_input(struct sk_buff *skb, __be32 dst, __be32 s= rc, - dscp_t dscp, struct net_device *devin) +static inline enum skb_drop_reason +ip_route_input(struct sk_buff *skb, __be32 dst, __be32 src, dscp_t dscp, + struct net_device *devin) { enum skb_drop_reason reason; =20 @@ -224,7 +225,7 @@ static inline int ip_route_input(struct sk_buff *skb, _= _be32 dst, __be32 src, } rcu_read_unlock(); =20 - return reason ? -EINVAL : 0; + return reason; } =20 void ipv4_update_pmtu(struct sk_buff *skb, struct net *net, u32 mtu, int o= if, diff --git a/net/bridge/br_netfilter_hooks.c b/net/bridge/br_netfilter_hook= s.c index 17a5f5923d61..110cffc24a1d 100644 --- a/net/bridge/br_netfilter_hooks.c +++ b/net/bridge/br_netfilter_hooks.c @@ -373,8 +373,8 @@ static int br_nf_pre_routing_finish(struct net *net, st= ruct sock *sk, struct sk_ struct nf_bridge_info *nf_bridge =3D nf_bridge_info_get(skb); struct net_device *dev =3D skb->dev, *br_indev; const struct iphdr *iph =3D ip_hdr(skb); + enum skb_drop_reason reason; struct rtable *rt; - int err; =20 br_indev =3D nf_bridge_get_physindev(skb, net); if (!br_indev) { @@ -390,9 +390,9 @@ static int br_nf_pre_routing_finish(struct net *net, st= ruct sock *sk, struct sk_ } nf_bridge->in_prerouting =3D 0; if (br_nf_ipv4_daddr_was_changed(skb, nf_bridge)) { - err =3D ip_route_input(skb, iph->daddr, iph->saddr, - ip4h_dscp(iph), dev); - if (err) { + reason =3D ip_route_input(skb, iph->daddr, iph->saddr, + ip4h_dscp(iph), dev); + if (reason) { struct in_device *in_dev =3D __in_dev_get_rcu(dev); =20 /* If err equals -EHOSTUNREACH the error is due to a @@ -402,7 +402,8 @@ static int br_nf_pre_routing_finish(struct net *net, st= ruct sock *sk, struct sk_ * martian destinations: loopback destinations and destination * 0.0.0.0. In both cases the packet will be dropped because the * destination is the loopback device and not the bridge. */ - if (err !=3D -EHOSTUNREACH || !in_dev || IN_DEV_FORWARD(in_dev)) + if (reason !=3D SKB_DROP_REASON_IP_INADDRERRORS || !in_dev || + IN_DEV_FORWARD(in_dev)) goto free_skb; =20 rt =3D ip_route_output(net, iph->daddr, 0, diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c index 33eec844a5a0..4f088fa1c2f2 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 =3D skb_in->_skb_refdst; /* save old refdst */ skb_dst_set(skb_in, NULL); err =3D ip_route_input(skb_in, fl4_dec.daddr, fl4_dec.saddr, - dscp, rt2->dst.dev); + dscp, rt2->dst.dev) ? -EINVAL : 0; =20 dst_release(&rt2->dst); rt2 =3D skb_rtable(skb_in); diff --git a/net/ipv4/ip_options.c b/net/ipv4/ip_options.c index 81e86e5defee..e3321932bec0 100644 --- a/net/ipv4/ip_options.c +++ b/net/ipv4/ip_options.c @@ -618,7 +618,7 @@ int ip_options_rcv_srr(struct sk_buff *skb, struct net_= device *dev) orefdst =3D skb->_skb_refdst; skb_dst_set(skb, NULL); err =3D ip_route_input(skb, nexthop, iph->saddr, ip4h_dscp(iph), - dev); + dev) ? -EINVAL : 0; rt2 =3D skb_rtable(skb); if (err || (rt2->rt_type !=3D RTN_UNICAST && rt2->rt_type !=3D RTN_LOCAL= )) { skb_dst_drop(skb); diff --git a/net/ipv6/seg6_local.c b/net/ipv6/seg6_local.c index c74705ead984..ac1dbd492c22 100644 --- a/net/ipv6/seg6_local.c +++ b/net/ipv6/seg6_local.c @@ -954,10 +954,10 @@ static int input_action_end_dx4_finish(struct net *ne= t, struct sock *sk, struct sk_buff *skb) { struct dst_entry *orig_dst =3D skb_dst(skb); + enum skb_drop_reason reason; struct seg6_local_lwt *slwt; struct iphdr *iph; __be32 nhaddr; - int err; =20 slwt =3D seg6_local_lwtunnel(orig_dst->lwtstate); =20 @@ -967,9 +967,9 @@ static int input_action_end_dx4_finish(struct net *net,= struct sock *sk, =20 skb_dst_drop(skb); =20 - err =3D ip_route_input(skb, nhaddr, iph->saddr, 0, skb->dev); - if (err) { - kfree_skb(skb); + reason =3D ip_route_input(skb, nhaddr, iph->saddr, 0, skb->dev); + if (reason) { + kfree_skb_reason(skb, reason); return -EINVAL; } =20 @@ -1174,8 +1174,8 @@ static struct sk_buff *end_dt_vrf_core(struct sk_buff= *skb, static int input_action_end_dt4(struct sk_buff *skb, struct seg6_local_lwt *slwt) { + enum skb_drop_reason reason; struct iphdr *iph; - int err; =20 if (!decap_and_validate(skb, IPPROTO_IPIP)) goto drop; @@ -1193,8 +1193,8 @@ static int input_action_end_dt4(struct sk_buff *skb, =20 iph =3D ip_hdr(skb); =20 - err =3D ip_route_input(skb, iph->daddr, iph->saddr, 0, skb->dev); - if (unlikely(err)) + reason =3D ip_route_input(skb, iph->daddr, iph->saddr, 0, skb->dev); + if (unlikely(reason)) goto drop; =20 return dst_input(skb); --=20 2.39.5