aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2011-08-30 16:36:44 +0200
committerHolger Hans Peter Freyther <zecke@selfish.org>2011-08-30 16:36:44 +0200
commitdc75669e42d561d0526b53f7cb2054b56ba93abf (patch)
tree5c2c817458086f8881689b8b3b984500ee55c742
parent1650d5d50b0282af51b6e6929cc955cf99852c96 (diff)
mgcp: Add a per BSC option to use compression or not use it.
-rw-r--r--openbsc/include/openbsc/bsc_nat.h5
-rw-r--r--openbsc/src/osmo-bsc_nat/bsc_mgcp_utils.c20
-rw-r--r--openbsc/src/osmo-bsc_nat/bsc_nat_vty.c13
-rw-r--r--openbsc/src/osmo-bsc_nat/bsc_ussd.c2
-rw-r--r--openbsc/tests/bsc-nat/bsc_data.c9
-rw-r--r--openbsc/tests/bsc-nat/bsc_nat_test.c3
6 files changed, 46 insertions, 6 deletions
diff --git a/openbsc/include/openbsc/bsc_nat.h b/openbsc/include/openbsc/bsc_nat.h
index 6680614a9..9dd489038 100644
--- a/openbsc/include/openbsc/bsc_nat.h
+++ b/openbsc/include/openbsc/bsc_nat.h
@@ -169,6 +169,9 @@ struct bsc_config {
struct bsc_config_stats stats;
struct llist_head lac_list;
+
+ /* compr */
+ int allow_compr;
};
struct bsc_lac_entry {
@@ -382,7 +385,7 @@ void bsc_mgcp_free_endpoints(struct bsc_nat *nat);
int bsc_mgcp_nat_init(struct bsc_nat *nat);
struct sccp_connections *bsc_mgcp_find_con(struct bsc_nat *, int endpoint_number);
-struct msgb *bsc_mgcp_rewrite(char *input, int length, int endp, const char *ip, int port);
+struct msgb *bsc_mgcp_rewrite(char *input, int length, int endp, const char *ip, int port, int allow_compr);
void bsc_mgcp_forward(struct bsc_connection *bsc, struct msgb *msg);
void bsc_mgcp_clear_endpoints_for(struct bsc_connection *bsc);
diff --git a/openbsc/src/osmo-bsc_nat/bsc_mgcp_utils.c b/openbsc/src/osmo-bsc_nat/bsc_mgcp_utils.c
index 9ac54dabe..ddeb2413c 100644
--- a/openbsc/src/osmo-bsc_nat/bsc_mgcp_utils.c
+++ b/openbsc/src/osmo-bsc_nat/bsc_mgcp_utils.c
@@ -339,7 +339,8 @@ int bsc_mgcp_policy_cb(struct mgcp_trunk_config *tcfg, int endpoint, int state,
/* we need to generate a new and patched message */
bsc_msg = bsc_mgcp_rewrite((char *) nat->mgcp_msg, nat->mgcp_length, sccp->bsc_endp,
- nat->mgcp_cfg->source_addr, mgcp_endp->bts_end.local_port);
+ nat->mgcp_cfg->source_addr, mgcp_endp->bts_end.local_port,
+ sccp->bsc->cfg->allow_compr);
if (!bsc_msg) {
LOGP(DMGCP, LOGL_ERROR, "Failed to patch the msg.\n");
return MGCP_POLICY_CONT;
@@ -471,7 +472,8 @@ void bsc_mgcp_forward(struct bsc_connection *bsc, struct msgb *msg)
* with the value of 0 should be no problem.
*/
output = bsc_mgcp_rewrite((char * ) msg->l2h, msgb_l2len(msg), -1,
- bsc->nat->mgcp_cfg->source_addr, endp->net_end.local_port);
+ bsc->nat->mgcp_cfg->source_addr, endp->net_end.local_port,
+ bsc->cfg->allow_compr);
if (!output) {
LOGP(DMGCP, LOGL_ERROR, "Failed to rewrite MGCP msg.\n");
@@ -523,7 +525,8 @@ static void patch_mgcp(struct msgb *output, const char *op, const char *tok,
}
/* we need to replace some strings... */
-struct msgb *bsc_mgcp_rewrite(char *input, int length, int endpoint, const char *ip, int port)
+struct msgb *bsc_mgcp_rewrite(char *input, int length, int endpoint,
+ const char *ip, int port, int allow_compr)
{
static const char *crcx_str = "CRCX ";
static const char *dlcx_str = "DLCX ";
@@ -535,6 +538,7 @@ struct msgb *bsc_mgcp_rewrite(char *input, int length, int endpoint, const char
char buf[128];
char *running, *token;
struct msgb *output;
+ int is_crcx;
if (length > 4096 - 128) {
LOGP(DMGCP, LOGL_ERROR, "Input is too long.\n");
@@ -555,11 +559,21 @@ struct msgb *bsc_mgcp_rewrite(char *input, int length, int endpoint, const char
int cr = len > 0 && token[len - 1] == '\r';
if (strncmp(crcx_str, token, (sizeof crcx_str) - 1) == 0) {
+ is_crcx = 1;
patch_mgcp(output, "CRCX", token, endpoint, len, cr);
} else if (strncmp(dlcx_str, token, (sizeof dlcx_str) - 1) == 0) {
patch_mgcp(output, "DLCX", token, endpoint, len, cr);
} else if (strncmp(mdcx_str, token, (sizeof mdcx_str) - 1) == 0) {
patch_mgcp(output, "MDCX", token, endpoint, len, cr);
+ } else if (strncmp("C:", token, 2) == 0 && is_crcx && allow_compr) {
+ output->l3h = msgb_put(output, len + 1);
+ memcpy(output->l3h, token, len);
+ output->l3h[len] = '\n';
+
+ snprintf(buf, sizeof(buf) - 1,
+ "X-ow-encr: 1%s", cr ? "\r\n" : "\n");
+ output->l3h = msgb_put(output, strlen(buf));
+ memcpy(output->l3h, buf, strlen(buf));
} else if (strncmp(ip_str, token, (sizeof ip_str) - 1) == 0) {
output->l3h = msgb_put(output, strlen(ip_str));
memcpy(output->l3h, ip_str, strlen(ip_str));
diff --git a/openbsc/src/osmo-bsc_nat/bsc_nat_vty.c b/openbsc/src/osmo-bsc_nat/bsc_nat_vty.c
index 55b3958c0..78b19558b 100644
--- a/openbsc/src/osmo-bsc_nat/bsc_nat_vty.c
+++ b/openbsc/src/osmo-bsc_nat/bsc_nat_vty.c
@@ -149,6 +149,8 @@ static void config_write_bsc_single(struct vty *vty, struct bsc_config *bsc)
if (bsc->paging_group != -1)
vty_out(vty, " paging group %d%s", bsc->paging_group, VTY_NEWLINE);
vty_out(vty, " paging forbidden %d%s", bsc->forbid_paging, VTY_NEWLINE);
+ if (bsc->allow_compr)
+ vty_out(vty, " allow-compression allow%s", VTY_NEWLINE);
}
static int config_write_bsc(struct vty *vty)
@@ -790,6 +792,16 @@ DEFUN(cfg_bsc_no_paging_grp,
return CMD_SUCCESS;
}
+DEFUN(cfg_bsc_allow_compr,
+ cfg_bsc_allow_compr_cmd,
+ "allow-compression (forbid|allow)",
+ "Allow RTP compression for this BSC\n" "Forbid\n" "Allow\n")
+{
+ struct bsc_config *conf = vty->index;
+ conf->allow_compr = argv[0][0] == 'a' ? 1 : 0;
+ return CMD_SUCCESS;
+}
+
DEFUN(test_regex, test_regex_cmd,
"test regex PATTERN STRING",
"Check if the string is matching the current pattern.")
@@ -983,6 +995,7 @@ int bsc_nat_vty_init(struct bsc_nat *nat)
install_element(NAT_BSC_NODE, &cfg_bsc_old_grp_cmd);
install_element(NAT_BSC_NODE, &cfg_bsc_paging_grp_cmd);
install_element(NAT_BSC_NODE, &cfg_bsc_no_paging_grp_cmd);
+ install_element(NAT_BSC_NODE, &cfg_bsc_allow_compr_cmd);
mgcp_vty_init();
diff --git a/openbsc/src/osmo-bsc_nat/bsc_ussd.c b/openbsc/src/osmo-bsc_nat/bsc_ussd.c
index bbbeead9a..1bae02c75 100644
--- a/openbsc/src/osmo-bsc_nat/bsc_ussd.c
+++ b/openbsc/src/osmo-bsc_nat/bsc_ussd.c
@@ -386,7 +386,7 @@ int bsc_check_ussd(struct sccp_connections *con, struct bsc_nat_parsed *parsed,
return 0;
if (regexec(&con->bsc->nat->ussd_query_re,
- req.text, 0, NULL, 0) == REG_NOMATCH)
+ (const char *) req.text, 0, NULL, 0) == REG_NOMATCH)
return 0;
/* found a USSD query for our subscriber */
diff --git a/openbsc/tests/bsc-nat/bsc_data.c b/openbsc/tests/bsc-nat/bsc_data.c
index 8a06348fd..974a2b809 100644
--- a/openbsc/tests/bsc-nat/bsc_data.c
+++ b/openbsc/tests/bsc-nat/bsc_data.c
@@ -125,6 +125,7 @@ static const uint8_t smsc_rewrite_patched[] = {
/* nothing to patch */
static const char crcx[] = "CRCX 23265295 8@mgw MGCP 1.0\r\nC: 394b0439fb\r\nL: p:20, a:AMR, nt:IN\r\nM: recvonly\r\n";
static const char crcx_patched[] = "CRCX 23265295 1e@mgw MGCP 1.0\r\nC: 394b0439fb\r\nL: p:20, a:AMR, nt:IN\r\nM: recvonly\r\n";
+static const char crcx_patched_compr[] = "CRCX 23265295 1e@mgw MGCP 1.0\r\nC: 394b0439fb\r\nX-ow-encr: 1\r\nL: p:20, a:AMR, nt:IN\r\nM: recvonly\r\n";
/* patch the ip and port */
@@ -148,6 +149,7 @@ struct mgcp_patch_test {
const char *patch;
const char *ip;
const int port;
+ int allow_compr;
};
static const struct mgcp_patch_test mgcp_messages[] = {
@@ -158,6 +160,13 @@ static const struct mgcp_patch_test mgcp_messages[] = {
.port = 2323,
},
{
+ .orig = crcx,
+ .patch = crcx_patched_compr,
+ .ip = "0.0.0.0",
+ .port = 2323,
+ .allow_compr = 1,
+ },
+ {
.orig = crcx_resp,
.patch = crcx_resp_patched,
.ip = "10.0.0.1",
diff --git a/openbsc/tests/bsc-nat/bsc_nat_test.c b/openbsc/tests/bsc-nat/bsc_nat_test.c
index d6105adb8..119d4b584 100644
--- a/openbsc/tests/bsc-nat/bsc_nat_test.c
+++ b/openbsc/tests/bsc-nat/bsc_nat_test.c
@@ -581,10 +581,11 @@ static void test_mgcp_rewrite(void)
const char *patc = mgcp_messages[i].patch;
const char *ip = mgcp_messages[i].ip;
const int port = mgcp_messages[i].port;
+ int compr = mgcp_messages[i].allow_compr;
char *input = strdup(orig);
- output = bsc_mgcp_rewrite(input, strlen(input), 0x1e, ip, port);
+ output = bsc_mgcp_rewrite(input, strlen(input), 0x1e, ip, port, compr);
if (msgb_l2len(output) != strlen(patc)) {
fprintf(stderr, "Wrong sizes for test: %d %d != %d != %d\n", i, msgb_l2len(output), strlen(patc), strlen(orig));
fprintf(stderr, "String '%s' vs '%s'\n", (const char *) output->l2h, patc);