Skip to content

Commit 5e1a99e

Browse files
liuhangbindavem330
authored andcommitted
ipv4: Add ICMPv6 support when parse route ipproto
For ip rules, we need to use 'ipproto ipv6-icmp' to match ICMPv6 headers. But for ip -6 route, currently we only support tcp, udp and icmp. Add ICMPv6 support so we can match ipv6-icmp rules for route lookup. v2: As David Ahern and Sabrina Dubroca suggested, Add an argument to rtm_getroute_parse_ip_proto() to handle ICMP/ICMPv6 with different family. Reported-by: Jianlin Shi <jishi@redhat.com> Fixes: eacb938 ("ipv6: support sport, dport and ip_proto in RTM_GETROUTE") Signed-off-by: Hangbin Liu <liuhangbin@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 90490ef commit 5e1a99e

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

include/net/ip.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ extern int sysctl_icmp_msgs_burst;
718718
int ip_misc_proc_init(void);
719719
#endif
720720

721-
int rtm_getroute_parse_ip_proto(struct nlattr *attr, u8 *ip_proto,
721+
int rtm_getroute_parse_ip_proto(struct nlattr *attr, u8 *ip_proto, u8 family,
722722
struct netlink_ext_ack *extack);
723723

724724
#endif /* _IP_H */

net/ipv4/netlink.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,30 @@
33
#include <linux/types.h>
44
#include <net/net_namespace.h>
55
#include <net/netlink.h>
6+
#include <linux/in6.h>
67
#include <net/ip.h>
78

8-
int rtm_getroute_parse_ip_proto(struct nlattr *attr, u8 *ip_proto,
9+
int rtm_getroute_parse_ip_proto(struct nlattr *attr, u8 *ip_proto, u8 family,
910
struct netlink_ext_ack *extack)
1011
{
1112
*ip_proto = nla_get_u8(attr);
1213

1314
switch (*ip_proto) {
1415
case IPPROTO_TCP:
1516
case IPPROTO_UDP:
17+
return 0;
1618
case IPPROTO_ICMP:
19+
if (family != AF_INET)
20+
break;
21+
return 0;
22+
#if IS_ENABLED(CONFIG_IPV6)
23+
case IPPROTO_ICMPV6:
24+
if (family != AF_INET6)
25+
break;
1726
return 0;
18-
default:
19-
NL_SET_ERR_MSG(extack, "Unsupported ip proto");
20-
return -EOPNOTSUPP;
27+
#endif
2128
}
29+
NL_SET_ERR_MSG(extack, "Unsupported ip proto");
30+
return -EOPNOTSUPP;
2231
}
2332
EXPORT_SYMBOL_GPL(rtm_getroute_parse_ip_proto);

net/ipv4/route.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2803,7 +2803,7 @@ static int inet_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh,
28032803

28042804
if (tb[RTA_IP_PROTO]) {
28052805
err = rtm_getroute_parse_ip_proto(tb[RTA_IP_PROTO],
2806-
&ip_proto, extack);
2806+
&ip_proto, AF_INET, extack);
28072807
if (err)
28082808
return err;
28092809
}

net/ipv6/route.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4893,7 +4893,8 @@ static int inet6_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh,
48934893

48944894
if (tb[RTA_IP_PROTO]) {
48954895
err = rtm_getroute_parse_ip_proto(tb[RTA_IP_PROTO],
4896-
&fl6.flowi6_proto, extack);
4896+
&fl6.flowi6_proto, AF_INET6,
4897+
extack);
48974898
if (err)
48984899
goto errout;
48994900
}

0 commit comments

Comments
 (0)