aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2010-08-05 03:37:22 +0800
committerHolger Hans Peter Freyther <zecke@selfish.org>2010-08-05 06:10:58 +0800
commitc49212778f84736f1cc59fccf7946595c629ed91 (patch)
tree8345d1c5ce33c0b94a7c0f825f5524df0ed3e064
parentbb89aa1430872598cec1f2508cefd040efaefc87 (diff)
mgcp: Move the bfd for rtp/rtcp into the port
Stop using the memset in the mgcp_rtp_end_reset as we will reset the list pointers and then have a mess..
-rw-r--r--openbsc/include/openbsc/mgcp_internal.h14
-rw-r--r--openbsc/src/mgcp/mgcp_network.c40
-rw-r--r--openbsc/src/mgcp/mgcp_protocol.c17
3 files changed, 38 insertions, 33 deletions
diff --git a/openbsc/include/openbsc/mgcp_internal.h b/openbsc/include/openbsc/mgcp_internal.h
index 7f999a35..357f3bf8 100644
--- a/openbsc/include/openbsc/mgcp_internal.h
+++ b/openbsc/include/openbsc/mgcp_internal.h
@@ -59,6 +59,12 @@ struct mgcp_rtp_end {
int payload_type;
+ /*
+ * Each end has a socket...
+ */
+ struct bsc_fd rtp;
+ struct bsc_fd rtcp;
+
int local_port;
};
@@ -69,14 +75,6 @@ struct mgcp_endpoint {
int conn_mode;
int orig_mode;
- /*
- * RTP mangling:
- * - we get RTP and RTCP to us and need to forward to the BTS
- * - we get RTP and RTCP from the BTS and forward to the network
- */
- struct bsc_fd local_rtp;
- struct bsc_fd local_rtcp;
-
/* backpointer */
struct mgcp_config *cfg;
diff --git a/openbsc/src/mgcp/mgcp_network.c b/openbsc/src/mgcp/mgcp_network.c
index 2fe5f116..94f88b95 100644
--- a/openbsc/src/mgcp/mgcp_network.c
+++ b/openbsc/src/mgcp/mgcp_network.c
@@ -90,7 +90,7 @@ int mgcp_send_dummy(struct mgcp_endpoint *endp)
{
static char buf[] = { DUMMY_LOAD };
- return udp_send(endp->local_rtp.fd, &endp->net_end.addr,
+ return udp_send(endp->net_end.rtp.fd, &endp->net_end.addr,
endp->net_end.rtp_port, buf, 1);
}
@@ -192,7 +192,7 @@ static int rtp_data_cb(struct bsc_fd *fd, unsigned int what)
dest = memcmp(&addr.sin_addr, &endp->net_end.addr, sizeof(addr.sin_addr)) == 0 &&
(endp->net_end.rtp_port == addr.sin_port || endp->net_end.rtcp_port == addr.sin_port)
? DEST_BTS : DEST_NETWORK;
- proto = fd == &endp->local_rtp ? PROTO_RTP : PROTO_RTCP;
+ proto = (fd == &endp->net_end.rtp || fd == &endp->bts_end.rtp) ? PROTO_RTP : PROTO_RTCP;
/* We have no idea who called us, maybe it is the BTS. */
if (dest == DEST_NETWORK && endp->bts_end.rtp_port == 0) {
@@ -200,7 +200,7 @@ static int rtp_data_cb(struct bsc_fd *fd, unsigned int what)
if (!cfg->bts_ip
|| memcmp(&addr.sin_addr, &cfg->bts_in, sizeof(cfg->bts_in)) == 0
|| memcmp(&addr.sin_addr, &endp->bts_end.addr, sizeof(endp->bts_end.addr)) == 0) {
- if (fd == &endp->local_rtp) {
+ if (proto == PROTO_RTP) {
endp->bts_end.rtp_port = addr.sin_port;
} else {
endp->bts_end.rtcp_port = addr.sin_port;
@@ -290,34 +290,34 @@ static int bind_rtp(struct mgcp_endpoint *endp)
{
struct mgcp_config *cfg = endp->cfg;
- if (create_bind(cfg->source_addr, &endp->local_rtp, endp->bts_end.local_port) != 0) {
+ if (create_bind(cfg->source_addr, &endp->bts_end.rtp, endp->bts_end.local_port) != 0) {
LOGP(DMGCP, LOGL_ERROR, "Failed to create RTP port: %s:%d on 0x%x\n",
cfg->source_addr, endp->bts_end.local_port, ENDPOINT_NUMBER(endp));
goto cleanup0;
}
- if (create_bind(cfg->source_addr, &endp->local_rtcp, endp->bts_end.local_port + 1) != 0) {
+ if (create_bind(cfg->source_addr, &endp->bts_end.rtcp, endp->bts_end.local_port + 1) != 0) {
LOGP(DMGCP, LOGL_ERROR, "Failed to create RTCP port: %s:%d on 0x%x\n",
cfg->source_addr, endp->bts_end.local_port + 1, ENDPOINT_NUMBER(endp));
goto cleanup1;
}
- set_ip_tos(endp->local_rtp.fd, cfg->endp_dscp);
- set_ip_tos(endp->local_rtcp.fd, cfg->endp_dscp);
+ set_ip_tos(endp->bts_end.rtp.fd, cfg->endp_dscp);
+ set_ip_tos(endp->bts_end.rtcp.fd, cfg->endp_dscp);
- endp->local_rtp.cb = rtp_data_cb;
- endp->local_rtp.data = endp;
- endp->local_rtp.when = BSC_FD_READ;
- if (bsc_register_fd(&endp->local_rtp) != 0) {
+ endp->bts_end.rtp.cb = rtp_data_cb;
+ endp->bts_end.rtp.data = endp;
+ endp->bts_end.rtp.when = BSC_FD_READ;
+ if (bsc_register_fd(&endp->bts_end.rtp) != 0) {
LOGP(DMGCP, LOGL_ERROR, "Failed to register RTP port %d on 0x%x\n",
endp->bts_end.local_port, ENDPOINT_NUMBER(endp));
goto cleanup2;
}
- endp->local_rtcp.cb = rtp_data_cb;
- endp->local_rtcp.data = endp;
- endp->local_rtcp.when = BSC_FD_READ;
- if (bsc_register_fd(&endp->local_rtcp) != 0) {
+ endp->bts_end.rtcp.cb = rtp_data_cb;
+ endp->bts_end.rtcp.data = endp;
+ endp->bts_end.rtcp.when = BSC_FD_READ;
+ if (bsc_register_fd(&endp->bts_end.rtcp) != 0) {
LOGP(DMGCP, LOGL_ERROR, "Failed to register RTCP port %d on 0x%x\n",
endp->bts_end.local_port + 1, ENDPOINT_NUMBER(endp));
goto cleanup3;
@@ -326,13 +326,13 @@ static int bind_rtp(struct mgcp_endpoint *endp)
return 0;
cleanup3:
- bsc_unregister_fd(&endp->local_rtp);
+ bsc_unregister_fd(&endp->bts_end.rtp);
cleanup2:
- close(endp->local_rtcp.fd);
- endp->local_rtcp.fd = -1;
+ close(endp->bts_end.rtcp.fd);
+ endp->bts_end.rtcp.fd = -1;
cleanup1:
- close(endp->local_rtp.fd);
- endp->local_rtp.fd = -1;
+ close(endp->bts_end.rtp.fd);
+ endp->bts_end.rtp.fd = -1;
cleanup0:
return -1;
}
diff --git a/openbsc/src/mgcp/mgcp_protocol.c b/openbsc/src/mgcp/mgcp_protocol.c
index 8b990221..69362e4b 100644
--- a/openbsc/src/mgcp/mgcp_protocol.c
+++ b/openbsc/src/mgcp/mgcp_protocol.c
@@ -715,10 +715,19 @@ struct mgcp_config *mgcp_config_alloc(void)
static void mgcp_rtp_end_reset(struct mgcp_rtp_end *end)
{
- memset(end, 0, sizeof(*end));
+ end->packets = 0;
+ memset(&end->addr, 0, sizeof(end->addr));
+ end->rtp_port = end->rtcp_port = end->local_port;
end->payload_type = -1;
}
+static void mgcp_rtp_end_init(struct mgcp_rtp_end *end)
+{
+ mgcp_rtp_end_reset(end);
+ end->rtp.fd = -1;
+ end->rtcp.fd = -1;
+}
+
int mgcp_endpoints_allocate(struct mgcp_config *cfg)
{
int i;
@@ -731,12 +740,10 @@ int mgcp_endpoints_allocate(struct mgcp_config *cfg)
return -1;
for (i = 0; i < cfg->number_endpoints; ++i) {
- cfg->endpoints[i].local_rtp.fd = -1;
- cfg->endpoints[i].local_rtcp.fd = -1;
cfg->endpoints[i].ci = CI_UNUSED;
cfg->endpoints[i].cfg = cfg;
- mgcp_rtp_end_reset(&cfg->endpoints[i].net_end);
- mgcp_rtp_end_reset(&cfg->endpoints[i].bts_end);
+ mgcp_rtp_end_init(&cfg->endpoints[i].net_end);
+ mgcp_rtp_end_init(&cfg->endpoints[i].bts_end);
}
return 0;