diff options
Diffstat (limited to 'openbsc')
-rw-r--r-- | openbsc/src/nat/bsc_mgcp_utils.c | 22 | ||||
-rw-r--r-- | openbsc/tests/bsc-nat/bsc_data.c | 10 |
2 files changed, 23 insertions, 9 deletions
diff --git a/openbsc/src/nat/bsc_mgcp_utils.c b/openbsc/src/nat/bsc_mgcp_utils.c index 164b6f64c..2b28305a8 100644 --- a/openbsc/src/nat/bsc_mgcp_utils.c +++ b/openbsc/src/nat/bsc_mgcp_utils.c @@ -277,21 +277,24 @@ struct msgb *bsc_mgcp_rewrite(char *input, int length, const char *ip, int port) running = input; output->l2h = output->data; - for (token = strsep(&running, "\n"); token; token = strsep(&running, "\n")) { + for (token = strsep(&running, "\n"); running; token = strsep(&running, "\n")) { int len = strlen(token); - - /* ignore completely empty lines for now */ - if (len == 0) - continue; + int cr = len > 0 && token[len - 1] == '\r'; 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)); output->l3h = msgb_put(output, strlen(ip)); memcpy(output->l3h, ip, strlen(ip)); - output->l3h = msgb_put(output, 2); - output->l3h[0] = '\r'; - output->l3h[1] = '\n'; + + if (cr) { + output->l3h = msgb_put(output, 2); + output->l3h[0] = '\r'; + output->l3h[1] = '\n'; + } else { + output->l3h = msgb_put(output, 1); + output->l3h[0] = '\n'; + } } else if (strncmp(aud_str, token, (sizeof aud_str) - 1) == 0) { int payload; if (sscanf(token, "m=audio %*d RTP/AVP %d", &payload) != 1) { @@ -300,7 +303,8 @@ struct msgb *bsc_mgcp_rewrite(char *input, int length, const char *ip, int port) return NULL; } - snprintf(buf, sizeof(buf)-1, "m=audio %d RTP/AVP %d\r\n", port, payload); + snprintf(buf, sizeof(buf)-1, "m=audio %d RTP/AVP %d%s", + port, payload, cr ? "\r\n" : "\n"); buf[sizeof(buf)-1] = '\0'; output->l3h = msgb_put(output, strlen(buf)); diff --git a/openbsc/tests/bsc-nat/bsc_data.c b/openbsc/tests/bsc-nat/bsc_data.c index 28d506466..34242db8c 100644 --- a/openbsc/tests/bsc-nat/bsc_data.c +++ b/openbsc/tests/bsc-nat/bsc_data.c @@ -109,6 +109,10 @@ static const char mdcx_patched[] = " MDCX 23330829 8@mgw MGCP 1.0\r\nC: 394b0439 static const char mdcx_resp[] = "200 23330829\r\n\r\nv=0\r\nc=IN IP4 172.16.18.2\r\nm=audio 4002 RTP/AVP 98\r\na=rtpmap:98 AMR/8000\r\n"; static const char mdcx_resp_patched[] = "200 23330829\r\n\r\nv=0\r\nc=IN IP4 10.0.0.23\r\nm=audio 5555 RTP/AVP 98\r\na=rtpmap:98 AMR/8000\r\n"; +/* different line ending */ +static const char mdcx_resp2[] = "200 33330829\n\nv=0\nc=IN IP4 172.16.18.2\nm=audio 4002 RTP/AVP 98\na=rtpmap:98 AMR/8000\n"; +static const char mdcx_resp_patched2[] = "200 33330829\n\nv=0\nc=IN IP4 10.0.0.23\nm=audio 5555 RTP/AVP 98\na=rtpmap:98 AMR/8000\n"; + struct mgcp_patch_test { const char *orig; const char *patch; @@ -141,4 +145,10 @@ static const struct mgcp_patch_test mgcp_messages[] = { .ip = "10.0.0.23", .port = 5555, }, + { + .orig = mdcx_resp2, + .patch = mdcx_resp_patched2, + .ip = "10.0.0.23", + .port = 5555, + }, }; |