aboutsummaryrefslogtreecommitdiff
blob: 63aca0ad891846f7d4a4bf6b6b7c0b5210246b06 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
 * lxc: linux Container library
 *
 * (C) Copyright IBM Corp. 2007, 2008
 *
 * Authors:
 * Daniel Lezcano <dlezcano at fr.ibm.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */
#ifndef __genl_h
#define __genl_h

/*
 * Use this as a good size to allocate route netlink messages
 */
#define RTNLMSG_GOOD_SIZE NLMSG_GOOD_SIZE
#define RTNLMSG_DATA(glh) ((void *)(NLMSG_DATA(glh) + RTNL_HDRLEN))

/*
 * struct genl_handler : the structure which store the netlink handler 
 *  and the family number
 *
 * @nlh: the netlink socket handler
 */
struct rtnl_handler
{
	struct nl_handler nlh;
};

/*
 * struct rtnlmsg : the struct containing the route netlink message
 *  format
 *
 * @nlmsghdr: a netlink message header
 * @rtnlmsghdr: a route netlink message header pointer
 *
 */
struct rtnlmsg {
	struct nlmsghdr nlmsghdr;
};

/*
 * rtnetlink_open : open a route netlink socket
 *
 * @handler: a struct rtnl_handler pointer
 *
 * Returns 0 on success, < 0 otherwise
 */
int rtnetlink_open(struct rtnl_handler *handler);

/*
 * genetlink_close : close a route netlink socket
 *
 * @handler: the handler of the socket to be closed
 *
 * Returns 0 on success, < 0 otherwise
 */
int rtnetlink_close(struct rtnl_handler *handler);

/*
 * rtnetlink_rcv : receive a route netlink socket, it is up
 *  to the caller to manage the allocation of the route netlink message
 *
 * @handler: the handler of the route netlink socket
 * @rtnlmsg: the pointer to a route netlink message pre-allocated
 *
 * Returns 0 on success, < 0 otherwise
 */
int rtnetlink_rcv(struct rtnl_handler *handler, struct rtnlmsg *rtnlmsg);

/*
 * rtnetlink_send : send a route netlink socket, it is up
 *  to the caller to manage the allocation of the route netlink message
 *
 * @handler: the handler of the route netlink socket
 * @rtnlmsg: the pointer to a netlink message pre-allocated
 *
 * Returns 0 on success, < 0 otherwise
 */
int rtnetlink_send(struct rtnl_handler *handler, struct rtnlmsg *rtnlmsg);

struct genlmsg *genlmsg_alloc(size_t size);

void rtnlmsg_free(struct rtnlmsg *rtnlmsg);

/*
 * rtnetlink_transaction : send and receive a route netlink message in one shot
 *
 * @handler: the handler of the route netlink socket
 * @request: a route netlink message containing the request to be sent
 * @answer: a pre-allocated route netlink message to receive the response
 *
 * Returns 0 on success, < 0 otherwise
 */
int rtnetlink_transaction(struct rtnl_handler *handler, 
			  struct rtnlmsg *request, struct rtnlmsg *answer);
#endif