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