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


Change subject: pdp: Introduce new API pdp_count_secondary
......................................................................

pdp: Introduce new API pdp_count_secondary

Change-Id: Id2d84ad1cdb0f3b500efeda4cc0fbccb24ae0c61
---
M gtp/gtp.c
M gtp/pdp.c
M gtp/pdp.h
3 files changed, 20 insertions(+), 10 deletions(-)



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

diff --git a/gtp/gtp.c b/gtp/gtp.c
index 430eeb4..4bc18b1 100644
--- a/gtp/gtp.c
+++ b/gtp/gtp.c
@@ -2442,8 +2442,7 @@
            get_default_gtp(pdp->version, GTP_DELETE_PDP_REQ, &packet);
        struct in_addr addr;
        struct pdp_t *linked_pdp;
-       int n;
-       int count = 0;
+       int count;

        if (gsna2in_addr(&addr, &pdp->gsnrc)) {
                gsn->err_address++;
@@ -2458,9 +2457,7 @@
        }

        if (!teardown) {
-               for (n = 0; n < PDP_MAXNSAPI; n++)
-                       if (linked_pdp->secondary_tei[n])
-                               count++;
+               count = pdp_count_secondary(linked_pdp);
                if (count <= 1) {
                        LOGP(DLGTP, LOGL_ERROR,
                                "Must use teardown for last context: %d\n", 
count);
@@ -2550,8 +2547,7 @@

        uint8_t nsapi;
        uint8_t teardown = 0;
-       int n;
-       int count = 0;
+       int count;

        /* Is this a dublicate ? */
        if (!gtp_dublicate(gsn, version, peer, seq)) {
@@ -2621,9 +2617,7 @@
                         * signalling messages will eventually lead to a 
consistent
                         * situation, allowing the teardown of the PDP context.)
                         */
-                       for (n = 0; n < PDP_MAXNSAPI; n++)
-                               if (linked_pdp->secondary_tei[n])
-                                       count++;
+                       count = pdp_count_secondary(linked_pdp);
                        if (count <= 1) {
                                GTP_LOGPKG(LOGL_NOTICE, peer, pack, len,
                                           "Ignoring CTX DEL without teardown 
and count=%d\n",
diff --git a/gtp/pdp.c b/gtp/pdp.c
index a630ee9..92fe5ec 100644
--- a/gtp/pdp.c
+++ b/gtp/pdp.c
@@ -374,3 +374,17 @@
        pdp->imsi = teid & 0x0fffffffffffffffull;
        pdp->nsapi = (teid & 0xf000000000000000ull) >> 60;
 }
+
+/* Count amount of secondary PDP contexts linked to this primary PDP context
+ * (itself included). Must be called on a primary PDP context. */
+unsigned int pdp_count_secondary(struct pdp_t *pdp)
+{
+       unsigned int n;
+       unsigned int count = 0;
+       OSMO_ASSERT(!pdp->secondary);
+
+       for (n = 0; n < PDP_MAXNSAPI; n++)
+               if (pdp->secondary_tei[n])
+                       count++;
+       return count;
+}
diff --git a/gtp/pdp.h b/gtp/pdp.h
index 81a38f4..e48f1a1 100644
--- a/gtp/pdp.h
+++ b/gtp/pdp.h
@@ -260,6 +260,8 @@

 void pdp_set_imsi_nsapi(struct pdp_t *pdp, uint64_t teid);

+unsigned int pdp_count_secondary(struct pdp_t *pdp);
+
 /*
 int pdp_iphash(void* ipif, struct ul66_t *eua);
 int pdp_ipset(struct pdp_t *pdp, void* ipif, struct ul66_t *eua);

--
To view, visit https://gerrit.osmocom.org/14283
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: Id2d84ad1cdb0f3b500efeda4cc0fbccb24ae0c61
Gerrit-Change-Number: 14283
Gerrit-PatchSet: 1
Gerrit-Owner: Pau Espin Pedrol <[email protected]>

Reply via email to