aboutsummaryrefslogtreecommitdiffstats
path: root/src/vty/vty.c
diff options
context:
space:
mode:
authorNeels Hofmeyr <neels@hofmeyr.de>2017-09-07 03:08:06 +0200
committerNeels Hofmeyr <nhofmeyr@sysmocom.de>2017-09-19 01:35:30 +0000
commit4a31ffa2f0097d96201f80305a0495c57552f0ad (patch)
tree65e45b9fcbb5782aa7e50e788c46798f934c76a5 /src/vty/vty.c
parenta52d839343aea9b81c2463f52c3c3358778698f3 (diff)
VTY: implicit node exit by de-indenting, not parent lookup
Note: This will break users' config files if they do not use consistent indenting. (see below for a definition of "consistent".) When reading VTY commands from a file, use indenting as means to implicitly exit child nodes. Do not look for commands in the parent node implicitly. The VTY so far implies 'exit' commands if a VTY line cannot be parsed on the current node, but succeeds on the parent node. That is the mechanism by which our VTY config files do not need 'exit' at the end of each child node. We've hit problems with this in the following scenarios, which will show improved user experience after this patch: *) When both a parent and its child node have commands with identical names: cs7 instace 0 point-code 1.2.3 sccp-address osmo-msc point-code 0.0.1 If I put the parent's command below the child, it is still interpreted in the context of the child node: cs7 instace 0 sccp-address osmo-msc point-code 0.0.1 point-code 1.2.3 Though the indenting lets me assume I am setting the cs7 instance's global PC to 1.2.3, I'm actually overwriting osmo-msc's PC with 1.2.3 and discarding the 0.0.1. *) When a software change moves a VTY command from a child to a parent. Say 'timezone' moved from 'bts' to 'network' level: network timezone 1 2 Say a user still has an old config file with 'timezone' on the child level: network bts 0 timezone 1 2 trx 0 The user would expect an error message that 'timezone' is invalid on the 'bts' level. Instead, the VTY finds the parent node's 'timezone', steps out of 'bts' to the 'network' level, and instead says that the 'trx' command does not exist. Format: Consistent means that two adjacent indenting lines have the exact same indenting characters for the common length: Weird mix if you ask me, but correct and consistent: ROOT <space>PARENT <space><tab><space>CHILD <space><tab><space><tab><tab>GRANDCHILD <space><tab><space><tab><tab>GRANDCHILD2 <space>SIBLING Inconsistent: ROOT <space>PARENT <tab><space>CHILD <space><space><tab>GRANDCHILD <space><tab><tab>GRANDCHILD2 <tab>SIBLING Also, when going back to a parent level, the exact same indenting must be used as before in that node: Incorrect: ROOT <tab>PARENT <tab><tab><tab>CHILD <tab><tab>SIBLING As not really intended side effect, it is also permitted to indent the entire file starting from the root level. We could guard against it but there's no harm: Correct and consistent: <tab>ROOT <tab><tab>PARENT <tab><tab><tab><tab>CHILD <tab><tab>SIBLING Implementation: Track parent nodes state: whenever a command enters a child node, push a parent node onto an llist to remember the exact indentation characters used for that level. As soon as the first line on a child node is parsed, remember this new indentation (which must have a longer strlen() than its parent level) to apply to all remaining child siblings and grandchildren. If the amount of spaces that indent a following VTY command are less than this expected indentation, call vty_go_parent() until it matches up. At any level, if the common length of indentation characters mismatch, abort parsing in error. Transitions to child node are spread across VTY implementations and are hard to change. But transitions to the parent node are all handled by vty_go_parent(). By popping a parent from the list of parents in vty_go_parent(), we can also detect that a command has changed the node without changing the parent, hence it must have stepped into a child node, and we can push a parent frame. The behavior on the interactive telnet VTY remains unchanged. Change-Id: I24cbb3f6de111f2d31110c3c484c066f1153aac9
Diffstat (limited to 'src/vty/vty.c')
-rw-r--r--src/vty/vty.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/vty/vty.c b/src/vty/vty.c
index 113a781c..bd0d2c37 100644
--- a/src/vty/vty.c
+++ b/src/vty/vty.c
@@ -110,6 +110,8 @@ struct vty *vty_new(void)
if (!new)
goto out;
+ INIT_LLIST_HEAD(&new->parent_nodes);
+
new->obuf = buffer_new(new, 0); /* Use default buffer size. */
if (!new->obuf)
goto out_new;
@@ -1480,6 +1482,12 @@ vty_read_file(FILE *confp, void *priv)
case CMD_ERR_NO_MATCH:
fprintf(stderr, "There is no such command.\n");
break;
+ case CMD_ERR_INVALID_INDENT:
+ fprintf(stderr,
+ "Inconsistent indentation -- leading whitespace must match adjacent lines, and\n"
+ "indentation must reflect child node levels. A mix of tabs and spaces is\n"
+ "allowed, but their sequence must not change within a child block.\n");
+ break;
}
fprintf(stderr, "Error occurred during reading the below "
"line:\n%s\n", vty->buf);