diff options
author | Harald Welte <laforge@osmocom.org> | 2021-01-31 11:41:34 +0100 |
---|---|---|
committer | Harald Welte <laforge@osmocom.org> | 2021-02-01 09:39:29 +0100 |
commit | c3aa8f903a58db8af5c2687a3c040fe9f49474fb (patch) | |
tree | 2566076c74bd220591bba69a240c0b1b390964ee /src/gb/gprs_ns2_frgre.c | |
parent | b40bf8ba3b60ed0f2b97b5a13a85712c4a09fe45 (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_frgre.c')
-rw-r--r-- | src/gb/gprs_ns2_frgre.c | 32 |
1 files changed, 11 insertions, 21 deletions
diff --git a/src/gb/gprs_ns2_frgre.c b/src/gb/gprs_ns2_frgre.c index 5047af06..863f8f21 100644 --- a/src/gb/gprs_ns2_frgre.c +++ b/src/gb/gprs_ns2_frgre.c @@ -537,29 +537,22 @@ int gprs_ns2_frgre_bind(struct gprs_ns2_inst *nsi, int dscp, 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; int rc; - if (!name) - return -ENOSPC; + 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)) + bind = gprs_ns2_bind_by_name(nsi, name); + if (bind) { + *result = bind; return -EALREADY; - - if (!bind) - return -ENOSPC; - - if (local->u.sa.sa_family != AF_INET && local->u.sa.sa_family != AF_INET6) { - talloc_free(bind); - return -EINVAL; } - bind->name = talloc_strdup(bind, name); - if (!bind->name) { - talloc_free(bind); - return -ENOSPC; - } + rc = ns2_bind_alloc(nsi, name, &bind); + if (rc < 0) + return rc; bind->driver = &vc_driver_frgre; bind->ll = GPRS_NS2_LL_FR_GRE; @@ -571,7 +564,7 @@ int gprs_ns2_frgre_bind(struct gprs_ns2_inst *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 = frgre_fd_cb; @@ -579,14 +572,11 @@ int gprs_ns2_frgre_bind(struct gprs_ns2_inst *nsi, priv->addr = *local; INIT_LLIST_HEAD(&bind->nsvc); - llist_add(&bind->list, &nsi->binding); - rc = osmo_sock_init_osa_ofd(&priv->fd, SOCK_RAW, IPPROTO_GRE, local, NULL, OSMO_SOCK_F_BIND); if (rc < 0) { - talloc_free(priv); - talloc_free(bind); + gprs_ns2_free_bind(bind); return rc; } |