aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeels Hofmeyr <neels@hofmeyr.de>2019-12-04 01:04:32 +0100
committerNeels Hofmeyr <neels@hofmeyr.de>2020-04-30 19:19:17 +0200
commitc79bcdedc92a5ae7dad67b5f10452d549ccfb39e (patch)
treee6d952b6fc4b2dc5d14399da0e88e551e89b6493
parentad868e29ba1b838f151cdf2ad9cb4f068a817493 (diff)
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
-rw-r--r--include/Makefile.am2
-rw-r--r--include/osmocom/gsupclient/cni_peer_id.h (renamed from include/osmocom/gsupclient/ipa_name.h)28
-rw-r--r--include/osmocom/gsupclient/gsup_req.h10
-rw-r--r--include/osmocom/hlr/db.h2
-rw-r--r--include/osmocom/hlr/gsup_server.h2
-rw-r--r--src/Makefile.am2
-rw-r--r--src/db_hlr.c2
-rw-r--r--src/gsup_server.c39
-rw-r--r--src/gsupclient/Makefile.am2
-rw-r--r--src/gsupclient/cni_peer_id.c (renamed from src/gsupclient/ipa_name.c)102
-rw-r--r--src/gsupclient/gsup_req.c13
-rw-r--r--src/hlr.c2
-rw-r--r--src/hlr_ussd.c27
-rw-r--r--src/lu_fsm.c30
-rw-r--r--tests/db/Makefile.am2
-rw-r--r--tests/db/db_test.c2
-rw-r--r--tests/gsup_server/Makefile.am2
17 files changed, 217 insertions, 52 deletions
diff --git a/include/Makefile.am b/include/Makefile.am
index aeeb03f..e93fe29 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -1,7 +1,7 @@
SUBDIRS = osmocom
nobase_include_HEADERS = \
- osmocom/gsupclient/ipa_name.h \
+ osmocom/gsupclient/cni_peer_id.h \
osmocom/gsupclient/gsup_client.h \
osmocom/gsupclient/gsup_req.h \
osmocom/mslookup/mdns.h \
diff --git a/include/osmocom/gsupclient/ipa_name.h b/include/osmocom/gsupclient/cni_peer_id.h
index 73cd1fb..6e58d06 100644
--- a/include/osmocom/gsupclient/ipa_name.h
+++ b/include/osmocom/gsupclient/cni_peer_id.h
@@ -19,6 +19,7 @@
#pragma once
#include <unistd.h>
#include <stdint.h>
+#include <osmocom/core/utils.h>
/*! IPA Name: Arbitrary length blob, not necessarily zero-terminated.
* In osmo-hlr, struct hlr_subscriber is mostly used as static reference and cannot serve as talloc context, which is
@@ -31,8 +32,35 @@ struct osmo_ipa_name {
uint8_t val[128];
};
+bool osmo_ipa_name_is_empty(const struct osmo_ipa_name *ipa_name);
int osmo_ipa_name_set(struct osmo_ipa_name *ipa_name, const uint8_t *val, size_t len);
int osmo_ipa_name_set_str(struct osmo_ipa_name *ipa_name, const char *str_fmt, ...);
int osmo_ipa_name_cmp(const struct osmo_ipa_name *a, const struct osmo_ipa_name *b);
const char *osmo_ipa_name_to_str_c(void *ctx, const struct osmo_ipa_name *ipa_name);
const char *osmo_ipa_name_to_str(const struct osmo_ipa_name *ipa_name);
+
+enum osmo_cni_peer_id_type {
+ OSMO_CNI_PEER_ID_EMPTY=0,
+ OSMO_CNI_PEER_ID_IPA_NAME,
+ /* OSMO_CNI_PEER_ID_GLOBAL_TITLE, <-- currently not implemented, but likely future possibility */
+};
+
+extern const struct value_string osmo_cni_peer_id_type_names[];
+static inline const char *osmo_cni_peer_id_type_name(enum osmo_cni_peer_id_type val)
+{ return get_value_string(osmo_cni_peer_id_type_names, val); }
+
+struct osmo_cni_peer_id {
+ enum osmo_cni_peer_id_type type;
+ union {
+ struct osmo_ipa_name ipa_name;
+ };
+};
+
+bool osmo_cni_peer_id_is_empty(const struct osmo_cni_peer_id *cni_peer_id);
+int osmo_cni_peer_id_set(struct osmo_cni_peer_id *cni_peer_id, enum osmo_cni_peer_id_type type,
+ const uint8_t *val, size_t len);
+int osmo_cni_peer_id_set_str(struct osmo_cni_peer_id *cni_peer_id, enum osmo_cni_peer_id_type type,
+ const char *str_fmt, ...);
+int osmo_cni_peer_id_cmp(const struct osmo_cni_peer_id *a, const struct osmo_cni_peer_id *b);
+const char *osmo_cni_peer_id_to_str(const struct osmo_cni_peer_id *cni_peer_id);
+const char *osmo_cni_peer_id_to_str_c(void *ctx, const struct osmo_cni_peer_id *cni_peer_id);
diff --git a/include/osmocom/gsupclient/gsup_req.h b/include/osmocom/gsupclient/gsup_req.h
index c61483b..2d3cf38 100644
--- a/include/osmocom/gsupclient/gsup_req.h
+++ b/include/osmocom/gsupclient/gsup_req.h
@@ -19,14 +19,14 @@
#pragma once
#include <osmocom/gsm/gsup.h>
-#include <osmocom/gsupclient/ipa_name.h>
+#include <osmocom/gsupclient/cni_peer_id.h>
struct osmo_gsup_req;
#define LOG_GSUP_REQ_CAT_SRC(req, subsys, level, file, line, fmt, args...) \
LOGPSRC(subsys, level, file, line, "GSUP %u: %s: IMSI-%s %s: " fmt, \
(req) ? (req)->nr : 0, \
- (req) ? osmo_ipa_name_to_str(&(req)->source_name) : "NULL", \
+ (req) ? osmo_cni_peer_id_to_str(&(req)->source_name) : "NULL", \
(req) ? (req)->gsup.imsi : "NULL", \
(req) ? osmo_gsup_message_type_name((req)->gsup.message_type) : "NULL", \
##args)
@@ -56,11 +56,11 @@ struct osmo_gsup_req {
/* The ultimate source of this message: the source_name form the GSUP message, or, if not present, then the
* immediate GSUP peer. GSUP messages going via a proxy reflect the initial source in the source_name.
* This source_name is implicitly added to the routes for the conn the message was received on. */
- struct osmo_ipa_name source_name;
+ struct osmo_cni_peer_id source_name;
/* If the source_name is not an immediate GSUP peer, this is set to the closest intermediate peer between here
* and source_name. */
- struct osmo_ipa_name via_proxy;
+ struct osmo_cni_peer_id via_proxy;
/* Identify this request by number, for logging. */
unsigned int nr;
@@ -82,7 +82,7 @@ struct osmo_gsup_req {
struct msgb *msg;
};
-struct osmo_gsup_req *osmo_gsup_req_new(void *ctx, const struct osmo_ipa_name *from_peer, struct msgb *msg,
+struct osmo_gsup_req *osmo_gsup_req_new(void *ctx, const struct osmo_cni_peer_id *from_peer, struct msgb *msg,
osmo_gsup_req_send_response_t send_response_cb, void *cb_data,
struct llist_head *add_to_list);
void osmo_gsup_req_free(struct osmo_gsup_req *req);
diff --git a/include/osmocom/hlr/db.h b/include/osmocom/hlr/db.h
index 5c627be..9be88d8 100644
--- a/include/osmocom/hlr/db.h
+++ b/include/osmocom/hlr/db.h
@@ -3,7 +3,7 @@
#include <stdbool.h>
#include <sqlite3.h>
-#include <osmocom/gsupclient/ipa_name.h>
+#include <osmocom/gsupclient/cni_peer_id.h>
struct hlr;
diff --git a/include/osmocom/hlr/gsup_server.h b/include/osmocom/hlr/gsup_server.h
index 149971a..774f750 100644
--- a/include/osmocom/hlr/gsup_server.h
+++ b/include/osmocom/hlr/gsup_server.h
@@ -5,7 +5,7 @@
#include <osmocom/abis/ipa.h>
#include <osmocom/abis/ipaccess.h>
#include <osmocom/gsm/gsup.h>
-#include <osmocom/gsupclient/ipa_name.h>
+#include <osmocom/gsupclient/cni_peer_id.h>
#include <osmocom/gsupclient/gsup_req.h>
#ifndef OSMO_GSUP_MAX_CALLED_PARTY_BCD_LEN
diff --git a/src/Makefile.am b/src/Makefile.am
index bfbe775..fec5275 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -72,7 +72,7 @@ osmo_hlr_db_tool_SOURCES = \
logging.c \
rand_urandom.c \
dbd_decode_binary.c \
- $(srcdir)/gsupclient/ipa_name.c \
+ $(srcdir)/gsupclient/cni_peer_id.c \
$(NULL)
osmo_hlr_db_tool_LDADD = \
diff --git a/src/db_hlr.c b/src/db_hlr.c
index fdac75f..ec8f896 100644
--- a/src/db_hlr.c
+++ b/src/db_hlr.c
@@ -37,7 +37,7 @@
#include <osmocom/hlr/logging.h>
#include <osmocom/hlr/hlr.h>
#include <osmocom/hlr/db.h>
-#include <osmocom/gsupclient/ipa_name.h>
+#include <osmocom/gsupclient/cni_peer_id.h>
#define LOGHLR(imsi, level, fmt, args ...) LOGP(DAUC, level, "IMSI='%s': " fmt, imsi, ## args)
diff --git a/src/gsup_server.c b/src/gsup_server.c
index ba2d456..e9418d4 100644
--- a/src/gsup_server.c
+++ b/src/gsup_server.c
@@ -65,13 +65,21 @@ int osmo_gsup_conn_send(struct osmo_gsup_conn *conn, struct msgb *msg)
static void gsup_server_send_req_response(struct osmo_gsup_req *req, struct osmo_gsup_message *response)
{
struct osmo_gsup_server *server = req->cb_data;
- struct osmo_gsup_conn *conn;
+ struct osmo_gsup_conn *conn = NULL;
struct msgb *msg = osmo_gsup_msgb_alloc("GSUP Tx");
int rc;
- conn = gsup_route_find_by_ipa_name(server, &req->source_name);
+ switch (req->source_name.type) {
+ case OSMO_CNI_PEER_ID_IPA_NAME:
+ conn = gsup_route_find_by_ipa_name(server, &req->source_name.ipa_name);
+ break;
+ default:
+ LOG_GSUP_REQ(req, LOGL_ERROR, "GSUP peer id kind not supported: %s\n",
+ osmo_cni_peer_id_type_name(req->source_name.type));
+ break;
+ }
if (!conn) {
- LOG_GSUP_REQ(req, LOGL_ERROR, "GSUP client that sent this request was disconnected, cannot respond\n");
+ LOG_GSUP_REQ(req, LOGL_ERROR, "GSUP client that sent this request not found, cannot respond\n");
msgb_free(msg);
return;
}
@@ -91,19 +99,34 @@ static void gsup_server_send_req_response(struct osmo_gsup_req *req, struct osmo
struct osmo_gsup_req *osmo_gsup_conn_rx(struct osmo_gsup_conn *conn, struct msgb *msg)
{
- struct osmo_gsup_req *req = osmo_gsup_req_new(conn->server, &conn->peer_name, msg, gsup_server_send_req_response,
- conn->server, NULL);
+ struct osmo_gsup_req *req;
+ struct osmo_cni_peer_id cpi = {
+ .type = OSMO_CNI_PEER_ID_IPA_NAME,
+ .ipa_name = conn->peer_name,
+ };
+
+ req = osmo_gsup_req_new(conn->server, &cpi, msg, gsup_server_send_req_response, conn->server, NULL);
if (!req)
return NULL;
- if (req->via_proxy.len) {
+ if (!osmo_cni_peer_id_is_empty(&req->via_proxy)) {
+ switch (req->via_proxy.type) {
+ case OSMO_CNI_PEER_ID_IPA_NAME:
+ break;
+ default:
+ LOG_GSUP_REQ(req, LOGL_ERROR, "GSUP peer id kind not supported: %s\n",
+ osmo_cni_peer_id_type_name(req->source_name.type));
+ osmo_gsup_req_respond_msgt(req, OSMO_GSUP_MSGT_ROUTING_ERROR, true);
+ return NULL;
+ }
+
/* The source of the GSUP message is not the immediate GSUP peer, but that peer is our proxy for that
* source. Add it to the routes for this conn (so we can route responses back). */
- if (gsup_route_add_ipa_name(conn, &req->source_name)) {
+ if (gsup_route_add_ipa_name(conn, &req->source_name.ipa_name)) {
LOG_GSUP_REQ(req, LOGL_ERROR,
"GSUP message received from %s via peer %s, but there already exists a"
" different route to this source, message is not routable\n",
- osmo_ipa_name_to_str(&req->source_name),
+ osmo_cni_peer_id_to_str(&req->source_name),
osmo_ipa_name_to_str(&conn->peer_name));
osmo_gsup_req_respond_msgt(req, OSMO_GSUP_MSGT_ROUTING_ERROR, true);
return NULL;
diff --git a/src/gsupclient/Makefile.am b/src/gsupclient/Makefile.am
index 38b1582..3412c40 100644
--- a/src/gsupclient/Makefile.am
+++ b/src/gsupclient/Makefile.am
@@ -9,7 +9,7 @@ AM_CFLAGS = -Wall $(all_includes) -I$(top_srcdir)/include -I$(top_builddir)/incl
lib_LTLIBRARIES = libosmo-gsup-client.la
libosmo_gsup_client_la_SOURCES = \
- ipa_name.c \
+ cni_peer_id.c \
gsup_client.c \
gsup_req.c \
$(NULL)
diff --git a/src/gsupclient/ipa_name.c b/src/gsupclient/cni_peer_id.c
index 2db069f..de7b4bc 100644
--- a/src/gsupclient/ipa_name.c
+++ b/src/gsupclient/cni_peer_id.c
@@ -19,7 +19,12 @@
#include <errno.h>
#include <string.h>
#include <osmocom/core/utils.h>
-#include <osmocom/gsupclient/ipa_name.h>
+#include <osmocom/gsupclient/cni_peer_id.h>
+
+bool osmo_ipa_name_is_empty(const struct osmo_ipa_name *ipa_name)
+{
+ return (!ipa_name) || (!ipa_name->len);
+}
int osmo_ipa_name_set(struct osmo_ipa_name *ipa_name, const uint8_t *val, size_t len)
{
@@ -34,19 +39,25 @@ int osmo_ipa_name_set(struct osmo_ipa_name *ipa_name, const uint8_t *val, size_t
return 0;
}
-int osmo_ipa_name_set_str(struct osmo_ipa_name *ipa_name, const char *str_fmt, ...)
+static int osmo_ipa_name_set_str_va(struct osmo_ipa_name *ipa_name, const char *str_fmt, va_list ap)
{
- va_list ap;
if (!str_fmt)
return osmo_ipa_name_set(ipa_name, NULL, 0);
-
- va_start(ap, str_fmt);
vsnprintf((char*)(ipa_name->val), sizeof(ipa_name->val), str_fmt, ap);
- va_end(ap);
ipa_name->len = strlen((char*)(ipa_name->val))+1;
return 0;
}
+int osmo_ipa_name_set_str(struct osmo_ipa_name *ipa_name, const char *str_fmt, ...)
+{
+ va_list ap;
+ int rc;
+ va_start(ap, str_fmt);
+ rc = osmo_ipa_name_set_str_va(ipa_name, str_fmt, ap);
+ va_end(ap);
+ return rc;
+}
+
int osmo_ipa_name_cmp(const struct osmo_ipa_name *a, const struct osmo_ipa_name *b)
{
int cmp;
@@ -95,3 +106,82 @@ const char *osmo_ipa_name_to_str_c(void *ctx, const struct osmo_ipa_name *ipa_na
len--;
return osmo_escape_str_c(ctx, (char*)ipa_name->val, len);
}
+
+bool osmo_cni_peer_id_is_empty(const struct osmo_cni_peer_id *cni_peer_id)
+{
+ if (!cni_peer_id)
+ return true;
+ switch (cni_peer_id->type) {
+ case OSMO_CNI_PEER_ID_EMPTY:
+ return true;
+ case OSMO_CNI_PEER_ID_IPA_NAME:
+ return osmo_ipa_name_is_empty(&cni_peer_id->ipa_name);
+ default:
+ return false;
+ }
+}
+int osmo_cni_peer_id_set(struct osmo_cni_peer_id *cni_peer_id, enum osmo_cni_peer_id_type type,
+ const uint8_t *val, size_t len)
+{
+ cni_peer_id->type = type;
+ switch (type) {
+ case OSMO_CNI_PEER_ID_IPA_NAME:
+ return osmo_ipa_name_set(&cni_peer_id->ipa_name, val, len);
+ default:
+ return -EINVAL;
+ }
+}
+
+int osmo_cni_peer_id_set_str(struct osmo_cni_peer_id *cni_peer_id, enum osmo_cni_peer_id_type type,
+ const char *str_fmt, ...)
+{
+ va_list ap;
+ int rc;
+
+ *cni_peer_id = (struct osmo_cni_peer_id){};
+
+ switch (type) {
+ case OSMO_CNI_PEER_ID_IPA_NAME:
+ cni_peer_id->type = OSMO_CNI_PEER_ID_IPA_NAME;
+ va_start(ap, str_fmt);
+ rc = osmo_ipa_name_set_str_va(&cni_peer_id->ipa_name, str_fmt, ap);
+ va_end(ap);
+ return rc;
+ default:
+ return -EINVAL;
+ }
+}
+
+int osmo_cni_peer_id_cmp(const struct osmo_cni_peer_id *a, const struct osmo_cni_peer_id *b)
+{
+ if (a->type != b->type)
+ return OSMO_CMP(a->type, b->type);
+ switch (a->type) {
+ case OSMO_CNI_PEER_ID_IPA_NAME:
+ return osmo_ipa_name_cmp(&a->ipa_name, &b->ipa_name);
+ default:
+ return -EINVAL;
+ }
+}
+
+const struct value_string osmo_cni_peer_id_type_names[] = {
+ { OSMO_CNI_PEER_ID_IPA_NAME, "IPA-name" },
+ {}
+};
+
+/* Call osmo_cni_peer_id_to_str_c with OTC_SELECT */
+const char *osmo_cni_peer_id_to_str(const struct osmo_cni_peer_id *cpi)
+{
+ return osmo_cni_peer_id_to_str_c(OTC_SELECT, cpi);
+}
+
+/* Return an unquoted string, not including the terminating zero. Used for writing VTY config. */
+const char *osmo_cni_peer_id_to_str_c(void *ctx, const struct osmo_cni_peer_id *cpi)
+{
+ switch (cpi->type) {
+ case OSMO_CNI_PEER_ID_IPA_NAME:
+ return osmo_ipa_name_to_str_c(ctx, &cpi->ipa_name);
+ default:
+ return talloc_strdup(ctx, osmo_cni_peer_id_type_name(cpi->type));
+ }
+}
diff --git a/src/gsupclient/gsup_req.c b/src/gsupclient/gsup_req.c
index 4a2ff23..a8a66d5 100644
--- a/src/gsupclient/gsup_req.c
+++ b/src/gsupclient/gsup_req.c
@@ -99,7 +99,7 @@
* \return a newly allocated osmo_gsup_req, or NULL on error. If NULL is returned, an error response has already been
* dispatched to the send_response_cb.
*/
-struct osmo_gsup_req *osmo_gsup_req_new(void *ctx, const struct osmo_ipa_name *from_peer, struct msgb *msg,
+struct osmo_gsup_req *osmo_gsup_req_new(void *ctx, const struct osmo_cni_peer_id *from_peer, struct msgb *msg,
osmo_gsup_req_send_response_t send_response_cb, void *cb_data,
struct llist_head *add_to_list)
{
@@ -109,7 +109,7 @@ struct osmo_gsup_req *osmo_gsup_req_new(void *ctx, const struct osmo_ipa_name *f
if (!msgb_l2(msg) || !msgb_l2len(msg)) {
LOGP(DLGSUP, LOGL_ERROR, "Rx GSUP from %s: missing or empty L2 data\n",
- osmo_ipa_name_to_str(from_peer));
+ osmo_cni_peer_id_to_str(from_peer));
msgb_free(msg);
return NULL;
}
@@ -125,7 +125,7 @@ struct osmo_gsup_req *osmo_gsup_req_new(void *ctx, const struct osmo_ipa_name *f
req->source_name = *from_peer;
rc = osmo_gsup_decode(msgb_l2(req->msg), msgb_l2len(req->msg), (struct osmo_gsup_message*)&req->gsup);
if (rc < 0) {
- LOGP(DLGSUP, LOGL_ERROR, "Rx GSUP from %s: cannot decode (rc=%d)\n", osmo_ipa_name_to_str(from_peer), rc);
+ LOGP(DLGSUP, LOGL_ERROR, "Rx GSUP from %s: cannot decode (rc=%d)\n", osmo_cni_peer_id_to_str(from_peer), rc);
osmo_gsup_req_free(req);
return NULL;
}
@@ -133,17 +133,18 @@ struct osmo_gsup_req *osmo_gsup_req_new(void *ctx, const struct osmo_ipa_name *f
LOG_GSUP_REQ(req, LOGL_DEBUG, "new request: {%s}\n", osmo_gsup_message_to_str_c(OTC_SELECT, &req->gsup));
if (req->gsup.source_name_len) {
- if (osmo_ipa_name_set(&req->source_name, req->gsup.source_name, req->gsup.source_name_len)) {
+ if (osmo_cni_peer_id_set(&req->source_name, OSMO_CNI_PEER_ID_IPA_NAME,
+ req->gsup.source_name, req->gsup.source_name_len)) {
LOGP(DLGSUP, LOGL_ERROR,
"Rx GSUP from %s: failed to decode source_name, message is not routable\n",
- osmo_ipa_name_to_str(from_peer));
+ osmo_cni_peer_id_to_str(from_peer));
osmo_gsup_req_respond_msgt(req, OSMO_GSUP_MSGT_ROUTING_ERROR, true);
return NULL;
}
/* The source of the GSUP message is not the immediate GSUP peer; the peer is our proxy for that source.
*/
- if (osmo_ipa_name_cmp(&req->source_name, from_peer))
+ if (osmo_cni_peer_id_cmp(&req->source_name, from_peer))
req->via_proxy = *from_peer;
}
diff --git a/src/hlr.c b/src/hlr.c
index 47b3211..a33a68c 100644
--- a/src/hlr.c
+++ b/src/hlr.c
@@ -37,7 +37,7 @@
#include <osmocom/gsm/gsm_utils.h>
#include <osmocom/gsm/gsm23003.h>
-#include <osmocom/gsupclient/ipa_name.h>
+#include <osmocom/gsupclient/cni_peer_id.h>
#include <osmocom/hlr/db.h>
#include <osmocom/hlr/hlr.h>
#include <osmocom/hlr/ctrl.h>
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 @@ static bool ss_op_is_ussd(uint8_t opcode)
}
/* 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 @@ void rx_proc_ss_req(struct osmo_gsup_req *gsup_req)
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 @@ void rx_proc_ss_req(struct osmo_gsup_req *gsup_req)
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;
diff --git a/src/lu_fsm.c b/src/lu_fsm.c
index bded4ef..b5493db 100644
--- a/src/lu_fsm.c
+++ b/src/lu_fsm.c
@@ -26,7 +26,7 @@
#include <osmocom/gsm/apn.h>
#include <osmocom/gsm/gsm48_ie.h>
-#include <osmocom/gsupclient/ipa_name.h>
+#include <osmocom/gsupclient/cni_peer_id.h>
#include <osmocom/gsupclient/gsup_req.h>
#include <osmocom/hlr/logging.h>
#include <osmocom/hlr/hlr.h>
@@ -52,11 +52,11 @@ struct lu {
bool is_ps;
/* VLR requesting the LU. */
- struct osmo_ipa_name vlr_name;
+ struct osmo_cni_peer_id vlr_name;
/* If the LU request was received via a proxy and not immediately from a local VLR, this indicates the closest
* peer that forwarded the GSUP message. */
- struct osmo_ipa_name via_proxy;
+ struct osmo_cni_peer_id via_proxy;
};
LLIST_HEAD(g_all_lu);
@@ -130,7 +130,7 @@ static void lu_start(struct osmo_gsup_req *update_location_req)
osmo_fsm_inst_update_id_f_sanitize(fi, '_', "%s:IMSI-%s", lu->is_ps ? "PS" : "CS", update_location_req->gsup.imsi);
- if (!lu->vlr_name.len) {
+ if (osmo_cni_peer_id_is_empty(&lu->vlr_name)) {
lu_failure(lu, GMM_CAUSE_NET_FAIL, "LU without a VLR");
return;
}
@@ -163,18 +163,30 @@ static void lu_start(struct osmo_gsup_req *update_location_req)
#endif
/* Store the VLR / SGSN number with the subscriber, so we know where it was last seen. */
- if (lu->via_proxy.len) {
+ if (!osmo_cni_peer_id_is_empty(&lu->via_proxy)) {
LOG_GSUP_REQ(update_location_req, LOGL_DEBUG, "storing %s = %s, via proxy %s\n",
lu->is_ps ? "SGSN number" : "VLR number",
- osmo_ipa_name_to_str(&lu->vlr_name),
- osmo_ipa_name_to_str(&lu->via_proxy));
+ osmo_cni_peer_id_to_str(&lu->vlr_name),
+ osmo_cni_peer_id_to_str(&lu->via_proxy));
} else {
LOG_GSUP_REQ(update_location_req, LOGL_DEBUG, "storing %s = %s\n",
lu->is_ps ? "SGSN number" : "VLR number",
- osmo_ipa_name_to_str(&lu->vlr_name));
+ osmo_cni_peer_id_to_str(&lu->vlr_name));
}
- if (db_subscr_lu(g_hlr->dbc, lu->subscr.id, &lu->vlr_name, lu->is_ps, &lu->via_proxy)) {
+ if (osmo_cni_peer_id_is_empty(&lu->vlr_name)
+ || (lu->vlr_name.type != OSMO_CNI_PEER_ID_IPA_NAME)) {
+ lu_failure(lu, GMM_CAUSE_PROTO_ERR_UNSPEC, "Unsupported GSUP peer id type for vlr_name: %s",
+ osmo_cni_peer_id_type_name(lu->vlr_name.type));
+ return;
+ }
+ if (!osmo_cni_peer_id_is_empty(&lu->via_proxy) && (lu->via_proxy.type != OSMO_CNI_PEER_ID_IPA_NAME)) {
+ lu_failure(lu, GMM_CAUSE_PROTO_ERR_UNSPEC, "Unsupported GSUP peer id type for via_proxy: %s",
+ osmo_cni_peer_id_type_name(lu->via_proxy.type));
+ return;
+ }
+ if (db_subscr_lu(g_hlr->dbc, lu->subscr.id, &lu->vlr_name.ipa_name, lu->is_ps,
+ osmo_cni_peer_id_is_empty(&lu->via_proxy)? NULL : &lu->via_proxy.ipa_name)) {
lu_failure(lu, GMM_CAUSE_NET_FAIL, "Cannot update %s in the database",
lu->is_ps ? "SGSN number" : "VLR number");
return;
diff --git a/tests/db/Makefile.am b/tests/db/Makefile.am
index 0194957..ece34d3 100644
--- a/tests/db/Makefile.am
+++ b/tests/db/Makefile.am
@@ -30,7 +30,7 @@ db_test_LDADD = \
$(top_builddir)/src/db_auc.o \
$(top_builddir)/src/db_hlr.o \
$(top_builddir)/src/db.o \
- $(top_builddir)/src/ipa_name.o \
+ $(top_builddir)/src/cni_peer_id.o \
$(LIBOSMOCORE_LIBS) \
$(LIBOSMOGSM_LIBS) \
$(LIBOSMOABIS_LIBS) \
diff --git a/tests/db/db_test.c b/tests/db/db_test.c
index c53baed..c1df9bf 100644
--- a/tests/db/db_test.c
+++ b/tests/db/db_test.c
@@ -27,7 +27,7 @@
#include <osmocom/core/utils.h>
#include <osmocom/core/logging.h>
-#include <osmocom/gsupclient/ipa_name.h>
+#include <osmocom/gsupclient/cni_peer_id.h>
#include <osmocom/hlr/db.h>
#include <osmocom/hlr/logging.h>
diff --git a/tests/gsup_server/Makefile.am b/tests/gsup_server/Makefile.am
index 48fda88..a32ddf9 100644
--- a/tests/gsup_server/Makefile.am
+++ b/tests/gsup_server/Makefile.am
@@ -31,7 +31,7 @@ gsup_server_test_SOURCES = \
gsup_server_test_LDADD = \
$(top_srcdir)/src/gsup_server.c \
$(top_srcdir)/src/gsup_router.c \
- $(top_srcdir)/src/gsupclient/ipa_name.c \
+ $(top_srcdir)/src/gsupclient/cni_peer_id.c \
$(top_srcdir)/src/gsupclient/gsup_req.c \
$(LIBOSMOCORE_LIBS) \
$(LIBOSMOGSM_LIBS) \