Blame view
include/linux/netlink.h
7.8 KB
b24413180 License cleanup: ... |
1 |
/* SPDX-License-Identifier: GPL-2.0 */ |
1da177e4c Linux-2.6.12-rc2 |
2 3 |
#ifndef __LINUX_NETLINK_H #define __LINUX_NETLINK_H |
1da177e4c Linux-2.6.12-rc2 |
4 5 6 |
#include <linux/capability.h> #include <linux/skbuff.h> |
abb17e6c0 netlink: use <lin... |
7 |
#include <linux/export.h> |
dbe9a4173 scm: Don't use st... |
8 |
#include <net/scm.h> |
607ca46e9 UAPI: (Scripted) ... |
9 |
#include <uapi/linux/netlink.h> |
1da177e4c Linux-2.6.12-rc2 |
10 |
|
56b49f4b8 net: Move "struct... |
11 |
struct net; |
b529ccf27 [NETLINK]: Introd... |
12 13 14 15 |
static inline struct nlmsghdr *nlmsg_hdr(const struct sk_buff *skb) { return (struct nlmsghdr *)skb->data; } |
9652e931e netlink: add mmap... |
16 |
enum netlink_skb_flags { |
2d7a85f4b netlink: Only che... |
17 |
NETLINK_SKB_DST = 0x8, /* Dst set in sendto or sendmsg */ |
9652e931e netlink: add mmap... |
18 |
}; |
d94d9fee9 net: cleanup incl... |
19 |
struct netlink_skb_parms { |
dbe9a4173 scm: Don't use st... |
20 |
struct scm_creds creds; /* Skb credentials */ |
15e473046 netlink: Rename p... |
21 |
__u32 portid; |
d629b836d [NETLINK]: Use gr... |
22 |
__u32 dst_group; |
9652e931e netlink: add mmap... |
23 |
__u32 flags; |
e32123e59 netlink: rename s... |
24 |
struct sock *sk; |
59324cf35 netlink: allow to... |
25 26 |
bool nsid_is_set; int nsid; |
1da177e4c Linux-2.6.12-rc2 |
27 28 29 30 |
}; #define NETLINK_CB(skb) (*(struct netlink_skb_parms*)&((skb)->cb)) #define NETLINK_CREDS(skb) (&NETLINK_CB((skb)).creds) |
aa9d6e0f3 linux/netlink.h: ... |
31 32 |
void netlink_table_grab(void); void netlink_table_ungrab(void); |
d136f1bd3 genetlink: fix ne... |
33 |
|
9785e10ae netlink: kill net... |
34 35 |
#define NL_CFG_F_NONROOT_RECV (1 << 0) #define NL_CFG_F_NONROOT_SEND (1 << 1) |
a31f2d17b netlink: add netl... |
36 37 38 |
/* optional Netlink kernel configuration parameters */ struct netlink_kernel_cfg { unsigned int groups; |
c9d2ea96c netlink: Rearrang... |
39 |
unsigned int flags; |
a31f2d17b netlink: add netl... |
40 41 |
void (*input)(struct sk_buff *skb); struct mutex *cb_mutex; |
023e2cfa3 netlink/genetlink... |
42 43 |
int (*bind)(struct net *net, int group); void (*unbind)(struct net *net, int group); |
da12c90e0 netlink: Add comp... |
44 |
bool (*compare)(struct net *net, struct sock *sk); |
a31f2d17b netlink: add netl... |
45 |
}; |
aa9d6e0f3 linux/netlink.h: ... |
46 |
struct sock *__netlink_kernel_create(struct net *net, int unit, |
9f00d9776 netlink: hide str... |
47 48 49 50 51 52 53 |
struct module *module, struct netlink_kernel_cfg *cfg); static inline struct sock * netlink_kernel_create(struct net *net, int unit, struct netlink_kernel_cfg *cfg) { return __netlink_kernel_create(net, unit, THIS_MODULE, cfg); } |
ba0dc5f6e netlink: allow se... |
54 55 |
/* this can be increased when necessary - don't expose to userland */ #define NETLINK_MAX_COOKIE_LEN 20 |
2d4bc9336 netlink: extended... |
56 57 58 59 60 |
/** * struct netlink_ext_ack - netlink extended ACK report struct * @_msg: message string to report - don't access directly, use * %NL_SET_ERR_MSG * @bad_attr: attribute with error |
44f3625bc netlink: export p... |
61 |
* @policy: policy for a bad attribute |
ba0dc5f6e netlink: allow se... |
62 63 |
* @cookie: cookie data to return to userspace (for success) * @cookie_len: actual cookie data length |
2d4bc9336 netlink: extended... |
64 65 66 67 |
*/ struct netlink_ext_ack { const char *_msg; const struct nlattr *bad_attr; |
44f3625bc netlink: export p... |
68 |
const struct nla_policy *policy; |
ba0dc5f6e netlink: allow se... |
69 70 |
u8 cookie[NETLINK_MAX_COOKIE_LEN]; u8 cookie_len; |
2d4bc9336 netlink: extended... |
71 72 73 74 75 76 77 78 |
}; /* Always use this macro, this allows later putting the * message into a separate section or such for things * like translation or listing all possible messages. * Currently string formatting is not supported (due * to the lack of an output buffer.) */ |
4d463c4db xdp: use common h... |
79 |
#define NL_SET_ERR_MSG(extack, msg) do { \ |
6311b7ce4 netlink: extack: ... |
80 |
static const char __msg[] = msg; \ |
4d463c4db xdp: use common h... |
81 82 83 84 |
struct netlink_ext_ack *__extack = (extack); \ \ if (__extack) \ __extack->_msg = __msg; \ |
2d4bc9336 netlink: extended... |
85 |
} while (0) |
4d463c4db xdp: use common h... |
86 87 |
#define NL_SET_ERR_MSG_MOD(extack, msg) \ NL_SET_ERR_MSG((extack), KBUILD_MODNAME ": " msg) |
45d9b378e netlink: add NULL... |
88 |
|
44f3625bc netlink: export p... |
89 90 |
#define NL_SET_BAD_ATTR_POLICY(extack, attr, pol) do { \ if ((extack)) { \ |
c3ab2b4ec net: ipv4: Add ex... |
91 |
(extack)->bad_attr = (attr); \ |
44f3625bc netlink: export p... |
92 93 |
(extack)->policy = (pol); \ } \ |
c3ab2b4ec net: ipv4: Add ex... |
94 |
} while (0) |
44f3625bc netlink: export p... |
95 96 97 98 99 100 101 102 103 104 105 |
#define NL_SET_BAD_ATTR(extack, attr) NL_SET_BAD_ATTR_POLICY(extack, attr, NULL) #define NL_SET_ERR_MSG_ATTR_POL(extack, attr, pol, msg) do { \ static const char __msg[] = msg; \ struct netlink_ext_ack *__extack = (extack); \ \ if (__extack) { \ __extack->_msg = __msg; \ __extack->bad_attr = (attr); \ __extack->policy = (pol); \ } \ |
9ae287274 net: add extack a... |
106 |
} while (0) |
44f3625bc netlink: export p... |
107 108 |
#define NL_SET_ERR_MSG_ATTR(extack, attr, msg) \ NL_SET_ERR_MSG_ATTR_POL(extack, attr, NULL, msg) |
801f87469 netlink: add nl_s... |
109 110 111 112 |
static inline void nl_set_extack_cookie_u64(struct netlink_ext_ack *extack, u64 cookie) { u64 __cookie = cookie; |
55b474c41 netlink: check fo... |
113 114 |
if (!extack) return; |
801f87469 netlink: add nl_s... |
115 116 117 |
memcpy(extack->cookie, &__cookie, sizeof(__cookie)); extack->cookie_len = sizeof(__cookie); } |
f1388ec4a netlink: add nl_s... |
118 119 120 121 |
static inline void nl_set_extack_cookie_u32(struct netlink_ext_ack *extack, u32 cookie) { u32 __cookie = cookie; |
55b474c41 netlink: check fo... |
122 123 |
if (!extack) return; |
801f87469 netlink: add nl_s... |
124 125 126 |
memcpy(extack->cookie, &__cookie, sizeof(__cookie)); extack->cookie_len = sizeof(__cookie); } |
aa9d6e0f3 linux/netlink.h: ... |
127 128 129 130 131 132 133 |
void netlink_kernel_release(struct sock *sk); int __netlink_change_ngroups(struct sock *sk, unsigned int groups); int netlink_change_ngroups(struct sock *sk, unsigned int groups); void __netlink_clear_multicast_users(struct sock *sk, unsigned int group); void netlink_ack(struct sk_buff *in_skb, struct nlmsghdr *nlh, int err, const struct netlink_ext_ack *extack); int netlink_has_listeners(struct sock *sk, unsigned int group); |
59c28058f net: netlink: add... |
134 |
bool netlink_strict_get_check(struct sk_buff *skb); |
aa9d6e0f3 linux/netlink.h: ... |
135 136 137 138 139 140 141 142 143 144 145 |
int netlink_unicast(struct sock *ssk, struct sk_buff *skb, __u32 portid, int nonblock); int netlink_broadcast(struct sock *ssk, struct sk_buff *skb, __u32 portid, __u32 group, gfp_t allocation); int netlink_broadcast_filtered(struct sock *ssk, struct sk_buff *skb, __u32 portid, __u32 group, gfp_t allocation, int (*filter)(struct sock *dsk, struct sk_buff *skb, void *data), void *filter_data); int netlink_set_err(struct sock *ssk, __u32 portid, __u32 group, int code); int netlink_register_notifier(struct notifier_block *nb); int netlink_unregister_notifier(struct notifier_block *nb); |
1da177e4c Linux-2.6.12-rc2 |
146 147 148 |
/* finegrained unicast helpers: */ struct sock *netlink_getsockbyfilp(struct file *filp); |
9457afee8 netlink: Remove n... |
149 |
int netlink_attachskb(struct sock *sk, struct sk_buff *skb, |
c3d8d1e30 [NETLINK]: Fix un... |
150 |
long *timeo, struct sock *ssk); |
1da177e4c Linux-2.6.12-rc2 |
151 |
void netlink_detachskb(struct sock *sk, struct sk_buff *skb); |
7ee015e0f [NET]: cleanup 3r... |
152 |
int netlink_sendskb(struct sock *sk, struct sk_buff *skb); |
1da177e4c Linux-2.6.12-rc2 |
153 |
|
3a36515f7 netlink: fix spla... |
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
static inline struct sk_buff * netlink_skb_clone(struct sk_buff *skb, gfp_t gfp_mask) { struct sk_buff *nskb; nskb = skb_clone(skb, gfp_mask); if (!nskb) return NULL; /* This is a large skb, set destructor callback to release head */ if (is_vmalloc_addr(skb->head)) nskb->destructor = skb->destructor; return nskb; } |
1da177e4c Linux-2.6.12-rc2 |
169 170 |
/* * skb should fit one page. This choice is good for headerless malloc. |
fc910a278 [NETLINK]: Limit ... |
171 172 173 |
* But we should limit to 8K so that userspace does not have to * use enormous buffer sizes on recvmsg() calls just to avoid * MSG_TRUNC when PAGE_SIZE is very large. |
1da177e4c Linux-2.6.12-rc2 |
174 |
*/ |
fc910a278 [NETLINK]: Limit ... |
175 176 177 178 179 |
#if PAGE_SIZE < 8192UL #define NLMSG_GOODSIZE SKB_WITH_OVERHEAD(PAGE_SIZE) #else #define NLMSG_GOODSIZE SKB_WITH_OVERHEAD(8192UL) #endif |
339bf98ff [NETLINK]: Do pre... |
180 |
#define NLMSG_DEFAULT_SIZE (NLMSG_GOODSIZE - NLMSG_HDRLEN) |
1da177e4c Linux-2.6.12-rc2 |
181 |
|
d94d9fee9 net: cleanup incl... |
182 |
struct netlink_callback { |
3a6c2b419 netlink: constify... |
183 184 185 186 187 |
struct sk_buff *skb; const struct nlmsghdr *nlh; int (*dump)(struct sk_buff * skb, struct netlink_callback *cb); int (*done)(struct netlink_callback *cb); |
7175c8830 netlink: allow to... |
188 |
void *data; |
6dc878a8c netlink: add refe... |
189 190 |
/* the module that dump function belong to */ struct module *module; |
4a19edb60 netlink: Pass ext... |
191 |
struct netlink_ext_ack *extack; |
c7ac8679b rtnetlink: Comput... |
192 |
u16 family; |
22e6c58b8 netlink: Add answ... |
193 |
u16 answer_flags; |
085c20cac bpf: inet_diag: D... |
194 |
u32 min_dump_alloc; |
670dc2833 netlink: advertis... |
195 |
unsigned int prev_seq, seq; |
085c20cac bpf: inet_diag: D... |
196 |
bool strict_check; |
362b87f5b netlink: use 48 b... |
197 198 199 200 201 202 203 204 |
union { u8 ctx[48]; /* args is deprecated. Cast a struct over ctx instead * for proper type safety. */ long args[6]; }; |
1da177e4c Linux-2.6.12-rc2 |
205 |
}; |
d94d9fee9 net: cleanup incl... |
206 |
struct netlink_notify { |
b4b510290 [NET]: Support mu... |
207 |
struct net *net; |
0392d099a netlink: Fix port... |
208 |
u32 portid; |
1da177e4c Linux-2.6.12-rc2 |
209 210 |
int protocol; }; |
a46621a3a net: Deinline __n... |
211 |
struct nlmsghdr * |
15e473046 netlink: Rename p... |
212 |
__nlmsg_put(struct sk_buff *skb, u32 portid, u32 seq, int type, int len, int flags); |
1da177e4c Linux-2.6.12-rc2 |
213 |
|
80d326fab netlink: add netl... |
214 |
struct netlink_dump_control { |
fc9e50f5a netlink: add a st... |
215 |
int (*start)(struct netlink_callback *); |
80d326fab netlink: add netl... |
216 |
int (*dump)(struct sk_buff *skb, struct netlink_callback *); |
6dc878a8c netlink: add refe... |
217 |
int (*done)(struct netlink_callback *); |
7175c8830 netlink: allow to... |
218 |
void *data; |
6dc878a8c netlink: add refe... |
219 |
struct module *module; |
ebfe3c518 rtnetlink: fix da... |
220 |
u32 min_dump_alloc; |
80d326fab netlink: add netl... |
221 |
}; |
aa9d6e0f3 linux/netlink.h: ... |
222 |
int __netlink_dump_start(struct sock *ssk, struct sk_buff *skb, |
6dc878a8c netlink: add refe... |
223 224 225 226 227 228 229 230 231 232 233 |
const struct nlmsghdr *nlh, struct netlink_dump_control *control); static inline int netlink_dump_start(struct sock *ssk, struct sk_buff *skb, const struct nlmsghdr *nlh, struct netlink_dump_control *control) { if (!control->module) control->module = THIS_MODULE; return __netlink_dump_start(ssk, skb, nlh, control); } |
1da177e4c Linux-2.6.12-rc2 |
234 |
|
bcbde0d44 net: netlink: vir... |
235 236 237 238 239 |
struct netlink_tap { struct net_device *dev; struct module *module; struct list_head list; }; |
aa9d6e0f3 linux/netlink.h: ... |
240 241 |
int netlink_add_tap(struct netlink_tap *nt); int netlink_remove_tap(struct netlink_tap *nt); |
bcbde0d44 net: netlink: vir... |
242 |
|
aa4cf9452 net: Add variants... |
243 244 245 246 247 248 |
bool __netlink_ns_capable(const struct netlink_skb_parms *nsp, struct user_namespace *ns, int cap); bool netlink_ns_capable(const struct sk_buff *skb, struct user_namespace *ns, int cap); bool netlink_capable(const struct sk_buff *skb, int cap); bool netlink_net_capable(const struct sk_buff *skb, int cap); |
1da177e4c Linux-2.6.12-rc2 |
249 |
#endif /* __LINUX_NETLINK_H */ |