Skip to content

Commit 72331bc

Browse files
sladkanidavem330
authored andcommitted
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>
1 parent cdaf0b8 commit 72331bc

1 file changed

Lines changed: 27 additions & 7 deletions

File tree

‎net/ipv6/route.c‎

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,16 @@ static struct rt6_info *ip6_pol_route_input(struct net *net, struct fib6_table *
881881
return ip6_pol_route(net, table, fl6->flowi6_iif, fl6, flags);
882882
}
883883

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+
884894
void ip6_route_input(struct sk_buff *skb)
885895
{
886896
const struct ipv6hdr *iph = ipv6_hdr(skb);
@@ -895,10 +905,7 @@ void ip6_route_input(struct sk_buff *skb)
895905
.flowi6_proto = iph->nexthdr,
896906
};
897907

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));
902909
}
903910

904911
static struct rt6_info *ip6_pol_route_output(struct net *net, struct fib6_table *table,
@@ -2537,7 +2544,7 @@ static int inet6_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr* nlh, void
25372544
struct sk_buff *skb;
25382545
struct rtmsg *rtm;
25392546
struct flowi6 fl6;
2540-
int err, iif = 0;
2547+
int err, iif = 0, oif = 0;
25412548

25422549
err = nlmsg_parse(nlh, sizeof(*rtm), tb, RTA_MAX, rtm_ipv6_policy);
25432550
if (err < 0)
@@ -2564,15 +2571,29 @@ static int inet6_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr* nlh, void
25642571
iif = nla_get_u32(tb[RTA_IIF]);
25652572

25662573
if (tb[RTA_OIF])
2567-
fl6.flowi6_oif = nla_get_u32(tb[RTA_OIF]);
2574+
oif = nla_get_u32(tb[RTA_OIF]);
25682575

25692576
if (iif) {
25702577
struct net_device *dev;
2578+
int flags = 0;
2579+
25712580
dev = __dev_get_by_index(net, iif);
25722581
if (!dev) {
25732582
err = -ENODEV;
25742583
goto errout;
25752584
}
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);
25762597
}
25772598

25782599
skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
@@ -2587,7 +2608,6 @@ static int inet6_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr* nlh, void
25872608
skb_reset_mac_header(skb);
25882609
skb_reserve(skb, MAX_HEADER + sizeof(struct ipv6hdr));
25892610

2590-
rt = (struct rt6_info*) ip6_route_output(net, NULL, &fl6);
25912611
skb_dst_set(skb, &rt->dst);
25922612

25932613
err = rt6_fill_node(net, skb, rt, &fl6.daddr, &fl6.saddr, iif,

0 commit comments

Comments
 (0)