netlink.c 696 B

123456789101112131415161718192021222324252627282930313233
  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. int rtm_getroute_parse_ip_proto(struct nlattr *attr, u8 *ip_proto, u8 family,
  9. struct netlink_ext_ack *extack)
  10. {
  11. *ip_proto = nla_get_u8(attr);
  12. switch (*ip_proto) {
  13. case IPPROTO_TCP:
  14. case IPPROTO_UDP:
  15. return 0;
  16. case IPPROTO_ICMP:
  17. if (family != AF_INET)
  18. break;
  19. return 0;
  20. #if IS_ENABLED(CONFIG_IPV6)
  21. case IPPROTO_ICMPV6:
  22. if (family != AF_INET6)
  23. break;
  24. return 0;
  25. #endif
  26. }
  27. NL_SET_ERR_MSG(extack, "Unsupported ip proto");
  28. return -EOPNOTSUPP;
  29. }
  30. EXPORT_SYMBOL_GPL(rtm_getroute_parse_ip_proto);