aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2010-08-05 01:34:51 +0800
committerHolger Hans Peter Freyther <zecke@selfish.org>2010-08-05 06:10:54 +0800
commita17d701a708c157f26b91c6ab8960fa7db33e7cd (patch)
tree3661beadf93f71063b4adc6b448b5c4bdad70918
parent8b5772ebe4d6844976324882004403de6327af83 (diff)
mgcp: Group the state for bts/net into a struct and have two instances
Group the data that each end (network/bts) have into a struct and use this struct throughout the sourcecode.
-rw-r--r--openbsc/include/openbsc/mgcp_internal.h27
-rw-r--r--openbsc/src/mgcp/mgcp_network.c36
-rw-r--r--openbsc/src/mgcp/mgcp_protocol.c37
-rw-r--r--openbsc/src/mgcp/mgcp_vty.c9
-rw-r--r--openbsc/src/nat/bsc_mgcp_utils.c2
5 files changed, 58 insertions, 53 deletions
diff --git a/openbsc/include/openbsc/mgcp_internal.h b/openbsc/include/openbsc/mgcp_internal.h
index 2d9629aa..1ac8ad42 100644
--- a/openbsc/include/openbsc/mgcp_internal.h
+++ b/openbsc/include/openbsc/mgcp_internal.h
@@ -49,6 +49,17 @@ struct mgcp_rtp_state {
int32_t timestamp_offset;
};
+struct mgcp_rtp_end {
+ /* statistics */
+ unsigned int packets;
+ struct in_addr addr;
+
+ /* in network byte order */
+ int rtp_port, rtcp_port;
+
+ int payload_type;
+};
+
struct mgcp_endpoint {
int ci;
char *callid;
@@ -56,9 +67,6 @@ struct mgcp_endpoint {
int conn_mode;
int orig_mode;
- int bts_payload_type;
- int net_payload_type;
-
/* the local rtp port we are binding to */
int rtp_port;
@@ -70,19 +78,12 @@ struct mgcp_endpoint {
struct bsc_fd local_rtp;
struct bsc_fd local_rtcp;
- struct in_addr remote;
- struct in_addr bts;
-
- /* in network byte order */
- int net_rtp, net_rtcp;
- int bts_rtp, bts_rtcp;
-
/* backpointer */
struct mgcp_config *cfg;
- /* statistics */
- unsigned int in_bts;
- unsigned int in_remote;
+ /* port status for bts/net */
+ struct mgcp_rtp_end bts_end;
+ struct mgcp_rtp_end net_end;
/* sequence bits */
struct mgcp_rtp_state net_state;
diff --git a/openbsc/src/mgcp/mgcp_network.c b/openbsc/src/mgcp/mgcp_network.c
index 7f3c11ee..8ffc2660 100644
--- a/openbsc/src/mgcp/mgcp_network.c
+++ b/openbsc/src/mgcp/mgcp_network.c
@@ -90,8 +90,8 @@ int mgcp_send_dummy(struct mgcp_endpoint *endp)
{
static char buf[] = { DUMMY_LOAD };
- return udp_send(endp->local_rtp.fd, &endp->remote,
- endp->net_rtp, buf, 1);
+ return udp_send(endp->local_rtp.fd, &endp->net_end.addr,
+ endp->net_end.rtp_port, buf, 1);
}
static void patch_and_count(struct mgcp_endpoint *endp, struct mgcp_rtp_state *state,
@@ -189,26 +189,26 @@ static int rtp_data_cb(struct bsc_fd *fd, unsigned int what)
* able to tell if this is legitimate.
*/
#warning "Slight spec violation. With connection mode recvonly we should attempt to forward."
- dest = memcmp(&addr.sin_addr, &endp->remote, sizeof(addr.sin_addr)) == 0 &&
- (endp->net_rtp == addr.sin_port || endp->net_rtcp == addr.sin_port)
+ 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;
/* We have no idea who called us, maybe it is the BTS. */
- if (dest == DEST_NETWORK && endp->bts_rtp == 0) {
+ if (dest == DEST_NETWORK && endp->bts_end.rtp_port == 0) {
/* it was the BTS... */
if (!cfg->bts_ip
|| memcmp(&addr.sin_addr, &cfg->bts_in, sizeof(cfg->bts_in)) == 0
- || memcmp(&addr.sin_addr, &endp->bts, sizeof(endp->bts)) == 0) {
+ || memcmp(&addr.sin_addr, &endp->bts_end.addr, sizeof(endp->bts_end.addr)) == 0) {
if (fd == &endp->local_rtp) {
- endp->bts_rtp = addr.sin_port;
+ endp->bts_end.rtp_port = addr.sin_port;
} else {
- endp->bts_rtcp = addr.sin_port;
+ endp->bts_end.rtcp_port = addr.sin_port;
}
- endp->bts = addr.sin_addr;
+ endp->bts_end.addr = addr.sin_addr;
LOGP(DMGCP, LOGL_NOTICE, "Found BTS for endpoint: 0x%x on port: %d/%d of %s\n",
- ENDPOINT_NUMBER(endp), ntohs(endp->bts_rtp), ntohs(endp->bts_rtcp),
+ ENDPOINT_NUMBER(endp), ntohs(endp->bts_end.rtp_port), ntohs(endp->bts_end.rtcp_port),
inet_ntoa(addr.sin_addr));
}
@@ -223,9 +223,9 @@ static int rtp_data_cb(struct bsc_fd *fd, unsigned int what)
/* do this before the loop handling */
if (dest == DEST_NETWORK)
- ++endp->in_bts;
+ ++endp->bts_end.packets;
else
- ++endp->in_remote;
+ ++endp->net_end.packets;
/* For loop toggle the destination and then dispatch. */
if (cfg->audio_loop)
@@ -238,18 +238,18 @@ static int rtp_data_cb(struct bsc_fd *fd, unsigned int what)
if (dest == DEST_NETWORK) {
if (proto == PROTO_RTP)
patch_and_count(endp, &endp->bts_state,
- endp->net_payload_type,
+ endp->net_end.payload_type,
&addr, buf, rc);
- return udp_send(fd->fd, &endp->remote,
- proto == PROTO_RTP ? endp->net_rtp : endp->net_rtcp,
+ return udp_send(fd->fd, &endp->net_end.addr,
+ proto == PROTO_RTP ? endp->net_end.rtp_port : endp->net_end.rtcp_port,
buf, rc);
} else {
if (proto == PROTO_RTP)
patch_and_count(endp, &endp->net_state,
- endp->bts_payload_type,
+ endp->bts_end.payload_type,
&addr, buf, rc);
- return udp_send(fd->fd, &endp->bts,
- proto == PROTO_RTP ? endp->bts_rtp : endp->bts_rtcp,
+ return udp_send(fd->fd, &endp->bts_end.addr,
+ proto == PROTO_RTP ? endp->bts_end.rtp_port : endp->bts_end.rtcp_port,
buf, rc);
}
}
diff --git a/openbsc/src/mgcp/mgcp_protocol.c b/openbsc/src/mgcp/mgcp_protocol.c
index 12b7fc45..5ef57ccd 100644
--- a/openbsc/src/mgcp/mgcp_protocol.c
+++ b/openbsc/src/mgcp/mgcp_protocol.c
@@ -175,7 +175,7 @@ static struct msgb *create_response_with_sdp(struct mgcp_endpoint *endp,
"m=audio %d RTP/AVP %d\r\n"
"a=rtpmap:%d %s\r\n",
endp->ci, addr, endp->rtp_port,
- endp->bts_payload_type, endp->bts_payload_type,
+ endp->bts_end.payload_type, endp->bts_end.payload_type,
endp->cfg->audio_name);
return mgcp_create_response_with_data(200, msg, trans_id, sdp_record);
}
@@ -421,10 +421,10 @@ static struct msgb *handle_create_con(struct mgcp_config *cfg, struct msgb *msg)
MSG_TOKENIZE_END
/* initialize */
- endp->net_rtp = endp->net_rtcp = endp->bts_rtp = endp->bts_rtcp = 0;
+ endp->net_end.rtp_port = endp->net_end.rtcp_port = endp->bts_end.rtp_port = endp->bts_end.rtcp_port = 0;
/* set to zero until we get the info */
- memset(&endp->remote, 0, sizeof(endp->remote));
+ memset(&endp->net_end.addr, 0, sizeof(endp->net_end.addr));
/* bind to the port now */
port = rtp_calculate_port(ENDPOINT_NUMBER(endp), cfg->rtp_base_port);
@@ -438,7 +438,7 @@ static struct msgb *handle_create_con(struct mgcp_config *cfg, struct msgb *msg)
if (endp->ci == CI_UNUSED)
goto error2;
- endp->bts_payload_type = cfg->audio_payload;
+ endp->bts_end.payload_type = cfg->audio_payload;
/* policy CB */
if (cfg->policy_cb) {
@@ -536,9 +536,9 @@ static struct msgb *handle_modify_con(struct mgcp_config *cfg, struct msgb *msg)
const char *param = (const char *)&msg->l3h[line_start];
if (sscanf(param, "m=audio %d RTP/AVP %d", &port, &payload) == 2) {
- endp->net_rtp = htons(port);
- endp->net_rtcp = htons(port + 1);
- endp->net_payload_type = payload;
+ endp->net_end.rtp_port = htons(port);
+ endp->net_end.rtcp_port = htons(port + 1);
+ endp->net_end.payload_type = payload;
}
break;
}
@@ -547,7 +547,7 @@ static struct msgb *handle_modify_con(struct mgcp_config *cfg, struct msgb *msg)
const char *param = (const char *)&msg->l3h[line_start];
if (sscanf(param, "c=IN IP4 %15s", ipv4) == 1) {
- inet_aton(ipv4, &endp->remote);
+ inet_aton(ipv4, &endp->net_end.addr);
}
break;
}
@@ -581,7 +581,7 @@ static struct msgb *handle_modify_con(struct mgcp_config *cfg, struct msgb *msg)
/* modify */
LOGP(DMGCP, LOGL_NOTICE, "Modified endpoint on: 0x%x Server: %s:%u\n",
- ENDPOINT_NUMBER(endp), inet_ntoa(endp->remote), ntohs(endp->net_rtp));
+ ENDPOINT_NUMBER(endp), inet_ntoa(endp->net_end.addr), ntohs(endp->net_end.rtp_port));
if (cfg->change_cb)
cfg->change_cb(cfg, ENDPOINT_NUMBER(endp), MGCP_ENDP_MDCX, endp->rtp_port);
if (silent)
@@ -666,7 +666,7 @@ static struct msgb *handle_delete_con(struct mgcp_config *cfg, struct msgb *msg)
/* free the connection */
LOGP(DMGCP, LOGL_NOTICE, "Deleted endpoint on: 0x%x Server: %s:%u\n",
- ENDPOINT_NUMBER(endp), inet_ntoa(endp->remote), ntohs(endp->net_rtp));
+ ENDPOINT_NUMBER(endp), inet_ntoa(endp->net_end.addr), ntohs(endp->net_end.rtp_port));
mgcp_free_endp(endp);
if (cfg->change_cb)
cfg->change_cb(cfg, ENDPOINT_NUMBER(endp), MGCP_ENDP_DLCX, endp->rtp_port);
@@ -714,6 +714,12 @@ struct mgcp_config *mgcp_config_alloc(void)
return cfg;
}
+static void mgcp_rtp_end_reset(struct mgcp_rtp_end *end)
+{
+ memset(end, 0, sizeof(*end));
+ end->payload_type = -1;
+}
+
int mgcp_endpoints_allocate(struct mgcp_config *cfg)
{
int i;
@@ -730,8 +736,8 @@ int mgcp_endpoints_allocate(struct mgcp_config *cfg)
cfg->endpoints[i].local_rtcp.fd = -1;
cfg->endpoints[i].ci = CI_UNUSED;
cfg->endpoints[i].cfg = cfg;
- cfg->endpoints[i].net_payload_type = -1;
- cfg->endpoints[i].bts_payload_type = -1;
+ mgcp_rtp_end_reset(&cfg->endpoints[i].net_end);
+ mgcp_rtp_end_reset(&cfg->endpoints[i].bts_end);
}
return 0;
@@ -757,11 +763,8 @@ void mgcp_free_endp(struct mgcp_endpoint *endp)
bsc_unregister_fd(&endp->local_rtcp);
}
- endp->net_rtp = endp->net_rtcp = endp->bts_rtp = endp->bts_rtcp = 0;
- endp->net_payload_type = endp->bts_payload_type = -1;
- endp->in_bts = endp->in_remote = 0;
- memset(&endp->remote, 0, sizeof(endp->remote));
- memset(&endp->bts, 0, sizeof(endp->bts));
+ mgcp_rtp_end_reset(&endp->bts_end);
+ mgcp_rtp_end_reset(&endp->net_end);
memset(&endp->net_state, 0, sizeof(endp->net_state));
memset(&endp->bts_state, 0, sizeof(endp->bts_state));
diff --git a/openbsc/src/mgcp/mgcp_vty.c b/openbsc/src/mgcp/mgcp_vty.c
index 84299d0c..c109491b 100644
--- a/openbsc/src/mgcp/mgcp_vty.c
+++ b/openbsc/src/mgcp/mgcp_vty.c
@@ -81,10 +81,11 @@ DEFUN(show_mcgp, show_mgcp_cmd, "show mgcp",
struct mgcp_endpoint *endp = &g_cfg->endpoints[i];
vty_out(vty, " Endpoint 0x%.2x: CI: %d net: %u/%u bts: %u/%u on %s traffic received bts: %u/%u remote: %u/%u%s",
i, endp->ci,
- ntohs(endp->net_rtp), ntohs(endp->net_rtcp),
- ntohs(endp->bts_rtp), ntohs(endp->bts_rtcp),
- inet_ntoa(endp->bts), endp->in_bts, endp->bts_state.lost_no,
- endp->in_remote, endp->net_state.lost_no,
+ ntohs(endp->net_end.rtp_port), ntohs(endp->net_end.rtcp_port),
+ ntohs(endp->bts_end.rtp_port), ntohs(endp->bts_end.rtcp_port),
+ inet_ntoa(endp->bts_end.addr),
+ endp->bts_end.packets, endp->bts_state.lost_no,
+ endp->net_end.packets, endp->net_state.lost_no,
VTY_NEWLINE);
}
diff --git a/openbsc/src/nat/bsc_mgcp_utils.c b/openbsc/src/nat/bsc_mgcp_utils.c
index 25462364..d309ba21 100644
--- a/openbsc/src/nat/bsc_mgcp_utils.c
+++ b/openbsc/src/nat/bsc_mgcp_utils.c
@@ -247,7 +247,7 @@ int bsc_mgcp_policy_cb(struct mgcp_config *cfg, int endpoint, int state, const c
LOGP(DMGCP, LOGL_ERROR, "Can not get the peername...%d/%s\n",
errno, strerror(errno));
} else {
- mgcp_endp->bts = sock.sin_addr;
+ mgcp_endp->bts_end.addr = sock.sin_addr;
}
/* send the message and a fake MDCX to force sending of a dummy packet */