libnl  1.1
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 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 struct nl_cb;
26 struct nl_handle;
27 struct nl_msg;
28 
29 /**
30  * @name Callback Typedefs
31  * @{
32  */
33 
34 /**
35  * nl_recvmsgs() callback for message processing customization
36  * @ingroup cb
37  * @arg msg netlink message being processed
38  * @arg arg argument passwd on through caller
39  */
40 typedef int (*nl_recvmsg_msg_cb_t)(struct nl_msg *msg, void *arg);
41 
42 /**
43  * nl_recvmsgs() callback for error message processing customization
44  * @ingroup cb
45  * @arg nla netlink address of the peer
46  * @arg nlerr netlink error message being processed
47  * @arg arg argument passed on through caller
48  */
49 typedef int (*nl_recvmsg_err_cb_t)(struct sockaddr_nl *nla,
50  struct nlmsgerr *nlerr, void *arg);
51 
52 /** @} */
53 
54 /**
55  * Callback actions
56  * @ingroup cb
57  */
59  /** Proceed with wathever would come next */
61  /** Skip this message */
63  /** Stop parsing altogether and discard remaining messages */
65 };
66 
67 /* backwards compatibility */
68 #define NL_PROCEED NL_OK
69 #define NL_EXIT NL_STOP
70 
71 /**
72  * Callback kinds
73  * @ingroup cb
74  */
75 enum nl_cb_kind {
76  /** Default handlers (quiet) */
78  /** Verbose default handlers (error messages printed) */
80  /** Debug handlers for debugging */
82  /** Customized handler specified by the user */
84  __NL_CB_KIND_MAX,
85 };
86 
87 #define NL_CB_KIND_MAX (__NL_CB_KIND_MAX - 1)
88 
89 /**
90  * Callback types
91  * @ingroup cb
92  */
93 enum nl_cb_type {
94  /** Message is valid */
96  /** Last message in a series of multi part messages received */
98  /** Report received that data was lost */
100  /** Message wants to be skipped */
102  /** Message is an acknowledge */
104  /** Called for every message received */
106  /** Called for every message sent out except for nl_sendto() */
108  /** Message is malformed and invalid */
110  /** Called instead of internal sequence number checking */
112  /** Sending of an acknowledge message has been requested */
114  __NL_CB_TYPE_MAX,
115 };
116 
117 #define NL_CB_TYPE_MAX (__NL_CB_TYPE_MAX - 1)
118 
119 extern struct nl_cb * nl_cb_alloc(enum nl_cb_kind);
120 extern struct nl_cb * nl_cb_clone(struct nl_cb *);
121 extern struct nl_cb * nl_cb_get(struct nl_cb *);
122 extern void nl_cb_put(struct nl_cb *);
123 
124 extern int nl_cb_set(struct nl_cb *, enum nl_cb_type, enum nl_cb_kind,
125  nl_recvmsg_msg_cb_t, void *);
126 extern int nl_cb_set_all(struct nl_cb *, enum nl_cb_kind,
127  nl_recvmsg_msg_cb_t, void *);
128 extern int nl_cb_err(struct nl_cb *, enum nl_cb_kind, nl_recvmsg_err_cb_t,
129  void *);
130 
131 extern void nl_cb_overwrite_recvmsgs(struct nl_cb *,
132  int (*func)(struct nl_handle *,
133  struct nl_cb *));
134 extern void nl_cb_overwrite_recv(struct nl_cb *,
135  int (*func)(struct nl_handle *,
136  struct sockaddr_nl *,
137  unsigned char **,
138  struct ucred **));
139 extern void nl_cb_overwrite_send(struct nl_cb *,
140  int (*func)(struct nl_handle *,
141  struct nl_msg *));
142 
143 #ifdef __cplusplus
144 }
145 #endif
146 
147 #endif