From faac387ce9f5b05c6e1d7035e2a9379266ff722e Mon Sep 17 00:00:00 2001 From: StefanBruens Date: Fri, 10 Apr 2020 18:44:13 +0000 Subject: [PATCH] raop: Send initial timing packet to prime UDP connection tracking In case the local UDP port is blocked by a firewall by default, send an initial timing packet so the connection tracking will accept the response packages. Otherwise, the connection will fail with an 'RTSP/1.0 500 Internal Server Error' after some timeout. Fixes: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/issues/840 --- src/modules/raop/raop-client.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/modules/raop/raop-client.c b/src/modules/raop/raop-client.c index 9a026db24..85dea55e5 100644 --- a/src/modules/raop/raop-client.c +++ b/src/modules/raop/raop-client.c @@ -681,6 +681,18 @@ static size_t handle_udp_timing_packet(pa_raop_client *c, const uint8_t packet[] return written; } +static void send_initial_udp_timing_packet(pa_raop_client *c) { + uint32_t data[6] = { 0 }; + struct timeval tv; + uint64_t initial_time = 0; + + initial_time = timeval_to_ntp(pa_rtclock_get(&tv)); + data[4] = htonl(initial_time >> 32); + data[5] = htonl(initial_time & 0xffffffff); + + send_udp_timing_packet(c, data, initial_time); +} + static int connect_udp_socket(pa_raop_client *c, int fd, uint16_t port) { struct sockaddr_in sa4; #ifdef HAVE_IPV6 @@ -1077,6 +1089,13 @@ connect_finish: pa_log_debug("Connection established (UDP;control_port=%d;timing_port=%d)", cport, tport); + /* Send an initial UDP packet so a connection tracking firewall + * knows the src_ip:src_port <-> dest_ip:dest_port relation + * and accepts the incoming timing packets. + */ + send_initial_udp_timing_packet(c); + pa_log_debug("Sent initial timing packet to UDP port %d", tport); + if (c->state_callback) c->state_callback(PA_RAOP_CONNECTED, c->state_userdata); }