diff options
author | Pau Espin Pedrol <pespin@sysmocom.de> | 2019-05-30 12:44:20 +0200 |
---|---|---|
committer | Pau Espin Pedrol <pespin@sysmocom.de> | 2019-05-31 16:34:32 +0200 |
commit | aad77a0acfa65189aebf92bcbf63715f359c9b1a (patch) | |
tree | 756ccd22a4efe22144e9fbcf784ecfd2e65f3c2f | |
parent | 9ee8d3264b1d860792968f9456cd66a7233fd98b (diff) |
gtp_create_pdp_ind: simplify code by reordering and compacting parsing
Move all parsing with same conditions under same blocks to make code
easier to follow and make it more compact.
Change-Id: I52d5a3543ce6cf764bd84303b5a0d8b0643d998d
-rw-r--r-- | gtp/gtp.c | 170 |
1 files changed, 71 insertions, 99 deletions
@@ -1435,70 +1435,22 @@ int gtp_create_pdp_ind(struct gsn_t *gsn, int version, pdp->apn_req = linked_pdp->apn_req; pdp->teic_gn = linked_pdp->teic_gn; pdp->secondary = 1; + } else { + /* Not Secondary PDP Context Activation Procedure */ + /* IMSI (conditional): If the MS is emergency attached + and the MS is UICCless, the IMSI cannot be included + in the message and therefore IMSI shall not be + included in the message. */ + if (gtpie_gettv0 + (ie, GTPIE_IMSI, 0, &pdp->imsi, sizeof(pdp->imsi))) { + gsn->missing++; + GTP_LOGPKG(LOGL_ERROR, peer, pack, + len, "Missing IMSI not supported\n"); + return gtp_create_pdp_resp(gsn, version, pdp, + GTPCAUSE_MAN_IE_MISSING); + } } - } - /* if (version == 1) */ - if (version == 0) { - if (gtpie_gettv0(ie, GTPIE_QOS_PROFILE0, 0, - pdp->qos_req0, sizeof(pdp->qos_req0))) { - gsn->missing++; - GTP_LOGPKG(LOGL_ERROR, peer, pack, - len, "Missing mandatory information field\n"); - return gtp_create_pdp_resp(gsn, version, pdp, - GTPCAUSE_MAN_IE_MISSING); - } - } - - if ((version == 1) && (!linked_pdp)) { - /* Not Secondary PDP Context Activation Procedure */ - /* IMSI (conditional) */ - if (gtpie_gettv0 - (ie, GTPIE_IMSI, 0, &pdp->imsi, sizeof(pdp->imsi))) { - gsn->missing++; - GTP_LOGPKG(LOGL_ERROR, peer, pack, - len, "Missing mandatory information field\n"); - return gtp_create_pdp_resp(gsn, version, pdp, - GTPCAUSE_MAN_IE_MISSING); - } - } - - /* Recovery (optional) */ - if (!gtpie_gettv1(ie, GTPIE_RECOVERY, 0, &recovery)) { - /* we use recovery futher down after announcing new pdp ctx to user */ - recovery_recvd = true; - } - - /* Selection mode (conditional) */ - if (!linked_pdp) { /* Not Secondary PDP Context Activation Procedure */ - if (gtpie_gettv0(ie, GTPIE_SELECTION_MODE, 0, - &pdp->selmode, sizeof(pdp->selmode))) { - gsn->missing++; - GTP_LOGPKG(LOGL_ERROR, peer, pack, - len, "Missing mandatory information field\n"); - return gtp_create_pdp_resp(gsn, version, pdp, - GTPCAUSE_MAN_IE_MISSING); - } - } - - if (version == 0) { - if (gtpie_gettv2(ie, GTPIE_FL_DI, 0, &pdp->flru)) { - gsn->missing++; - GTP_LOGPKG(LOGL_ERROR, peer, pack, - len, "Missing mandatory information field\n"); - return gtp_create_pdp_resp(gsn, version, pdp, - GTPCAUSE_MAN_IE_MISSING); - } - - if (gtpie_gettv2(ie, GTPIE_FL_C, 0, &pdp->flrc)) { - gsn->missing++; - GTP_LOGPKG(LOGL_ERROR, peer, pack, - len, "Missing mandatory information field\n"); - return gtp_create_pdp_resp(gsn, version, pdp, - GTPCAUSE_MAN_IE_MISSING); - } - } - if (version == 1) { /* TEID (mandatory) */ if (gtpie_gettv4(ie, GTPIE_TEI_DI, 0, &pdp->teid_gn)) { gsn->missing++; @@ -1507,7 +1459,6 @@ int gtp_create_pdp_ind(struct gsn_t *gsn, int version, return gtp_create_pdp_resp(gsn, version, pdp, GTPCAUSE_MAN_IE_MISSING); } - /* TEIC (conditional) */ if (!linked_pdp) { /* Not Secondary PDP Context Activation Procedure */ if (gtpie_gettv4(ie, GTPIE_TEI_C, 0, &pdp->teic_gn)) { @@ -1519,7 +1470,6 @@ int gtp_create_pdp_ind(struct gsn_t *gsn, int version, GTPCAUSE_MAN_IE_MISSING); } } - /* NSAPI (mandatory) */ if (gtpie_gettv1(ie, GTPIE_NSAPI, 0, &pdp->nsapi)) { gsn->missing++; @@ -1528,37 +1478,43 @@ int gtp_create_pdp_ind(struct gsn_t *gsn, int version, return gtp_create_pdp_resp(gsn, version, pdp, GTPCAUSE_MAN_IE_MISSING); } + /* QoS (mandatory) */ + if (gtpie_gettlv(ie, GTPIE_QOS_PROFILE, 0, &pdp->qos_req.l, + &pdp->qos_req.v, sizeof(pdp->qos_req.v))) { + gsn->missing++; + GTP_LOGPKG(LOGL_ERROR, peer, pack, + len, "Missing mandatory information field\n"); + return gtp_create_pdp_resp(gsn, version, pdp, + GTPCAUSE_MAN_IE_MISSING); + } + /* TFT (conditional) */ + if (gtpie_gettlv(ie, GTPIE_TFT, 0, &pdp->tft.l, + &pdp->tft.v, sizeof(pdp->tft.v))) { + } } - - /* Charging Characteriatics (optional) */ - /* Trace reference (optional) */ - /* Trace type (optional) */ - /* Charging Characteriatics (optional) */ - - if (!linked_pdp) { /* Not Secondary PDP Context Activation Procedure */ - /* End User Address (conditional) */ - if (gtpie_gettlv(ie, GTPIE_EUA, 0, &pdp->eua.l, - &pdp->eua.v, sizeof(pdp->eua.v))) { + /* if (version == 1) */ + if (version == 0) { + if (gtpie_gettv0(ie, GTPIE_QOS_PROFILE0, 0, + pdp->qos_req0, sizeof(pdp->qos_req0))) { gsn->missing++; GTP_LOGPKG(LOGL_ERROR, peer, pack, len, "Missing mandatory information field\n"); return gtp_create_pdp_resp(gsn, version, pdp, GTPCAUSE_MAN_IE_MISSING); } - - /* APN */ - if (gtpie_gettlv(ie, GTPIE_APN, 0, &pdp->apn_req.l, - &pdp->apn_req.v, sizeof(pdp->apn_req.v))) { + if (gtpie_gettv2(ie, GTPIE_FL_DI, 0, &pdp->flru)) { gsn->missing++; GTP_LOGPKG(LOGL_ERROR, peer, pack, len, "Missing mandatory information field\n"); return gtp_create_pdp_resp(gsn, version, pdp, GTPCAUSE_MAN_IE_MISSING); } - - /* Extract protocol configuration options (optional) */ - if (!gtpie_gettlv(ie, GTPIE_PCO, 0, &pdp->pco_req.l, - &pdp->pco_req.v, sizeof(pdp->pco_req.v))) { + if (gtpie_gettv2(ie, GTPIE_FL_C, 0, &pdp->flrc)) { + gsn->missing++; + GTP_LOGPKG(LOGL_ERROR, peer, pack, + len, "Missing mandatory information field\n"); + return gtp_create_pdp_resp(gsn, version, pdp, + GTPCAUSE_MAN_IE_MISSING); } } @@ -1581,37 +1537,53 @@ int gtp_create_pdp_ind(struct gsn_t *gsn, int version, return gtp_create_pdp_resp(gsn, version, pdp, GTPCAUSE_MAN_IE_MISSING); } + /* Recovery (optional) */ + if (!gtpie_gettv1(ie, GTPIE_RECOVERY, 0, &recovery)) { + /* we use recovery futher down after announcing new pdp ctx to user */ + recovery_recvd = true; + } if (!linked_pdp) { /* Not Secondary PDP Context Activation Procedure */ - /* MSISDN (conditional) */ - if (gtpie_gettlv(ie, GTPIE_MSISDN, 0, &pdp->msisdn.l, - &pdp->msisdn.v, sizeof(pdp->msisdn.v))) { + /* Selection mode (conditional) */ + if (gtpie_gettv0(ie, GTPIE_SELECTION_MODE, 0, + &pdp->selmode, sizeof(pdp->selmode))) { gsn->missing++; GTP_LOGPKG(LOGL_ERROR, peer, pack, len, "Missing mandatory information field\n"); return gtp_create_pdp_resp(gsn, version, pdp, GTPCAUSE_MAN_IE_MISSING); } - } - - if (version == 1) { - /* QoS (mandatory) */ - if (gtpie_gettlv(ie, GTPIE_QOS_PROFILE, 0, &pdp->qos_req.l, - &pdp->qos_req.v, sizeof(pdp->qos_req.v))) { + /* End User Address (conditional) */ + if (gtpie_gettlv(ie, GTPIE_EUA, 0, &pdp->eua.l, + &pdp->eua.v, sizeof(pdp->eua.v))) { gsn->missing++; GTP_LOGPKG(LOGL_ERROR, peer, pack, len, "Missing mandatory information field\n"); return gtp_create_pdp_resp(gsn, version, pdp, GTPCAUSE_MAN_IE_MISSING); } - - /* TFT (conditional) */ - if (gtpie_gettlv(ie, GTPIE_TFT, 0, &pdp->tft.l, - &pdp->tft.v, sizeof(pdp->tft.v))) { + /* APN */ + if (gtpie_gettlv(ie, GTPIE_APN, 0, &pdp->apn_req.l, + &pdp->apn_req.v, sizeof(pdp->apn_req.v))) { + gsn->missing++; + GTP_LOGPKG(LOGL_ERROR, peer, pack, + len, "Missing mandatory information field\n"); + return gtp_create_pdp_resp(gsn, version, pdp, + GTPCAUSE_MAN_IE_MISSING); + } + /* Extract protocol configuration options (optional) */ + if (!gtpie_gettlv(ie, GTPIE_PCO, 0, &pdp->pco_req.l, + &pdp->pco_req.v, sizeof(pdp->pco_req.v))) { + } + /* MSISDN (conditional) */ + if (gtpie_gettlv(ie, GTPIE_MSISDN, 0, &pdp->msisdn.l, + &pdp->msisdn.v, sizeof(pdp->msisdn.v))) { + gsn->missing++; + GTP_LOGPKG(LOGL_ERROR, peer, pack, + len, "Missing mandatory information field\n"); + return gtp_create_pdp_resp(gsn, version, pdp, + GTPCAUSE_MAN_IE_MISSING); } - - /* Trigger ID */ - /* OMC identity */ } /* Initialize our own IP addresses */ @@ -1688,7 +1660,7 @@ int gtp_create_pdp_ind(struct gsn_t *gsn, int version, if (pdp) pdp->gsn = gsn; - /* Callback function to validata login */ + /* Callback function to validate login */ if (gsn->cb_create_context_ind != 0) rc = gsn->cb_create_context_ind(pdp); else { |