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

Added option to ignore mDNS candidates #1998

Merged
merged 1 commit into from
Mar 17, 2020
Merged
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions conf/janus.jcfg.sample.in
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,14 @@ nat: {
#ice_lite = true
#ice_tcp = true

# By default Janus tries to resolve mDNS (.local) candidates: since
# this is currently done synchronously and might keep the API busy,
# especially in case mDNS resolution takes a long time to timeout,
# you can choose to drop all .local candidates instead, which is
# helpful in case you know clients will never be in the same private
# network as the one the Janus instance is running from.
#ignore_mdns = true

# In case you're deploying Janus on a server which is configured with
# a 1:1 NAT (e.g., Amazon EC2), you might want to also specify the public
# address of the machine using the setting below. This will result in
Expand Down
12 changes: 11 additions & 1 deletion ice.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ gboolean janus_ice_is_full_trickle_enabled(void) {
return janus_full_trickle_enabled;
}

/* mDNS resolution support */
static gboolean janus_mdns_enabled;
gboolean janus_ice_is_mdns_enabled(void) {
return janus_mdns_enabled;
}

/* IPv6 support (still mostly WIP) */
static gboolean janus_ipv6_enabled;
gboolean janus_ice_is_ipv6_enabled(void) {
Expand Down Expand Up @@ -784,10 +790,12 @@ void janus_ice_trickle_destroy(janus_ice_trickle *trickle) {


/* libnice initialization */
void janus_ice_init(gboolean ice_lite, gboolean ice_tcp, gboolean full_trickle, gboolean ipv6, uint16_t rtp_min_port, uint16_t rtp_max_port) {
void janus_ice_init(gboolean ice_lite, gboolean ice_tcp, gboolean full_trickle, gboolean ignore_mdns,
gboolean ipv6, uint16_t rtp_min_port, uint16_t rtp_max_port) {
janus_ice_lite_enabled = ice_lite;
janus_ice_tcp_enabled = ice_tcp;
janus_full_trickle_enabled = full_trickle;
janus_mdns_enabled = !ignore_mdns;
janus_ipv6_enabled = ipv6;
JANUS_LOG(LOG_INFO, "Initializing ICE stuff (%s mode, ICE-TCP candidates %s, %s-trickle, IPv6 support %s)\n",
janus_ice_lite_enabled ? "Lite" : "Full",
Expand Down Expand Up @@ -822,6 +830,8 @@ void janus_ice_init(gboolean ice_lite, gboolean ice_tcp, gboolean full_trickle,
JANUS_LOG(LOG_INFO, "ICE port range: %"SCNu16"-%"SCNu16"\n", rtp_range_min, rtp_range_max);
#endif
}
if(!janus_mdns_enabled)
JANUS_LOG(LOG_WARN, "mDNS resolution disabled, .local candidates will be ignored\n");

/* We keep track of plugin sessions to avoid problems */
plugin_sessions = g_hash_table_new_full(NULL, NULL, NULL, (GDestroyNotify)janus_plugin_session_dereference);
Expand Down
7 changes: 6 additions & 1 deletion ice.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@
* @param[in] ice_lite Whether the ICE Lite mode should be enabled or not
* @param[in] ice_tcp Whether ICE-TCP support should be enabled or not (only libnice >= 0.1.8, currently broken)
* @param[in] full_trickle Whether full-trickle must be used (instead of half-trickle)
* @param[in] ignore_mdns Whether mDNS candidates should be ignored, instead of resolved
* @param[in] ipv6 Whether IPv6 candidates must be negotiated or not
* @param[in] rtp_min_port Minimum port to use for RTP/RTCP, if a range is to be used
* @param[in] rtp_max_port Maximum port to use for RTP/RTCP, if a range is to be used */
void janus_ice_init(gboolean ice_lite, gboolean ice_tcp, gboolean full_trickle, gboolean ipv6, uint16_t rtp_min_port, uint16_t rtp_max_port);
void janus_ice_init(gboolean ice_lite, gboolean ice_tcp, gboolean full_trickle, gboolean ignore_mdns,
gboolean ipv6, uint16_t rtp_min_port, uint16_t rtp_max_port);
/*! \brief ICE stuff de-initialization */
void janus_ice_deinit(void);
/*! \brief Method to check whether a STUN server is reachable
Expand Down Expand Up @@ -119,6 +121,9 @@ gboolean janus_ice_is_ice_tcp_enabled(void);
/*! \brief Method to check whether full-trickle support is enabled or not
* @returns true if full-trickle support is enabled, false otherwise */
gboolean janus_ice_is_full_trickle_enabled(void);
/*! \brief Method to check whether mDNS resolution is enabled or not
* @returns true if mDNS resolution is enabled, false otherwise */
gboolean janus_ice_is_mdns_enabled(void);
/*! \brief Method to check whether IPv6 candidates are enabled/supported or not (still WIP)
* @returns true if IPv6 candidates are enabled/supported, false otherwise */
gboolean janus_ice_is_ipv6_enabled(void);
Expand Down
9 changes: 7 additions & 2 deletions janus.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ static json_t *janus_info(const char *transaction) {
json_object_set_new(info, "ice-lite", janus_ice_is_ice_lite_enabled() ? json_true() : json_false());
json_object_set_new(info, "ice-tcp", janus_ice_is_ice_tcp_enabled() ? json_true() : json_false());
json_object_set_new(info, "full-trickle", janus_ice_is_full_trickle_enabled() ? json_true() : json_false());
json_object_set_new(info, "mdns-enabled", janus_ice_is_mdns_enabled() ? json_true() : json_false());
json_object_set_new(info, "min-nack-queue", json_integer(janus_get_min_nack_queue()));
json_object_set_new(info, "twcc-period", json_integer(janus_get_twcc_period()));
if(janus_ice_get_stun_server() != NULL) {
Expand Down Expand Up @@ -4438,7 +4439,8 @@ gint main(int argc, char *argv[])
#endif
const char *nat_1_1_mapping = NULL;
uint16_t rtp_min_port = 0, rtp_max_port = 0;
gboolean ice_lite = FALSE, ice_tcp = FALSE, full_trickle = FALSE, ipv6 = FALSE, ignore_unreachable_ice_server = FALSE;
gboolean ice_lite = FALSE, ice_tcp = FALSE, full_trickle = FALSE, ipv6 = FALSE,
ignore_mdns = FALSE, ignore_unreachable_ice_server = FALSE;
item = janus_config_get(config, config_media, janus_config_type_item, "ipv6");
ipv6 = (item && item->value) ? janus_is_true(item->value) : FALSE;
item = janus_config_get(config, config_media, janus_config_type_item, "rtp_port_range");
Expand Down Expand Up @@ -4485,6 +4487,9 @@ gint main(int argc, char *argv[])
JANUS_LOG(LOG_WARN, "Invalid STUN port: %s (disabling STUN)\n", item->value);
stun_server = NULL;
}
/* Check if we should drop mDNS candidates */
item = janus_config_get(config, config_nat, janus_config_type_item, "ignore_mdns");
ignore_mdns = (item && item->value) ? janus_is_true(item->value) : FALSE;
/* Any 1:1 NAT mapping to take into account? */
item = janus_config_get(config, config_nat, janus_config_type_item, "nat_1_1_mapping");
if(item && item->value) {
Expand Down Expand Up @@ -4532,7 +4537,7 @@ gint main(int argc, char *argv[])
if(item && item->value)
janus_ice_set_static_event_loops(atoi(item->value));
/* Initialize the ICE stack now */
janus_ice_init(ice_lite, ice_tcp, full_trickle, ipv6, rtp_min_port, rtp_max_port);
janus_ice_init(ice_lite, ice_tcp, full_trickle, ignore_mdns, ipv6, rtp_min_port, rtp_max_port);
if(janus_ice_set_stun_server(stun_server, stun_port) < 0) {
if(!ignore_unreachable_ice_server) {
JANUS_LOG(LOG_FATAL, "Invalid STUN address %s:%u\n", stun_server, stun_port);
Expand Down
9 changes: 6 additions & 3 deletions sdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,12 @@ int janus_sdp_parse_candidate(void *ice_stream, const char *candidate, int trick
if(res >= 7) {
if(strstr(rip, ".local")) {
/* The IP is actually an mDNS address, try to resolve it
* https://tools.ietf.org/html/draft-ietf-rtcweb-mdns-ice-candidates-00 */
* https://tools.ietf.org/html/draft-ietf-rtcweb-mdns-ice-candidates-04 */
if(!janus_ice_is_mdns_enabled()) {
/* ...unless mDNS resolution is disabled, in which case ignore this candidate */
JANUS_LOG(LOG_VERB, "[%"SCNu64"] mDNS candidate ignored\n", handle->handle_id);
return 0;
}
struct addrinfo *info = NULL;
janus_network_address addr;
janus_network_address_string_buffer addr_buf;
Expand Down Expand Up @@ -798,13 +803,11 @@ int janus_sdp_parse_candidate(void *ice_stream, const char *candidate, int trick
added = nice_address_set_from_string(&c->base_addr, rrelip);
if(added)
nice_address_set_port(&c->base_addr, rrelport);

} else if(c->type == NICE_CANDIDATE_TYPE_RELAYED) {
/* FIXME Do we really need the base address for TURN? */
added = nice_address_set_from_string(&c->base_addr, rrelip);
if(added)
nice_address_set_port(&c->base_addr, rrelport);

}
if(!added) {
JANUS_LOG(LOG_WARN, "[%"SCNu64"] Invalid base address '%s', skipping %s candidate (%s)\n",
Expand Down