[PATCH] osmo-hlr[master]: add hlr_subsrc_nam to put GSUP client notification in proper...

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Neels Hofmeyr gerrit-no-reply at lists.osmocom.org
Tue Oct 17 01:09:36 UTC 2017


Review at  https://gerrit.osmocom.org/4310

add hlr_subsrc_nam to put GSUP client notification in proper API

This code should not live in a CTRL interface function but be proper hlr_* API.

Change-Id: I4c9b8f9ad51d49517474e8b51afc3cc2e1c9299a
---
M src/ctrl.c
M src/db.h
M src/db_hlr.c
3 files changed, 53 insertions(+), 15 deletions(-)


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

diff --git a/src/ctrl.c b/src/ctrl.c
index 74172c4..3bd4d8f 100644
--- a/src/ctrl.c
+++ b/src/ctrl.c
@@ -35,31 +35,19 @@
 
 static int handle_cmd_ps(struct hlr *ctx, struct ctrl_cmd *cmd, bool enable)
 {
-	struct lu_operation *luop = NULL;
-	struct osmo_gsup_conn *co;
+	struct hlr_subscriber subscr;
 
-	if (db_subscr_get_by_imsi(ctx->dbc, cmd->value, NULL) < 0) {
+	if (db_subscr_get_by_imsi(ctx->dbc, cmd->value, &subscr) < 0) {
 		cmd->reply = "Subscriber Unknown in HLR";
 		return CTRL_CMD_ERROR;
 	}
 
-	if (db_subscr_nam(ctx->dbc, cmd->value, enable, true) < 0) {
+	if (hlr_subscr_nam(ctx, &subscr, enable, true) < 0) {
 		cmd->reply = "Error updating DB";
 		return CTRL_CMD_ERROR;
 	}
 
-	/* FIXME: only send to single SGSN where latest update for IMSI came from */
-	if (!enable) {
-		llist_for_each_entry(co, &ctx->gs->clients, list) {
-			luop = lu_op_alloc_conn(co);
-			lu_op_fill_subscr(luop, ctx->dbc, cmd->value);
-			lu_op_tx_del_subscr_data(luop);
-			lu_op_free(luop);
-		}
-	}
-
 	cmd->reply = "OK";
-
 	return CTRL_CMD_REPLY;
 }
 
diff --git a/src/db.h b/src/db.h
index f6aaa58..dcffe5a 100644
--- a/src/db.h
+++ b/src/db.h
@@ -125,3 +125,5 @@
 
 int db_subscr_purge(struct db_context *dbc, const char *by_imsi,
 		    bool purge_val, bool is_ps);
+
+int hlr_subscr_nam(struct hlr *hlr, struct hlr_subscriber *subscr, bool nam_val, bool is_ps);
diff --git a/src/db_hlr.c b/src/db_hlr.c
index cf6e4f8..088a0ee 100644
--- a/src/db_hlr.c
+++ b/src/db_hlr.c
@@ -609,3 +609,51 @@
 
 	return ret;
 }
+
+/*! Update subscriber database and trigger notifications to GSUP clients.
+ * \param hlr     Global hlr context.
+ * \param subscr  Subscriber from a fresh db_subscr_get_by_*() call.
+ * \param nam_val True to enable CS/PS, false to disable.
+ * \param is_ps   True to enable/disable PS, false for CS.
+ * \returns 0 on success, ENOEXEC if there is no need to change, a negative
+ *          value on error.
+ */
+int hlr_subscr_nam(struct hlr *hlr, struct hlr_subscriber *subscr, bool nam_val, bool is_ps)
+{
+	int rc;
+        struct lu_operation *luop;
+        struct osmo_gsup_conn *co;
+	bool is_val = is_ps? subscr->nam_ps : subscr->nam_cs;
+
+	if (is_val == nam_val) {
+		LOGHLR(subscr->imsi, LOGL_DEBUG, "Already the requested value when asked to %s %s\n",
+		       nam_val ? "enable" : "disable", is_ps ? "PS" : "CS");
+		return ENOEXEC;
+	}
+
+	rc = db_subscr_nam(hlr->dbc, subscr->imsi, nam_val, is_ps);
+	if (rc)
+		return rc > 0? -rc : rc;
+
+	/* If we're disabling, send a notice out to the GSUP client that is
+	 * responsible. Otherwise no need. */
+	if (nam_val)
+		return 0;
+
+	/* FIXME: only send to single SGSN where latest update for IMSI came from */
+	llist_for_each_entry(co, &hlr->gs->clients, list) {
+		luop = lu_op_alloc_conn(co);
+		if (!luop) {
+			LOGHLR(subscr->imsi, LOGL_ERROR,
+			       "Cannot notify GSUP client, cannot allocate lu_operation,"
+			       " for %s:%u\n",
+			       co && co->conn && co->conn->server? co->conn->server->addr : "unset",
+			       co && co->conn && co->conn->server? co->conn->server->port : 0);
+			continue;
+		}
+		lu_op_fill_subscr(luop, ctx->dbc, cmd->value);
+		lu_op_tx_del_subscr_data(luop);
+		lu_op_free(luop);
+	}
+	return 0;
+}

-- 
To view, visit https://gerrit.osmocom.org/4310
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4c9b8f9ad51d49517474e8b51afc3cc2e1c9299a
Gerrit-PatchSet: 1
Gerrit-Project: osmo-hlr
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>



More information about the gerrit-log mailing list