sock_diag.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #ifndef __SOCK_DIAG_H__
  2. #define __SOCK_DIAG_H__
  3. #include <linux/netlink.h>
  4. #include <linux/user_namespace.h>
  5. #include <net/net_namespace.h>
  6. #include <net/sock.h>
  7. #include <uapi/linux/sock_diag.h>
  8. struct sk_buff;
  9. struct nlmsghdr;
  10. struct sock;
  11. struct sock_diag_handler {
  12. __u8 family;
  13. int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
  14. int (*get_info)(struct sk_buff *skb, struct sock *sk);
  15. int (*destroy)(struct sk_buff *skb, struct nlmsghdr *nlh);
  16. };
  17. int sock_diag_register(const struct sock_diag_handler *h);
  18. void sock_diag_unregister(const struct sock_diag_handler *h);
  19. void sock_diag_register_inet_compat(int (*fn)(struct sk_buff *skb, struct nlmsghdr *nlh));
  20. void sock_diag_unregister_inet_compat(int (*fn)(struct sk_buff *skb, struct nlmsghdr *nlh));
  21. int sock_diag_check_cookie(struct sock *sk, const __u32 *cookie);
  22. void sock_diag_save_cookie(struct sock *sk, __u32 *cookie);
  23. int sock_diag_put_meminfo(struct sock *sk, struct sk_buff *skb, int attr);
  24. int sock_diag_put_filterinfo(bool may_report_filterinfo, struct sock *sk,
  25. struct sk_buff *skb, int attrtype);
  26. static inline
  27. enum sknetlink_groups sock_diag_destroy_group(const struct sock *sk)
  28. {
  29. switch (sk->sk_family) {
  30. case AF_INET:
  31. if (sk->sk_type == SOCK_RAW)
  32. return SKNLGRP_NONE;
  33. switch (sk->sk_protocol) {
  34. case IPPROTO_TCP:
  35. return SKNLGRP_INET_TCP_DESTROY;
  36. case IPPROTO_UDP:
  37. return SKNLGRP_INET_UDP_DESTROY;
  38. default:
  39. return SKNLGRP_NONE;
  40. }
  41. case AF_INET6:
  42. if (sk->sk_type == SOCK_RAW)
  43. return SKNLGRP_NONE;
  44. switch (sk->sk_protocol) {
  45. case IPPROTO_TCP:
  46. return SKNLGRP_INET6_TCP_DESTROY;
  47. case IPPROTO_UDP:
  48. return SKNLGRP_INET6_UDP_DESTROY;
  49. default:
  50. return SKNLGRP_NONE;
  51. }
  52. default:
  53. return SKNLGRP_NONE;
  54. }
  55. }
  56. static inline
  57. bool sock_diag_has_destroy_listeners(const struct sock *sk)
  58. {
  59. const struct net *n = sock_net(sk);
  60. const enum sknetlink_groups group = sock_diag_destroy_group(sk);
  61. return group != SKNLGRP_NONE && n->diag_nlsk &&
  62. netlink_has_listeners(n->diag_nlsk, group);
  63. }
  64. void sock_diag_broadcast_destroy(struct sock *sk);
  65. int sock_diag_destroy(struct sock *sk, int err);
  66. #endif