lynxis lazus has submitted this change. ( 
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, 19 insertions(+), 1 deletion(-)

Approvals:
  Jenkins Builder: Verified
  pespin: Looks good to me, but someone else must approve
  daniel: Looks good to me, approved
  laforge: Looks good to me, approved



diff --git a/src/gb/gprs_ns2_fr.c b/src/gb/gprs_ns2_fr.c
index c1bed6c..7b9450c 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;

@@ -740,6 +744,7 @@
        struct priv_bind *bpriv = bind->priv;
        char idbuf[64];

+       OSMO_ASSERT(gprs_ns2_is_fr_bind(bind));
        nsvc = gprs_ns2_fr_nsvc_by_dlci(bind, dlci);
        if (nsvc) {
                goto err;
@@ -780,7 +785,10 @@
 {
        bool created_nse = false;
        struct gprs_ns2_vc *nsvc = 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)
@@ -812,6 +820,7 @@
        struct gprs_ns2_vc *nsvc;
        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 d93b66d..1037b19 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)
@@ -397,6 +402,8 @@
        char *sockaddr_str;
        char idbuf[64];

+       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",
@@ -492,6 +499,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;
@@ -509,6 +517,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: 10
Gerrit-Owner: lynxis lazus <lyn...@fe80.eu>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: daniel <dwillm...@sysmocom.de>
Gerrit-Reviewer: laforge <lafo...@osmocom.org>
Gerrit-Reviewer: lynxis lazus <lyn...@fe80.eu>
Gerrit-Reviewer: pespin <pes...@sysmocom.de>
Gerrit-MessageType: merged

Reply via email to