pespin has submitted this change. (
https://gerrit.osmocom.org/c/osmo-mgw/+/39180?usp=email )
Change subject: mgcp-cli: Fix filling in wrong local IP address of SDP Origin o=
......................................................................
mgcp-cli: Fix filling in wrong local IP address of SDP Origin o=
If user (VTY) configured the local IP address to use for MGCP, and that
IP address was not the one selected by kernel routing table lookup, the
IP address filled in the MGCP message would be wrong, not matching the
one sending the MGCP message.
Change-Id: I35624db853dc1f0fee85503105960613f70473c6
---
M src/libosmo-mgcp-client/mgcp_client.c
1 file changed, 34 insertions(+), 7 deletions(-)
Approvals:
Jenkins Builder: Verified
fixeria: Looks good to me, approved
laforge: Looks good to me, but someone else must approve
diff --git a/src/libosmo-mgcp-client/mgcp_client.c
b/src/libosmo-mgcp-client/mgcp_client.c
index 1c89e69..8a7c1f6 100644
--- a/src/libosmo-mgcp-client/mgcp_client.c
+++ b/src/libosmo-mgcp-client/mgcp_client.c
@@ -1320,6 +1320,36 @@
#undef MSGB_PRINTF_OR_RET
}
+/* Helper function to obtain local IP address used in MGCP towards MGW,
+ * in string format, to fill the SDP "Origin" ("o=") field.
+ * return 0 on success, negative on error.
+ */
+static int get_mgcp_local_addr(const struct mgcp_client *mgcp, char *local_ip, size_t
local_ip_len)
+{
+ int fd;
+
+ /* Try to get the socket local IP address if available: */
+ if (mgcp->iofd && ((fd = osmo_iofd_get_fd(mgcp->iofd)) >= 0)) {
+ if (osmo_sock_get_local_ip(fd, local_ip, local_ip_len) == 0)
+ return 0;
+ /* else: continue below */
+ }
+
+ /* If MGCP local address was explicitly specified in config, use it: */
+ if (mgcp->actual.local_addr) {
+ osmo_strlcpy(local_ip, mgcp->actual.local_addr, local_ip_len);
+ return 0;
+ }
+
+ /* Guess our local address based on system routing towards MGW: */
+ OSMO_ASSERT(local_ip_len >= INET6_ADDRSTRLEN);
+ if (osmo_sock_local_ip(local_ip, mgcp->actual.remote_addr) == 0)
+ return 0;
+
+ LOGPMGW(mgcp, LOGL_ERROR, "Could not determine local IP-Address!\n");
+ return -EINVAL;
+}
+
/* Helper function for mgcp_msg_gen(): Add SDP information to MGCP message */
static int add_sdp(struct msgb *msg, struct mgcp_msg *mgcp_msg, struct mgcp_client
*mgcp)
{
@@ -1329,6 +1359,7 @@
const char *codec;
unsigned int pt;
uint16_t audio_port;
+ int rc;
#define MSGB_PRINTF_OR_RET(FMT, ARGS...) do { \
if (msgb_printf(msg, FMT, ##ARGS) != 0) { \
@@ -1344,13 +1375,9 @@
MSGB_PRINTF_OR_RET("v=0\r\n");
/* Determine local IP-Address */
- if (mgcp->actual.local_addr) {
- OSMO_STRLCPY_ARRAY(local_ip, mgcp->actual.local_addr);
- } else if (osmo_sock_local_ip(local_ip, mgcp->actual.remote_addr) < 0) {
- LOGPMGW(mgcp, LOGL_ERROR,
- "Could not determine local IP-Address!\n");
- return -EINVAL;
- }
+ rc = get_mgcp_local_addr(mgcp, local_ip, sizeof(local_ip));
+ if (rc < 0)
+ return rc;
local_ip_family = osmo_ip_str_type(local_ip);
if (local_ip_family == AF_UNSPEC)
return -EINVAL;
--
To view, visit
https://gerrit.osmocom.org/c/osmo-mgw/+/39180?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: osmo-mgw
Gerrit-Branch: master
Gerrit-Change-Id: I35624db853dc1f0fee85503105960613f70473c6
Gerrit-Change-Number: 39180
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>