gprs_ns2: fix crash when changing the MTU
When the MTU changes for any fr device, all
NSE will recalculate their MTU. If any NSE is alive,
libosmocore will crash.
Related: OS#5192
Change-Id: I31ba5cefea7bbb0b74060d6664b42c58815ee2a1
diff --git a/src/gb/gprs_ns2.c b/src/gb/gprs_ns2.c
index 720e836..a8e646b 100644
--- a/src/gb/gprs_ns2.c
+++ b/src/gb/gprs_ns2.c
@@ -1552,7 +1552,7 @@
nse->mtu = mtu;
if (nse->alive)
- ns2_prim_status_ind(nsvc->nse, NULL, 0, GPRS_NS2_AFF_CAUSE_MTU_CHANGE);
+ ns2_prim_status_ind(nse, NULL, 0, GPRS_NS2_AFF_CAUSE_MTU_CHANGE);
}
/*! calculate the transfer capabilities for a nse
diff --git a/tests/gb/gprs_ns2_test.c b/tests/gb/gprs_ns2_test.c
index c53cc6d..b96e739 100644
--- a/tests/gb/gprs_ns2_test.c
+++ b/tests/gb/gprs_ns2_test.c
@@ -41,6 +41,7 @@
static struct log_info info = {};
static struct osmo_wqueue *unitdata = NULL;
static struct osmo_gprs_ns2_prim last_nse_recovery = {};
+static struct osmo_gprs_ns2_prim last_nse_mtu_change = {};
static int ns_prim_cb(struct osmo_prim_hdr *oph, void *ctx)
{
@@ -54,8 +55,12 @@
msgb_free(oph->msg);
}
}
- if (oph->primitive == GPRS_NS2_PRIM_STATUS && nsp->u.status.cause == GPRS_NS2_AFF_CAUSE_RECOVERY) {
- last_nse_recovery = *nsp;
+ if (oph->primitive == GPRS_NS2_PRIM_STATUS) {
+ if (nsp->u.status.cause == GPRS_NS2_AFF_CAUSE_RECOVERY) {
+ last_nse_recovery = *nsp;
+ } else if (nsp->u.status.cause == GPRS_NS2_AFF_CAUSE_MTU_CHANGE) {
+ last_nse_mtu_change = *nsp;
+ }
}
return 0;
}
@@ -579,6 +584,10 @@
/* 1b NS PDU type, 1b NS SDU control, 2b BVCI */
OSMO_ASSERT(last_nse_recovery.u.status.mtu == 123 - 4);
+ bind[0]->mtu = 100;
+ ns2_nse_update_mtu(nse);
+ OSMO_ASSERT(last_nse_mtu_change.u.status.mtu == 100 - 4);
+
gprs_ns2_free(nsi);
printf("--- Finish unitdata test\n");
}