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