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
This commit is contained in:
Alexander Couzens 2021-01-18 18:39:57 +01:00
parent 7741bc320c
commit 55bc86931e
2 changed files with 19 additions and 1 deletions

View File

@ -106,6 +106,7 @@ static void free_vc(struct gprs_ns2_vc *nsvc)
if (!nsvc->priv)
return;
OSMO_ASSERT(gprs_ns2_is_fr_bind(nsvc->bind));
talloc_free(nsvc->priv);
nsvc->priv = NULL;
}
@ -137,6 +138,7 @@ static void free_bind(struct gprs_ns2_vc_bind *bind)
{
struct priv_bind *priv;
OSMO_ASSERT(gprs_ns2_is_fr_bind(bind));
if (!bind)
return;
@ -158,6 +160,7 @@ static struct priv_vc *fr_alloc_vc(struct gprs_ns2_vc_bind *bind,
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 @@ int gprs_ns2_find_vc_by_dlci(struct gprs_ns2_vc_bind *bind,
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 gprs_ns2_vc *gprs_ns2_fr_connect(struct gprs_ns2_vc_bind *bind,
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 @@ struct gprs_ns2_vc *gprs_ns2_fr_connect2(struct gprs_ns2_vc_bind *bind,
{
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 *gprs_ns2_fr_nsvc_by_dlci(struct gprs_ns2_vc_bind *bind,
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;

View File

@ -63,6 +63,8 @@ static void free_bind(struct gprs_ns2_vc_bind *bind)
if (!bind)
return;
OSMO_ASSERT(gprs_ns2_is_ip_bind(bind));
priv = bind->priv;
osmo_fd_close(&priv->fd);
@ -74,6 +76,7 @@ static void free_vc(struct gprs_ns2_vc *nsvc)
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 *gprs_ns2_nsvc_by_sockaddr_bind(struct gprs_ns2_vc_bind *bind
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 @@ struct gprs_ns2_vc *gprs_ns2_ip_bind_connect(struct gprs_ns2_vc_bind *bind,
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 @@ bool gprs_ns2_ip_vc_equal(const struct gprs_ns2_vc *nsvc,
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 @@ int gprs_ns2_ip_bind_set_dscp(struct gprs_ns2_vc_bind *bind, int dscp)
struct priv_bind *priv;
int rc = 0;
OSMO_ASSERT(gprs_ns2_is_ip_bind(bind));
priv = bind->priv;
if (dscp != priv->dscp) {