[MERGED] osmocom-bb[fixeria/trx]: trxcon: Fix '-i' to specify the "TRX IP address"

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Thu Mar 1 18:09:46 UTC 2018


Harald Welte has submitted this change and it was merged.

Change subject: trxcon: Fix '-i' to specify the "TRX IP address"
......................................................................


trxcon: Fix '-i' to specify the "TRX IP address"

The command line help states '-i' is for 'TRX IP address', which is
the remote IP address at which the TRX is to be found.  Hoewever, it
was used as the local (bind) IP address of the socket used towards
the TRX.  This is my attempt at fixing this.  A more complete solution
probably allows to specify both local (bind) and remote (connect)
address, just to be clear.

Change-Id: If0252b15e9c7942687c6dc470951d777f7af651c
---
M src/host/trxcon/trx_if.c
M src/host/trxcon/trx_if.h
M src/host/trxcon/trxcon.c
3 files changed, 15 insertions(+), 35 deletions(-)

Approvals:
  Vadim Yanitskiy: Looks good to me, but someone else must approve
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/src/host/trxcon/trx_if.c b/src/host/trxcon/trx_if.c
index 98e3cdd..048b720 100644
--- a/src/host/trxcon/trx_if.c
+++ b/src/host/trxcon/trx_if.c
@@ -83,42 +83,20 @@
 	.event_names = trx_evt_names,
 };
 
-static int trx_udp_open(void *priv, struct osmo_fd *ofd, const char *host,
-	uint16_t port_local, uint16_t port_remote,
+static int trx_udp_open(void *priv, struct osmo_fd *ofd, const char *host_local,
+	uint16_t port_local, const char *host_remote, uint16_t port_remote,
 	int (*cb)(struct osmo_fd *fd, unsigned int what))
 {
-	struct sockaddr_storage sas;
-	struct sockaddr *sa = (struct sockaddr *) &sas;
-	socklen_t sa_len;
 	int rc;
 
 	ofd->data = priv;
 	ofd->fd = -1;
 	ofd->cb = cb;
 
-	/* Init RX side for UDP connection */
-	rc = osmo_sock_init_ofd(ofd, AF_UNSPEC, SOCK_DGRAM,
-		0, host, port_local, OSMO_SOCK_F_BIND);
-	if (rc < 0)
-		return rc;
-
-	/* Init TX side for UDP connection */
-	sa_len = sizeof(sas);
-	rc = getsockname(ofd->fd, sa, &sa_len);
-	if (rc)
-		return rc;
-
-	if (sa->sa_family == AF_INET) {
-		struct sockaddr_in *sin = (struct sockaddr_in *) sa;
-		sin->sin_port = htons(port_remote);
-	} else if (sa->sa_family == AF_INET6) {
-		struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) sa;
-		sin6->sin6_port = htons(port_remote);
-	} else {
-		return -EINVAL;
-	}
-
-	rc = connect(ofd->fd, sa, sa_len);
+	/* Init UDP Connection */
+	rc = osmo_sock_init2_ofd(ofd, AF_UNSPEC, SOCK_DGRAM, 0, host_local, port_local,
+				 host_remote, port_remote,
+				 OSMO_SOCK_F_BIND | OSMO_SOCK_F_CONNECT);
 	return rc;
 }
 
@@ -641,7 +619,8 @@
  * Open/close OsmoTRX connection
  */
 
-int trx_if_open(struct trx_instance **trx, const char *host, uint16_t port)
+int trx_if_open(struct trx_instance **trx, const char *local_host,
+		const char *remote_host, uint16_t port)
 {
 	struct trx_instance *trx_new;
 	int rc;
@@ -659,13 +638,13 @@
 	INIT_LLIST_HEAD(&trx_new->trx_ctrl_list);
 
 	/* Open sockets */
-	rc = trx_udp_open(trx_new, &trx_new->trx_ofd_ctrl, host,
-		port + 101, port + 1, trx_ctrl_read_cb);
+	rc = trx_udp_open(trx_new, &trx_new->trx_ofd_ctrl, local_host,
+		port + 101, remote_host, port + 1, trx_ctrl_read_cb);
 	if (rc < 0)
 		goto error;
 
-	rc = trx_udp_open(trx_new, &trx_new->trx_ofd_data, host,
-		port + 102, port + 2, trx_data_rx_cb);
+	rc = trx_udp_open(trx_new, &trx_new->trx_ofd_data, local_host,
+		port + 102, remote_host, port + 2, trx_data_rx_cb);
 	if (rc < 0)
 		goto error;
 
diff --git a/src/host/trxcon/trx_if.h b/src/host/trxcon/trx_if.h
index dd84315..6080dce 100644
--- a/src/host/trxcon/trx_if.h
+++ b/src/host/trxcon/trx_if.h
@@ -52,7 +52,8 @@
 	int cmd_len;
 };
 
-int trx_if_open(struct trx_instance **trx, const char *host, uint16_t port);
+int trx_if_open(struct trx_instance **trx, const char *local_host,
+		const char *remote_host, uint16_t port);
 void trx_if_flush_ctrl(struct trx_instance *trx);
 void trx_if_close(struct trx_instance *trx);
 
diff --git a/src/host/trxcon/trxcon.c b/src/host/trxcon/trxcon.c
index 60db887..5542240 100644
--- a/src/host/trxcon/trxcon.c
+++ b/src/host/trxcon/trxcon.c
@@ -270,7 +270,7 @@
 		goto exit;
 
 	/* Init transceiver interface */
-	rc = trx_if_open(&app_data.trx, app_data.trx_ip, app_data.trx_base_port);
+	rc = trx_if_open(&app_data.trx, "0.0.0.0", app_data.trx_ip, app_data.trx_base_port);
 	if (rc)
 		goto exit;
 

-- 
To view, visit https://gerrit.osmocom.org/7026
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: If0252b15e9c7942687c6dc470951d777f7af651c
Gerrit-PatchSet: 1
Gerrit-Project: osmocom-bb
Gerrit-Branch: fixeria/trx
Gerrit-Owner: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Vadim Yanitskiy <axilirator at gmail.com>



More information about the gerrit-log mailing list