aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc/src/osmo-bsc_nat/bsc_nat_utils.c
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/src/osmo-bsc_nat/bsc_nat_utils.c
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/src/osmo-bsc_nat/bsc_nat_utils.c')
-rw-r--r--openbsc/src/osmo-bsc_nat/bsc_nat_utils.c55
1 files changed, 31 insertions, 24 deletions
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);