Change in osmo-ggsn[master]: gtp: Refactor code to use gtp_freepdp(_teardown) APIs

Pau Espin Pedrol gerrit-no-reply at lists.osmocom.org
Thu May 30 15:20:53 UTC 2019


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


Change subject: gtp: Refactor code to use gtp_freepdp(_teardown) APIs
......................................................................

gtp: Refactor code to use gtp_freepdp(_teardown) APIs

* API gtp_freepdp was already there but was not really being used by
anyone currently, so we can change its behaviour to call cb_delete_ctx.
It makes sense to call the cb in there too to be consistent with rest of
APIs.
* Add API gtp_freepdp_teardown, which calls gtp_freepdp on pdp and its
secondary contexts. It will also be used later on by osmo-ggsn.
* Use new APIs in internal code to simplify it.

Change-Id: I9f0b774e9385a7a8d81ec9702f158e2f9a50d571
---
M gtp/gtp.c
M gtp/gtp.h
2 files changed, 32 insertions(+), 50 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-ggsn refs/changes/85/14285/1

diff --git a/gtp/gtp.c b/gtp/gtp.c
index 0fb4de0..c57ecff 100644
--- a/gtp/gtp.c
+++ b/gtp/gtp.c
@@ -146,9 +146,36 @@
 
 int gtp_freepdp(struct gsn_t *gsn, struct pdp_t *pdp)
 {
+	if (gsn->cb_delete_context)
+		gsn->cb_delete_context(pdp);
 	return pdp_freepdp(pdp);
 }
 
+/* Free pdp and all its secondary PDP contexts. Must be called on the primary PDP context. */
+int gtp_freepdp_teardown(struct gsn_t *gsn, struct pdp_t *pdp)
+{
+	int n;
+	struct pdp_t *secondary_pdp;
+	OSMO_ASSERT(!pdp->secondary);
+
+	for (n = 0; n < PDP_MAXNSAPI; n++) {
+		if (pdp->secondary_tei[n]) {
+			if (pdp_getgtp1
+			    (&secondary_pdp,
+			     pdp->secondary_tei[n])) {
+				LOGP(DLGTP, LOGL_ERROR,
+					"Unknown secondary PDP context\n");
+				continue;
+			}
+			if (pdp != secondary_pdp) {
+				gtp_freepdp(gsn, secondary_pdp);
+			}
+		}
+	}
+
+	return gtp_freepdp(gsn, pdp);
+}
+
 /* gtp_gpdu */
 
 extern int gtp_fd(struct gsn_t *gsn)
@@ -1636,9 +1663,7 @@
 
 			DEBUGP(DLGTP, "gtp_create_pdp_ind: Deleting old context\n");
 
-			if (gsn->cb_delete_context)
-				gsn->cb_delete_context(pdp_old);
-			pdp_freepdp(pdp_old);
+			gtp_freepdp(gsn, pdp_old);
 
 			DEBUGP(DLGTP, "gtp_create_pdp_ind: Deleted...\n");
 		}
@@ -2359,8 +2384,6 @@
 			   int teardown)
 {
 	struct pdp_t *linked_pdp;
-	struct pdp_t *secondary_pdp;
-	int n;
 
 	if (pdp_getgtp1(&linked_pdp, pdp->teic_own)) {
 		LOGP(DLGTP, LOGL_ERROR,
@@ -2372,26 +2395,7 @@
 		return EOF;
 
 	if (teardown) {		/* Remove all contexts */
-		for (n = 0; n < PDP_MAXNSAPI; n++) {
-			if (linked_pdp->secondary_tei[n]) {
-				if (pdp_getgtp1
-				    (&secondary_pdp,
-				     linked_pdp->secondary_tei[n])) {
-					LOGP(DLGTP, LOGL_ERROR,
-						"Unknown secondary PDP context\n");
-					return EOF;
-				}
-				if (linked_pdp != secondary_pdp) {
-					if (gsn->cb_delete_context)
-						gsn->cb_delete_context
-						    (secondary_pdp);
-					pdp_freepdp(secondary_pdp);
-				}
-			}
-		}
-		if (gsn->cb_delete_context)
-			gsn->cb_delete_context(linked_pdp);
-		pdp_freepdp(linked_pdp);
+		gtp_freepdp_teardown(gsn, linked_pdp);
 	} else {
 		if (gsn->cb_delete_context)
 			gsn->cb_delete_context(pdp);
@@ -2458,10 +2462,8 @@
 			uint8_t cause, int teardown)
 {
 	union gtp_packet packet;
-	struct pdp_t *secondary_pdp;
 	unsigned int length =
 	    get_default_gtp(version, GTP_DELETE_PDP_RSP, &packet);
-	int n;
 
 	gtpie_tv1(&packet, &length, GTP_MAX, GTPIE_CAUSE, cause);
 
@@ -2470,26 +2472,7 @@
 
 	if (cause == GTPCAUSE_ACC_REQ) {
 		if ((teardown) || (version == 0)) {	/* Remove all contexts */
-			for (n = 0; n < PDP_MAXNSAPI; n++) {
-				if (linked_pdp->secondary_tei[n]) {
-					if (pdp_getgtp1
-					    (&secondary_pdp,
-					     linked_pdp->secondary_tei[n])) {
-						LOGP(DLGTP, LOGL_ERROR,
-							"Unknown secondary PDP context\n");
-						return EOF;
-					}
-					if (linked_pdp != secondary_pdp) {
-						if (gsn->cb_delete_context)
-							gsn->cb_delete_context
-							    (secondary_pdp);
-						pdp_freepdp(secondary_pdp);
-					}
-				}
-			}
-			if (gsn->cb_delete_context)
-				gsn->cb_delete_context(linked_pdp);
-			pdp_freepdp(linked_pdp);
+			gtp_freepdp_teardown(gsn, linked_pdp);
 		} else {	/* Remove only current context */
 			if (gsn->cb_delete_context)
 				gsn->cb_delete_context(pdp);
@@ -2740,9 +2723,7 @@
 	 * code should ever change. */
 	OSMO_ASSERT(pdp);
 
-	if (gsn->cb_delete_context)
-		gsn->cb_delete_context(pdp);
-	pdp_freepdp(pdp);
+	gtp_freepdp(gsn, pdp);
 	return 0;
 }
 
diff --git a/gtp/gtp.h b/gtp/gtp.h
index 5f35ab5..6582319 100644
--- a/gtp/gtp.h
+++ b/gtp/gtp.h
@@ -309,6 +309,7 @@
 extern int gtp_newpdp(struct gsn_t *gsn, struct pdp_t **pdp,
 		      uint64_t imsi, uint8_t nsapi);
 extern int gtp_freepdp(struct gsn_t *gsn, struct pdp_t *pdp);
+extern int gtp_freepdp_teardown(struct gsn_t *gsn, struct pdp_t *pdp);
 
 extern int gtp_create_context_req(struct gsn_t *gsn, struct pdp_t *pdp,
 				  void *cbp);

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

Gerrit-Project: osmo-ggsn
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I9f0b774e9385a7a8d81ec9702f158e2f9a50d571
Gerrit-Change-Number: 14285
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/20190530/434b1cf3/attachment.html>


More information about the gerrit-log mailing list