]>
git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - include/linux/netlink.h
1 #ifndef __LINUX_NETLINK_H
2 #define __LINUX_NETLINK_H
5 #include <linux/capability.h>
6 #include <linux/skbuff.h>
7 #include <linux/export.h>
9 #include <uapi/linux/netlink.h>
13 static inline struct nlmsghdr
*nlmsg_hdr(const struct sk_buff
*skb
)
15 return (struct nlmsghdr
*)skb
->data
;
18 struct netlink_skb_parms
{
19 struct scm_creds creds
; /* Skb credentials */
25 #define NETLINK_CB(skb) (*(struct netlink_skb_parms*)&((skb)->cb))
26 #define NETLINK_CREDS(skb) (&NETLINK_CB((skb)).creds)
29 extern void netlink_table_grab(void);
30 extern void netlink_table_ungrab(void);
32 #define NL_CFG_F_NONROOT_RECV (1 << 0)
33 #define NL_CFG_F_NONROOT_SEND (1 << 1)
35 /* optional Netlink kernel configuration parameters */
36 struct netlink_kernel_cfg
{
39 void (*input
)(struct sk_buff
*skb
);
40 struct mutex
*cb_mutex
;
41 void (*bind
)(int group
);
44 extern struct sock
*__netlink_kernel_create(struct net
*net
, int unit
,
45 struct module
*module
,
46 struct netlink_kernel_cfg
*cfg
);
47 static inline struct sock
*
48 netlink_kernel_create(struct net
*net
, int unit
, struct netlink_kernel_cfg
*cfg
)
50 return __netlink_kernel_create(net
, unit
, THIS_MODULE
, cfg
);
53 extern void netlink_kernel_release(struct sock
*sk
);
54 extern int __netlink_change_ngroups(struct sock
*sk
, unsigned int groups
);
55 extern int netlink_change_ngroups(struct sock
*sk
, unsigned int groups
);
56 extern void __netlink_clear_multicast_users(struct sock
*sk
, unsigned int group
);
57 extern void netlink_clear_multicast_users(struct sock
*sk
, unsigned int group
);
58 extern void netlink_ack(struct sk_buff
*in_skb
, struct nlmsghdr
*nlh
, int err
);
59 extern int netlink_has_listeners(struct sock
*sk
, unsigned int group
);
60 extern int netlink_unicast(struct sock
*ssk
, struct sk_buff
*skb
, __u32 portid
, int nonblock
);
61 extern int netlink_broadcast(struct sock
*ssk
, struct sk_buff
*skb
, __u32 portid
,
62 __u32 group
, gfp_t allocation
);
63 extern int netlink_broadcast_filtered(struct sock
*ssk
, struct sk_buff
*skb
,
64 __u32 portid
, __u32 group
, gfp_t allocation
,
65 int (*filter
)(struct sock
*dsk
, struct sk_buff
*skb
, void *data
),
67 extern int netlink_set_err(struct sock
*ssk
, __u32 portid
, __u32 group
, int code
);
68 extern int netlink_register_notifier(struct notifier_block
*nb
);
69 extern int netlink_unregister_notifier(struct notifier_block
*nb
);
71 /* finegrained unicast helpers: */
72 struct sock
*netlink_getsockbyfilp(struct file
*filp
);
73 int netlink_attachskb(struct sock
*sk
, struct sk_buff
*skb
,
74 long *timeo
, struct sock
*ssk
);
75 void netlink_detachskb(struct sock
*sk
, struct sk_buff
*skb
);
76 int netlink_sendskb(struct sock
*sk
, struct sk_buff
*skb
);
79 * skb should fit one page. This choice is good for headerless malloc.
80 * But we should limit to 8K so that userspace does not have to
81 * use enormous buffer sizes on recvmsg() calls just to avoid
82 * MSG_TRUNC when PAGE_SIZE is very large.
84 #if PAGE_SIZE < 8192UL
85 #define NLMSG_GOODSIZE SKB_WITH_OVERHEAD(PAGE_SIZE)
87 #define NLMSG_GOODSIZE SKB_WITH_OVERHEAD(8192UL)
90 #define NLMSG_DEFAULT_SIZE (NLMSG_GOODSIZE - NLMSG_HDRLEN)
93 struct netlink_callback
{
95 const struct nlmsghdr
*nlh
;
96 int (*dump
)(struct sk_buff
* skb
,
97 struct netlink_callback
*cb
);
98 int (*done
)(struct netlink_callback
*cb
);
100 /* the module that dump function belong to */
101 struct module
*module
;
104 unsigned int prev_seq
, seq
;
108 struct netlink_notify
{
115 __nlmsg_put(struct sk_buff
*skb
, u32 portid
, u32 seq
, int type
, int len
, int flags
);
117 struct netlink_dump_control
{
118 int (*dump
)(struct sk_buff
*skb
, struct netlink_callback
*);
119 int (*done
)(struct netlink_callback
*);
121 struct module
*module
;
125 extern int __netlink_dump_start(struct sock
*ssk
, struct sk_buff
*skb
,
126 const struct nlmsghdr
*nlh
,
127 struct netlink_dump_control
*control
);
128 static inline int netlink_dump_start(struct sock
*ssk
, struct sk_buff
*skb
,
129 const struct nlmsghdr
*nlh
,
130 struct netlink_dump_control
*control
)
132 if (!control
->module
)
133 control
->module
= THIS_MODULE
;
135 return __netlink_dump_start(ssk
, skb
, nlh
, control
);
138 #endif /* __LINUX_NETLINK_H */