Commit ec20b283 authored by Guillaume Nault's avatar Guillaume Nault Committed by David S. Miller
Browse files

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: default avatarGuillaume Nault <gnault@redhat.com>
Acked-by: Leon Romanovsky <leonro@nvidia.com> # infiniband
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 22978397
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -1985,7 +1985,8 @@ static int irdma_addr_resolve_neigh(struct irdma_device *iwdev, u32 src_ip,
	__be32 dst_ipaddr = htonl(dst_ip);
	__be32 src_ipaddr = htonl(src_ip);

	rt = ip_route_output(&init_net, dst_ipaddr, src_ipaddr, 0, 0);
	rt = ip_route_output(&init_net, dst_ipaddr, src_ipaddr, 0, 0,
			     RT_SCOPE_UNIVERSE);
	if (IS_ERR(rt)) {
		ibdev_dbg(&iwdev->ibdev, "CM: ip_route_output fail\n");
		return -EINVAL;
+2 −1
Original line number Diff line number Diff line
@@ -447,7 +447,8 @@ qedr_addr4_resolve(struct qedr_dev *dev,
	struct rtable *rt = NULL;
	int rc = 0;

	rt = ip_route_output(&init_net, dst_ip, src_ip, 0, 0);
	rt = ip_route_output(&init_net, dst_ip, src_ip, 0, 0,
			     RT_SCOPE_UNIVERSE);
	if (IS_ERR(rt)) {
		DP_ERR(dev, "ip_route_output returned error\n");
		return -EINVAL;
+2 −2
Original line number Diff line number Diff line
@@ -3014,8 +3014,8 @@ static void bond_arp_send_all(struct bonding *bond, struct slave *slave)
		tags = NULL;

		/* Find out through which dev should the packet go */
		rt = ip_route_output(dev_net(bond->dev), targets[i], 0,
				     RTO_ONLINK, 0);
		rt = ip_route_output(dev_net(bond->dev), targets[i], 0, 0, 0,
				     RT_SCOPE_LINK);
		if (IS_ERR(rt)) {
			/* there's no route to target - try to send arp
			 * probe to generate any traffic (arp_validate=0)
+2 −1
Original line number Diff line number Diff line
@@ -3682,7 +3682,8 @@ static int cnic_get_v4_route(struct sockaddr_in *dst_addr,
#if defined(CONFIG_INET)
	struct rtable *rt;

	rt = ip_route_output(&init_net, dst_addr->sin_addr.s_addr, 0, 0, 0);
	rt = ip_route_output(&init_net, dst_addr->sin_addr.s_addr, 0, 0, 0,
			     RT_SCOPE_UNIVERSE);
	if (!IS_ERR(rt)) {
		*dst = &rt->dst;
		return 0;
+8 −1
Original line number Diff line number Diff line
@@ -141,15 +141,22 @@ static inline struct rtable *ip_route_output_key(struct net *net, struct flowi4
	return ip_route_output_flow(net, flp, NULL);
}

/* Simplistic IPv4 route lookup function.
 * This is only suitable for some particular use cases: since the flowi4
 * structure is only partially set, it may bypass some fib-rules.
 */
static inline struct rtable *ip_route_output(struct net *net, __be32 daddr,
					     __be32 saddr, u8 tos, int oif)
					     __be32 saddr, u8 tos, int oif,
					     __u8 scope)
{
	struct flowi4 fl4 = {
		.flowi4_oif = oif,
		.flowi4_tos = tos,
		.flowi4_scope = scope,
		.daddr = daddr,
		.saddr = saddr,
	};

	return ip_route_output_key(net, &fl4);
}

Loading