libnl: /data/src/libnl/include/netlink/handlers.h Source File

libnl 3.12.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 */
38 typedef 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 */
47 typedef 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 */
56 enum nl_cb_action {
57 /** Proceed with whatever would come next */
58 NL_OK,
59 /** Skip this message */
60 NL_SKIP,
61 /** Stop parsing altogether and discard remaining messages */
62 NL_STOP,
63};
64
65/**
66 * Callback kinds
67 * @ingroup cb
68 */
69 enum nl_cb_kind {
70 /** Default handlers (quiet) */
71 NL_CB_DEFAULT,
72 /** Verbose default handlers (error messages printed) */
73 NL_CB_VERBOSE,
74 /** Debug handlers for debugging */
75 NL_CB_DEBUG,
76 /** Customized handler specified by the user */
77 NL_CB_CUSTOM,
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 */
87 enum nl_cb_type {
88 /** Message is valid */
89 NL_CB_VALID,
90 /** Last message in a series of multi part messages received */
91 NL_CB_FINISH,
92 /** Report received that data was lost */
93 NL_CB_OVERRUN,
94 /** Message wants to be skipped */
95 NL_CB_SKIPPED,
96 /** Message is an acknowledgement */
97 NL_CB_ACK,
98 /** Called for every message received */
99 NL_CB_MSG_IN,
100 /** Called for every message sent out except for nl_sendto() */
101 NL_CB_MSG_OUT,
102 /** Message is malformed and invalid */
103 NL_CB_INVALID,
104 /** Called instead of internal sequence number checking */
105 NL_CB_SEQ_CHECK,
106 /** Sending of an acknowledge message has been requested */
107 NL_CB_SEND_ACK,
108 /** Flag NLM_F_DUMP_INTR is set in message */
109 NL_CB_DUMP_INTR,
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
nl_cb_overwrite_send
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:392
nl_cb_action
nl_cb_action
Callback actions.
Definition handlers.h:56
nl_recvmsg_err_cb_t
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
nl_cb_overwrite_recv
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:380
nl_cb_type
nl_cb_type
Callback types.
Definition handlers.h:87
nl_recvmsg_msg_cb_t
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
nl_cb_kind
Callback kinds.
Definition handlers.h:69
nl_cb_set
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:290
nl_cb_set_all
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:319
nl_cb_clone
struct nl_cb * nl_cb_clone(struct nl_cb *)
Clone an existing callback handle.
Definition handlers.c:227
nl_cb_alloc
struct nl_cb * nl_cb_alloc(enum nl_cb_kind)
Allocate a new callback handle.
Definition handlers.c:198
nl_cb_active_type
enum nl_cb_type nl_cb_active_type(struct nl_cb *cb)
Obtain type of current active callback.
Definition handlers.c:268
nl_cb_overwrite_recvmsgs
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:369
nl_cb_err
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:340
NL_STOP
@ NL_STOP
Stop parsing altogether and discard remaining messages.
Definition handlers.h:62
NL_OK
@ NL_OK
Proceed with whatever would come next.
Definition handlers.h:58
NL_SKIP
@ NL_SKIP
Skip this message.
Definition handlers.h:60
NL_CB_SKIPPED
@ NL_CB_SKIPPED
Message wants to be skipped.
Definition handlers.h:95
NL_CB_FINISH
@ NL_CB_FINISH
Last message in a series of multi part messages received.
Definition handlers.h:91
NL_CB_MSG_OUT
@ NL_CB_MSG_OUT
Called for every message sent out except for nl_sendto()
Definition handlers.h:101
NL_CB_DUMP_INTR
@ NL_CB_DUMP_INTR
Flag NLM_F_DUMP_INTR is set in message.
Definition handlers.h:109
NL_CB_MSG_IN
@ NL_CB_MSG_IN
Called for every message received.
Definition handlers.h:99
NL_CB_OVERRUN
@ NL_CB_OVERRUN
Report received that data was lost.
Definition handlers.h:93
NL_CB_VALID
@ NL_CB_VALID
Message is valid.
Definition handlers.h:89
NL_CB_ACK
@ NL_CB_ACK
Message is an acknowledgement.
Definition handlers.h:97
NL_CB_SEQ_CHECK
@ NL_CB_SEQ_CHECK
Called instead of internal sequence number checking.
Definition handlers.h:105
NL_CB_SEND_ACK
@ NL_CB_SEND_ACK
Sending of an acknowledge message has been requested.
Definition handlers.h:107
NL_CB_INVALID
@ NL_CB_INVALID
Message is malformed and invalid.
Definition handlers.h:103
NL_CB_DEFAULT
@ NL_CB_DEFAULT
Default handlers (quiet)
Definition handlers.h:71
NL_CB_CUSTOM
@ NL_CB_CUSTOM
Customized handler specified by the user.
Definition handlers.h:77
NL_CB_VERBOSE
@ NL_CB_VERBOSE
Verbose default handlers (error messages printed)
Definition handlers.h:73
NL_CB_DEBUG
@ NL_CB_DEBUG
Debug handlers for debugging.
Definition handlers.h:75
nl_cb
Definition nl-core.h:10