pespin has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/libosmo-sccp/+/33647 )


Change subject: ss7: Refactor osmo_ss7_asp_find_or_create()
......................................................................

ss7: Refactor osmo_ss7_asp_find_or_create()

Move allocation code to its own function. Simplify
osmo_ss7_asp_find_or_create() code paths.

Change-Id: Ibbf20c63fc1d2b22a7c5d750002f94795ee31f26
---
M src/osmo_ss7.c
1 file changed, 43 insertions(+), 25 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmo-sccp refs/changes/47/33647/1

diff --git a/src/osmo_ss7.c b/src/osmo_ss7.c
index 3851ab8..839d756 100644
--- a/src/osmo_ss7.c
+++ b/src/osmo_ss7.c
@@ -1521,6 +1521,31 @@
        return asp;
 }

+static struct osmo_ss7_asp *
+osmo_ss7_asp_alloc(struct osmo_ss7_instance *inst, const char *name,
+                  uint16_t remote_port, uint16_t local_port,
+                  enum osmo_ss7_asp_protocol proto)
+{
+       struct osmo_ss7_asp *asp = talloc_zero(inst, struct osmo_ss7_asp);
+       asp->ctrg = rate_ctr_group_alloc(asp, &ss7_asp_rcgd, 
g_ss7_asp_rcg_idx++);
+       if (!asp->ctrg) {
+               talloc_free(asp);
+               return NULL;
+       }
+       rate_ctr_group_set_name(asp->ctrg, name);
+       asp->inst = inst;
+       asp->cfg.remote.port = remote_port;
+       asp->cfg.local.port = local_port;
+       asp->cfg.proto = proto;
+       asp->cfg.name = talloc_strdup(asp, name);
+       llist_add_tail(&asp->list, &inst->asp_list);
+
+       /* The SUA code internally needs SCCP to work */
+       if (proto == OSMO_SS7_ASP_PROT_SUA)
+               osmo_ss7_ensure_sccp(inst);
+       return asp;
+}
+
 struct osmo_ss7_asp *
 osmo_ss7_asp_find_or_create(struct osmo_ss7_instance *inst, const char *name,
                            uint16_t remote_port, uint16_t local_port,
@@ -1530,34 +1555,15 @@

        OSMO_ASSERT(ss7_initialized);
        asp = osmo_ss7_asp_find_by_name(inst, name);
-
-       if (asp && (asp->cfg.remote.port != remote_port ||
+       if (asp) {
+               if (asp->cfg.remote.port != remote_port ||
                    asp->cfg.local.port != local_port ||
-                   asp->cfg.proto != proto))
-               return NULL;
-
-       if (!asp) {
-               /* FIXME: check if local port has SCTP? */
-               asp = talloc_zero(inst, struct osmo_ss7_asp);
-               asp->ctrg = rate_ctr_group_alloc(asp, &ss7_asp_rcgd, 
g_ss7_asp_rcg_idx++);
-               if (!asp->ctrg) {
-                       talloc_free(asp);
+                   asp->cfg.proto != proto)
                        return NULL;
-               }
-               rate_ctr_group_set_name(asp->ctrg, name);
-               asp->inst = inst;
-               asp->cfg.remote.port = remote_port;
-               asp->cfg.local.port = local_port;
-               asp->cfg.proto = proto;
-               asp->cfg.name = talloc_strdup(asp, name);
-               llist_add_tail(&asp->list, &inst->asp_list);
-
-               /* The SUA code internally needs SCCP to work */
-               if (proto == OSMO_SS7_ASP_PROT_SUA)
-                       osmo_ss7_ensure_sccp(inst);
-
+               return asp;
        }
-       return asp;
+
+       return osmo_ss7_asp_alloc(inst, name, remote_port, local_port, proto);
 }

 void osmo_ss7_asp_destroy(struct osmo_ss7_asp *asp)

--
To view, visit https://gerrit.osmocom.org/c/libosmo-sccp/+/33647
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmo-sccp
Gerrit-Branch: master
Gerrit-Change-Id: Ibbf20c63fc1d2b22a7c5d750002f94795ee31f26
Gerrit-Change-Number: 33647
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <[email protected]>
Gerrit-MessageType: newchange

Reply via email to