aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHarald Welte <laforge@osmocom.org>2021-03-24 13:16:27 +0100
committerdaniel <dwillmann@sysmocom.de>2021-03-24 16:18:15 +0000
commite8c6106c2e02d3055c705aed415ea43b2f849a2f (patch)
tree729b76c03b83dcc6d956c35e081b1ca5e2dc329d /src
parent27e5873c8d7b63912fd93b68cd58659f980975f5 (diff)
gprs_ns2_sns: remove code duplication in create_missing_nsvcs()
Diffstat (limited to 'src')
-rw-r--r--src/gb/gprs_ns2_sns.c49
1 files changed, 25 insertions, 24 deletions
diff --git a/src/gb/gprs_ns2_sns.c b/src/gb/gprs_ns2_sns.c
index 72688094..2370f01c 100644
--- a/src/gb/gprs_ns2_sns.c
+++ b/src/gb/gprs_ns2_sns.c
@@ -367,6 +367,21 @@ static void ns2_nsvc_create_ip6(struct osmo_fsm_inst *fi,
ns2_vc_create_ip(fi, nse, &remote, ip6->sig_weight, ip6->data_weight);
}
+static struct gprs_ns2_vc *nsvc_for_bind_and_remote(struct gprs_ns2_nse *nse,
+ struct gprs_ns2_vc_bind *bind,
+ const struct osmo_sockaddr *remote)
+{
+ struct gprs_ns2_vc *nsvc;
+
+ llist_for_each_entry(nsvc, &nse->nsvc, list) {
+ if (nsvc->bind != bind)
+ continue;
+
+ if (!osmo_sockaddr_cmp(remote, gprs_ns2_ip_vc_remote(nsvc)))
+ return nsvc;
+ }
+ return NULL;
+}
static int create_missing_nsvcs(struct osmo_fsm_inst *fi)
{
@@ -377,6 +392,7 @@ static int create_missing_nsvcs(struct osmo_fsm_inst *fi)
struct osmo_sockaddr remote = { };
unsigned int i;
+ /* iterate over all remote IPv4 endpoints */
for (i = 0; i < gss->num_ip4_remote; i++) {
const struct gprs_ns_ie_ip4_elem *ip4 = &gss->ip4_remote[i];
@@ -384,22 +400,14 @@ static int create_missing_nsvcs(struct osmo_fsm_inst *fi)
remote.u.sin.sin_addr.s_addr = ip4->ip_addr;
remote.u.sin.sin_port = ip4->udp_port;
+ /* iterate over all local binds */
llist_for_each_entry(bind, &nse->nsi->binding, list) {
- bool found = false;
+ /* we only care about UDP binds */
if (bind->ll != GPRS_NS2_LL_UDP)
continue;
- llist_for_each_entry(nsvc, &nse->nsvc, list) {
- if (nsvc->bind != bind)
- continue;
-
- if (!osmo_sockaddr_cmp(&remote, gprs_ns2_ip_vc_remote(nsvc))) {
- found = true;
- break;
- }
- }
-
- if (!found) {
+ nsvc = nsvc_for_bind_and_remote(nse, bind, &remote);
+ if (!nsvc) {
nsvc = gprs_ns2_ip_connect_inactive(bind, &remote, nse, 0);
if (!nsvc) {
/* TODO: add to a list to send back a NS-STATUS */
@@ -414,6 +422,7 @@ static int create_missing_nsvcs(struct osmo_fsm_inst *fi)
}
}
+ /* iterate over all remote IPv4 endpoints */
for (i = 0; i < gss->num_ip6_remote; i++) {
const struct gprs_ns_ie_ip6_elem *ip6 = &gss->ip6_remote[i];
@@ -421,22 +430,14 @@ static int create_missing_nsvcs(struct osmo_fsm_inst *fi)
remote.u.sin6.sin6_addr = ip6->ip_addr;
remote.u.sin6.sin6_port = ip6->udp_port;
+ /* iterate over all local binds */
llist_for_each_entry(bind, &nse->nsi->binding, list) {
- bool found = false;
if (bind->ll != GPRS_NS2_LL_UDP)
continue;
- llist_for_each_entry(nsvc, &nse->nsvc, list) {
- if (nsvc->bind != bind)
- continue;
-
- if (!osmo_sockaddr_cmp(&remote, gprs_ns2_ip_vc_remote(nsvc))) {
- found = true;
- break;
- }
- }
-
- if (!found) {
+ /* we only care about UDP binds */
+ nsvc = nsvc_for_bind_and_remote(nse, bind, &remote);
+ if (!nsvc) {
nsvc = gprs_ns2_ip_connect_inactive(bind, &remote, nse, 0);
if (!nsvc) {
/* TODO: add to a list to send back a NS-STATUS */