2 * netlink/handlers.c default netlink message handlers
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
9 * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
12 #ifndef NETLINK_HANDLERS_H_
13 #define NETLINK_HANDLERS_H_
17 #include <sys/types.h>
18 #include <netlink/netlink-compat.h>
19 #include <netlink/netlink-kernel.h>
20 #include <netlink/types.h>
30 * @name Callback Typedefs
35 * nl_recvmsgs() callback for message processing customization
37 * @arg msg netlink message being processed
38 * @arg arg argument passwd on through caller
40 typedef int (*nl_recvmsg_msg_cb_t
)(struct nl_msg
*msg
, void *arg
);
43 * nl_recvmsgs() callback for error message processing customization
45 * @arg nla netlink address of the peer
46 * @arg nlerr netlink error message being processed
47 * @arg arg argument passed on through caller
49 typedef int (*nl_recvmsg_err_cb_t
)(struct sockaddr_nl
*nla
,
50 struct nlmsgerr
*nlerr
, void *arg
);
59 /** Proceed with wathever would come next */
61 /** Skip this message */
63 /** Stop parsing altogether and discard remaining messages */
72 /** Default handlers (quiet) */
74 /** Verbose default handlers (error messages printed) */
76 /** Debug handlers for debugging */
78 /** Customized handler specified by the user */
83 #define NL_CB_KIND_MAX (__NL_CB_KIND_MAX - 1)
90 /** Message is valid */
92 /** Last message in a series of multi part messages received */
94 /** Report received that data was lost */
96 /** Message wants to be skipped */
98 /** Message is an acknowledge */
100 /** Called for every message received */
102 /** Called for every message sent out except for nl_sendto() */
104 /** Message is malformed and invalid */
106 /** Called instead of internal sequence number checking */
108 /** Sending of an acknowledge message has been requested */
113 #define NL_CB_TYPE_MAX (__NL_CB_TYPE_MAX - 1)
117 nl_recvmsg_msg_cb_t cb_set
[NL_CB_TYPE_MAX
+1];
118 void * cb_args
[NL_CB_TYPE_MAX
+1];
120 nl_recvmsg_err_cb_t cb_err
;
123 /** May be used to replace nl_recvmsgs with your own implementation
124 * in all internal calls to nl_recvmsgs. */
125 int (*cb_recvmsgs_ow
)(struct nl_sock
*,
128 /** Overwrite internal calls to nl_recv, must return the number of
129 * octets read and allocate a buffer for the received data. */
130 int (*cb_recv_ow
)(struct nl_sock
*,
131 struct sockaddr_nl
*,
135 /** Overwrites internal calls to nl_send, must send the netlink
137 int (*cb_send_ow
)(struct nl_sock
*,
144 extern struct nl_cb
* nl_cb_alloc(enum nl_cb_kind
);
145 extern struct nl_cb
* nl_cb_clone(struct nl_cb
*);
146 extern void nl_cb_put(struct nl_cb
*);
148 extern int nl_cb_set(struct nl_cb
*, enum nl_cb_type
, enum nl_cb_kind
,
149 nl_recvmsg_msg_cb_t
, void *);
150 extern int nl_cb_err(struct nl_cb
*, enum nl_cb_kind
, nl_recvmsg_err_cb_t
,
153 static inline struct nl_cb
*nl_cb_get(struct nl_cb
*cb
)
161 * Set up a all callbacks
162 * @arg cb callback set
163 * @arg kind kind of callback
164 * @arg func callback function
165 * @arg arg argument to be passwd to callback function
167 * @return 0 on success or a negative error code
169 static inline int nl_cb_set_all(struct nl_cb
*cb
, enum nl_cb_kind kind
,
170 nl_recvmsg_msg_cb_t func
, void *arg
)
174 for (i
= 0; i
<= NL_CB_TYPE_MAX
; i
++) {
175 err
= nl_cb_set(cb
,(enum nl_cb_type
)i
, kind
, func
, arg
);
190 * Overwrite internal calls to nl_recvmsgs()
191 * @arg cb callback set
192 * @arg func replacement callback for nl_recvmsgs()
194 static inline void nl_cb_overwrite_recvmsgs(struct nl_cb
*cb
,
195 int (*func
)(struct nl_sock
*, struct nl_cb
*))
197 cb
->cb_recvmsgs_ow
= func
;
201 * Overwrite internal calls to nl_recv()
202 * @arg cb callback set
203 * @arg func replacement callback for nl_recv()
205 static inline void nl_cb_overwrite_recv(struct nl_cb
*cb
,
206 int (*func
)(struct nl_sock
*, struct sockaddr_nl
*,
207 unsigned char **, struct ucred
**))
209 cb
->cb_recv_ow
= func
;
213 * Overwrite internal calls to nl_send()
214 * @arg cb callback set
215 * @arg func replacement callback for nl_send()
217 static inline void nl_cb_overwrite_send(struct nl_cb
*cb
,
218 int (*func
)(struct nl_sock
*, struct nl_msg
*))
220 cb
->cb_send_ow
= func
;