gprs_ns2: improve handling of TLV errors on new nsvcs

The specification says the PDU should be ignored if the PDU type is
unknown.

Change-Id: I2992d06b37ed122b7ff315d4852e86acc936800b
This commit is contained in:
Alexander Couzens 2020-12-10 00:18:17 +01:00 committed by lynxis lazus
parent 2060bbb4c1
commit 12e5e6bd78
1 changed files with 20 additions and 8 deletions

View File

@ -793,19 +793,17 @@ enum gprs_ns2_cs ns2_create_vc(struct gprs_ns2_vc_bind *bind,
uint16_t nsvci;
uint16_t nsei;
int rc;
int rc, tlv;
if (msg->len < sizeof(struct gprs_ns_hdr))
return GPRS_NS2_CS_ERROR;
rc = ns2_tlv_parse(&tp, nsh->data,
/* parse the tlv early to allow reject status msg to
* work with valid tp.
* Ignore the return code until the pdu type is parsed because
* an unknown pdu type should be ignored */
tlv = ns2_tlv_parse(&tp, nsh->data,
msgb_l2len(msg) - sizeof(*nsh), 0, 0);
if (rc < 0) {
LOGP(DLNS, LOGL_ERROR, "Rx NS RESET Error %d during "
"TLV Parse\n", rc);
/* TODO: send invalid message back */
return GPRS_NS2_CS_REJECTED;
}
switch (nsh->pdu_type) {
case NS_PDUT_STATUS:
@ -849,6 +847,20 @@ enum gprs_ns2_cs ns2_create_vc(struct gprs_ns2_vc_bind *bind,
return GPRS_NS2_CS_REJECTED;
}
if (tlv < 0) {
/* TODO: correct behaviour would checking what's wrong.
* If it's an essential TLV for the PDU return NS_CAUSE_INVAL_ESSENT_IE.
* Otherwise ignore the non-essential TLV. */
LOGP(DLNS, LOGL_ERROR, "Rx NS RESET Error %d during "
"TLV Parse\n", tlv);
rc = reject_status_msg(msg, &tp, reject, NS_CAUSE_PROTO_ERR_UNSPEC);
if (rc < 0) {
LOGP(DLNS, LOGL_ERROR, "Failed to generate reject message (%d)\n", rc);
return rc;
}
return GPRS_NS2_CS_REJECTED;
}
if (!TLVP_PRES_LEN(&tp, NS_IE_CAUSE, 1) ||
!TLVP_PRES_LEN(&tp, NS_IE_VCI, 2) || !TLVP_PRES_LEN(&tp, NS_IE_NSEI, 2)) {
LOGP(DLNS, LOGL_ERROR, "NS RESET Missing mandatory IE\n");