Skip to content

Commit b8da7d2

Browse files
author
CKI Backport Bot
committed
ipv4: Set scope explicitly in ip_route_output().
JIRA: https://issues.redhat.com/browse/RHEL-57748 commit ec20b28 Author: Guillaume Nault <gnault@redhat.com> Date: Fri Apr 5 22:05:00 2024 +0200 ipv4: Set scope explicitly in ip_route_output(). Add a "scope" parameter to ip_route_output() so that callers don't have to override the tos parameter with the RTO_ONLINK flag if they want a local scope. This will allow converting flowi4_tos to dscp_t in the future, thus allowing static analysers to flag invalid interactions between "tos" (the DSCP bits) and ECN. Only three users ask for local scope (bonding, arp and atm). The others continue to use RT_SCOPE_UNIVERSE. While there, add a comment to warn users about the limitations of ip_route_output(). Signed-off-by: Guillaume Nault <gnault@redhat.com> Acked-by: Leon Romanovsky <leonro@nvidia.com> # infiniband Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: CKI Backport Bot <cki-ci-bot+cki-gitlab-backport-bot@redhat.com>
1 parent 5dced41 commit b8da7d2

File tree

10 files changed

+28
-13
lines changed

10 files changed

+28
-13
lines changed

drivers/infiniband/hw/irdma/cm.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1985,7 +1985,8 @@ static int irdma_addr_resolve_neigh(struct irdma_device *iwdev, u32 src_ip,
19851985
__be32 dst_ipaddr = htonl(dst_ip);
19861986
__be32 src_ipaddr = htonl(src_ip);
19871987

1988-
rt = ip_route_output(&init_net, dst_ipaddr, src_ipaddr, 0, 0);
1988+
rt = ip_route_output(&init_net, dst_ipaddr, src_ipaddr, 0, 0,
1989+
RT_SCOPE_UNIVERSE);
19891990
if (IS_ERR(rt)) {
19901991
ibdev_dbg(&iwdev->ibdev, "CM: ip_route_output fail\n");
19911992
return -EINVAL;

drivers/infiniband/hw/qedr/qedr_iw_cm.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,8 @@ qedr_addr4_resolve(struct qedr_dev *dev,
447447
struct rtable *rt = NULL;
448448
int rc = 0;
449449

450-
rt = ip_route_output(&init_net, dst_ip, src_ip, 0, 0);
450+
rt = ip_route_output(&init_net, dst_ip, src_ip, 0, 0,
451+
RT_SCOPE_UNIVERSE);
451452
if (IS_ERR(rt)) {
452453
DP_ERR(dev, "ip_route_output returned error\n");
453454
return -EINVAL;

drivers/net/bonding/bond_main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3019,8 +3019,8 @@ static void bond_arp_send_all(struct bonding *bond, struct slave *slave)
30193019
tags = NULL;
30203020

30213021
/* Find out through which dev should the packet go */
3022-
rt = ip_route_output(dev_net(bond->dev), targets[i], 0,
3023-
RTO_ONLINK, 0);
3022+
rt = ip_route_output(dev_net(bond->dev), targets[i], 0, 0, 0,
3023+
RT_SCOPE_LINK);
30243024
if (IS_ERR(rt)) {
30253025
/* there's no route to target - try to send arp
30263026
* probe to generate any traffic (arp_validate=0)

drivers/net/ethernet/broadcom/cnic.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3682,7 +3682,8 @@ static int cnic_get_v4_route(struct sockaddr_in *dst_addr,
36823682
#if defined(CONFIG_INET)
36833683
struct rtable *rt;
36843684

3685-
rt = ip_route_output(&init_net, dst_addr->sin_addr.s_addr, 0, 0, 0);
3685+
rt = ip_route_output(&init_net, dst_addr->sin_addr.s_addr, 0, 0, 0,
3686+
RT_SCOPE_UNIVERSE);
36863687
if (!IS_ERR(rt)) {
36873688
*dst = &rt->dst;
36883689
return 0;

include/net/route.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,15 +131,22 @@ static inline struct rtable *ip_route_output_key(struct net *net, struct flowi4
131131
return ip_route_output_flow(net, flp, NULL);
132132
}
133133

134+
/* Simplistic IPv4 route lookup function.
135+
* This is only suitable for some particular use cases: since the flowi4
136+
* structure is only partially set, it may bypass some fib-rules.
137+
*/
134138
static inline struct rtable *ip_route_output(struct net *net, __be32 daddr,
135-
__be32 saddr, u8 tos, int oif)
139+
__be32 saddr, u8 tos, int oif,
140+
__u8 scope)
136141
{
137142
struct flowi4 fl4 = {
138143
.flowi4_oif = oif,
139144
.flowi4_tos = tos,
145+
.flowi4_scope = scope,
140146
.daddr = daddr,
141147
.saddr = saddr,
142148
};
149+
143150
return ip_route_output_key(net, &fl4);
144151
}
145152

net/atm/clip.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ static int clip_setentry(struct atm_vcc *vcc, __be32 ip)
463463
unlink_clip_vcc(clip_vcc);
464464
return 0;
465465
}
466-
rt = ip_route_output(&init_net, ip, 0, 1, 0);
466+
rt = ip_route_output(&init_net, ip, 0, 0, 0, RT_SCOPE_LINK);
467467
if (IS_ERR(rt))
468468
return PTR_ERR(rt);
469469
neigh = __neigh_lookup(&arp_tbl, &ip, rt->dst.dev, 1);

net/bridge/br_netfilter_hooks.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,8 @@ static int br_nf_pre_routing_finish(struct net *net, struct sock *sk, struct sk_
399399
goto free_skb;
400400

401401
rt = ip_route_output(net, iph->daddr, 0,
402-
RT_TOS(iph->tos), 0);
402+
RT_TOS(iph->tos), 0,
403+
RT_SCOPE_UNIVERSE);
403404
if (!IS_ERR(rt)) {
404405
/* - Bridged-and-DNAT'ed traffic doesn't
405406
* require ip_forwarding. */

net/ipv4/arp.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,8 @@ static int arp_filter(__be32 sip, __be32 tip, struct net_device *dev)
435435
/*unsigned long now; */
436436
struct net *net = dev_net(dev);
437437

438-
rt = ip_route_output(net, sip, tip, 0, l3mdev_master_ifindex_rcu(dev));
438+
rt = ip_route_output(net, sip, tip, 0, l3mdev_master_ifindex_rcu(dev),
439+
RT_SCOPE_UNIVERSE);
439440
if (IS_ERR(rt))
440441
return 1;
441442
if (rt->dst.dev != dev) {
@@ -1035,7 +1036,8 @@ static int arp_req_set(struct net *net, struct arpreq *r,
10351036
if (r->arp_flags & ATF_PERM)
10361037
r->arp_flags |= ATF_COM;
10371038
if (!dev) {
1038-
struct rtable *rt = ip_route_output(net, ip, 0, RTO_ONLINK, 0);
1039+
struct rtable *rt = ip_route_output(net, ip, 0, 0, 0,
1040+
RT_SCOPE_LINK);
10391041

10401042
if (IS_ERR(rt))
10411043
return PTR_ERR(rt);
@@ -1167,7 +1169,8 @@ static int arp_req_delete(struct net *net, struct arpreq *r,
11671169

11681170
ip = ((struct sockaddr_in *)&r->arp_pa)->sin_addr.s_addr;
11691171
if (!dev) {
1170-
struct rtable *rt = ip_route_output(net, ip, 0, RTO_ONLINK, 0);
1172+
struct rtable *rt = ip_route_output(net, ip, 0, 0, 0,
1173+
RT_SCOPE_LINK);
11711174
if (IS_ERR(rt))
11721175
return PTR_ERR(rt);
11731176
dev = rt->dst.dev;

net/ipv4/igmp.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1842,7 +1842,8 @@ static struct in_device *ip_mc_find_dev(struct net *net, struct ip_mreqn *imr)
18421842
if (!dev) {
18431843
struct rtable *rt = ip_route_output(net,
18441844
imr->imr_multiaddr.s_addr,
1845-
0, 0, 0);
1845+
0, 0, 0,
1846+
RT_SCOPE_UNIVERSE);
18461847
if (!IS_ERR(rt)) {
18471848
dev = rt->dst.dev;
18481849
ip_rt_put(rt);

net/mpls/af_mpls.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ static struct net_device *inet_fib_lookup_dev(struct net *net,
594594
struct in_addr daddr;
595595

596596
memcpy(&daddr, addr, sizeof(struct in_addr));
597-
rt = ip_route_output(net, daddr.s_addr, 0, 0, 0);
597+
rt = ip_route_output(net, daddr.s_addr, 0, 0, 0, RT_SCOPE_UNIVERSE);
598598
if (IS_ERR(rt))
599599
return ERR_CAST(rt);
600600

0 commit comments

Comments
 (0)