Line data Source code
1 1 : /*
2 : * Copyright (c) 2018 Linaro Limited.
3 : *
4 : * SPDX-License-Identifier: Apache-2.0
5 : */
6 :
7 : /**
8 : * @file
9 : * @brief Socket Offload Redirect API
10 : */
11 :
12 : #ifndef ZEPHYR_INCLUDE_NET_SOCKET_OFFLOAD_H_
13 : #define ZEPHYR_INCLUDE_NET_SOCKET_OFFLOAD_H_
14 :
15 : #include <zephyr/net/net_ip.h>
16 : #include <zephyr/net/socket.h>
17 :
18 : #ifdef __cplusplus
19 : extern "C" {
20 : #endif
21 :
22 : /**
23 : * @brief An offloaded Socket DNS API interface
24 : *
25 : * It is assumed that these offload functions follow the
26 : * POSIX socket API standard for arguments, return values and setting of errno.
27 : */
28 1 : struct socket_dns_offload {
29 : /** DNS getaddrinfo offloaded implementation API */
30 1 : int (*getaddrinfo)(const char *node, const char *service,
31 : const struct zsock_addrinfo *hints,
32 : struct zsock_addrinfo **res);
33 : /** DNS freeaddrinfo offloaded implementation API */
34 1 : void (*freeaddrinfo)(struct zsock_addrinfo *res);
35 : };
36 :
37 : /**
38 : * @brief Register an offloaded socket DNS API interface.
39 : *
40 : * @param ops A pointer to the offloaded socket DNS API interface.
41 : */
42 1 : void socket_offload_dns_register(const struct socket_dns_offload *ops);
43 :
44 : /**
45 : * @brief Deregister an offloaded socket DNS API interface.
46 : *
47 : * @param ops A pointer to the offloaded socket DNS API interface.
48 : *
49 : * @retval 0 On success
50 : * @retval -EINVAL Offloaded DNS API was not regsitered.
51 : */
52 1 : int socket_offload_dns_deregister(const struct socket_dns_offload *ops);
53 :
54 : /**
55 : * @brief Enable/disable DNS offloading at runtime.
56 : *
57 : * @param enable Whether to enable or disable the DNS offloading.
58 : */
59 1 : void socket_offload_dns_enable(bool enable);
60 :
61 : /**
62 : * @brief Check if DNS offloading is enabled.
63 : *
64 : * @retval true DNS offloaded API is registered and enabled.
65 : * @retval false DNS offloading is disabled.
66 : */
67 : #if defined(CONFIG_NET_SOCKETS_OFFLOAD)
68 : bool socket_offload_dns_is_enabled(void);
69 : #else
70 1 : #define socket_offload_dns_is_enabled() false
71 : #endif /* defined(CONFIG_NET_SOCKETS_OFFLOAD) */
72 :
73 :
74 : /** @cond INTERNAL_HIDDEN */
75 :
76 : int socket_offload_getaddrinfo(const char *node, const char *service,
77 : const struct zsock_addrinfo *hints,
78 : struct zsock_addrinfo **res);
79 :
80 : void socket_offload_freeaddrinfo(struct zsock_addrinfo *res);
81 :
82 : /** @endcond */
83 :
84 : #ifdef __cplusplus
85 : }
86 : #endif
87 :
88 : #endif /* ZEPHYR_INCLUDE_NET_SOCKET_OFFLOAD_H_ */
|