aboutsummaryrefslogtreecommitdiffstats
path: root/src/osmo_ss7_vty.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/osmo_ss7_vty.c')
-rw-r--r--src/osmo_ss7_vty.c70
1 files changed, 50 insertions, 20 deletions
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 @@ DEFUN(show_cs7_as, show_cs7_as_cmd,
/* 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 @@ static struct cmd_node sccpaddr_gt_node = {
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 @@ DEFUN(cs7_sccpaddr, cs7_sccpaddr_cmd,
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 @@ DEFUN(cs7_sccpaddr, cs7_sccpaddr_cmd,
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 @@ DEFUN(cs7_sccpaddr_del, cs7_sccpaddr_del_cmd,
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);