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