0001
0002 #ifndef _AF_NETLINK_H
0003 #define _AF_NETLINK_H
0004
0005 #include <linux/rhashtable.h>
0006 #include <linux/atomic.h>
0007 #include <linux/workqueue.h>
0008 #include <net/sock.h>
0009
0010
0011 #define NETLINK_F_KERNEL_SOCKET 0x1
0012 #define NETLINK_F_RECV_PKTINFO 0x2
0013 #define NETLINK_F_BROADCAST_SEND_ERROR 0x4
0014 #define NETLINK_F_RECV_NO_ENOBUFS 0x8
0015 #define NETLINK_F_LISTEN_ALL_NSID 0x10
0016 #define NETLINK_F_CAP_ACK 0x20
0017 #define NETLINK_F_EXT_ACK 0x40
0018 #define NETLINK_F_STRICT_CHK 0x80
0019
0020 #define NLGRPSZ(x) (ALIGN(x, sizeof(unsigned long) * 8) / 8)
0021 #define NLGRPLONGS(x) (NLGRPSZ(x)/sizeof(unsigned long))
0022
0023 struct netlink_sock {
0024
0025 struct sock sk;
0026 u32 portid;
0027 u32 dst_portid;
0028 u32 dst_group;
0029 u32 flags;
0030 u32 subscriptions;
0031 u32 ngroups;
0032 unsigned long *groups;
0033 unsigned long state;
0034 size_t max_recvmsg_len;
0035 wait_queue_head_t wait;
0036 bool bound;
0037 bool cb_running;
0038 int dump_done_errno;
0039 struct netlink_callback cb;
0040 struct mutex *cb_mutex;
0041 struct mutex cb_def_mutex;
0042 void (*netlink_rcv)(struct sk_buff *skb);
0043 int (*netlink_bind)(struct net *net, int group);
0044 void (*netlink_unbind)(struct net *net, int group);
0045 struct module *module;
0046
0047 struct rhash_head node;
0048 struct rcu_head rcu;
0049 struct work_struct work;
0050 };
0051
0052 static inline struct netlink_sock *nlk_sk(struct sock *sk)
0053 {
0054 return container_of(sk, struct netlink_sock, sk);
0055 }
0056
0057 struct netlink_table {
0058 struct rhashtable hash;
0059 struct hlist_head mc_list;
0060 struct listeners __rcu *listeners;
0061 unsigned int flags;
0062 unsigned int groups;
0063 struct mutex *cb_mutex;
0064 struct module *module;
0065 int (*bind)(struct net *net, int group);
0066 void (*unbind)(struct net *net, int group);
0067 bool (*compare)(struct net *net, struct sock *sock);
0068 int registered;
0069 };
0070
0071 extern struct netlink_table *nl_table;
0072 extern rwlock_t nl_table_lock;
0073
0074 #endif