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
This commit is contained in:
Alexander Couzens 2020-12-03 06:02:03 +01:00 committed by lynxis lazus
parent 93ad499832
commit aaa55a663e
8 changed files with 75 additions and 4 deletions

View File

@ -162,8 +162,13 @@ void gprs_ns2_free_nses(struct gprs_ns2_inst *nsi);
void gprs_ns2_free_nsvc(struct gprs_ns2_vc *nsvc);
struct gprs_ns2_vc *gprs_ns2_nsvc_by_nsvci(struct gprs_ns2_inst *nsi, uint16_t nsvci);
/* generic VL driver */
struct gprs_ns2_vc_bind *gprs_ns2_bind_by_name(struct gprs_ns2_inst *nsi,
const char *name);
/* IP VL driver */
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);
@ -176,6 +181,7 @@ struct gprs_ns2_vc_bind *gprs_ns2_fr_bind_by_netif(
const char *netif);
const char *gprs_ns2_fr_bind_netif(struct gprs_ns2_vc_bind *bind);
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,
@ -226,6 +232,7 @@ struct gprs_ns2_vc *gprs_ns2_nsvc_by_sockaddr_bind(
const struct osmo_sockaddr *saddr);
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);

View File

@ -1239,6 +1239,7 @@ void gprs_ns2_free_bind(struct gprs_ns2_vc_bind *bind)
bind->driver->free_bind(bind);
llist_del(&bind->list);
talloc_free((char *)bind->name);
talloc_free(bind);
}
@ -1251,6 +1252,24 @@ void gprs_ns2_free_binds(struct gprs_ns2_inst *nsi)
}
}
/*! 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)
{

View File

@ -453,19 +453,33 @@ static void linkmon_initial_dump(struct osmo_mnl *omnl)
* \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 @@ int gprs_ns2_fr_bind(struct gprs_ns2_inst *nsi,
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 @@ err_fr:
osmo_fr_link_free(fr_link);
err_priv:
talloc_free(priv);
err_name:
talloc_free((char *)bind->name);
err_bind:
talloc_free(bind);

View File

@ -538,6 +538,7 @@ int gprs_ns2_is_frgre_bind(struct gprs_ns2_vc_bind *bind)
* \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 @@ int gprs_ns2_frgre_bind(struct gprs_ns2_inst *nsi,
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 @@ int gprs_ns2_frgre_bind(struct gprs_ns2_inst *nsi,
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;

View File

@ -181,6 +181,8 @@ struct gprs_ns2_vc {
/*! 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 */

View File

@ -298,6 +298,7 @@ struct gprs_ns2_vc_bind *gprs_ns2_ip_bind_by_sockaddr(struct gprs_ns2_inst *nsi,
* \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 @@ int gprs_ns2_ip_bind(struct gprs_ns2_inst *nsi,
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 @@ int gprs_ns2_ip_bind(struct gprs_ns2_inst *nsi,
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;

View File

@ -895,7 +895,7 @@ int gprs_ns2_vty_create() {
} 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 @@ int gprs_ns2_vty_create() {
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;

View File

@ -109,6 +109,7 @@ gprs_ns_ll_clear;
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;