aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc/src/mgcp/mgcp_network.c
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2010-11-01 21:15:22 +0100
committerHolger Hans Peter Freyther <zecke@selfish.org>2010-11-02 19:08:09 +0100
commit386a940736d5f8c65ba5d5409c4858f5c829a338 (patch)
tree3b6282253bc343d09e6f720457c814749c68ebfe /openbsc/src/mgcp/mgcp_network.c
parentbd7b3c5e45426efc79b4dd685d1e818de3550d0a (diff)
mgcp: Refactor the network binding routines
Create another wrapper function that takes most of the arguments from the caller.
Diffstat (limited to 'openbsc/src/mgcp/mgcp_network.c')
-rw-r--r--openbsc/src/mgcp/mgcp_network.c73
1 files changed, 26 insertions, 47 deletions
diff --git a/openbsc/src/mgcp/mgcp_network.c b/openbsc/src/mgcp/mgcp_network.c
index ae0504ff9..c90219774 100644
--- a/openbsc/src/mgcp/mgcp_network.c
+++ b/openbsc/src/mgcp/mgcp_network.c
@@ -511,68 +511,47 @@ cleanup0:
return -1;
}
-int mgcp_bind_bts_rtp_port(struct mgcp_endpoint *endp, int rtp_port)
+static int int_bind(const char *port,
+ struct mgcp_rtp_end *end, int (*cb)(struct bsc_fd *, unsigned),
+ struct mgcp_endpoint *_endp, int rtp_port)
{
- if (endp->bts_end.rtp.fd != -1 || endp->bts_end.rtcp.fd != -1) {
- LOGP(DMGCP, LOGL_ERROR, "Previous bts-port was still bound on %d\n",
- ENDPOINT_NUMBER(endp));
- mgcp_free_rtp_port(&endp->bts_end);
+ if (end->rtp.fd != -1 || end->rtcp.fd != -1) {
+ LOGP(DMGCP, LOGL_ERROR, "Previous %s was still bound on %d\n",
+ port, ENDPOINT_NUMBER(_endp));
+ mgcp_free_rtp_port(end);
}
- endp->bts_end.local_port = rtp_port;
- endp->bts_end.rtp.cb = rtp_data_bts;
- endp->bts_end.rtp.data = endp;
- endp->bts_end.rtcp.data = endp;
- endp->bts_end.rtcp.cb = rtp_data_bts;
- return bind_rtp(endp->cfg, &endp->bts_end, ENDPOINT_NUMBER(endp));
+ end->local_port = rtp_port;
+ end->rtp.cb = cb;
+ end->rtp.data = _endp;
+ end->rtcp.data = _endp;
+ end->rtcp.cb = cb;
+ return bind_rtp(_endp->cfg, end, ENDPOINT_NUMBER(_endp));
}
-int mgcp_bind_net_rtp_port(struct mgcp_endpoint *endp, int rtp_port)
+
+int mgcp_bind_bts_rtp_port(struct mgcp_endpoint *endp, int rtp_port)
{
- if (endp->net_end.rtp.fd != -1 || endp->net_end.rtcp.fd != -1) {
- LOGP(DMGCP, LOGL_ERROR, "Previous net-port was still bound on %d\n",
- ENDPOINT_NUMBER(endp));
- mgcp_free_rtp_port(&endp->net_end);
- }
+ return int_bind("bts-port", &endp->bts_end,
+ rtp_data_bts, endp, rtp_port);
+}
- endp->net_end.local_port = rtp_port;
- endp->net_end.rtp.cb = rtp_data_net;
- endp->net_end.rtp.data = endp;
- endp->net_end.rtcp.data = endp;
- endp->net_end.rtcp.cb = rtp_data_net;
- return bind_rtp(endp->cfg, &endp->net_end, ENDPOINT_NUMBER(endp));
+int mgcp_bind_net_rtp_port(struct mgcp_endpoint *endp, int rtp_port)
+{
+ return int_bind("net-port", &endp->net_end,
+ rtp_data_net, endp, rtp_port);
}
int mgcp_bind_trans_net_rtp_port(struct mgcp_endpoint *endp, int rtp_port)
{
- if (endp->trans_net.rtp.fd != -1 || endp->trans_net.rtcp.fd != -1) {
- LOGP(DMGCP, LOGL_ERROR, "Previous net-port was still bound on %d\n",
- ENDPOINT_NUMBER(endp));
- mgcp_free_rtp_port(&endp->trans_net);
- }
-
- endp->trans_net.local_port = rtp_port;
- endp->trans_net.rtp.cb = rtp_data_transcoder;
- endp->trans_net.rtp.data = endp;
- endp->trans_net.rtcp.data = endp;
- endp->trans_net.rtcp.cb = rtp_data_transcoder;
- return bind_rtp(endp->cfg, &endp->trans_net, ENDPOINT_NUMBER(endp));
+ return int_bind("trans-net", &endp->trans_net,
+ rtp_data_transcoder, endp, rtp_port);
}
int mgcp_bind_trans_bts_rtp_port(struct mgcp_endpoint *endp, int rtp_port)
{
- if (endp->trans_bts.rtp.fd != -1 || endp->trans_bts.rtcp.fd != -1) {
- LOGP(DMGCP, LOGL_ERROR, "Previous net-port was still bound on %d\n",
- ENDPOINT_NUMBER(endp));
- mgcp_free_rtp_port(&endp->trans_bts);
- }
-
- endp->trans_bts.local_port = rtp_port;
- endp->trans_bts.rtp.cb = rtp_data_transcoder;
- endp->trans_bts.rtp.data = endp;
- endp->trans_bts.rtcp.data = endp;
- endp->trans_bts.rtcp.cb = rtp_data_transcoder;
- return bind_rtp(endp->cfg, &endp->trans_bts, ENDPOINT_NUMBER(endp));
+ return int_bind("trans-bts", &endp->trans_bts,
+ rtp_data_transcoder, endp, rtp_port);
}
int mgcp_free_rtp_port(struct mgcp_rtp_end *end)