Change in osmocom-bb[master]: trxcon: update trx_udp_open()

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/.

Max gerrit-no-reply at lists.osmocom.org
Thu Mar 21 15:59:20 UTC 2019


Max has uploaded this change for review. ( https://gerrit.osmocom.org/13367


Change subject: trxcon: update trx_udp_open()
......................................................................

trxcon: update trx_udp_open()

* explicitly log created socket type (ctrl vs data)
* log local/remote ip/port
* log detailed per-socket error in case of failure
* internalize callback and osmo_fd selection based on socket type

Change-Id: I33b01879f6ea468941e5dab5b46492be8fe5730d
---
M src/host/trxcon/trx_if.c
1 file changed, 25 insertions(+), 22 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/67/13367/1

diff --git a/src/host/trxcon/trx_if.c b/src/host/trxcon/trx_if.c
index 4c10da6..9b7a5d6 100644
--- a/src/host/trxcon/trx_if.c
+++ b/src/host/trxcon/trx_if.c
@@ -83,23 +83,6 @@
 	.event_names = trx_evt_names,
 };
 
-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))
-{
-	int rc;
-
-	ofd->data = priv;
-	ofd->fd = -1;
-	ofd->cb = cb;
-
-	/* 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;
-}
-
 static void trx_udp_close(struct osmo_fd *ofd)
 {
 	if (ofd->fd > 0) {
@@ -626,6 +609,29 @@
 	return 0;
 }
 
+static int trx_udp_open(struct trx_instance *trx, bool is_ctrl, const char *host_local,
+			uint16_t port_local, const char *host_remote, uint16_t port_remote)
+{
+	int rc;
+	struct osmo_fd *ofd = is_ctrl ? &trx->trx_ofd_ctrl : &trx->trx_ofd_data;
+
+	ofd->data = trx;
+	ofd->fd = -1;
+	ofd->cb = is_ctrl ? trx_ctrl_read_cb : trx_data_rx_cb;
+
+	/* 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);
+	if (rc < 0)
+		LOGP(DTRX, LOGL_ERROR, "Failed to prepare %s UDP socket r=%s:%u<->l=%s:%u\n",
+		     is_ctrl ? "CTRL" : "DATA", host_remote, port_remote, host_local, port_local);
+	else
+		LOGP(DTRX, LOGL_NOTICE, "%s UDP socket %s ready\n", is_ctrl ? "CTRL" : "DATA", osmo_sock_get_name2(rc));
+
+	return rc;
+}
+
 /* Init TRX interface (TRXC, TRXD sockets and FSM) */
 struct trx_instance *trx_if_open(void *tall_ctx,
 	const char *local_host, const char *remote_host,
@@ -658,20 +664,17 @@
 	INIT_LLIST_HEAD(&trx->trx_ctrl_list);
 
 	/* Open sockets */
-	rc = trx_udp_open(trx, &trx->trx_ofd_ctrl, local_host,
-		base_port + 101, remote_host, base_port + 1, trx_ctrl_read_cb);
+	rc = trx_udp_open(trx, true, local_host, base_port + 101, remote_host, base_port + 1);
 	if (rc < 0)
 		goto udp_error;
 
-	rc = trx_udp_open(trx, &trx->trx_ofd_data, local_host,
-		base_port + 102, remote_host, base_port + 2, trx_data_rx_cb);
+	rc = trx_udp_open(trx, false, local_host, base_port + 102, remote_host, base_port + 2);
 	if (rc < 0)
 		goto udp_error;
 
 	return trx;
 
 udp_error:
-	LOGP(DTRX, LOGL_ERROR, "Couldn't establish UDP connection\n");
 	osmo_fsm_inst_free(trx->fsm);
 	talloc_free(trx);
 	return NULL;

-- 
To view, visit https://gerrit.osmocom.org/13367
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I33b01879f6ea468941e5dab5b46492be8fe5730d
Gerrit-Change-Number: 13367
Gerrit-PatchSet: 1
Gerrit-Owner: Max <msuraev at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190321/d5d05bbc/attachment.htm>


More information about the gerrit-log mailing list