Commit graph

68 commits

Author SHA1 Message Date
Fabrice Bellet
7bd11cf01a conncheck: don't ignore local socket errors
With this patch we ensure that local socket errors during connection
establishment are properly transmitted to the connection check layer, so
the related pair can be put in state failed when needed. The local
socket errors we are interested in, are those occuring when the local
source address cannot be bound anymore, because the underlying interface
vanished for example.

In particular, we don't ignore errors coming from g_socket_bind() with
tcp active sockets, that perform a bind to *whatever* local address is
available, in case it cannot bind to the specified address.

This behaviour was demonstrated with the test-tcp example, that tried
to bind to the IPv4 loopback address on a socket initially created for
the IPv6 loopback.
2021-11-22 21:28:26 +00:00
Olivier Crête
69c2015cb5 Remove g_assert_cmp* macros outside of the unit tests 2021-11-01 22:22:32 -04:00
Olivier Crête
80c43a546b udp-turn: Remove request before freeing it
As removing the request from the queue looks into the SendRequest, one
needs to unqueue it before freeing it.
2021-05-03 18:42:43 -04:00
Fabrice Bellet
b353f30cfc udp-turn: don't allocate large arrays on the stack 2021-04-20 14:44:06 +00:00
Olivier Crête
1da0537b3b Use g_assert_cmp.int() to get better debug logs on crash 2020-05-05 20:04:00 -04:00
Olivier Crête
bd14e25681 udp-bsd: Check all return value
Errors found by coverity
2020-02-12 19:45:32 -05:00
alex
1ff29177d4 Assign source out of the for loop 2019-06-05 11:45:17 +02:00
alex
083ac5a95c Fix regression introduced by da41258a21. Fix . 2019-06-05 09:26:59 +00:00
Olivier Crête
df5b9e64c2 turn: Replace magic numbers with define 2019-01-22 18:48:24 -05:00
Jakub Adam
6b1eec0630 udp-turn: Avoid potential integer overflow 2019-01-04 23:40:18 +00:00
Jakub Adam
603ab1d45d udp-turn: Fix unaligned memory access on ARM 2019-01-04 23:40:18 +00:00
Olivier Crête
3c29a99cac udp-turn: Create locked version of realm&nonce cache function
To be able to call it from a context that is already locked.
2018-11-19 09:05:13 +00:00
Jakub Adam
d79d117911 udp-turn: handle multiple RFC4571 frames received in a TCP-TURN message
There might be multiple RFC4571-framed messages (or fragments thereof)
within a single TCP-TURN message. Make sure each NiceInputMessage
passed by the user into socket_recv_messages() gets exactly one RFC4571
frame, or remains empty if there aren't any messages to receive.

We should keep any data that doesn't fit into the user buffers for
the next time socket_recv_messages() gets called with the socket.
2018-10-31 12:45:16 +01:00
Jakub Adam
5aa499206c udp-turn: don't re-iterate incoming TURN control messages
After being parsed, a TURN control message turns into a NiceInputMessage
with zero length. Such message doesn't increment the iteration counter i
and so is re-processed in the next iteration, which detects right away
that message->length == 0 and continues to the next element in
recv_messages.

Thus, n_valid_messages variable serves no real purpose and to achieve
the same result we can simply increment the iteration counter after each
message.
2018-10-31 12:45:16 +01:00
Olivier Crête
67771ba2a3 udp-turn: Start function with lock instead of unlock 2018-10-31 11:44:16 +00:00
Olivier Crête
d1611c0c0b udp-turn: Restore global locks
The socket abstraction not being reference counted, we need a global
lock for them in the short term.
2018-10-28 16:32:27 +00:00
Olivier Crête
cc5bca828c udp-turn: Rename misleading function, it's a timeout
It's not locked in any way.
2018-10-28 16:15:02 +00:00
Olivier Crête
37d6d00fbf udp-turn: Factor our SendRequest destruction 2018-10-28 16:09:55 +00:00
Olivier Crête
d2cdf2e284 udp-turn: Restore synchronized seconds timeout 2018-10-28 15:19:02 +00:00
Juan Navarro
da41258a21 Use per-agent locks and GWeakRefs in callbacks from timeout sources
Work on libnice's bug  in Gitlab. This work is composed of multiple
merged parts:

- "Global lock contention removed"
Phabricator D1900: https://phabricator.freedesktop.org/D1900
By @nifigase
Opened in GitLab as Merge Request 

- "agent: properly handle NiceAgent ref in callbacks from timeout
sources"
Phabricator D1898: https://phabricator.freedesktop.org/D1898
By @mparis
This patch was itself based upon a previous version of the work done in
D1900. After the switch of hosting, it got lost.

On top of these, additions to follow some review comments from @ocrete:
- https://phabricator.freedesktop.org/D1900#40412
- https://phabricator.freedesktop.org/D1898#39332
2018-10-28 14:47:32 +00:00
Nicolas Dufresne
23b5926885 Fix cast-function-type warning introduced in GCC 8
This is new warning introduced with GCC 8. This is being fixed by using appropriate function, like g_queue_free_full/g_list_free_full or by casting to GCallback before casting to the target function signature.

Closes: 
2018-06-12 16:57:03 +02:00
Olivier Crête
cd255bddc7 udp-turn: Add some const to internal APIs 2017-04-04 18:46:07 -04:00
Olivier Crête
db05e8b0fd Make clang-analyzer happy
Various little things, none of which should make a functional difference.
2017-04-04 13:29:01 -04:00
Olivier Crête
68ff86f942 stun: Use unions fix alignment issues
This makes clang happy.
2017-04-03 12:11:55 -04:00
Olivier Crête
b58e852de6 socket: Assert trying to use free'd socket
Cleanly returnign makes no sense and may hide
worse problems.
2016-06-02 19:23:49 -04:00
Olivier Crête
1513ce23ff Replace g_malloc/g_new with g_alloca where possible
This should reduce the overhead a bit.
2016-05-30 15:41:20 -04:00
Olivier Crête
8ee6d1bbed udp-turn: Fix binding timeout leak 2016-05-26 16:08:35 -04:00
Olivier Crête
0a6c779f1f udp-turn: Don't expose GSocket
UDP turn sockets should never be read frm directly.
Because they may share the same socket with the non-relay,
so the incoming data may not be relayed and then the NiceSocket
API doesn't allow returning the base socket as the source.
2016-05-26 16:03:54 -04:00
Olivier Crête
501f9a82e4 turn: Cache the nonce & realm to remove useless round trips
Instead of re-discovering the nonce and realm for every request, cache them
in th socket.
2016-05-26 15:28:17 -04:00
Jakub Adam
e0ed4fb3a2 socket: refactor nice_socket_is_base_of()
• rename to nice_socket_is_based_on() and swap the order of arguments
   accordingly; the implementation doesn't have to use the confusing
   'return other->is_base_of()' pattern anymore
 • fix potential NULL dereferences

The argument order in agent_recv_message_unlocked() was already wrongly
swapped in 1732c7d6 and thus this commit isn't changing it back because
that order has become the correct one.

Reviewed-by: Philip Withnall <philip.withnall@collabora.co.uk>
Differential Revision: https://phabricator.freedesktop.org/D866
2016-04-04 21:54:02 +01:00
Philip Withnall
80973c096d conncheck: add more debug information
Add a more debug details, specifically in some places, it is interesting
to have the src and dst IP addresses of the pairs being checked, and
also to make the difference between log related to different stream ids.

Reviewed-by: Philip Withnall <philip@tecnocode.co.uk>
Differential Revision: https://phabricator.freedesktop.org/D803
2016-03-01 22:28:48 +00:00
Jakub Adam
837c8953fe socket: add nice_socket_is_base_of()
This will be used in the next commit.

Maniphest Tasks: T114
Reviewed-by: Philip Withnall <philip.withnall@collabora.co.uk>
Differential Revision: https://phabricator.freedesktop.org/D240
2015-09-11 11:30:23 +01:00
Jakub Adam
ab4ced5a46 ms-turn: don't wait for a reply to STUN_SEND request
As per [MS-TURN] Section 2.2.1, TURN message type 0x0104 "Send request
response" isn't supported and the TURN server MUST NOT send them. Thus,
libnice should not remember Send requests in agent->sent_ids because
without replies coming, the number of allowed pending transaction gets
quickly exhausted, causing our data packets to be dropped until a
request timeout frees some space in the queue.

This behavior resulted in choppy reception of our audio on a Lync client
when connected via Lync Edge (TURN) Server.

Maniphest Tasks: T126

Reviewers: pwithnall

Projects: #libnice

Reviewed By: pwithnall

Subscribers: pwithnall

Differential Revision: https://phabricator.freedesktop.org/D223
2015-09-02 16:33:22 +01:00
Olivier Crête
c4d5ec572a Split "verbose" on-every-packet messages to a verbose log
This way, the regular log will only contain connection-time information.
2015-06-24 14:50:16 +01:00
Olivier Crête
39ff48d40f udp-turn: Don't dereference priv before check that it's valid 2014-10-09 17:17:21 -04:00
Philip Withnall
34502d67f3 socket: Fix a leak on the slow TURN packet handling path 2014-09-23 15:20:56 +01:00
Philip Withnall
b80bc3a17f socket: Return early from socket functions if the socket is closed
Explicitly check whether the socket is closed (universally represented
as sock->priv == NULL) before doing anything else in the socket methods.
This should safely return from unusual situations where the socket has
been closed and part-destroyed but still ends up having send() or recv()
called on it.
2014-09-02 13:54:32 +01:00
Youness Alaoui
5ab7c88349 Fix timer for TURN CreatePermission.
The TURN CreatePermission is a list of multiple permissions but the timer
is created and overwrites the old one, so some of them don't get triggered
at the right time.
This patch was suggested by Livio Madaro. We create a timer for the minimal
amount of time, and trigger the retransmissions on the permissions that
timed out, then reschedule for the next retransmissions.
2014-07-22 21:11:46 -04:00
Youness Alaoui
dfba87d08e Add a nice_socket_can_send and nice_socket_set_writable_callback APIs 2014-05-17 00:22:36 -04:00
Youness Alaoui
c6ba5a2497 Move the rfc4571 handling for OC2007 into udp-turn
In the case of OC2007, we must consider that the turn control messages
are framed with rfc4571 and udp-turn-over-tcp only adds a single guint16
to represent turn-control or end-to-end indication. Otherwise, we will
have issues with double-framing when we do the allocate directly on
the udp-turn-over-tcp but we'd have no framing once we add the udp-turn
socket layer on top of udp-turn-over-tcp
2014-05-17 00:22:36 -04:00
Youness Alaoui
9eaa6d5cae Wrap socket_send in udp-turn to avoid if/else on reliable everywhere 2014-05-17 00:22:36 -04:00
Youness Alaoui
6263028ed2 Rename turn files and API to be UDP specific
The TURN-TCP RFC is very different from TURN-UDP, the current turn and tcp-turn
files were only for UDP TURN RFC and UDP TURN using TCP transport.
When we implement TCP-TURN, we'll need a different algorithm, so I
renamed the files and API to avoid any confusion.
2014-05-15 09:44:00 -04:00
Youness Alaoui
0cf65d142c Socket layer refactorising and adding of tcp-bsd, pseudossl, and moved the tcp stuff from tcp-turn and made udp-turn into turn since it's generic 2008-12-08 15:35:14 -05:00
Youness Alaoui
580afc6c8a use nice_address_new and nice_address_free instead of g_new0 and g_free 2008-11-12 19:59:01 -05:00
Youness Alaoui
ae614812cf make nice_socket_send return a boolean so we can know whether or not the send worked 2008-11-04 16:19:47 -05:00
Youness Alaoui
b4246f0481 Replace all references to 3489BIS into RFC 5389 as it has just been released 2008-11-03 17:00:06 -05:00
Youness Alaoui
50455d76f1 Fix includes for win32 compilation 2008-11-03 16:34:05 -05:00
Youness Alaoui
753b61bd69 Add an else to HAVE_CONFIG_H in order to define NICEAPI_EXPORT. Also removed that define from not public functions and removed them from libnice.sym 2008-11-03 16:30:05 -05:00
Youness Alaoui
7def93cf33 use socklen_t where needed, and cast it to size_t as it defined as an int in mingw and as an uint on linux systems 2008-10-28 19:01:12 -04:00
Youness Alaoui
7e4bf0eefc remove unnecessary inclusion of socket files in some files, and make glib included before stdlib.h because it redefines atexit 2008-10-28 18:59:55 -04:00