aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2011-05-27 14:09:55 +0200
committerHolger Hans Peter Freyther <zecke@selfish.org>2011-06-01 20:41:30 +0200
commitdf8e6e9e4a14327a06468c43b1189c90f36f8c61 (patch)
tree7ec4be0dc11c1433a3a47dba43e32e869b16d0fd /openbsc
parentad75eababc153d513e75f7f052818ca02acd9533 (diff)
nat: Prepare to patch more than the CC Setup message
Refactor the code to allow having different handlers. The goal is to be able to patch some SMS messages too.
Diffstat (limited to 'openbsc')
-rw-r--r--openbsc/include/openbsc/bsc_nat.h2
-rw-r--r--openbsc/src/osmo-bsc_nat/bsc_nat.c2
-rw-r--r--openbsc/src/osmo-bsc_nat/bsc_nat_utils.c55
-rw-r--r--openbsc/tests/bsc-nat/bsc_nat_test.c8
4 files changed, 37 insertions, 30 deletions
diff --git a/openbsc/include/openbsc/bsc_nat.h b/openbsc/include/openbsc/bsc_nat.h
index 650d1133c..bf88e0af4 100644
--- a/openbsc/include/openbsc/bsc_nat.h
+++ b/openbsc/include/openbsc/bsc_nat.h
@@ -385,7 +385,7 @@ int bsc_ussd_init(struct bsc_nat *nat);
int bsc_check_ussd(struct sccp_connections *con, struct bsc_nat_parsed *parsed, struct msgb *msg);
int bsc_close_ussd_connections(struct bsc_nat *nat);
-struct msgb *bsc_nat_rewrite_setup(struct bsc_nat *nat, struct msgb *msg, struct bsc_nat_parsed *, const char *imsi);
+struct msgb *bsc_nat_rewrite_msg(struct bsc_nat *nat, struct msgb *msg, struct bsc_nat_parsed *, const char *imsi);
/** paging group handling */
struct bsc_nat_paging_group *bsc_nat_paging_group_num(struct bsc_nat *nat, int group);
diff --git a/openbsc/src/osmo-bsc_nat/bsc_nat.c b/openbsc/src/osmo-bsc_nat/bsc_nat.c
index 8649f43c3..e0eb635f0 100644
--- a/openbsc/src/osmo-bsc_nat/bsc_nat.c
+++ b/openbsc/src/osmo-bsc_nat/bsc_nat.c
@@ -1040,7 +1040,7 @@ static int forward_sccp_to_msc(struct bsc_connection *bsc, struct msgb *msg)
* replace the msg and the parsed structure becomes
* invalid.
*/
- msg = bsc_nat_rewrite_setup(bsc->nat, msg, parsed, con->imsi);
+ msg = bsc_nat_rewrite_msg(bsc->nat, msg, parsed, con->imsi);
talloc_free(parsed);
parsed = NULL;
} else if (con->con_local == NAT_CON_END_USSD) {
diff --git a/openbsc/src/osmo-bsc_nat/bsc_nat_utils.c b/openbsc/src/osmo-bsc_nat/bsc_nat_utils.c
index a7b00440a..47eaabdd1 100644
--- a/openbsc/src/osmo-bsc_nat/bsc_nat_utils.c
+++ b/openbsc/src/osmo-bsc_nat/bsc_nat_utils.c
@@ -838,39 +838,19 @@ static char *rewrite_non_international(struct bsc_nat *nat, void *ctx, const cha
/**
* Rewrite non global numbers... according to rules based on the IMSI
*/
-struct msgb *bsc_nat_rewrite_setup(struct bsc_nat *nat, struct msgb *msg, struct bsc_nat_parsed *parsed, const char *imsi)
+static struct msgb *rewrite_setup(struct bsc_nat *nat, struct msgb *msg,
+ struct bsc_nat_parsed *parsed, const char *imsi,
+ struct gsm48_hdr *hdr48, const uint32_t len)
{
struct tlv_parsed tp;
- struct gsm48_hdr *hdr48;
- uint32_t len;
- uint8_t msg_type, proto;
unsigned int payload_len;
struct gsm_mncc_number called;
- char *new_number = NULL;
struct msgb *out, *sccp;
+ char *new_number = NULL;
uint8_t *outptr;
const uint8_t *msgptr;
int sec_len;
- if (!imsi || strlen(imsi) < 5)
- return msg;
-
- /* only care about DTAP messages */
- if (parsed->bssap != BSSAP_MSG_DTAP)
- return msg;
- if (!parsed->dest_local_ref)
- return msg;
-
- hdr48 = bsc_unpack_dtap(parsed, msg, &len);
- if (!hdr48)
- return msg;
-
- proto = hdr48->proto_discr & 0x0f;
- msg_type = hdr48->msg_type & 0xbf;
- if (proto != GSM48_PDISC_CC ||
- msg_type != GSM48_MT_CC_SETUP)
- return msg;
-
/* decode and rewrite the message */
payload_len = len - sizeof(*hdr48);
tlv_parse(&tp, &gsm48_att_tlvdef, hdr48->data, payload_len, 0, 0);
@@ -957,6 +937,33 @@ struct msgb *bsc_nat_rewrite_setup(struct bsc_nat *nat, struct msgb *msg, struct
return sccp;
}
+struct msgb *bsc_nat_rewrite_msg(struct bsc_nat *nat, struct msgb *msg, struct bsc_nat_parsed *parsed, const char *imsi)
+{
+ struct gsm48_hdr *hdr48;
+ uint32_t len;
+ uint8_t msg_type, proto;
+
+ if (!imsi || strlen(imsi) < 5)
+ return msg;
+
+ /* only care about DTAP messages */
+ if (parsed->bssap != BSSAP_MSG_DTAP)
+ return msg;
+ if (!parsed->dest_local_ref)
+ return msg;
+
+ hdr48 = bsc_unpack_dtap(parsed, msg, &len);
+ if (!hdr48)
+ return msg;
+
+ proto = hdr48->proto_discr & 0x0f;
+ msg_type = hdr48->msg_type & 0xbf;
+
+ if (proto == GSM48_PDISC_CC && msg_type == GSM48_MT_CC_SETUP)
+ return rewrite_setup(nat, msg, parsed, imsi, hdr48, len);
+
+ return msg;
+}
static void num_rewr_free_data(struct bsc_nat_num_rewr_entry *entry)
{
regfree(&entry->msisdn_reg);
diff --git a/openbsc/tests/bsc-nat/bsc_nat_test.c b/openbsc/tests/bsc-nat/bsc_nat_test.c
index 32f4f72ff..c9432fefd 100644
--- a/openbsc/tests/bsc-nat/bsc_nat_test.c
+++ b/openbsc/tests/bsc-nat/bsc_nat_test.c
@@ -865,7 +865,7 @@ static void test_setup_rewrite()
abort();
}
- out = bsc_nat_rewrite_setup(nat, msg, parsed, imsi);
+ out = bsc_nat_rewrite_msg(nat, msg, parsed, imsi);
if (msg != out) {
fprintf(stderr, "FAIL: The message should not have been changed\n");
abort();
@@ -891,7 +891,7 @@ static void test_setup_rewrite()
abort();
}
- out = bsc_nat_rewrite_setup(nat, msg, parsed, imsi);
+ out = bsc_nat_rewrite_msg(nat, msg, parsed, imsi);
if (!out) {
fprintf(stderr, "FAIL: A new message should be created.\n");
abort();
@@ -926,7 +926,7 @@ static void test_setup_rewrite()
abort();
}
- out = bsc_nat_rewrite_setup(nat, msg, parsed, imsi);
+ out = bsc_nat_rewrite_msg(nat, msg, parsed, imsi);
if (!out) {
fprintf(stderr, "FAIL: A new message should be created.\n");
abort();
@@ -961,7 +961,7 @@ static void test_setup_rewrite()
abort();
}
- out = bsc_nat_rewrite_setup(nat, msg, parsed, imsi);
+ out = bsc_nat_rewrite_msg(nat, msg, parsed, imsi);
if (out != msg) {
fprintf(stderr, "FAIL: The message should be unchanged.\n");
abort();