Commit Graph

118 Commits

Author SHA1 Message Date
Pavel Punsky
89a5600be1
Drop TLS version support detection (#1617)
With requiring openssl version at least 1.1.1 all versions of TLS (up to
and including 1.3) and DTLS 1.2 are supported
With that, no detection or ability to disable a version will be provided
2024-12-19 17:10:49 -08:00
Pavel Punsky
20da9cd09a
Cleanup ALPN_SUPPORTED define usage (#1616)
As of openssl 1.1.1 ALPN is supported - no need for all the ifdefs anymore
2024-12-19 16:41:45 -08:00
Pavel Punsky
9f779a64d0
Fix warnings type conversion (#1615) 2024-12-19 09:05:37 -08:00
Michael Jones
c9878469fc
[BREAKING] Remove support for openssl older than 1.1.1 (#1397)
Openssl 1.1.1 is end-of-life in September 2023.
This PR removes support for versions of openssl OLDER than 1.1.1
1.1.1 should still be usable after this change is merged.

I don't see any value in supporting 1.1.1, but didn't see a reason to
purge support for 1.1.1 when there are so few checks for >= 3.0.

Note that this does also remove CI support for Ubuntu 16.04. The
official version of OpenSSL from Ubuntu for this release is listed here:
https://launchpad.net/ubuntu/+source/openssl as 1.0.2g

Since no newer releases of coturn will be backported by Canonical to
Ubuntu 16.04, anyone using Coturn on this operating system will have to
download and compile it themselves. They may build their own version of
OpenSSL if they somehow cannot upgrade to a newer version of Ubuntu.

My position is that these users should prefer to upgrade to a newer
operating system than worry about chasing newer releases of Coturn.

Co-authored-by: Pavel Punsky <eakraly@users.noreply.github.com>
2024-12-13 13:06:24 -08:00
Michael Jones
b523616b1f
Use bool, instead of int, for the functions in ns_turn_msg.c (#1553)
And address knockon effects in other files, e.g. adjust if-statements
and other function parameters and return types.
2024-08-23 17:49:14 -07:00
Michael Jones
958f70d5c2
Use calloc where appropriate, avoid memset when normal buffer initialization works (#1550)
Depends on https://github.com/coturn/coturn/pull/1547
2024-08-04 17:30:58 -07:00
Michael Jones
868f15a672
Move the hiredis_libevent2 code from common to relay (#1509)
The point of this change is to make the build instructions a bit more
straight forward. Since the hiresevent2 source files are only ever used
by the relay target, this scoping makes sense in general.
2024-06-01 18:16:39 -07:00
Michael Jones
d1db5e590d
Include what you use (#1512)
Use the include-what-you-use program to (partially) clean up header
includes, so that only includes which are needed, and no includes that
are not needed (or at least closer to that ideal) are done.

For a c-language project, the build-time improvements from this change
is minimal. This would have a much bigger impact on a C++ project than a
C-project for build times.

So for coturn, this change is mostly intended to just provide
consistency and make it easier to locate weird issues like strange
dependencies, and unnecessary connections between code.
2024-06-01 18:13:08 -07:00
Michael Jones
ad94684b23
Use bool over int for the turnutils_uclient program (#1420)
Converts all of the variables in the uclient program that should be bool
but weren't.

A few other minor adjustments made at the behest of clang-tidy, but this
change does not address all of clang-tidy's complaints.
2024-05-29 20:39:51 -07:00
Michael Jones
544382f313
Fix mingw and MSVC ci build (#1491) 2024-05-27 13:43:40 -07:00
NO NAME
3f66c028fa
Fix Cmake find issue in libevent (#1466)
Fixed an issue in libevent's CMake configuration where pthreads were not
correctly added to the optional components list, leading to a
compilation error. #1448

Co-authored-by: linwenchen <wenchen0803@qq.com>
2024-04-09 11:51:31 +02:00
Michael Jones
da332ed9e7
Add the InsertBraces command for clang-format to ensure that all conditionals always have braces (#1408)
- Why? Because code where conditionals lack braces is much harder to read, and prone to indentation confusion.
- How? Just added an extra flag to .clang-format and re-ran clang-format on all the files.

I also moved .clang-format up to the top level of the repo so that it can be applied to the fuzz targets as well.
2024-01-27 16:38:40 -08:00
Pavel Punsky
c062d5e2af
Simplify macOS detection macros (#1372) 2024-01-15 15:18:35 -08:00
Gustavo Garcia
88ced47138
Replace srand/rand with srandom/random (#1279)
- srandom/random provide stronger randomness characteristics than
srand/rand in some operating systems.
- usage of srand/rand is not very consistent in coturn.

There is room for more refactoring and use apputils helper functions in
ns_turn_msg.c too but i'm not sure that dependency from "client" module
to "apps" module is a good idea yet.

Thx @0xdea

Co-authored-by: Gustavo Garcia <gustavogb@mail.com>
2023-10-02 16:19:57 +02:00
Gustavo Garcia
4e0d21e1b5
Fix memcpy len checks stun_is_challenge_response_str (#1280)
Add missing checks for length of realm/nonce/server_name before copying
those values to the buffer passed to stun_is_challenge_response_str.

The function stun_is_challenge_response_str is only used in uclient test
application.

Thank you very much @0xdea

Co-authored-by: Gustavo Garcia <gustavogb@mail.com>
2023-10-02 16:19:38 +02:00
Aaron Bird
0f450f5492
Fix error of make command in Cygwin environment (#1236)
Environment:
- Windows 10
- Cygwin 2.925

make output:
```
<command-line>: note: this is the location of the previous definition
src/apps/common/ns_turn_utils.c:53:10: fatal error: sys/syscall.h: No such file or directory
   53 | #include <sys/syscall.h>
      |          ^~~~~~~~~~~~~~~
compilation terminated.
In file included from src/client/ns_turn_ioaddr.h:34,
                 from src/client/ns_turn_msg.h:34,
                 from src/apps/common/stun_buffer.h:34,
                 from src/apps/common/stun_buffer.c:31:
src/ns_turn_defs.h:223: warning: "TURN_NO_SCTP" redefined
  223 | #define TURN_NO_SCTP
      |
<command-line>: note: this is the location of the previous definition
make: *** [Makefile:127: bin/turnutils_oauth] Error 1
```
2023-08-13 17:14:16 -07:00
Robert Scheck
8f9446cf8f
Change printf() to TURN_LOG_FUNC() for --no-stdout-log (#1221) 2023-06-01 19:38:33 -07:00
Pavel Punsky
79fb65519c
Remove unused include that breaks OpenBSD (#1165)
PR #855 introduced new include <ssys/sysinfo.h> 
It is not required for compilation or turnserver function but breaks
OpenBSD build (which does not have this file)
This PR removes the include to restore OpenBSD build compatibility

Fixes #1162

Test Plan:
TBD - need some one to test build
2023-03-06 08:50:12 +01:00
Emil Ljungdahl
9fa8af6163
Use inline functions for errno checks (#1123)
Since winsock do not use errno, and have different error codes, this is
needed to be windows compatible

This pull request is a split of PR #1061
2022-12-22 11:10:34 -08:00
Pavel Punsky
95373d3e2a
Cleanup logs on turnserver start (#1088)
Reformatting and removing some duplications:
- Some lines have WARNING WARNING: cleaned up.
- Lines printed using perror: only LOG_ mechanism should be used.
- Printing IO mechanism (epoll for example) for each thread: selected
mechanism logged once
- Duplicate lines (perror and also LOG): duplication removed
- Duplicates: clean up (because calling function multiple times -
configuration load)
2022-11-14 17:45:20 -08:00
Gustavo Garcia
d9108a4b54
Add clang format rules and checks (#935)
I would like to get feedback on this and see if people is confortable
with these clang rules.

Right now is using the "llvm" style increasing the line length from 80
to 120 given that coturn is using long lines often.

Co-authored-by: Pavel Punsky <eakraly@users.noreply.github.com>
2022-11-06 22:05:17 +01:00
Scott Godin
7fb7b1da21
Log threadId to logs to aid in multi-threaded debugging. (#1030) 2022-11-01 12:59:08 -07:00
Gregor Jasny
83b8ddb744
Check and fix format string for turn_log_func_default (#1064) 2022-10-31 11:07:04 -07:00
Pavel Punsky
2716ed035a
Simplify defines for macOS platform (#1058)
`__APPLE__` is enough to detect macOS
2022-10-29 20:16:07 -07:00
Emil Ljungdahl
c4f670fa24
WINDOWS: unsigned long should not be used to store pointers (#1055)
On LLP64 systems (read Windows) unsigned long is only 4 bytes wide,
which makes it very unsuitable for storing pointers.
-----
Additional comments:
uintptr_t since c99 or uintptr_t since C++11
see: https://cplusplus.com/reference/cstdint/,
https://en.cppreference.com/w/c/types/integer,
https://en.cppreference.com/w/cpp/types/integer

C11 re-enabled in #1056
2022-10-29 20:13:25 -07:00
Pavel Punsky
6ff98239f4
Reduce usage of TURN_NO_HIREDIS macros (#1022)
`TURN_NO_HIREDIS` is defined when hiredis library is not present and any
redis functionality must be disabled

While all above is correct, it does not require ifdef-ing out all
related code.
For example, redis related fields in `turn_params` do not need to be
compiled out. Same for certain function parameters.

This PR reduces amount of places in code where `TURN_NO_HIREDIS` is used
to make code simpler by moving as much usage of this define into
dbd_redis.h/c files and compiling them unconditionally.

- Always compile/link `dbd_redis.c`
- Move many `TURN_NO_HIREDIS` decisions into `dbd_redis.c`
- Delete empty function redis_async_init
2022-10-29 18:17:12 -07:00
Yoshiki Kadoshita
78674aebee
Remove unnecessary declaration from header file (#1052)
Remove unnecessary declaration.

The implementation of the vrtpprintf function has been removed in commit
5e87c44469.
2022-10-28 20:22:26 -07:00
Pavel Punsky
af48249f29
Fix compilation warnings for functions with no arguments (#1053)
Function with no arguments must be defined as f(void) according to C
standard
2022-10-28 20:21:49 -07:00
Kang Lin
40c99db6ba
Support Windows MSVC (#855)
The following changes have been made:
1. Replace deprecated functions with new standard functions
2. Add corresponding MSVC functions for non-standard functions 
3. Remove warnings about unsafe functions
4. CMAKE: modify find pack Libevent and openssl 
5. Modify include files
6. Use pthread4W
7. Modify socket in windows
8. Add CI - github action
8.1. msvc
8.2. mingw
10. The database:
9.1. sqlite, pgsql, hiredis, mongo  is test compiled.
9.2. mysql, isnot test compiled.
11. The applications、server can be compiled and run successfully! 
12. Add vcpkg manifest mode in cmake.
2022-10-28 19:32:23 -07:00
Gregor Jasny
8c15f4bf23
Fix warnings (#1046)
Clang emitted some easy to fix warnings.
2022-10-25 09:28:46 -07:00
Thibaut ACKERMANN
13ecb7d012
Redis memleaks and socketleaks (#1015)
Hello,

while using the `redis-statsdb` option, I found that coturn is leaking
sockets (and memory) in case of redis reconnection.

This occurs a lot to me, because in my setup I have a `coturn -> haproxy
-> redis` and if all my redis servers are down, HaProxy abruptly close
the connection to coturn and coturn reconnects periodically. After some
time I can see thousands of pending sockets (`CLOSE_WAIT`) :

```
user@server[11:32:48 UTC]:~$ sudo lsof -i | grep turn
turnserve 461797       root   15u  IPv4 12856075      0t0  TCP server:3478 (LISTEN)
turnserve 461797       root   22u  IPv4 12856081      0t0  TCP server:3478 (LISTEN)
turnserve 461797       root   23u  IPv4 12857384      0t0  UDP server:3478 
turnserve 461797       root   24u  IPv4 12857385      0t0  UDP server:3478 
turnserve 461797       root   36u  IPv4 12857390      0t0  TCP server:5766 (LISTEN)
turnserve 461797       root   43u  IPv4 12856096      0t0  TCP server:10059->haproxy-server:redis (CLOSE_WAIT)
turnserve 461797       root   46u  IPv4 12857403      0t0  TCP server:10087->haproxy-server:redis (CLOSE_WAIT)
turnserve 461797       root   48u  IPv4 12856124      0t0  TCP server:53867->haproxy-server:redis (CLOSE_WAIT)
turnserve 461797       root   50u  IPv4 12857633      0t0  TCP server:53875->haproxy-server:redis (CLOSE_WAIT)
turnserve 461797       root   51u  IPv4 12856138      0t0  TCP server:53877->haproxy-server:redis (CLOSE_WAIT)
turnserve 461797       root   54u  IPv4 12857738      0t0  TCP server:10001->haproxy-server:redis (CLOSE_WAIT)
turnserve 461797       root   55u  IPv4 12856152      0t0  TCP server:10003->haproxy-server:redis (CLOSE_WAIT)
.... (many many lines)
```


After searching and using valgrind I found 2 interesting leaks:

```
...
==460721== 32 bytes in 1 blocks are definitely lost in loss record 586 of 1,053
==460721==    at 0x483877F: malloc (vg_replace_malloc.c:307)
==460721==    by 0x1414FF: RyconninfoParse (dbd_redis.c:69)
==460721==    by 0x141B04: get_redis_async_connection (dbd_redis.c:169)
==460721==    by 0x110D7B: create_ioa_engine (ns_ioalib_engine_impl.c:407)
==460721==    by 0x12ECB0: setup_admin_thread (turn_admin_server.c:1309)
==460721==    by 0x127724: run_admin_server_thread (netengine.c:1815)
==460721==    by 0x4DA9EA6: start_thread (pthread_create.c:477)
==460721==    by 0x4EC0AEE: clone (clone.S:95)
...
==460979== 2,170 (688 direct, 1,482 indirect) bytes in 2 blocks are definitely lost in loss record 1,029 of 1,049
==460979==    at 0x483AD7B: realloc (vg_replace_malloc.c:834)
==460979==    by 0x49A1BD0: ??? (in /usr/lib/x86_64-linux-gnu/libhiredis.so.0.14)
==460979==    by 0x49A2829: redisAsyncConnect (in /usr/lib/x86_64-linux-gnu/libhiredis.so.0.14)
==460979==    by 0x13DB37: redis_reconnect (hiredis_libevent2.c:331)
==460979==    by 0x13D1A7: redisLibeventReadEvent (hiredis_libevent2.c:101)
==460979==    by 0x4D5135E: ??? (in /usr/lib/x86_64-linux-gnu/libevent_core-2.1.so.7.0.1)
==460979==    by 0x4D51A9E: event_base_loop (in /usr/lib/x86_64-linux-gnu/libevent_core-2.1.so.7.0.1)
==460979==    by 0x126D5A: run_events (netengine.c:1579)
==460979==    by 0x127272: run_general_relay_thread (netengine.c:1707)
==460979==    by 0x4DA9EA6: start_thread (pthread_create.c:477)
==460979==    by 0x4EC0AEE: clone (clone.S:95)
==460979== 
...
```

I made 1 commit for each fix.

Obviously with these fixes, I don't have anymore the leaks of thousands
of sockets (even after some time)

Thanks & hope it helps.

Thibaut
2022-10-11 21:57:23 +02:00
Pavel Punsky
d9e74af75d
Cleanup unused include of header files (#1004)
Using clang-tidy to detect unused header files

Inspired by #855

Test Plan:
- Rebuild all on mac, review no warnings/errors
- Pass builds/docker build - review for no issues
2022-10-05 10:28:40 +02:00
Pavel Punsky
a3d338e2c1
Silence warnings by converting STRCPY to strncpy calls (#995)
STRCPY macro makes pointer comparison which creates a warning

In those places, replace the macro with `strncpy` with careful review of
destination buffer size

With this change I do not get compiler warnings at all
2022-09-30 08:17:46 -07:00
Pavel Punsky
e87c42524a
Fix TLS1.3 support
Fix TLS1.3 support

`TLSv1_3_SUPPORTED` was not defined so TLS1.3 was not enabled properly
2022-09-28 20:28:09 -07:00
Pavel Punsky
bd9e44dd7c
Replace bcopy with memcpy (#991)
Replace all instances of `bcopy` with memcpy.

Inspired by https://github.com/coturn/coturn/pull/855
2022-09-20 10:39:11 +02:00
Pavel Punsky
ae259637eb
Replace bzero with memset (#986)
Replace all instances of `bzero` with memset by find-replace-edit.
This is straightforward replacement which is suboptimal in a few cases
(for example we could use calloc instead of malloc+memset(0))

Inspired by #855
2022-09-17 08:36:28 +02:00
Pavel Punsky
98d19fc441
Fix small issues reported by cppcheck (#967)
- Redundant checks for variable values
- Potential nullptr dereference
- Double check for the same variable

Run with:
```
cppcheck --inline-suppr --language=c --enable=warning,performance --force .
```

Co-authored-by: Pavel Punsky <pavel.punsky@epicgames.com>
2022-09-08 11:25:38 +02:00
Pavel Punsky
e2ff7caf9d
Fix long log line printing (#974)
`vsnprintf` will stop at the max buffer size as provided in its 2nd
argument

But the return value is `The number of characters that would have been
written if n had been sufficiently large` meaning it can be larger than
actual buffer size
`fwrite` will actually use the larger, incorrect number and dump
unrelated memory to log (and crash with high confidence)

Test:
- Query admin interface with super long path (>16KB) - crash
- With the fix - no crash with the same input, log line cut off

Co-authored-by: Pavel Punsky <pavel.punsky@epicgames.com>
2022-09-08 11:24:28 +02:00
Steffen Moser
b722c84b45 Allow compilation on Solaris 11.4 2022-08-22 11:22:59 +02:00
Jeremy Murphy
832f11331f Depend on OpenSSL::Crypto and OpenSSL::SSL
Maybe only one is strictly required, but the list of headers used in
ns_turn_openssl.h includes things from both.
2022-08-16 12:41:44 +10:00
KORAY VATANSEVER
2b91f0ad8b Function renamed for the consistency. Incomplete coding completed.
Tested for the empty and invalid values.  Parameter is ignored in those cases.
2022-08-09 13:06:45 +03:00
KORAY VATANSEVER
22af3ea567 Add syslog facility configuration 2021-07-07 15:56:30 +03:00
Mészáros Mihály
54ef051844 Disable stun backward compatibility 2021-06-05 22:10:31 +02:00
KangLin
9f6defdac4 CMake: add -Wno-deprecated-declarations 2021-03-29 07:22:12 -07:00
KangLin
73da474804 CMake: add runtime install 2021-03-28 20:19:15 -07:00
Mészáros Mihály
31c936d51d
Merge pull request #721 from KangLin/cmake
Add to support cmake
2021-03-23 09:31:59 +01:00
KangLin
677e5dc5d3 Add cmake 2021-02-26 09:02:50 +08:00
Mark Hills
9bcc898b05 Restore no_stdout_log behaviour
In commit 599a61ee this was removed, by accident it could seem.
2021-01-25 09:31:47 +00:00
Mészáros Mihály
00659f3948
Merge pull request #599 from cedk/libressl
Do not use FIPS and remove hardcode OPENSSL_VERSION_NUMBER with LibreSSL
2020-12-08 08:48:15 +01:00
Paul Wayper
ed88f1605a Neater ISO-8601 timestamp format string
Signed-off-by: Paul Wayper <paulway@mabula.net>
2020-09-01 20:57:54 +10:00