libnl 3.7.0
handlers.h
1/* SPDX-License-Identifier: LGPL-2.1-only */
2/*
3 * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
4 */
5
6#ifndef NETLINK_HANDLERS_H_
7#define NETLINK_HANDLERS_H_
8
9#include <stdio.h>
10#include <stdint.h>
11#include <sys/types.h>
12#include <netlink/netlink-compat.h>
13#include <netlink/netlink-kernel.h>
14
15#ifdef __cplusplus
16extern "C" {
17#endif
18
19struct nlmsgerr;
20struct sockaddr_nl;
21struct ucred;
22
23struct nl_cb;
24struct nl_sock;
25struct nl_msg;
26
27/**
28 * @name Callback Typedefs
29 * @{
30 */
31
32/**
33 * nl_recvmsgs() callback for message processing customization
34 * @ingroup cb
35 * @arg msg netlink message being processed
36 * @arg arg argument passed on through caller
37 */
38typedef int (*nl_recvmsg_msg_cb_t)(struct nl_msg *msg, void *arg);
39
40/**
41 * nl_recvmsgs() callback for error message processing customization
42 * @ingroup cb
43 * @arg nla netlink address of the peer
44 * @arg nlerr netlink error message being processed
45 * @arg arg argument passed on through caller
46 */
47typedef int (*nl_recvmsg_err_cb_t)(struct sockaddr_nl *nla,
48 struct nlmsgerr *nlerr, void *arg);
49
50/** @} */
51
52/**
53 * Callback actions
54 * @ingroup cb
55 */
57 /** Proceed with whatever would come next */
59 /** Skip this message */
61 /** Stop parsing altogether and discard remaining messages */
63};
64
65/**
66 * Callback kinds
67 * @ingroup cb
68 */
70 /** Default handlers (quiet) */
72 /** Verbose default handlers (error messages printed) */
74 /** Debug handlers for debugging */
76 /** Customized handler specified by the user */
78 __NL_CB_KIND_MAX,
79};
80
81#define NL_CB_KIND_MAX (__NL_CB_KIND_MAX - 1)
82
83/**
84 * Callback types
85 * @ingroup cb
86 */
88 /** Message is valid */
90 /** Last message in a series of multi part messages received */
92 /** Report received that data was lost */
94 /** Message wants to be skipped */
96 /** Message is an acknowledgement */
98 /** Called for every message received */
100 /** Called for every message sent out except for nl_sendto() */
102 /** Message is malformed and invalid */
104 /** Called instead of internal sequence number checking */
106 /** Sending of an acknowledge message has been requested */
108 /** Flag NLM_F_DUMP_INTR is set in message */
110 __NL_CB_TYPE_MAX,
111};
112
113#define NL_CB_TYPE_MAX (__NL_CB_TYPE_MAX - 1)
114
115extern struct nl_cb * nl_cb_alloc(enum nl_cb_kind);
116extern struct nl_cb * nl_cb_clone(struct nl_cb *);
117extern struct nl_cb * nl_cb_get(struct nl_cb *);
118extern void nl_cb_put(struct nl_cb *);
119
120extern int nl_cb_set(struct nl_cb *, enum nl_cb_type, enum nl_cb_kind,
121 nl_recvmsg_msg_cb_t, void *);
122extern int nl_cb_set_all(struct nl_cb *, enum nl_cb_kind,
123 nl_recvmsg_msg_cb_t, void *);
124extern int nl_cb_err(struct nl_cb *, enum nl_cb_kind, nl_recvmsg_err_cb_t,
125 void *);
126
127extern void nl_cb_overwrite_recvmsgs(struct nl_cb *,
128 int (*func)(struct nl_sock *,
129 struct nl_cb *));
130extern void nl_cb_overwrite_recv(struct nl_cb *,
131 int (*func)(struct nl_sock *,
132 struct sockaddr_nl *,
133 unsigned char **,
134 struct ucred **));
135extern void nl_cb_overwrite_send(struct nl_cb *,
136 int (*func)(struct nl_sock *,
137 struct nl_msg *));
138
139extern enum nl_cb_type nl_cb_active_type(struct nl_cb *cb);
140
141#ifdef __cplusplus
142}
143#endif
144
145#endif
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:389
nl_cb_action
Callback actions.
Definition: handlers.h:56
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:47
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:377
nl_cb_type
Callback types.
Definition: handlers.h:87
int(* nl_recvmsg_msg_cb_t)(struct nl_msg *msg, void *arg)
nl_recvmsgs() callback for message processing customization
Definition: handlers.h:38
nl_cb_kind
Callback kinds.
Definition: handlers.h:69
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:287
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:316
struct nl_cb * nl_cb_clone(struct nl_cb *)
Clone an existing callback handle.
Definition: handlers.c:224
struct nl_cb * nl_cb_alloc(enum nl_cb_kind)
Allocate a new callback handle.
Definition: handlers.c:195
enum nl_cb_type nl_cb_active_type(struct nl_cb *cb)
Obtain type of current active callback.
Definition: handlers.c:265
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:366
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:337
@ NL_STOP
Stop parsing altogether and discard remaining messages.
Definition: handlers.h:62
@ NL_OK
Proceed with whatever would come next.
Definition: handlers.h:58
@ NL_SKIP
Skip this message.
Definition: handlers.h:60
@ NL_CB_SKIPPED
Message wants to be skipped.
Definition: handlers.h:95
@ NL_CB_FINISH
Last message in a series of multi part messages received.
Definition: handlers.h:91
@ NL_CB_MSG_OUT
Called for every message sent out except for nl_sendto()
Definition: handlers.h:101
@ NL_CB_DUMP_INTR
Flag NLM_F_DUMP_INTR is set in message.
Definition: handlers.h:109
@ NL_CB_MSG_IN
Called for every message received.
Definition: handlers.h:99
@ NL_CB_OVERRUN
Report received that data was lost.
Definition: handlers.h:93
@ NL_CB_VALID
Message is valid.
Definition: handlers.h:89
@ NL_CB_ACK
Message is an acknowledgement.
Definition: handlers.h:97
@ NL_CB_SEQ_CHECK
Called instead of internal sequence number checking.
Definition: handlers.h:105
@ NL_CB_SEND_ACK
Sending of an acknowledge message has been requested.
Definition: handlers.h:107
@ NL_CB_INVALID
Message is malformed and invalid.
Definition: handlers.h:103
@ NL_CB_DEFAULT
Default handlers (quiet)
Definition: handlers.h:71
@ NL_CB_CUSTOM
Customized handler specified by the user.
Definition: handlers.h:77
@ NL_CB_VERBOSE
Verbose default handlers (error messages printed)
Definition: handlers.h:73
@ NL_CB_DEBUG
Debug handlers for debugging.
Definition: handlers.h:75