libnl 3.5.0

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 nlmsgerr;
26 struct sockaddr_nl;
27 struct ucred;
28
29 struct nl_cb;
30 struct nl_sock;
31 struct nl_msg;
32
33 /**
34 * @name Callback Typedefs
35 * @{
36 */
37
38 /**
39 * nl_recvmsgs() callback for message processing customization
40 * @ingroup cb
41 * @arg msg netlink message being processed
42 * @arg arg argument passwd on through caller
43 */
44 typedef int (*nl_recvmsg_msg_cb_t)(struct nl_msg *msg, void *arg);
45
46 /**
47 * nl_recvmsgs() callback for error message processing customization
48 * @ingroup cb
49 * @arg nla netlink address of the peer
50 * @arg nlerr netlink error message being processed
51 * @arg arg argument passed on through caller
52 */
53 typedef int (*nl_recvmsg_err_cb_t)(struct sockaddr_nl *nla,
54 struct nlmsgerr *nlerr, void *arg);
55
56 /** @} */
57
58 /**
59 * Callback actions
60 * @ingroup cb
61 */
62 enum nl_cb_action {
63 /** Proceed with wathever would come next */
64 NL_OK,
65 /** Skip this message */
66 NL_SKIP,
67 /** Stop parsing altogether and discard remaining messages */
68 NL_STOP,
69 };
70
71 /**
72 * Callback kinds
73 * @ingroup cb
74 */
75 enum nl_cb_kind {
76 /** Default handlers (quiet) */
77 NL_CB_DEFAULT,
78 /** Verbose default handlers (error messages printed) */
79 NL_CB_VERBOSE,
80 /** Debug handlers for debugging */
81 NL_CB_DEBUG,
82 /** Customized handler specified by the user */
83 NL_CB_CUSTOM,
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 */
95 NL_CB_VALID,
96 /** Last message in a series of multi part messages received */
97 NL_CB_FINISH,
98 /** Report received that data was lost */
99 NL_CB_OVERRUN,
100 /** Message wants to be skipped */
101 NL_CB_SKIPPED,
102 /** Message is an acknowledge */
103 NL_CB_ACK,
104 /** Called for every message received */
105 NL_CB_MSG_IN,
106 /** Called for every message sent out except for nl_sendto() */
107 NL_CB_MSG_OUT,
108 /** Message is malformed and invalid */
109 NL_CB_INVALID,
110 /** Called instead of internal sequence number checking */
111 NL_CB_SEQ_CHECK,
112 /** Sending of an acknowledge message has been requested */
113 NL_CB_SEND_ACK,
114 /** Flag NLM_F_DUMP_INTR is set in message */
115 NL_CB_DUMP_INTR,
116 __NL_CB_TYPE_MAX,
117 };
118
119 #define NL_CB_TYPE_MAX (__NL_CB_TYPE_MAX - 1)
120
121 extern struct nl_cb * nl_cb_alloc(enum nl_cb_kind);
122 extern struct nl_cb * nl_cb_clone(struct nl_cb *);
123 extern struct nl_cb * nl_cb_get(struct nl_cb *);
124 extern void nl_cb_put(struct nl_cb *);
125
126 extern int nl_cb_set(struct nl_cb *, enum nl_cb_type, enum nl_cb_kind,
127 nl_recvmsg_msg_cb_t, void *);
128 extern int nl_cb_set_all(struct nl_cb *, enum nl_cb_kind,
129 nl_recvmsg_msg_cb_t, void *);
130 extern int nl_cb_err(struct nl_cb *, enum nl_cb_kind, nl_recvmsg_err_cb_t,
131 void *);
132
133 extern void nl_cb_overwrite_recvmsgs(struct nl_cb *,
134 int (*func)(struct nl_sock *,
135 struct nl_cb *));
136 extern void nl_cb_overwrite_recv(struct nl_cb *,
137 int (*func)(struct nl_sock *,
138 struct sockaddr_nl *,
139 unsigned char **,
140 struct ucred **));
141 extern void nl_cb_overwrite_send(struct nl_cb *,
142 int (*func)(struct nl_sock *,
143 struct nl_msg *));
144
145 extern enum nl_cb_type nl_cb_active_type(struct nl_cb *cb);
146
147 #ifdef __cplusplus
148 }
149 #endif
150
151 #endif
NL_CB_OVERRUN
Report received that data was lost.
Definition: handlers.h:99
NL_CB_MSG_OUT
Called for every message sent out except for nl_sendto()
Definition: handlers.h:107
NL_CB_ACK
Message is an acknowledge.
Definition: handlers.h:103
nl_cb_set_all
int nl_cb_set_all(struct nl_cb *, enum nl_cb_kind, nl_recvmsg_msg_cb_t, void *)
Set up a all callbacks.
Definition: handlers.c:323
NL_CB_SEND_ACK
Sending of an acknowledge message has been requested.
Definition: handlers.h:113
NL_CB_CUSTOM
Customized handler specified by the user.
Definition: handlers.h:83
nl_cb_overwrite_send
void nl_cb_overwrite_send(struct nl_cb *, int(*func)(struct nl_sock *, struct nl_msg *))
Overwrite internal calls to nl_send()
Definition: handlers.c:396
NL_CB_SKIPPED
Message wants to be skipped.
Definition: handlers.h:101
NL_STOP
Stop parsing altogether and discard remaining messages.
Definition: handlers.h:68
NL_CB_MSG_IN
Called for every message received.
Definition: handlers.h:105
nl_cb_kind
nl_cb_kind
Callback kinds.
Definition: handlers.h:75
nl_cb_overwrite_recvmsgs
void nl_cb_overwrite_recvmsgs(struct nl_cb *, int(*func)(struct nl_sock *, struct nl_cb *))
Overwrite internal calls to nl_recvmsgs()
Definition: handlers.c:373
nl_cb_clone
struct nl_cb * nl_cb_clone(struct nl_cb *)
Clone an existing callback handle.
Definition: handlers.c:231
nl_cb_set
int nl_cb_set(struct nl_cb *, enum nl_cb_type, enum nl_cb_kind, nl_recvmsg_msg_cb_t, void *)
Set up a callback.
Definition: handlers.c:294
NL_CB_INVALID
Message is malformed and invalid.
Definition: handlers.h:109
NL_CB_DUMP_INTR
Flag NLM_F_DUMP_INTR is set in message.
Definition: handlers.h:115
NL_SKIP
Skip this message.
Definition: handlers.h:66
NL_CB_FINISH
Last message in a series of multi part messages received.
Definition: handlers.h:97
nl_recvmsg_err_cb_t
int(* nl_recvmsg_err_cb_t)(struct sockaddr_nl *nla, struct nlmsgerr *nlerr, void *arg)
nl_recvmsgs() callback for error message processing customization
Definition: handlers.h:53
NL_CB_DEBUG
Debug handlers for debugging.
Definition: handlers.h:81
nl_recvmsg_msg_cb_t
int(* nl_recvmsg_msg_cb_t)(struct nl_msg *msg, void *arg)
nl_recvmsgs() callback for message processing customization
Definition: handlers.h:44
NL_CB_VALID
Message is valid.
Definition: handlers.h:95
NL_CB_SEQ_CHECK
Called instead of internal sequence number checking.
Definition: handlers.h:111
NL_OK
Proceed with wathever would come next.
Definition: handlers.h:64
nl_cb_type
nl_cb_type
Callback types.
Definition: handlers.h:93
nl_cb_alloc
struct nl_cb * nl_cb_alloc(enum nl_cb_kind)
Allocate a new callback handle.
Definition: handlers.c:202
nl_cb_overwrite_recv
void nl_cb_overwrite_recv(struct nl_cb *, int(*func)(struct nl_sock *, struct sockaddr_nl *, unsigned char **, struct ucred **))
Overwrite internal calls to nl_recv()
Definition: handlers.c:384
nl_cb_action
nl_cb_action
Callback actions.
Definition: handlers.h:62
nl_cb_active_type
enum nl_cb_type nl_cb_active_type(struct nl_cb *cb)
Obtain type of current active callback.
Definition: handlers.c:272
NL_CB_DEFAULT
Default handlers (quiet)
Definition: handlers.h:77
nl_cb_err
int nl_cb_err(struct nl_cb *, enum nl_cb_kind, nl_recvmsg_err_cb_t, void *)
Set up an error callback.
Definition: handlers.c:344
NL_CB_VERBOSE
Verbose default handlers (error messages printed)
Definition: handlers.h:79