Change in ...osmo-sgsn[master]: Merge common allocation steps for Gb and Iu ctx

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

pespin gerrit-no-reply at lists.osmocom.org
Thu Aug 29 18:54:28 UTC 2019


pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-sgsn/+/15338


Change subject: Merge common allocation steps for Gb and Iu ctx
......................................................................

Merge common allocation steps for Gb and Iu ctx

This way it's easier to add new common functionalitites without
forgetting to add it on both sides, and simplifies the code.

Change-Id: Ib6c0427ac7b35295cf1caf2f28cb2a5c155b9d9c
---
M src/gprs/gprs_sgsn.c
1 file changed, 27 insertions(+), 31 deletions(-)



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

diff --git a/src/gprs/gprs_sgsn.c b/src/gprs/gprs_sgsn.c
index b395852..16f3f34 100644
--- a/src/gprs/gprs_sgsn.c
+++ b/src/gprs/gprs_sgsn.c
@@ -214,9 +214,8 @@
 
 }
 
-/* Allocate a new SGSN MM context for GERAN_Gb */
-struct sgsn_mm_ctx *sgsn_mm_ctx_alloc_gb(uint32_t tlli,
-					const struct gprs_ra_id *raid)
+/* Allocate a new SGSN MM context, generic part */
+struct sgsn_mm_ctx *sgsn_mm_ctx_alloc(uint32_t rate_ctr_id)
 {
 	struct sgsn_mm_ctx *ctx;
 
@@ -224,16 +223,9 @@
 	if (!ctx)
 		return NULL;
 
-	memcpy(&ctx->ra, raid, sizeof(ctx->ra));
-	ctx->ran_type = MM_CTX_T_GERAN_Gb;
-	ctx->gb.tlli = tlli;
-	ctx->gb.mm_state = MM_IDLE;
 	ctx->gmm_state = GMM_DEREGISTERED;
 	ctx->auth_triplet.key_seq = GSM_KEY_SEQ_INVAL;
-	ctx->ciph_algo = sgsn->cfg.cipher;
-	LOGMMCTXP(LOGL_DEBUG, ctx, "Allocated with %s cipher.\n",
-		  get_value_string(gprs_cipher_names, ctx->ciph_algo));
-	ctx->ctrg = rate_ctr_group_alloc(ctx, &mmctx_ctrg_desc, tlli);
+	ctx->ctrg = rate_ctr_group_alloc(ctx, &mmctx_ctrg_desc, rate_ctr_id);
 	if (!ctx->ctrg) {
 		LOGMMCTXP(LOGL_ERROR, ctx, "Cannot allocate counter group\n");
 		talloc_free(ctx);
@@ -241,45 +233,49 @@
 	}
 	ctx->gmm_att_req.fsm = osmo_fsm_inst_alloc(&gmm_attach_req_fsm, ctx, ctx, LOGL_DEBUG, "gb_gmm_req");
 	INIT_LLIST_HEAD(&ctx->pdp_list);
-
 	llist_add(&ctx->list, &sgsn_mm_ctxts);
 
 	return ctx;
 }
+/* Allocate a new SGSN MM context for GERAN_Gb */
+struct sgsn_mm_ctx *sgsn_mm_ctx_alloc_gb(uint32_t tlli,
+					const struct gprs_ra_id *raid)
+{
+	struct sgsn_mm_ctx *ctx;
 
-/* Allocate a new SGSN MM context */
+	ctx = sgsn_mm_ctx_alloc(tlli);
+	if (!ctx)
+		return NULL;
+
+	memcpy(&ctx->ra, raid, sizeof(ctx->ra));
+	ctx->ran_type = MM_CTX_T_GERAN_Gb;
+	ctx->gb.tlli = tlli;
+	ctx->gb.mm_state = MM_IDLE;
+	ctx->ciph_algo = sgsn->cfg.cipher;
+
+	LOGMMCTXP(LOGL_DEBUG, ctx, "Allocated with %s cipher.\n",
+		  get_value_string(gprs_cipher_names, ctx->ciph_algo));
+	return ctx;
+}
+
+/* Allocate a new SGSN MM context for UTRAN_Iu */
 struct sgsn_mm_ctx *sgsn_mm_ctx_alloc_iu(void *uectx)
 {
 #if BUILD_IU
 	struct sgsn_mm_ctx *ctx;
 	struct ranap_ue_conn_ctx *ue_ctx = uectx;
 
-	ctx = talloc_zero(tall_sgsn_ctx, struct sgsn_mm_ctx);
+	ctx = sgsn_mm_ctx_alloc(ue_ctx->conn_id);
 	if (!ctx)
 		return NULL;
 
+	/* Need to get RAID from IU conn */
+	ctx->ra = ue_ctx->ra_id;
 	ctx->ran_type = MM_CTX_T_UTRAN_Iu;
 	ctx->iu.ue_ctx = ue_ctx;
 	ctx->iu.ue_ctx->rab_assign_addr_enc = sgsn->cfg.iu.rab_assign_addr_enc;
 	ctx->iu.new_key = 1;
 	ctx->iu.mm_state = PMM_DETACHED;
-	ctx->gmm_state = GMM_DEREGISTERED;
-	ctx->auth_triplet.key_seq = GSM_KEY_SEQ_INVAL;
-	ctx->ctrg = rate_ctr_group_alloc(ctx, &mmctx_ctrg_desc, ue_ctx->conn_id);
-	if (!ctx->ctrg) {
-		LOGMMCTXP(LOGL_ERROR, ctx, "Cannot allocate counter group for %s.%u\n",
-			  mmctx_ctrg_desc.group_name_prefix, ue_ctx->conn_id);
-		talloc_free(ctx);
-		return NULL;
-	}
-	ctx->gmm_att_req.fsm = osmo_fsm_inst_alloc(&gmm_attach_req_fsm, ctx, ctx, LOGL_DEBUG, "gb_gmm_req");
-
-	/* Need to get RAID from IU conn */
-	ctx->ra = ctx->iu.ue_ctx->ra_id;
-
-	INIT_LLIST_HEAD(&ctx->pdp_list);
-
-	llist_add(&ctx->list, &sgsn_mm_ctxts);
 
 	return ctx;
 #else

-- 
To view, visit https://gerrit.osmocom.org/c/osmo-sgsn/+/15338
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-sgsn
Gerrit-Branch: master
Gerrit-Change-Id: Ib6c0427ac7b35295cf1caf2f28cb2a5c155b9d9c
Gerrit-Change-Number: 15338
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190829/7dca528c/attachment.htm>


More information about the gerrit-log mailing list