aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Couzens <lynxis@fe80.eu>2020-11-30 22:20:20 +0100
committerAlexander Couzens <lynxis@fe80.eu>2020-12-03 06:15:09 +0100
commitd87a2f14e630fadb8560d8d21900a2d01c795238 (patch)
tree5bc13274e098357ce67568a72591a038776f491c
parent036bf140c98cff07251a87d11757c92fb3f464a1 (diff)
gprs_ns2: use switch() case instead of multiple if in ns2_create_vc()
Improve readibilty and allows it to extend for future ns2 vty changes Change-Id: I8bd9c75fb04169a166b7a3f5e13a5902250cfd0e
-rw-r--r--src/gb/gprs_ns2.c33
1 files changed, 14 insertions, 19 deletions
diff --git a/src/gb/gprs_ns2.c b/src/gb/gprs_ns2.c
index 15364fc6..69c1174e 100644
--- a/src/gb/gprs_ns2.c
+++ b/src/gb/gprs_ns2.c
@@ -772,42 +772,37 @@ enum gprs_ns2_cs ns2_create_vc(struct gprs_ns2_vc_bind *bind,
if (msg->len < sizeof(struct gprs_ns_hdr))
return GPRS_NS2_CS_ERROR;
- if (nsh->pdu_type == NS_PDUT_STATUS) {
+ switch (nsh->pdu_type) {
+ case NS_PDUT_STATUS:
/* Do not respond, see 3GPP TS 08.16, 7.5.1 */
LOGP(DLNS, LOGL_INFO, "Ignoring NS STATUS from %s "
"for non-existing NS-VC\n",
logname);
return GPRS_NS2_CS_SKIPPED;
- }
-
- if (nsh->pdu_type == NS_PDUT_ALIVE_ACK) {
+ case NS_PDUT_ALIVE_ACK:
/* Ignore this, see 3GPP TS 08.16, 7.4.1 */
LOGP(DLNS, LOGL_INFO, "Ignoring NS ALIVE ACK from %s "
"for non-existing NS-VC\n",
logname);
return GPRS_NS2_CS_SKIPPED;
- }
-
- if (nsh->pdu_type == NS_PDUT_RESET_ACK) {
+ case NS_PDUT_RESET_ACK:
/* Ignore this, see 3GPP TS 08.16, 7.3.1 */
LOGP(DLNS, LOGL_INFO, "Ignoring NS RESET ACK from %s "
"for non-existing NS-VC\n",
logname);
return GPRS_NS2_CS_SKIPPED;
- }
-
- if (bind->vc_mode == NS2_VC_MODE_BLOCKRESET) {
- /* Only the RESET procedure creates a new NSVC */
- if (nsh->pdu_type != NS_PDUT_RESET) {
- rc = reject_status_msg(msg, &tp, reject, NS_CAUSE_PDU_INCOMP_PSTATE);
+ case NS_PDUT_RESET:
+ /* accept PDU RESET when vc_mode matches */
+ if (bind->vc_mode == NS2_VC_MODE_BLOCKRESET)
+ break;
- if (rc < 0) {
- LOGP(DLNS, LOGL_ERROR, "Failed to generate reject message (%d)\n", rc);
- return rc;
- }
- return GPRS_NS2_CS_REJECTED;
+ rc = reject_status_msg(msg, &tp, reject, NS_CAUSE_PDU_INCOMP_PSTATE);
+ if (rc < 0) {
+ LOGP(DLNS, LOGL_ERROR, "Failed to generate reject message (%d)\n", rc);
+ return rc;
}
- } else { /* NS2_VC_MODE_ALIVE */
+ return GPRS_NS2_CS_REJECTED;
+ default:
rc = reject_status_msg(msg, &tp, reject, NS_CAUSE_PDU_INCOMP_PSTATE);
if (rc < 0) {