aboutsummaryrefslogtreecommitdiffstats
path: root/src/gb/gprs_ns2_udp.c
diff options
context:
space:
mode:
authorHarald Welte <laforge@osmocom.org>2021-01-31 11:41:34 +0100
committerHarald Welte <laforge@osmocom.org>2021-02-01 09:39:29 +0100
commitc3aa8f903a58db8af5c2687a3c040fe9f49474fb (patch)
tree2566076c74bd220591bba69a240c0b1b390964ee /src/gb/gprs_ns2_udp.c
parentb40bf8ba3b60ed0f2b97b5a13a85712c4a09fe45 (diff)
ns2: Move to one common/shared ns2_bind_alloc()
Avoid code duplication between three different drivers by sharing the "core" of the bind initialization in a new, shared ns2_bind_alloc(). Change-Id: I535fc68e94fcd695de827dd922706adc1c5a2cb7
Diffstat (limited to 'src/gb/gprs_ns2_udp.c')
-rw-r--r--src/gb/gprs_ns2_udp.c30
1 files changed, 6 insertions, 24 deletions
diff --git a/src/gb/gprs_ns2_udp.c b/src/gb/gprs_ns2_udp.c
index 43ece136..b4bcd018 100644
--- a/src/gb/gprs_ns2_udp.c
+++ b/src/gb/gprs_ns2_udp.c
@@ -315,32 +315,18 @@ int gprs_ns2_ip_bind(struct gprs_ns2_inst *nsi,
struct priv_bind *priv;
int rc;
- if (!name)
+ if (local->u.sa.sa_family != AF_INET && local->u.sa.sa_family != AF_INET6)
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;
return -EBUSY;
}
- bind = talloc_zero(nsi, struct gprs_ns2_vc_bind);
- 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;
- }
+ rc = ns2_bind_alloc(nsi, name, &bind);
+ if (rc < 0)
+ return rc;
bind->driver = &vc_driver_ip;
bind->ll = GPRS_NS2_LL_UDP;
@@ -351,24 +337,21 @@ int gprs_ns2_ip_bind(struct gprs_ns2_inst *nsi,
bind->send_vc = nsip_vc_sendmsg;
bind->free_vc = free_vc;
bind->dump_vty = dump_vty;
- bind->nsi = nsi;
priv = bind->priv = talloc_zero(bind, struct priv_bind);
if (!priv) {
- talloc_free(bind);
+ gprs_ns2_free_bind(bind);
return -ENOSPC;
}
priv->fd.cb = nsip_fd_cb;
priv->fd.data = bind;
priv->addr = *local;
- INIT_LLIST_HEAD(&bind->nsvc);
rc = osmo_sock_init_osa_ofd(&priv->fd, SOCK_DGRAM, IPPROTO_UDP,
local, NULL,
OSMO_SOCK_F_BIND);
if (rc < 0) {
- talloc_free(priv);
- talloc_free(bind);
+ gprs_ns2_free_bind(bind);
return rc;
}
@@ -382,7 +365,6 @@ int gprs_ns2_ip_bind(struct gprs_ns2_inst *nsi,
dscp, rc, errno);
}
- llist_add(&bind->list, &nsi->binding);
if (result)
*result = bind;