Change in osmo-sgsn[master]: Allocate sgsn_instance with talloc

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/.

Pau Espin Pedrol gerrit-no-reply at lists.osmocom.org
Tue Oct 30 17:14:04 UTC 2018


Pau Espin Pedrol has uploaded this change for review. ( https://gerrit.osmocom.org/11529


Change subject: Allocate sgsn_instance with talloc
......................................................................

Allocate sgsn_instance with talloc

Change-Id: I4a83c5799f0dbd5eb762039c6cfba671f6e465be
---
M include/osmocom/sgsn/gprs_sgsn.h
M src/gprs/gprs_sgsn.c
M src/gprs/sgsn_main.c
3 files changed, 28 insertions(+), 24 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-sgsn refs/changes/29/11529/1

diff --git a/include/osmocom/sgsn/gprs_sgsn.h b/include/osmocom/sgsn/gprs_sgsn.h
index 1913591..cf78766 100644
--- a/include/osmocom/sgsn/gprs_sgsn.h
+++ b/include/osmocom/sgsn/gprs_sgsn.h
@@ -396,7 +396,8 @@
 extern struct llist_head sgsn_pdp_ctxts;
 
 uint32_t sgsn_alloc_ptmsi(void);
-void sgsn_inst_init(void);
+struct sgsn_instance *sgsn_instance_alloc(void *talloc_ctx);
+void sgsn_inst_init(struct sgsn_instance *sgsn);
 
 char *gprs_pdpaddr2str(uint8_t *pdpa, uint8_t len);
 
diff --git a/src/gprs/gprs_sgsn.c b/src/gprs/gprs_sgsn.c
index bac7325..01f039a 100644
--- a/src/gprs/gprs_sgsn.c
+++ b/src/gprs/gprs_sgsn.c
@@ -32,6 +32,7 @@
 #include <osmocom/gsm/protocol/gsm_04_08_gprs.h>
 #include <osmocom/gsm/apn.h>
 #include <osmocom/gsm/gsm_utils.h>
+#include <osmocom/gsm/gsup.h>
 
 #include <osmocom/sgsn/gprs_subscriber.h>
 #include <osmocom/sgsn/debug.h>
@@ -978,7 +979,17 @@
 	osmo_timer_schedule(&sgsn->llme_timer, GPRS_LLME_CHECK_TICK, 0);
 }
 
-void sgsn_inst_init()
+struct sgsn_instance *sgsn_instance_alloc(void *talloc_ctx)
+{
+	struct sgsn_instance *inst;
+	inst = talloc_zero(talloc_ctx, struct sgsn_instance);
+	inst->cfg.gtp_statedir = talloc_strdup(inst, "./");
+	inst->cfg.auth_policy = SGSN_AUTH_POLICY_CLOSED;
+	inst->cfg.gsup_server_port = OSMO_GSUP_PORT;
+	return inst;
+}
+
+void sgsn_inst_init(struct sgsn_instance *sgsn)
 {
 	osmo_timer_setup(&sgsn->llme_timer, sgsn_llme_check_cb, NULL);
 	osmo_timer_schedule(&sgsn->llme_timer, GPRS_LLME_CHECK_TICK, 0);
diff --git a/src/gprs/sgsn_main.c b/src/gprs/sgsn_main.c
index a17d925..04fc5e1 100644
--- a/src/gprs/sgsn_main.c
+++ b/src/gprs/sgsn_main.c
@@ -40,8 +40,6 @@
 #include <osmocom/core/logging.h>
 #include <osmocom/core/stats.h>
 
-#include <osmocom/gsm/gsup.h>
-
 #include <osmocom/gprs/gprs_ns.h>
 #include <osmocom/gprs/gprs_bssgp.h>
 
@@ -90,15 +88,8 @@
 #define CONFIG_FILE_DEFAULT "osmo-sgsn.cfg"
 #define CONFIG_FILE_LEGACY "osmo_sgsn.cfg"
 
-static struct sgsn_instance sgsn_inst = {
-	.config_file = NULL,
-	.cfg = {
-		.gtp_statedir = "./",
-		.auth_policy = SGSN_AUTH_POLICY_CLOSED,
-		.gsup_server_port = OSMO_GSUP_PORT,
-	},
-};
-struct sgsn_instance *sgsn = &sgsn_inst;
+
+struct sgsn_instance *sgsn;
 
 /* call-back function for the NS protocol */
 static int sgsn_ns_cb(enum gprs_ns_evt event, struct gprs_nsvc *nsvc,
@@ -261,7 +252,7 @@
 			daemonize = 1;
 			break;
 		case 'c':
-			sgsn_inst.config_file = strdup(optarg);
+			osmo_talloc_replace_string(sgsn, &sgsn->config_file, optarg);
 			break;
 		case 'T':
 			log_set_print_timestamp(osmo_stderr_target, 1);
@@ -376,6 +367,7 @@
 
 	srand(time(NULL));
 	tall_sgsn_ctx = talloc_named_const(NULL, 0, "osmo_sgsn");
+	sgsn = sgsn_instance_alloc(tall_sgsn_ctx);
 	msgb_talloc_ctx_init(tall_sgsn_ctx, 0);
 	vty_info.tall_ctx = tall_sgsn_ctx;
 
@@ -394,7 +386,7 @@
 	logging_vty_add_cmds(NULL);
 	osmo_talloc_vty_add_cmds();
 	osmo_stats_vty_add_cmds(&gprs_log_info);
-	sgsn_vty_init(&sgsn_inst.cfg);
+	sgsn_vty_init(&sgsn->cfg);
 	ctrl_vty_init(tall_sgsn_ctx);
 
 #if BUILD_IU
@@ -411,13 +403,13 @@
 	 * previous setups that might rely on the legacy default config file
 	 * name, we need to look for the old config file if no -c option was
 	 * passed AND no file exists with the new default file name. */
-	if (!sgsn_inst.config_file) {
+	if (sgsn->config_file) {
 		/* No -c option was passed */
 		if (file_exists(CONFIG_FILE_LEGACY)
 		    && !file_exists(CONFIG_FILE_DEFAULT))
-			sgsn_inst.config_file = CONFIG_FILE_LEGACY;
+			osmo_talloc_replace_string(sgsn, &sgsn->config_file, CONFIG_FILE_LEGACY);
 		else
-			sgsn_inst.config_file = CONFIG_FILE_DEFAULT;
+			osmo_talloc_replace_string(sgsn, &sgsn->config_file, CONFIG_FILE_DEFAULT);
 	}
 
 	rate_ctr_init(tall_sgsn_ctx);
@@ -430,21 +422,21 @@
 		LOGP(DGPRS, LOGL_ERROR, "Unable to instantiate NS\n");
 		exit(1);
 	}
-	bssgp_nsi = sgsn_inst.cfg.nsi = sgsn_nsi;
+	bssgp_nsi = sgsn->cfg.nsi = sgsn_nsi;
 
 	gprs_llc_init("/usr/local/lib/osmocom/crypt/");
 	sgsn_rate_ctr_init();
-	sgsn_inst_init();
+	sgsn_inst_init(sgsn);
 
 	gprs_ns_vty_init(bssgp_nsi);
 	bssgp_vty_init();
 	gprs_llc_vty_init();
 	gprs_sndcp_vty_init();
 	sgsn_auth_init();
-	sgsn_cdr_init(&sgsn_inst);
+	sgsn_cdr_init(sgsn);
 	/* FIXME: register signal handler for SS_L_NS */
 
-	rc = sgsn_parse_config(sgsn_inst.config_file);
+	rc = sgsn_parse_config(sgsn->config_file);
 	if (rc < 0) {
 		LOGP(DGPRS, LOGL_FATAL, "Error in config file\n");
 		exit(2);
@@ -471,14 +463,14 @@
 	}
 
 
-	rc = sgsn_gtp_init(&sgsn_inst);
+	rc = sgsn_gtp_init(sgsn);
 	if (rc) {
 		LOGP(DGPRS, LOGL_FATAL, "Cannot bind/listen on GTP socket\n");
 		exit(2);
 	} else
 		LOGP(DGPRS, LOGL_NOTICE, "libGTP v%s initialized\n", gtp_version());
 
-	rc = gprs_subscr_init(&sgsn_inst);
+	rc = gprs_subscr_init(sgsn);
 	if (rc < 0) {
 		LOGP(DGPRS, LOGL_FATAL, "Cannot set up subscriber management\n");
 		exit(2);

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

Gerrit-Project: osmo-sgsn
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I4a83c5799f0dbd5eb762039c6cfba671f6e465be
Gerrit-Change-Number: 11529
Gerrit-PatchSet: 1
Gerrit-Owner: Pau Espin Pedrol <pespin at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20181030/01712536/attachment.htm>


More information about the gerrit-log mailing list