2
* lxc: linux Container library
4
* (C) Copyright IBM Corp. 2007, 2008
7
* Daniel Lezcano <dlezcano at fr.ibm.com>
9
* This library is free software; you can redistribute it and/or
10
* modify it under the terms of the GNU Lesser General Public
11
* License as published by the Free Software Foundation; either
12
* version 2.1 of the License, or (at your option) any later version.
14
* This library is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
* Lesser General Public License for more details.
19
* You should have received a copy of the GNU Lesser General Public
20
* License along with this library; if not, write to the Free Software
21
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27
* Use this as a good size to allocate generic netlink messages
29
#define GENLMSG_GOOD_SIZE NLMSG_GOOD_SIZE
30
#define GENLMSG_DATA(glh) ((void *)(NLMSG_DATA(glh) + GENL_HDRLEN))
33
* struct genl_handler : the structure which store the netlink handler
34
* and the family number resulting of the auto-generating id family
35
* for the generic netlink protocol
37
* @nlh: the netlink socket handler
38
* @family: the generic netlink family assigned number
42
struct nl_handler nlh;
47
* struct genlmsg : the struct containing the generic netlink message
50
* @nlmsghdr: a netlink message header
51
* @genlmsghdr: a generic netlink message header pointer
54
/* __attribute__ ((aligned(4))); */
56
struct nlmsghdr nlmsghdr;
57
struct genlmsghdr genlmsghdr;
60
static inline int genetlink_len(const struct genlmsg *genlmsg)
62
return ((genlmsg->nlmsghdr.nlmsg_len) - GENL_HDRLEN - NLMSG_HDRLEN);
66
* genetlink_open : resolve family number id and open a generic netlink socket
68
* @handler: a struct genl_handler pointer
69
* @family: the family name of the generic netlink protocol
71
* Returns 0 on success, < 0 otherwise
73
int genetlink_open(struct genl_handler *handler, const char *family);
76
* genetlink_close : close a generic netlink socket
78
* @handler: the handler of the socket to be closed
80
* Returns 0 on success, < 0 otherwise
82
int genetlink_close(struct genl_handler *handler);
85
* genetlink_rcv : receive a generic netlink socket, it is up
86
* to the caller to manage the allocation of the generic netlink message
88
* @handler: the handler of the generic netlink socket
89
* @genlmsg: the pointer to a generic netlink message pre-allocated
91
* Returns 0 on success, < 0 otherwise
93
int genetlink_rcv(struct genl_handler *handler, struct genlmsg *genlmsg);
96
* genetlink_send : send a generic netlink socket, it is up
97
* to the caller to manage the allocation of the generic netlink message
99
* @handler: the handler of the generic netlink socket
100
* @genlmsg: the pointer to a generic netlink message pre-allocated
102
* Returns 0 on success, < 0 otherwise
104
int genetlink_send(struct genl_handler *handler, struct genlmsg *genlmsg);
106
struct genlmsg *genlmsg_alloc(size_t size);
108
void genlmsg_free(struct genlmsg *genlmsg);
111
* genetlink_transaction : send and receive a generic netlink message in one shot
113
* @handler: the handler of the generic netlink socket
114
* @request: a generic netlink message containing the request to be sent
115
* @answer: a pre-allocated generic netlink message to receive the response
117
* Returns 0 on success, < 0 otherwise
119
int genetlink_transaction(struct genl_handler *handler,
120
struct genlmsg *request, struct genlmsg *answer);