genetlink.h (5c670a010de46687ed27553602d8131ce4d7a9fb) genetlink.h (5aa51d9f889ca61201044b28677eb60236b0d746)
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef __NET_GENERIC_NETLINK_H
3#define __NET_GENERIC_NETLINK_H
4
5#include <linux/genetlink.h>
6#include <net/netlink.h>
7#include <net/net_namespace.h>
8

--- 99 unchanged lines hidden (view full) ---

108 const struct nlmsghdr * nlhdr;
109 struct genlmsghdr * genlhdr;
110 struct nlattr ** attrs;
111 possible_net_t _net;
112 void * user_ptr[2];
113 struct netlink_ext_ack *extack;
114};
115
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef __NET_GENERIC_NETLINK_H
3#define __NET_GENERIC_NETLINK_H
4
5#include <linux/genetlink.h>
6#include <net/netlink.h>
7#include <net/net_namespace.h>
8

--- 99 unchanged lines hidden (view full) ---

108 const struct nlmsghdr * nlhdr;
109 struct genlmsghdr * genlhdr;
110 struct nlattr ** attrs;
111 possible_net_t _net;
112 void * user_ptr[2];
113 struct netlink_ext_ack *extack;
114};
115
116static inline struct net *genl_info_net(struct genl_info *info)
116static inline struct net *genl_info_net(const struct genl_info *info)
117{
118 return read_pnet(&info->_net);
119}
120
121static inline void genl_info_net_set(struct genl_info *info, struct net *net)
122{
123 write_pnet(&info->_net, net);
124}

--- 140 unchanged lines hidden (view full) ---

265}
266
267static inline const struct genl_info *
268genl_info_dump(struct netlink_callback *cb)
269{
270 return &genl_dumpit_info(cb)->info;
271}
272
117{
118 return read_pnet(&info->_net);
119}
120
121static inline void genl_info_net_set(struct genl_info *info, struct net *net)
122{
123 write_pnet(&info->_net, net);
124}

--- 140 unchanged lines hidden (view full) ---

265}
266
267static inline const struct genl_info *
268genl_info_dump(struct netlink_callback *cb)
269{
270 return &genl_dumpit_info(cb)->info;
271}
272
273/**
274 * genl_info_init_ntf() - initialize genl_info for notifications
275 * @info: genl_info struct to set up
276 * @family: pointer to the genetlink family
277 * @cmd: command to be used in the notification
278 *
279 * Initialize a locally declared struct genl_info to pass to various APIs.
280 * Intended to be used when creating notifications.
281 */
282static inline void
283genl_info_init_ntf(struct genl_info *info, const struct genl_family *family,
284 u8 cmd)
285{
286 struct genlmsghdr *hdr = (void *) &info->user_ptr[0];
287
288 memset(info, 0, sizeof(*info));
289 info->family = family;
290 info->genlhdr = hdr;
291 hdr->cmd = cmd;
292}
293
294static inline bool genl_info_is_ntf(const struct genl_info *info)
295{
296 return !info->nlhdr;
297}
298
273int genl_register_family(struct genl_family *family);
274int genl_unregister_family(const struct genl_family *family);
275void genl_notify(const struct genl_family *family, struct sk_buff *skb,
276 struct genl_info *info, u32 group, gfp_t flags);
277
278void *genlmsg_put(struct sk_buff *skb, u32 portid, u32 seq,
279 const struct genl_family *family, int flags, u8 cmd);
280
299int genl_register_family(struct genl_family *family);
300int genl_unregister_family(const struct genl_family *family);
301void genl_notify(const struct genl_family *family, struct sk_buff *skb,
302 struct genl_info *info, u32 group, gfp_t flags);
303
304void *genlmsg_put(struct sk_buff *skb, u32 portid, u32 seq,
305 const struct genl_family *family, int flags, u8 cmd);
306
307static inline void *
308__genlmsg_iput(struct sk_buff *skb, const struct genl_info *info, int flags)
309{
310 return genlmsg_put(skb, info->snd_portid, info->snd_seq, info->family,
311 flags, info->genlhdr->cmd);
312}
313
281/**
314/**
315 * genlmsg_iput - start genetlink message based on genl_info
316 * @skb: skb in which message header will be placed
317 * @info: genl_info as provided to do/dump handlers
318 *
319 * Convenience wrapper which starts a genetlink message based on
320 * information in user request. @info should be either the struct passed
321 * by genetlink core to do/dump handlers (when constructing replies to
322 * such requests) or a struct initialized by genl_info_init_ntf()
323 * when constructing notifications.
324 *
325 * Returns pointer to new genetlink header.
326 */
327static inline void *
328genlmsg_iput(struct sk_buff *skb, const struct genl_info *info)
329{
330 return __genlmsg_iput(skb, info, 0);
331}
332
333/**
282 * genlmsg_nlhdr - Obtain netlink header from user specified header
283 * @user_hdr: user header as returned from genlmsg_put()
284 *
285 * Returns pointer to netlink header.
286 */
287static inline struct nlmsghdr *genlmsg_nlhdr(void *user_hdr)
288{
289 return (struct nlmsghdr *)((char *)user_hdr -

--- 245 unchanged lines hidden ---
334 * genlmsg_nlhdr - Obtain netlink header from user specified header
335 * @user_hdr: user header as returned from genlmsg_put()
336 *
337 * Returns pointer to netlink header.
338 */
339static inline struct nlmsghdr *genlmsg_nlhdr(void *user_hdr)
340{
341 return (struct nlmsghdr *)((char *)user_hdr -

--- 245 unchanged lines hidden ---