blob: e94cd348e264c187d0569ad85f92508c3add5bcd [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/*
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_sock;
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 */
59enum nl_cb_action {
60 /** Proceed with wathever would come next */
61 NL_OK,
62 /** Skip this message */
63 NL_SKIP,
64 /** Stop parsing altogether and discard remaining messages */
65 NL_STOP,
66};
67
68/**
69 * Callback kinds
70 * @ingroup cb
71 */
72enum nl_cb_kind {
73 /** Default handlers (quiet) */
74 NL_CB_DEFAULT,
75 /** Verbose default handlers (error messages printed) */
76 NL_CB_VERBOSE,
77 /** Debug handlers for debugging */
78 NL_CB_DEBUG,
79 /** Customized handler specified by the user */
80 NL_CB_CUSTOM,
81 __NL_CB_KIND_MAX,
82};
83
84#define NL_CB_KIND_MAX (__NL_CB_KIND_MAX - 1)
85
86/**
87 * Callback types
88 * @ingroup cb
89 */
90enum nl_cb_type {
91 /** Message is valid */
92 NL_CB_VALID,
93 /** Last message in a series of multi part messages received */
94 NL_CB_FINISH,
95 /** Report received that data was lost */
96 NL_CB_OVERRUN,
97 /** Message wants to be skipped */
98 NL_CB_SKIPPED,
99 /** Message is an acknowledge */
100 NL_CB_ACK,
101 /** Called for every message received */
102 NL_CB_MSG_IN,
103 /** Called for every message sent out except for nl_sendto() */
104 NL_CB_MSG_OUT,
105 /** Message is malformed and invalid */
106 NL_CB_INVALID,
107 /** Called instead of internal sequence number checking */
108 NL_CB_SEQ_CHECK,
109 /** Sending of an acknowledge message has been requested */
110 NL_CB_SEND_ACK,
111 /** Flag NLM_F_DUMP_INTR is set in message */
112 NL_CB_DUMP_INTR,
113 __NL_CB_TYPE_MAX,
114};
115
116#define NL_CB_TYPE_MAX (__NL_CB_TYPE_MAX - 1)
117
118extern struct nl_cb * nl_cb_alloc(enum nl_cb_kind);
119extern struct nl_cb * nl_cb_clone(struct nl_cb *);
120extern struct nl_cb * nl_cb_get(struct nl_cb *);
121extern void nl_cb_put(struct nl_cb *);
122
123extern int nl_cb_set(struct nl_cb *, enum nl_cb_type, enum nl_cb_kind,
124 nl_recvmsg_msg_cb_t, void *);
125extern int nl_cb_set_all(struct nl_cb *, enum nl_cb_kind,
126 nl_recvmsg_msg_cb_t, void *);
127extern int nl_cb_err(struct nl_cb *, enum nl_cb_kind, nl_recvmsg_err_cb_t,
128 void *);
129
130extern void nl_cb_overwrite_recvmsgs(struct nl_cb *,
131 int (*func)(struct nl_sock *,
132 struct nl_cb *));
133extern void nl_cb_overwrite_recv(struct nl_cb *,
134 int (*func)(struct nl_sock *,
135 struct sockaddr_nl *,
136 unsigned char **,
137 struct ucred **));
138extern void nl_cb_overwrite_send(struct nl_cb *,
139 int (*func)(struct nl_sock *,
140 struct nl_msg *));
141
142extern enum nl_cb_type nl_cb_active_type(struct nl_cb *cb);
143
144#ifdef __cplusplus
145}
146#endif
147
148#endif