embed strings into structs
They are mostly not even as large as the talloc header used to dynamically allocate them, and they are also not "shared" by anything. Change-Id: I7b46d531c5d3b53984f2ce44538116973f6a074dchanges/26/25426/12
parent
55fdfc223e
commit
2764bdb1aa
|
@ -95,8 +95,8 @@ typedef void (*mgcp_get_format)(struct mgcp_endpoint *endp,
|
|||
struct mgcp_port_range {
|
||||
pthread_mutex_t lock;
|
||||
/* addr or NULL to fall-back to default */
|
||||
char *bind_addr_v4;
|
||||
char *bind_addr_v6;
|
||||
char bind_addr_v4[INET6_ADDRSTRLEN];
|
||||
char bind_addr_v6[INET6_ADDRSTRLEN];
|
||||
|
||||
/* dynamically allocated */
|
||||
int range_start;
|
||||
|
@ -129,9 +129,9 @@ enum mgcp_role {
|
|||
|
||||
struct mgcp_config {
|
||||
int source_port;
|
||||
char *local_ip;
|
||||
char *source_addr;
|
||||
char *call_agent_addr;
|
||||
char local_ip[INET6_ADDRSTRLEN];
|
||||
char source_addr[INET6_ADDRSTRLEN];
|
||||
char call_agent_addr[INET6_ADDRSTRLEN];
|
||||
|
||||
/* RTP processing */
|
||||
mgcp_processing rtp_processing_cb;
|
||||
|
@ -151,8 +151,6 @@ struct mgcp_config {
|
|||
mgcp_rqnt rqnt_cb;
|
||||
void *data;
|
||||
|
||||
uint32_t last_call_id;
|
||||
|
||||
/* list holding the trunks */
|
||||
struct llist_head trunks;
|
||||
|
||||
|
@ -161,7 +159,7 @@ struct mgcp_config {
|
|||
/* osmux translator: 0 means disabled, 1 means enabled */
|
||||
int osmux;
|
||||
/* addr to bind the server to */
|
||||
char *osmux_addr;
|
||||
char osmux_addr[INET6_ADDRSTRLEN];
|
||||
/* The BSC-NAT may ask for enabling osmux on demand. This tells us if
|
||||
* the osmux socket is already initialized.
|
||||
*/
|
||||
|
|
|
@ -135,10 +135,10 @@ void mgcp_get_local_addr(char *addr, struct mgcp_conn_rtp *conn)
|
|||
} else {
|
||||
/* Choose any of the bind addresses, preferring v6 over v4 */
|
||||
bind_addr = endp->cfg->net_ports.bind_addr_v6;
|
||||
if (!bind_addr)
|
||||
if (!strlen(bind_addr))
|
||||
bind_addr = endp->cfg->net_ports.bind_addr_v4;
|
||||
}
|
||||
if (bind_addr) {
|
||||
if (strlen(bind_addr)) {
|
||||
LOGPCONN(conn->conn, DRTP, LOGL_DEBUG,
|
||||
"using configured rtp bind ip as local bind ip %s\n",
|
||||
bind_addr);
|
||||
|
|
|
@ -273,7 +273,7 @@ static struct msgb *create_response_with_sdp(struct mgcp_endpoint *endp,
|
|||
* us for OSMUX connections. Perhaps adding a new internal API to get it
|
||||
* based on conn type.
|
||||
*/
|
||||
const char *addr = endp->cfg->local_ip ? : conn->end.local_addr;
|
||||
const char *addr = strlen(endp->cfg->local_ip) ? endp->cfg->local_ip : conn->end.local_addr;
|
||||
struct msgb *sdp;
|
||||
int rc;
|
||||
struct msgb *result;
|
||||
|
@ -1615,8 +1615,8 @@ struct mgcp_config *mgcp_config_alloc(void)
|
|||
cfg->net_ports.last_port = cfg->net_ports.range_start;
|
||||
|
||||
cfg->source_port = 2427;
|
||||
cfg->source_addr = talloc_strdup(cfg, "0.0.0.0");
|
||||
cfg->osmux_addr = talloc_strdup(cfg, "0.0.0.0");
|
||||
osmo_strlcpy(cfg->source_addr, "0.0.0.0", sizeof(cfg->source_addr));
|
||||
osmo_strlcpy(cfg->osmux_addr, "0.0.0.0", sizeof(cfg->osmux_addr));
|
||||
|
||||
cfg->rtp_processing_cb = &mgcp_rtp_processing_default;
|
||||
cfg->setup_rtp_processing_cb = &mgcp_setup_rtp_processing_default;
|
||||
|
|
|
@ -65,17 +65,17 @@ static int config_write_mgcp(struct vty *vty)
|
|||
|
||||
vty_out(vty, "mgcp%s", VTY_NEWLINE);
|
||||
vty_out(vty, " domain %s%s", g_cfg->domain, VTY_NEWLINE);
|
||||
if (g_cfg->local_ip)
|
||||
if (strlen(g_cfg->local_ip))
|
||||
vty_out(vty, " local ip %s%s", g_cfg->local_ip, VTY_NEWLINE);
|
||||
vty_out(vty, " bind ip %s%s", g_cfg->source_addr, VTY_NEWLINE);
|
||||
vty_out(vty, " bind port %u%s", g_cfg->source_port, VTY_NEWLINE);
|
||||
vty_out(vty, " rtp port-range %u %u%s",
|
||||
g_cfg->net_ports.range_start, g_cfg->net_ports.range_end,
|
||||
VTY_NEWLINE);
|
||||
if (g_cfg->net_ports.bind_addr_v4)
|
||||
if (strlen(g_cfg->net_ports.bind_addr_v4))
|
||||
vty_out(vty, " rtp bind-ip %s%s",
|
||||
g_cfg->net_ports.bind_addr_v4, VTY_NEWLINE);
|
||||
if (g_cfg->net_ports.bind_addr_v6)
|
||||
if (strlen(g_cfg->net_ports.bind_addr_v6))
|
||||
vty_out(vty, " rtp bind-ip-v6 %s%s",
|
||||
g_cfg->net_ports.bind_addr_v6, VTY_NEWLINE);
|
||||
if (g_cfg->net_ports.bind_addr_probe)
|
||||
|
@ -122,7 +122,7 @@ static int config_write_mgcp(struct vty *vty)
|
|||
trunk->v.vty_number_endpoints, VTY_NEWLINE);
|
||||
vty_out(vty, " %sallow-transcoding%s",
|
||||
trunk->no_audio_transcoding ? "no " : "", VTY_NEWLINE);
|
||||
if (g_cfg->call_agent_addr)
|
||||
if (strlen(g_cfg->call_agent_addr))
|
||||
vty_out(vty, " call-agent ip %s%s", g_cfg->call_agent_addr,
|
||||
VTY_NEWLINE);
|
||||
if (g_cfg->force_ptime > 0)
|
||||
|
@ -443,7 +443,7 @@ DEFUN_USRATTR(cfg_mgcp_local_ip,
|
|||
"IPv4 Address to use in SDP record\n"
|
||||
"IPv6 Address to use in SDP record\n")
|
||||
{
|
||||
osmo_talloc_replace_string(g_cfg, &g_cfg->local_ip, argv[0]);
|
||||
osmo_strlcpy(g_cfg->local_ip, argv[0], sizeof(g_cfg->local_ip));
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -455,7 +455,7 @@ DEFUN(cfg_mgcp_bind_ip,
|
|||
"IPv4 Address to bind to\n"
|
||||
"IPv6 Address to bind to\n")
|
||||
{
|
||||
osmo_talloc_replace_string(g_cfg, &g_cfg->source_addr, argv[0]);
|
||||
osmo_strlcpy(g_cfg->source_addr, argv[0], sizeof(g_cfg->source_addr));
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -533,7 +533,7 @@ DEFUN_USRATTR(cfg_mgcp_rtp_bind_ip,
|
|||
RTP_STR "Bind endpoints facing the Network\n"
|
||||
"IPv4 Address to bind to\n")
|
||||
{
|
||||
osmo_talloc_replace_string(g_cfg, &g_cfg->net_ports.bind_addr_v4, argv[0]);
|
||||
osmo_strlcpy(g_cfg->net_ports.bind_addr_v4, argv[0], sizeof(g_cfg->net_ports.bind_addr_v4));
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
ALIAS_DEPRECATED(cfg_mgcp_rtp_bind_ip,
|
||||
|
@ -548,8 +548,7 @@ DEFUN_USRATTR(cfg_mgcp_rtp_no_bind_ip,
|
|||
NO_STR RTP_STR "Bind endpoints facing the Network\n"
|
||||
"Address to bind to\n")
|
||||
{
|
||||
talloc_free(g_cfg->net_ports.bind_addr_v4);
|
||||
g_cfg->net_ports.bind_addr_v4 = NULL;
|
||||
osmo_strlcpy(g_cfg->net_ports.bind_addr_v4, "", sizeof(g_cfg->net_ports.bind_addr_v4));
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
ALIAS_DEPRECATED(cfg_mgcp_rtp_no_bind_ip,
|
||||
|
@ -565,7 +564,7 @@ DEFUN_USRATTR(cfg_mgcp_rtp_bind_ip_v6,
|
|||
RTP_STR "Bind endpoints facing the Network\n"
|
||||
"IPv6 Address to bind to\n")
|
||||
{
|
||||
osmo_talloc_replace_string(g_cfg, &g_cfg->net_ports.bind_addr_v6, argv[0]);
|
||||
osmo_strlcpy(g_cfg->net_ports.bind_addr_v6, argv[0], sizeof(g_cfg->net_ports.bind_addr_v6));
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -576,8 +575,7 @@ DEFUN_USRATTR(cfg_mgcp_rtp_no_bind_ip_v6,
|
|||
NO_STR RTP_STR "Bind endpoints facing the Network\n"
|
||||
"Address to bind to\n")
|
||||
{
|
||||
talloc_free(g_cfg->net_ports.bind_addr_v6);
|
||||
g_cfg->net_ports.bind_addr_v6 = NULL;
|
||||
osmo_strlcpy(g_cfg->net_ports.bind_addr_v6, "", sizeof(g_cfg->net_ports.bind_addr_v6));
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -950,7 +948,7 @@ DEFUN(cfg_mgcp_agent_addr,
|
|||
"IPv4 Address of the call agent\n"
|
||||
"IPv6 Address of the call agent\n")
|
||||
{
|
||||
osmo_talloc_replace_string(g_cfg, &g_cfg->call_agent_addr, argv[0]);
|
||||
osmo_strlcpy(g_cfg->call_agent_addr, argv[0], sizeof(g_cfg->call_agent_addr));
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -1559,7 +1557,7 @@ DEFUN(cfg_mgcp_osmux_ip,
|
|||
"IPv4 Address to bind to\n"
|
||||
"IPv6 Address to bind to\n")
|
||||
{
|
||||
osmo_talloc_replace_string(g_cfg, &g_cfg->osmux_addr, argv[0]);
|
||||
osmo_strlcpy(g_cfg->osmux_addr, argv[0], sizeof(g_cfg->osmux_addr));
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -1748,7 +1746,7 @@ int mgcp_parse_config(const char *config_file, struct mgcp_config *cfg,
|
|||
return rc;
|
||||
}
|
||||
|
||||
if (!g_cfg->source_addr) {
|
||||
if (!strlen(g_cfg->source_addr)) {
|
||||
fprintf(stderr, "You need to specify a bind address.\n");
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -369,12 +369,12 @@ int main(int argc, char **argv)
|
|||
|
||||
/* we need to bind a socket */
|
||||
flags = OSMO_SOCK_F_BIND;
|
||||
if (cfg->call_agent_addr)
|
||||
if (strlen(cfg->call_agent_addr))
|
||||
flags |= OSMO_SOCK_F_CONNECT;
|
||||
|
||||
rc = osmo_sock_init2_ofd(&cfg->gw_fd.bfd, AF_UNSPEC, SOCK_DGRAM, IPPROTO_UDP,
|
||||
cfg->source_addr, cfg->source_port,
|
||||
cfg->call_agent_addr, cfg->call_agent_addr ? 2727 : 0, flags);
|
||||
cfg->call_agent_addr, strlen(cfg->call_agent_addr) ? 2727 : 0, flags);
|
||||
if (rc < 0) {
|
||||
perror("Gateway failed to bind");
|
||||
return -1;
|
||||
|
|
Loading…
Reference in New Issue