capi.i 3.0 KB

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