/src/coturn/src/ns_turn_defs.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * SPDX-License-Identifier: BSD-3-Clause |
3 | | * |
4 | | * https://opensource.org/license/bsd-3-clause |
5 | | * |
6 | | * Copyright (C) 2011, 2012, 2013 Citrix Systems |
7 | | * |
8 | | * All rights reserved. |
9 | | * |
10 | | * Redistribution and use in source and binary forms, with or without |
11 | | * modification, are permitted provided that the following conditions |
12 | | * are met: |
13 | | * 1. Redistributions of source code must retain the above copyright |
14 | | * notice, this list of conditions and the following disclaimer. |
15 | | * 2. Redistributions in binary form must reproduce the above copyright |
16 | | * notice, this list of conditions and the following disclaimer in the |
17 | | * documentation and/or other materials provided with the distribution. |
18 | | * 3. Neither the name of the project nor the names of its contributors |
19 | | * may be used to endorse or promote products derived from this software |
20 | | * without specific prior written permission. |
21 | | * |
22 | | * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND |
23 | | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
24 | | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
25 | | * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE |
26 | | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
27 | | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
28 | | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
29 | | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
30 | | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
31 | | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
32 | | * SUCH DAMAGE. |
33 | | */ |
34 | | |
35 | | #ifndef __IOADEFS__ |
36 | | #define __IOADEFS__ |
37 | | |
38 | | #define TURN_SERVER_VERSION "4.7.0" |
39 | | #define TURN_SERVER_VERSION_NAME "Gorst" |
40 | | #ifndef TURN_SERVER_BUILD_INFO |
41 | | #define TURN_SERVER_BUILD_INFO "" |
42 | | #endif |
43 | | #define TURN_SOFTWARE "Coturn-" TURN_SERVER_VERSION " '" TURN_SERVER_VERSION_NAME "'" TURN_SERVER_BUILD_INFO |
44 | | |
45 | | #if (defined(__unix__) || defined(unix)) && !defined(USG) |
46 | | #include <sys/param.h> |
47 | | #endif |
48 | | |
49 | | #if defined(__APPLE__) |
50 | | #define __APPLE_USE_RFC_3542 |
51 | | #endif |
52 | | |
53 | | #if defined(WINDOWS) |
54 | | #include <process.h> |
55 | | #include <ws2tcpip.h> |
56 | | #else |
57 | | #include <arpa/inet.h> // IWYU pragma: export |
58 | | #include <net/if.h> // IWYU pragma: export |
59 | | #include <netinet/in.h> // IWYU pragma: export |
60 | | #include <netinet/tcp.h> // IWYU pragma: export |
61 | | #include <strings.h> |
62 | | #include <sys/socket.h> // IWYU pragma: export |
63 | | #include <unistd.h> // IWYU pragma: export |
64 | | #endif |
65 | | |
66 | | #include <ctype.h> |
67 | | #include <errno.h> |
68 | | #include <inttypes.h> |
69 | | #include <stdarg.h> |
70 | | #include <stddef.h> // IWYU pragma: export |
71 | | #include <stdint.h> // IWYU pragma: export |
72 | | #include <stdio.h> |
73 | | #include <stdlib.h> |
74 | | #include <string.h> |
75 | | #include <sys/types.h> |
76 | | #include <time.h> |
77 | | |
78 | | #ifdef __cplusplus |
79 | | extern "C" { |
80 | | #endif |
81 | | |
82 | 15.5k | #define nswap16(s) ntohs(s) |
83 | 807 | #define nswap32(ul) ntohl(ul) |
84 | 0 | #define nswap64(ull) ioa_ntoh64(ull) |
85 | | |
86 | 0 | static inline uint64_t _ioa_ntoh64(uint64_t v) { |
87 | 0 | #if BYTE_ORDER == LITTLE_ENDIAN |
88 | 0 | uint8_t *src = (uint8_t *)&v; |
89 | 0 | uint8_t *dst = src + 7; |
90 | 0 | while (src < dst) { |
91 | 0 | uint8_t vdst = *dst; |
92 | 0 | *(dst--) = *src; |
93 | 0 | *(src++) = vdst; |
94 | 0 | } |
95 | | #elif BYTE_ORDER == BIG_ENDIAN |
96 | | /* OK */ |
97 | | #else |
98 | | #error WRONG BYTE_ORDER SETTING |
99 | | #endif |
100 | 0 | return v; |
101 | 0 | } Unexecuted instantiation: FuzzStunClient.c:_ioa_ntoh64 Unexecuted instantiation: stun_buffer.c:_ioa_ntoh64 Unexecuted instantiation: ns_turn_msg.c:_ioa_ntoh64 Unexecuted instantiation: ns_turn_ioaddr.c:_ioa_ntoh64 Unexecuted instantiation: ns_turn_msg_addr.c:_ioa_ntoh64 Unexecuted instantiation: FuzzStun.c:_ioa_ntoh64 |
102 | | |
103 | | /* TTL */ |
104 | | #define TTL_IGNORE ((int)(-1)) |
105 | | #define TTL_DEFAULT (64) |
106 | | |
107 | | /* TOS */ |
108 | | #define TOS_IGNORE ((int)(-1)) |
109 | | #define TOS_DEFAULT (0) |
110 | | |
111 | 0 | #define ioa_ntoh64 _ioa_ntoh64 |
112 | | #define ioa_hton64 _ioa_ntoh64 |
113 | | |
114 | | #if defined(WINDOWS) |
115 | | static inline int socket_errno(void) { return WSAGetLastError(); } |
116 | | static inline int socket_enomem(void) { return socket_errno() == WSA_NOT_ENOUGH_MEMORY; } |
117 | | static inline int socket_eintr(void) { return socket_errno() == WSAEINTR; } |
118 | | static inline int socket_ebadf(void) { return socket_errno() == WSAEBADF; } |
119 | | static inline int socket_eacces(void) { return socket_errno() == WSAEACCES; } |
120 | | static inline int socket_enobufs(void) { return socket_errno() == WSAENOBUFS; } |
121 | | static inline int socket_eagain(void) { return socket_errno() == WSATRY_AGAIN; } |
122 | | static inline int socket_ewouldblock(void) { return socket_errno() == WSAEWOULDBLOCK; } |
123 | | static inline int socket_einprogress(void) { return socket_errno() == WSAEINPROGRESS; } |
124 | | static inline int socket_econnreset(void) { return socket_errno() == WSAECONNRESET; } |
125 | | static inline int socket_econnrefused(void) { return socket_errno() == WSAECONNREFUSED; } |
126 | | static inline int socket_ehostdown(void) { return socket_errno() == WSAEHOSTDOWN; } |
127 | | static inline int socket_emsgsize(void) { return socket_errno() == WSAEMSGSIZE; } |
128 | | #else |
129 | 0 | static inline int socket_errno(void) { return errno; } Unexecuted instantiation: FuzzStunClient.c:socket_errno Unexecuted instantiation: stun_buffer.c:socket_errno Unexecuted instantiation: ns_turn_msg.c:socket_errno Unexecuted instantiation: ns_turn_ioaddr.c:socket_errno Unexecuted instantiation: ns_turn_msg_addr.c:socket_errno Unexecuted instantiation: FuzzStun.c:socket_errno |
130 | 0 | static inline int socket_eperm(void) { return socket_errno() == EPERM; } Unexecuted instantiation: FuzzStunClient.c:socket_eperm Unexecuted instantiation: stun_buffer.c:socket_eperm Unexecuted instantiation: ns_turn_msg.c:socket_eperm Unexecuted instantiation: ns_turn_ioaddr.c:socket_eperm Unexecuted instantiation: ns_turn_msg_addr.c:socket_eperm Unexecuted instantiation: FuzzStun.c:socket_eperm |
131 | 0 | static inline int socket_enomem(void) { return socket_errno() == ENOMEM; } Unexecuted instantiation: FuzzStunClient.c:socket_enomem Unexecuted instantiation: stun_buffer.c:socket_enomem Unexecuted instantiation: ns_turn_msg.c:socket_enomem Unexecuted instantiation: ns_turn_ioaddr.c:socket_enomem Unexecuted instantiation: ns_turn_msg_addr.c:socket_enomem Unexecuted instantiation: FuzzStun.c:socket_enomem |
132 | 0 | static inline int socket_eintr(void) { return socket_errno() == EINTR; } Unexecuted instantiation: FuzzStunClient.c:socket_eintr Unexecuted instantiation: stun_buffer.c:socket_eintr Unexecuted instantiation: ns_turn_msg.c:socket_eintr Unexecuted instantiation: ns_turn_ioaddr.c:socket_eintr Unexecuted instantiation: ns_turn_msg_addr.c:socket_eintr Unexecuted instantiation: FuzzStun.c:socket_eintr |
133 | 0 | static inline int socket_ebadf(void) { return socket_errno() == EBADF; } Unexecuted instantiation: FuzzStunClient.c:socket_ebadf Unexecuted instantiation: stun_buffer.c:socket_ebadf Unexecuted instantiation: ns_turn_msg.c:socket_ebadf Unexecuted instantiation: ns_turn_ioaddr.c:socket_ebadf Unexecuted instantiation: ns_turn_msg_addr.c:socket_ebadf Unexecuted instantiation: FuzzStun.c:socket_ebadf |
134 | 0 | static inline int socket_eacces(void) { return socket_errno() == EACCES; } Unexecuted instantiation: FuzzStunClient.c:socket_eacces Unexecuted instantiation: stun_buffer.c:socket_eacces Unexecuted instantiation: ns_turn_msg.c:socket_eacces Unexecuted instantiation: ns_turn_ioaddr.c:socket_eacces Unexecuted instantiation: ns_turn_msg_addr.c:socket_eacces Unexecuted instantiation: FuzzStun.c:socket_eacces |
135 | 0 | static inline int socket_enobufs(void) { return socket_errno() == ENOBUFS; } Unexecuted instantiation: FuzzStunClient.c:socket_enobufs Unexecuted instantiation: stun_buffer.c:socket_enobufs Unexecuted instantiation: ns_turn_msg.c:socket_enobufs Unexecuted instantiation: ns_turn_ioaddr.c:socket_enobufs Unexecuted instantiation: ns_turn_msg_addr.c:socket_enobufs Unexecuted instantiation: FuzzStun.c:socket_enobufs |
136 | 0 | static inline int socket_eagain(void) { return socket_errno() == EAGAIN; } Unexecuted instantiation: FuzzStunClient.c:socket_eagain Unexecuted instantiation: stun_buffer.c:socket_eagain Unexecuted instantiation: ns_turn_msg.c:socket_eagain Unexecuted instantiation: ns_turn_ioaddr.c:socket_eagain Unexecuted instantiation: ns_turn_msg_addr.c:socket_eagain Unexecuted instantiation: FuzzStun.c:socket_eagain |
137 | | #if defined(EWOULDBLOCK) |
138 | 0 | static inline int socket_ewouldblock(void) { return socket_errno() == EWOULDBLOCK; } Unexecuted instantiation: FuzzStunClient.c:socket_ewouldblock Unexecuted instantiation: stun_buffer.c:socket_ewouldblock Unexecuted instantiation: ns_turn_msg.c:socket_ewouldblock Unexecuted instantiation: ns_turn_ioaddr.c:socket_ewouldblock Unexecuted instantiation: ns_turn_msg_addr.c:socket_ewouldblock Unexecuted instantiation: FuzzStun.c:socket_ewouldblock |
139 | | #else |
140 | | static inline int socket_ewouldblock(void) { return socket_errno() == EAGAIN; } |
141 | | #endif |
142 | 0 | static inline int socket_einprogress(void) { return socket_errno() == EINPROGRESS; } Unexecuted instantiation: FuzzStunClient.c:socket_einprogress Unexecuted instantiation: stun_buffer.c:socket_einprogress Unexecuted instantiation: ns_turn_msg.c:socket_einprogress Unexecuted instantiation: ns_turn_ioaddr.c:socket_einprogress Unexecuted instantiation: ns_turn_msg_addr.c:socket_einprogress Unexecuted instantiation: FuzzStun.c:socket_einprogress |
143 | 0 | static inline int socket_econnreset(void) { return socket_errno() == ECONNRESET; } Unexecuted instantiation: FuzzStunClient.c:socket_econnreset Unexecuted instantiation: stun_buffer.c:socket_econnreset Unexecuted instantiation: ns_turn_msg.c:socket_econnreset Unexecuted instantiation: ns_turn_ioaddr.c:socket_econnreset Unexecuted instantiation: ns_turn_msg_addr.c:socket_econnreset Unexecuted instantiation: FuzzStun.c:socket_econnreset |
144 | 0 | static inline int socket_econnrefused(void) { return socket_errno() == ECONNREFUSED; } Unexecuted instantiation: FuzzStunClient.c:socket_econnrefused Unexecuted instantiation: stun_buffer.c:socket_econnrefused Unexecuted instantiation: ns_turn_msg.c:socket_econnrefused Unexecuted instantiation: ns_turn_ioaddr.c:socket_econnrefused Unexecuted instantiation: ns_turn_msg_addr.c:socket_econnrefused Unexecuted instantiation: FuzzStun.c:socket_econnrefused |
145 | 0 | static inline int socket_ehostdown(void) { return socket_errno() == EHOSTDOWN; } Unexecuted instantiation: FuzzStunClient.c:socket_ehostdown Unexecuted instantiation: stun_buffer.c:socket_ehostdown Unexecuted instantiation: ns_turn_msg.c:socket_ehostdown Unexecuted instantiation: ns_turn_ioaddr.c:socket_ehostdown Unexecuted instantiation: ns_turn_msg_addr.c:socket_ehostdown Unexecuted instantiation: FuzzStun.c:socket_ehostdown |
146 | 0 | static inline int socket_emsgsize(void) { return socket_errno() == EMSGSIZE; } Unexecuted instantiation: FuzzStunClient.c:socket_emsgsize Unexecuted instantiation: stun_buffer.c:socket_emsgsize Unexecuted instantiation: ns_turn_msg.c:socket_emsgsize Unexecuted instantiation: ns_turn_ioaddr.c:socket_emsgsize Unexecuted instantiation: ns_turn_msg_addr.c:socket_emsgsize Unexecuted instantiation: FuzzStun.c:socket_emsgsize |
147 | | #endif |
148 | | |
149 | | #define BUFFEREVENT_FREE(be) \ |
150 | | do { \ |
151 | | if (be) { \ |
152 | | bufferevent_flush(be, EV_READ | EV_WRITE, BEV_FLUSH); \ |
153 | | bufferevent_disable(be, EV_READ | EV_WRITE); \ |
154 | | bufferevent_free(be); \ |
155 | | be = NULL; \ |
156 | | } \ |
157 | | } while (0) |
158 | | |
159 | 0 | #define turn_time() ((turn_time_t)time(NULL)) |
160 | | |
161 | | typedef int vint; |
162 | | typedef vint *vintp; |
163 | | |
164 | | typedef uint32_t turn_time_t; |
165 | | |
166 | | #define turn_time_before(t1, t2) ((((int32_t)(t1)) - ((int32_t)(t2))) < 0) |
167 | | |
168 | | #if !defined(UNUSED_ARG) |
169 | | #define UNUSED_ARG(A) \ |
170 | 205 | do { \ |
171 | 205 | A = A; \ |
172 | 205 | } while (0) |
173 | | #endif |
174 | | |
175 | 0 | #define MAX_STUN_MESSAGE_SIZE (65507) |
176 | | #define STUN_BUFFER_SIZE (MAX_STUN_MESSAGE_SIZE) |
177 | | #define UDP_STUN_BUFFER_SIZE (1024 << 4) |
178 | | |
179 | | #define NONCE_LENGTH_32BITS (4) |
180 | | |
181 | | #define DEFAULT_STUN_PORT (3478) |
182 | | #define DEFAULT_STUN_TLS_PORT (5349) |
183 | | |
184 | | #if BYTE_ORDER == LITTLE_ENDIAN |
185 | | #define DEFAULT_STUN_PORT_NBO (0x960D) |
186 | | #elif BYTE_ORDER == BIG_ENDIAN |
187 | | #define DEFAULT_STUN_PORT_NBO (0x0D96) |
188 | | #else |
189 | | #error WRONG BYTE_ORDER SETTING |
190 | | #endif |
191 | | |
192 | | // NOLINTBEGIN(clang-diagnostic-string-compare) |
193 | | #define STRCPY(dst, src) \ |
194 | 0 | do { \ |
195 | 0 | if ((const char *)(dst) != (const char *)(src)) { \ |
196 | 0 | if (sizeof(dst) == sizeof(char *)) \ |
197 | 0 | strcpy(((char *)(dst)), (const char *)(src)); \ |
198 | 0 | else { \ |
199 | 0 | size_t szdst = sizeof((dst)); \ |
200 | 0 | strncpy((char *)(dst), (const char *)(src), szdst); \ |
201 | 0 | ((char *)(dst))[szdst - 1] = 0; \ |
202 | 0 | } \ |
203 | 0 | } \ |
204 | 0 | } while (0) |
205 | | // NOLINTEND(clang-diagnostic-string-compare) |
206 | | |
207 | | //////////////// Bufferevents ///////////////////// |
208 | | |
209 | | #define TURN_BUFFEREVENTS_OPTIONS (BEV_OPT_DEFER_CALLBACKS | BEV_OPT_THREADSAFE | BEV_OPT_UNLOCK_CALLBACKS) |
210 | | |
211 | | //////////////// KERNEL-LEVEL CHANNEL HANDLERS ///////// |
212 | | |
213 | | #if !defined(TURN_CHANNEL_HANDLER_KERNEL) |
214 | | #define TURN_CHANNEL_HANDLER_KERNEL void * |
215 | | #endif |
216 | | |
217 | | #if !defined(CREATE_TURN_CHANNEL_KERNEL) |
218 | | #define CREATE_TURN_CHANNEL_KERNEL(channel_number, address_family_client, address_family_peer, protocol_client, \ |
219 | | client_addr, local_addr, local_relay_addr, peer_addr) \ |
220 | | ((TURN_CHANNEL_HANDLER_KERNEL)(1)) |
221 | | #endif |
222 | | |
223 | | #if !defined(DELETE_TURN_CHANNEL_KERNEL) |
224 | | #define DELETE_TURN_CHANNEL_KERNEL(handler) |
225 | | #endif |
226 | | |
227 | | //////////////////////////////////////////////////////// |
228 | | |
229 | | #if !defined(IPPROTO_SCTP) && !defined(TURN_NO_SCTP) |
230 | | #define TURN_NO_SCTP |
231 | | #endif |
232 | | |
233 | | #define CLIENT_DGRAM_SOCKET_TYPE SOCK_DGRAM |
234 | | #define CLIENT_DGRAM_SOCKET_PROTOCOL IPPROTO_IP |
235 | | |
236 | | #define CLIENT_STREAM_SOCKET_TYPE SOCK_STREAM |
237 | | #define CLIENT_STREAM_SOCKET_PROTOCOL IPPROTO_IP |
238 | | |
239 | | #define SCTP_CLIENT_STREAM_SOCKET_TYPE SOCK_STREAM |
240 | | |
241 | | #if !defined(TURN_NO_SCTP) |
242 | | #define SCTP_CLIENT_STREAM_SOCKET_PROTOCOL IPPROTO_SCTP |
243 | | #else |
244 | | #define SCTP_CLIENT_STREAM_SOCKET_PROTOCOL IPPROTO_IP |
245 | | #endif |
246 | | |
247 | | #define RELAY_DGRAM_SOCKET_TYPE SOCK_DGRAM |
248 | | #define RELAY_DGRAM_SOCKET_PROTOCOL IPPROTO_IP |
249 | | #define RELAY_STREAM_SOCKET_TYPE SOCK_STREAM |
250 | | #define RELAY_STREAM_SOCKET_PROTOCOL IPPROTO_IP |
251 | | |
252 | | #define ADMIN_STREAM_SOCKET_TYPE SOCK_STREAM |
253 | | #define ADMIN_STREAM_SOCKET_PROTOCOL IPPROTO_IP |
254 | | |
255 | | //////////////////////////////////////////////////////// |
256 | | |
257 | | #ifdef __cplusplus |
258 | | } |
259 | | #endif |
260 | | |
261 | | #endif |
262 | | /* __IODEFS__ */ |