• 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 #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
152