Change in osmocom-bb[master]: virtphy: Sync virtual_um.[ch] with osmo-bts

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

laforge gerrit-no-reply at lists.osmocom.org
Tue Mar 10 20:58:51 UTC 2020


laforge has submitted this change. ( https://gerrit.osmocom.org/c/osmocom-bb/+/17445 )

Change subject: virtphy: Sync virtual_um.[ch] with osmo-bts
......................................................................

virtphy: Sync virtual_um.[ch] with osmo-bts

The files are used in both projects, and while the osmo-bts code has
evolved, this copy didn't.  Let's sync again (to libosmocore
change-Id I303f2e616d2d32b5a8005c3dcf0f5fad19ad3445).

Change-Id: I189ee28a85a6d7a7a07b062f6b07012478503e8f
Depends: libosmocore.git Ib52d22710020b56965aefcef09bde8247ace4a9c
Related: OS#2966
---
M src/host/virt_phy/include/virtphy/virtual_um.h
M src/host/virt_phy/src/shared/virtual_um.c
M src/host/virt_phy/src/virtphy.c
3 files changed, 54 insertions(+), 26 deletions(-)

Approvals:
  Jenkins Builder: Verified
  laforge: Looks good to me, approved



diff --git a/src/host/virt_phy/include/virtphy/virtual_um.h b/src/host/virt_phy/include/virtphy/virtual_um.h
index 52f2df6..fe06092 100644
--- a/src/host/virt_phy/include/virtphy/virtual_um.h
+++ b/src/host/virt_phy/include/virtphy/virtual_um.h
@@ -17,7 +17,9 @@
 
 #define VIRT_UM_MSGB_SIZE	256
 #define DEFAULT_MS_MCAST_GROUP	"239.193.23.1"
+#define DEFAULT_MS_MCAST_PORT 4729 /* IANA-registered port for GSMTAP */
 #define DEFAULT_BTS_MCAST_GROUP	"239.193.23.2"
+#define DEFAULT_BTS_MCAST_PORT 4729 /* IANA-registered port for GSMTAP */
 
 struct virt_um_inst {
 	void *priv;
@@ -27,7 +29,7 @@
 
 struct virt_um_inst *virt_um_init(
                 void *ctx, char *tx_mcast_group, uint16_t tx_mcast_port,
-                char *rx_mcast_group, uint16_t rx_mcast_port,
+                char *rx_mcast_group, uint16_t rx_mcast_port, int ttl, const char *dev_name,
                 void (*recv_cb)(struct virt_um_inst *vui, struct msgb *msg));
 
 void virt_um_destroy(struct virt_um_inst *vui);
diff --git a/src/host/virt_phy/src/shared/virtual_um.c b/src/host/virt_phy/src/shared/virtual_um.c
index 9415bfb..14a444c 100644
--- a/src/host/virt_phy/src/shared/virtual_um.c
+++ b/src/host/virt_phy/src/shared/virtual_um.c
@@ -27,7 +27,9 @@
 #include <osmocom/core/talloc.h>
 #include <virtphy/osmo_mcast_sock.h>
 #include <virtphy/virtual_um.h>
+
 #include <unistd.h>
+#include <errno.h>
 
 /**
  * Virtual UM interface file descriptor callback.
@@ -37,49 +39,71 @@
 {
 	struct virt_um_inst *vui = ofd->data;
 
-	// check if the read flag is set
 	if (what & BSC_FD_READ) {
-		// allocate message buffer of specified size
-		struct msgb *msg = msgb_alloc(VIRT_UM_MSGB_SIZE,
-		                "Virtual UM Rx");
+		struct msgb *msg = msgb_alloc(VIRT_UM_MSGB_SIZE, "Virtual UM Rx");
 		int rc;
 
-		// read message from fd in message buffer
-		rc = mcast_bidir_sock_rx(vui->mcast_sock, msgb_data(msg),
-		                msgb_tailroom(msg));
-		// rc is number of bytes actually read
+		/* read message from fd into message buffer */
+		rc = mcast_bidir_sock_rx(vui->mcast_sock, msgb_data(msg), msgb_tailroom(msg));
 		if (rc > 0) {
 			msgb_put(msg, rc);
 			msg->l1h = msgb_data(msg);
-			// call the l1 callback function for a received msg
+			/* call the l1 callback function for a received msg */
 			vui->recv_cb(vui, msg);
-		} else {
-			// TODO: this kind of error handling might be a bit harsh
+		} else if (rc == 0) {
 			vui->recv_cb(vui, NULL);
-			// Unregister fd from select loop
-			osmo_fd_unregister(ofd);
-			close(ofd->fd);
-			ofd->fd = -1;
-			ofd->when = 0;
-		}
+			osmo_fd_close(ofd);
+		} else
+			perror("Read from multicast socket");
+
 	}
 
 	return 0;
 }
 
-struct virt_um_inst *virt_um_init(
-                void *ctx, char *tx_mcast_group, uint16_t tx_mcast_port,
-                char *rx_mcast_group, uint16_t rx_mcast_port,
-                void (*recv_cb)(struct virt_um_inst *vui, struct msgb *msg))
+struct virt_um_inst *virt_um_init(void *ctx, char *tx_mcast_group, uint16_t tx_mcast_port,
+				  char *rx_mcast_group, uint16_t rx_mcast_port, int ttl, const char *dev_name,
+				  void (*recv_cb)(struct virt_um_inst *vui, struct msgb *msg))
 {
 	struct virt_um_inst *vui = talloc_zero(ctx, struct virt_um_inst);
-	vui->mcast_sock = mcast_bidir_sock_setup(ctx, tx_mcast_group,
-	                tx_mcast_port, rx_mcast_group, rx_mcast_port, 1,
-	                virt_um_fd_cb, vui);
+	int rc;
+
+	vui->mcast_sock = mcast_bidir_sock_setup(ctx, tx_mcast_group, tx_mcast_port,
+						 rx_mcast_group, rx_mcast_port, 1, virt_um_fd_cb, vui);
+	if (!vui->mcast_sock) {
+		perror("Unable to create VirtualUm multicast socket");
+		talloc_free(vui);
+		return NULL;
+	}
 	vui->recv_cb = recv_cb;
 
+	if (ttl >= 0) {
+		rc = osmo_sock_mcast_ttl_set(vui->mcast_sock->tx_ofd.fd, ttl);
+		if (rc < 0) {
+			perror("Cannot set TTL of Virtual Um transmit socket");
+			goto out_close;
+		}
+	}
+
+	if (dev_name) {
+		rc = osmo_sock_mcast_iface_set(vui->mcast_sock->tx_ofd.fd, dev_name);
+		if (rc < 0) {
+			perror("Cannot bind multicast tx to given device");
+			goto out_close;
+		}
+		rc = osmo_sock_mcast_iface_set(vui->mcast_sock->rx_ofd.fd, dev_name);
+		if (rc < 0) {
+			perror("Cannot bind multicast rx to given device");
+			goto out_close;
+		}
+	}
+
 	return vui;
 
+out_close:
+	mcast_bidir_sock_close(vui->mcast_sock);
+	talloc_free(vui);
+	return NULL;
 }
 
 void virt_um_destroy(struct virt_um_inst *vui)
@@ -97,6 +121,8 @@
 
 	rc = mcast_bidir_sock_tx(vui->mcast_sock, msgb_data(msg),
 	                msgb_length(msg));
+	if (rc < 0)
+		rc = -errno;
 	msgb_free(msg);
 
 	return rc;
diff --git a/src/host/virt_phy/src/virtphy.c b/src/host/virt_phy/src/virtphy.c
index d0a2ddb..3290dd8 100644
--- a/src/host/virt_phy/src/virtphy.c
+++ b/src/host/virt_phy/src/virtphy.c
@@ -231,7 +231,7 @@
 
 	LOGP(DVIRPHY, LOGL_INFO, "Virtual physical layer starting up...\n");
 
-	g_vphy.virt_um = virt_um_init(tall_vphy_ctx, ul_tx_grp, port, dl_rx_grp, port,
+	g_vphy.virt_um = virt_um_init(tall_vphy_ctx, ul_tx_grp, port, dl_rx_grp, port, -1, NULL,
 					gsmtapl1_rx_from_virt_um_inst_cb);
 
 	g_vphy.l1ctl_sock = l1ctl_sock_init(tall_vphy_ctx, l1ctl_sap_rx_from_l23_inst_cb,

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

Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-Change-Id: I189ee28a85a6d7a7a07b062f6b07012478503e8f
Gerrit-Change-Number: 17445
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge at osmocom.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20200310/73c53d1e/attachment.htm>


More information about the gerrit-log mailing list