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_sock;
  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. /**
  59. * Callback kinds
  60. * @ingroup cb
  61. */
  62. enum nl_cb_kind {
  63. /** Default handlers (quiet) */
  64. NL_CB_DEFAULT,
  65. /** Verbose default handlers (error messages printed) */
  66. NL_CB_VERBOSE,
  67. /** Debug handlers for debugging */
  68. NL_CB_DEBUG,
  69. /** Customized handler specified by the user */
  70. NL_CB_CUSTOM,
  71. __NL_CB_KIND_MAX,
  72. };
  73. #define NL_CB_KIND_MAX (__NL_CB_KIND_MAX - 1)
  74. /**
  75. * Callback types
  76. * @ingroup cb
  77. */
  78. enum nl_cb_type {
  79. /** Message is valid */
  80. NL_CB_VALID,
  81. /** Last message in a series of multi part messages received */
  82. NL_CB_FINISH,
  83. /** Report received that data was lost */
  84. NL_CB_OVERRUN,
  85. /** Message wants to be skipped */
  86. NL_CB_SKIPPED,
  87. /** Message is an acknowledge */
  88. NL_CB_ACK,
  89. /** Called for every message received */
  90. NL_CB_MSG_IN,
  91. /** Called for every message sent out except for nl_sendto() */
  92. NL_CB_MSG_OUT,
  93. /** Message is malformed and invalid */
  94. NL_CB_INVALID,
  95. /** Called instead of internal sequence number checking */
  96. NL_CB_SEQ_CHECK,
  97. /** Sending of an acknowledge message has been requested */
  98. NL_CB_SEND_ACK,
  99. /** Flag NLM_F_DUMP_INTR is set in message */
  100. NL_CB_DUMP_INTR,
  101. __NL_CB_TYPE_MAX,
  102. };
  103. #define NL_CB_TYPE_MAX (__NL_CB_TYPE_MAX - 1)
  104. extern struct nl_cb * nl_cb_alloc(enum nl_cb_kind);
  105. extern struct nl_cb * nl_cb_clone(struct nl_cb *);
  106. extern struct nl_cb * nl_cb_get(struct nl_cb *);
  107. extern void nl_cb_put(struct nl_cb *);
  108. extern int nl_cb_set(struct nl_cb *, enum nl_cb_type, enum nl_cb_kind,
  109. nl_recvmsg_msg_cb_t, void *);
  110. extern int nl_cb_set_all(struct nl_cb *, enum nl_cb_kind,
  111. nl_recvmsg_msg_cb_t, void *);
  112. extern int nl_cb_err(struct nl_cb *, enum nl_cb_kind, nl_recvmsg_err_cb_t,
  113. void *);
  114. extern void nl_cb_overwrite_recvmsgs(struct nl_cb *,
  115. int (*func)(struct nl_sock *,
  116. struct nl_cb *));
  117. extern void nl_cb_overwrite_recv(struct nl_cb *,
  118. int (*func)(struct nl_sock *,
  119. struct sockaddr_nl *,
  120. unsigned char **,
  121. struct ucred **));
  122. extern void nl_cb_overwrite_send(struct nl_cb *,
  123. int (*func)(struct nl_sock *,
  124. struct nl_msg *));
  125. extern enum nl_cb_type nl_cb_active_type(struct nl_cb *cb);
  126. #ifdef __cplusplus
  127. }
  128. #endif
  129. #endif