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
22extern "C" {
23#endif
24
25struct nl_cb;
26struct nl_handle;
27struct nl_msg;
28struct 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 */
41typedef 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 */
50typedef 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 */
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 */
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
120extern struct nl_cb * nl_cb_alloc(enum nl_cb_kind);
121extern struct nl_cb * nl_cb_clone(struct nl_cb *);
122extern struct nl_cb * nl_cb_get(struct nl_cb *);
123extern void nl_cb_put(struct nl_cb *);
124
125extern int nl_cb_set(struct nl_cb *, enum nl_cb_type, enum nl_cb_kind,
126 nl_recvmsg_msg_cb_t, void *);
127extern int nl_cb_set_all(struct nl_cb *, enum nl_cb_kind,
128 nl_recvmsg_msg_cb_t, void *);
129extern int nl_cb_err(struct nl_cb *, enum nl_cb_kind, nl_recvmsg_err_cb_t,
130 void *);
131
132extern void nl_cb_overwrite_recvmsgs(struct nl_cb *,
133 int (*func)(struct nl_handle *,
134 struct nl_cb *));
135extern void nl_cb_overwrite_recv(struct nl_cb *,
136 int (*func)(struct nl_handle *,
137 struct sockaddr_nl *,
138 unsigned char **,
139 struct ucred **));
140extern 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
nl_cb_action
Callback actions.
Definition: handlers.h:59
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
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
nl_cb_type
Callback types.
Definition: handlers.h:94
int(* nl_recvmsg_msg_cb_t)(struct nl_msg *msg, void *arg)
nl_recvmsgs() callback for message processing customization
Definition: handlers.h:41
nl_cb_kind
Callback kinds.
Definition: handlers.h:76
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
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_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
struct nl_cb * nl_cb_clone(struct nl_cb *)
Clone an existing callback handle.
Definition: handlers.c:286
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
struct nl_cb * nl_cb_alloc(enum nl_cb_kind)
Allocate a new callback handle.
Definition: handlers.c:256
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
@ NL_STOP
Stop parsing altogether and discard remaining messages.
Definition: handlers.h:65
@ NL_OK
Proceed with wathever would come next.
Definition: handlers.h:61
@ NL_SKIP
Skip this message.
Definition: handlers.h:63
@ NL_CB_SKIPPED
Message wants to be skipped.
Definition: handlers.h:102
@ NL_CB_FINISH
Last message in a series of multi part messages received.
Definition: handlers.h:98
@ NL_CB_MSG_OUT
Called for every message sent out except for nl_sendto()
Definition: handlers.h:108
@ NL_CB_MSG_IN
Called for every message received.
Definition: handlers.h:106
@ NL_CB_OVERRUN
Report received that data was lost.
Definition: handlers.h:100
@ NL_CB_VALID
Message is valid.
Definition: handlers.h:96
@ NL_CB_ACK
Message is an acknowledge.
Definition: handlers.h:104
@ NL_CB_SEQ_CHECK
Called instead of internal sequence number checking.
Definition: handlers.h:112
@ NL_CB_SEND_ACK
Sending of an acknowledge message has been requested.
Definition: handlers.h:114
@ NL_CB_INVALID
Message is malformed and invalid.
Definition: handlers.h:110
@ NL_CB_DEFAULT
Default handlers (quiet)
Definition: handlers.h:78
@ NL_CB_CUSTOM
Customized handler specified by the user.
Definition: handlers.h:84
@ NL_CB_VERBOSE
Verbose default handlers (error messages printed)
Definition: handlers.h:80
@ NL_CB_DEBUG
Debug handlers for debugging.
Definition: handlers.h:82
Netlink error message.
Netlink socket address.
Definition: netlink-kernel.h:9