libnl 1.1
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_handle;
00027 struct nl_msg;
00028 
00029 /**
00030  * @name Callback Typedefs
00031  * @{
00032  */
00033 
00034 /**
00035  * nl_recvmsgs() callback for message processing customization
00036  * @ingroup cb
00037  * @arg msg             netlink message being processed
00038  * @arg arg             argument passwd on through caller
00039  */
00040 typedef int (*nl_recvmsg_msg_cb_t)(struct nl_msg *msg, void *arg);
00041 
00042 /**
00043  * nl_recvmsgs() callback for error message processing customization
00044  * @ingroup cb
00045  * @arg nla             netlink address of the peer
00046  * @arg nlerr           netlink error message being processed
00047  * @arg arg             argument passed on through caller
00048  */
00049 typedef int (*nl_recvmsg_err_cb_t)(struct sockaddr_nl *nla,
00050                                    struct nlmsgerr *nlerr, void *arg);
00051 
00052 /** @} */
00053 
00054 /**
00055  * Callback actions
00056  * @ingroup cb
00057  */
00058 enum nl_cb_action {
00059         /** Proceed with wathever would come next */
00060         NL_OK,
00061         /** Skip this message */
00062         NL_SKIP,
00063         /** Stop parsing altogether and discard remaining messages */
00064         NL_STOP,
00065 };
00066 
00067 /* backwards compatibility */
00068 #define NL_PROCEED NL_OK
00069 #define NL_EXIT NL_STOP
00070 
00071 /**
00072  * Callback kinds
00073  * @ingroup cb
00074  */
00075 enum nl_cb_kind {
00076         /** Default handlers (quiet) */
00077         NL_CB_DEFAULT,
00078         /** Verbose default handlers (error messages printed) */
00079         NL_CB_VERBOSE,
00080         /** Debug handlers for debugging */
00081         NL_CB_DEBUG,
00082         /** Customized handler specified by the user */
00083         NL_CB_CUSTOM,
00084         __NL_CB_KIND_MAX,
00085 };
00086 
00087 #define NL_CB_KIND_MAX (__NL_CB_KIND_MAX - 1)
00088 
00089 /**
00090  * Callback types
00091  * @ingroup cb
00092  */
00093 enum nl_cb_type {
00094         /** Message is valid */
00095         NL_CB_VALID,
00096         /** Last message in a series of multi part messages received */
00097         NL_CB_FINISH,
00098         /** Report received that data was lost */
00099         NL_CB_OVERRUN,
00100         /** Message wants to be skipped */
00101         NL_CB_SKIPPED,
00102         /** Message is an acknowledge */
00103         NL_CB_ACK,
00104         /** Called for every message received */
00105         NL_CB_MSG_IN,
00106         /** Called for every message sent out except for nl_sendto() */
00107         NL_CB_MSG_OUT,
00108         /** Message is malformed and invalid */
00109         NL_CB_INVALID,
00110         /** Called instead of internal sequence number checking */
00111         NL_CB_SEQ_CHECK,
00112         /** Sending of an acknowledge message has been requested */
00113         NL_CB_SEND_ACK,
00114         __NL_CB_TYPE_MAX,
00115 };
00116 
00117 #define NL_CB_TYPE_MAX (__NL_CB_TYPE_MAX - 1)
00118 
00119 extern struct nl_cb *   nl_cb_alloc(enum nl_cb_kind);
00120 extern struct nl_cb *   nl_cb_clone(struct nl_cb *);
00121 extern struct nl_cb *   nl_cb_get(struct nl_cb *);
00122 extern void             nl_cb_put(struct nl_cb *);
00123 
00124 extern int  nl_cb_set(struct nl_cb *, enum nl_cb_type, enum nl_cb_kind,
00125                       nl_recvmsg_msg_cb_t, void *);
00126 extern int  nl_cb_set_all(struct nl_cb *, enum nl_cb_kind,
00127                           nl_recvmsg_msg_cb_t, void *);
00128 extern int  nl_cb_err(struct nl_cb *, enum nl_cb_kind, nl_recvmsg_err_cb_t,
00129                       void *);
00130 
00131 extern void nl_cb_overwrite_recvmsgs(struct nl_cb *,
00132                                      int (*func)(struct nl_handle *,
00133                                                  struct nl_cb *));
00134 extern void nl_cb_overwrite_recv(struct nl_cb *,
00135                                  int (*func)(struct nl_handle *,
00136                                              struct sockaddr_nl *,
00137                                              unsigned char **,
00138                                              struct ucred **));
00139 extern void nl_cb_overwrite_send(struct nl_cb *,
00140                                  int (*func)(struct nl_handle *,
00141                                              struct nl_msg *));
00142 
00143 #ifdef __cplusplus
00144 }
00145 #endif
00146 
00147 #endif