osmith has submitted this change. ( 
https://gerrit.osmocom.org/c/osmo-bsc-nat/+/27546 )

Change subject: bsc_nat_print_addr: pass net enum, not sccp_inst
......................................................................

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
---
M include/osmocom/bsc_nat/bsc_nat.h
M src/osmo-bsc-nat/bsc_nat.c
M src/osmo-bsc-nat/bsc_nat_fsm.c
M src/osmo-bsc-nat/bssap.c
4 files changed, 22 insertions(+), 15 deletions(-)

Approvals:
  Jenkins Builder: Verified
  pespin: Looks good to me, but someone else must approve
  laforge: Looks good to me, approved



diff --git a/include/osmocom/bsc_nat/bsc_nat.h 
b/include/osmocom/bsc_nat/bsc_nat.h
index d80510a..af4041b 100644
--- a/include/osmocom/bsc_nat/bsc_nat.h
+++ b/include/osmocom/bsc_nat/bsc_nat.h
@@ -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 *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;
diff --git a/src/osmo-bsc-nat/bsc_nat.c b/src/osmo-bsc-nat/bsc_nat.c
index 2e9c781..cae65e5 100644
--- a/src/osmo-bsc-nat/bsc_nat.c
+++ b/src/osmo-bsc-nat/bsc_nat.c
@@ -53,12 +53,12 @@
        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;
 }
diff --git a/src/osmo-bsc-nat/bsc_nat_fsm.c b/src/osmo-bsc-nat/bsc_nat_fsm.c
index 0c36607..1f4662f 100644
--- a/src/osmo-bsc-nat/bsc_nat_fsm.c
+++ b/src/osmo-bsc-nat/bsc_nat_fsm.c
@@ -123,7 +123,7 @@
                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 @@
                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 @@
                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 @@
                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 @@
                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 @@
                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 @@
                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 @@
                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 @@
                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 @@
                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. */
diff --git a/src/osmo-bsc-nat/bssap.c b/src/osmo-bsc-nat/bssap.c
index c054db6..597c0e6 100644
--- a/src/osmo-bsc-nat/bssap.c
+++ b/src/osmo-bsc-nat/bssap.c
@@ -29,9 +29,9 @@
 {
        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);
 }

--
To view, visit https://gerrit.osmocom.org/c/osmo-bsc-nat/+/27546
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-bsc-nat
Gerrit-Branch: master
Gerrit-Change-Id: I3c6046a6726c31bf137223c46c2c96b3898ad324
Gerrit-Change-Number: 27546
Gerrit-PatchSet: 2
Gerrit-Owner: osmith <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <[email protected]>
Gerrit-Reviewer: osmith <[email protected]>
Gerrit-Reviewer: pespin <[email protected]>
Gerrit-MessageType: merged

Reply via email to