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/.
Max gerrit-no-reply at lists.osmocom.orgHello Harald Welte, Jenkins Builder, I'd like you to reexamine a change. Please visit https://gerrit.osmocom.org/1856 to look at the new patch set (#7). Add global HLR struct Introduce g_hlr of type 'struct hlr' which holds pointers to all globally accessible variables. Change-Id: I275d3d54482f696e3378606b2406c7e0ad939e0f Related: OS#1645 --- M src/Makefile.am M src/db_test.c M src/hlr.c A src/hlr.h 4 files changed, 64 insertions(+), 24 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-hlr refs/changes/56/1856/7 diff --git a/src/Makefile.am b/src/Makefile.am index 56a5670..1791343 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -14,6 +14,7 @@ noinst_HEADERS = \ auc.h \ db.h \ + hlr.h \ luop.h \ gsup_router.h \ gsup_server.h \ diff --git a/src/db_test.c b/src/db_test.c index 75fcb62..998a37a 100644 --- a/src/db_test.c +++ b/src/db_test.c @@ -4,12 +4,13 @@ #include <osmocom/core/application.h> #include "db.h" +#include "hlr.h" #include "rand.h" #include "logging.h" -static struct db_context *g_dbc; +static struct hlr *g_hlr; -static int test(const char *imsi) +static int test(const char *imsi, struct db_context *dbc) { struct osmo_auth_vector vec[3]; int rc, i; @@ -19,7 +20,7 @@ for (i = 0; i < ARRAY_SIZE(vec); i++) vec[i].res_len = 0; - rc = db_get_auc(g_dbc, imsi, vec, ARRAY_SIZE(vec), NULL, NULL); + rc = db_get_auc(dbc, imsi, vec, ARRAY_SIZE(vec), NULL, NULL); if (rc <= 0) { LOGP(DMAIN, LOGL_ERROR, "Cannot obtain auth tuples for '%s'\n", imsi); return rc; @@ -46,6 +47,8 @@ { int rc; + g_hlr = talloc_zero(NULL, struct hlr); + rc = osmo_init_logging(&hlr_log_info); if (rc < 0) { fprintf(stderr, "Error initializing logging\n"); @@ -59,24 +62,24 @@ exit(1); } - g_dbc = db_open(NULL, "hlr.db"); - if (!g_dbc) { + g_hlr->dbc = db_open(NULL, "hlr.db"); + if (!g_hlr->dbc) { LOGP(DMAIN, LOGL_ERROR, "Error opening database\n"); exit(1); } /* non-existing subscriber */ - rc = test("901990123456789"); + rc = test("901990123456789", g_hlr->dbc); /* 2G only AUC data (COMP128v1 / MILENAGE) */ - rc = test("901990000000001"); + rc = test("901990000000001", g_hlr->dbc); /* 2G + 3G AUC data (COMP128v1 / MILENAGE) */ - rc = test("901990000000002"); + rc = test("901990000000002", g_hlr->dbc); /* 3G AUC data (MILENAGE) */ - rc = test("901990000000003"); + rc = test("901990000000003", g_hlr->dbc); LOGP(DMAIN, LOGL_NOTICE, "Exiting\n"); - db_close(g_dbc); + db_close(g_hlr->dbc); log_fini(); diff --git a/src/hlr.c b/src/hlr.c index d74d9fb..bb6f05a 100644 --- a/src/hlr.c +++ b/src/hlr.c @@ -34,6 +34,7 @@ #include <osmocom/vty/ports.h> #include "db.h" +#include "hlr.h" #include "logging.h" #include "gsup_server.h" #include "gsup_router.h" @@ -41,7 +42,7 @@ #include "luop.h" #include "hlr_vty.h" -static struct db_context *g_dbc; +static struct hlr *g_hlr; /*********************************************************************** * Send Auth Info handling @@ -49,7 +50,8 @@ /* process an incoming SAI request */ static int rx_send_auth_info(struct osmo_gsup_conn *conn, - const struct osmo_gsup_message *gsup) + const struct osmo_gsup_message *gsup, + struct db_context *dbc) { struct osmo_gsup_message gsup_out; struct msgb *msg_out; @@ -59,7 +61,7 @@ memset(&gsup_out, 0, sizeof(gsup_out)); memcpy(&gsup_out.imsi, &gsup->imsi, sizeof(gsup_out.imsi)); - rc = db_get_auc(g_dbc, gsup->imsi, gsup_out.auth_vectors, + rc = db_get_auc(dbc, gsup->imsi, gsup_out.auth_vectors, ARRAY_SIZE(gsup_out.auth_vectors), gsup->rand, gsup->auts); if (rc < 0) { @@ -157,7 +159,7 @@ /* Roughly follwing "Process Update_Location_HLR" of TS 09.02 */ /* check if subscriber is known at all */ - if (!lu_op_fill_subscr(luop, g_dbc, gsup->imsi)) { + if (!lu_op_fill_subscr(luop, g_hlr->dbc, gsup->imsi)) { /* Send Error back: Subscriber Unknown in HLR */ strcpy(luop->subscr.imsi, gsup->imsi); lu_op_tx_error(luop, GMM_CAUSE_IMSI_UNKNOWN); @@ -216,7 +218,7 @@ * we have on record. Only update if yes */ /* Perform the actual update of the DB */ - rc = db_subscr_purge(g_dbc, gsup->imsi, is_ps); + rc = db_subscr_purge(g_hlr->dbc, gsup->imsi, is_ps); if (rc == 1) gsup_reply.message_type = OSMO_GSUP_MSGT_PURGE_MS_RESULT; @@ -247,7 +249,7 @@ switch (gsup.message_type) { /* requests sent to us */ case OSMO_GSUP_MSGT_SEND_AUTH_INFO_REQUEST: - rx_send_auth_info(conn, &gsup); + rx_send_auth_info(conn, &gsup, g_hlr->dbc); break; case OSMO_GSUP_MSGT_UPDATE_LOCATION_REQUEST: rx_upd_loc_req(conn, &gsup); @@ -372,15 +374,14 @@ } static void *hlr_ctx = NULL; -static struct osmo_gsup_server *gs; static void signal_hdlr(int signal) { switch (signal) { case SIGINT: LOGP(DMAIN, LOGL_NOTICE, "Terminating due to SIGINT\n"); - osmo_gsup_server_destroy(gs); - db_close(g_dbc); + osmo_gsup_server_destroy(g_hlr->gs); + db_close(g_hlr->dbc); log_fini(); talloc_report_full(hlr_ctx, stderr); exit(0); @@ -404,6 +405,8 @@ hlr_ctx = talloc_named_const(NULL, 1, "OsmoHLR"); msgb_talloc_ctx_init(hlr_ctx, 0); + + g_hlr = talloc_zero(hlr_ctx, struct hlr); rc = osmo_init_logging(&hlr_log_info); if (rc < 0) { @@ -437,14 +440,14 @@ exit(1); } - g_dbc = db_open(hlr_ctx, cmdline_opts.db_file); - if (!g_dbc) { + g_hlr->dbc = db_open(hlr_ctx, cmdline_opts.db_file); + if (!g_hlr->dbc) { LOGP(DMAIN, LOGL_FATAL, "Error opening database\n"); exit(1); } - gs = osmo_gsup_server_create(hlr_ctx, NULL, 2222, read_cb); - if (!gs) { + g_hlr->gs = osmo_gsup_server_create(hlr_ctx, NULL, 2222, read_cb); + if (!g_hlr->gs) { LOGP(DMAIN, LOGL_FATAL, "Error starting GSUP server\n"); exit(1); } @@ -465,7 +468,7 @@ osmo_select_main(0); } - db_close(g_dbc); + db_close(g_hlr->dbc); log_fini(); diff --git a/src/hlr.h b/src/hlr.h new file mode 100644 index 0000000..77751dd --- /dev/null +++ b/src/hlr.h @@ -0,0 +1,33 @@ +/* OsmoHLR generic header */ + +/* (C) 2017 sysmocom s.f.m.c. GmbH <info at sysmocom.de> + * All Rights Reserved + * + * Author: Max Suraev <msuraev at sysmocom.de> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +#pragma once + +#include <stdbool.h> + +struct hlr { + /* GSUP server pointer */ + struct osmo_gsup_server *gs; + + /* DB context */ + struct db_context *dbc; +}; -- To view, visit https://gerrit.osmocom.org/1856 To unsubscribe, visit https://gerrit.osmocom.org/settings Gerrit-MessageType: newpatchset Gerrit-Change-Id: I275d3d54482f696e3378606b2406c7e0ad939e0f Gerrit-PatchSet: 7 Gerrit-Project: osmo-hlr Gerrit-Branch: master Gerrit-Owner: Max <msuraev at sysmocom.de> Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: Max <msuraev at sysmocom.de> Gerrit-Reviewer: Neels Hofmeyr <nhofmeyr at sysmocom.de>