Skip to content

Commit bbadb9a

Browse files
florolfdavem330
authored andcommitted
net: ipv4: fix multipath RTM_GETROUTE behavior when iif is given
inet_rtm_getroute synthesizes a skeletal ICMP skb, which is passed to ip_route_input when iif is given. If a multipath route is present for the designated destination, fib_multipath_hash ends up being called with that skb. However, as that skb contains no information beyond the protocol type, the calculated hash does not match the one we would see for a real packet. There is currently no way to fix this for layer 4 hashing, as RTM_GETROUTE doesn't have the necessary information to create layer 4 headers. To fix this for layer 3 hashing, set appropriate saddr/daddrs in the skb and also change the protocol to UDP to avoid special treatment for ICMP. Signed-off-by: Florian Larysch <fl@n621.de> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 6f551bd commit bbadb9a

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

net/ipv4/route.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2667,10 +2667,6 @@ static int inet_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh)
26672667
skb_reset_mac_header(skb);
26682668
skb_reset_network_header(skb);
26692669

2670-
/* Bugfix: need to give ip_route_input enough of an IP header to not gag. */
2671-
ip_hdr(skb)->protocol = IPPROTO_ICMP;
2672-
skb_reserve(skb, MAX_HEADER + sizeof(struct iphdr));
2673-
26742670
src = tb[RTA_SRC] ? nla_get_in_addr(tb[RTA_SRC]) : 0;
26752671
dst = tb[RTA_DST] ? nla_get_in_addr(tb[RTA_DST]) : 0;
26762672
iif = tb[RTA_IIF] ? nla_get_u32(tb[RTA_IIF]) : 0;
@@ -2680,6 +2676,15 @@ static int inet_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh)
26802676
else
26812677
uid = (iif ? INVALID_UID : current_uid());
26822678

2679+
/* Bugfix: need to give ip_route_input enough of an IP header to
2680+
* not gag.
2681+
*/
2682+
ip_hdr(skb)->protocol = IPPROTO_UDP;
2683+
ip_hdr(skb)->saddr = src;
2684+
ip_hdr(skb)->daddr = dst;
2685+
2686+
skb_reserve(skb, MAX_HEADER + sizeof(struct iphdr));
2687+
26832688
memset(&fl4, 0, sizeof(fl4));
26842689
fl4.daddr = dst;
26852690
fl4.saddr = src;

0 commit comments

Comments
 (0)