nat: Use the write_queue inside the CFG.
This commit is contained in:
parent
6f6801066b
commit
249d69a26c
|
@ -190,7 +190,6 @@ struct bsc_nat {
|
||||||
|
|
||||||
/* MGCP config */
|
/* MGCP config */
|
||||||
struct mgcp_config *mgcp_cfg;
|
struct mgcp_config *mgcp_cfg;
|
||||||
struct write_queue mgcp_queue;
|
|
||||||
uint8_t mgcp_msg[4096];
|
uint8_t mgcp_msg[4096];
|
||||||
int mgcp_length;
|
int mgcp_length;
|
||||||
|
|
||||||
|
|
|
@ -412,7 +412,7 @@ void bsc_mgcp_forward(struct bsc_connection *bsc, struct msgb *msg)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (write_queue_enqueue(&bsc->nat->mgcp_queue, output) != 0) {
|
if (write_queue_enqueue(&bsc->nat->mgcp_cfg->gw_fd, output) != 0) {
|
||||||
LOGP(DMGCP, LOGL_ERROR, "Failed to queue MGCP msg.\n");
|
LOGP(DMGCP, LOGL_ERROR, "Failed to queue MGCP msg.\n");
|
||||||
msgb_free(output);
|
msgb_free(output);
|
||||||
}
|
}
|
||||||
|
@ -562,7 +562,7 @@ static int mgcp_do_read(struct bsc_fd *fd)
|
||||||
|
|
||||||
/* we do have a direct answer... e.g. AUEP */
|
/* we do have a direct answer... e.g. AUEP */
|
||||||
if (resp) {
|
if (resp) {
|
||||||
if (write_queue_enqueue(&nat->mgcp_queue, resp) != 0) {
|
if (write_queue_enqueue(&nat->mgcp_cfg->gw_fd, resp) != 0) {
|
||||||
LOGP(DMGCP, LOGL_ERROR, "Failed to enqueue msg.\n");
|
LOGP(DMGCP, LOGL_ERROR, "Failed to enqueue msg.\n");
|
||||||
msgb_free(resp);
|
msgb_free(resp);
|
||||||
}
|
}
|
||||||
|
@ -589,81 +589,82 @@ int bsc_mgcp_nat_init(struct bsc_nat *nat)
|
||||||
{
|
{
|
||||||
int on;
|
int on;
|
||||||
struct sockaddr_in addr;
|
struct sockaddr_in addr;
|
||||||
|
struct mgcp_config *cfg = nat->mgcp_cfg;
|
||||||
|
|
||||||
if (!nat->mgcp_cfg->call_agent_addr) {
|
if (!cfg->call_agent_addr) {
|
||||||
LOGP(DMGCP, LOGL_ERROR, "The BSC nat requires the call agent ip to be set.\n");
|
LOGP(DMGCP, LOGL_ERROR, "The BSC nat requires the call agent ip to be set.\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nat->mgcp_cfg->bts_ip) {
|
if (cfg->bts_ip) {
|
||||||
LOGP(DMGCP, LOGL_ERROR, "Do not set the BTS ip for the nat.\n");
|
LOGP(DMGCP, LOGL_ERROR, "Do not set the BTS ip for the nat.\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
nat->mgcp_queue.bfd.fd = socket(AF_INET, SOCK_DGRAM, 0);
|
cfg->gw_fd.bfd.fd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||||
if (nat->mgcp_queue.bfd.fd < 0) {
|
if (cfg->gw_fd.bfd.fd < 0) {
|
||||||
LOGP(DMGCP, LOGL_ERROR, "Failed to create MGCP socket. errno: %d\n", errno);
|
LOGP(DMGCP, LOGL_ERROR, "Failed to create MGCP socket. errno: %d\n", errno);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
on = 1;
|
on = 1;
|
||||||
setsockopt(nat->mgcp_queue.bfd.fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
|
setsockopt(cfg->gw_fd.bfd.fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
|
||||||
|
|
||||||
addr.sin_family = AF_INET;
|
addr.sin_family = AF_INET;
|
||||||
addr.sin_port = htons(nat->mgcp_cfg->source_port);
|
addr.sin_port = htons(cfg->source_port);
|
||||||
inet_aton(nat->mgcp_cfg->source_addr, &addr.sin_addr);
|
inet_aton(cfg->source_addr, &addr.sin_addr);
|
||||||
|
|
||||||
if (bind(nat->mgcp_queue.bfd.fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
|
if (bind(cfg->gw_fd.bfd.fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
|
||||||
LOGP(DMGCP, LOGL_ERROR, "Failed to bind. errno: %d\n", errno);
|
LOGP(DMGCP, LOGL_ERROR, "Failed to bind. errno: %d\n", errno);
|
||||||
close(nat->mgcp_queue.bfd.fd);
|
close(cfg->gw_fd.bfd.fd);
|
||||||
nat->mgcp_queue.bfd.fd = -1;
|
cfg->gw_fd.bfd.fd = -1;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
addr.sin_port = htons(2727);
|
addr.sin_port = htons(2727);
|
||||||
inet_aton(nat->mgcp_cfg->call_agent_addr, &addr.sin_addr);
|
inet_aton(cfg->call_agent_addr, &addr.sin_addr);
|
||||||
if (connect(nat->mgcp_queue.bfd.fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
|
if (connect(cfg->gw_fd.bfd.fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
|
||||||
LOGP(DMGCP, LOGL_ERROR, "Failed to connect to: '%s'. errno: %d\n",
|
LOGP(DMGCP, LOGL_ERROR, "Failed to connect to: '%s'. errno: %d\n",
|
||||||
nat->mgcp_cfg->call_agent_addr, errno);
|
cfg->call_agent_addr, errno);
|
||||||
close(nat->mgcp_queue.bfd.fd);
|
close(cfg->gw_fd.bfd.fd);
|
||||||
nat->mgcp_queue.bfd.fd = -1;
|
cfg->gw_fd.bfd.fd = -1;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
write_queue_init(&nat->mgcp_queue, 10);
|
write_queue_init(&cfg->gw_fd, 10);
|
||||||
nat->mgcp_queue.bfd.when = BSC_FD_READ;
|
cfg->gw_fd.bfd.when = BSC_FD_READ;
|
||||||
nat->mgcp_queue.bfd.data = nat;
|
cfg->gw_fd.bfd.data = nat;
|
||||||
nat->mgcp_queue.read_cb = mgcp_do_read;
|
cfg->gw_fd.read_cb = mgcp_do_read;
|
||||||
nat->mgcp_queue.write_cb = mgcp_do_write;
|
cfg->gw_fd.write_cb = mgcp_do_write;
|
||||||
|
|
||||||
if (bsc_register_fd(&nat->mgcp_queue.bfd) != 0) {
|
if (bsc_register_fd(&cfg->gw_fd.bfd) != 0) {
|
||||||
LOGP(DMGCP, LOGL_ERROR, "Failed to register MGCP fd.\n");
|
LOGP(DMGCP, LOGL_ERROR, "Failed to register MGCP fd.\n");
|
||||||
close(nat->mgcp_queue.bfd.fd);
|
close(cfg->gw_fd.bfd.fd);
|
||||||
nat->mgcp_queue.bfd.fd = -1;
|
cfg->gw_fd.bfd.fd = -1;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* some more MGCP config handling */
|
/* some more MGCP config handling */
|
||||||
if (nat->mgcp_cfg->audio_name)
|
if (cfg->audio_name)
|
||||||
talloc_free(nat->mgcp_cfg->audio_name);
|
talloc_free(cfg->audio_name);
|
||||||
nat->mgcp_cfg->audio_name = NULL;
|
cfg->audio_name = NULL;
|
||||||
|
|
||||||
nat->mgcp_cfg->audio_payload = -1;
|
cfg->audio_payload = -1;
|
||||||
nat->mgcp_cfg->data = nat;
|
cfg->data = nat;
|
||||||
nat->mgcp_cfg->policy_cb = bsc_mgcp_policy_cb;
|
cfg->policy_cb = bsc_mgcp_policy_cb;
|
||||||
nat->mgcp_cfg->force_realloc = 1;
|
cfg->force_realloc = 1;
|
||||||
|
|
||||||
if (nat->mgcp_cfg->bts_ip)
|
if (cfg->bts_ip)
|
||||||
talloc_free(nat->mgcp_cfg->bts_ip);
|
talloc_free(cfg->bts_ip);
|
||||||
nat->mgcp_cfg->bts_ip = "";
|
cfg->bts_ip = "";
|
||||||
|
|
||||||
nat->bsc_endpoints = talloc_zero_array(nat,
|
nat->bsc_endpoints = talloc_zero_array(nat,
|
||||||
struct bsc_endpoint,
|
struct bsc_endpoint,
|
||||||
nat->mgcp_cfg->number_endpoints + 1);
|
cfg->number_endpoints + 1);
|
||||||
if (!nat->bsc_endpoints) {
|
if (!nat->bsc_endpoints) {
|
||||||
LOGP(DMGCP, LOGL_ERROR, "Failed to allocate nat endpoints\n");
|
LOGP(DMGCP, LOGL_ERROR, "Failed to allocate nat endpoints\n");
|
||||||
close(nat->mgcp_queue.bfd.fd);
|
close(cfg->gw_fd.bfd.fd);
|
||||||
nat->mgcp_queue.bfd.fd = -1;
|
cfg->gw_fd.bfd.fd = -1;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue