Commit 72331bc0cd072c3f4b670cd1256e47681fc53b80
Committed by
David S. Miller
1 parent
cdaf0b835d
Exists in
smarc-l5.0.0_1.0.0-ga
and in
5 other branches
ipv6: Fix RTM_GETROUTE's interpretation of RTA_IIF to be consistent with ipv4
In IPv4, if an RTA_IIF attribute is specified within an RTM_GETROUTE message, then a route is searched as if a packet was received on the specified 'iif' interface. However in IPv6, RTA_IIF is not interpreted in the same way: 'inet6_rtm_getroute()' always calls 'ip6_route_output()', regardless the RTA_IIF attribute. As a result, in IPv6 there's no way to use RTM_GETROUTE in order to look for a route as if a packet was received on a specific interface. Fix 'inet6_rtm_getroute()' so that RTA_IIF is interpreted as "lookup a route as if a packet was received on the specified interface", similar to IPv4's 'inet_rtm_getroute()' interpretation. Reported-by: Ami Koren <amikoren@yahoo.com> Signed-off-by: Shmulik Ladkani <shmulik.ladkani@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Showing 1 changed file with 27 additions and 7 deletions Side-by-side Diff
net/ipv6/route.c
... | ... | @@ -881,6 +881,16 @@ |
881 | 881 | return ip6_pol_route(net, table, fl6->flowi6_iif, fl6, flags); |
882 | 882 | } |
883 | 883 | |
884 | +static struct dst_entry *ip6_route_input_lookup(struct net *net, | |
885 | + struct net_device *dev, | |
886 | + struct flowi6 *fl6, int flags) | |
887 | +{ | |
888 | + if (rt6_need_strict(&fl6->daddr) && dev->type != ARPHRD_PIMREG) | |
889 | + flags |= RT6_LOOKUP_F_IFACE; | |
890 | + | |
891 | + return fib6_rule_lookup(net, fl6, flags, ip6_pol_route_input); | |
892 | +} | |
893 | + | |
884 | 894 | void ip6_route_input(struct sk_buff *skb) |
885 | 895 | { |
886 | 896 | const struct ipv6hdr *iph = ipv6_hdr(skb); |
... | ... | @@ -895,10 +905,7 @@ |
895 | 905 | .flowi6_proto = iph->nexthdr, |
896 | 906 | }; |
897 | 907 | |
898 | - if (rt6_need_strict(&iph->daddr) && skb->dev->type != ARPHRD_PIMREG) | |
899 | - flags |= RT6_LOOKUP_F_IFACE; | |
900 | - | |
901 | - skb_dst_set(skb, fib6_rule_lookup(net, &fl6, flags, ip6_pol_route_input)); | |
908 | + skb_dst_set(skb, ip6_route_input_lookup(net, skb->dev, &fl6, flags)); | |
902 | 909 | } |
903 | 910 | |
904 | 911 | static struct rt6_info *ip6_pol_route_output(struct net *net, struct fib6_table *table, |
... | ... | @@ -2537,7 +2544,7 @@ |
2537 | 2544 | struct sk_buff *skb; |
2538 | 2545 | struct rtmsg *rtm; |
2539 | 2546 | struct flowi6 fl6; |
2540 | - int err, iif = 0; | |
2547 | + int err, iif = 0, oif = 0; | |
2541 | 2548 | |
2542 | 2549 | err = nlmsg_parse(nlh, sizeof(*rtm), tb, RTA_MAX, rtm_ipv6_policy); |
2543 | 2550 | if (err < 0) |
2544 | 2551 | |
2545 | 2552 | |
... | ... | @@ -2564,15 +2571,29 @@ |
2564 | 2571 | iif = nla_get_u32(tb[RTA_IIF]); |
2565 | 2572 | |
2566 | 2573 | if (tb[RTA_OIF]) |
2567 | - fl6.flowi6_oif = nla_get_u32(tb[RTA_OIF]); | |
2574 | + oif = nla_get_u32(tb[RTA_OIF]); | |
2568 | 2575 | |
2569 | 2576 | if (iif) { |
2570 | 2577 | struct net_device *dev; |
2578 | + int flags = 0; | |
2579 | + | |
2571 | 2580 | dev = __dev_get_by_index(net, iif); |
2572 | 2581 | if (!dev) { |
2573 | 2582 | err = -ENODEV; |
2574 | 2583 | goto errout; |
2575 | 2584 | } |
2585 | + | |
2586 | + fl6.flowi6_iif = iif; | |
2587 | + | |
2588 | + if (!ipv6_addr_any(&fl6.saddr)) | |
2589 | + flags |= RT6_LOOKUP_F_HAS_SADDR; | |
2590 | + | |
2591 | + rt = (struct rt6_info *)ip6_route_input_lookup(net, dev, &fl6, | |
2592 | + flags); | |
2593 | + } else { | |
2594 | + fl6.flowi6_oif = oif; | |
2595 | + | |
2596 | + rt = (struct rt6_info *)ip6_route_output(net, NULL, &fl6); | |
2576 | 2597 | } |
2577 | 2598 | |
2578 | 2599 | skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL); |
... | ... | @@ -2587,7 +2608,6 @@ |
2587 | 2608 | skb_reset_mac_header(skb); |
2588 | 2609 | skb_reserve(skb, MAX_HEADER + sizeof(struct ipv6hdr)); |
2589 | 2610 | |
2590 | - rt = (struct rt6_info*) ip6_route_output(net, NULL, &fl6); | |
2591 | 2611 | skb_dst_set(skb, &rt->dst); |
2592 | 2612 | |
2593 | 2613 | err = rt6_fill_node(net, skb, rt, &fl6.daddr, &fl6.saddr, iif, |