aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc/src/libmgcp/mgcp_protocol.c
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@soleta.eu>2014-08-27 17:02:52 +0200
committerPablo Neira Ayuso <pablo@soleta.eu>2014-08-28 12:08:29 +0200
commitb769f3ce0bc1bf88f907856182f9fc6f871bbfef (patch)
tree34286cb9da1c64806be22fc93990c7d7e1264724 /openbsc/src/libmgcp/mgcp_protocol.c
parent8be171e88f2a64c29f93cf325945a7b5156b87ec (diff)
osmux: add osmux circuit ID management and resolve NAT problems
This patch includes several osmux fixes that are interdependent: 1) This adds Osmux circuit ID, this is allocated from the bsc-nat. This announces the circuit ID in the CRCX MGCP message. This aims to resolve the lack of uniqueness due to the use of endp->ci, which is local to the bsc. This ID is notified via X-Osmux: NUM where NUM is the osmux circuit ID. 2) The dummy load routines are now used to setup osmux both in bsc and bsc-nat to resolve source port NAT issues as suggested by Holger. The source port that is used from the bsc is not known until the first voice message is sent to the bsc-nat, therefore enabling osmux from the MGCP plane breaks when a different source port is used. 3) Add refcnt to struct osmux_handle, several endpoints can be using the same input RTP osmux handle to perform the batching. Remove it from the osmux handle list once nobody is using it anymore to clean it up. 4) Add a simple Osmux state-machine with three states. The initial state is disabled, then if the bsc-nat requests Osmux, both sides enters activating. The final enabled state is reached once the bsc-nat sees the dummy load message that tells what source port is used by the bsc. 5) The osmux input handle (which transforms RTP messages to one Osmux batch) is now permanently attached to the endpoint when Osmux is set up from the dummy load path, so we skip a lookup for each message. This simplifies osmux_xfrm_to_osmux(). After this patch, the workflow to setup Osmux is the following: bsc bsc-nat | | |<------ CRCX ----------| | X-Osmux: 3 | (where 3 is the Osmux circuit ID | | that the bsc-nat has allocated) |------- resp --------->| | X-Osmux: 3 | (the bsc confirm that it can | | use Osmux). . . | | setup osmux |----- dummy load ----->| setup osmux | Osmux CID: 3 | In two steps: 1st) Allocate the Osmux Circuit ID (CID): The bsc-nat allocates an unique Osmux CID that is notified to the bsc through the 'X-Osmux:' extension. The bsc-nat annotates this circuit ID in the endpoint object. The bsc replies back with the 'X-Osmux:' to confirm that it agrees to use Osmux. If the bsc doesn't want to use Osmux, it doesn't include the extension so the bsc-nat knows that it has to use to RTP. 2nd) The dummy load is used to convey the Osmux CID. This needs to happen at this stage since the bsc-nat needs to know what source port the bsc uses to get this working since the bsc may use a different source port due to NAT. Unfortunately, this can't be done from the MGCP signal plane since the real source port is not known that the bsc uses is not known. This patch also reverts the MDCX handling until it is clear that we need this special handling for this case.
Diffstat (limited to 'openbsc/src/libmgcp/mgcp_protocol.c')
-rw-r--r--openbsc/src/libmgcp/mgcp_protocol.c83
1 files changed, 47 insertions, 36 deletions
diff --git a/openbsc/src/libmgcp/mgcp_protocol.c b/openbsc/src/libmgcp/mgcp_protocol.c
index 0681c1038..db8354abf 100644
--- a/openbsc/src/libmgcp/mgcp_protocol.c
+++ b/openbsc/src/libmgcp/mgcp_protocol.c
@@ -320,16 +320,18 @@ static struct msgb *create_response_with_sdp(struct mgcp_endpoint *endp,
char sdp_record[4096];
int len;
int nchars;
+ char osmux_extension[strlen("\nX-Osmux: 255") + 1];
if (!addr)
addr = endp->cfg->source_addr;
- len = snprintf(sdp_record, sizeof(sdp_record),
- "I: %u%s\n\n",
- endp->ci,
- endp->cfg->osmux && endp->osmux.enable ?
- "\nX-Osmux: On" : "");
+ if (endp->osmux.state == OSMUX_STATE_ACTIVATING)
+ sprintf(osmux_extension, "\nX-Osmux: %u", endp->osmux.cid);
+ else
+ osmux_extension[0] = '\0';
+ len = snprintf(sdp_record, sizeof(sdp_record),
+ "I: %u%s\n\n", endp->ci, osmux_extension);
if (len < 0)
return NULL;
@@ -347,7 +349,7 @@ static struct msgb *create_response_with_sdp(struct mgcp_endpoint *endp,
static void send_dummy(struct mgcp_endpoint *endp)
{
- if (endp->osmux.enable)
+ if (endp->osmux.state != OSMUX_STATE_DISABLED)
osmux_send_dummy(endp);
else
mgcp_send_dummy(endp);
@@ -879,7 +881,22 @@ uint32_t mgcp_rtp_packet_duration(struct mgcp_endpoint *endp,
return rtp->rate * f * rtp->frame_duration_num / rtp->frame_duration_den;
}
-static int mgcp_osmux_setup(struct mgcp_endpoint *endp)
+static int mgcp_parse_osmux_cid(const char *line)
+{
+ uint32_t osmux_cid;
+
+ sscanf(line + 2, "Osmux: %u", &osmux_cid);
+ if (osmux_cid > OSMUX_CID_MAX) {
+ LOGP(DMGCP, LOGL_ERROR, "Osmux ID too large: %u > %u\n",
+ osmux_cid, OSMUX_CID_MAX);
+ return -1;
+ }
+ LOGP(DMGCP, LOGL_DEBUG, "bsc-nat offered Osmux CID %u\n", osmux_cid);
+
+ return osmux_cid;
+}
+
+static int mgcp_osmux_setup(struct mgcp_endpoint *endp, const char *line)
{
if (!endp->cfg->osmux_init) {
if (osmux_init(OSMUX_ROLE_BSC, endp->cfg) < 0) {
@@ -889,12 +906,7 @@ static int mgcp_osmux_setup(struct mgcp_endpoint *endp)
LOGP(DMGCP, LOGL_NOTICE, "OSMUX socket has been set up\n");
}
- if (osmux_enable_endpoint(endp, OSMUX_ROLE_BSC) < 0) {
- LOGP(DMGCP, LOGL_ERROR,
- "Could not activate Osmux in endpoint %d\n",
- ENDPOINT_NUMBER(endp));
- }
- return 0;
+ return mgcp_parse_osmux_cid(line);
}
static struct msgb *handle_create_con(struct mgcp_parse_data *p)
@@ -907,7 +919,7 @@ static struct msgb *handle_create_con(struct mgcp_parse_data *p)
const char *callid = NULL;
const char *mode = NULL;
char *line;
- int have_sdp = 0;
+ int have_sdp = 0, osmux_cid = -1;
if (p->found != 0)
return create_err_response(NULL, 510, "CRCX", p->trans);
@@ -928,8 +940,14 @@ static struct msgb *handle_create_con(struct mgcp_parse_data *p)
mode = (const char *) line + 3;
break;
case 'X':
- if (strcmp("Osmux: on", line + 2) == 0)
- mgcp_osmux_setup(endp);
+ /* Osmux is not enabled in this bsc, ignore it so the
+ * bsc-nat knows that we don't want to use Osmux.
+ */
+ if (!p->endp->cfg->osmux)
+ break;
+
+ if (strncmp("Osmux: ", line + 2, strlen("Osmux: ")) == 0)
+ osmux_cid = mgcp_osmux_setup(endp, line);
break;
case '\0':
have_sdp = 1;
@@ -993,6 +1011,15 @@ mgcp_header_done:
if (endp->ci == CI_UNUSED)
goto error2;
+ /* Annotate Osmux circuit ID and set it to activating state until this
+ * is fully set up from the dummy load.
+ */
+ endp->osmux.state = OSMUX_STATE_DISABLED;
+ if (osmux_cid >= 0) {
+ endp->osmux.cid = osmux_cid;
+ endp->osmux.state = OSMUX_STATE_ACTIVATING;
+ }
+
endp->allocated = 1;
/* set up RTP media parameters */
@@ -1057,7 +1084,7 @@ static struct msgb *handle_modify_con(struct mgcp_parse_data *p)
{
struct mgcp_endpoint *endp = p->endp;
int error_code = 500;
- int silent = 0, osmux = 0;
+ int silent = 0;
int have_sdp = 0;
char *line;
const char *local_options = NULL;
@@ -1096,10 +1123,6 @@ static struct msgb *handle_modify_con(struct mgcp_parse_data *p)
}
endp->orig_mode = endp->conn_mode;
break;
- case 'X':
- if (strcmp("Osmux: on", line + 2) == 0)
- osmux = 1;
- break;
case 'Z':
silent = strcmp("noanswer", line + 3) == 0;
break;
@@ -1118,21 +1141,6 @@ static struct msgb *handle_modify_con(struct mgcp_parse_data *p)
}
}
- /* Re-enable Osmux if we receive a MDCX, we have to set up a new
- * RTP flow: this generates a randomly allocated RTP SSRC and sequence
- * number.
- */
- if (osmux) {
- if (osmux_enable_endpoint(endp, OSMUX_ROLE_BSC) < 0) {
- LOGP(DMGCP, LOGL_ERROR,
- "Could not update osmux in endpoint %d\n",
- ENDPOINT_NUMBER(endp));
- }
- LOGP(DMGCP, LOGL_NOTICE,
- "Re-enabling osmux in endpoint %d, we got updated\n",
- ENDPOINT_NUMBER(endp));
- }
-
set_local_cx_options(endp->tcfg->endpoints, &endp->local_options,
local_options);
@@ -1528,6 +1536,9 @@ void mgcp_release_endp(struct mgcp_endpoint *endp)
endp->conn_mode = endp->orig_mode = MGCP_CONN_NONE;
+ if (endp->osmux.state == OSMUX_STATE_ENABLED)
+ osmux_disable_endpoint(endp);
+
memset(&endp->taps, 0, sizeof(endp->taps));
}