bsc_nat_print_addr: pass net enum, not sccp_inst

The sccp_inst was only used to differentiate between CN / RAN. Instead
of passing that, pass an enum and add bsc_nat_print_addr_cn and _ran
defines to keep it short.

This is in preparation for refactoring struct bsc_nat as suggested in
code review.

Related: SYS#5560
Change-Id: I3c6046a6726c31bf137223c46c2c96b3898ad324
This commit is contained in:
Oliver Smith 2022-03-21 12:25:22 +01:00
parent d0059e2bd2
commit 0aa4cb372b
4 changed files with 22 additions and 15 deletions

View File

@ -22,6 +22,11 @@
#include <osmocom/core/fsm.h>
#include <osmocom/sigtran/sccp_sap.h>
enum bsc_nat_net {
BSC_NAT_NET_CN = 0,
BSC_NAT_NET_RAN
};
struct bsc_nat_sccp_inst {
uint32_t ss7_id;
struct osmo_ss7_instance *ss7_inst;
@ -40,7 +45,9 @@ struct bsc_nat {
struct bsc_nat *bsc_nat_alloc(void *tall_ctx);
void bsc_nat_free(struct bsc_nat *bsc_nat);
const char *bsc_nat_print_addr(struct bsc_nat_sccp_inst *sccp_inst, struct osmo_sccp_addr *addr);
#define bsc_nat_print_addr_cn(addr) bsc_nat_print_addr(BSC_NAT_NET_CN, addr)
#define bsc_nat_print_addr_ran(addr) bsc_nat_print_addr(BSC_NAT_NET_RAN, addr)
const char *bsc_nat_print_addr(enum bsc_nat_net net, struct osmo_sccp_addr *addr);
extern void *tall_bsc_nat_ctx;
extern struct bsc_nat *g_bsc_nat;

View File

@ -53,12 +53,12 @@ void bsc_nat_free(struct bsc_nat *bsc_nat)
talloc_free(bsc_nat);
}
const char *bsc_nat_print_addr(struct bsc_nat_sccp_inst *sccp_inst, struct osmo_sccp_addr *addr)
const char *bsc_nat_print_addr(enum bsc_nat_net net, struct osmo_sccp_addr *addr)
{
static char buf[25];
snprintf(buf, sizeof(buf), "PC=%s in %s", osmo_ss7_pointcode_print(NULL, addr->pc),
sccp_inst == g_bsc_nat->cn ? "CN" : "RAN");
net == BSC_NAT_NET_CN ? "CN" : "RAN");
return buf;
}

View File

@ -123,7 +123,7 @@ static int sccp_sap_up_cn(struct osmo_prim_hdr *oph, void *scu)
if (sccp_sap_get_peer_addr_out(sccp_inst, addr, &peer_addr_out) < 0)
goto error;
LOGP(DMAIN, LOGL_DEBUG, "Fwd to %s\n", bsc_nat_print_addr(g_bsc_nat->ran, &peer_addr_out));
LOGP(DMAIN, LOGL_DEBUG, "Fwd to %s\n", bsc_nat_print_addr_ran(&peer_addr_out));
msgb_pull_to_l2(oph->msg);
osmo_sccp_tx_conn_req(g_bsc_nat->ran->scu,
@ -144,7 +144,7 @@ static int sccp_sap_up_cn(struct osmo_prim_hdr *oph, void *scu)
if (sccp_sap_get_peer_addr_out(sccp_inst, addr, &peer_addr_out) < 0)
goto error;
LOGP(DMAIN, LOGL_DEBUG, "Fwd to %s\n", bsc_nat_print_addr(g_bsc_nat->ran, &peer_addr_out));
LOGP(DMAIN, LOGL_DEBUG, "Fwd to %s\n", bsc_nat_print_addr_ran(&peer_addr_out));
msgb_pull_to_l2(oph->msg);
osmo_sccp_tx_conn_resp(g_bsc_nat->ran->scu,
@ -160,7 +160,7 @@ static int sccp_sap_up_cn(struct osmo_prim_hdr *oph, void *scu)
if (sccp_sap_get_peer_addr_out(sccp_inst, NULL, &peer_addr_out) < 0)
goto error;
LOGP(DMAIN, LOGL_DEBUG, "Fwd to %s\n", bsc_nat_print_addr(g_bsc_nat->ran, &peer_addr_out));
LOGP(DMAIN, LOGL_DEBUG, "Fwd to %s\n", bsc_nat_print_addr_ran(&peer_addr_out));
msgb_pull_to_l2(oph->msg);
osmo_sccp_tx_data(g_bsc_nat->ran->scu,
@ -175,7 +175,7 @@ static int sccp_sap_up_cn(struct osmo_prim_hdr *oph, void *scu)
if (sccp_sap_get_peer_addr_out(sccp_inst, NULL, &peer_addr_out) < 0)
goto error;
LOGP(DMAIN, LOGL_DEBUG, "Fwd to %s\n", bsc_nat_print_addr(g_bsc_nat->ran, &peer_addr_out));
LOGP(DMAIN, LOGL_DEBUG, "Fwd to %s\n", bsc_nat_print_addr_ran(&peer_addr_out));
osmo_sccp_tx_disconn(g_bsc_nat->ran->scu,
prim->u.disconnect.conn_id,
@ -191,7 +191,7 @@ static int sccp_sap_up_cn(struct osmo_prim_hdr *oph, void *scu)
if (sccp_sap_get_peer_addr_out(sccp_inst, addr, &peer_addr_out) < 0)
goto error;
LOGP(DMAIN, LOGL_DEBUG, "Fwd to %s\n", bsc_nat_print_addr(g_bsc_nat->ran, &peer_addr_out));
LOGP(DMAIN, LOGL_DEBUG, "Fwd to %s\n", bsc_nat_print_addr_ran(&peer_addr_out));
/* oph->msg stores oph and unitdata msg. Move oph->msg->data to
* unitdata msg and send it again. */
@ -237,7 +237,7 @@ static int sccp_sap_up_ran(struct osmo_prim_hdr *oph, void *scu)
if (sccp_sap_get_peer_addr_out(sccp_inst, addr, &peer_addr_out) < 0)
goto error;
LOGP(DMAIN, LOGL_DEBUG, "Fwd to %s\n", bsc_nat_print_addr(g_bsc_nat->cn, &peer_addr_out));
LOGP(DMAIN, LOGL_DEBUG, "Fwd to %s\n", bsc_nat_print_addr_cn(&peer_addr_out));
msgb_pull_to_l2(oph->msg);
osmo_sccp_tx_conn_req(g_bsc_nat->cn->scu,
@ -258,7 +258,7 @@ static int sccp_sap_up_ran(struct osmo_prim_hdr *oph, void *scu)
if (sccp_sap_get_peer_addr_out(sccp_inst, addr, &peer_addr_out) < 0)
goto error;
LOGP(DMAIN, LOGL_DEBUG, "Fwd to %s\n", bsc_nat_print_addr(g_bsc_nat->cn, &peer_addr_out));
LOGP(DMAIN, LOGL_DEBUG, "Fwd to %s\n", bsc_nat_print_addr_cn(&peer_addr_out));
msgb_pull_to_l2(oph->msg);
osmo_sccp_tx_conn_resp(g_bsc_nat->cn->scu,
@ -274,7 +274,7 @@ static int sccp_sap_up_ran(struct osmo_prim_hdr *oph, void *scu)
if (sccp_sap_get_peer_addr_out(sccp_inst, NULL, &peer_addr_out) < 0)
goto error;
LOGP(DMAIN, LOGL_DEBUG, "Fwd to %s\n", bsc_nat_print_addr(g_bsc_nat->cn, &peer_addr_out));
LOGP(DMAIN, LOGL_DEBUG, "Fwd to %s\n", bsc_nat_print_addr_cn(&peer_addr_out));
msgb_pull_to_l2(oph->msg);
osmo_sccp_tx_data(g_bsc_nat->cn->scu,
@ -289,7 +289,7 @@ static int sccp_sap_up_ran(struct osmo_prim_hdr *oph, void *scu)
if (sccp_sap_get_peer_addr_out(sccp_inst, NULL, &peer_addr_out) < 0)
goto error;
LOGP(DMAIN, LOGL_DEBUG, "Fwd to %s\n", bsc_nat_print_addr(g_bsc_nat->cn, &peer_addr_out));
LOGP(DMAIN, LOGL_DEBUG, "Fwd to %s\n", bsc_nat_print_addr_cn(&peer_addr_out));
osmo_sccp_tx_disconn(g_bsc_nat->cn->scu,
prim->u.disconnect.conn_id,
@ -309,7 +309,7 @@ static int sccp_sap_up_ran(struct osmo_prim_hdr *oph, void *scu)
if (sccp_sap_get_peer_addr_out(sccp_inst, addr, &peer_addr_out) < 0)
goto error;
LOGP(DMAIN, LOGL_DEBUG, "Fwd to %s\n", bsc_nat_print_addr(g_bsc_nat->cn, &peer_addr_out));
LOGP(DMAIN, LOGL_DEBUG, "Fwd to %s\n", bsc_nat_print_addr_cn(&peer_addr_out));
/* oph->msg stores oph and unitdata msg. Move oph->msg->data to
* unitdata msg and send it again. */

View File

@ -29,9 +29,9 @@ static int bssap_ran_handle_reset(struct osmo_sccp_addr *addr, struct msgb *msg,
{
struct bsc_nat_sccp_inst *sccp_inst = g_bsc_nat->ran;
LOGP(DMAIN, LOGL_NOTICE, "Rx RESET from %s\n", bsc_nat_print_addr(sccp_inst, addr));
LOGP(DMAIN, LOGL_NOTICE, "Rx RESET from %s\n", bsc_nat_print_addr_ran(addr));
LOGP(DMAIN, LOGL_NOTICE, "Tx RESET ACK to %s\n", bsc_nat_print_addr(sccp_inst, addr));
LOGP(DMAIN, LOGL_NOTICE, "Tx RESET ACK to %s\n", bsc_nat_print_addr_ran(addr));
msg = gsm0808_create_reset_ack();
return osmo_sccp_tx_unitdata_msg(sccp_inst->scu, &sccp_inst->addr, addr, msg);
}