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