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
This commit is contained in:
Pau Espin 2023-08-29 17:26:53 +02:00
parent 66221e60d6
commit 7fbd6aa472
3 changed files with 26 additions and 0 deletions

View File

@ -57,11 +57,13 @@ struct cbc {
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;

View File

@ -108,12 +108,16 @@ static const struct log_info log_info = {
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;

View File

@ -576,6 +576,26 @@ DEFUN(cfg_cbc_peer, cfg_cbc_peer_cmd,
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);