Add packaging directory
[platform/upstream/libnl3.git] / python / netlink / capi.i
1 %module capi
2 %{
3 #include <netlink/netlink.h>
4 #include <netlink/types.h>
5 #include <netlink/socket.h>
6 #include <netlink/msg.h>
7 #include <netlink/object.h>
8 #include <netlink/cache.h>
9 %}
10
11 %include <stdint.i>
12 %include <cstring.i>
13
14 %inline %{
15         struct nl_dump_params *alloc_dump_params(void)
16         {
17                 struct nl_dump_params *dp;
18                 if (!(dp = calloc(1, sizeof(*dp))))
19                         return NULL;
20                 dp->dp_fd = stdout;
21                 return dp;
22         }
23
24         void free_dump_params(struct nl_dump_params *dp)
25         {
26                 free(dp);
27         }
28 %};
29
30 /* <netlink/types.h> */
31
32 enum nl_dump_type {
33         NL_DUMP_LINE,           /**< Dump object briefly on one line */
34         NL_DUMP_DETAILS,        /**< Dump all attributes but no statistics */
35         NL_DUMP_STATS,          /**< Dump all attributes including statistics */
36         __NL_DUMP_MAX,
37 };
38
39 struct nl_dump_params
40 {
41         /**
42          * Specifies the type of dump that is requested.
43          */
44         enum nl_dump_type       dp_type;
45
46         /**
47          * Specifies the number of whitespaces to be put in front
48          * of every new line (indentation).
49          */
50         int                     dp_prefix;
51
52         /**
53          * Causes the cache index to be printed for each element.
54          */
55         int                     dp_print_index;
56
57         /**
58          * Causes each element to be prefixed with the message type.
59          */
60         int                     dp_dump_msgtype;
61
62         /**
63          * A callback invoked for output
64          *
65          * Passed arguments are:
66          *  - dumping parameters
67          *  - string to append to the output
68          */
69         void                    (*dp_cb)(struct nl_dump_params *, char *);
70
71         /**
72          * A callback invoked for every new line, can be used to
73          * customize the indentation.
74          *
75          * Passed arguments are:
76          *  - dumping parameters
77          *  - line number starting from 0
78          */
79         void                    (*dp_nl_cb)(struct nl_dump_params *, int);
80
81         /**
82          * User data pointer, can be used to pass data to callbacks.
83          */
84         void                    *dp_data;
85
86         /**
87          * File descriptor the dumping output should go to
88          */
89         FILE *                  dp_fd;
90
91         /**
92          * Alternatively the output may be redirected into a buffer
93          */
94         char *                  dp_buf;
95
96         /**
97          * Length of the buffer dp_buf
98          */
99         size_t                  dp_buflen;
100
101         /**
102          * PRIVATE
103          * Set if a dump was performed prior to the actual dump handler.
104          */
105         int                     dp_pre_dump;
106
107         /**
108          * PRIVATE
109          * Owned by the current caller
110          */
111         int                     dp_ivar;
112
113         unsigned int            dp_line;
114 };
115
116 /* <netlink/errno.h> */
117 extern const char *nl_geterror(int);
118
119 /* <netlink/utils.h> */
120
121 extern double nl_cancel_down_bytes(unsigned long long, char **);
122 extern double nl_cancel_down_bits(unsigned long long, char **);
123 %cstring_output_maxsize(char *buf, size_t len)
124 extern int nl_rate2str(unsigned long long rate, int type, char *buf, size_t len);
125 extern double nl_cancel_down_us(uint32_t, char **);
126
127 extern long nl_size2int(const char *);
128 %cstring_output_maxsize(char *buf, const size_t len)
129 extern char *nl_size2str(const size_t, char *buf, const size_t len);
130 extern long nl_prob2int(const char *);
131
132 extern int nl_get_user_hz(void);
133 extern uint32_t nl_us2ticks(uint32_t);
134 extern uint32_t nl_ticks2us(uint32_t);
135 extern int nl_str2msec(const char *, uint64_t *);
136
137 %cstring_output_maxsize(char *buf, size_t len)
138 extern char *nl_msec2str(uint64_t, char *buf, size_t len);
139
140 %cstring_output_maxsize(char *buf, size_t len)
141 extern char *nl_llproto2str(int, char *buf, size_t len);
142 extern int nl_str2llproto(const char *);
143
144 %cstring_output_maxsize(char *buf, size_t len)
145 extern char *nl_ether_proto2str(int, char *buf, size_t len);
146 extern int nl_str2ether_proto(const char *);
147
148 %cstring_output_maxsize(char *buf, size_t len)
149 extern char *nl_ip_proto2str(int, char *buf, size_t len);
150 extern int nl_str2ip_proto(const char *);
151
152 extern void nl_new_line(struct nl_dump_params *);
153 extern void nl_dump(struct nl_dump_params *, const char *, ...);
154 extern void nl_dump_line(struct nl_dump_params *, const char *, ...);
155
156 /* <netlink/netlink.h> */
157 extern struct nl_dump_params *alloc_dump_params(void);
158 extern void free_dump_params(struct nl_dump_params *);
159
160 extern int nl_connect(struct nl_sock *, int);
161 extern void nl_close(struct nl_sock *);
162
163 /* <netlink/socket.h> */
164 extern struct nl_sock *nl_socket_alloc(void);
165 extern struct nl_sock *nl_socket_alloc_cb(struct nl_cb *);
166 extern void nl_socket_free(struct nl_sock *);
167
168 extern uint32_t nl_socket_get_local_port(const struct nl_sock *);
169 extern void nl_socket_set_local_port(struct nl_sock *, uint32_t);
170
171 extern uint32_t nl_socket_get_peer_port(const struct nl_sock *);
172 extern void nl_socket_set_peer_port(struct nl_sock *, uint32_t);
173
174 extern uint32_t nl_socket_get_peer_groups(const struct nl_sock *sk);
175 extern void  nl_socket_set_peer_groups(struct nl_sock *sk, uint32_t groups);
176
177 extern int nl_socket_set_buffer_size(struct nl_sock *, int, int);
178
179 /* <netlink/msg.h> */
180 extern int                      nlmsg_size(int);
181 extern int                      nlmsg_total_size(int);
182 extern int                      nlmsg_padlen(int);
183
184 extern void *                   nlmsg_data(const struct nlmsghdr *);
185 extern int                      nlmsg_datalen(const struct nlmsghdr *);
186 extern void *                   nlmsg_tail(const struct nlmsghdr *);
187
188 /* attribute access */
189 extern struct nlattr *    nlmsg_attrdata(const struct nlmsghdr *, int);
190 extern int                nlmsg_attrlen(const struct nlmsghdr *, int);
191
192 /* message parsing */
193 extern int                nlmsg_valid_hdr(const struct nlmsghdr *, int);
194 extern int                nlmsg_ok(const struct nlmsghdr *, int);
195 extern struct nlmsghdr *  nlmsg_next(struct nlmsghdr *, int *);
196 extern int                nlmsg_parse(struct nlmsghdr *, int, struct nlattr **,
197                                       int, struct nla_policy *);
198 extern struct nlattr *    nlmsg_find_attr(struct nlmsghdr *, int, int);
199 extern int                nlmsg_validate(struct nlmsghdr *, int, int,
200                                          struct nla_policy *);
201
202 extern struct nl_msg *    nlmsg_alloc(void);
203 extern struct nl_msg *    nlmsg_alloc_size(size_t);
204 extern struct nl_msg *    nlmsg_alloc_simple(int, int);
205 extern void               nlmsg_set_default_size(size_t);
206 extern struct nl_msg *    nlmsg_inherit(struct nlmsghdr *);
207 extern struct nl_msg *    nlmsg_convert(struct nlmsghdr *);
208 extern void *             nlmsg_reserve(struct nl_msg *, size_t, int);
209 extern int                nlmsg_append(struct nl_msg *, void *, size_t, int);
210 extern int                nlmsg_expand(struct nl_msg *, size_t);
211
212 extern struct nlmsghdr *  nlmsg_put(struct nl_msg *, uint32_t, uint32_t,
213                                     int, int, int);
214 extern struct nlmsghdr *  nlmsg_hdr(struct nl_msg *);
215 extern void               nlmsg_get(struct nl_msg *);
216 extern void               nlmsg_free(struct nl_msg *);
217
218 /* attribute modification */
219 extern void               nlmsg_set_proto(struct nl_msg *, int);
220 extern int                nlmsg_get_proto(struct nl_msg *);
221 extern size_t             nlmsg_get_max_size(struct nl_msg *);
222 extern void               nlmsg_set_src(struct nl_msg *, struct sockaddr_nl *);
223 extern struct sockaddr_nl *nlmsg_get_src(struct nl_msg *);
224 extern void               nlmsg_set_dst(struct nl_msg *, struct sockaddr_nl *);
225 extern struct sockaddr_nl *nlmsg_get_dst(struct nl_msg *);
226 extern void               nlmsg_set_creds(struct nl_msg *, struct ucred *);
227 extern struct ucred *     nlmsg_get_creds(struct nl_msg *);
228
229 extern char *             nl_nlmsgtype2str(int, char *, size_t);
230 extern int                nl_str2nlmsgtype(const char *);
231
232 extern char *             nl_nlmsg_flags2str(int, char *, size_t);
233
234 extern int                nl_msg_parse(struct nl_msg *,
235                                        void (*cb)(struct nl_object *, void *),
236                                        void *);
237
238 extern void             nl_msg_dump(struct nl_msg *, FILE *);
239
240 %inline %{
241         struct nl_object *cast_obj(void *obj)
242         {
243                 return (struct nl_object *) obj;
244         }
245
246         struct nl_object *object_alloc_name(const char *name)
247         {
248                 struct nl_object *obj;
249
250                 if (nl_object_alloc_name(name, &obj) < 0)
251                         return NULL;
252
253                 return obj;
254         }
255 %};
256
257 extern struct nl_object *nl_object_alloc(struct nl_object_ops *);
258 extern void nl_object_free(struct nl_object *);
259 extern struct nl_object *nl_object_clone(struct nl_object *);
260 extern void nl_object_get(struct nl_object *);
261 extern void nl_object_put(struct nl_object *);
262 extern int nl_object_shared(struct nl_object *);
263
264 %cstring_output_maxsize(char *buf, size_t len)
265 extern void nl_object_dump_buf(struct nl_object *, char *buf, size_t len);
266
267 extern void nl_object_dump(struct nl_object *, struct nl_dump_params *);
268
269 extern int nl_object_identical(struct nl_object *, struct nl_object *);
270 extern uint32_t nl_object_diff(struct nl_object *, struct nl_object *);
271 extern int nl_object_match_filter(struct nl_object *, struct nl_object *);
272
273 %cstring_output_maxsize(char *buf, size_t len)
274 extern char *nl_object_attrs2str(struct nl_object *, uint32_t, char *buf, size_t len);
275
276 %cstring_output_maxsize(char *buf, size_t len)
277 extern char *nl_object_attr_list(struct nl_object *, char *buf, size_t len);
278
279 extern void nl_object_mark(struct nl_object *);
280 extern void nl_object_unmark(struct nl_object *);
281 extern int nl_object_is_marked(struct nl_object *);
282
283 extern int nl_object_get_refcnt(struct nl_object *);
284
285 /* <netlink/cache.h> */
286
287 typedef void (*change_func_t)(struct nl_cache *, struct nl_object *, int, void *);
288
289 %inline %{
290         struct nl_cache *alloc_cache_name(const char *name)
291         {
292                 struct nl_cache *c;
293                 if (nl_cache_alloc_name(name, &c) < 0)
294                         return NULL;
295                 return c;
296         }
297
298         struct nl_cache_mngr *alloc_cache_mngr(struct nl_sock *sock,
299                                                int protocol, int flags)
300         {
301                 struct nl_cache_mngr *mngr;
302
303                 if (nl_cache_mngr_alloc(sock, protocol, flags, &mngr) < 0)
304                         return NULL;
305
306                 return mngr;
307         }
308
309         struct nl_cache *cache_mngr_add(struct nl_cache_mngr *mngr,
310                                         const char *name, change_func_t func,
311                                         void *arg)
312         {
313                 struct nl_cache *cache;
314
315                 if (nl_cache_mngr_add(mngr, name, func, arg, &cache) < 0)
316                         return NULL;
317
318                 return cache;
319         }
320 %}
321
322 /* Access Functions */
323 extern int                      nl_cache_nitems(struct nl_cache *);
324 extern int                      nl_cache_nitems_filter(struct nl_cache *,
325                                                        struct nl_object *);
326 extern struct nl_cache_ops *    nl_cache_get_ops(struct nl_cache *);
327 extern struct nl_object *       nl_cache_get_first(struct nl_cache *);
328 extern struct nl_object *       nl_cache_get_last(struct nl_cache *);
329 extern struct nl_object *       nl_cache_get_next(struct nl_object *);
330 extern struct nl_object *       nl_cache_get_prev(struct nl_object *);
331
332 extern struct nl_cache *        nl_cache_alloc(struct nl_cache_ops *);
333 extern struct nl_cache *        nl_cache_subset(struct nl_cache *,
334                                                 struct nl_object *);
335 extern void                     nl_cache_clear(struct nl_cache *);
336 extern void                     nl_cache_free(struct nl_cache *);
337
338 /* Cache modification */
339 extern int                      nl_cache_add(struct nl_cache *,
340                                              struct nl_object *);
341 extern int                      nl_cache_parse_and_add(struct nl_cache *,
342                                                        struct nl_msg *);
343 extern void                     nl_cache_remove(struct nl_object *);
344 extern int                      nl_cache_refill(struct nl_sock *,
345                                                 struct nl_cache *);
346 extern int                      nl_cache_pickup(struct nl_sock *,
347                                                 struct nl_cache *);
348 extern int                      nl_cache_resync(struct nl_sock *,
349                                                 struct nl_cache *,
350                                                 change_func_t,
351                                                 void *);
352 extern int                      nl_cache_include(struct nl_cache *,
353                                                  struct nl_object *,
354                                                  change_func_t,
355                                                  void *);
356 extern void                     nl_cache_set_arg1(struct nl_cache *, int);
357 extern void                     nl_cache_set_arg2(struct nl_cache *, int);
358
359 /* General */
360 extern int                      nl_cache_is_empty(struct nl_cache *);
361 extern struct nl_object *       nl_cache_search(struct nl_cache *,
362                                                 struct nl_object *);
363 extern void                     nl_cache_mark_all(struct nl_cache *);
364
365 /* Dumping */
366 extern void                     nl_cache_dump(struct nl_cache *,
367                                               struct nl_dump_params *);
368 extern void                     nl_cache_dump_filter(struct nl_cache *,
369                                                      struct nl_dump_params *,
370                                                      struct nl_object *);
371
372 /* Iterators */
373 extern void                     nl_cache_foreach(struct nl_cache *,
374                                                  void (*cb)(struct nl_object *,
375                                                             void *),
376                                                  void *arg);
377 extern void                     nl_cache_foreach_filter(struct nl_cache *,
378                                                         struct nl_object *,
379                                                         void (*cb)(struct
380                                                                    nl_object *,
381                                                                    void *),
382                                                         void *arg);
383
384 /* --- cache management --- */
385
386 /* Cache type management */
387 extern struct nl_cache_ops *    nl_cache_ops_lookup(const char *);
388 extern struct nl_cache_ops *    nl_cache_ops_associate(int, int);
389 extern struct nl_msgtype *      nl_msgtype_lookup(struct nl_cache_ops *, int);
390 extern void                     nl_cache_ops_foreach(void (*cb)(struct nl_cache_ops *, void *), void *);
391 extern int                      nl_cache_mngt_register(struct nl_cache_ops *);
392 extern int                      nl_cache_mngt_unregister(struct nl_cache_ops *);
393
394 /* Global cache provisioning/requiring */
395 extern void                     nl_cache_mngt_provide(struct nl_cache *);
396 extern void                     nl_cache_mngt_unprovide(struct nl_cache *);
397 extern struct nl_cache *        nl_cache_mngt_require(const char *);
398
399 struct nl_cache_mngr;
400
401 #define NL_AUTO_PROVIDE         1
402
403 extern int                      nl_cache_mngr_get_fd(struct nl_cache_mngr *);
404 extern int                      nl_cache_mngr_poll(struct nl_cache_mngr *,
405                                                    int);
406 extern int                      nl_cache_mngr_data_ready(struct nl_cache_mngr *);
407 extern void                     nl_cache_mngr_free(struct nl_cache_mngr *);
408
409 /* <netlink/addr.h> */
410 %inline %{
411         struct nl_addr *addr_parse(const char *addr, int guess)
412         {
413                 struct nl_addr *result;
414
415                 if (nl_addr_parse(addr, guess, &result) < 0)
416                         return NULL;
417
418                 return result;
419         }
420 %};
421
422 extern struct nl_addr *nl_addr_alloc(size_t);
423 extern struct nl_addr *nl_addr_alloc_attr(struct nlattr *, int);
424 extern struct nl_addr *nl_addr_build(int, void *, size_t);
425 extern struct nl_addr *nl_addr_clone(struct nl_addr *);
426
427 extern struct nl_addr *nl_addr_get(struct nl_addr *);
428 extern void nl_addr_put(struct nl_addr *);
429 extern int nl_addr_shared(struct nl_addr *);
430
431 extern int nl_addr_cmp(struct nl_addr *, struct nl_addr *);
432 extern int nl_addr_cmp_prefix(struct nl_addr *, struct nl_addr *);
433 extern int nl_addr_iszero(struct nl_addr *);
434 extern int nl_addr_valid(char *, int);
435 extern int nl_addr_guess_family(struct nl_addr *);
436 extern int nl_addr_fill_sockaddr(struct nl_addr *, struct sockaddr *, socklen_t *);
437 extern int nl_addr_info(struct nl_addr *, struct addrinfo **);
438 extern int nl_addr_resolve(struct nl_addr *addr, char *host, size_t hostlen);
439
440 extern void nl_addr_set_family(struct nl_addr *, int);
441 extern int nl_addr_get_family(struct nl_addr *);
442 extern int nl_addr_set_binary_addr(struct nl_addr *, void *, size_t);
443
444 extern void *nl_addr_get_binary_addr(struct nl_addr *);
445 extern unsigned int nl_addr_get_len(struct nl_addr *);
446 extern void nl_addr_set_prefixlen(struct nl_addr *, int);
447 extern unsigned int nl_addr_get_prefixlen(struct nl_addr *);
448
449 %cstring_output_maxsize(char *buf, size_t len)
450 extern char *nl_af2str(int, char *buf, size_t len);
451 extern int nl_str2af(const char *);
452
453 %cstring_output_maxsize(char *buf, size_t len)
454 extern char *nl_addr2str(struct nl_addr *, char *buf, size_t len);