Change in osmo-pcu[master]: WIP add IPv6 support for the PCU SOCKET

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

lynxis lazus gerrit-no-reply at lists.osmocom.org
Mon Jul 13 11:43:21 UTC 2020


lynxis lazus has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-pcu/+/19236 )


Change subject: WIP add IPv6 support for the PCU SOCKET
......................................................................

WIP add IPv6 support for the PCU SOCKET

This is the "old" approach. Not for master.

Change-Id: Iaa2113644fcb4e6ff38649ca7f3abb6469f33d48
---
M include/osmocom/pcu/pcuif_proto.h
M src/gprs_bssgp_pcu.cpp
M src/gprs_bssgp_pcu.h
M src/pcu_l1_if.cpp
M tests/emu/pcu_emu.cpp
5 files changed, 41 insertions(+), 20 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-pcu refs/changes/36/19236/1

diff --git a/include/osmocom/pcu/pcuif_proto.h b/include/osmocom/pcu/pcuif_proto.h
index fd989a5..a6714ca 100644
--- a/include/osmocom/pcu/pcuif_proto.h
+++ b/include/osmocom/pcu/pcuif_proto.h
@@ -1,11 +1,12 @@
 #ifndef _PCUIF_PROTO_H
 #define _PCUIF_PROTO_H
 
+#include <arpa/inet.h>
 #include <osmocom/gsm/l1sap.h>
 
 #define PCU_SOCK_DEFAULT	"/tmp/pcu_bts"
 
-#define PCU_IF_VERSION		0x09
+#define PCU_IF_VERSION		0x10
 #define TXT_MAX_LEN	128
 
 /* msg_type */
@@ -153,7 +154,11 @@
 	uint16_t	nsvci[2];
 	uint16_t	local_port[2];
 	uint16_t	remote_port[2];
-	uint32_t	remote_ip[2];
+	uint8_t		adress_family;
+	union {
+		struct in_addr ipv4;
+		struct in6_addr ipv6;
+	} remote_ip[2];
 } __attribute__ ((packed));
 
 struct gsm_pcu_if_act_req {
diff --git a/src/gprs_bssgp_pcu.cpp b/src/gprs_bssgp_pcu.cpp
index abcb106..d769333 100644
--- a/src/gprs_bssgp_pcu.cpp
+++ b/src/gprs_bssgp_pcu.cpp
@@ -882,13 +882,13 @@
 }
 
 /* create BSSGP/NS layer instances */
+/* TODO: use a pointer for sgsn */
 struct gprs_bssgp_pcu *gprs_bssgp_create_and_connect(struct gprs_rlcmac_bts *bts,
-	uint16_t local_port, uint32_t sgsn_ip,
-	uint16_t sgsn_port, uint16_t nsei, uint16_t nsvci, uint16_t bvci,
+	uint16_t local_port, struct osmo_sockaddr *sgsn,
+	uint16_t nsei, uint16_t nsvci, uint16_t bvci,
 	uint16_t mcc, uint16_t mnc, bool mnc_3_digits, uint16_t lac, uint16_t rac,
 	uint16_t cell_id)
 {
-	struct sockaddr_in dest;
 	int rc;
 
 	/* if already created... return the current address */
@@ -901,10 +901,9 @@
 	 * issue a connect() on the socket, which prevents us to dynamically communicate
 	 * with any number of IP-SNS endpoints on the SGSN side */
 	if (!bts->gb_dialect_sns) {
-		bssgp_nsi->nsip.remote_port = sgsn_port;
-		bssgp_nsi->nsip.remote_ip = sgsn_ip;
+		bssgp_nsi->nsip.remote = *sgsn;
 	}
-	bssgp_nsi->nsip.local_port = local_port;
+	bssgp_nsi->nsip.local.u.sin.sin_port = local_port;
 	rc = gprs_ns_nsip_listen(bssgp_nsi);
 	if (rc < 0) {
 		LOGP(DBSSGP, LOGL_ERROR, "Failed to create socket\n");
@@ -912,14 +911,10 @@
 		return NULL;
 	}
 
-	dest.sin_family = AF_INET;
-	dest.sin_port = htons(sgsn_port);
-	dest.sin_addr.s_addr = htonl(sgsn_ip);
-
 	if (bts->gb_dialect_sns)
-		the_pcu.nsvc = gprs_ns_nsip_connect_sns(bssgp_nsi, &dest, nsei, nsvci);
+		the_pcu.nsvc = gprs_ns_nsip_connect_sns(bssgp_nsi, sgsn, nsei, nsvci);
 	else
-		the_pcu.nsvc = gprs_ns_nsip_connect(bssgp_nsi, &dest, nsei, nsvci);
+		the_pcu.nsvc = gprs_ns_nsip_connect(bssgp_nsi, sgsn, nsei, nsvci);
 	if (!the_pcu.nsvc) {
 		LOGP(DBSSGP, LOGL_ERROR, "Failed to create NSVCt\n");
 		gprs_ns_close(bssgp_nsi);
diff --git a/src/gprs_bssgp_pcu.h b/src/gprs_bssgp_pcu.h
index f98e719..9b40059 100644
--- a/src/gprs_bssgp_pcu.h
+++ b/src/gprs_bssgp_pcu.h
@@ -75,8 +75,7 @@
 };
 
 struct gprs_bssgp_pcu *gprs_bssgp_create_and_connect(struct gprs_rlcmac_bts *bts,
-		uint16_t local_port,
-		uint32_t sgsn_ip, uint16_t sgsn_port, uint16_t nsei,
+		uint16_t local_port, struct osmo_sockaddr *sgsn, uint16_t nsei,
 		uint16_t nsvci, uint16_t bvci, uint16_t mcc, uint16_t mnc, bool mnc_3_digits,
 		uint16_t lac, uint16_t rac, uint16_t cell_id);
 
diff --git a/src/pcu_l1_if.cpp b/src/pcu_l1_if.cpp
index 883cb22..e0ff701 100644
--- a/src/pcu_l1_if.cpp
+++ b/src/pcu_l1_if.cpp
@@ -34,6 +34,8 @@
 #include <osmocom/core/gsmtap_util.h>
 #include <osmocom/core/gsmtap.h>
 #include <osmocom/core/bitvec.h>
+#include <osmocom/core/sockaddr_str.h>
+#include <osmocom/core/socket.h>
 #include <osmocom/core/logging.h>
 #include <osmocom/core/utils.h>
 #include <osmocom/gsm/l1sap.h>
@@ -424,6 +426,8 @@
 	struct gprs_rlcmac_bts *bts = bts_main_data();
 	struct gprs_bssgp_pcu *pcu;
 	struct gprs_rlcmac_pdch *pdch;
+	struct osmo_sockaddr saddr;
+	struct osmo_sockaddr_str addr;
 	struct in_addr ia;
 	int rc = 0;
 	unsigned int trx, ts;
@@ -502,11 +506,25 @@
 	LOGP(DL1IF, LOGL_DEBUG, " nsvci=%d\n", info_ind->nsvci[0]);
 	LOGP(DL1IF, LOGL_DEBUG, " local_port=%d\n", info_ind->local_port[0]);
 	LOGP(DL1IF, LOGL_DEBUG, " remote_port=%d\n", info_ind->remote_port[0]);
-	ia.s_addr = htonl(info_ind->remote_ip[0]);
-	LOGP(DL1IF, LOGL_DEBUG, " remote_ip=%s\n", inet_ntoa(ia));
+
+	switch (info_ind->adress_family) {
+	case IPPROTO_IPIP:
+		saddr.u.sin.sin_addr = info_ind->remote_ip[0].ipv4;
+		saddr.u.sin.sin_port = info_ind->remote_port[0];
+		saddr.u.sin.sin_family = AF_INET;
+		break;
+	case IPPROTO_IPV6:
+		saddr.u.sin6.sin6_addr = info_ind->remote_ip[0].ipv6;
+		saddr.u.sin6.sin6_port = info_ind->remote_port[0];
+		saddr.u.sin6.sin6_family = AF_INET6;
+		break;
+	}
+	osmo_sockaddr_str_from_sockaddr(&addr, &saddr.u.sas);
+
+	LOGP(DL1IF, LOGL_DEBUG, " remote_ip=%s\n", addr.ip);
 
 	pcu = gprs_bssgp_create_and_connect(bts, info_ind->local_port[0],
-		info_ind->remote_ip[0], info_ind->remote_port[0],
+		&saddr,
 		info_ind->nsei, info_ind->nsvci[0], info_ind->bvci,
 		info_ind->mcc, info_ind->mnc, info_ind->mnc_3_digits, info_ind->lac, info_ind->rac,
 		info_ind->cell_id);
diff --git a/tests/emu/pcu_emu.cpp b/tests/emu/pcu_emu.cpp
index 7f99355..e8d8f05 100644
--- a/tests/emu/pcu_emu.cpp
+++ b/tests/emu/pcu_emu.cpp
@@ -93,8 +93,12 @@
 			uint32_t sgsn_ip, uint16_t sgsn_port)
 {
 	struct gprs_bssgp_pcu *pcu;
+	struct osmo_sockaddr saddr;
+	saddr.u.sin.sin_family = AF_INET;
+	saddr.u.sin.sin_addr.s_addr = htonl(sgsn_ip);
+	saddr.u.sin.sin_port = htons(sgsn_port);
 
-	pcu = gprs_bssgp_create_and_connect(bts, 0, sgsn_ip, sgsn_port,
+	pcu = gprs_bssgp_create_and_connect(bts, 0, &saddr,
 					20, 20, 20, 901, 99, false, 1, 0, 0);
 	pcu->on_unblock_ack = bvci_unblocked;
 	pcu->on_dl_unit_data = bssgp_data;

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

Gerrit-Project: osmo-pcu
Gerrit-Branch: master
Gerrit-Change-Id: Iaa2113644fcb4e6ff38649ca7f3abb6469f33d48
Gerrit-Change-Number: 19236
Gerrit-PatchSet: 1
Gerrit-Owner: lynxis lazus <lynxis at fe80.eu>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20200713/73225b49/attachment.htm>


More information about the gerrit-log mailing list