зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1189040: add a whitelist for network interfaces to use with ICE/webrtc r=ekr
This commit is contained in:
Родитель
e92a0a38f4
Коммит
efb47b11df
|
@ -435,6 +435,7 @@ RefPtr<NrIceCtx> NrIceCtx::Create(const std::string& name,
|
|||
int32_t ice_trickle_grace_period = 5000;
|
||||
int32_t ice_tcp_so_sock_count = 3;
|
||||
int32_t ice_tcp_listen_backlog = 10;
|
||||
nsAutoCString force_net_interface;
|
||||
#ifndef MOZILLA_XPCOMRT_API
|
||||
nsresult res;
|
||||
nsCOMPtr<nsIPrefService> prefs =
|
||||
|
@ -455,6 +456,9 @@ RefPtr<NrIceCtx> NrIceCtx::Create(const std::string& name,
|
|||
branch->GetIntPref(
|
||||
"media.peerconnection.ice.tcp_listen_backlog",
|
||||
&ice_tcp_listen_backlog);
|
||||
branch->GetCharPref(
|
||||
"media.peerconnection.ice.force_interface",
|
||||
getter_Copies(force_net_interface));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -478,6 +482,11 @@ RefPtr<NrIceCtx> NrIceCtx::Create(const std::string& name,
|
|||
if (allow_link_local) {
|
||||
NR_reg_set_char((char *)NR_STUN_REG_PREF_ALLOW_LINK_LOCAL_ADDRS, 1);
|
||||
}
|
||||
if (force_net_interface.Length() > 0) {
|
||||
// Stupid cast.... but needed
|
||||
const nsCString& flat = PromiseFlatCString(static_cast<nsACString&>(force_net_interface));
|
||||
NR_reg_set_string((char *)NR_ICE_REG_PREF_FORCE_INTERFACE_NAME, const_cast<char*>(flat.get()));
|
||||
}
|
||||
}
|
||||
|
||||
// Create the ICE context
|
||||
|
|
|
@ -316,7 +316,7 @@ int nr_ice_fetch_turn_servers(int ct, nr_ice_turn_server **out)
|
|||
}
|
||||
#endif /* USE_TURN */
|
||||
|
||||
#define MAXADDRS 100 // Ridiculously high
|
||||
#define MAXADDRS 100 /* Ridiculously high */
|
||||
int nr_ice_ctx_create(char *label, UINT4 flags, nr_ice_ctx **ctxp)
|
||||
{
|
||||
nr_ice_ctx *ctx=0;
|
||||
|
@ -400,6 +400,14 @@ int nr_ice_ctx_create(char *label, UINT4 flags, nr_ice_ctx **ctxp)
|
|||
if (r=nr_socket_factory_create_int(NULL, &default_socket_factory_vtbl, &ctx->socket_factory))
|
||||
ABORT(r);
|
||||
|
||||
if ((r=NR_reg_get_string((char *)NR_ICE_REG_PREF_FORCE_INTERFACE_NAME, ctx->force_net_interface, sizeof(ctx->force_net_interface)))) {
|
||||
if (r == R_NOT_FOUND) {
|
||||
ctx->force_net_interface[0] = 0;
|
||||
} else {
|
||||
ABORT(r);
|
||||
}
|
||||
}
|
||||
|
||||
STAILQ_INIT(&ctx->streams);
|
||||
STAILQ_INIT(&ctx->sockets);
|
||||
STAILQ_INIT(&ctx->foundations);
|
||||
|
@ -492,7 +500,7 @@ void nr_ice_gather_finished_cb(NR_SOCKET s, int h, void *cb_arg)
|
|||
|
||||
ctx->uninitialized_candidates--;
|
||||
|
||||
// Avoid the need for yet another initialization function
|
||||
/* Avoid the need for yet another initialization function */
|
||||
if (cand->state == NR_ICE_CAND_STATE_INITIALIZING && cand->type == HOST)
|
||||
cand->state = NR_ICE_CAND_STATE_INITIALIZED;
|
||||
|
||||
|
@ -640,6 +648,23 @@ static int nr_ice_get_local_addresses(nr_ice_ctx *ctx)
|
|||
ABORT(r);
|
||||
}
|
||||
|
||||
if (ctx->force_net_interface[0]) {
|
||||
/* Limit us to only addresses on a single interface */
|
||||
int force_addr_ct = 0;
|
||||
for(i=0;i<addr_ct;i++){
|
||||
if (!strcmp(local_addrs[i].addr.ifname, ctx->force_net_interface)) {
|
||||
// copy it down in the array, if needed
|
||||
if (i != force_addr_ct) {
|
||||
if (r=nr_local_addr_copy(&local_addrs[force_addr_ct], &local_addrs[i])) {
|
||||
ABORT(r);
|
||||
}
|
||||
}
|
||||
force_addr_ct++;
|
||||
}
|
||||
}
|
||||
addr_ct = force_addr_ct;
|
||||
}
|
||||
|
||||
if (ctx->flags & NR_ICE_CTX_FLAGS_ONLY_DEFAULT_ADDRS) {
|
||||
/* Get just the default IPv4 and IPv6 addrs */
|
||||
if(!nr_ice_get_default_local_address(ctx, NR_IPV4, local_addrs, addr_ct,
|
||||
|
@ -801,8 +826,6 @@ static int nr_ice_random_string(char *str, int len)
|
|||
|
||||
if(needed>sizeof(bytes)) ABORT(R_BAD_ARGS);
|
||||
|
||||
//memset(bytes,0,needed);
|
||||
|
||||
if(r=nr_crypto_random_bytes(bytes,needed))
|
||||
ABORT(r);
|
||||
|
||||
|
@ -930,4 +953,3 @@ int nr_ice_ctx_hide_candidate(nr_ice_ctx *ctx, nr_ice_candidate *cand)
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -150,6 +150,8 @@ struct nr_ice_ctx_ {
|
|||
|
||||
nr_ice_trickle_candidate_cb trickle_cb;
|
||||
void *trickle_cb_arg;
|
||||
|
||||
char force_net_interface[MAXIFNAME];
|
||||
};
|
||||
|
||||
int nr_ice_ctx_create(char *label, UINT4 flags, nr_ice_ctx **ctxp);
|
||||
|
|
|
@ -70,6 +70,8 @@ extern "C" {
|
|||
#define NR_ICE_REG_KEEPALIVE_TIMER "ice.keepalive_timer"
|
||||
|
||||
#define NR_ICE_REG_TRICKLE_GRACE_PERIOD "ice.trickle_grace_period"
|
||||
#define NR_ICE_REG_PREF_FORCE_INTERFACE_NAME "ice.forced_interface_name"
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
|
|
@ -398,6 +398,7 @@ pref("media.peerconnection.default_iceservers", "[]");
|
|||
pref("media.peerconnection.ice.loopback", false); // Set only for testing in offline environments.
|
||||
pref("media.peerconnection.ice.tcp", false);
|
||||
pref("media.peerconnection.ice.link_local", false); // Set only for testing IPV6 in networks that don't assign IPV6 addresses
|
||||
pref("media.peerconnection.ice.force_interface", ""); // Limit to only a single interface
|
||||
pref("media.peerconnection.ice.relay_only", false); // Limit candidates to TURN
|
||||
pref("media.peerconnection.use_document_iceservers", true);
|
||||
pref("media.peerconnection.identity.enabled", true);
|
||||
|
|
Загрузка…
Ссылка в новой задаче