mirror of
https://gitea.osmocom.org/cellular-infrastructure/osmo-cbc.git
synced 2025-10-23 00:12:21 +00:00
Set default SBcAP local host when no VTY cfg sbcap node provided
During 7fbd6aa472
a "configured" flag was
introduced which could be used to make sure the SBcAP node was
configured before "peer" node, which made sure the local IP address was
set before triggering connect() in client mode.
However, the patch didn't account for the possibility that a user may
use a config file with no "sbcap" node at all, which hence ends up with
no local address being configured and opening the listen server SBcAP
socket will fail.
Related: OS#6814
Change-Id: I48eb465fecbeebd7cd8eafb17908ba0439bb9e50
This commit is contained in:
@@ -89,6 +89,7 @@ struct cbc {
|
||||
extern struct cbc *g_cbc;
|
||||
struct cbc *cbc_alloc(void *ctx);
|
||||
int cbc_start(struct cbc *cbc);
|
||||
void cbc_add_sbcap_default_local_host_if_needed(struct cbc *cbc);
|
||||
|
||||
/* rest_api.c */
|
||||
int rest_api_init(void *ctx, const char *bind_addr, uint16_t port);
|
||||
|
@@ -85,7 +85,9 @@ struct cbc *cbc_alloc(void *ctx)
|
||||
INIT_LLIST_HEAD(&cbc->expired_messages);
|
||||
cbc->config.cbsp.local_host = talloc_strdup(cbc, "127.0.0.1");
|
||||
cbc->config.cbsp.local_port = CBSP_TCP_PORT;
|
||||
/* cbc->config.sbcap local_host set up during VTY (and vty_go_parent) */
|
||||
/* Due to SCTP multi-home support, cbc->config.sbcap.local_host is not set here,
|
||||
* but through VTY (user or vty_go_parent()), or if not set default is set after
|
||||
* VTY cfg read, during cbc_start(). */
|
||||
cbc->config.sbcap.local_port = SBcAP_SCTP_PORT;
|
||||
cbc->config.ecbe.local_host = talloc_strdup(cbc, "127.0.0.1");
|
||||
cbc->config.ecbe.local_port = 12345;
|
||||
@@ -103,6 +105,16 @@ struct cbc *cbc_alloc(void *ctx)
|
||||
return cbc;
|
||||
}
|
||||
|
||||
/* If no local addr set, add a default one: */
|
||||
void cbc_add_sbcap_default_local_host_if_needed(struct cbc *cbc)
|
||||
{
|
||||
if (g_cbc->config.sbcap.num_local_host > 0)
|
||||
return;
|
||||
|
||||
g_cbc->config.sbcap.local_host[0] = talloc_strdup(g_cbc, "127.0.0.1");
|
||||
g_cbc->config.sbcap.num_local_host = 1;
|
||||
}
|
||||
|
||||
int cbc_start(struct cbc *cbc)
|
||||
{
|
||||
void *tall_rest_ctx;
|
||||
@@ -115,6 +127,12 @@ int cbc_start(struct cbc *cbc)
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* User didn't configure an SBcAP node with a local address, use default: */
|
||||
if (!cbc->config.sbcap.configured) {
|
||||
cbc_add_sbcap_default_local_host_if_needed(cbc);
|
||||
cbc->config.sbcap.configured = true;
|
||||
}
|
||||
|
||||
if ((rc = cbc_sbcap_mgr_open_srv(cbc->sbcap.mgr)) < 0) {
|
||||
LOGP(DMAIN, LOGL_ERROR, "Error binding SBc-AP port\n");
|
||||
return rc;
|
||||
|
@@ -113,10 +113,7 @@ static int cbc_vty_go_parent(struct vty *vty)
|
||||
break;
|
||||
case SBcAP_NODE:
|
||||
/* If no local addr set, add a default one: */
|
||||
if (g_cbc->config.sbcap.num_local_host == 0) {
|
||||
g_cbc->config.sbcap.local_host[0] = talloc_strdup(g_cbc, "127.0.0.1");
|
||||
g_cbc->config.sbcap.num_local_host = 1;
|
||||
}
|
||||
cbc_add_sbcap_default_local_host_if_needed(g_cbc);
|
||||
g_cbc->config.sbcap.configured = true;
|
||||
vty->node = CONFIG_NODE;
|
||||
vty->index = NULL;
|
||||
|
Reference in New Issue
Block a user