handlers.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. * netlink/handlers.c default netlink message handlers
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation version 2.1
  7. * of the License.
  8. *
  9. * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
  10. */
  11. #ifndef NETLINK_HANDLERS_H_
  12. #define NETLINK_HANDLERS_H_
  13. #include <stdio.h>
  14. #include <stdint.h>
  15. #include <sys/types.h>
  16. #include <netlink/netlink-compat.h>
  17. #include <netlink/netlink-kernel.h>
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. struct nl_cb;
  22. struct nl_handle;
  23. struct nl_msg;
  24. struct ucred;
  25. /**
  26. * @name Callback Typedefs
  27. * @{
  28. */
  29. /**
  30. * nl_recvmsgs() callback for message processing customization
  31. * @ingroup cb
  32. * @arg msg netlink message being processed
  33. * @arg arg argument passwd on through caller
  34. */
  35. typedef int (*nl_recvmsg_msg_cb_t)(struct nl_msg *msg, void *arg);
  36. /**
  37. * nl_recvmsgs() callback for error message processing customization
  38. * @ingroup cb
  39. * @arg nla netlink address of the peer
  40. * @arg nlerr netlink error message being processed
  41. * @arg arg argument passed on through caller
  42. */
  43. typedef int (*nl_recvmsg_err_cb_t)(struct sockaddr_nl *nla,
  44. struct nlmsgerr *nlerr, void *arg);
  45. /** @} */
  46. /**
  47. * Callback actions
  48. * @ingroup cb
  49. */
  50. enum nl_cb_action {
  51. /** Proceed with wathever would come next */
  52. NL_OK,
  53. /** Skip this message */
  54. NL_SKIP,
  55. /** Stop parsing altogether and discard remaining messages */
  56. NL_STOP,
  57. };
  58. /* backwards compatibility */
  59. #define NL_PROCEED NL_OK
  60. #define NL_EXIT NL_STOP
  61. /**
  62. * Callback kinds
  63. * @ingroup cb
  64. */
  65. enum nl_cb_kind {
  66. /** Default handlers (quiet) */
  67. NL_CB_DEFAULT,
  68. /** Verbose default handlers (error messages printed) */
  69. NL_CB_VERBOSE,
  70. /** Debug handlers for debugging */
  71. NL_CB_DEBUG,
  72. /** Customized handler specified by the user */
  73. NL_CB_CUSTOM,
  74. __NL_CB_KIND_MAX,
  75. };
  76. #define NL_CB_KIND_MAX (__NL_CB_KIND_MAX - 1)
  77. /**
  78. * Callback types
  79. * @ingroup cb
  80. */
  81. enum nl_cb_type {
  82. /** Message is valid */
  83. NL_CB_VALID,
  84. /** Last message in a series of multi part messages received */
  85. NL_CB_FINISH,
  86. /** Report received that data was lost */
  87. NL_CB_OVERRUN,
  88. /** Message wants to be skipped */
  89. NL_CB_SKIPPED,
  90. /** Message is an acknowledge */
  91. NL_CB_ACK,
  92. /** Called for every message received */
  93. NL_CB_MSG_IN,
  94. /** Called for every message sent out except for nl_sendto() */
  95. NL_CB_MSG_OUT,
  96. /** Message is malformed and invalid */
  97. NL_CB_INVALID,
  98. /** Called instead of internal sequence number checking */
  99. NL_CB_SEQ_CHECK,
  100. /** Sending of an acknowledge message has been requested */
  101. NL_CB_SEND_ACK,
  102. __NL_CB_TYPE_MAX,
  103. };
  104. #define NL_CB_TYPE_MAX (__NL_CB_TYPE_MAX - 1)
  105. extern struct nl_cb * nl_cb_alloc(enum nl_cb_kind);
  106. extern struct nl_cb * nl_cb_clone(struct nl_cb *);
  107. extern struct nl_cb * nl_cb_get(struct nl_cb *);
  108. extern void nl_cb_put(struct nl_cb *);
  109. extern int nl_cb_set(struct nl_cb *, enum nl_cb_type, enum nl_cb_kind,
  110. nl_recvmsg_msg_cb_t, void *);
  111. extern int nl_cb_set_all(struct nl_cb *, enum nl_cb_kind,
  112. nl_recvmsg_msg_cb_t, void *);
  113. extern int nl_cb_err(struct nl_cb *, enum nl_cb_kind, nl_recvmsg_err_cb_t,
  114. void *);
  115. extern void nl_cb_overwrite_recvmsgs(struct nl_cb *,
  116. int (*func)(struct nl_handle *,
  117. struct nl_cb *));
  118. extern void nl_cb_overwrite_recv(struct nl_cb *,
  119. int (*func)(struct nl_handle *,
  120. struct sockaddr_nl *,
  121. unsigned char **,
  122. struct ucred **));
  123. extern void nl_cb_overwrite_send(struct nl_cb *,
  124. int (*func)(struct nl_handle *,
  125. struct nl_msg *));
  126. #ifdef __cplusplus
  127. }
  128. #endif
  129. #endif