aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2010-09-29 02:30:50 +0800
committerHolger Hans Peter Freyther <zecke@selfish.org>2010-10-21 12:23:27 +0200
commita3967579f8b290d19030f10aeb9c1c827bbf263c (patch)
tree0018903d41525ac5db4193069cbfd13d05757d8b
parent749497eeb3cae13fa2252abcf93468ecd415f063 (diff)
nat: Move the DTAP unpacking into a new method
DTAP unpacking will be used by the USSD checking code
-rw-r--r--openbsc/include/openbsc/bsc_nat.h3
-rw-r--r--openbsc/src/nat/bsc_nat_utils.c34
2 files changed, 24 insertions, 13 deletions
diff --git a/openbsc/include/openbsc/bsc_nat.h b/openbsc/include/openbsc/bsc_nat.h
index 6fc0e650..b6d04043 100644
--- a/openbsc/include/openbsc/bsc_nat.h
+++ b/openbsc/include/openbsc/bsc_nat.h
@@ -32,6 +32,7 @@
#include <osmocore/write_queue.h>
#include <osmocore/rate_ctr.h>
#include <osmocore/statistics.h>
+#include <osmocore/protocol/gsm_04_08.h>
#include <regex.h>
@@ -315,4 +316,6 @@ int bsc_nat_msc_is_connected(struct bsc_nat *nat);
int bsc_conn_type_to_ctr(struct sccp_connections *conn);
+struct gsm48_hdr *bsc_unpack_dtap(struct bsc_nat_parsed *parsed, struct msgb *msg, uint32_t *len);
+
#endif
diff --git a/openbsc/src/nat/bsc_nat_utils.c b/openbsc/src/nat/bsc_nat_utils.c
index 674de418..dc18cffe 100644
--- a/openbsc/src/nat/bsc_nat_utils.c
+++ b/openbsc/src/nat/bsc_nat_utils.c
@@ -549,6 +549,25 @@ int bsc_nat_filter_sccp_cr(struct bsc_connection *bsc, struct msgb *msg,
}
}
+struct gsm48_hdr *bsc_unpack_dtap(struct bsc_nat_parsed *parsed,
+ struct msgb *msg, uint32_t *len)
+{
+ /* gsm_type is actually the size of the dtap */
+ *len = parsed->gsm_type;
+ if (*len < msgb_l3len(msg) - 3) {
+ LOGP(DNAT, LOGL_ERROR, "Not enough space for DTAP.\n");
+ return NULL;
+ }
+
+ if (*len < sizeof(struct gsm48_hdr)) {
+ LOGP(DNAT, LOGL_ERROR, "GSM48 header does not fit.\n");
+ return NULL;
+ }
+
+ msg->l4h = &msg->l3h[3];
+ return (struct gsm48_hdr *) msg->l4h;
+}
+
int bsc_nat_filter_dt(struct bsc_connection *bsc, struct msgb *msg,
struct sccp_connections *con, struct bsc_nat_parsed *parsed)
{
@@ -563,20 +582,9 @@ int bsc_nat_filter_dt(struct bsc_connection *bsc, struct msgb *msg,
if (parsed->bssap != BSSAP_MSG_DTAP)
return 0;
- /* gsm_type is actually the size of the dtap */
- len = parsed->gsm_type;
- if (len < msgb_l3len(msg) - 3) {
- LOGP(DNAT, LOGL_ERROR, "Not enough space for DTAP.\n");
+ hdr48 = bsc_unpack_dtap(parsed, msg, &len);
+ if (!hdr48)
return -1;
- }
-
- if (len < sizeof(*hdr48)) {
- LOGP(DNAT, LOGL_ERROR, "GSM48 header does not fit.\n");
- return -1;
- }
-
- msg->l4h = &msg->l3h[3];
- hdr48 = (struct gsm48_hdr *) msg->l4h;
msg_type = hdr48->msg_type & 0xbf;
if (hdr48->proto_discr == GSM48_PDISC_MM &&