[PATCH] libosmo-sccp[master]: sccp: global addressbook search + api fix

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

dexter gerrit-no-reply at lists.osmocom.org
Thu Jul 20 10:46:08 UTC 2017


Hello Neels Hofmeyr, Jenkins Builder,

I'd like you to reexamine a change.  Please visit

    https://gerrit.osmocom.org/3265

to look at the new patch set (#3).

sccp: global addressbook search + api fix

The sccp-addressbook only allows defining addresses for a specific
ss7 instance. It is not possible to use an sscp-address, that is
defined in the one ss7 instance in another ss7 instance.

Add a second global list where all sscp-addresses are added,
regardless on which instance they are defined.

Fixup the search functions so that they always search the global
list.

Change the API, so that the address data is written to a
destination pointer. This protects the stored address from
unintentional changes. Also return the ss7 instance, where the
address is associated with.

Change-Id: I5acc1e5abc3b3081149a9f476038e4e53d23b763
---
M include/osmocom/sigtran/sccp_sap.h
M src/osmo_ss7_vty.c
2 files changed, 54 insertions(+), 24 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmo-sccp refs/changes/65/3265/3

diff --git a/include/osmocom/sigtran/sccp_sap.h b/include/osmocom/sigtran/sccp_sap.h
index 2258b0d..24d64d9 100644
--- a/include/osmocom/sigtran/sccp_sap.h
+++ b/include/osmocom/sigtran/sccp_sap.h
@@ -248,8 +248,8 @@
 
 int osmo_sccp_user_sap_down(struct osmo_sccp_user *scu, struct osmo_prim_hdr *oph);
 
-struct osmo_sccp_addr *
-osmo_sccp_addr_by_name(const char *name, const struct osmo_ss7_instance *ss7);
+struct osmo_ss7_instance *
+osmo_sccp_addr_by_name(struct osmo_sccp_addr *dest_addr,
+		       const char *name);
 
-char * osmo_sccp_name_by_addr(const struct osmo_sccp_addr *addr,
-			      const struct osmo_ss7_instance *ss7);
+const char *osmo_sccp_name_by_addr(const struct osmo_sccp_addr *addr);
diff --git a/src/osmo_ss7_vty.c b/src/osmo_ss7_vty.c
index 7e6f9ee..8a03303 100644
--- a/src/osmo_ss7_vty.c
+++ b/src/osmo_ss7_vty.c
@@ -934,6 +934,7 @@
 /* SCCP addressbook */
 struct osmo_sccp_addr_entry {
 	struct llist_head list;
+	struct llist_head list_global;
 	struct osmo_ss7_instance *inst;
 	char name[512];
 	struct osmo_sccp_addr addr;
@@ -951,45 +952,72 @@
 	1,
 };
 
-/* Pick an SCCP address entry from the addressbook by its name */
-struct osmo_sccp_addr_entry *addr_entry_by_name(const char *name,
-						const struct osmo_ss7_instance
-						*inst)
+/* A global list that holds all addressbook entries at once
+ * (see also .cfg in struct osmo_ss7_instance) */
+LLIST_HEAD(sccp_address_book_global);
+
+/* Pick an SCCP address entry from the addressbook list by its name */
+static struct osmo_sccp_addr_entry
+*addr_entry_by_name_local(const char *name,
+			  const struct osmo_ss7_instance *inst)
 {
 	struct osmo_sccp_addr_entry *entry;
+
 	llist_for_each_entry(entry, &inst->cfg.sccp_address_book, list) {
+		if (strcmp(entry->name, name) == 0) {
+			OSMO_ASSERT(entry->inst == inst);
+			return entry;
+		}
+	}
+
+	return NULL;
+}
+
+/* Pick an SCCP address entry from the global addressbook
+ * list by its name */
+static struct osmo_sccp_addr_entry
+*addr_entry_by_name_global(const char *name)
+{
+	struct osmo_sccp_addr_entry *entry;
+
+	llist_for_each_entry(entry, &sccp_address_book_global,
+			     list_global) {
 		if (strcmp(entry->name, name) == 0)
 			return entry;
 	}
+
 	return NULL;
 }
 
 /*! \brief Lookup an SCCP address from the addressbook by its name.
- *  \param[in] lookup-name of the address to lookup
- *  \param[in] ss7 instance
- *  \returns SCCP address; NULL on error */
-struct osmo_sccp_addr *osmo_sccp_addr_by_name(const char *name,
-					      const struct osmo_ss7_instance
-					      *ss7)
+ *  \param[out] dest_addr pointer to output the resulting sccp-address;
+ *		(set to NULL if not interested)
+ *  \param[in] name of the address to lookup
+ *  \returns SS7 instance; NULL on error */
+struct osmo_ss7_instance *
+osmo_sccp_addr_by_name(struct osmo_sccp_addr *dest_addr,
+		       const char *name)
 {
 	struct osmo_sccp_addr_entry *entry;
 
-	entry = addr_entry_by_name(name, ss7);
-	if (entry)
-		return &entry->addr;
+	entry = addr_entry_by_name_global(name);
+	if (!entry)
+		return NULL;
 
-	return NULL;
+	if (dest_addr)
+		*dest_addr = entry->addr;
+
+	return entry->inst;
 }
 
 /*! \brief Reverse lookup the lookup-name of a specified SCCP address.
  *  \param[in] name of the address to lookup
- *  \param[in] ss7 instance
  *  \returns char pointer to the lookup-name; NULL on error */
-char *osmo_sccp_name_by_addr(const struct osmo_sccp_addr *addr,
-			     const struct osmo_ss7_instance *ss7)
+const char *osmo_sccp_name_by_addr(const struct osmo_sccp_addr *addr)
 {
 	struct osmo_sccp_addr_entry *entry;
-	llist_for_each_entry(entry, &ss7->cfg.sccp_address_book, list) {
+
+	llist_for_each_entry(entry, &sccp_address_book_global, list_global) {
 		if (memcmp(&entry->addr, addr, sizeof(*addr)) == 0)
 			return entry->name;
 	}
@@ -1177,7 +1205,7 @@
 		return CMD_WARNING;
 	}
 
-	entry = addr_entry_by_name(name, inst);
+	entry = addr_entry_by_name_local(name, inst);
 
 	/* Create a new addressbook entry if we can not find an
 	 * already existing entry */
@@ -1185,6 +1213,7 @@
 		entry = talloc_zero(inst, struct osmo_sccp_addr_entry);
 		osmo_strlcpy(entry->name, name, sizeof(entry->name));
 		llist_add_tail(&entry->list, &inst->cfg.sccp_address_book);
+		llist_add_tail(&entry->list_global, &sccp_address_book_global);
 		entry->addr.ri = OSMO_SCCP_RI_SSN_PC;
 	}
 
@@ -1203,9 +1232,10 @@
 	struct osmo_sccp_addr_entry *entry;
 	const char *name = argv[0];
 
-	entry = addr_entry_by_name(name, inst);
+	entry = addr_entry_by_name_local(name, inst);
 	if (entry) {
 		llist_del(&entry->list);
+		llist_del(&entry->list_global);
 		talloc_free(entry);
 	} else {
 		vty_out(vty, "Addressbook entry not found!%s", VTY_NEWLINE);

-- 
To view, visit https://gerrit.osmocom.org/3265
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I5acc1e5abc3b3081149a9f476038e4e53d23b763
Gerrit-PatchSet: 3
Gerrit-Project: libosmo-sccp
Gerrit-Branch: master
Gerrit-Owner: dexter <pmaier at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Neels Hofmeyr <nhofmeyr at sysmocom.de>



More information about the gerrit-log mailing list