gprs_ns2: add member name to bind
Every bind will have a unique name. Add a name argument
to all bind creating functions and require them to be unique.
This is an API break but there wasn't yet a release with NS2.
Change-Id: I8f1d66b7b3b12da12db8b5e6bd08c1beff085b3e
diff --git a/src/gb/gprs_ns2.c b/src/gb/gprs_ns2.c
index 890b656..bd69acf 100644
--- a/src/gb/gprs_ns2.c
+++ b/src/gb/gprs_ns2.c
@@ -1239,6 +1239,7 @@
bind->driver->free_bind(bind);
llist_del(&bind->list);
+ talloc_free((char *)bind->name);
talloc_free(bind);
}
@@ -1251,6 +1252,24 @@
}
}
+/*! Search for a bind with a unique name
+ * \param[in] nsi NS instance on which we operate
+ * \param[in] name The unique bind name to search for
+ * \return the bind or NULL if not found
+ */
+struct gprs_ns2_vc_bind *gprs_ns2_bind_by_name(
+ struct gprs_ns2_inst *nsi, const char *name)
+{
+ struct gprs_ns2_vc_bind *bind;
+
+ llist_for_each_entry(bind, &nsi->binding, list) {
+ if (!strcmp(bind->name, name))
+ return bind;
+ }
+
+ return NULL;
+}
+
enum gprs_ns2_vc_mode gprs_ns2_dialect_to_vc_mode(
enum gprs_ns2_dialect dialect)
{
diff --git a/src/gb/gprs_ns2_fr.c b/src/gb/gprs_ns2_fr.c
index 6b4fa52..5da6fce 100644
--- a/src/gb/gprs_ns2_fr.c
+++ b/src/gb/gprs_ns2_fr.c
@@ -453,19 +453,33 @@
* \param[out] result pointer to created bind
* \return 0 on success; negative on error */
int gprs_ns2_fr_bind(struct gprs_ns2_inst *nsi,
+ const char *name,
const char *netif,
struct osmo_fr_network *fr_network,
enum osmo_fr_role fr_role,
struct gprs_ns2_vc_bind **result)
{
- struct gprs_ns2_vc_bind *bind = talloc_zero(nsi, struct gprs_ns2_vc_bind);
+ struct gprs_ns2_vc_bind *bind;
struct priv_bind *priv;
struct osmo_fr_link *fr_link;
int rc = 0;
+ if (!name)
+ return -EINVAL;
+
+ if (gprs_ns2_bind_by_name(nsi, name))
+ return -EALREADY;
+
+ bind = talloc_zero(nsi, struct gprs_ns2_vc_bind);
if (!bind)
return -ENOSPC;
+ bind->name = talloc_strdup(bind, name);
+ if (!bind->name) {
+ rc = -ENOSPC;
+ goto err_bind;
+ }
+
bind->driver = &vc_driver_fr;
bind->ll = GPRS_NS2_LL_FR;
bind->send_vc = fr_vc_sendmsg;
@@ -475,7 +489,7 @@
priv = bind->priv = talloc_zero(bind, struct priv_bind);
if (!priv) {
rc = -ENOSPC;
- goto err_bind;
+ goto err_name;
}
priv->fd.cb = fr_fd_cb;
@@ -536,6 +550,8 @@
osmo_fr_link_free(fr_link);
err_priv:
talloc_free(priv);
+err_name:
+ talloc_free((char *)bind->name);
err_bind:
talloc_free(bind);
diff --git a/src/gb/gprs_ns2_frgre.c b/src/gb/gprs_ns2_frgre.c
index 423ea4b..014517a 100644
--- a/src/gb/gprs_ns2_frgre.c
+++ b/src/gb/gprs_ns2_frgre.c
@@ -538,6 +538,7 @@
* \param[out] result pointer to created bind
* \return 0 on success; negative on error */
int gprs_ns2_frgre_bind(struct gprs_ns2_inst *nsi,
+ const char *name,
const struct osmo_sockaddr *local,
int dscp,
struct gprs_ns2_vc_bind **result)
@@ -546,6 +547,12 @@
struct priv_bind *priv;
int rc;
+ if (!name)
+ return -ENOSPC;
+
+ if (gprs_ns2_bind_by_name(nsi, name))
+ return -EALREADY;
+
if (!bind)
return -ENOSPC;
@@ -554,6 +561,12 @@
return -EINVAL;
}
+ bind->name = talloc_strdup(bind, name);
+ if (!bind->name) {
+ talloc_free(bind);
+ return -ENOSPC;
+ }
+
bind->driver = &vc_driver_frgre;
bind->ll = GPRS_NS2_LL_FR_GRE;
bind->send_vc = frgre_vc_sendmsg;
diff --git a/src/gb/gprs_ns2_internal.h b/src/gb/gprs_ns2_internal.h
index 8c0c135..9bfe0b0 100644
--- a/src/gb/gprs_ns2_internal.h
+++ b/src/gb/gprs_ns2_internal.h
@@ -181,6 +181,8 @@
/*! Structure repesenting a bind instance. E.g. IPv4 listen port. */
struct gprs_ns2_vc_bind {
+ /*! unique name */
+ const char *name;
/*! list entry in nsi */
struct llist_head list;
/*! list of all VC */
diff --git a/src/gb/gprs_ns2_udp.c b/src/gb/gprs_ns2_udp.c
index b923e81..3eb8116 100644
--- a/src/gb/gprs_ns2_udp.c
+++ b/src/gb/gprs_ns2_udp.c
@@ -298,6 +298,7 @@
* \param[out] result if set, returns the bind object
* \return 0 on success; negative in case of error */
int gprs_ns2_ip_bind(struct gprs_ns2_inst *nsi,
+ const char *name,
const struct osmo_sockaddr *local,
int dscp,
struct gprs_ns2_vc_bind **result)
@@ -306,6 +307,12 @@
struct priv_bind *priv;
int rc;
+ if (!name)
+ return -EINVAL;
+
+ if (gprs_ns2_bind_by_name(nsi, name))
+ return -EALREADY;
+
bind = gprs_ns2_ip_bind_by_sockaddr(nsi, local);
if (bind) {
*result = bind;
@@ -316,6 +323,12 @@
if (!bind)
return -ENOSPC;
+ bind->name = talloc_strdup(bind, name);
+ if (!bind->name) {
+ talloc_free(bind);
+ return -ENOSPC;
+ }
+
if (local->u.sa.sa_family != AF_INET && local->u.sa.sa_family != AF_INET6) {
talloc_free(bind);
return -EINVAL;
diff --git a/src/gb/gprs_ns2_vty.c b/src/gb/gprs_ns2_vty.c
index d285c22..fdb6b0b 100644
--- a/src/gb/gprs_ns2_vty.c
+++ b/src/gb/gprs_ns2_vty.c
@@ -895,7 +895,7 @@
} else {
/* UDP */
osmo_sockaddr_str_to_sockaddr(&priv.udp, &sockaddr.u.sas);
- if (gprs_ns2_ip_bind(vty_nsi, &sockaddr, priv.dscp, &bind)) {
+ if (gprs_ns2_ip_bind(vty_nsi, "vtybind", &sockaddr, priv.dscp, &bind)) {
/* TODO: could not bind on the specific address */
return -1;
}
@@ -962,7 +962,7 @@
vty_nsi,
vtyvc->netif);
if (!fr) {
- rc = gprs_ns2_fr_bind(vty_nsi, vtyvc->netif, vty_fr_network, vtyvc->fr.role, &fr);
+ rc = gprs_ns2_fr_bind(vty_nsi, vtyvc->netif, vtyvc->netif, vty_fr_network, vtyvc->fr.role, &fr);
if (rc < 0) {
LOGP(DLNS, LOGL_ERROR, "Can not create fr bind on device %s err: %d\n", vtyvc->netif, rc);
return rc;
diff --git a/src/gb/libosmogb.map b/src/gb/libosmogb.map
index e3301be..7cc1cc8 100644
--- a/src/gb/libosmogb.map
+++ b/src/gb/libosmogb.map
@@ -109,6 +109,7 @@
gprs_ns_msgb_alloc;
gprs_ns2_aff_cause_prim_strs;
+gprs_ns2_bind_by_name;
gprs_ns2_cause_strs;
gprs_ns2_create_nse;
gprs_ns2_dynamic_create_nse;