From a914daf174e9d1a78bdccb1d5bd8b69ec8ff2280 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Thu, 21 Oct 2010 12:12:57 +0200 Subject: [PATCH] nat: Add hook for rewriting a setup message Create a new function, hand the data to this function, take back a possible modified msgb and invalidate parsed at this point. --- openbsc/include/openbsc/bsc_nat.h | 2 ++ openbsc/src/nat/bsc_nat.c | 12 +++++++++++- openbsc/src/nat/bsc_nat_utils.c | 7 +++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/openbsc/include/openbsc/bsc_nat.h b/openbsc/include/openbsc/bsc_nat.h index 083746f68..049421716 100644 --- a/openbsc/include/openbsc/bsc_nat.h +++ b/openbsc/include/openbsc/bsc_nat.h @@ -343,4 +343,6 @@ struct gsm48_hdr *bsc_unpack_dtap(struct bsc_nat_parsed *parsed, struct msgb *ms int bsc_ussd_init(struct bsc_nat *nat); int bsc_check_ussd(struct sccp_connections *con, struct bsc_nat_parsed *parsed, struct msgb *msg); +struct msgb *bsc_nat_rewrite_setup(struct bsc_nat *nat, struct msgb *msg, struct bsc_nat_parsed *); + #endif diff --git a/openbsc/src/nat/bsc_nat.c b/openbsc/src/nat/bsc_nat.c index daabf0976..dcacfb9ab 100644 --- a/openbsc/src/nat/bsc_nat.c +++ b/openbsc/src/nat/bsc_nat.c @@ -858,6 +858,15 @@ static int forward_sccp_to_msc(struct bsc_connection *bsc, struct msgb *msg) /* hand data to a side channel */ if (bsc_check_ussd(con, parsed, msg) == 1) con->con_local = 2; + + /* + * Optionally rewrite setup message. This can + * replace the msg and the parsed structure becomes + * invalid. + */ + msg = bsc_nat_rewrite_setup(bsc->nat, msg, parsed); + talloc_free(parsed); + parsed = NULL; } con_bsc = con->bsc; @@ -913,7 +922,8 @@ static int forward_sccp_to_msc(struct bsc_connection *bsc, struct msgb *msg) /* send the non-filtered but maybe modified msg */ queue_for_msc(con_msc, msg); - talloc_free(parsed); + if (parsed) + talloc_free(parsed); return 0; exit: diff --git a/openbsc/src/nat/bsc_nat_utils.c b/openbsc/src/nat/bsc_nat_utils.c index 0cef01b24..a3fd97aaf 100644 --- a/openbsc/src/nat/bsc_nat_utils.c +++ b/openbsc/src/nat/bsc_nat_utils.c @@ -721,3 +721,10 @@ int bsc_write_cb(struct bsc_fd *bfd, struct msgb *msg) return rc; } +/** + * Rewrite non global numbers... according to rules based on the IMSI + */ +struct msgb *bsc_nat_rewrite_setup(struct bsc_nat *nat, struct msgb *msg, struct bsc_nat_parsed *pa) +{ + return msg; +}