]> git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/rtnl.h
Merge pull request #3956 from brauner/2021-08-27.list
[mirror_lxc.git] / src / lxc / rtnl.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2
3 #ifndef __LXC_RTNL_H
4 #define __LXC_RTNL_H
5
6 #include <compiler.h>
7
8 /*
9 * Use this as a good size to allocate route netlink messages
10 */
11 #define RTNLMSG_GOOD_SIZE NLMSG_GOOD_SIZE
12 #define RTNLMSG_DATA(glh) ((void *)(NLMSG_DATA(glh) + RTNL_HDRLEN))
13
14 /*
15 * struct genl_handler : the structure which store the netlink handler
16 * and the family number
17 *
18 * @nlh: the netlink socket handler
19 */
20 struct rtnl_handler {
21 struct nl_handler nlh;
22 };
23
24 /*
25 * struct rtnlmsg : the struct containing the route netlink message
26 * format
27 *
28 * @nlmsghdr: a netlink message header
29 * @rtnlmsghdr: a route netlink message header pointer
30 *
31 */
32 struct rtnlmsg {
33 struct nlmsghdr nlmsghdr;
34 };
35
36 /*
37 * rtnetlink_open : open a route netlink socket
38 *
39 * @handler: a struct rtnl_handler pointer
40 *
41 * Returns 0 on success, < 0 otherwise
42 */
43 __hidden extern int rtnetlink_open(struct rtnl_handler *handler);
44
45 /*
46 * genetlink_close : close a route netlink socket
47 *
48 * @handler: the handler of the socket to be closed
49 */
50 __hidden extern void rtnetlink_close(struct rtnl_handler *handler);
51
52 /*
53 * rtnetlink_rcv : receive a route netlink socket, it is up
54 * to the caller to manage the allocation of the route netlink message
55 *
56 * @handler: the handler of the route netlink socket
57 * @rtnlmsg: the pointer to a route netlink message pre-allocated
58 *
59 * Returns 0 on success, < 0 otherwise
60 */
61 __hidden extern int rtnetlink_rcv(struct rtnl_handler *handler, struct rtnlmsg *rtnlmsg);
62
63 /*
64 * rtnetlink_send : send a route netlink socket, it is up
65 * to the caller to manage the allocation of the route netlink message
66 *
67 * @handler: the handler of the route netlink socket
68 * @rtnlmsg: the pointer to a netlink message pre-allocated
69 *
70 * Returns 0 on success, < 0 otherwise
71 */
72 __hidden extern int rtnetlink_send(struct rtnl_handler *handler, struct rtnlmsg *rtnlmsg);
73
74 __hidden struct genlmsg *genlmsg_alloc(size_t size);
75
76 __hidden extern void rtnlmsg_free(struct rtnlmsg *rtnlmsg);
77
78 /*
79 * rtnetlink_transaction : send and receive a route netlink message in one shot
80 *
81 * @handler: the handler of the route netlink socket
82 * @request: a route netlink message containing the request to be sent
83 * @answer: a pre-allocated route netlink message to receive the response
84 *
85 * Returns 0 on success, < 0 otherwise
86 */
87 __hidden extern int rtnetlink_transaction(struct rtnl_handler *handler, struct rtnlmsg *request,
88 struct rtnlmsg *answer);
89
90 __hidden struct rtnlmsg *rtnlmsg_alloc(size_t size);
91
92 #endif /* __LXC_RTNL_H */