libosmocore/tests/vty
Neels Hofmeyr d31de23758 vty: track parent nodes also for telnet sessions
Keep track of parent nodes and go back hierarchically, not only for .cfg file
reading, but also for telnet VTY sessions.

A long time ago cfg file parsing was made strictly hierarchical: node exits go
back to parent nodes exactly as they were entered. However, live telnet VTY
sessions still lacked this and depended on the go_parent_cb().

From this commit on, implementing a go_parent_cb() is completely optional. The
go_parent_cb() no longer has the task to determine the correct parent node,
neither for cfg files (as already the case before this patch) nor for telnet
VTY sessions (added by this patch). Instead, a go_parent_cb() implementation
can merely take actions it requires on node exits, for example applying some
config when leaving a specific node.

The node value that is returned by the go_parent_cb() and the vty->node and
vty->index values that might be set are completely ignored; instead the
implicit parent node tracking determines the parent and node object.

As a side effect, the is_config_node() callback is no longer needed, since the
VTY now always implicitly knows when to exit back to the CONFIG_NODE.

For example, osmo_ss7_is_config_node() could now be dropped, and the
osmo_ss7_vty_go_parent() could be shortened by five switch cases, does no
longer need to set vty->node nor vty->index and could thus be shortened to:

int osmo_ss7_vty_go_parent(struct vty *vty)
{
        struct osmo_ss7_asp *asp;
        struct osmo_xua_server *oxs;

        switch (vty->node) {
        case L_CS7_ASP_NODE:
                asp = vty->index;
                /* If no local addr was set */
                if (!asp->cfg.local.host_cnt) {
                        asp->cfg.local.host[0] = NULL;
                        asp->cfg.local.host_cnt = 1;
                }
                osmo_ss7_asp_restart(asp);
                break;
        case L_CS7_XUA_NODE:
                oxs = vty->index;
                /* If no local addr was set, or erased after _create(): */
                if (!oxs->cfg.local.host_cnt)
                        osmo_ss7_xua_server_set_local_host(oxs, NULL);
                if (osmo_ss7_xua_server_bind(oxs) < 0)
                        vty_out(vty, "%% Unable to bind xUA server to IP(s)%s", VTY_NEWLINE);
                break;
        }
        return 0;
}

Before parent tracking, every program was required to write a go_parent_cb()
which has to return every node's parent node, basically a switch() statement
that manually traces the way back out of child nodes. If the go_parent_cb() has
errors, we may wildly jump around the node tree: a common error is to jump
right out to the top config node with one exit, even though we were N levels
deep. This kind of error has been eliminated for cfg files long ago, but still
exists for telnet VTY sessions, which this patch fixes.

This came up when I was adding multi-level config nodes to osmo-hlr to support
Distributed GSM / remote MS lookup: the config file worked fine, while vty node
tests failed to exit to the correct nodes.

Change-Id: I2b32b4fe20732728db6e9cdac7e484d96ab86dc5
2019-11-24 19:59:35 +01:00
..
fail_cmd_ret_warning.cfg vty: Return error if cmd returns CMD_WARNING while reading cfg file 2019-10-28 19:15:29 +00:00
fail_not_de-indented.cfg vty_test: add artificial node levels for better testing 2017-09-20 03:32:24 +02:00
fail_tabs_and_spaces.cfg vty_test: add artificial node levels for better testing 2017-09-20 03:32:24 +02:00
fail_too_much_indent.cfg vty_test: add artificial node levels for better testing 2017-09-20 03:32:24 +02:00
ok.cfg vty_test: add artificial node levels for better testing 2017-09-20 03:32:24 +02:00
ok_deprecated_logging.cfg logging/vty: fix: actually ignore deprecated logging commands 2019-11-21 10:48:02 +07:00
ok_empty_parent.cfg vty_test: add artificial node levels for better testing 2017-09-20 03:32:24 +02:00
ok_ignore_blank.cfg vty_test: add artificial node levels for better testing 2017-09-20 03:32:24 +02:00
ok_ignore_comment.cfg vty_test: add artificial node levels for better testing 2017-09-20 03:32:24 +02:00
ok_indented_root.cfg vty_test: add artificial node levels for better testing 2017-09-20 03:32:24 +02:00
ok_more_spaces.cfg vty_test: add artificial node levels for better testing 2017-09-20 03:32:24 +02:00
ok_tabs.cfg vty_test: add artificial node levels for better testing 2017-09-20 03:32:24 +02:00
ok_tabs_and_spaces.cfg vty_test: add artificial node levels for better testing 2017-09-20 03:32:24 +02:00
vty_test.c vty: track parent nodes also for telnet sessions 2019-11-24 19:59:35 +01:00
vty_test.ok logging/vty: fix: actually ignore deprecated logging commands 2019-11-21 10:48:02 +07:00
vty_transcript_test.c vty: tests: Verify incomplete optional parameters are passed to vty funcs 2019-06-14 12:43:19 +02:00
vty_transcript_test.vty vty: command.c: Fix: single-choice optional args are no longer passed incomplete to vty func 2019-06-14 17:44:21 +02:00