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