pespin submitted this change.
1 is the latest approved patch-set.
No files were changed between the latest approved patch-set and the submitted one.
gsup_client: Add new APIs to avoid users accessing struct fields
This is a first step towards changing gsup_client implementation to use
an osmo_stream_cli instead of libosmo-abis' ipa_client_conn.
The libosmo-abis' ipa_client_conn will eventually be deprecated together
with all IPA related code in libosmo-abis.
In order to be able to make the implementation change, we first need to
make sure no users are using the struct fields of gsup_client (this
patch); 2nd step will be making the struct private by moving it to a
private header; 3rd step will be changing the implementation to use
osmo_stream.
Related: OS#5896
Change-Id: I401af83232022f1c141eef1f428cbe206a8aaaa2
---
M TODO-RELEASE
M include/osmocom/gsupclient/gsup_client.h
M src/gsupclient/gsup_client.c
M src/gsupclient/gsup_client_mux.c
M src/remote_hlr.c
5 files changed, 59 insertions(+), 8 deletions(-)
diff --git a/TODO-RELEASE b/TODO-RELEASE
index 0ed7189..f14e8b5 100644
--- a/TODO-RELEASE
+++ b/TODO-RELEASE
@@ -7,3 +7,6 @@
# If any interfaces have been added since the last public release: c:r:a + 1.
# If any interfaces have been removed or changed since the last public release: c:r:0.
#library what description / commit summary line
+libosmo-gsup-client new API osmo_gsup_client_{get,set}_data(),
+ osmo_gsup_client_get_rem_addr(), osmo_gsup_client_get_rem_port(),
+ osmo_gsup_client_is_connected(), osmo_gsup_client_get_ipaccess_unit()
\ No newline at end of file
diff --git a/include/osmocom/gsupclient/gsup_client.h b/include/osmocom/gsupclient/gsup_client.h
index ea66ca1..61cd45d 100644
--- a/include/osmocom/gsupclient/gsup_client.h
+++ b/include/osmocom/gsupclient/gsup_client.h
@@ -20,6 +20,9 @@
*/
#pragma once
+#include <stdint.h>
+#include <stdbool.h>
+
#include <osmocom/core/timer.h>
#include <osmocom/gsm/oap_client.h>
#include <osmocom/gsm/ipa.h>
@@ -40,6 +43,7 @@
typedef bool (*osmo_gsup_client_up_down_cb_t)(struct osmo_gsup_client *gsupc, bool up);
+/* NOTE: THIS STRUCT IS CONSIDERED PRIVATE, AVOID ACCESSING ITS FIELDS! */
struct osmo_gsup_client {
const char *unit_name; /* same as ipa_dev->unit_name, for backwards compat */
@@ -99,3 +103,12 @@
const struct osmo_gsup_message *gsup_msg);
struct msgb *osmo_gsup_client_msgb_alloc(void);
+void *osmo_gsup_client_get_data(const struct osmo_gsup_client *gsupc);
+void osmo_gsup_client_set_data(struct osmo_gsup_client *gsupc, void *data);
+
+const char *osmo_gsup_client_get_rem_addr(const struct osmo_gsup_client *gsupc);
+uint16_t osmo_gsup_client_get_rem_port(const struct osmo_gsup_client *gsupc);
+
+bool osmo_gsup_client_is_connected(const struct osmo_gsup_client *gsupc);
+const struct ipaccess_unit *osmo_gsup_client_get_ipaccess_unit(const struct osmo_gsup_client *gsupc);
+
diff --git a/src/gsupclient/gsup_client.c b/src/gsupclient/gsup_client.c
index e7d03f2..1168c9d 100644
--- a/src/gsupclient/gsup_client.c
+++ b/src/gsupclient/gsup_client.c
@@ -450,3 +450,36 @@
{
return msgb_alloc_headroom(4000, 64, __func__);
}
+
+void *osmo_gsup_client_get_data(const struct osmo_gsup_client *gsupc)
+{
+ return gsupc->data;
+}
+
+void osmo_gsup_client_set_data(struct osmo_gsup_client *gsupc, void *data)
+{
+ gsupc->data = data;
+}
+
+const char *osmo_gsup_client_get_rem_addr(const struct osmo_gsup_client *gsupc)
+{
+ if (!gsupc->link)
+ return NULL;
+ return gsupc->link->addr;
+}
+uint16_t osmo_gsup_client_get_rem_port(const struct osmo_gsup_client *gsupc)
+{
+ if (!gsupc->link)
+ return 0;
+ return gsupc->link->port;
+}
+
+bool osmo_gsup_client_is_connected(const struct osmo_gsup_client *gsupc)
+{
+ return gsupc->is_connected;
+}
+
+const struct ipaccess_unit *osmo_gsup_client_get_ipaccess_unit(const struct osmo_gsup_client *gsupc)
+{
+ return gsupc->ipa_dev;
+}
diff --git a/src/gsupclient/gsup_client_mux.c b/src/gsupclient/gsup_client_mux.c
index 7699ca1..45ebd75 100644
--- a/src/gsupclient/gsup_client_mux.c
+++ b/src/gsupclient/gsup_client_mux.c
@@ -58,7 +58,7 @@
/* Non-static for unit tests */
int gsup_client_mux_rx(struct osmo_gsup_client *gsup_client, struct msgb *msg)
{
- struct gsup_client_mux *gcm = gsup_client->data;
+ struct gsup_client_mux *gcm = osmo_gsup_client_get_data(gsup_client);
struct osmo_gsup_message gsup;
enum osmo_gsup_message_class message_class;
int rc;
@@ -115,7 +115,7 @@
&gsup_client_mux_rx, NULL);
if (!gcm->gsup_client)
return -ENOMEM;
- gcm->gsup_client->data = gcm;
+ osmo_gsup_client_set_data(gcm->gsup_client, gcm);
return 0;
}
@@ -144,14 +144,16 @@
struct osmo_gsup_message *gsup_msg)
{
const char *local_msc_name;
+ const struct ipaccess_unit *ipa_dev;
if (!gcm)
return;
if (!gcm->gsup_client)
return;
- if (!gcm->gsup_client->ipa_dev)
+ ipa_dev = osmo_gsup_client_get_ipaccess_unit(gcm->gsup_client);
+ if (!ipa_dev)
return;
- local_msc_name = gcm->gsup_client->ipa_dev->serno;
+ local_msc_name = ipa_dev->serno;
if (!local_msc_name)
return;
gsup_msg->source_name = (const uint8_t *) local_msc_name;
diff --git a/src/remote_hlr.c b/src/remote_hlr.c
index 00bfbb1..93157a3 100644
--- a/src/remote_hlr.c
+++ b/src/remote_hlr.c
@@ -66,7 +66,7 @@
* The local MSC shall be indicated by gsup.destination_name. */
static int remote_hlr_rx(struct osmo_gsup_client *gsupc, struct msgb *msg)
{
- struct remote_hlr *rh = gsupc->data;
+ struct remote_hlr *rh = osmo_gsup_client_get_data(gsupc);
struct proxy_subscr proxy_subscr;
struct osmo_gsup_message gsup;
int rc;
@@ -108,7 +108,7 @@
static bool remote_hlr_up_down(struct osmo_gsup_client *gsupc, bool up)
{
- struct remote_hlr *remote_hlr = gsupc->data;
+ struct remote_hlr *remote_hlr = osmo_gsup_client_get_data(gsupc);
struct remote_hlr_pending_up *p, *n;
if (!up) {
LOG_REMOTE_HLR(remote_hlr, LOGL_NOTICE, "link to remote HLR is down, removing GSUP client\n");
@@ -127,7 +127,7 @@
bool remote_hlr_is_up(struct remote_hlr *remote_hlr)
{
- return remote_hlr && remote_hlr->gsupc && remote_hlr->gsupc->is_connected;
+ return remote_hlr && remote_hlr->gsupc && osmo_gsup_client_is_connected(remote_hlr->gsupc);
}
struct remote_hlr *remote_hlr_get_or_connect(const struct osmo_sockaddr_str *addr, bool connect,
@@ -180,7 +180,7 @@
return NULL;
}
- rh->gsupc->data = rh;
+ osmo_gsup_client_set_data(rh->gsupc, rh);
llist_add(&rh->entry, &remote_hlrs);
add_result_cb:
To view, visit change 39009. To unsubscribe, or for help writing mail filters, visit settings.