aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc/src/nat/bsc_nat.c
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2010-01-29 06:27:21 +0100
committerHolger Hans Peter Freyther <zecke@selfish.org>2010-01-30 10:33:07 +0100
commit55b4f5cc2e7fd8d97547f2ee4db3a925428e9c25 (patch)
tree2db9fda797ef6e90ccc1f8a7cfd7b3e473fb4e88 /openbsc/src/nat/bsc_nat.c
parent1ac5ac75a9b15d8a1cea8bf852853eb336ba68fa (diff)
[nat] Prepare more sophisicated filtering and patching
Introduce a bsc_nat_parse method to parse a IP Access method into various parts. Write out the IPA Proto, in case SCCP is used, store the msg type, pointers to the source/dest local reference and other information. Use the result of bsc_nat_parse inside the bsc_nat_filter method to decide if the message should be dropped or not. In the future the bsc_nat_parse result will be used for patching SCCP references and other parts of the message. The filter language should be able to filter the msg type of SCCP messages and gain the "NOT" word in the filter language.
Diffstat (limited to 'openbsc/src/nat/bsc_nat.c')
-rw-r--r--openbsc/src/nat/bsc_nat.c35
1 files changed, 27 insertions, 8 deletions
diff --git a/openbsc/src/nat/bsc_nat.c b/openbsc/src/nat/bsc_nat.c
index 96444884c..609a17d96 100644
--- a/openbsc/src/nat/bsc_nat.c
+++ b/openbsc/src/nat/bsc_nat.c
@@ -102,13 +102,18 @@ static void initialize_msc_if_needed()
static void forward_sccp_to_bts(struct msgb *msg)
{
struct bsc_connection *bsc;
+ struct bsc_nat_parsed *parsed;
int rc;
/* filter, drop, patch the message? */
-
- /* drop packets with the wrong IPA header */
- if (bsc_nat_filter_ipa(msg))
+ parsed = bsc_nat_parse(msg);
+ if (!parsed) {
+ LOGP(DNAT, LOGL_ERROR, "Can not parse msg from BSC.\n");
return;
+ }
+
+ if (bsc_nat_filter_ipa(msg, parsed))
+ goto exit;
/* currently send this to every BSC connected */
llist_for_each_entry(bsc, &bsc_connections, list_entry) {
@@ -118,6 +123,9 @@ static void forward_sccp_to_bts(struct msgb *msg)
if (rc < msg->len)
LOGP(DNAT, LOGL_ERROR, "Failed to write message to BTS: %d\n", rc);
}
+
+exit:
+ talloc_free(parsed);
}
static int ipaccess_msc_cb(struct bsc_fd *bfd, unsigned int what)
@@ -171,14 +179,25 @@ static void remove_bsc_connection(struct bsc_connection *connection)
static int forward_sccp_to_msc(struct msgb *msg)
{
- /* FIXME: We need to filter out certain messages */
+ struct bsc_nat_parsed *parsed;
+ int rc = -1;
- /* drop packets with the wrong IPA header */
- if (bsc_nat_filter_ipa(msg))
- return 0;
+ /* Parse and filter messages */
+ parsed = bsc_nat_parse(msg);
+ if (!parsed) {
+ LOGP(DNAT, LOGL_ERROR, "Can not parse msg from BSC.\n");
+ return -1;
+ }
+
+ if (bsc_nat_filter_ipa(msg, parsed))
+ goto exit;
/* send the non-filtered but maybe modified msg */
- return write(msc_connection.fd, msg->data, msg->len);
+ rc = write(msc_connection.fd, msg->data, msg->len);
+
+exit:
+ talloc_free(parsed);
+ return rc;
}
static int ipaccess_bsc_cb(struct bsc_fd *bfd, unsigned int what)