From 68368dd99a2c98a4e8761f222f6174855d38bdd8 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Tue, 10 Jan 2012 22:39:07 +0100 Subject: nat: Implement clearing of TP-SRR flags from TPDUs Match IMSI and destination address against a set of entries, if it is matching the header will be modified and no sender report will be requested. Change the test case to request the sender report and then verify that this bit is reset to 0. --- openbsc/tests/bsc-nat/bsc_data.c | 12 +++++++- openbsc/tests/bsc-nat/bsc_nat_test.c | 55 +++++++++++++++++++++++++++++++++-- openbsc/tests/bsc-nat/bsc_nat_test.ok | 3 ++ 3 files changed, 67 insertions(+), 3 deletions(-) (limited to 'openbsc/tests/bsc-nat') diff --git a/openbsc/tests/bsc-nat/bsc_data.c b/openbsc/tests/bsc-nat/bsc_data.c index 101c57614..08b900b83 100644 --- a/openbsc/tests/bsc-nat/bsc_data.c +++ b/openbsc/tests/bsc-nat/bsc_data.c @@ -101,7 +101,7 @@ static const uint8_t smsc_rewrite[] = { 0x00, 0x30, 0xfd, 0x06, 0x01, 0x13, 0x1e, 0x00, 0x01, 0x29, 0x01, 0x03, 0x26, 0x09, 0x01, 0x23, 0x00, 0x0c, 0x00, 0x07, 0x91, 0x36, 0x19, 0x08, -0x00, 0x10, 0x50, 0x17, 0x01, 0x0c, 0x0f, 0x81, +0x00, 0x10, 0x50, 0x17, 0x21, 0x0c, 0x0f, 0x81, 0x00, 0x94, 0x51, 0x87, 0x86, 0x78, 0x46, 0xf5, 0x00, 0x00, 0x09, 0xcc, 0xb7, 0xbd, 0x0c, 0xca, 0xbf, 0xeb, 0x20 @@ -117,6 +117,16 @@ static const uint8_t smsc_rewrite_patched[] = { 0xca, 0xbf, 0xeb, 0x20 }; +static const uint8_t smsc_rewrite_patched_hdr[] = { +0x00, 0x30, 0xfd, 0x06, 0x01, 0x13, 0x1e, 0x00, +0x01, 0x29, 0x01, 0x03, 0x26, 0x09, 0x01, 0x23, +0x00, 0x0c, 0x00, 0x07, 0x91, 0x36, 0x19, 0x08, +0x00, 0x10, 0x50, 0x17, 0x01, 0x0c, 0x0f, 0x81, +0x00, 0x94, 0x51, 0x87, 0x86, 0x78, 0x46, 0xf5, +0x00, 0x00, 0x09, 0xcc, 0xb7, 0xbd, 0x0c, 0xca, +0xbf, 0xeb, 0x20 +}; + /* * MGCP messages diff --git a/openbsc/tests/bsc-nat/bsc_nat_test.c b/openbsc/tests/bsc-nat/bsc_nat_test.c index 974dfa55f..65ff4f65a 100644 --- a/openbsc/tests/bsc-nat/bsc_nat_test.c +++ b/openbsc/tests/bsc-nat/bsc_nat_test.c @@ -986,11 +986,12 @@ static void test_smsc_rewrite() struct bsc_nat *nat = bsc_nat_alloc(); /* a fake list */ - struct osmo_config_list smsc_entries, dest_entries; - struct osmo_config_entry smsc_entry, dest_entry; + struct osmo_config_list smsc_entries, dest_entries, clear_entries; + struct osmo_config_entry smsc_entry, dest_entry, clear_entry; INIT_LLIST_HEAD(&smsc_entries.entry); INIT_LLIST_HEAD(&dest_entries.entry); + INIT_LLIST_HEAD(&clear_entries.entry); smsc_entry.mcc = "^515039"; smsc_entry.option = "639180000105()"; smsc_entry.text = "6666666666667"; @@ -1000,10 +1001,20 @@ static void test_smsc_rewrite() dest_entry.option = "^0049"; dest_entry.text = ""; llist_add_tail(&dest_entry.list, &dest_entries.entry); + clear_entry.mcc = "^515039"; + clear_entry.option = "^0049"; + clear_entry.text = ""; + llist_add_tail(&clear_entry.list, &clear_entries.entry); bsc_nat_num_rewr_entry_adapt(nat, &nat->smsc_rewr, &smsc_entries); bsc_nat_num_rewr_entry_adapt(nat, &nat->tpdest_match, &dest_entries); + bsc_nat_num_rewr_entry_adapt(nat, &nat->sms_clear_tp_srr, &clear_entries); + printf("Testing SMSC rewriting.\n"); + + /* + * Check if the SMSC address is changed + */ copy_to_msg(msg, smsc_rewrite, ARRAY_SIZE(smsc_rewrite)); parsed = bsc_nat_parse(msg); if (!parsed) { @@ -1019,6 +1030,46 @@ static void test_smsc_rewrite() verify_msg(out, smsc_rewrite_patched, ARRAY_SIZE(smsc_rewrite_patched)); msgb_free(out); + + /* clear out the filter for SMSC */ + printf("Attempting to only rewrite the HDR\n"); + bsc_nat_num_rewr_entry_adapt(nat, &nat->smsc_rewr, NULL); + msg = msgb_alloc(4096, "SMSC rewrite"); + copy_to_msg(msg, smsc_rewrite, ARRAY_SIZE(smsc_rewrite)); + parsed = bsc_nat_parse(msg); + if (!parsed) { + printf("FAIL: Could not parse SMS\n"); + abort(); + } + + out = bsc_nat_rewrite_msg(nat, msg, parsed, imsi); + if (out == msg) { + printf("FAIL: This should have changed.\n"); + abort(); + } + + verify_msg(out, smsc_rewrite_patched_hdr, ARRAY_SIZE(smsc_rewrite_patched_hdr)); + msgb_free(out); + + /* clear out the next filter */ + printf("Attempting to change nothing.\n"); + bsc_nat_num_rewr_entry_adapt(nat, &nat->sms_clear_tp_srr, NULL); + msg = msgb_alloc(4096, "SMSC rewrite"); + copy_to_msg(msg, smsc_rewrite, ARRAY_SIZE(smsc_rewrite)); + parsed = bsc_nat_parse(msg); + if (!parsed) { + printf("FAIL: Could not parse SMS\n"); + abort(); + } + + out = bsc_nat_rewrite_msg(nat, msg, parsed, imsi); + if (out != msg) { + printf("FAIL: This should not have changed.\n"); + abort(); + } + + verify_msg(out, smsc_rewrite, ARRAY_SIZE(smsc_rewrite)); + msgb_free(out); } int main(int argc, char **argv) diff --git a/openbsc/tests/bsc-nat/bsc_nat_test.ok b/openbsc/tests/bsc-nat/bsc_nat_test.ok index 2aff594fb..f8eee238d 100644 --- a/openbsc/tests/bsc-nat/bsc_nat_test.ok +++ b/openbsc/tests/bsc-nat/bsc_nat_test.ok @@ -18,4 +18,7 @@ Testing MGCP. Testing finding of a BSC Connection Testing rewriting MGCP messages. Testing MGCP response parsing. +Testing SMSC rewriting. +Attempting to only rewrite the HDR +Attempting to change nothing. Testing execution completed. -- cgit v1.2.3