| 1 |
%module capi |
| 2 |
%{ |
| 3 |
#include <netlink/genl/ctrl.h> |
| 4 |
#include <netlink/genl/family.h> |
| 5 |
#include <netlink/genl/genl.h> |
| 6 |
#include <netlink/genl/mngt.h> |
| 7 |
%} |
| 8 |
|
| 9 |
%include <stdint.i> |
| 10 |
%include <cstring.i> |
| 11 |
|
| 12 |
/* #include <netlink/genl/ctrl.h> */ |
| 13 |
extern int genl_ctrl_alloc_cache(struct nl_sock *, struct nl_cache **o_cache); |
| 14 |
extern struct genl_family *genl_ctrl_search(struct nl_cache *, int); |
| 15 |
extern struct genl_family *genl_ctrl_search_by_name(struct nl_cache *, |
| 16 |
const char *); |
| 17 |
extern int genl_ctrl_resolve(struct nl_sock *, const char *); |
| 18 |
extern int genl_ctrl_resolve_grp(struct nl_sock *sk, const char *family, |
| 19 |
const char *grp); |
| 20 |
|
| 21 |
/* #include <netlink/genl/family.h> */ |
| 22 |
extern struct genl_family *genl_family_alloc(void); |
| 23 |
extern void genl_family_put(struct genl_family *); |
| 24 |
|
| 25 |
extern unsigned int genl_family_get_id(struct genl_family *); |
| 26 |
extern void genl_family_set_id(struct genl_family *, unsigned int); |
| 27 |
extern char *genl_family_get_name(struct genl_family *); |
| 28 |
extern void genl_family_set_name(struct genl_family *, const char *name); |
| 29 |
extern uint8_t genl_family_get_version(struct genl_family *); |
| 30 |
extern void genl_family_set_version(struct genl_family *, uint8_t); |
| 31 |
extern uint32_t genl_family_get_hdrsize(struct genl_family *); |
| 32 |
extern void genl_family_set_hdrsize(struct genl_family *, uint32_t); |
| 33 |
extern uint32_t genl_family_get_maxattr(struct genl_family *); |
| 34 |
extern void genl_family_set_maxattr(struct genl_family *, uint32_t); |
| 35 |
|
| 36 |
extern int genl_family_add_op(struct genl_family *, int, int); |
| 37 |
extern int genl_family_add_grp(struct genl_family *, uint32_t , const char *); |
| 38 |
|
| 39 |
/* #include <linux/genetlink.h> */ |
| 40 |
struct genlmsghdr { |
| 41 |
uint8_t cmd; |
| 42 |
uint8_t version; |
| 43 |
uint16_t reserved; |
| 44 |
}; |
| 45 |
|
| 46 |
/* #include <netlink/genl/genl.h> */ |
| 47 |
extern int genl_connect(struct nl_sock *); |
| 48 |
extern struct genlmsghdr *genlmsg_hdr(struct nlmsghdr *); |
| 49 |
|
| 50 |
extern void *genlmsg_put(struct nl_msg *, uint32_t, uint32_t, |
| 51 |
int, int, int, uint8_t, uint8_t); |
| 52 |
|
| 53 |
struct nlattr { |
| 54 |
}; |
| 55 |
|
| 56 |
struct nla_policy { |
| 57 |
/** Type of attribute or NLA_UNSPEC */ |
| 58 |
uint16_t type; |
| 59 |
|
| 60 |
/** Minimal length of payload required */ |
| 61 |
uint16_t minlen; |
| 62 |
|
| 63 |
/** Maximal length of payload allowed */ |
| 64 |
uint16_t maxlen; |
| 65 |
}; |
| 66 |
|
| 67 |
%inline %{ |
| 68 |
PyObject *py_genlmsg_parse(struct nlmsghdr *nlh, int uhl, int max, |
| 69 |
PyObject *p) |
| 70 |
{ |
| 71 |
struct nlattr *tb_msg[max + 1]; |
| 72 |
struct nla_policy *policy = NULL; |
| 73 |
void *pol; |
| 74 |
PyObject *attrs = Py_None; |
| 75 |
PyObject *k; |
| 76 |
PyObject *v; |
| 77 |
PyObject *resobj; |
| 78 |
int err; |
| 79 |
int i; |
| 80 |
|
| 81 |
if (p != Py_None) { |
| 82 |
PyObject *pobj; |
| 83 |
|
| 84 |
if (!PyList_Check(p)) { |
| 85 |
fprintf(stderr, "expected list object\n"); |
| 86 |
err = -1; |
| 87 |
goto fail; |
| 88 |
} |
| 89 |
pobj = PyList_GetItem(p, 0); |
| 90 |
err = SWIG_ConvertPtr(pobj, &pol, SWIGTYPE_p_nla_policy, 0 | 0 ); |
| 91 |
if (!SWIG_IsOK(err)) |
| 92 |
goto fail; |
| 93 |
policy = pol; |
| 94 |
} |
| 95 |
err = genlmsg_parse(nlh, uhl, tb_msg, max, policy); |
| 96 |
if (err < 0) { |
| 97 |
fprintf(stderr, "Failed to parse response message\n"); |
| 98 |
} else { |
| 99 |
attrs = PyDict_New(); |
| 100 |
for (i = 0; i <= max; i++) |
| 101 |
if (tb_msg[i]) { |
| 102 |
k = PyInt_FromLong((long)i); |
| 103 |
v = SWIG_NewPointerObj(SWIG_as_voidptr(tb_msg[i]), SWIGTYPE_p_nlattr, 0 | 0 ); |
| 104 |
PyDict_SetItem(attrs, k, v); |
| 105 |
} |
| 106 |
} |
| 107 |
fail: |
| 108 |
if (attrs == Py_None) |
| 109 |
Py_INCREF(Py_None); |
| 110 |
resobj = Py_BuildValue("(iO)", err, attrs); |
| 111 |
return resobj; |
| 112 |
} |
| 113 |
|
| 114 |
%} |
| 115 |
/* #include <netlink/genl/mngt.h> */ |
| 116 |
/* nothing yet */ |