From c4ef4a21c67a2e96f7f217862b28b66bbcfe15c6 Mon Sep 17 00:00:00 2001 From: Pau Espin Pedrol Date: Wed, 2 Sep 2020 17:00:12 +0200 Subject: [PATCH] mgcp_client: Support validating IPv6 addresses in CRCX and MDCX commands Change-Id: Ie97675f173dc3a223f6c2ced913906d760ffb732 --- src/libosmo-mgcp-client/mgcp_client_fsm.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/libosmo-mgcp-client/mgcp_client_fsm.c b/src/libosmo-mgcp-client/mgcp_client_fsm.c index e38a4ba9a..2505ff281 100644 --- a/src/libosmo-mgcp-client/mgcp_client_fsm.c +++ b/src/libosmo-mgcp-client/mgcp_client_fsm.c @@ -25,6 +25,7 @@ #include #include #include +#include /* Context information, this is attached to the priv pointer of the FSM and * is also handed back when dispatcheing events to the parent FSM. This is @@ -607,14 +608,16 @@ struct osmo_fsm_inst *mgcp_conn_create(struct mgcp_client *mgcp, struct osmo_fsm { struct mgcp_ctx *mgcp_ctx; struct osmo_fsm_inst *fi; - struct in_addr ip_test; + struct in6_addr ip_test; + OSMO_ASSERT(parent_fi); OSMO_ASSERT(mgcp); OSMO_ASSERT(conn_peer); /* Check if IP/Port information in conn info makes sense */ - if (conn_peer->port && inet_aton(conn_peer->addr, &ip_test) == 0) + if (conn_peer->port && inet_pton(osmo_ip_str_type(conn_peer->addr), + conn_peer->addr, &ip_test) != 1) return NULL; /* Allocate and configure a new fsm instance */ @@ -644,7 +647,7 @@ int mgcp_conn_modify(struct osmo_fsm_inst *fi, uint32_t parent_evt, struct mgcp_ { OSMO_ASSERT(fi); struct mgcp_ctx *mgcp_ctx = fi->priv; - struct in_addr ip_test; + struct in6_addr ip_test; OSMO_ASSERT(mgcp_ctx); OSMO_ASSERT(conn_peer); @@ -668,8 +671,8 @@ int mgcp_conn_modify(struct osmo_fsm_inst *fi, uint32_t parent_evt, struct mgcp_ LOGPFSML(fi, LOGL_ERROR, "Cannot MDCX, port == 0\n"); return -EINVAL; } - if (inet_aton(conn_peer->addr, &ip_test) == 0) { - LOGPFSML(fi, LOGL_ERROR, "Cannot MDCX, IP address == 0.0.0.0\n"); + if (inet_pton(osmo_ip_str_type(conn_peer->addr), conn_peer->addr, &ip_test) != 1) { + LOGPFSML(fi, LOGL_ERROR, "Cannot MDCX, IP address %s\n", conn_peer->addr); return -EINVAL; }