mgw: Introduce VTY cmd 'rtp bind-ip-v6' command
This commit allows for fully IPv6 systems to work fine. However, if a
remote endpoint still wants to use IPv4, it will fail since at this
point osmo-mgw still doesn't re-bind the local end of the connection to
an IPv4 after having initially bound it to an IPv6 one. This kind of
scenarios get fixed in next commits.
TODO: really bind the socket if a different IP address is requested.
Change-Id: I8ed94bd3f674f498e6ba315f44a351fff9c1be15
diff --git a/src/libosmo-mgcp/mgcp_network.c b/src/libosmo-mgcp/mgcp_network.c
index 6ecb945..84f3604 100644
--- a/src/libosmo-mgcp/mgcp_network.c
+++ b/src/libosmo-mgcp/mgcp_network.c
@@ -102,9 +102,11 @@
char ipbuf[INET6_ADDRSTRLEN];
int rc;
endp = conn->conn->endp;
+ bool rem_addr_set = !addr_is_any(&conn->end.addr);
+ char *bind_addr;
/* Try probing the local IP-Address */
- if (endp->cfg->net_ports.bind_addr_probe && !addr_is_any(&conn->end.addr)) {
+ if (endp->cfg->net_ports.bind_addr_probe && rem_addr_set) {
rc = osmo_sock_local_ip(addr, osmo_sockaddr_ntop(&conn->end.addr.u.sa, ipbuf));
if (rc < 0)
LOGPCONN(conn->conn, DRTP, LOGL_ERROR,
@@ -118,21 +120,31 @@
}
/* Select from preconfigured IP-Addresses. We don't have bind_addr for Osmux (yet?). */
- if (endp->cfg->net_ports.bind_addr) {
+ if (rem_addr_set) {
/* Check there is a bind IP for the RTP traffic configured,
* if so, use that IP-Address */
- osmo_strlcpy(addr, endp->cfg->net_ports.bind_addr, INET6_ADDRSTRLEN);
+ bind_addr = conn->end.addr.u.sa.sa_family == AF_INET6 ?
+ endp->cfg->net_ports.bind_addr_v6 :
+ endp->cfg->net_ports.bind_addr_v4;
+ } else {
+ /* Choose any of the bind addresses, preferring v6 over v4 */
+ bind_addr = endp->cfg->net_ports.bind_addr_v6;
+ if (!bind_addr)
+ bind_addr = endp->cfg->net_ports.bind_addr_v4;
+ }
+ if (bind_addr) {
LOGPCONN(conn->conn, DRTP, LOGL_DEBUG,
"using configured rtp bind ip as local bind ip %s\n",
- addr);
+ bind_addr);
} else {
/* No specific bind IP is configured for the RTP traffic, so
* assume the IP where we listen for incoming MGCP messages
* as bind IP */
- osmo_strlcpy(addr, endp->cfg->source_addr, INET6_ADDRSTRLEN);
+ bind_addr = endp->cfg->source_addr;
LOGPCONN(conn->conn, DRTP, LOGL_DEBUG,
- "using mgcp bind ip as local rtp bind ip: %s\n", addr);
+ "using mgcp bind ip as local rtp bind ip: %s\n", bind_addr);
}
+ osmo_strlcpy(addr, bind_addr, INET6_ADDRSTRLEN);
}
/* This does not need to be a precision timestamp and
diff --git a/src/libosmo-mgcp/mgcp_vty.c b/src/libosmo-mgcp/mgcp_vty.c
index 8ea1cdd..aa27d41 100644
--- a/src/libosmo-mgcp/mgcp_vty.c
+++ b/src/libosmo-mgcp/mgcp_vty.c
@@ -71,9 +71,12 @@
vty_out(vty, " rtp port-range %u %u%s",
g_cfg->net_ports.range_start, g_cfg->net_ports.range_end,
VTY_NEWLINE);
- if (g_cfg->net_ports.bind_addr)
+ if (g_cfg->net_ports.bind_addr_v4)
vty_out(vty, " rtp bind-ip %s%s",
- g_cfg->net_ports.bind_addr, VTY_NEWLINE);
+ g_cfg->net_ports.bind_addr_v4, VTY_NEWLINE);
+ if (g_cfg->net_ports.bind_addr_v6)
+ vty_out(vty, " rtp bind-ip-v6 %s%s",
+ g_cfg->net_ports.bind_addr_v6, VTY_NEWLINE);
if (g_cfg->net_ports.bind_addr_probe)
vty_out(vty, " rtp ip-probing%s", VTY_NEWLINE);
else
@@ -500,12 +503,11 @@
DEFUN(cfg_mgcp_rtp_bind_ip,
cfg_mgcp_rtp_bind_ip_cmd,
- "rtp bind-ip " VTY_IPV46_CMD,
+ "rtp bind-ip A.B.C.D",
RTP_STR "Bind endpoints facing the Network\n"
- "IPv4 Address to bind to\n"
- "IPv6 Address to bind to\n")
+ "IPv4 Address to bind to\n")
{
- osmo_talloc_replace_string(g_cfg, &g_cfg->net_ports.bind_addr, argv[0]);
+ osmo_talloc_replace_string(g_cfg, &g_cfg->net_ports.bind_addr_v4, argv[0]);
return CMD_SUCCESS;
}
ALIAS_DEPRECATED(cfg_mgcp_rtp_bind_ip,
@@ -519,8 +521,8 @@
NO_STR RTP_STR "Bind endpoints facing the Network\n"
"Address to bind to\n")
{
- talloc_free(g_cfg->net_ports.bind_addr);
- g_cfg->net_ports.bind_addr = NULL;
+ talloc_free(g_cfg->net_ports.bind_addr_v4);
+ g_cfg->net_ports.bind_addr_v4 = NULL;
return CMD_SUCCESS;
}
ALIAS_DEPRECATED(cfg_mgcp_rtp_no_bind_ip,
@@ -529,6 +531,27 @@
NO_STR RTP_STR "Bind endpoints facing the Network\n"
"Address to bind to\n")
+DEFUN(cfg_mgcp_rtp_bind_ip_v6,
+ cfg_mgcp_rtp_bind_ip_v6_cmd,
+ "rtp bind-ip-v6 " VTY_IPV6_CMD,
+ RTP_STR "Bind endpoints facing the Network\n"
+ "IPv6 Address to bind to\n")
+{
+ osmo_talloc_replace_string(g_cfg, &g_cfg->net_ports.bind_addr_v6, argv[0]);
+ return CMD_SUCCESS;
+}
+
+DEFUN(cfg_mgcp_rtp_no_bind_ip_v6,
+cfg_mgcp_rtp_no_bind_ip_v6_cmd,
+"no rtp bind-ip-v6",
+NO_STR RTP_STR "Bind endpoints facing the Network\n"
+"Address to bind to\n")
+{
+ talloc_free(g_cfg->net_ports.bind_addr_v6);
+ g_cfg->net_ports.bind_addr_v6 = NULL;
+ return CMD_SUCCESS;
+}
+
DEFUN(cfg_mgcp_rtp_net_bind_ip_probing,
cfg_mgcp_rtp_net_bind_ip_probing_cmd,
"rtp ip-probing",
@@ -1527,8 +1550,10 @@
install_element(MGCP_NODE, &cfg_mgcp_rtp_port_range_cmd);
install_element(MGCP_NODE, &cfg_mgcp_rtp_net_bind_ip_cmd);
install_element(MGCP_NODE, &cfg_mgcp_rtp_bind_ip_cmd);
+ install_element(MGCP_NODE, &cfg_mgcp_rtp_bind_ip_v6_cmd);
install_element(MGCP_NODE, &cfg_mgcp_rtp_no_net_bind_ip_cmd);
install_element(MGCP_NODE, &cfg_mgcp_rtp_no_bind_ip_cmd);
+ install_element(MGCP_NODE, &cfg_mgcp_rtp_no_bind_ip_v6_cmd);
install_element(MGCP_NODE, &cfg_mgcp_rtp_net_bind_ip_probing_cmd);
install_element(MGCP_NODE, &cfg_mgcp_rtp_no_net_bind_ip_probing_cmd);
install_element(MGCP_NODE, &cfg_mgcp_rtp_ip_dscp_cmd);