Change in libosmocore[master]: gprs_ns2: add assert on most bind calls

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
Sun Jan 17 21:43:25 UTC 2021


lynxis lazus has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/22273 )


Change subject: gprs_ns2: add assert on most bind calls
......................................................................

gprs_ns2: add assert on most bind calls

Add a OSMO_ASSERT to all bind calls which doesn't
check if the bind is from the expected type.
The only exception is rx and tx functions (hot path).

Change-Id: Ia4f8932263c60618c7f0dfc32d50ba5a8d57602b
---
M src/gb/gprs_ns2_fr.c
M src/gb/gprs_ns2_udp.c
2 files changed, 21 insertions(+), 3 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/73/22273/1

diff --git a/src/gb/gprs_ns2_fr.c b/src/gb/gprs_ns2_fr.c
index 2c797f3..c897cbc 100644
--- a/src/gb/gprs_ns2_fr.c
+++ b/src/gb/gprs_ns2_fr.c
@@ -106,6 +106,7 @@
 	if (!nsvc->priv)
 		return;
 
+	OSMO_ASSERT(gprs_ns2_is_fr_bind(nsvc->bind));
 	talloc_free(nsvc->priv);
 	nsvc->priv = NULL;
 }
@@ -137,6 +138,7 @@
 {
 	struct priv_bind *priv;
 
+	OSMO_ASSERT(gprs_ns2_is_fr_bind(bind));
 	if (!bind)
 		return;
 
@@ -158,6 +160,7 @@
 	if (!priv)
 		return NULL;
 
+	OSMO_ASSERT(gprs_ns2_is_fr_bind(bind));
 	nsvc->priv = priv;
 	priv->dlci = dlci;
 	priv->dlc = osmo_fr_dlc_alloc(privb->link, dlci);
@@ -180,6 +183,7 @@
 	struct gprs_ns2_vc *nsvc;
 	struct priv_vc *vcpriv;
 
+	OSMO_ASSERT(gprs_ns2_is_fr_bind(bind));
 	if (!result)
 		return -EINVAL;
 
@@ -738,6 +742,7 @@
 	struct gprs_ns2_vc *nsvc = NULL;
 	struct priv_vc *priv = NULL;
 
+	OSMO_ASSERT(gprs_ns2_is_fr_bind(bind));
 	nsvc = gprs_ns2_fr_nsvc_by_dlci(bind, dlci);
 	if (nsvc) {
 		goto err;
@@ -777,7 +782,10 @@
 	bool created_nse = false;
 	struct gprs_ns2_vc *nsvc = NULL;
 	struct priv_vc *priv = NULL;
-	struct gprs_ns2_nse *nse = gprs_ns2_nse_by_nsei(bind->nsi, nsei);
+	struct gprs_ns2_nse *nse;
+
+	OSMO_ASSERT(gprs_ns2_is_fr_bind(bind));
+	nse = gprs_ns2_nse_by_nsei(bind->nsi, nsei);
 	if (!nse) {
 		nse = gprs_ns2_create_nse(bind->nsi, nsei, GPRS_NS2_LL_FR, NS2_DIALECT_STATIC_RESETBLOCK);
 		if (!nse)
@@ -823,8 +831,9 @@
 					     uint16_t dlci)
 {
 	struct gprs_ns2_vc *nsvc;
-	struct priv_vc *vcpriv;
+	struct priv_vc *vcpriv;	
 
+	OSMO_ASSERT(gprs_ns2_is_fr_bind(bind));
 	llist_for_each_entry(nsvc, &bind->nsvc, blist) {
 		vcpriv = nsvc->priv;
 
diff --git a/src/gb/gprs_ns2_udp.c b/src/gb/gprs_ns2_udp.c
index 370937f..2a2886a 100644
--- a/src/gb/gprs_ns2_udp.c
+++ b/src/gb/gprs_ns2_udp.c
@@ -63,6 +63,8 @@
 	if (!bind)
 		return;
 
+	OSMO_ASSERT(gprs_ns2_is_ip_bind(bind));
+
 	priv = bind->priv;
 
 	osmo_fd_close(&priv->fd);
@@ -74,6 +76,7 @@
 	if (!nsvc->priv)
 		return;
 
+	OSMO_ASSERT(gprs_ns2_is_ip_bind(nsvc->bind));
 	talloc_free(nsvc->priv);
 	nsvc->priv = NULL;
 }
@@ -116,6 +119,8 @@
 	struct gprs_ns2_vc *nsvc;
 	struct priv_vc *vcpriv;
 
+	OSMO_ASSERT(gprs_ns2_is_ip_bind(bind));
+
 	llist_for_each_entry(nsvc, &bind->nsvc, blist) {
 		vcpriv = nsvc->priv;
 		if (vcpriv->remote.u.sa.sa_family != saddr->u.sa.sa_family)
@@ -277,7 +282,7 @@
 	const struct osmo_sockaddr *local;
 
 	OSMO_ASSERT(nsi);
-	OSMO_ASSERT(sockaddr);
+	OSMO_ASSERT(sockaddr);	
 
 	llist_for_each_entry(bind, &nsi->binding, list) {
 		if (!gprs_ns2_is_ip_bind(bind))
@@ -395,6 +400,8 @@
 	struct priv_vc *priv;
 	enum gprs_ns2_vc_mode vc_mode;
 
+	OSMO_ASSERT(gprs_ns2_is_ip_bind(bind));
+
 	vc_mode = gprs_ns2_dialect_to_vc_mode(nse->dialect);
 	if ((int) vc_mode == -1) {
 		LOGP(DLNS, LOGL_ERROR, "Can not derive vc mode from dialect %d. Maybe libosmocore is too old.\n",
@@ -486,6 +493,7 @@
 const struct osmo_sockaddr *gprs_ns2_ip_bind_sockaddr(struct gprs_ns2_vc_bind *bind)
 {
 	struct priv_bind *priv;
+	OSMO_ASSERT(gprs_ns2_is_ip_bind(bind));
 
 	priv = bind->priv;
 	return &priv->addr;
@@ -503,6 +511,7 @@
 	struct priv_bind *priv;
 	int rc = 0;
 
+	OSMO_ASSERT(gprs_ns2_is_ip_bind(bind));
 	priv = bind->priv;
 
 	if (dscp != priv->dscp) {

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

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Ia4f8932263c60618c7f0dfc32d50ba5a8d57602b
Gerrit-Change-Number: 22273
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/20210117/97d3a221/attachment.htm>


More information about the gerrit-log mailing list