osmith has uploaded this change for review. ( https://gerrit.osmocom.org/13006


Change subject: hlr.c: forward GSUP messages between clients
......................................................................

hlr.c: forward GSUP messages between clients

Allow clients to forward any GSUP message between clients. Determine the
sender and receiver from the new {source,dest}_name{,_len} IEs. Reject
messages with a forged source name or invalid source/dest name lengths.

This will be used for the inter-MSC handover.

Depends: Ic00b0601eacff6d72927cea51767801142ee75db (libosmocore.git)
Related: OS#3793
Change-Id: Ia4f345abc877baaf0a8f73b8988e6514d9589bf5
---
M src/hlr.c
1 file changed, 50 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-hlr refs/changes/06/13006/1

diff --git a/src/hlr.c b/src/hlr.c
index c544310..15ebc20 100644
--- a/src/hlr.c
+++ b/src/hlr.c
@@ -440,6 +440,53 @@
        return osmo_gsup_conn_send(conn, msg_out);
 }

+static int read_cb_forward(const struct osmo_gsup_conn *conn, struct msgb 
*msg, const struct osmo_gsup_message *gsup)
+{
+       struct msgb *msg_out;
+       int ret = -EINVAL;
+
+       /* Check for routing IEs */
+       if (!gsup->source_name
+           || !gsup->source_name_len
+           || !gsup->destination_name
+           || !gsup->destination_name_len) {
+               LOGP(DMAIN, LOGL_ERROR, "Can't forward GSUP message for IMSI 
%s: missing routing IEs\n", gsup->imsi);
+               goto end;
+       }
+
+       /* Verify source/dest string length */
+       if (gsup->source_name_len < 1
+           || gsup->destination_name_len < 1
+           || gsup->source_name[gsup->source_name_len - 1] != '\0'
+           || gsup->destination_name[gsup->destination_name_len - 1] != '\0')
+       {
+               LOGP(DMAIN, LOGL_ERROR, "Can't forward GSUP message for IMSI 
%s: unexpected source/dest length\n",
+                    gsup->imsi);
+               goto end;
+       }
+
+       /* Verify source name (e.g. "MSC-00-00-00-00-00-00") */
+       if (gsup_route_find(conn->server, gsup->source_name, 
gsup->source_name_len) != conn) {
+               LOGP(DMAIN, LOGL_ERROR, "Can't forward GSUP message for IMSI 
%s: invalid source name '%s'\n",
+                    gsup->imsi, gsup->source_name);
+               goto end;
+       }
+
+       /* Forward message without re-encoding (so we don't remove unknown IEs) 
*/
+       LOGP(DMAIN, LOGL_DEBUG, "Forwarding GSUP message for IMSI %s from %s to 
%s\n", gsup->imsi, gsup->source_name,
+            gsup->destination_name);
+       msg_out = msgb_alloc_headroom(1024+16, 16, "GSUP FORWARD");
+       ret = osmo_gsup_addr_send(g_hlr->gs, gsup->destination_name, 
gsup->destination_name_len, msg_out);
+       if (ret)
+               LOGP(DMAIN, LOGL_ERROR, "Can't forward GSUP message for IMSI %s 
from %s to %s: destination not"
+                                       " connected?\n", gsup->imsi, 
gsup->source_name, gsup->destination_name);
+
+end:
+       /* FIXME: send message back to sender on failure (new GSUP message 
type?) */
+       msgb_free(msg);
+       return ret;
+}
+
 static int read_cb(struct osmo_gsup_conn *conn, struct msgb *msg)
 {
        static struct osmo_gsup_message gsup;
@@ -456,6 +503,9 @@
        if (strlen(gsup.imsi) < 5)
                return gsup_send_err_reply(conn, gsup.imsi, gsup.message_type, 
GMM_CAUSE_INV_MAND_INFO);

+       if (gsup.destination_name_len)
+               return read_cb_forward(conn, msg, &gsup);
+
        switch (gsup.message_type) {
        /* requests sent to us */
        case OSMO_GSUP_MSGT_SEND_AUTH_INFO_REQUEST:

--
To view, visit https://gerrit.osmocom.org/13006
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-hlr
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia4f345abc877baaf0a8f73b8988e6514d9589bf5
Gerrit-Change-Number: 13006
Gerrit-PatchSet: 1
Gerrit-Owner: osmith <[email protected]>

Reply via email to