1 /* SPDX-License-Identifier: LGPL-2.1-only */
2 /*
3 * Copyright (c) 2014 Thomas Graf <[email protected]>
4 */
5
6 #ifndef __LIB_NL_CORE_H__
7 #define __LIB_NL_CORE_H__
8
9 struct nl_cb
10 {
11 nl_recvmsg_msg_cb_t cb_set[NL_CB_TYPE_MAX+1];
12 void * cb_args[NL_CB_TYPE_MAX+1];
13
14 nl_recvmsg_err_cb_t cb_err;
15 void * cb_err_arg;
16
17 /** May be used to replace nl_recvmsgs with your own implementation
18 * in all internal calls to nl_recvmsgs. */
19 int (*cb_recvmsgs_ow)(struct nl_sock *,
20 struct nl_cb *);
21
22 /** Overwrite internal calls to nl_recv, must return the number of
23 * octets read and allocate a buffer for the received data. */
24 int (*cb_recv_ow)(struct nl_sock *,
25 struct sockaddr_nl *,
26 unsigned char **,
27 struct ucred **);
28
29 /** Overwrites internal calls to nl_send, must send the netlink
30 * message. */
31 int (*cb_send_ow)(struct nl_sock *,
32 struct nl_msg *);
33
34 int cb_refcnt;
35 /** indicates the callback that is currently active */
36 enum nl_cb_type cb_active;
37 };
38
nl_cb_call(struct nl_cb * cb,enum nl_cb_type type,struct nl_msg * msg)39 static inline int nl_cb_call(struct nl_cb *cb, enum nl_cb_type type, struct nl_msg *msg)
40 {
41 int ret;
42
43 cb->cb_active = type;
44 ret = cb->cb_set[type](msg, cb->cb_args[type]);
45 cb->cb_active = __NL_CB_TYPE_MAX;
46 return ret;
47 }
48
49 int _nl_socket_is_local_port_unspecified (struct nl_sock *sk);
50 uint32_t _nl_socket_set_local_port_no_release(struct nl_sock *sk, int generate_other);
51
52 void _nl_socket_used_ports_release_all(const uint32_t *used_ports);
53 void _nl_socket_used_ports_set(uint32_t *used_ports, uint32_t port);
54
55 extern int nl_cache_parse(struct nl_cache_ops *, struct sockaddr_nl *,
56 struct nlmsghdr *, struct nl_parser_param *);
57
58 extern void dump_from_ops(struct nl_object *, struct nl_dump_params *);
59
60 #endif /* __LIB_NL_CORE_H__ */
61