2/2: wrap ipa_name in osmo_cni_peer_id with type enum and union

To be prepared for the future in public API, wrap the new osmo_ipa_name struct
in an enum-type and union called osmo_cni_peer.

During code review it was requested to insert an ability to handle different
kinds of peer id, in order to be able to add a Global Title in the future.

Use the generic osmo_cni_peer only in the publicly visible API. For osmo-hlr
internal code, I intend to postpone implementing this into the future, when a
different peer identification actually gets introduced.

This way we don't need to implement it now in all osmo-hlr code paths (save
time now), but still make all external API users aware that this type may be
extended in the future.

Change-Id: Ide9dcdca283ab989240cfc6e53e9211862a199c5
diff --git a/src/hlr_ussd.c b/src/hlr_ussd.c
index aa7614e..25e9354 100644
--- a/src/hlr_ussd.c
+++ b/src/hlr_ussd.c
@@ -416,22 +416,24 @@
 }
 
 /* is this GSUP connection an EUSE (true) or not (false)? */
-static bool peer_name_is_euse(const struct osmo_ipa_name *peer_name)
+static bool peer_name_is_euse(const struct osmo_cni_peer_id *peer_name)
 {
-	if (peer_name->len <= 5)
+	if (peer_name->type != OSMO_CNI_PEER_ID_IPA_NAME)
 		return false;
-	if (!strncmp((char *)(peer_name->val), "EUSE-", 5))
-		return true;
-	else
+	if (peer_name->ipa_name.len <= 5)
 		return false;
+	return strncmp((char *)(peer_name->ipa_name.val), "EUSE-", 5) == 0;
 }
 
-static struct hlr_euse *euse_by_name(const struct osmo_ipa_name *peer_name)
+static struct hlr_euse *euse_by_name(const struct osmo_cni_peer_id *peer_name)
 {
 	if (!peer_name_is_euse(peer_name))
 		return NULL;
 
-	return euse_find(g_hlr, (const char*)(peer_name->val)+5);
+	/* above peer_name_is_euse() ensures this: */
+	OSMO_ASSERT(peer_name->type == OSMO_CNI_PEER_ID_IPA_NAME);
+
+	return euse_find(g_hlr, (const char*)(peer_name->ipa_name.val)+5);
 }
 
 static int handle_ss(struct ss_session *ss, bool is_euse_originated, const struct osmo_gsup_message *gsup,
@@ -519,6 +521,14 @@
 	LOGP(DSS, LOGL_DEBUG, "%s/0x%08x: Process SS (%s)\n", gsup->imsi, gsup->session_id,
 		osmo_gsup_session_state_name(gsup->session_state));
 
+	if (gsup_req->source_name.type != OSMO_CNI_PEER_ID_IPA_NAME) {
+		LOGP(DSS, LOGL_ERROR, "%s/0x%082x: Unable to process SS request: Unsupported GSUP peer id type%s\n",
+		     gsup->imsi, gsup->session_id,
+		     osmo_cni_peer_id_type_name(gsup_req->source_name.type));
+		osmo_gsup_req_respond_err(gsup_req, GMM_CAUSE_PROTO_ERR_UNSPEC, "error processing SS request");
+		return;
+	}
+
 	/* decode and find out what kind of SS message it is */
 	if (gsup->ss_info && gsup->ss_info_len) {
 		if (gsm0480_parse_facility_ie(gsup->ss_info, gsup->ss_info_len, &req)) {
@@ -556,7 +566,8 @@
 		if (!is_euse_originated) {
 			ss->initial_req_from_ms = gsup_req;
 			free_gsup_req = NULL;
-			ss->vlr_name = gsup_req->source_name;
+			OSMO_ASSERT(gsup_req->source_name.type == OSMO_CNI_PEER_ID_IPA_NAME); /* checked above */
+			ss->vlr_name = gsup_req->source_name.ipa_name;
 		} else {
 			ss->initial_req_from_euse = gsup_req;
 			free_gsup_req = NULL;