mirror of
https://gitea.osmocom.org/cellular-infrastructure/osmo-hlr.git
synced 2025-11-02 21:23:30 +00:00
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
This commit is contained in:
@@ -7,3 +7,6 @@
|
|||||||
# If any interfaces have been added since the last public release: c:r:a + 1.
|
# 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.
|
# If any interfaces have been removed or changed since the last public release: c:r:0.
|
||||||
#library what description / commit summary line
|
#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()
|
||||||
@@ -20,6 +20,9 @@
|
|||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
#include <osmocom/core/timer.h>
|
#include <osmocom/core/timer.h>
|
||||||
#include <osmocom/gsm/oap_client.h>
|
#include <osmocom/gsm/oap_client.h>
|
||||||
#include <osmocom/gsm/ipa.h>
|
#include <osmocom/gsm/ipa.h>
|
||||||
@@ -40,6 +43,7 @@ typedef int (*osmo_gsup_client_read_cb_t)(struct osmo_gsup_client *gsupc, struct
|
|||||||
|
|
||||||
typedef bool (*osmo_gsup_client_up_down_cb_t)(struct osmo_gsup_client *gsupc, bool up);
|
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 {
|
struct osmo_gsup_client {
|
||||||
const char *unit_name; /* same as ipa_dev->unit_name, for backwards compat */
|
const char *unit_name; /* same as ipa_dev->unit_name, for backwards compat */
|
||||||
|
|
||||||
@@ -99,3 +103,12 @@ int osmo_gsup_client_enc_send(struct osmo_gsup_client *gsupc,
|
|||||||
const struct osmo_gsup_message *gsup_msg);
|
const struct osmo_gsup_message *gsup_msg);
|
||||||
struct msgb *osmo_gsup_client_msgb_alloc(void);
|
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);
|
||||||
|
|
||||||
|
|||||||
@@ -450,3 +450,36 @@ struct msgb *osmo_gsup_client_msgb_alloc(void)
|
|||||||
{
|
{
|
||||||
return msgb_alloc_headroom(4000, 64, __func__);
|
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;
|
||||||
|
}
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ static enum osmo_gsup_message_class gsup_client_mux_classify(struct gsup_client_
|
|||||||
/* Non-static for unit tests */
|
/* Non-static for unit tests */
|
||||||
int gsup_client_mux_rx(struct osmo_gsup_client *gsup_client, struct msgb *msg)
|
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;
|
struct osmo_gsup_message gsup;
|
||||||
enum osmo_gsup_message_class message_class;
|
enum osmo_gsup_message_class message_class;
|
||||||
int rc;
|
int rc;
|
||||||
@@ -115,7 +115,7 @@ int gsup_client_mux_start(struct gsup_client_mux *gcm, const char *gsup_server_a
|
|||||||
&gsup_client_mux_rx, NULL);
|
&gsup_client_mux_rx, NULL);
|
||||||
if (!gcm->gsup_client)
|
if (!gcm->gsup_client)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
gcm->gsup_client->data = gcm;
|
osmo_gsup_client_set_data(gcm->gsup_client, gcm);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,14 +144,16 @@ void gsup_client_mux_tx_set_source(const struct gsup_client_mux *gcm,
|
|||||||
struct osmo_gsup_message *gsup_msg)
|
struct osmo_gsup_message *gsup_msg)
|
||||||
{
|
{
|
||||||
const char *local_msc_name;
|
const char *local_msc_name;
|
||||||
|
const struct ipaccess_unit *ipa_dev;
|
||||||
|
|
||||||
if (!gcm)
|
if (!gcm)
|
||||||
return;
|
return;
|
||||||
if (!gcm->gsup_client)
|
if (!gcm->gsup_client)
|
||||||
return;
|
return;
|
||||||
if (!gcm->gsup_client->ipa_dev)
|
ipa_dev = osmo_gsup_client_get_ipaccess_unit(gcm->gsup_client);
|
||||||
|
if (!ipa_dev)
|
||||||
return;
|
return;
|
||||||
local_msc_name = gcm->gsup_client->ipa_dev->serno;
|
local_msc_name = ipa_dev->serno;
|
||||||
if (!local_msc_name)
|
if (!local_msc_name)
|
||||||
return;
|
return;
|
||||||
gsup_msg->source_name = (const uint8_t *) local_msc_name;
|
gsup_msg->source_name = (const uint8_t *) local_msc_name;
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ static void remote_hlr_err_reply(struct remote_hlr *rh, const struct osmo_gsup_m
|
|||||||
* The local MSC shall be indicated by gsup.destination_name. */
|
* The local MSC shall be indicated by gsup.destination_name. */
|
||||||
static int remote_hlr_rx(struct osmo_gsup_client *gsupc, struct msgb *msg)
|
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 proxy_subscr proxy_subscr;
|
||||||
struct osmo_gsup_message gsup;
|
struct osmo_gsup_message gsup;
|
||||||
int rc;
|
int rc;
|
||||||
@@ -108,7 +108,7 @@ struct remote_hlr_pending_up {
|
|||||||
|
|
||||||
static bool remote_hlr_up_down(struct osmo_gsup_client *gsupc, bool up)
|
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;
|
struct remote_hlr_pending_up *p, *n;
|
||||||
if (!up) {
|
if (!up) {
|
||||||
LOG_REMOTE_HLR(remote_hlr, LOGL_NOTICE, "link to remote HLR is down, removing GSUP client\n");
|
LOG_REMOTE_HLR(remote_hlr, LOGL_NOTICE, "link to remote HLR is down, removing GSUP client\n");
|
||||||
@@ -127,7 +127,7 @@ static bool remote_hlr_up_down(struct osmo_gsup_client *gsupc, bool up)
|
|||||||
|
|
||||||
bool remote_hlr_is_up(struct remote_hlr *remote_hlr)
|
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,
|
struct remote_hlr *remote_hlr_get_or_connect(const struct osmo_sockaddr_str *addr, bool connect,
|
||||||
@@ -180,7 +180,7 @@ struct remote_hlr *remote_hlr_get_or_connect(const struct osmo_sockaddr_str *add
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
rh->gsupc->data = rh;
|
osmo_gsup_client_set_data(rh->gsupc, rh);
|
||||||
llist_add(&rh->entry, &remote_hlrs);
|
llist_add(&rh->entry, &remote_hlrs);
|
||||||
|
|
||||||
add_result_cb:
|
add_result_cb:
|
||||||
|
|||||||
Reference in New Issue
Block a user