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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
|
%module capi
%{
#include <netlink/netlink.h>
#include <netlink/types.h>
#include <netlink/socket.h>
#include <netlink/msg.h>
#include <netlink/object.h>
#include <netlink/cache.h>
%}
%include <stdint.i>
%include <cstring.i>
%inline %{
struct nl_dump_params *alloc_dump_params(void)
{
struct nl_dump_params *dp;
if (!(dp = calloc(1, sizeof(*dp))))
return NULL;
dp->dp_fd = stdout;
return dp;
}
void free_dump_params(struct nl_dump_params *dp)
{
free(dp);
}
%};
/* <netlink/types.h> */
enum nl_dump_type {
NL_DUMP_LINE, /**< Dump object briefly on one line */
NL_DUMP_DETAILS, /**< Dump all attributes but no statistics */
NL_DUMP_STATS, /**< Dump all attributes including statistics */
__NL_DUMP_MAX,
};
struct nl_dump_params
{
/**
* Specifies the type of dump that is requested.
*/
enum nl_dump_type dp_type;
/**
* Specifies the number of whitespaces to be put in front
* of every new line (indentation).
*/
int dp_prefix;
/**
* Causes the cache index to be printed for each element.
*/
int dp_print_index;
/**
* Causes each element to be prefixed with the message type.
*/
int dp_dump_msgtype;
/**
* A callback invoked for output
*
* Passed arguments are:
* - dumping parameters
* - string to append to the output
*/
void (*dp_cb)(struct nl_dump_params *, char *);
/**
* A callback invoked for every new line, can be used to
* customize the indentation.
*
* Passed arguments are:
* - dumping parameters
* - line number starting from 0
*/
void (*dp_nl_cb)(struct nl_dump_params *, int);
/**
* User data pointer, can be used to pass data to callbacks.
*/
void *dp_data;
/**
* File descriptor the dumping output should go to
*/
FILE * dp_fd;
/**
* Alternatively the output may be redirected into a buffer
*/
char * dp_buf;
/**
* Length of the buffer dp_buf
*/
size_t dp_buflen;
/**
* PRIVATE
* Set if a dump was performed prior to the actual dump handler.
*/
int dp_pre_dump;
/**
* PRIVATE
* Owned by the current caller
*/
int dp_ivar;
unsigned int dp_line;
};
/* <netlink/errno.h> */
extern const char *nl_geterror(int);
/* <netlink/utils.h> */
extern double nl_cancel_down_bytes(unsigned long long, char **);
extern double nl_cancel_down_bits(unsigned long long, char **);
%cstring_output_maxsize(char *buf, size_t len)
extern int nl_rate2str(unsigned long long rate, int type, char *buf, size_t len);
extern double nl_cancel_down_us(uint32_t, char **);
extern long nl_size2int(const char *);
%cstring_output_maxsize(char *buf, const size_t len)
extern char *nl_size2str(const size_t, char *buf, const size_t len);
extern long nl_prob2int(const char *);
extern int nl_get_user_hz(void);
extern uint32_t nl_us2ticks(uint32_t);
extern uint32_t nl_ticks2us(uint32_t);
extern int nl_str2msec(const char *, uint64_t *);
%cstring_output_maxsize(char *buf, size_t len)
extern char *nl_msec2str(uint64_t, char *buf, size_t len);
%cstring_output_maxsize(char *buf, size_t len)
extern char *nl_llproto2str(int, char *buf, size_t len);
extern int nl_str2llproto(const char *);
%cstring_output_maxsize(char *buf, size_t len)
extern char *nl_ether_proto2str(int, char *buf, size_t len);
extern int nl_str2ether_proto(const char *);
%cstring_output_maxsize(char *buf, size_t len)
extern char *nl_ip_proto2str(int, char *buf, size_t len);
extern int nl_str2ip_proto(const char *);
extern void nl_new_line(struct nl_dump_params *);
extern void nl_dump(struct nl_dump_params *, const char *, ...);
extern void nl_dump_line(struct nl_dump_params *, const char *, ...);
/* <netlink/netlink.h> */
extern struct nl_dump_params *alloc_dump_params(void);
extern void free_dump_params(struct nl_dump_params *);
extern int nl_connect(struct nl_sock *, int);
extern void nl_close(struct nl_sock *);
/* <netlink/socket.h> */
extern struct nl_sock *nl_socket_alloc(void);
extern struct nl_sock *nl_socket_alloc_cb(struct nl_cb *);
extern void nl_socket_free(struct nl_sock *);
extern uint32_t nl_socket_get_local_port(const struct nl_sock *);
extern void nl_socket_set_local_port(struct nl_sock *, uint32_t);
extern uint32_t nl_socket_get_peer_port(const struct nl_sock *);
extern void nl_socket_set_peer_port(struct nl_sock *, uint32_t);
extern uint32_t nl_socket_get_peer_groups(const struct nl_sock *sk);
extern void nl_socket_set_peer_groups(struct nl_sock *sk, uint32_t groups);
extern int nl_socket_set_buffer_size(struct nl_sock *, int, int);
/* <netlink/msg.h> */
extern int nlmsg_size(int);
extern int nlmsg_total_size(int);
extern int nlmsg_padlen(int);
extern void * nlmsg_data(const struct nlmsghdr *);
extern int nlmsg_datalen(const struct nlmsghdr *);
extern void * nlmsg_tail(const struct nlmsghdr *);
/* attribute access */
extern struct nlattr * nlmsg_attrdata(const struct nlmsghdr *, int);
extern int nlmsg_attrlen(const struct nlmsghdr *, int);
/* message parsing */
extern int nlmsg_valid_hdr(const struct nlmsghdr *, int);
extern int nlmsg_ok(const struct nlmsghdr *, int);
extern struct nlmsghdr * nlmsg_next(struct nlmsghdr *, int *);
extern int nlmsg_parse(struct nlmsghdr *, int, struct nlattr **,
int, struct nla_policy *);
extern struct nlattr * nlmsg_find_attr(struct nlmsghdr *, int, int);
extern int nlmsg_validate(struct nlmsghdr *, int, int,
struct nla_policy *);
extern struct nl_msg * nlmsg_alloc(void);
extern struct nl_msg * nlmsg_alloc_size(size_t);
extern struct nl_msg * nlmsg_alloc_simple(int, int);
extern void nlmsg_set_default_size(size_t);
extern struct nl_msg * nlmsg_inherit(struct nlmsghdr *);
extern struct nl_msg * nlmsg_convert(struct nlmsghdr *);
extern void * nlmsg_reserve(struct nl_msg *, size_t, int);
extern int nlmsg_append(struct nl_msg *, void *, size_t, int);
extern int nlmsg_expand(struct nl_msg *, size_t);
extern struct nlmsghdr * nlmsg_put(struct nl_msg *, uint32_t, uint32_t,
int, int, int);
extern struct nlmsghdr * nlmsg_hdr(struct nl_msg *);
extern void nlmsg_get(struct nl_msg *);
extern void nlmsg_free(struct nl_msg *);
/* attribute modification */
extern void nlmsg_set_proto(struct nl_msg *, int);
extern int nlmsg_get_proto(struct nl_msg *);
extern size_t nlmsg_get_max_size(struct nl_msg *);
extern void nlmsg_set_src(struct nl_msg *, struct sockaddr_nl *);
extern struct sockaddr_nl *nlmsg_get_src(struct nl_msg *);
extern void nlmsg_set_dst(struct nl_msg *, struct sockaddr_nl *);
extern struct sockaddr_nl *nlmsg_get_dst(struct nl_msg *);
extern void nlmsg_set_creds(struct nl_msg *, struct ucred *);
extern struct ucred * nlmsg_get_creds(struct nl_msg *);
extern char * nl_nlmsgtype2str(int, char *, size_t);
extern int nl_str2nlmsgtype(const char *);
extern char * nl_nlmsg_flags2str(int, char *, size_t);
extern int nl_msg_parse(struct nl_msg *,
void (*cb)(struct nl_object *, void *),
void *);
extern void nl_msg_dump(struct nl_msg *, FILE *);
%inline %{
struct nl_object *cast_obj(void *obj)
{
return (struct nl_object *) obj;
}
struct nl_object *object_alloc_name(const char *name)
{
struct nl_object *obj;
if (nl_object_alloc_name(name, &obj) < 0)
return NULL;
return obj;
}
%};
extern struct nl_object *nl_object_alloc(struct nl_object_ops *);
extern void nl_object_free(struct nl_object *);
extern struct nl_object *nl_object_clone(struct nl_object *);
extern void nl_object_get(struct nl_object *);
extern void nl_object_put(struct nl_object *);
extern int nl_object_shared(struct nl_object *);
%cstring_output_maxsize(char *buf, size_t len)
extern void nl_object_dump_buf(struct nl_object *, char *buf, size_t len);
extern void nl_object_dump(struct nl_object *, struct nl_dump_params *);
extern int nl_object_identical(struct nl_object *, struct nl_object *);
extern uint32_t nl_object_diff(struct nl_object *, struct nl_object *);
extern int nl_object_match_filter(struct nl_object *, struct nl_object *);
%cstring_output_maxsize(char *buf, size_t len)
extern char *nl_object_attrs2str(struct nl_object *, uint32_t, char *buf, size_t len);
%cstring_output_maxsize(char *buf, size_t len)
extern char *nl_object_attr_list(struct nl_object *, char *buf, size_t len);
extern void nl_object_mark(struct nl_object *);
extern void nl_object_unmark(struct nl_object *);
extern int nl_object_is_marked(struct nl_object *);
extern int nl_object_get_refcnt(struct nl_object *);
/* <netlink/cache.h> */
typedef void (*change_func_t)(struct nl_cache *, struct nl_object *, int, void *);
%inline %{
struct nl_cache *alloc_cache_name(const char *name)
{
struct nl_cache *c;
if (nl_cache_alloc_name(name, &c) < 0)
return NULL;
return c;
}
struct nl_cache_mngr *alloc_cache_mngr(struct nl_sock *sock,
int protocol, int flags)
{
struct nl_cache_mngr *mngr;
if (nl_cache_mngr_alloc(sock, protocol, flags, &mngr) < 0)
return NULL;
return mngr;
}
struct nl_cache *cache_mngr_add(struct nl_cache_mngr *mngr,
const char *name, change_func_t func,
void *arg)
{
struct nl_cache *cache;
if (nl_cache_mngr_add(mngr, name, func, arg, &cache) < 0)
return NULL;
return cache;
}
%}
/* Access Functions */
extern int nl_cache_nitems(struct nl_cache *);
extern int nl_cache_nitems_filter(struct nl_cache *,
struct nl_object *);
extern struct nl_cache_ops * nl_cache_get_ops(struct nl_cache *);
extern struct nl_object * nl_cache_get_first(struct nl_cache *);
extern struct nl_object * nl_cache_get_last(struct nl_cache *);
extern struct nl_object * nl_cache_get_next(struct nl_object *);
extern struct nl_object * nl_cache_get_prev(struct nl_object *);
extern struct nl_cache * nl_cache_alloc(struct nl_cache_ops *);
extern struct nl_cache * nl_cache_subset(struct nl_cache *,
struct nl_object *);
extern void nl_cache_clear(struct nl_cache *);
extern void nl_cache_free(struct nl_cache *);
/* Cache modification */
extern int nl_cache_add(struct nl_cache *,
struct nl_object *);
extern int nl_cache_parse_and_add(struct nl_cache *,
struct nl_msg *);
extern void nl_cache_remove(struct nl_object *);
extern int nl_cache_refill(struct nl_sock *,
struct nl_cache *);
extern int nl_cache_pickup(struct nl_sock *,
struct nl_cache *);
extern int nl_cache_resync(struct nl_sock *,
struct nl_cache *,
change_func_t,
void *);
extern int nl_cache_include(struct nl_cache *,
struct nl_object *,
change_func_t,
void *);
extern void nl_cache_set_arg1(struct nl_cache *, int);
extern void nl_cache_set_arg2(struct nl_cache *, int);
/* General */
extern int nl_cache_is_empty(struct nl_cache *);
extern struct nl_object * nl_cache_search(struct nl_cache *,
struct nl_object *);
extern void nl_cache_mark_all(struct nl_cache *);
/* Dumping */
extern void nl_cache_dump(struct nl_cache *,
struct nl_dump_params *);
extern void nl_cache_dump_filter(struct nl_cache *,
struct nl_dump_params *,
struct nl_object *);
/* Iterators */
extern void nl_cache_foreach(struct nl_cache *,
void (*cb)(struct nl_object *,
void *),
void *arg);
extern void nl_cache_foreach_filter(struct nl_cache *,
struct nl_object *,
void (*cb)(struct
nl_object *,
void *),
void *arg);
/* --- cache management --- */
/* Cache type management */
extern struct nl_cache_ops * nl_cache_ops_lookup(const char *);
extern struct nl_cache_ops * nl_cache_ops_associate(int, int);
extern struct nl_msgtype * nl_msgtype_lookup(struct nl_cache_ops *, int);
extern void nl_cache_ops_foreach(void (*cb)(struct nl_cache_ops *, void *), void *);
extern int nl_cache_mngt_register(struct nl_cache_ops *);
extern int nl_cache_mngt_unregister(struct nl_cache_ops *);
/* Global cache provisioning/requiring */
extern void nl_cache_mngt_provide(struct nl_cache *);
extern void nl_cache_mngt_unprovide(struct nl_cache *);
extern struct nl_cache * nl_cache_mngt_require(const char *);
struct nl_cache_mngr;
#define NL_AUTO_PROVIDE 1
extern int nl_cache_mngr_get_fd(struct nl_cache_mngr *);
extern int nl_cache_mngr_poll(struct nl_cache_mngr *,
int);
extern int nl_cache_mngr_data_ready(struct nl_cache_mngr *);
extern void nl_cache_mngr_free(struct nl_cache_mngr *);
/* <netlink/addr.h> */
%inline %{
struct nl_addr *addr_parse(const char *addr, int guess)
{
struct nl_addr *result;
if (nl_addr_parse(addr, guess, &result) < 0)
return NULL;
return result;
}
%};
extern struct nl_addr *nl_addr_alloc(size_t);
extern struct nl_addr *nl_addr_alloc_attr(struct nlattr *, int);
extern struct nl_addr *nl_addr_build(int, void *, size_t);
extern struct nl_addr *nl_addr_clone(struct nl_addr *);
extern struct nl_addr *nl_addr_get(struct nl_addr *);
extern void nl_addr_put(struct nl_addr *);
extern int nl_addr_shared(struct nl_addr *);
extern int nl_addr_cmp(struct nl_addr *, struct nl_addr *);
extern int nl_addr_cmp_prefix(struct nl_addr *, struct nl_addr *);
extern int nl_addr_iszero(struct nl_addr *);
extern int nl_addr_valid(char *, int);
extern int nl_addr_guess_family(struct nl_addr *);
extern int nl_addr_fill_sockaddr(struct nl_addr *, struct sockaddr *, socklen_t *);
extern int nl_addr_info(struct nl_addr *, struct addrinfo **);
extern int nl_addr_resolve(struct nl_addr *addr, char *host, size_t hostlen);
extern void nl_addr_set_family(struct nl_addr *, int);
extern int nl_addr_get_family(struct nl_addr *);
extern int nl_addr_set_binary_addr(struct nl_addr *, void *, size_t);
extern void *nl_addr_get_binary_addr(struct nl_addr *);
extern unsigned int nl_addr_get_len(struct nl_addr *);
extern void nl_addr_set_prefixlen(struct nl_addr *, int);
extern unsigned int nl_addr_get_prefixlen(struct nl_addr *);
%cstring_output_maxsize(char *buf, size_t len)
extern char *nl_af2str(int, char *buf, size_t len);
extern int nl_str2af(const char *);
%cstring_output_maxsize(char *buf, size_t len)
extern char *nl_addr2str(struct nl_addr *, char *buf, size_t len);
|