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/.
laforge gerrit-no-reply at lists.osmocom.orglaforge has uploaded this change for review. ( 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, 26 insertions(+), 22 deletions(-) git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/80/23480/1 diff --git a/src/gb/gprs_ns2_sns.c b/src/gb/gprs_ns2_sns.c index 7268809..5470e43 100644 --- a/src/gb/gprs_ns2_sns.c +++ b/src/gb/gprs_ns2_sns.c @@ -367,6 +367,20 @@ ns2_vc_create_ip(fi, nse, &remote, ip6->sig_weight, ip6->data_weight); } +static bool do_we_have_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 true; + } + return false; +} static int create_missing_nsvcs(struct osmo_fsm_inst *fi) { @@ -377,6 +391,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,21 +399,15 @@ 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; + bool found; + + /* 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; - } - } - + found = do_we_have_nsvc_for_bind_and_remote(nse, bind, &remote); if (!found) { nsvc = gprs_ns2_ip_connect_inactive(bind, &remote, nse, 0); if (!nsvc) { @@ -414,6 +423,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,21 +431,15 @@ 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; + bool found; + 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; - } - } - + /* we only care about UDP binds */ + found = do_we_have_nsvc_for_bind_and_remote(nse, bind, &remote); if (!found) { nsvc = gprs_ns2_ip_connect_inactive(bind, &remote, nse, 0); if (!nsvc) { -- 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: 1 Gerrit-Owner: laforge <laforge at osmocom.org> Gerrit-MessageType: newchange -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210324/e0c7bf52/attachment.htm>