libnl  3.3.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  */
63  /** Proceed with wathever would come next */
65  /** Skip this message */
67  /** Stop parsing altogether and discard remaining messages */
69 };
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  /** Flag NLM_F_DUMP_INTR is set in message */
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
Report received that data was lost.
Definition: handlers.h:99
Called for every message sent out except for nl_sendto()
Definition: handlers.h:107
Message is an acknowledge.
Definition: handlers.h:103
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:322
Sending of an acknowledge message has been requested.
Definition: handlers.h:113
Customized handler specified by the user.
Definition: handlers.h:83
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:395
Message wants to be skipped.
Definition: handlers.h:101
Stop parsing altogether and discard remaining messages.
Definition: handlers.h:68
Called for every message received.
Definition: handlers.h:105
nl_cb_kind
Callback kinds.
Definition: handlers.h:75
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:372
struct nl_cb * nl_cb_clone(struct nl_cb *)
Clone an existing callback handle.
Definition: handlers.c:230
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:293
Message is malformed and invalid.
Definition: handlers.h:109
Flag NLM_F_DUMP_INTR is set in message.
Definition: handlers.h:115
Skip this message.
Definition: handlers.h:66
Last message in a series of multi part messages received.
Definition: handlers.h:97
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
Debug handlers for debugging.
Definition: handlers.h:81
int(* nl_recvmsg_msg_cb_t)(struct nl_msg *msg, void *arg)
nl_recvmsgs() callback for message processing customization
Definition: handlers.h:44
Message is valid.
Definition: handlers.h:95
Called instead of internal sequence number checking.
Definition: handlers.h:111
Proceed with wathever would come next.
Definition: handlers.h:64
nl_cb_type
Callback types.
Definition: handlers.h:93
struct nl_cb * nl_cb_alloc(enum nl_cb_kind)
Allocate a new callback handle.
Definition: handlers.c:201
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:383
nl_cb_action
Callback actions.
Definition: handlers.h:62
enum nl_cb_type nl_cb_active_type(struct nl_cb *cb)
Obtain type of current active callback.
Definition: handlers.c:271
Default handlers (quiet)
Definition: handlers.h:77
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:343
Verbose default handlers (error messages printed)
Definition: handlers.h:79