Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 #include <linux/netlink.h>
0003 #include <linux/rtnetlink.h>
0004 #include <linux/types.h>
0005 #include <net/net_namespace.h>
0006 #include <net/netlink.h>
0007 #include <linux/in6.h>
0008 #include <net/ip.h>
0009 
0010 int rtm_getroute_parse_ip_proto(struct nlattr *attr, u8 *ip_proto, u8 family,
0011                 struct netlink_ext_ack *extack)
0012 {
0013     *ip_proto = nla_get_u8(attr);
0014 
0015     switch (*ip_proto) {
0016     case IPPROTO_TCP:
0017     case IPPROTO_UDP:
0018         return 0;
0019     case IPPROTO_ICMP:
0020         if (family != AF_INET)
0021             break;
0022         return 0;
0023 #if IS_ENABLED(CONFIG_IPV6)
0024     case IPPROTO_ICMPV6:
0025         if (family != AF_INET6)
0026             break;
0027         return 0;
0028 #endif
0029     }
0030     NL_SET_ERR_MSG(extack, "Unsupported ip proto");
0031     return -EOPNOTSUPP;
0032 }
0033 EXPORT_SYMBOL_GPL(rtm_getroute_parse_ip_proto);