Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if IPv6 is disabled when loading the Streaming plugin (fixes #3470) #3519

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/plugins/janus_streaming.c
Original file line number Diff line number Diff line change
Expand Up @@ -1239,6 +1239,7 @@ static janus_mutex config_mutex = JANUS_MUTEX_INITIALIZER;
static volatile gint initialized = 0, stopping = 0;
static gboolean notify_events = TRUE;
static gboolean string_ids = FALSE;
static gboolean ipv6_disabled = FALSE;
static janus_callbacks *gateway = NULL;
static GThread *handler_thread;
static void *janus_streaming_handler(void *data);
Expand Down Expand Up @@ -1995,6 +1996,21 @@ int janus_streaming_init(janus_callbacks *callback, const char *config_path) {
if(config != NULL)
janus_config_print(config);

/* Let's check if IPv6 is disabled, as we may need when creating sockets */
int fd = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
if(fd < 0) {
ipv6_disabled = TRUE;
} else {
int v6only = 0;
if(setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &v6only, sizeof(v6only)) != 0)
ipv6_disabled = TRUE;
}
if(fd >= 0)
close(fd);
if(ipv6_disabled) {
JANUS_LOG(LOG_WARN, "IPv6 disabled, will only use IPv4 sockets for mountpoints\n");
}

/* Threads will expect this to be set */
g_atomic_int_set(&initialized, 1);

Expand Down Expand Up @@ -7211,7 +7227,8 @@ static int janus_streaming_create_fd(int port, in_addr_t mcast, const janus_netw

int fd = -1, family = 0;
while(1) {
family = 0; /* By default, we bind to both IPv4 and IPv6 */
/* By default, we bind to both IPv4 and IPv6, unless IPv6 is disabled */
family = ipv6_disabled ? AF_INET : 0;
if(use_range && rtp_port_wrap && rtp_port_next >= rtp_port_start) {
/* Full range scanned */
JANUS_LOG(LOG_ERR, "No ports available for RTP/RTCP in range: %u -- %u\n",
Expand Down Expand Up @@ -7308,6 +7325,10 @@ static int janus_streaming_create_fd(int port, in_addr_t mcast, const janus_netw
if(host && hostlen > 0)
g_strlcpy(host, janus_network_address_string_from_buffer(&address_representation), hostlen);
} else if(iface->family == AF_INET6) {
if(ipv6_disabled) {
JANUS_LOG(LOG_ERR, "[%s] Can't bind to IPv6 address, IPv6 is disabled\n", mountpointname);
continue;
}
memcpy(&address6.sin6_addr, &iface->ipv6, sizeof(iface->ipv6));
(void) janus_network_address_to_string_buffer(iface, &address_representation); /* This is OK: if we get here iface must be non-NULL */
JANUS_LOG(LOG_INFO, "[%s] %s listener restricted to interface address: %s\n",
Expand Down