nat: Patch the destination SMS address of a message

Use the same filtering infrasturcture to patch the SMSC
address in a CP-DATA/RP-DATA message. Add a very simple
testcase for this code.
diff --git a/openbsc/tests/bsc-nat/bsc_nat_test.c b/openbsc/tests/bsc-nat/bsc_nat_test.c
index c9432fe..a31efca 100644
--- a/openbsc/tests/bsc-nat/bsc_nat_test.c
+++ b/openbsc/tests/bsc-nat/bsc_nat_test.c
@@ -854,7 +854,7 @@
 	entry.option = "^0([1-9])";
 	entry.text = "0049";
 	llist_add_tail(&entry.list, &entries.entry);
-	bsc_nat_num_rewr_entry_adapt(nat, &entries);
+	bsc_nat_num_rewr_entry_adapt(nat, &nat->num_rewr, &entries);
 
 	/* verify that nothing changed */
 	msgb_reset(msg);
@@ -917,7 +917,7 @@
 
 	/* Make sure that a wildcard is matching */
 	entry.mnc = "*";
-	bsc_nat_num_rewr_entry_adapt(nat, &entries);
+	bsc_nat_num_rewr_entry_adapt(nat, &nat->num_rewr, &entries);
 	msg = msgb_alloc(4096, "test_dt_filter");
 	copy_to_msg(msg, cc_setup_national, ARRAY_SIZE(cc_setup_national));
 	parsed = bsc_nat_parse(msg);
@@ -952,7 +952,7 @@
 
 	/* Make sure that a wildcard is matching */
 	entry.mnc = "09";
-	bsc_nat_num_rewr_entry_adapt(nat, &entries);
+	bsc_nat_num_rewr_entry_adapt(nat, &nat->num_rewr, &entries);
 	msg = msgb_alloc(4096, "test_dt_filter");
 	copy_to_msg(msg, cc_setup_national, ARRAY_SIZE(cc_setup_national));
 	parsed = bsc_nat_parse(msg);
@@ -980,6 +980,49 @@
 	msgb_free(out);
 }
 
+static void test_smsc_rewrite()
+{
+	struct msgb *msg = msgb_alloc(4096, "SMSC rewrite"), *out;
+	struct bsc_nat_parsed *parsed;
+	const char *imsi = "515039900406700";
+
+	struct bsc_nat *nat = bsc_nat_alloc();
+
+	/* a fake list */
+	struct osmo_config_list entries;
+	struct osmo_config_entry entry;
+
+	INIT_LLIST_HEAD(&entries.entry);
+	entry.mcc = "^515039";
+	entry.option = "639180000105()";
+	entry.text   = "6666666666667";
+	llist_add_tail(&entry.list, &entries.entry);
+	bsc_nat_num_rewr_entry_adapt(nat, &nat->smsc_rewr, &entries);
+
+	copy_to_msg(msg, smsc_rewrite, ARRAY_SIZE(smsc_rewrite));
+	parsed = bsc_nat_parse(msg);
+	if (!parsed) {
+		fprintf(stderr, "FAIL: Could not parse SMS\n");
+		abort();
+	}
+
+	out = bsc_nat_rewrite_msg(nat, msg, parsed, imsi);
+	if (out == msg) {
+		fprintf(stderr, "FAIL: This should have changed.\n");
+		abort();
+	}
+
+	if (out->len != ARRAY_SIZE(smsc_rewrite_patched)) {
+		fprintf(stderr, "FAIL: The size should match.\n");
+		abort();
+	}
+
+	if (memcmp(out->data, smsc_rewrite_patched, out->len) != 0) {
+		fprintf(stderr, "FAIL: the data should be changed.\n");
+		abort();
+	}
+}
+
 int main(int argc, char **argv)
 {
 	sccp_set_log_area(DSCCP);
@@ -995,6 +1038,7 @@
 	test_cr_filter();
 	test_dt_filter();
 	test_setup_rewrite();
+	test_smsc_rewrite();
 	test_mgcp_allocations();
 	return 0;
 }