]> git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/rtnl.h
licensing: Add missing headers and FSF address
[mirror_lxc.git] / src / lxc / rtnl.h
1 /*
2 * lxc: linux Container library
3 *
4 * (C) Copyright IBM Corp. 2007, 2008
5 *
6 * Authors:
7 * Daniel Lezcano <daniel.lezcano at free.fr>
8 *
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.
13 *
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.
18 *
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23 #ifndef __genl_h
24 #define __genl_h
25
26 /*
27 * Use this as a good size to allocate route netlink messages
28 */
29 #define RTNLMSG_GOOD_SIZE NLMSG_GOOD_SIZE
30 #define RTNLMSG_DATA(glh) ((void *)(NLMSG_DATA(glh) + RTNL_HDRLEN))
31
32 /*
33 * struct genl_handler : the structure which store the netlink handler
34 * and the family number
35 *
36 * @nlh: the netlink socket handler
37 */
38 struct rtnl_handler
39 {
40 struct nl_handler nlh;
41 };
42
43 /*
44 * struct rtnlmsg : the struct containing the route netlink message
45 * format
46 *
47 * @nlmsghdr: a netlink message header
48 * @rtnlmsghdr: a route netlink message header pointer
49 *
50 */
51 struct rtnlmsg {
52 struct nlmsghdr nlmsghdr;
53 };
54
55 /*
56 * rtnetlink_open : open a route netlink socket
57 *
58 * @handler: a struct rtnl_handler pointer
59 *
60 * Returns 0 on success, < 0 otherwise
61 */
62 int rtnetlink_open(struct rtnl_handler *handler);
63
64 /*
65 * genetlink_close : close a route netlink socket
66 *
67 * @handler: the handler of the socket to be closed
68 *
69 * Returns 0 on success, < 0 otherwise
70 */
71 int rtnetlink_close(struct rtnl_handler *handler);
72
73 /*
74 * rtnetlink_rcv : receive a route netlink socket, it is up
75 * to the caller to manage the allocation of the route netlink message
76 *
77 * @handler: the handler of the route netlink socket
78 * @rtnlmsg: the pointer to a route netlink message pre-allocated
79 *
80 * Returns 0 on success, < 0 otherwise
81 */
82 int rtnetlink_rcv(struct rtnl_handler *handler, struct rtnlmsg *rtnlmsg);
83
84 /*
85 * rtnetlink_send : send a route netlink socket, it is up
86 * to the caller to manage the allocation of the route netlink message
87 *
88 * @handler: the handler of the route netlink socket
89 * @rtnlmsg: the pointer to a netlink message pre-allocated
90 *
91 * Returns 0 on success, < 0 otherwise
92 */
93 int rtnetlink_send(struct rtnl_handler *handler, struct rtnlmsg *rtnlmsg);
94
95 struct genlmsg *genlmsg_alloc(size_t size);
96
97 void rtnlmsg_free(struct rtnlmsg *rtnlmsg);
98
99 /*
100 * rtnetlink_transaction : send and receive a route netlink message in one shot
101 *
102 * @handler: the handler of the route netlink socket
103 * @request: a route netlink message containing the request to be sent
104 * @answer: a pre-allocated route netlink message to receive the response
105 *
106 * Returns 0 on success, < 0 otherwise
107 */
108 int rtnetlink_transaction(struct rtnl_handler *handler,
109 struct rtnlmsg *request, struct rtnlmsg *answer);
110 #endif