laforge has submitted this change. (
https://gerrit.osmocom.org/c/osmo-cbc/+/40735?usp=email )
Change subject: Set default SBcAP local host when no VTY cfg sbcap node provided
......................................................................
Set default SBcAP local host when no VTY cfg sbcap node provided
During 7fbd6aa472b011876894949b8a9a6c2784473451 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
---
M include/osmocom/cbc/cbc_data.h
M src/cbc_data.c
M src/cbc_main.c
3 files changed, 21 insertions(+), 5 deletions(-)
Approvals:
fixeria: Looks good to me, but someone else must approve
laforge: Looks good to me, approved
Jenkins Builder: Verified
diff --git a/include/osmocom/cbc/cbc_data.h b/include/osmocom/cbc/cbc_data.h
index d5e5cde..9040b99 100644
--- a/include/osmocom/cbc/cbc_data.h
+++ b/include/osmocom/cbc/cbc_data.h
@@ -89,6 +89,7 @@
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);
diff --git a/src/cbc_data.c b/src/cbc_data.c
index 3029ffc..a9c2c9e 100644
--- a/src/cbc_data.c
+++ b/src/cbc_data.c
@@ -85,7 +85,9 @@
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 @@
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 @@
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;
diff --git a/src/cbc_main.c b/src/cbc_main.c
index 2de8c72..d34546d 100644
--- a/src/cbc_main.c
+++ b/src/cbc_main.c
@@ -113,10 +113,7 @@
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;
--
To view, visit
https://gerrit.osmocom.org/c/osmo-cbc/+/40735?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: osmo-cbc
Gerrit-Branch: master
Gerrit-Change-Id: I48eb465fecbeebd7cd8eafb17908ba0439bb9e50
Gerrit-Change-Number: 40735
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>