pespin has uploaded this change for review.

View Change

Pass pdp_t to sgsn_pdp_ctx_alloc()

Refactor sgsn_create_pdp_ctx() to pass the libgtp pdp_t to our pctx.
This will be used in follow-up patch to use the teic_own as ID of the
rate_ctr.

Change-Id: Ie7312039fc97f50d09f00661e7c156610f3304b8
---
M include/osmocom/sgsn/pdpctx.h
M src/sgsn/pdpctx.c
M src/sgsn/sgsn_libgtp.c
3 files changed, 31 insertions(+), 26 deletions(-)

git pull ssh://gerrit.osmocom.org:29418/osmo-sgsn refs/changes/57/41457/1
diff --git a/include/osmocom/sgsn/pdpctx.h b/include/osmocom/sgsn/pdpctx.h
index a4bbd97..c6a43de 100644
--- a/include/osmocom/sgsn/pdpctx.h
+++ b/include/osmocom/sgsn/pdpctx.h
@@ -92,6 +92,7 @@

struct sgsn_pdp_ctx *sgsn_pdp_ctx_alloc(struct sgsn_mm_ctx *mm,
struct sgsn_ggsn_ctx *ggsn,
+ struct pdp_t *pdp,
uint8_t nsapi);
void sgsn_pdp_ctx_terminate(struct sgsn_pdp_ctx *pdp);
void sgsn_pdp_ctx_free(struct sgsn_pdp_ctx *pdp);
diff --git a/src/sgsn/pdpctx.c b/src/sgsn/pdpctx.c
index 7806ada..2c3fb03 100644
--- a/src/sgsn/pdpctx.c
+++ b/src/sgsn/pdpctx.c
@@ -60,32 +60,40 @@
/* you don't want to use this directly, call sgsn_create_pdp_ctx() */
struct sgsn_pdp_ctx *sgsn_pdp_ctx_alloc(struct sgsn_mm_ctx *mm,
struct sgsn_ggsn_ctx *ggsn,
+ struct pdp_t *pdp,
uint8_t nsapi)
{
- struct sgsn_pdp_ctx *pdp;
+ struct sgsn_pdp_ctx *pctx;

- pdp = sgsn_pdp_ctx_by_nsapi(mm, nsapi);
- if (pdp)
+ pctx = sgsn_pdp_ctx_by_nsapi(mm, nsapi);
+ if (pctx)
return NULL;

- pdp = talloc_zero(sgsn, struct sgsn_pdp_ctx);
- if (!pdp)
+ pctx = talloc_zero(sgsn, struct sgsn_pdp_ctx);
+ if (!pctx)
return NULL;

- pdp->mm = mm;
- pdp->ggsn = ggsn;
- pdp->nsapi = nsapi;
- pdp->ctrg = rate_ctr_group_alloc(pdp, &pdpctx_ctrg_desc, nsapi);
- if (!pdp->ctrg) {
- LOGPDPCTXP(LOGL_ERROR, pdp, "Error allocation counter group\n");
- talloc_free(pdp);
+ pctx->ctrg = rate_ctr_group_alloc(pctx, &pdpctx_ctrg_desc, nsapi);
+ if (!pctx->ctrg) {
+ LOGPDPCTXP(LOGL_ERROR, pctx, "Error allocation counter group\n");
+ talloc_free(pctx);
return NULL;
}
- llist_add(&pdp->list, &mm->pdp_list);
- sgsn_ggsn_ctx_add_pdp(pdp->ggsn, pdp);
- llist_add(&pdp->g_list, &sgsn->pdp_list);

- return pdp;
+ pdp->priv = pctx;
+ pctx->lib = pdp;
+ pctx->mm = mm;
+ pctx->ggsn = ggsn;
+ pctx->nsapi = nsapi;
+
+ /* Back up our own local TEID in case we update the library one with RNC TEID when setting up Direct Tunnel: */
+ pctx->sgsn_teid_own = pdp->teid_own;
+
+ llist_add(&pctx->list, &mm->pdp_list);
+ sgsn_ggsn_ctx_add_pdp(pctx->ggsn, pctx);
+ llist_add(&pctx->g_list, &sgsn->pdp_list);
+
+ return pctx;
}

/*
diff --git a/src/sgsn/sgsn_libgtp.c b/src/sgsn/sgsn_libgtp.c
index e637967..4021bbc 100644
--- a/src/sgsn/sgsn_libgtp.c
+++ b/src/sgsn/sgsn_libgtp.c
@@ -152,12 +152,6 @@
const uint8_t *qos;
int rc;

- pctx = sgsn_pdp_ctx_alloc(mmctx, ggsn, nsapi);
- if (!pctx) {
- LOGP(DGPRS, LOGL_ERROR, "Couldn't allocate PDP Ctx\n");
- return NULL;
- }
-
imsi_ui64 = imsi_str2gtp(mmctx->imsi);

rc = gtp_pdp_newpdp(ggsn->gsn, &pdp, imsi_ui64, nsapi, NULL);
@@ -165,11 +159,13 @@
LOGP(DGPRS, LOGL_ERROR, "Out of libgtp PDP Contexts\n");
return NULL;
}
- pdp->priv = pctx;
- pctx->lib = pdp;

- /* Back up our own local TEID in case we update the library one with RNC TEID when setting up Direct Tunnel: */
- pctx->sgsn_teid_own = pdp->teid_own;
+ pctx = sgsn_pdp_ctx_alloc(mmctx, ggsn, pdp, nsapi);
+ if (!pctx) {
+ LOGP(DGPRS, LOGL_ERROR, "Couldn't allocate PDP Ctx\n");
+ pdp_freepdp(pdp);
+ return NULL;
+ }

//pdp->peer = /* sockaddr_in of GGSN (receive) */
//pdp->ipif = /* not used by library */

To view, visit change 41457. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: newchange
Gerrit-Project: osmo-sgsn
Gerrit-Branch: master
Gerrit-Change-Id: Ie7312039fc97f50d09f00661e7c156610f3304b8
Gerrit-Change-Number: 41457
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin@sysmocom.de>