xref: /openbmc/linux/net/ipv4/netlink.c (revision e657c18a)
1 #include <linux/netlink.h>
2 #include <linux/rtnetlink.h>
3 #include <linux/types.h>
4 #include <net/net_namespace.h>
5 #include <net/netlink.h>
6 #include <linux/in6.h>
7 #include <net/ip.h>
8 
9 int rtm_getroute_parse_ip_proto(struct nlattr *attr, u8 *ip_proto, u8 family,
10 				struct netlink_ext_ack *extack)
11 {
12 	*ip_proto = nla_get_u8(attr);
13 
14 	switch (*ip_proto) {
15 	case IPPROTO_TCP:
16 	case IPPROTO_UDP:
17 		return 0;
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;
26 		return 0;
27 #endif
28 	}
29 	NL_SET_ERR_MSG(extack, "Unsupported ip proto");
30 	return -EOPNOTSUPP;
31 }
32 EXPORT_SYMBOL_GPL(rtm_getroute_parse_ip_proto);
33