pespin submitted this change.
Catch and forbid configuring peers before configuring main protocol node
When the user enters each "peer" node, the related object is created if
not yet existing, and its updated config is applied (connect()) upon
exiting the node (cbc_peer_apply_cfg_chg()). When connect happens, it
needs to obtain the local IP address from the main protocol node
(cbsp|sbcap)", which means it must be configured beforehand, otherwise
the peers connect using the default values.
Hence, it makes no sense to configure peers if the main protocol
information has not yet been configured. The usual example configs as
well as the write-config VTY commands provide correct order of things.
Catch and forbid the user providing a config file where the peers are
configured before the main protocol nodes.
Related: OS#6154
Change-Id: I678f9e6715c85b1eb9116cc892f1a8299577c0c2
---
M include/osmocom/cbc/cbc_data.h
M src/cbc_main.c
M src/cbc_vty.c
3 files changed, 49 insertions(+), 0 deletions(-)
diff --git a/include/osmocom/cbc/cbc_data.h b/include/osmocom/cbc/cbc_data.h
index 6d64f04..d5e5cde 100644
--- a/include/osmocom/cbc/cbc_data.h
+++ b/include/osmocom/cbc/cbc_data.h
@@ -57,11 +57,13 @@
struct {
char *local_host;
int local_port;
+ bool configured;
} cbsp;
struct {
char *local_host[CBC_MAX_LOC_ADDRS];
unsigned int num_local_host;
int local_port;
+ bool configured;
} sbcap;
struct {
char *local_host;
diff --git a/src/cbc_main.c b/src/cbc_main.c
index e75b328..c777ef6 100644
--- a/src/cbc_main.c
+++ b/src/cbc_main.c
@@ -108,12 +108,16 @@
static int cbc_vty_go_parent(struct vty *vty)
{
switch (vty->node) {
+ case CBSP_NODE:
+ g_cbc->config.cbsp.configured = true;
+ 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;
}
+ g_cbc->config.sbcap.configured = true;
vty->node = CONFIG_NODE;
vty->index = NULL;
break;
diff --git a/src/cbc_vty.c b/src/cbc_vty.c
index 631ef96..12b7d7b 100644
--- a/src/cbc_vty.c
+++ b/src/cbc_vty.c
@@ -576,6 +576,26 @@
enum cbc_peer_protocol proto;
proto = get_string_value(cbc_peer_proto_name_vty, argv[0]);
+ switch (proto) {
+ case CBC_PEER_PROTO_CBSP:
+ if (!g_cbc->config.cbsp.configured) {
+ vty_out(vty, "%% Node '%s' must be configured before configuring node 'peer'!%s",
+ argv[0], VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+ break;
+ case CBC_PEER_PROTO_SBcAP:
+ if (!g_cbc->config.sbcap.configured) {
+ vty_out(vty, "%% Node '%s' must be configured before configuring node 'peer'!%s",
+ argv[0], VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+ break;
+ case CBC_PEER_PROTO_SABP:
+ default:
+ return CMD_WARNING;
+ }
+
peer = cbc_peer_by_name(argv[1]);
if (!peer)
peer = cbc_peer_create(argv[1], proto);
To view, visit change 34246. To unsubscribe, or for help writing mail filters, visit settings.