aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Willmann <dwillmann@sysmocom.de>2021-01-16 15:13:51 +0100
committerDaniel Willmann <dwillmann@sysmocom.de>2021-01-17 08:32:51 +0100
commitcf8371ad4d2eb0f77556cff710d514004fb00277 (patch)
tree6a9a0d1bb58f2af7084d1042e74ba6c30d3d6a8d
parentbb8990582fcbb750d71e7d38414948aed6c98524 (diff)
Refactor ns2_nsvc_create_ip*
Move code common in ipv4/6 into a separate function and call that function. Change-Id: I076d53bee2e67e1cb3ad6ee5cd05c63ebe3359fb Related: OS#4948
-rw-r--r--src/gb/gprs_ns2_sns.c49
1 files changed, 19 insertions, 30 deletions
diff --git a/src/gb/gprs_ns2_sns.c b/src/gb/gprs_ns2_sns.c
index 19584775..ceff1151 100644
--- a/src/gb/gprs_ns2_sns.c
+++ b/src/gb/gprs_ns2_sns.c
@@ -255,18 +255,12 @@ void ns2_sns_free_nsvc(struct gprs_ns2_vc *nsvc)
}
}
-static void ns2_nsvc_create_ip4(struct osmo_fsm_inst *fi,
- struct gprs_ns2_nse *nse,
- const struct gprs_ns_ie_ip4_elem *ip4)
+static void ns2_vc_create_ip(struct osmo_fsm_inst *fi, struct gprs_ns2_nse *nse, const struct osmo_sockaddr *remote,
+ uint8_t sig_weight, uint8_t data_weight)
{
struct gprs_ns2_inst *nsi = nse->nsi;
struct gprs_ns2_vc *nsvc;
struct gprs_ns2_vc_bind *bind;
- struct osmo_sockaddr remote = { };
- /* copy over. Both data structures use network byte order */
- remote.u.sin.sin_family = AF_INET;
- remote.u.sin.sin_addr.s_addr = ip4->ip_addr;
- remote.u.sin.sin_port = ip4->udp_port;
/* for every bind, create a connection if bind type == IP */
llist_for_each_entry(bind, &nsi->binding, list) {
@@ -274,47 +268,42 @@ static void ns2_nsvc_create_ip4(struct osmo_fsm_inst *fi,
continue;
/* ignore failed connection */
nsvc = gprs_ns2_ip_connect_inactive(bind,
- &remote,
+ remote,
nse, 0);
if (!nsvc) {
LOGPFSML(fi, LOGL_ERROR, "SNS-CONFIG: Failed to create NSVC\n");
continue;
}
- nsvc->sig_weight = ip4->sig_weight;
- nsvc->data_weight = ip4->data_weight;
+ nsvc->sig_weight = sig_weight;
+ nsvc->data_weight = data_weight;
}
}
+static void ns2_nsvc_create_ip4(struct osmo_fsm_inst *fi,
+ struct gprs_ns2_nse *nse,
+ const struct gprs_ns_ie_ip4_elem *ip4)
+{
+ struct osmo_sockaddr remote = { };
+ /* copy over. Both data structures use network byte order */
+ remote.u.sin.sin_family = AF_INET;
+ remote.u.sin.sin_addr.s_addr = ip4->ip_addr;
+ remote.u.sin.sin_port = ip4->udp_port;
+
+ ns2_vc_create_ip(fi, nse, &remote, ip4->sig_weight, ip4->data_weight);
+}
+
static void ns2_nsvc_create_ip6(struct osmo_fsm_inst *fi,
struct gprs_ns2_nse *nse,
const struct gprs_ns_ie_ip6_elem *ip6)
{
- struct gprs_ns2_inst *nsi = nse->nsi;
- struct gprs_ns2_vc *nsvc;
- struct gprs_ns2_vc_bind *bind;
struct osmo_sockaddr remote = {};
/* copy over. Both data structures use network byte order */
remote.u.sin6.sin6_family = AF_INET6;
remote.u.sin6.sin6_addr = ip6->ip_addr;
remote.u.sin6.sin6_port = ip6->udp_port;
- /* for every bind, create a connection if bind type == IP */
- llist_for_each_entry(bind, &nsi->binding, list) {
- if (bind->ll != GPRS_NS2_LL_UDP)
- continue;
- /* ignore failed connection */
- nsvc = gprs_ns2_ip_connect_inactive(bind,
- &remote,
- nse, 0);
- if (!nsvc) {
- LOGPFSML(fi, LOGL_ERROR, "SNS-CONFIG: Failed to create NSVC\n");
- continue;
- }
-
- nsvc->sig_weight = ip6->sig_weight;
- nsvc->data_weight = ip6->data_weight;
- }
+ ns2_vc_create_ip(fi, nse, &remote, ip6->sig_weight, ip6->data_weight);
}