From e769f5226be6b0f8d59366c7b9a156e9cf8fc22d Mon Sep 17 00:00:00 2001 From: Alexander Couzens Date: Mon, 7 Dec 2020 07:37:07 +0100 Subject: gprs_ns2_sns: rework IP-SNS initial remote The IP-SNS requires at least one initial remote address of the SGSN. However it should be multiple initial remote address instead of a single in case the interface might fail. Rework the SNS to support multiple initial remote addresses. Change-Id: I71cdbfb53e361e6112fed5e2712236d797ef3ab2 --- src/gb/gprs_ns2_udp.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'src/gb/gprs_ns2_udp.c') diff --git a/src/gb/gprs_ns2_udp.c b/src/gb/gprs_ns2_udp.c index 3eb8116b..90582794 100644 --- a/src/gb/gprs_ns2_udp.c +++ b/src/gb/gprs_ns2_udp.c @@ -514,3 +514,52 @@ int gprs_ns2_ip_bind_set_dscp(struct gprs_ns2_vc_bind *bind, int dscp) return rc; } + +/*! Count UDP binds compatible with remote */ +int ns2_ip_count_bind(struct gprs_ns2_inst *nsi, struct osmo_sockaddr *remote) +{ + struct gprs_ns2_vc_bind *bind; + const struct osmo_sockaddr *sa; + int count = 0; + + llist_for_each_entry(bind, &nsi->binding, list) { + if (!gprs_ns2_is_ip_bind(bind)) + continue; + + sa = gprs_ns2_ip_bind_sockaddr(bind); + if (!sa) + continue; + + if (sa->u.sa.sa_family == remote->u.sa.sa_family) + count++; + } + + return count; +} + +/* return the matching bind by index */ +struct gprs_ns2_vc_bind *ns2_ip_get_bind_by_index(struct gprs_ns2_inst *nsi, + struct osmo_sockaddr *remote, + int index) +{ + struct gprs_ns2_vc_bind *bind; + const struct osmo_sockaddr *sa; + int i = 0; + + llist_for_each_entry(bind, &nsi->binding, list) { + if (!gprs_ns2_is_ip_bind(bind)) + continue; + + sa = gprs_ns2_ip_bind_sockaddr(bind); + if (!sa) + continue; + + if (sa->u.sa.sa_family == remote->u.sa.sa_family) { + if (index == i) + return bind; + i++; + } + } + + return NULL; +} -- cgit v1.2.3