Commit Graph

881 Commits

Author SHA1 Message Date
Pavel Punsky
af8a057eac
Update version to 4.6.2 (#1174)
Update version number, generate authors and changelog files

Release notes (short summary of changes)
```
- Make sure microhttpd starts using epoll if supported
- Add sessioncount to prometheus metrics
- Add STUN request/response/error prometheus counters
- Cleanup logs on turnserver start
- Fix duplicate stdout log output
- Log threadId to logs to aid in multi-threaded debugging
- Optional build info compiled into turnserver binary
- Fix arguments expansion in `docker-entrypoint.sh`
- Santise database connection strings before printing to log
- Support Windows MSVC
- Add configuration option for TLS 1.3 ciphersuites
- Improve openssl3 and FIPS support
- Use single SSL_CTX for TLS and DTLS support
- Update openssl API use to non-deprecated version
- Set string bytes to null to prevent random origin
- Fix memory corruption on socket close
- Fix packet backlog fifo that processed packets in reverse order in some scenarios
- Fix off-by-one when terminating gcm_nonce
- Fixes to Redis memleaks and socketleaks
- Fix malformed response to mobility refresh request
- Fuzzing support
- Ignore raw UDP if no_udp is enabled
- Better detect availability of SCTP protocol
```

---------

Co-authored-by: tyranron <tyranron@gmail.com>
2023-04-10 19:00:08 -07:00
Cédric DIJOUX
67beeb83b1
Fix MSVC CI build (#1182)
Removing windows.h inclusion, not needed with ws2tcpip.h. Causes some
struct redefinitions.
2023-04-01 18:28:27 -07:00
Thibaut ACKERMANN
242eb78227
Prometheus: make sure microhttpd starts using epoll if supported (#1173)
In some cases the prometheus server was started using SELECT even if
EPOLL was supported.
Some flags were changed in microhttpd and now we use MHD_VERSION to make
sure to use the right ones in all cases (support old version, for ubuntu
16.04 for ex).

This fixes the issue #1167

I also added a log to make sure we know which version is used,
especially to inform the user that the SELECT version might lead to
issues on highly used servers.
2023-03-19 18:04:04 -07:00
Stefan Sundin
43f8b873a7
Fix typo in mainrelay.c (#1169) 2023-03-12 17:29:39 -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
r3g_5z
212e782355
use santisied psql string (#1144)
Noticed the plaintext password of my postgresql server in my coturn
logs, but postgresql errors would return the password sanitised. Simple
fix to log the sanitised string.


![image](https://user-images.githubusercontent.com/112147643/213053494-c8a5d226-0b04-4c8d-9b52-3e1330291a39.png)


Signed-off-by: r3g_5z <june@girlboss.ceo>

Signed-off-by: r3g_5z <june@girlboss.ceo>
2023-01-19 17:55:46 -08:00
Jasper
8f8038a7fb
Use the actual redis connection string to connect, not the sanitized one (#1141)
fixes #1140
2023-01-13 15:52:47 -08:00
Emil Ljungdahl
980ef8f9dc
Implement non-blocking recvfrom on Windows (#1124)
This pull request is a split of PR #1061

As @KangLin pointed out in the original PR those sockets should ideally
be permanently non-blocking for performance reasons, but they are NOT at
the moment.
Someone with more knowledge about the code in dtls_listener.c should
probably have a look if it would be feasible to change the sockets to
non-blocking already at creation, similar to what is done in
udpserver.c...
2023-01-08 20:42:16 -08: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
7038763627
Add STUN request/response/error prometheus counters (#1115)
Somewhat relevant to #1075
2022-12-17 17:50:09 +01:00
Molly Miller
902cb99849
Add configuration option for TLS 1.3 ciphersuites (#1118)
There are two different API's in OpenSSL for configuring TLS ciphers,
one for TLS 1.2 and below, and another for TLS 1.3. coturn only calls
the TLS 1.2 API when handling the `--cipher-list` configuration option,
which means that it's not possible to use non-default ciphersuites with
TLS 1.3 connections.

This PR calls appropriate OpenSSL API to allow TLS 1.3 ciphersuites to be configured.
2022-12-16 15:53:36 -08:00
Paul Kramer
39d293c34d
Fix wrong usage of C-sytle in place generated array (#1122)
This should result in a address of temporary array.

Co-authored-by: Paul Kramer <paul.kramer@logmein.com>
2022-12-10 12:11:52 -08:00
Paul Kramer
72e2605562
bugfix: fix broken type label of turn_total_allocations gauge (#1119)
It's not working when constructing it in-place, likely this is undefined
behaviour.

Co-authored-by: Paul Kramer <paul.kramer@logmein.com>
2022-12-08 18:04:28 -08:00
Molly Miller
82646a9023
Add explicit SIGTERM and SIGINT handlers. (#1106)
coturn running inside a docker container runs as PID 1, however PID 1
has special signal handling semantics (see the note at the bottom of the
section
[here](https://docs.docker.com/engine/reference/run/#foreground)).
coturn relies on the default behaviour of SIGTERM to terminate the
process, however as no signal handler is explicitly installed, it
doesn't respond to SIGTERM when running inside a container. This PR
fixes this problem by installing explicit signal handlers for SIGINT and
SIGTERM, which trigger the same termination mechanism as the admin
interface "halt" command.

This is a port of wireapp#6 for upstream.
2022-12-06 17:06:51 -08:00
Pavel Punsky
eff1f9a09a
Set string bytes to null to prevent random origin (#1114)
Fix #1111
2022-12-06 17:04:57 -08:00
Molly Miller
af4f190a94
Fix inverted logic in TLS configuration options (#1105)
This PR fixes some errata from #996 and #989:

- Some DTLS code was left over in the common path for allocating and
initialising `SSL_CTX`'s, and the DTLS-specific configuration code was
erroneously operating on the TLS context instead of the DTLS context.

- In both the TLS and DTLS codepaths, the previous refactoring inverted
the logic for the `--no-tlsv1`/`--no-tlsv1_1`/etc command line options,
so that these options would instead *enable* the respective (D)TLS
versions, instead of disabling this. This would mean that by default
coturn would only support TLS 1.3 and DTLS 1.2, and no earlier versions.

I've also regenerated the manual pages (with the `make-man.sh` script)
to match the documentation in the README files.
2022-12-06 17:03:23 -08:00
Pavel Punsky
5d44f5087b
Reduce code duplication when printing userdb (#1103)
TURN_USERDB_TYPE enum does not need to be "dynamic" based on what
libraries actually available during the build - all potentially
supported DB options are now enumerated.
Printing (to log or http) the DB type name is done with much less code
(using a helper function `userdb_type_to_string`)
2022-12-04 10:49:05 -08:00
tyranron
744a263d80
Upgrade Docker image to 4.6.1 Coturn version 2022-12-04 12:37:47 +01:00
Gustavo Garcia
a005eee880 Update version to 4.6.1 2022-12-03 22:21:29 +01:00
Paul Kramer
d3e353fbb0 Fix memory corruption on socket close (#1113)
Fix memory corruption introduced by commit
c8663f4a91

If there was an unsuccessful session registration in
open_client_connection_session, it adds a timer (before it didn't).

Later during runtime, at session destruction, it removes the
client_socket in close_ioa_socket. Then the timer gets triggered and
runs the cleanup method client_to_be_allocated_timeout_handler and tries
to access the stored client_socket. This then fails as it already was
freed.

The fix just sets the client_socket pointer to null and then the timer
should detect this and not access already freed memory.

The issue affects version 4.6.0, 4.6.0-r0 and 4.6.0-r1.

Co-authored-by: Paul Kramer <paul.kramer@logmein.com>
2022-12-03 20:44:41 +01:00
Paul Kramer
83c25c44fd
Fix memory corruption on socket close (#1113)
Fix memory corruption introduced by commit
c8663f4a91

If there was an unsuccessful session registration in
open_client_connection_session, it adds a timer (before it didn't).

Later during runtime, at session destruction, it removes the
client_socket in close_ioa_socket. Then the timer gets triggered and
runs the cleanup method client_to_be_allocated_timeout_handler and tries
to access the stored client_socket. This then fails as it already was
freed.

The fix just sets the client_socket pointer to null and then the timer
should detect this and not access already freed memory.

The issue affects version 4.6.0, 4.6.0-r0 and 4.6.0-r1.

Co-authored-by: Paul Kramer <paul.kramer@logmein.com>
2022-12-03 10:23:19 +01: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
Erik Moqvist
e55bbc0413
Optional build info compiled into turnserver binary (#1083)
Example usage with make:

make CPPFLAGS="-DTURN_SERVER_BUILD_INFO=\"\\\" git: $(git rev-parse
HEAD) build: 123\\\"\""

Example usage with cmake:

cmake .. -DTURN_SERVER_BUILD_INFO="\" git: $(git rev-parse HEAD) build:
123\""
2022-11-13 10:24:50 -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
Pavel Punsky
da2ae173c4
Fix duplicate prometheus metric report (#1079)
Prometheus would aggregate across all labels (when not specifying)
In this scenario `turn_total_allocations` does not need separate label
"type=all" as such in this case the result would be double the actual
amount
2022-11-06 11:13:48 -08:00
Paul Kramer
5a28394200
feature(1026): add sessioncount to prometheus metrics (#1075)
Co-authored-by: Paul Kramer <paul.kramer@logmein.com>
2022-11-06 10:19:20 -08:00
Pavel Punsky
d3f0ad3be6
Update openssl API use to non-deprecated version (#1072)
Use version independent APIs for openssl-1.1.0 and above

Tested with turnutils_uclient against a turnserver with TLS and DTLS
modes
2022-11-02 19:36:20 -07: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
8cb2282598
Use khash 0.2.8 (#1047)
The previously used version of khash trigged some static code analysis
warnings that are gone with the latest version:


9a063b33ef/khash.h
2022-10-31 11:32:58 -07:00
Gregor Jasny
83b8ddb744
Check and fix format string for turn_log_func_default (#1064) 2022-10-31 11:07:04 -07:00
Emil Ljungdahl
15153f5406
Repair MSVC CI builds (#1066)
The MSVC CI pipelines broke in #1056 due to the bump in C standard
version.
2022-10-31 11:06:24 -07:00
Gregor Jasny
19ee59c3fe
Properly calculate size for sm_allocated (#1063)
The `sm_allocated` field is an array of `size_t` values. Therefore its
size must be calculated as `n * sizeof(size_t)`.

Our static code analysis tool complained:
```
Sizeof not portable (SIZEOF_MISMATCH)
suspicious_sizeof: Passing argument r->sm_allocated of type size_t * and argument (r->sm_chunk + 1) * 8UL /* sizeof (size_t *) */ to function realloc is suspicious. In this case, sizeof (size_t *) is equal to sizeof (size_t), but this is not a portable assumption.
```

Fix: #1045
2022-10-31 11:02:46 -07:00
Gregor Jasny
5d398348ee
Do not discard qualifiers in free() (#1065)
Warning emitted from GCC:
```
warning: passing argument 1 of ‘free’ discards ‘const’ qualifier from pointer target type
```
2022-10-31 10:58:52 -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
Pavel Punsky
4995b64453
Fix warnings (unused arguments, undeclared function) (#1057) 2022-10-29 20:13:55 -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
9a9e9671f4
Update to fix duplicate stdout log output (#1054)
Disables default log output to stdout if stdout is set as logfile.

When execute `turnutils_stunclient` , the output will be duplicated as
in the following example.

```
$ ./turnutils_stunclient stun.example.com
0: : IPv4. UDP reflexive addr: 203.0.113.1:10000
0: : IPv4. UDP reflexive addr: 203.0.113.1:10000
```

This is because stdout is set in `set_logfile` and furthermore log
output to stdout is done by default.

In this change, call `set_no_stdout_log` to disable default log output
to stdout when stdout is set as logfile.

This solves the problem of duplicate output to stdout of the same log.
2022-10-29 18:13:39 -07:00
Pavel Punsky
181216e9f1
Reduce usage of TURN_NO_PROMETHEUS (#1023)
`TURN_NO_PROMETHEUS` is defined when prometheus libraries are not
present and any prometheus functionality must be disabled

While all above is correct, it does not require ifdef-ing out all
related code.
For example, prometheus 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_PROMETHEUS` is
used to make code simpler by moving as much usage of this define into
prom_server.h/c files and compiling them unconditionally.

- Always compile/link prom_server.c
- Move many TURN_NO_PROMETHEUS decisions into prom_server.c
2022-10-28 20:22:50 -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
d992d0c049
Fix resource leaks (#1048) 2022-10-27 14:07:21 -07:00
Gregor Jasny
8c15f4bf23
Fix warnings (#1046)
Clang emitted some easy to fix warnings.
2022-10-25 09:28:46 -07:00
Scott Godin
cfa5f66cd7
Backlog fifo (#1029)
Modify SSL backlog buffer from LIFO to queue/FIFO

If data ends up in the ssl_backlog_buffer because we are waiting for a
handshake to finish, then this change ensures that the data is sent out
in the proper order once the handshake completes. Previous code was
sending in LIFO order.
2022-10-24 16:44:31 -07:00
Gregor Jasny
1148ed7d0d
Add missing comma (#1041) 2022-10-24 22:35:38 +02:00
Gregor Jasny
f488aa6921
Fix off-by-one when terminating gcm_nonce (#1039)
The `gcm_nonce` character array is `12 + 1` chars long. Writing to
`gcm_nonce[12 + 1]` overflows the array by one char.
2022-10-24 22:35:09 +02:00
Gregor Jasny
6f14716149
Use %zu format specifier for size_t (#1040) 2022-10-24 22:34:48 +02:00
Gregor Jasny
24480b85b3
Fix variable argument handling (#1042) 2022-10-24 22:34:02 +02:00
Pavel Punsky
d72a2a8920
Cleanup openssl initialization (#1012)
Rewriting openssl initialization code (threading support to make it
cleaner

- Regroup functions so that there is one ifdef (for old code and new
code)
- Modern openssl (>1.0.2) does not need any synchornization routines so
they are empty
- Old openssl (<=1.0.2) now require `OPENSSL_THREADS` which allows
running multiple threads in turnserver. Not having turnserver
multi-threaded is a huge waste. `OPENSSL_THREADS` is now a requirement.


Test Plan:
- CI builds pass for openssl versions 1.0.2, 1.1.1, 3.0, including tests
2022-10-24 22:06:35 +02:00