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/socket.h>
18 #include <sys/types.h>
19 #include <netlink/netlink-compat.h>
20 #include <netlink/netlink-kernel.h>
21 #include <netlink/types.h>
31 * @name Callback Typedefs
36 * nl_recvmsgs() callback for message processing customization
38 * @arg msg netlink message being processed
39 * @arg arg argument passwd on through caller
41 typedef int (*nl_recvmsg_msg_cb_t
)(struct nl_msg
*msg
, void *arg
);
44 * nl_recvmsgs() callback for error message processing customization
46 * @arg nla netlink address of the peer
47 * @arg nlerr netlink error message being processed
48 * @arg arg argument passed on through caller
50 typedef int (*nl_recvmsg_err_cb_t
)(struct sockaddr_nl
*nla
,
51 struct nlmsgerr
*nlerr
, void *arg
);
60 /** Proceed with wathever would come next */
62 /** Skip this message */
64 /** Stop parsing altogether and discard remaining messages */
73 /** Default handlers (quiet) */
75 /** Verbose default handlers (error messages printed) */
77 /** Debug handlers for debugging */
79 /** Customized handler specified by the user */
84 #define NL_CB_KIND_MAX (__NL_CB_KIND_MAX - 1)
91 /** Message is valid */
93 /** Last message in a series of multi part messages received */
95 /** Report received that data was lost */
97 /** Message wants to be skipped */
99 /** Message is an acknowledge */
101 /** Called for every message received */
103 /** Called for every message sent out except for nl_sendto() */
105 /** Message is malformed and invalid */
107 /** Called instead of internal sequence number checking */
109 /** Sending of an acknowledge message has been requested */
114 #define NL_CB_TYPE_MAX (__NL_CB_TYPE_MAX - 1)
118 nl_recvmsg_msg_cb_t cb_set
[NL_CB_TYPE_MAX
+1];
119 void * cb_args
[NL_CB_TYPE_MAX
+1];
121 nl_recvmsg_err_cb_t cb_err
;
124 /** May be used to replace nl_recvmsgs with your own implementation
125 * in all internal calls to nl_recvmsgs. */
126 int (*cb_recvmsgs_ow
)(struct nl_sock
*,
129 /** Overwrite internal calls to nl_recv, must return the number of
130 * octets read and allocate a buffer for the received data. */
131 int (*cb_recv_ow
)(struct nl_sock
*,
132 struct sockaddr_nl
*,
136 /** Overwrites internal calls to nl_send, must send the netlink
138 int (*cb_send_ow
)(struct nl_sock
*,
145 extern struct nl_cb
* nl_cb_alloc(enum nl_cb_kind
);
146 extern struct nl_cb
* nl_cb_clone(struct nl_cb
*);
147 extern void nl_cb_put(struct nl_cb
*);
149 extern int nl_cb_set(struct nl_cb
*, enum nl_cb_type
, enum nl_cb_kind
,
150 nl_recvmsg_msg_cb_t
, void *);
151 extern int nl_cb_err(struct nl_cb
*, enum nl_cb_kind
, nl_recvmsg_err_cb_t
,
154 static inline struct nl_cb
*nl_cb_get(struct nl_cb
*cb
)
162 * Set up a all callbacks
163 * @arg cb callback set
164 * @arg kind kind of callback
165 * @arg func callback function
166 * @arg arg argument to be passwd to callback function
168 * @return 0 on success or a negative error code
170 static inline int nl_cb_set_all(struct nl_cb
*cb
, enum nl_cb_kind kind
,
171 nl_recvmsg_msg_cb_t func
, void *arg
)
175 for (i
= 0; i
<= NL_CB_TYPE_MAX
; i
++) {
176 err
= nl_cb_set(cb
,(enum nl_cb_type
)i
, kind
, func
, arg
);
191 * Overwrite internal calls to nl_recvmsgs()
192 * @arg cb callback set
193 * @arg func replacement callback for nl_recvmsgs()
195 static inline void nl_cb_overwrite_recvmsgs(struct nl_cb
*cb
,
196 int (*func
)(struct nl_sock
*, struct nl_cb
*))
198 cb
->cb_recvmsgs_ow
= func
;
202 * Overwrite internal calls to nl_recv()
203 * @arg cb callback set
204 * @arg func replacement callback for nl_recv()
206 static inline void nl_cb_overwrite_recv(struct nl_cb
*cb
,
207 int (*func
)(struct nl_sock
*, struct sockaddr_nl
*,
208 unsigned char **, struct ucred
**))
210 cb
->cb_recv_ow
= func
;
214 * Overwrite internal calls to nl_send()
215 * @arg cb callback set
216 * @arg func replacement callback for nl_send()
218 static inline void nl_cb_overwrite_send(struct nl_cb
*cb
,
219 int (*func
)(struct nl_sock
*, struct nl_msg
*))
221 cb
->cb_send_ow
= func
;