[Asterisk-code-review] res_rtp_asterisk: Add ability to propose local address in ICE (...asterisk[13])
George Joseph
asteriskteam at digium.com
Wed May 22 12:46:41 CDT 2019
George Joseph has submitted this change and it was merged. ( https://gerrit.asterisk.org/c/asterisk/+/11388 )
Change subject: res_rtp_asterisk: Add ability to propose local address in ICE
......................................................................
res_rtp_asterisk: Add ability to propose local address in ICE
You can now add the "include_local_address" flag to an entry in
rtp.conf "[ice_host_candidates]" to include both the advertized
address and the local address in ICE negotiation:
[ice_host_candidates]
192.168.1.1 = 1.2.3.4,include_local_address
This causes both 192.168.1.1 and 1.2.3.4 to be advertized.
Change-Id: Ide492cd45ce84546175ca7d557de80d9770513db
---
M configs/samples/rtp.conf.sample
A doc/CHANGES-staging/rtp_ice_include_local_address.txt
M res/res_rtp_asterisk.c
3 files changed, 33 insertions(+), 3 deletions(-)
Approvals:
Joshua Colp: Looks good to me, but someone else must approve
Benjamin Keith Ford: Looks good to me, but someone else must approve
George Joseph: Looks good to me, approved; Approved for Submit
diff --git a/configs/samples/rtp.conf.sample b/configs/samples/rtp.conf.sample
index 26a70d2..a2664e4 100644
--- a/configs/samples/rtp.conf.sample
+++ b/configs/samples/rtp.conf.sample
@@ -118,13 +118,19 @@
;
; The format for these overrides is:
;
-; <local address> => <advertised address>
+; <local address> => <advertised address>,[include_local_address]
;
; The following will replace 192.168.1.10 with 1.2.3.4 during ICE
; negotiation:
;
;192.168.1.10 => 1.2.3.4
;
+; The following will include BOTH 192.168.1.10 and 1.2.3.4 during ICE
+; negotiation instead of replacing 192.168.1.10. This can make it easier
+; to serve both local and remote clients.
+;
+;192.168.1.10 => 1.2.3.4,include_local_address
+;
; You can define an override for more than 1 interface if you have a multihomed
; server. Any local interface that is not matched will be passed through
; unaltered. Both IPv4 and IPv6 addresses are supported.
diff --git a/doc/CHANGES-staging/rtp_ice_include_local_address.txt b/doc/CHANGES-staging/rtp_ice_include_local_address.txt
new file mode 100644
index 0000000..e5a65e5
--- /dev/null
+++ b/doc/CHANGES-staging/rtp_ice_include_local_address.txt
@@ -0,0 +1,5 @@
+Subject: RTP/ICE
+
+You can now indicate that you'd like an ice_host_candidate's local address
+to be published as well as the mapped address. See the sample rtp.conf
+for more information.
diff --git a/res/res_rtp_asterisk.c b/res/res_rtp_asterisk.c
index e384c23..efffeec 100644
--- a/res/res_rtp_asterisk.c
+++ b/res/res_rtp_asterisk.c
@@ -244,6 +244,7 @@
struct ast_ice_host_candidate {
pj_sockaddr local;
pj_sockaddr advertised;
+ unsigned int include_local;
AST_RWLIST_ENTRY(ast_ice_host_candidate) next;
};
@@ -543,21 +544,26 @@
}
/*! \brief Applies the ICE host candidate mapping */
-static void host_candidate_overrides_apply(unsigned int count, pj_sockaddr addrs[])
+static unsigned int host_candidate_overrides_apply(unsigned int count, unsigned int max_count, pj_sockaddr addrs[])
{
int pos;
struct ast_ice_host_candidate *candidate;
+ unsigned int added = 0;
AST_RWLIST_RDLOCK(&host_candidates);
for (pos = 0; pos < count; pos++) {
AST_LIST_TRAVERSE(&host_candidates, candidate, next) {
if (!pj_sockaddr_cmp(&candidate->local, &addrs[pos])) {
pj_sockaddr_copy_addr(&addrs[pos], &candidate->advertised);
+ if (candidate->include_local && (count + (++added)) <= max_count) {
+ pj_sockaddr_cp(&addrs[count + (added - 1)], &candidate->local);
+ }
break;
}
}
}
AST_RWLIST_UNLOCK(&host_candidates);
+ return added;
}
/*! \brief Helper function which updates an ast_sockaddr with the candidate used for the component */
@@ -2954,6 +2960,7 @@
{
pj_sockaddr address[PJ_ICE_MAX_CAND];
unsigned int count = PJ_ARRAY_SIZE(address), pos = 0;
+ unsigned int max_count = PJ_ARRAY_SIZE(address);
int basepos = -1;
/* Add all the local interface IP addresses */
@@ -2965,7 +2972,7 @@
pj_enum_ip_interface(pj_AF_INET6(), &count, address);
}
- host_candidate_overrides_apply(count, address);
+ count += host_candidate_overrides_apply(count, max_count, address);
for (pos = 0; pos < count; pos++) {
if (!rtp_address_is_ice_blacklisted(&address[pos])) {
@@ -6744,6 +6751,8 @@
for (var = ast_variable_browse(cfg, "ice_host_candidates"); var; var = var->next) {
struct ast_sockaddr local_addr, advertised_addr;
pj_str_t address;
+ unsigned int include_local_address = 0;
+ char *sep;
ast_sockaddr_setnull(&local_addr);
ast_sockaddr_setnull(&advertised_addr);
@@ -6753,6 +6762,14 @@
continue;
}
+ sep = strchr(var->value,',');
+ if (sep) {
+ *sep = '\0';
+ sep++;
+ sep = ast_skip_blanks(sep);
+ include_local_address = strcmp(sep, "include_local_address") == 0;
+ }
+
if (ast_parse_arg(var->value, PARSE_ADDR | PARSE_PORT_IGNORE, &advertised_addr)) {
ast_log(LOG_WARNING, "Invalid advertised ICE host address: %s\n", var->value);
continue;
@@ -6763,6 +6780,8 @@
break;
}
+ candidate->include_local = include_local_address;
+
pj_sockaddr_parse(pj_AF_UNSPEC(), 0, pj_cstr(&address, ast_sockaddr_stringify(&local_addr)), &candidate->local);
pj_sockaddr_parse(pj_AF_UNSPEC(), 0, pj_cstr(&address, ast_sockaddr_stringify(&advertised_addr)), &candidate->advertised);
--
To view, visit https://gerrit.asterisk.org/c/asterisk/+/11388
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Change-Id: Ide492cd45ce84546175ca7d557de80d9770513db
Gerrit-Change-Number: 11388
Gerrit-PatchSet: 1
Gerrit-Owner: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Benjamin Keith Ford <bford at digium.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Sean Bright <sean.bright at gmail.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20190522/706fae5a/attachment-0001.html>
More information about the asterisk-code-review
mailing list