summaryrefslogtreecommitdiff
path: root/src/nm-netlink-compat.h
blob: eb0926ad0700fab5f550bace8bce53501056a7a2 (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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* NetworkManager -- Network link manager
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Copyright (C) 2011 Caixa Magica Software.
 * Copyright (C) 2011 - 2012 Red Hat, Inc.
 */

#ifndef NM_NETLINK_COMPAT_H
#define NM_NETLINK_COMPAT_H

#include <errno.h>

#include <netlink/netlink.h>
#include <netlink/route/rtnl.h>
#include <netlink/route/link.h>
#include <netlink/route/route.h>
#include <netlink/route/addr.h>


#include <netlink/netlink.h>
#include <netlink/cache.h>
#include <netlink/utils.h>
#include <netlink/data.h>
#include <netlink/route/rtnl.h>
#include <netlink/route/route.h>
#include <netlink/route/link.h>
#include <netlink/route/nexthop.h>

#include <config.h>

/* libnl-1 API compatibility for libnl-2/3*/
#ifndef HAVE_LIBNL1

struct rtnl_nexthop * nm_netlink_get_nh(struct rtnl_route *);
int rtnl_route_get_oif(struct rtnl_route *);
int rtnl_route_set_oif(struct rtnl_route *, int);
int rtnl_route_set_gateway(struct rtnl_route *, struct nl_addr *);
int rtnl_route_get_dst_len(struct rtnl_route *);
struct nl_addr * rtnl_route_get_gateway(struct rtnl_route *);
#endif

/* libnl-2 API compatibility for libnl-3 */
#ifdef HAVE_LIBNL3
static inline int
__rtnl_link_alloc_cache (struct nl_sock *h, struct nl_cache **cache)
{
       return rtnl_link_alloc_cache (h, AF_UNSPEC, cache);
}
#define rtnl_link_alloc_cache __rtnl_link_alloc_cache
#endif


/* libnl-2.0 compat functions */
#ifdef HAVE_LIBNL2

/* functions with similar prototypes */
#define nlmsg_datalen nlmsg_len
#endif  /* HAVE_LIBNL2 */


/* libnl-1.0 compat functions */
#ifdef HAVE_LIBNL1

#define nl_sock nl_handle

/* libnl-1.0 functions with similar prototypes */
#define nl_socket_alloc nl_handle_alloc
#define nl_socket_alloc_cb nl_handle_alloc_cb
#define nl_socket_free nl_handle_destroy
#define nl_socket_set_passcred nl_set_passcred
#define nl_socket_disable_seq_check nl_disable_sequence_check
#define rtnl_route_set_priority rtnl_route_set_prio
#define nlmsg_datalen nlmsg_len

/* auxiliary functions */
int nl_compat_error (int);

/* libnl-1.0 functions with modified prototypes in libnl-2/3*/
static inline const char * 
__nl_geterror (int err)
{
        /* err is set, can be parsed */
        return nl_geterror ();
}
#define nl_geterror __nl_geterror

static inline int
__rtnl_addr_alloc_cache (struct nl_sock *h, struct nl_cache **cache)
{
	g_return_val_if_fail (cache != NULL, -EINVAL);

	*cache = rtnl_addr_alloc_cache (h);
	return *cache ? 0 : -ENOMEM;
}
#define rtnl_addr_alloc_cache __rtnl_addr_alloc_cache

static inline int
__rtnl_route_alloc_cache (struct nl_sock *h, int family, int flags, struct nl_cache **cache)
{
	g_return_val_if_fail (cache != NULL, -EINVAL);

	*cache = rtnl_route_alloc_cache (h);
	return *cache ? 0 : -ENOMEM;
}
#define rtnl_route_alloc_cache __rtnl_route_alloc_cache

static inline int
__rtnl_link_alloc_cache (struct nl_sock *h, struct nl_cache **cache)
{
	g_return_val_if_fail (cache != NULL, -EINVAL);

	*cache = rtnl_link_alloc_cache (h);
	return *cache ? 0 : -ENOMEM;
}
#define rtnl_link_alloc_cache __rtnl_link_alloc_cache

static inline int
__rtnl_route_get_metric (struct rtnl_route *route, int metric, unsigned int *value)
{
	g_return_val_if_fail (value != NULL, -EINVAL);

	*value = rtnl_route_get_metric (route, metric);
	return 0;
}
#define rtnl_route_get_metric __rtnl_route_get_metric

static inline int
__rtnl_addr_add (struct nl_sock *h, struct rtnl_addr *addr, int flags)
{
	return nl_compat_error (rtnl_addr_add (h, addr, flags));
}
#define rtnl_addr_add __rtnl_addr_add

static inline int
__rtnl_route_add (struct nl_sock *sk, struct rtnl_route *route, int flags)
{
	return nl_compat_error (rtnl_route_add (sk, route, flags));
}
#define rtnl_route_add __rtnl_route_add

static inline int
rtnl_route_delete (struct nl_sock *h, struct rtnl_route *route, int flags)
{
	return nl_compat_error (rtnl_route_del (h, route, flags));
}
#define rtnl_route_del rtnl_route_delete

static inline int
__rtnl_link_change (struct nl_sock *h, struct rtnl_link *old, struct rtnl_link *tmpl, int flags)
{
	return nl_compat_error (rtnl_link_change (h, old, tmpl,flags));
}
#define rtnl_link_change __rtnl_link_change

static inline int
__nl_cache_include (struct nl_cache *cache, struct nl_object *obj, change_func_t cb, void *data)
{
	return nl_cache_include (cache, obj, cb);
}
#define nl_cache_include __nl_cache_include

#define NLE_SUCCESS             0
#define NLE_FAILURE             1
#define NLE_INTR                2
#define NLE_BAD_SOCK            3
#define NLE_AGAIN               4
#define NLE_NOMEM               5
#define NLE_EXIST               6
#define NLE_INVAL               7
#define NLE_RANGE               8
#define NLE_MSGSIZE             9
#define NLE_OPNOTSUPP           10
#define NLE_AF_NOSUPPORT        11
#define NLE_OBJ_NOTFOUND        12
#define NLE_NOATTR              13
#define NLE_MISSING_ATTR        14
#define NLE_AF_MISMATCH         15
#define NLE_SEQ_MISMATCH        16
#define NLE_MSG_OVERFLOW        17
#define NLE_MSG_TRUNC           18
#define NLE_NOADDR              19
#define NLE_SRCRT_NOSUPPORT     20
#define NLE_MSG_TOOSHORT        21
#define NLE_MSGTYPE_NOSUPPORT   22
#define NLE_OBJ_MISMATCH        23
#define NLE_NOCACHE             24
#define NLE_BUSY                25
#define NLE_PROTO_MISMATCH      26
#define NLE_NOACCESS            27
#define NLE_PERM                28
#define NLE_PKTLOC_FILE         29

#endif  /* HAVE_LIBNL1 */

/* Stuff that only libnl3 has */
#if defined(HAVE_LIBNL1) || defined(HAVE_LIBNL2)

static inline int
rtnl_link_bond_add (struct nl_sock *h, const char *name, void *data)
{
	/* Bonding only in libnl3 */
	return -NLE_OPNOTSUPP;
}

static inline int
rtnl_link_get_kernel (struct nl_sock *h, int f, const char *name, struct rtnl_link **out_link)
{
	/* Bonding only in libnl3 */
	return -NLE_OPNOTSUPP;
}

static inline char *
rtnl_link_get_type (struct rtnl_link *rtnl_link)
{
	/* Bonding only in libnl3 */
	return NULL;
}

static inline int
rtnl_link_bond_enslave_ifindex (struct nl_sock *h, int master_ifidx, int slave_ifidx)
{
	/* Bonding only in libnl3 */
	return -NLE_OPNOTSUPP;
}

static inline int
rtnl_link_bond_release_ifindex (struct nl_sock *h, int slave_ifidx)
{
	/* Bonding only in libnl3 */
	return -NLE_OPNOTSUPP;
}

static inline int
rtnl_link_vlan_set_id (struct rtnl_link *l, int id)
{
	/* VLAN only in libnl3 */
	return -NLE_OPNOTSUPP;
}

int rtnl_link_vlan_get_id (struct rtnl_link *l);
int rtnl_link_vlan_set_flags (struct rtnl_link *l, unsigned int flags);
int rtnl_link_vlan_set_ingress_map (struct rtnl_link *l, int from, uint32_t to);
int rtnl_link_vlan_set_egress_map (struct rtnl_link *l, int from, uint32_t to);

static inline int
rtnl_link_set_type (struct rtnl_link *l, const char *type)
{
	/* Operation only in libnl3 */
	return -NLE_OPNOTSUPP;
}

static inline int
rtnl_link_add (struct nl_sock *sk, struct rtnl_link *l, int flags)
{
	/* Operation only in libnl3 */
	return -NLE_OPNOTSUPP;
}

static inline int
rtnl_link_delete(struct nl_sock *sk, const struct rtnl_link *l)
{
	/* Operation only in libnl3 */
	return -NLE_OPNOTSUPP;
}
#endif  /* HAVE_LIBNL1 || HAVE_LIBNL2 */

#endif /* NM_NETLINK_COMPAT_H */