libnl  3.2.3
/build/buildd/libnl3-3.2.3/include/netlink/handlers.h
00001 /*
00002  * netlink/handlers.c   default netlink message handlers
00003  *
00004  *      This library is free software; you can redistribute it and/or
00005  *      modify it under the terms of the GNU Lesser General Public
00006  *      License as published by the Free Software Foundation version 2.1
00007  *      of the License.
00008  *
00009  * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
00010  */
00011 
00012 #ifndef NETLINK_HANDLERS_H_
00013 #define NETLINK_HANDLERS_H_
00014 
00015 #include <stdio.h>
00016 #include <stdint.h>
00017 #include <sys/types.h>
00018 #include <netlink/netlink-compat.h>
00019 #include <netlink/netlink-kernel.h>
00020 
00021 #ifdef __cplusplus
00022 extern "C" {
00023 #endif
00024 
00025 struct nl_cb;
00026 struct nl_sock;
00027 struct nl_msg;
00028 struct ucred;
00029 
00030 /**
00031  * @name Callback Typedefs
00032  * @{
00033  */
00034 
00035 /**
00036  * nl_recvmsgs() callback for message processing customization
00037  * @ingroup cb
00038  * @arg msg             netlink message being processed
00039  * @arg arg             argument passwd on through caller
00040  */
00041 typedef int (*nl_recvmsg_msg_cb_t)(struct nl_msg *msg, void *arg);
00042 
00043 /**
00044  * nl_recvmsgs() callback for error message processing customization
00045  * @ingroup cb
00046  * @arg nla             netlink address of the peer
00047  * @arg nlerr           netlink error message being processed
00048  * @arg arg             argument passed on through caller
00049  */
00050 typedef int (*nl_recvmsg_err_cb_t)(struct sockaddr_nl *nla,
00051                                    struct nlmsgerr *nlerr, void *arg);
00052 
00053 /** @} */
00054 
00055 /**
00056  * Callback actions
00057  * @ingroup cb
00058  */
00059 enum nl_cb_action {
00060         /** Proceed with wathever would come next */
00061         NL_OK,
00062         /** Skip this message */
00063         NL_SKIP,
00064         /** Stop parsing altogether and discard remaining messages */
00065         NL_STOP,
00066 };
00067 
00068 /**
00069  * Callback kinds
00070  * @ingroup cb
00071  */
00072 enum nl_cb_kind {
00073         /** Default handlers (quiet) */
00074         NL_CB_DEFAULT,
00075         /** Verbose default handlers (error messages printed) */
00076         NL_CB_VERBOSE,
00077         /** Debug handlers for debugging */
00078         NL_CB_DEBUG,
00079         /** Customized handler specified by the user */
00080         NL_CB_CUSTOM,
00081         __NL_CB_KIND_MAX,
00082 };
00083 
00084 #define NL_CB_KIND_MAX (__NL_CB_KIND_MAX - 1)
00085 
00086 /**
00087  * Callback types
00088  * @ingroup cb
00089  */
00090 enum nl_cb_type {
00091         /** Message is valid */
00092         NL_CB_VALID,
00093         /** Last message in a series of multi part messages received */
00094         NL_CB_FINISH,
00095         /** Report received that data was lost */
00096         NL_CB_OVERRUN,
00097         /** Message wants to be skipped */
00098         NL_CB_SKIPPED,
00099         /** Message is an acknowledge */
00100         NL_CB_ACK,
00101         /** Called for every message received */
00102         NL_CB_MSG_IN,
00103         /** Called for every message sent out except for nl_sendto() */
00104         NL_CB_MSG_OUT,
00105         /** Message is malformed and invalid */
00106         NL_CB_INVALID,
00107         /** Called instead of internal sequence number checking */
00108         NL_CB_SEQ_CHECK,
00109         /** Sending of an acknowledge message has been requested */
00110         NL_CB_SEND_ACK,
00111         /** Flag NLM_F_DUMP_INTR is set in message */
00112         NL_CB_DUMP_INTR,
00113         __NL_CB_TYPE_MAX,
00114 };
00115 
00116 #define NL_CB_TYPE_MAX (__NL_CB_TYPE_MAX - 1)
00117 
00118 extern struct nl_cb *   nl_cb_alloc(enum nl_cb_kind);
00119 extern struct nl_cb *   nl_cb_clone(struct nl_cb *);
00120 extern struct nl_cb *   nl_cb_get(struct nl_cb *);
00121 extern void             nl_cb_put(struct nl_cb *);
00122 
00123 extern int  nl_cb_set(struct nl_cb *, enum nl_cb_type, enum nl_cb_kind,
00124                       nl_recvmsg_msg_cb_t, void *);
00125 extern int  nl_cb_set_all(struct nl_cb *, enum nl_cb_kind,
00126                           nl_recvmsg_msg_cb_t, void *);
00127 extern int  nl_cb_err(struct nl_cb *, enum nl_cb_kind, nl_recvmsg_err_cb_t,
00128                       void *);
00129 
00130 extern void nl_cb_overwrite_recvmsgs(struct nl_cb *,
00131                                      int (*func)(struct nl_sock *,
00132                                                  struct nl_cb *));
00133 extern void nl_cb_overwrite_recv(struct nl_cb *,
00134                                  int (*func)(struct nl_sock *,
00135                                              struct sockaddr_nl *,
00136                                              unsigned char **,
00137                                              struct ucred **));
00138 extern void nl_cb_overwrite_send(struct nl_cb *,
00139                                  int (*func)(struct nl_sock *,
00140                                              struct nl_msg *));
00141 
00142 #ifdef __cplusplus
00143 }
00144 #endif
00145 
00146 #endif