diff options
author | Hangbin Liu <liuhangbin@gmail.com> | 2019-02-27 03:15:29 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2019-03-01 19:41:27 -0500 |
commit | 5e1a99eae84999a2536f50a0beaf5d5262337f40 (patch) | |
tree | aee5af984c0d5af3510ed5095c7874dcaabf1e01 /net | |
parent | 90490ef7269906423a1c1b917fc24be8b1602658 (diff) |
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: eacb9384a3fe ("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>
Diffstat (limited to 'net')
-rw-r--r-- | net/ipv4/netlink.c | 17 | ||||
-rw-r--r-- | net/ipv4/route.c | 2 | ||||
-rw-r--r-- | net/ipv6/route.c | 3 |
3 files changed, 16 insertions, 6 deletions
diff --git a/net/ipv4/netlink.c b/net/ipv4/netlink.c index f86bb4f06609..d8e3a1fb8e82 100644 --- a/net/ipv4/netlink.c +++ b/net/ipv4/netlink.c | |||
@@ -3,9 +3,10 @@ | |||
3 | #include <linux/types.h> | 3 | #include <linux/types.h> |
4 | #include <net/net_namespace.h> | 4 | #include <net/net_namespace.h> |
5 | #include <net/netlink.h> | 5 | #include <net/netlink.h> |
6 | #include <linux/in6.h> | ||
6 | #include <net/ip.h> | 7 | #include <net/ip.h> |
7 | 8 | ||
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, |
9 | struct netlink_ext_ack *extack) | 10 | struct netlink_ext_ack *extack) |
10 | { | 11 | { |
11 | *ip_proto = nla_get_u8(attr); | 12 | *ip_proto = nla_get_u8(attr); |
@@ -13,11 +14,19 @@ int rtm_getroute_parse_ip_proto(struct nlattr *attr, u8 *ip_proto, | |||
13 | switch (*ip_proto) { | 14 | switch (*ip_proto) { |
14 | case IPPROTO_TCP: | 15 | case IPPROTO_TCP: |
15 | case IPPROTO_UDP: | 16 | case IPPROTO_UDP: |
17 | return 0; | ||
16 | case IPPROTO_ICMP: | 18 | 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; | ||
17 | return 0; | 26 | return 0; |
18 | default: | 27 | #endif |
19 | NL_SET_ERR_MSG(extack, "Unsupported ip proto"); | ||
20 | return -EOPNOTSUPP; | ||
21 | } | 28 | } |
29 | NL_SET_ERR_MSG(extack, "Unsupported ip proto"); | ||
30 | return -EOPNOTSUPP; | ||
22 | } | 31 | } |
23 | EXPORT_SYMBOL_GPL(rtm_getroute_parse_ip_proto); | 32 | EXPORT_SYMBOL_GPL(rtm_getroute_parse_ip_proto); |
diff --git a/net/ipv4/route.c b/net/ipv4/route.c index 5163b64f8fb3..7bb9128c8363 100644 --- a/net/ipv4/route.c +++ b/net/ipv4/route.c | |||
@@ -2803,7 +2803,7 @@ static int inet_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh, | |||
2803 | 2803 | ||
2804 | if (tb[RTA_IP_PROTO]) { | 2804 | if (tb[RTA_IP_PROTO]) { |
2805 | err = rtm_getroute_parse_ip_proto(tb[RTA_IP_PROTO], | 2805 | err = rtm_getroute_parse_ip_proto(tb[RTA_IP_PROTO], |
2806 | &ip_proto, extack); | 2806 | &ip_proto, AF_INET, extack); |
2807 | if (err) | 2807 | if (err) |
2808 | return err; | 2808 | return err; |
2809 | } | 2809 | } |
diff --git a/net/ipv6/route.c b/net/ipv6/route.c index b7a620023a52..8dad1d690b78 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c | |||
@@ -4893,7 +4893,8 @@ static int inet6_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh, | |||
4893 | 4893 | ||
4894 | if (tb[RTA_IP_PROTO]) { | 4894 | if (tb[RTA_IP_PROTO]) { |
4895 | err = rtm_getroute_parse_ip_proto(tb[RTA_IP_PROTO], | 4895 | err = rtm_getroute_parse_ip_proto(tb[RTA_IP_PROTO], |
4896 | &fl6.flowi6_proto, extack); | 4896 | &fl6.flowi6_proto, AF_INET6, |
4897 | extack); | ||
4897 | if (err) | 4898 | if (err) |
4898 | goto errout; | 4899 | goto errout; |
4899 | } | 4900 | } |