aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Couzens <lynxis@fe80.eu>2020-10-11 18:41:24 +0200
committerlaforge <laforge@osmocom.org>2020-10-12 13:08:42 +0000
commit4f60845552024419ecf8ad2c20cf108be7be4e04 (patch)
treead81f2eca11ca21ba33accdfd73c261dacd6dbe8
parentbb0a53ba40222afd3d3625e5adc3c0f1bfe6dd80 (diff)
gprs_ns2: add gprs_ns2_ip_bind_by_sockaddr() to search for binds by sockaddr
-rw-r--r--include/osmocom/gprs/gprs_ns2.h2
-rw-r--r--src/gb/gprs_ns2_udp.c26
-rw-r--r--src/gb/libosmogb.map1
3 files changed, 29 insertions, 0 deletions
diff --git a/include/osmocom/gprs/gprs_ns2.h b/include/osmocom/gprs/gprs_ns2.h
index dc27c96c..cbd6647d 100644
--- a/include/osmocom/gprs/gprs_ns2.h
+++ b/include/osmocom/gprs/gprs_ns2.h
@@ -110,6 +110,8 @@ int gprs_ns2_ip_bind(struct gprs_ns2_inst *nsi,
const struct osmo_sockaddr *local,
int dscp,
struct gprs_ns2_vc_bind **result);
+struct gprs_ns2_vc_bind *gprs_ns2_ip_bind_by_sockaddr(struct gprs_ns2_inst *nsi,
+ const struct osmo_sockaddr *sockaddr);
void gprs_ns2_bind_set_mode(struct gprs_ns2_vc_bind *bind, enum gprs_ns2_vc_mode mode);
/* create a VC connection */
diff --git a/src/gb/gprs_ns2_udp.c b/src/gb/gprs_ns2_udp.c
index 815e5168..a5781606 100644
--- a/src/gb/gprs_ns2_udp.c
+++ b/src/gb/gprs_ns2_udp.c
@@ -265,6 +265,32 @@ static int nsip_fd_cb(struct osmo_fd *bfd, unsigned int what)
return rc;
}
+/*! Find NS bind for a given socket address
+ * \param[in] nsi NS instance
+ * \param[in] sockaddr socket address to search for
+ * \return
+ */
+struct gprs_ns2_vc_bind *gprs_ns2_ip_bind_by_sockaddr(struct gprs_ns2_inst *nsi,
+ const struct osmo_sockaddr *sockaddr)
+{
+ struct gprs_ns2_vc_bind *bind;
+ struct osmo_sockaddr *local;
+
+ OSMO_ASSERT(nsi);
+ OSMO_ASSERT(sockaddr);
+
+ llist_for_each_entry(bind, &nsi->binding, list) {
+ if (!gprs_ns2_is_ip_bind(bind))
+ continue;
+
+ local = gprs_ns2_ip_bind_sockaddr(bind);
+ if (!osmo_sockaddr_cmp(sockaddr, local))
+ return bind;
+ }
+
+ return NULL;
+}
+
/*! Bind to an IPv4/IPv6 address
* \param[in] nsi NS Instance in which to create the NSVC
* \param[in] local the local address to bind to
diff --git a/src/gb/libosmogb.map b/src/gb/libosmogb.map
index d08e85e9..980b317f 100644
--- a/src/gb/libosmogb.map
+++ b/src/gb/libosmogb.map
@@ -84,6 +84,7 @@ gprs_ns2_free_nsvc;
gprs_ns2_frgre_bind;
gprs_ns2_instantiate;
gprs_ns2_ip_bind;
+gprs_ns2_ip_bind_by_sockaddr;
gprs_ns2_ip_bind_set_dscp;
gprs_ns2_ip_bind_sockaddr;
gprs_ns2_ip_connect;