This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
daniel gerrit-no-reply at lists.osmocom.orgdaniel has submitted this change. ( https://gerrit.osmocom.org/c/libosmocore/+/23480 ) Change subject: gprs_ns2_sns: remove code duplication in create_missing_nsvcs() ...................................................................... gprs_ns2_sns: remove code duplication in create_missing_nsvcs() Change-Id: I78d79c3bc92f0c0bebbbbe639b8406c4b188582f --- M src/gb/gprs_ns2_sns.c 1 file changed, 25 insertions(+), 24 deletions(-) Approvals: daniel: Looks good to me, approved lynxis lazus: Looks good to me, but someone else must approve Jenkins Builder: Verified diff --git a/src/gb/gprs_ns2_sns.c b/src/gb/gprs_ns2_sns.c index 7268809..2370f01 100644 --- a/src/gb/gprs_ns2_sns.c +++ b/src/gb/gprs_ns2_sns.c @@ -367,6 +367,21 @@ 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 @@ 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 @@ 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 @@ } } + /* 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 @@ 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 */ -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/23480 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I78d79c3bc92f0c0bebbbbe639b8406c4b188582f Gerrit-Change-Number: 23480 Gerrit-PatchSet: 3 Gerrit-Owner: laforge <laforge at osmocom.org> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: daniel <dwillmann at sysmocom.de> Gerrit-Reviewer: lynxis lazus <lynxis at fe80.eu> Gerrit-Reviewer: pespin <pespin at sysmocom.de> Gerrit-MessageType: merged -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210324/21b38e2b/attachment.htm>