aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc/tests/bsc-nat
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2010-09-15 19:00:53 +0800
committerHolger Hans Peter Freyther <zecke@selfish.org>2010-09-15 19:00:53 +0800
commita594342f71e835d0316a3ee655a6c1a58679e1b4 (patch)
tree3b2eb213c518ea3434c5f7f60a46246fcce1e79f /openbsc/tests/bsc-nat
parent5f54075a8be6e041c8fbf56ff6281fc78a6d7929 (diff)
parent09ecda49d7e12412d50e85109e3f3dc81d76927f (diff)
Merge branch 'zecke/imsi-filter'
Diffstat (limited to 'openbsc/tests/bsc-nat')
-rw-r--r--openbsc/tests/bsc-nat/bsc_data.c8
-rw-r--r--openbsc/tests/bsc-nat/bsc_nat_test.c64
2 files changed, 67 insertions, 5 deletions
diff --git a/openbsc/tests/bsc-nat/bsc_data.c b/openbsc/tests/bsc-nat/bsc_data.c
index a3239799c..1bc15c873 100644
--- a/openbsc/tests/bsc-nat/bsc_data.c
+++ b/openbsc/tests/bsc-nat/bsc_data.c
@@ -88,6 +88,14 @@ static const uint8_t ass_cmd[] = {
0x01, 0x0b, 0x03, 0x01, 0x0a, 0x11, 0x01, 0x00,
0x15 };
+/* identity response */
+static const uint8_t id_resp[] = {
+0x00, 0x15, 0xfd, 0x06, 0x01, 0x1c, 0xdc,
+0x00, 0x01, 0x0e, 0x01, 0x00, 0x0b, 0x05, 0x59,
+0x08, 0x29, 0x40, 0x21, 0x03, 0x07, 0x48, 0x66,
+0x31
+};
+
/*
* MGCP messages
*/
diff --git a/openbsc/tests/bsc-nat/bsc_nat_test.c b/openbsc/tests/bsc-nat/bsc_nat_test.c
index 8f4e2d152..926c97cd7 100644
--- a/openbsc/tests/bsc-nat/bsc_nat_test.c
+++ b/openbsc/tests/bsc-nat/bsc_nat_test.c
@@ -31,6 +31,7 @@
#include <osmocore/talloc.h>
#include <osmocom/sccp/sccp.h>
+#include <osmocore/protocol/gsm_08_08.h>
#include <stdio.h>
@@ -582,19 +583,19 @@ static struct cr_filter cr_filter[] = {
{
.data = bssmap_cr,
.length = sizeof(bssmap_cr),
- .result = 0,
+ .result = 1,
.contype = NAT_CON_TYPE_CM_SERV_REQ,
},
{
.data = bss_lu,
.length = sizeof(bss_lu),
- .result = 0,
+ .result = 1,
.contype = NAT_CON_TYPE_LU,
},
{
.data = pag_resp,
.length = sizeof(pag_resp),
- .result = 0,
+ .result = 1,
.contype = NAT_CON_TYPE_PAG_RESP,
},
{
@@ -609,7 +610,7 @@ static struct cr_filter cr_filter[] = {
/* BSC allow is before NAT deny */
.data = bss_lu,
.length = sizeof(bss_lu),
- .result = 0,
+ .result = 1,
.nat_imsi_deny = "[0-9]*",
.bsc_imsi_allow = "2440[0-9]*",
.contype = NAT_CON_TYPE_LU,
@@ -618,7 +619,7 @@ static struct cr_filter cr_filter[] = {
/* BSC allow is before NAT deny */
.data = bss_lu,
.length = sizeof(bss_lu),
- .result = 0,
+ .result = 1,
.bsc_imsi_allow = "[0-9]*",
.nat_imsi_deny = "[0-9]*",
.contype = NAT_CON_TYPE_LU,
@@ -696,6 +697,58 @@ static void test_cr_filter()
msgb_free(msg);
}
+static void test_dt_filter()
+{
+ int i;
+ struct msgb *msg = msgb_alloc(4096, "test_dt_filter");
+ struct bsc_nat_parsed *parsed;
+
+ struct bsc_nat *nat = bsc_nat_alloc();
+ struct bsc_connection *bsc = bsc_connection_alloc(nat);
+ struct sccp_connections *con = talloc_zero(0, struct sccp_connections);
+
+ bsc->cfg = bsc_config_alloc(nat, "foo", 23);
+ con->bsc = bsc;
+
+ msgb_reset(msg);
+ copy_to_msg(msg, id_resp, ARRAY_SIZE(id_resp));
+
+ parsed = bsc_nat_parse(msg);
+ if (!parsed) {
+ fprintf(stderr, "FAIL: Could not parse ID resp\n");
+ abort();
+ }
+
+ if (parsed->bssap != BSSAP_MSG_DTAP) {
+ fprintf(stderr, "FAIL: It should be dtap\n");
+ abort();
+ }
+
+ /* gsm_type is actually the size of the dtap */
+ if (parsed->gsm_type < msgb_l3len(msg) - 3) {
+ fprintf(stderr, "FAIL: Not enough space for the content\n");
+ abort();
+ }
+
+ if (bsc_nat_filter_dt(bsc, msg, con, parsed) != 1) {
+ fprintf(stderr, "FAIL: Should have passed..\n");
+ abort();
+ }
+
+ /* just some basic length checking... */
+ for (i = ARRAY_SIZE(id_resp); i >= 0; --i) {
+ msgb_reset(msg);
+ copy_to_msg(msg, id_resp, ARRAY_SIZE(id_resp));
+
+ parsed = bsc_nat_parse(msg);
+ if (!parsed)
+ continue;
+
+ con->imsi_checked = 0;
+ bsc_nat_filter_dt(bsc, msg, con, parsed);
+ }
+}
+
int main(int argc, char **argv)
{
struct log_target *stderr_target;
@@ -714,6 +767,7 @@ int main(int argc, char **argv)
test_mgcp_rewrite();
test_mgcp_parse();
test_cr_filter();
+ test_dt_filter();
return 0;
}