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