pespin has uploaded this change for review.

View Change

Move sccp_address_book logic out of vty.c

Move it tto a file containing data domain code.
Move the struct definition to a header so it can be used in other files
like ss7_vty.c.
It will be used in more places in follow-up patches.

Change-Id: Ib37a2503b8cf0fadce9072020e0e14a2a05561bf
---
M src/sccp_internal.h
M src/ss7_instance.c
M src/ss7_vty.c
3 files changed, 113 insertions(+), 104 deletions(-)

git pull ssh://gerrit.osmocom.org:29418/libosmo-sigtran refs/changes/00/40500/1
diff --git a/src/sccp_internal.h b/src/sccp_internal.h
index 37ada11..298ef3e 100644
--- a/src/sccp_internal.h
+++ b/src/sccp_internal.h
@@ -15,6 +15,19 @@

#include "ss7_user.h"

+/* SCCP addressbook */
+extern struct llist_head sccp_address_book_global;
+struct osmo_sccp_addr_entry {
+ struct llist_head list;
+ struct llist_head list_global;
+ struct osmo_ss7_instance *inst;
+ char name[32];
+ struct osmo_sccp_addr addr;
+};
+struct osmo_sccp_addr_entry *addr_entry_by_name_local(const char *name,
+ const struct osmo_ss7_instance *inst);
+struct osmo_sccp_addr_entry *addr_entry_by_name_global(const char *name);
+
/* Appendix C.4 of Q.714 */
enum osmo_sccp_timer {
/* 0 kept unused on purpose since it's handled specially by osmo_fsm */
diff --git a/src/ss7_instance.c b/src/ss7_instance.c
index 527cf2a..ef0fbd8 100644
--- a/src/ss7_instance.c
+++ b/src/ss7_instance.c
@@ -39,6 +39,7 @@
#include "ss7_instance.h"
#include "ss7_linkset.h"
#include "ss7_route_table.h"
+#include "sccp_internal.h"

static int32_t next_rctx = 1;
static int32_t next_l_rk_id = 1;
@@ -609,3 +610,102 @@
/* parse mask as point code */
return osmo_ss7_pointcode_parse(inst, in);
}
+
+/***********************************************************************
+ * SCCP addressbook handling
+ ***********************************************************************/
+
+/* 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 */
+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 */
+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[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_global(name);
+ if (!entry)
+ return NULL;
+
+ if (dest_addr)
+ *dest_addr = entry->addr;
+
+ return entry->inst;
+}
+
+/*! \brief Lookup an SCCP address from the addressbook of a specific instance
+ * by its name.
+ * \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
+ * \param[in] inst ss7 instance of which the address book will be searched
+ * \returns 0 on success; <0 on error */
+int osmo_sccp_addr_by_name_local(struct osmo_sccp_addr *dest_addr, const char *name,
+ const struct osmo_ss7_instance *inst)
+{
+ struct osmo_sccp_addr_entry *entry;
+
+ entry = addr_entry_by_name_local(name, inst);
+ if (!entry)
+ return -ENOENT;
+
+ if (dest_addr)
+ *dest_addr = entry->addr;
+
+ return 0;
+}
+
+/*! \brief Reverse lookup the lookup-name of a specified SCCP address.
+ * \param[in] name of the address to lookup
+ * \returns char pointer to the lookup-name; NULL on error */
+const char *osmo_sccp_name_by_addr(const struct osmo_sccp_addr *addr)
+{
+ struct osmo_sccp_addr_entry *entry;
+
+ llist_for_each_entry(entry, &sccp_address_book_global, list_global) {
+ if (memcmp(&entry->addr, addr, sizeof(*addr)) == 0)
+ return entry->name;
+ }
+
+ return NULL;
+}
diff --git a/src/ss7_vty.c b/src/ss7_vty.c
index 862e9ff..66efc03 100644
--- a/src/ss7_vty.c
+++ b/src/ss7_vty.c
@@ -727,15 +727,6 @@
* SCCP addressbook handling
***********************************************************************/

-/* SCCP addressbook */
-struct osmo_sccp_addr_entry {
- struct llist_head list;
- struct llist_head list_global;
- struct osmo_ss7_instance *inst;
- char name[32];
- struct osmo_sccp_addr addr;
-};
-
static struct cmd_node sccpaddr_node = {
L_CS7_SCCPADDR_NODE,
"%s(config-cs7-sccpaddr)# ",
@@ -748,101 +739,6 @@
1,
};

-/* 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[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_global(name);
- if (!entry)
- return NULL;
-
- if (dest_addr)
- *dest_addr = entry->addr;
-
- return entry->inst;
-}
-
-/*! \brief Lookup an SCCP address from the addressbook of a specific instance
- * by its name.
- * \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
- * \param[in] inst ss7 instance of which the address book will be searched
- * \returns 0 on success; <0 on error */
-int osmo_sccp_addr_by_name_local(struct osmo_sccp_addr *dest_addr, const char *name,
- const struct osmo_ss7_instance *inst)
-{
- struct osmo_sccp_addr_entry *entry;
-
- entry = addr_entry_by_name_local(name, inst);
- if (!entry)
- return -ENOENT;
-
- if (dest_addr)
- *dest_addr = entry->addr;
-
- return 0;
-}
-
-/*! \brief Reverse lookup the lookup-name of a specified SCCP address.
- * \param[in] name of the address to lookup
- * \returns char pointer to the lookup-name; NULL on error */
-const char *osmo_sccp_name_by_addr(const struct osmo_sccp_addr *addr)
-{
- struct osmo_sccp_addr_entry *entry;
-
- llist_for_each_entry(entry, &sccp_address_book_global, list_global) {
- if (memcmp(&entry->addr, addr, sizeof(*addr)) == 0)
- return entry->name;
- }
-
- return NULL;
-}
-
/* Generate VTY configuration file snippet */
static void write_sccp_addressbook(struct vty *vty,
const struct osmo_ss7_instance *inst)

To view, visit change 40500. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: newchange
Gerrit-Project: libosmo-sigtran
Gerrit-Branch: master
Gerrit-Change-Id: Ib37a2503b8cf0fadce9072020e0e14a2a05561bf
Gerrit-Change-Number: 40500
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin@sysmocom.de>