Commit Graph

43 Commits

Author SHA1 Message Date
Neels Hofmeyr c1aa178c8b vty api: add vty_out_va()
Provide a va_list type vty_out() variant, to be able to pass on variable
arguments from other function signatures to vty_out().

This will be used by Ibd6b1ed7f1bd6e1f2e0fde53352055a4468f23e5 for osmo_tdef.

Change-Id: Ie6e6f11a6b794f3cb686350c1ed678e4d5bbbb75
2019-02-04 16:43:57 +00:00
Neels Hofmeyr 8d04f95d96 vty telnet: consistently never change nodes upon CTRL-C
Remove any special node exiting from the VTY CTRL-C handling.

From a curious VTY transcript test glitch, I noticed weird behavior by the VTY
telnet shell: usually, when the user hits CTRL-C, that means to cancel the
current command line and present a fresh, clean prompt. However, only on the
CONFIG_NODE and CFG_LOG_NODE, a CTRL-C also exits the current node and moves up
by one level. This behavior is unexplainable and makes zero sense.

No other nodes exit on CTRL-C:
- on the ENABLE node, a CTRL-C stays on the ENABLE_NODE and doesn't exit to the
  VIEW_NODE.
- any sub-nodes of the CONFIG_NODE stay unchanged, e.g. 'network' or 'bts' /
  'trx', etc.

There is no apparent special meaning of CTRL-C on CONFIG_NODE nor CFG_LOG_NODE
to justify this odd choice.

Particularly, the vty transcript tests using osmo_verify_transcript_vty.py rely
on sending CTRL-C to clear the command prompt, so that we can properly test
sending '?' to the VTY during transcripts. In a live session, a '?' prints
available options and then updates the prompt with identical command arguments.
In a transcript test, that doesn't make sense, because each time the transcript
writes out a new command to run. Consider e.g. a transcript test like:

	tdef_vty_test(config)# timer ?
	  tea       Tea time
	  test      Test timers
	  software  Typical software development cycle

	tdef_vty_test(config)# timer tea ?
	  [TNNNN]  T-number, optionally preceded by 't' or 'T'.

To be able to issue a fresh command after '?', osmo_verify_transcript_vty.py
explicitly sends a CTRL-C to clear the command buffer. Hence there we rely on
predictable behavior of CTRL-C.

More particularly, the upcoming osmo_tdef_vty transcript tests are apparently
the first that want to test '?' behavior on the CONFIG_NODE's root level and
fall on their face, because of the implicit exit that happens only there.

Change-Id: I4f339ba61f1c273fa7da85caf77ba116ae2697b1
2019-02-04 16:43:57 +00:00
Harald Welte 34d54b2ba7 Fix VTY documentation error introduced in "bind" VTY port change
In 99ae401e49 we introduced the ability
to specify the TCP port to which the VTY should bind.  However, the VTY
dcumentation wasn't extended accordingly, causing virtually all master
build jobs to fail.

Change-Id: I54fb0ca0d3a884a64a349b22de70f3d9bd1a6d54
2018-12-23 10:27:45 +01:00
Holger Hans Peter Freyther 99ae401e49 vty: Make TCP port configurable and introduce telnet_init_default
Extend the vty_bind_cmd VTY command to allow to optionally specify
a port in addition to the IPv4 address.

Introduce telnet_init_default to relieve client code from having
to query the bind IPv4 address (and now the TCP port). Instead a
client only needs to pass the default TCP port to use.

Client code should use it like:

	int rc = telnet_init_default(ctx, priv, OSMO_VTY_PORT_SGSN);

Change-Id: Id5fb2faaf4311bd7284ee870526a6f87b7e260f3
2018-12-23 04:20:08 +00:00
Harald Welte 2e0a945d3d vty.c: Set vty->fd to -1 after closing the FD
Change-Id: I07d105f4a810dd809fbf6feb5c04e7410020c887
2018-10-21 13:46:07 +02:00
Mykola Shchetinin 893e49e993 vty/vty.c: fix bug in vty_config_write
the vty_config_write function should write:
line vty
 login
to the configuration file when the login is enabled. Otherwise after
saving the configuration the next login will be performed without
password checking (password_check variable will be 0 though it must be 1)

Change-Id: I39050b6bf617dac10d3fccc3106f67bdcca1d05a
2018-08-05 07:01:53 +00:00
Vadim Yanitskiy baed91709c vty/vty.c: remove dead unused tall_bsc_ctx
Change-Id: I160728544c0effe45757df22f1ff2314fcb13dd1
2018-07-30 03:43:00 +07:00
Alexander Couzens ab383e6d27 vty: initialize termios before using it
valgrind complains about using unitialised bytes in syscalls.
I could imagine this happens when tcgetattr fails to set termios.

Change-Id: I9d165911fa3127afa8f836fa5c5c2e14a949474a
2018-07-20 20:40:48 +00:00
Harald Welte a2501a2065 VTY: Don't welcome the user to the "control" interface, if it's VTY
This is quite confusing, I'm surprised that it has not been flagged
before...

Change-Id: I3dc07290579949891e481675d493e5a2ea6d0aed
2018-03-27 07:21:46 +00:00
Harald Welte e08da97570 Fix/Update copyright notices; Add SPDX annotation
Let's fix some erroneous/accidential references to wrong license,
update copyright information where applicable and introduce a
SPDX-License-Identifier to all files.

Change-Id: I39af26c6aaaf5c926966391f6565fc5936be21af
2017-11-13 01:35:12 +09:00
Neels Hofmeyr f4f23bd682 vty: install 'exit', 'end',... commands on *all* nodes
In many callers of the VTY API, we are lacking the vty_install_default() step
at certain node levels. This creates nodes that lack the 'exit' command, and
hence the only way to exit such a node is to restart the telnet session.

Historically, the VTY looked for missing commands on the immediate parent node,
and hence possibly found the parent's 'exit' command when the local node was
missing it. That is why we so far did not notice the missing default commands.

Furthermore, some callers call install_default() instead of
vty_install_default(). Only vty_install_default() also includes the 'exit' and
'end' commands. There is no reason why there are two sets of default commands.

To end this confusion, to catch all missing 'exit' commands and to prevent this
from re-appearing in the future, simply *always* install all default commands
implicitly when calling install_node().

In cmd_init(), there are some top-level nodes that apparently do not want the
default commands installed. Keep those the way they are, by changing the
invocation to new install_node_bare() ({VIEW,AUTH,AUTH_ENABLE}_NODE).

Make both install_default() and vty_install_default() no-ops so that users of
the API may still call them without harm. Do not yet deprecate yet, which
follows in Icf5d83f641e838cebcccc635a043e94ba352abff.

Drop all invocations to these two functions found in libosmocore.

Change-Id: I5021c64a787b63314e0f2f1cba0b8fc7bff4f09b
2017-09-27 14:04:09 +00:00
Vadim Yanitskiy 5584a14a31 vty/vty.c: do not bind vty context to application's one
The 'vty_app_info' struct could be used by some applications to
provide its talloc context. In the future, it will facilitate
the implementation of talloc context introspection via VTY.

But the 'vty' talloc context, that contains lots of items
(memory chunks), is being bound to an application's one,
so it becomes hard to read the last.

Let's do not bind the 'vty' context automatically, until some
common talloc context export policy is implemented.

Change-Id: I9cb6ce9f24dbae400029e2d9f9c933fbfb16248f
2017-09-27 11:02:18 +00:00
Neels Hofmeyr 4a31ffa2f0 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
2017-09-19 01:35:30 +00:00
Keith Whyte 03516d6dd2 cosmetic: clarify language in vty read error
This is very minor but it annoys every time I see it.
The text: "Error occurred during reading below line:"
is not a complete sentence. The default understanding
in english having left out the article implies
that the error occured reading below [the] specified line, not
that the error occured reading [the] specified line.

That is to say, The message implied that the printed line
was the last successfully parsed line.

Change-Id: Ib4dd135feb9609b14983db5dac321a70267d8f30
2017-09-05 10:44:22 +00:00
Neels Hofmeyr 17518fe393 doxygen: unify use of \file across the board
Considering the various styles and implications found in the sources, edit
scores of files to follow the same API doc guidelines around the doxygen
grouping and the \file tag.

Many files now show a short description in the generated API doc that was so
far only available as C comment.

The guidelines and reasoning behind it is documented at
https://osmocom.org/projects/cellular-infrastructure/wiki/Guidelines_for_API_documentation

In some instances, remove file comments and add to the corresponding group
instead, to be shared among several files (e.g. bitvec).

Change-Id: Ifa70e77e90462b5eb2b0457c70fd25275910c72b
2017-06-23 00:18:23 +00:00
Neels Hofmeyr 87e4550585 doxygen: enable AUTOBRIEF, drop \brief
Especially for short descriptions, it is annoying to have to type \brief for
every single API doc.

Drop all \brief and enable the AUTOBRIEF feature of doxygen, which always takes
the first sentence of an API doc as the brief description.

Change-Id: I11a8a821b065a128108641a2a63fb5a2b1916e87
2017-06-23 00:18:22 +00:00
Harald Welte 96e2a00d7a update/extend doxygen documentation
It's a pity that even with this patch we still are fare away from having
the whole API documented.  However, at least we have a more solid
foundation.  Updates not only extend the documentation, but also make
sure it is rendered properly in the doxygen HTML.

Change-Id: I1344bd1a6869fb00de7c1899a8db93bba9bafce3
2017-06-12 21:55:54 +00:00
Harald Welte 7165880ac2 Update doxygen main page for libosmo{core,gsm,vty}
We should link to project homepage as well as put the library into the
wider Osmocom context.

Change-Id: I07ca57ecef0f36c87c9ebacc1e1507c217bdb25b
2017-06-12 20:07:09 +00:00
Neels Hofmeyr 898e1d878e vty: use VTY_BIND_ADDR_DEFAULT instead of "127.0.0.1"
Change-Id: Ice0688ac9847524cb546f6d41547090b6a3cb3d8
2016-08-20 16:33:47 +02:00
Neels Hofmeyr 96172f0100 vty: add bind command for telnet vty line
Add VTY command
    line vty
     bind A.B.C.D

The command merely stores the configured IP-address, which can then be used by
the calling main program to set the telnet port of the VTY line. (Commits in
openbsc and osmo-iuh will follow up on this.)

Add function vty_get_bind_addr() to publish the address in the vty.h API.

Add static vty_bind_addr to store.

For allocation/freeing reasons, a NULL address defaults to 127.0.0.1.

BTW, I decided against allowing keywords 'any' and 'localhost' in place of an
actual IP address to make sure a written config is always identical to the
parsed config.
2016-02-25 11:02:34 +01:00
Holger Hans Peter Freyther d56c3cbb2c vty: Use NULL to have a null pointer instead of '\0'
'\0' gets translated to zero but the argument to vector_set is
a pointer and it gets converted to a pointer.

vty.c:985:21: warning: expression which evaluates to zero treated as a null pointer constant of type
      'void *' [-Wnon-literal-null-conversion]
                vector_set(vline, '\0');
                                  ^~~~
vty.c:1095:21: warning: expression which evaluates to zero treated as a null pointer constant of type
      'void *' [-Wnon-literal-null-conversion]
                vector_set(vline, '\0');
                                  ^~~~
vty.c:1097:21: warning: expression which evaluates to zero treated as a null pointer constant of type
      'void *' [-Wnon-literal-null-conversion]
                vector_set(vline, '\0');
                                  ^~~~
2015-11-09 16:16:00 +00:00
Harald Welte 78a870ed0f remove references to u_long type, use 'unsigned long' instead
.. Nuttx doesn't know u_long
2014-11-14 15:22:22 +01:00
Harald Welte 7b74dda31b remove references to u_char type, use 'unsigned char' instead
... u_char not being defined on Nuttx.
2014-11-14 15:22:14 +01:00
Holger Hans Peter Freyther eb55e6aa88 write_queue: Use EBADF instead of EBABDFD for portability
EBADFD is linux specific while EBADF is POSIX. Fix the build on
FreeBSD and use EBADF throughout the file.
2014-07-01 19:42:49 +02:00
Daniel Willmann 77ab2f723e vty: Avoid use-after-free in VTY telnet interface
If the read callback closes the connection conn is already freed so we
can't derefernce it. Instead return -EBADFD in the read function if it
closed the connection and check for that.
2014-06-22 16:57:22 +02:00
Jacob Erlbeck 0c987bd83b vty: Add vty_install_default() and use for the vty nodes
This adds the vty_install_default() function that is basically the
install_default() function plus the registration of the commands
'exit' and 'end'. The latter is only provided in subnodes of
ENABLED_NODE and CONFIG_NONE.

The VTY test program is extended to check these commands.

Ticket: OW#952
2013-09-08 10:49:52 +02:00
Holger Hans Peter Freyther 314c010733 vty: Address compiler warning about the const qualifier
vty.c: In function 'vty_out_newline':
vty.c:294:12: warning: initialization discards 'const' qualifier from pointer target type [enabled by default]
2012-09-11 10:40:07 +02:00
Holger Hans Peter Freyther ea8f238f04 vty: Print the string using "%s", string to avoid security issues
The Mandriva GCC is more strict about handling format strings, the
copyright string might contain escape sequences and then any memory
could be read.
2012-08-02 21:26:02 +02:00
Alexander Huemer e62651f220 correct inverted logic from commit f3ba8a 2012-07-11 11:00:02 +02:00
Diego Elio Pettenò f3ba8abc97 vty: avoid using a .data variable.
no_password_check was the only initialized, non-relocated data in the
set of libraries, inverting its logic let us keep it in .bss
(non-initialized data, which is mapped to the zero page).

Signed-off-by: Diego Elio Pettenò <flameeyes@flameeyes.eu>
2012-06-30 22:01:44 +02:00
Harald Welte 2d52d10a52 add additional newline in vty welcome message 2012-06-16 17:01:29 +08:00
Harald Welte 8b0d5b3726 VTY: safe version of printing VTY welcome message
The old method used raw writes to the telnet FD, which is bad for
several reasons:
  a) we don't know if we can actually write that many bytes to the
     socket at the given time
  b) the socket is still in blocking mode, so we could stall the entire
     process
  c) there may be weird interaction with the buffered writes of the
     vty_out

Now, the print_welcome() functionality has moved to vty_hello() instead,
where we can use normal vty_out() in buffered mode.

This commit is expected to fix the garbled welcome message on arm-eglibc
targets.

It might still be a good idea to migrate the entire telnet interface to
libtelnet - but at some later time ;)
2012-06-03 12:44:38 +02:00
Sylvain Munaut dca7d2caaa doc: Fix the Doxygen section endings
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
2012-04-18 21:53:23 +02:00
Andreas.Eversberg f948dbc442 vty: Fixed vty_down_level to move down from config nodes
When using ^D at config nodes above the CONFIG_NODE, the
go_parent_cb function is used to go down by one node. This
is equivalent to "exit" command.

Written-by: Andreas.Eversberg <jolly@eversberg.eu>
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
2011-11-12 23:23:36 +01:00
Harald Welte d38c8b88d7 doxygen: Add main page for all three libraries 2011-08-30 11:32:56 +02:00
Harald Welte 7acb30c69b doxygen: Add (partial) VTY API documentation 2011-08-17 17:14:12 +02:00
Harald Welte 95b2b47b26 get rid of non-ANSI function declarations missing (void)
Detected by Smatch
2011-07-16 12:03:46 +02:00
Pablo Neira Ayuso 8341934844 include: reorganize headers file to include/osmocom/[gsm|core]
This patch moves all GSM-specific definitions to include/osmocom/gsm.
Moreover, the headers in include/osmocore/ have been moved to
include/osmocom/core.

This has been proposed by Harald Welte and Sylvain Munaunt.

Tested with `make distcheck'.

Signed-off-by: Pablo Neira Ayuso <pablo@gnumonks.org>
2011-03-23 18:09:28 +01:00
Harald Welte 2822296ddb LOGGING: configure logging from the vty
We can now configure logging to (multiple) files, stderr and syslog
from the vty command line in a persistent way (config file)
2011-02-18 20:37:04 +01:00
Harald Welte df327f6d81 Use the app_info->name instead of the hostname
This makes more sense in case you run BCS, SGSN and other components
on the same host.  Having multiple telnet sessions with the same
prompt can otherwise be confusing.
2010-12-24 15:10:14 +01:00
Holger Hans Peter Freyther 08aaded3b8 vty: Add functions to access index and node
It is easier to call these two functions from bindings than
wrapping the vty structure and figuring out the alignment of
the enum on all different ABIs.
2010-09-14 02:24:03 +08:00
Harald Welte 237f6241f2 [VTY] Introduce "struct vty_app_info" for vty_init() function 2010-05-25 23:38:19 +02:00
Harald Welte 3fb0b6f26e Create libosmovty as library from OpenBSC VTY functions 2010-05-25 22:28:39 +02:00