laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmo-sigtran/+/38177?usp=email )
Change subject: Reject M3UA with "M3UA Network Appearance" ......................................................................
Reject M3UA with "M3UA Network Appearance"
The information element "Network Appearance" is not supported. In case it is included in a received message, an error is sent to the remote peer to indicate this. Additionally a message is sent on the log output.
Related: OS#6240 Change-Id: Ia2c2004a7495376fd3f44d26f6cf1b6d277c9b2f --- M src/m3ua.c M src/xua_rkm.c 2 files changed, 61 insertions(+), 9 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmo-sigtran refs/changes/77/38177/1
diff --git a/src/m3ua.c b/src/m3ua.c index fcbc759..af81da9 100644 --- a/src/m3ua.c +++ b/src/m3ua.c @@ -350,6 +350,11 @@ { struct xua_msg *xua = xua_msg_alloc();
+ if (!xua) { + LOGP(DLM3UA, LOGL_NOTICE, "Failed to allocate M3UA MGMT error message.\n"); + return NULL; + } + xua->hdr = XUA_HDR(M3UA_MSGC_MGMT, M3UA_MGMT_ERR); xua->hdr.version = M3UA_VERSION; xua_msg_add_u32(xua, M3UA_IEI_ERR_CODE, err_code); @@ -359,15 +364,31 @@
static struct xua_msg *m3ua_gen_error_msg(uint32_t err_code, struct msgb *msg) { - struct xua_msg *xua = m3ua_gen_error(err_code); - unsigned int len_max_40 = msgb_length(msg); + struct xua_msg *err = m3ua_gen_error(err_code); + struct xua_msg *xua; + struct xua_msg_part *na_ie; + unsigned int len_max_40;
- if (len_max_40 > 40) - len_max_40 = 40; + if (!err) + return NULL;
- xua_msg_add_data(xua, M3UA_IEI_DIAG_INFO, len_max_40, msgb_data(msg)); + switch (err_code) { + case M3UA_ERR_INVAL_NET_APPEAR: + /* Include NA IE in Error message. */ + xua = xua_from_msg(M3UA_VERSION, msgb_length(msg), msgb_data(msg)); + na_ie = xua_msg_find_tag(xua, M3UA_IEI_NET_APPEAR); + xua_msg_add_data(err, M3UA_IEI_NET_APPEAR, na_ie->len, na_ie->dat); + xua_msg_free(xua); + break; + default: + len_max_40 = msgb_length(msg); + if (len_max_40 > 40) + len_max_40 = 40;
- return xua; + xua_msg_add_data(err, M3UA_IEI_DIAG_INFO, len_max_40, msgb_data(msg)); + } + + return err; }
/*********************************************************************** @@ -534,6 +555,7 @@
static int m3ua_rx_xfer(struct osmo_ss7_asp *asp, struct xua_msg *xua) { + struct xua_msg_part *na_ie = xua_msg_find_tag(xua, M3UA_IEI_NET_APPEAR); struct xua_msg_part *rctx_ie = xua_msg_find_tag(xua, M3UA_IEI_ROUTE_CTX); struct m3ua_data_hdr *dh; struct osmo_ss7_as *as; @@ -549,6 +571,18 @@ return M3UA_ERR_UNSUPP_MSG_TYPE; }
+ /* Reject unsupported Network Appearance IE. */ + if (na_ie) { + uint32_t na = xua_msg_part_get_u32(na_ie); + + LOGPASP(asp, DLM3UA, LOGL_NOTICE, + "Unsupported 'Network Appearance' IE '0x%08x' in message type '%s', sending 'Error'.\n", + na, get_value_string(m3ua_xfer_msgt_names, xua->hdr.msg_type)); + if (na_ie->len != 4) + return M3UA_ERR_PARAM_FIELD_ERR; + return M3UA_ERR_INVAL_NET_APPEAR; + } + rc = xua_find_as_for_asp(&as, asp, rctx_ie); if (rc) return rc; @@ -978,6 +1012,8 @@
static int m3ua_rx_snm(struct osmo_ss7_asp *asp, struct xua_msg *xua) { + struct xua_msg_part *na_ie = xua_msg_find_tag(xua, M3UA_IEI_NET_APPEAR); + /* SNM only permitted in ACTIVE state */ if (asp->fi->state != XUA_ASP_S_ACTIVE) { if (asp->fi->state == XUA_ASP_S_INACTIVE && @@ -991,6 +1027,18 @@ } }
+ /* Reject unsupported Network Appearance IE. */ + if (na_ie) { + uint32_t na = xua_msg_part_get_u32(na_ie); + + LOGPASP(asp, DLM3UA, LOGL_NOTICE, + "Unsupported 'Network Appearance' IE '0x%08x' in message type '%s', sending 'Error'.\n", + na, get_value_string(m3ua_xfer_msgt_names, xua->hdr.msg_type)); + if (na_ie->len != 4) + return M3UA_ERR_PARAM_FIELD_ERR; + return M3UA_ERR_INVAL_NET_APPEAR; + } + switch (asp->cfg.role) { case OSMO_SS7_ASP_ROLE_SG: return m3ua_rx_snm_sg(asp, xua); diff --git a/src/xua_rkm.c b/src/xua_rkm.c index 6abd17d..914cb01 100644 --- a/src/xua_rkm.c +++ b/src/xua_rkm.c @@ -176,11 +176,15 @@
/* We don't support routing keys with the following criteria, so * we have to reject those */ - /* TODO: network appearance (optional) */ + /* Network Appearance (optional) */ + if (xua_msg_find_tag(inner, M3UA_IEI_NET_APPEAR)) { + LOGPASP(asp, DLSS7, LOGL_NOTICE, "RKM: Unsupported 'Network Appearance' IE.\n"); + msgb_append_reg_res(resp, rk_id, M3UA_RKM_REG_ERR_INVAL_NET_APPEAR, 0); + return -1; + } /* TODO: service indicators (optional) */ /* TODO: originating point code list (optional) */ - if (xua_msg_find_tag(inner, M3UA_IEI_NET_APPEAR) || - xua_msg_find_tag(inner, M3UA_IEI_SVC_IND) || + if (xua_msg_find_tag(inner, M3UA_IEI_SVC_IND) || xua_msg_find_tag(inner, M3UA_IEI_ORIG_PC)) { LOGPASP(asp, DLSS7, LOGL_NOTICE, "RKM: Unsupported Routing Key\n"); msgb_append_reg_res(resp, rk_id, M3UA_RKM_REG_ERR_UNSUPP_RK_PARAM, 0);