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