Commit Graph

86 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
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
Vadim Yanitskiy e65c8bad46 vty/command.h: document and prettify CMD_ATTR_* flags
Since the CMD_ATTR_* flags are intended to be used in bitwise
operations, let's assign them proper values. Adding a new flag
(e.g. CMD_ATTR_FOO_BAR) could actually result in assigning 0x03
instead of expected (0x01 << 2).

Change-Id: I3b1badef830f7e6436a67673b5709ec33c060c68
Related: OS#3584
2018-09-24 13:02:07 +07:00
Harald Welte 11eb4b5add vty: Add logging_vty_add_deprecated_subsys
This function permits the user to register deprecated log categories,
which will ensure that if log categories are removed from a program,
old config files will still load.

We simply dynamically allocate a cmd_element and install it at
CFG_LOG_NODE.  Not registering it at VIEW_NODE or ENABLE_NODE
ensures that it's not accessible from the interactive VTY, but only
from the config file / configure node.

Change-Id: I171f62ea2dc565b3a6c3eecd27fb7853e2529598
2018-06-09 17:43:33 +02:00
Daniel Willmann 07f075d197 ports.h: Add ctrl port for osmo-gbproxy
Change-Id: I46a1cef3013c9bbf9b5a6d64e83cd84568f2523c
2018-05-29 21:02:16 +02:00
Stefan Sperling 97d3da2c59 introduce vty_out_rate_ctr_group_fmt() function
This new function can be used to print a rate counter group according
to a format string. The intention is to generalize and replace manual
printing of counters as implemented for the 'show statistics' VTY
command of osmo-bsc.

Related: OS#3245
Related: osmo-bsc commit 71d524c059c5a5c90e7cb77d8a2134c1c68b9cde (g#9217)

Change-Id: Idb3ec12494ff6a3a05efcc8818e78d1baa6546bd
2018-05-24 18:04:56 +02:00
Pau Espin 98a7a2646b ports.h: Add VTY and CTRL ports for osmo-trx
Change-Id: Ib79cdb62d45d8c78445c7b064e58eb7e9faeccf9
2018-02-22 08:03:06 +00:00
Neels Hofmeyr 074478dc61 logging vty: tweak general 'logging' command doc
'logging' is not only for terminals, also for stderr and other log targets.

Change-Id: If1ee59c7d1073502259b7d60008206ac3d8e87a3
2017-12-20 16:00:59 +00:00
Neels Hofmeyr 58a5665ecb ports: define proper VTY and CTRL ports for OsmoHNBGW
So far it uses 2323, a development default. Instead, assign new ports,
appending to the common range of VTY and CTRL ports: 4261 and 4262.

Related: https://osmocom.org/projects/cellular-infrastructure/wiki/Port_Numbers
Related: I28bd7a97d24455f88fadc6724d45c3264ba2fce4 (osmo-gsm-manuals)
Change-Id: Ife52a968a41cb286f640006587877971ff66c1a4
2017-12-20 10:57:19 +00:00
Harald Welte abcd0e37b7 ports.h: Use same VTY port number for osmo-mgw and osmo-bsc_mgcp
It was decided that osmo-mgw as direct successor of osmo-bsc_mgcp
will use the same VTY port number (similar to osmo-nitb, osmo-bsc
and osmo-bsc-sccplite all using the same VTY port number)

Change-Id: Iec1da9f3b4d170416279f05876d9e1ae2970c577
2017-11-20 09:46:45 +00:00
Philipp Maier c0fc7940df vty: add port number for osmo-mgw
Change-Id: Ied224fe94b5152fd19e259396fbc0eaf69be4b96
2017-11-10 14:55:04 +00:00
Neels Hofmeyr 4a73d5e843 vty: deprecate now empty node commands
Following I5021c64a787b63314e0f2f1cba0b8fc7bff4f09b a deprecation of
vty_install_default() and install_default() commands is indicated.

However, compiler warnings may clutter build output or even fail strict builds,
hence I am submitting the deprecation in a separate patch.

Depends: I5021c64a787b63314e0f2f1cba0b8fc7bff4f09b
Change-Id: Icf5d83f641e838cebcccc635a043e94ba352abff
2017-11-08 02:54:54 +00: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 463deef8c2 VTY: implement talloc context introspection command
This change introduces a new command, which could be used to
inspect the application's talloc context directly from VTY.
To enable this feature, an application need to provide it's
context via the 'vty_app_info' struct, and register the VTY
command by calling the osmo_talloc_vty_add_cmds().

The new command is a sub-command of 'show':

  show talloc-context <context> <depth> [filter]

Currently the following contexts may be inspected:

  - application - a context provided by an application;
  - null - all contexts, if NULL-context tracking is enabled.

A report depth is defined by the next parameter, and could be:

  - full - full tree report, as the talloc_report_full() does;
  - brief - brief tree report, as the talloc_report() does;
  - DEPTH - user defined maximal report depth.

Also, there are two optional report filters:

  - regexp - print only contexts, matching a regular expression;
  - tree - print a specific context, pointed by specified address.

The command output is formatted the same way as in case of calling
the talloc_report() or talloc_report_full().

Change-Id: I43fc42880b22294d83c565ae600ac65e4f38b30d
2017-09-27 11:02:19 +00:00
Neels Hofmeyr 657c5b6cad vty: derive node name from prompt, use as XML ids
The 'show online-help' produces XML output with <node id="..."> ids.  We
reference those from the osmo-gsm-manuals.

Instead of numeric IDs coming from internal code, rather use a human-readable
node ID -- referencing id='config-msc' is much easier than referencing id='23'.

Add a char name[] to struct cmd_node, to hold this name. This may be provided
upon struct definition.

Since callers of the VTY API so far don't have a name yet, we would need to add
names everywhere to get meaningful node IDs. There is a way to get node ID
names without touching dependent code:

My first idea was to find out which command entered the node, i.e. command
'msc' enters the MSC_NODE. But it is impossible to derive which command entered
which node from data structs, it's hidden in the vty command definition.

But in fact all (TM) known API callers indeed provide a prompt string that
contains a logical and human readable string name. Thus, if the name is unset
in the struct, parse the prompt string and strip all "weird" characters to
obtain a node name from that. We can still set names later on, but for now will
have meaningful node IDs (e.g. 'config-msc' from '%s(config-msc)# ') without
touching any dependent code.

When VTY nodes get identical node names, which is quite possible, the XML
export de-dups these by appending _2, _3,... suffixes. The first occurence is
called e.g. 'name', the second 'name_2', then 'name_3', and so forth.

If a node has no name (even after parsing the prompt), it will be named merely
by the suffix. The first empty node will become id='_1', then '_2', '_3', and
so forth. This happens for nodes like VIEW_NODE or AUTH_NODE.

If this is merged, we need to adjust the references in osmo-gsm-manuals.git.
This can happen in our own time though, because we manually create the vty
reference xml and copy it to the osmo-gsm-manuals.git and then update the
references from the vty_additions.xml. This anyway has to happen because
currently the references tend to be hopelessly out of sync anyway, placing
comments at wildly unrelated VTY commands.

Change-Id: I8fa555570268b231c5e01727c661da92fad265de
2017-09-23 12:24:58 +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
Harald Welte bd3bb135a4 ports.h: Add VTY port for GGSN
Change-Id: I5bd49fbc19e88db96b4adbd56c82e7936059551c
2017-08-16 23:41:30 +02: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
Philipp Maier e05c1f45ed vty: additional nodes for sccp-address configuration
The planned sccp-addressbook implementation in libosmo-sccp
requires two additional VTY nodes.

See also in libosmo-sccp.git:
Change-Id I068ed7f7d113dab88424a9d47bab7fc703bb7942

Change-Id: I42aa29c0cccc97f284b85801c5329b015b189640
2017-06-21 12:56:41 +00:00
Max c65c5b4ea0 vty: cleanup logging functions
* remove unused parameter from logging_vty_add_cmds()
* mark log level descriptors static
* change internal static function int check_log_to_target() to more
  appropriate bool should_log_to_target()
* deprecate log_vty_command_*() from public API as it should only be
  used by logging_vty_add_cmds()

Change-Id: I0e9ddd7ba3ce211302d99a3494eb408907a2916e
Related: OS#71
2017-05-09 09:11:05 +00:00
Harald Welte b522740be5 vty/command.h: Introduce VTY nodes for libosmo-sigtran
This adds several VTY nodes required by the libosmo-sigtran VTY
interface.

Change-Id: I184a7e3187b48c15c71bf773f86e188fe1daad15
2017-04-14 14:01:56 +02:00
Harald Welte f7add0889c add VTY port number for osmo-stp
Change-Id: I978e1b73aa8097a7db6318d78f9f93457e6ce2af
2017-04-08 09:34:04 +02:00
Neels Hofmeyr fa5dc93fd0 ports.h: rename CSCN to MSC
See OS#1958

Change-Id: I85aee0f8fdfc9c69d0ba9240988c633d3e707f2d
2017-02-24 19:57:48 +00:00
Neels Hofmeyr 4a7f87cdc8 comment: ports.h: more visibly remind to keep docs+wiki synced
It is still too easy to forget syncing, so add another reminder at the end
of the list.

Change-Id: I95191906afa8e6ada31310d0e36de33e3fccf268
2017-01-30 12:57:47 +01:00
Neels Hofmeyr 92fa18e6b8 vty/ports.h: reserve port 4258 for OsmoHLR VTY
Change-Id: I08cb52d9399a27e6876e45da36f434708c4fddef
2017-01-28 04:02:53 +01:00
Harald Welte 3419391422 fsm: Add VTY introspection of osmo_fsm and their instances
Change-Id: I89212e4f149f019099115a85bab353c04170df90
2017-01-07 12:21:11 +00:00
Neels Hofmeyr 1a587bd782 fix GGSN Ctrl port to 4257
4253 used to collide with the sysmobts-mgr VTY port.
Note, openggsn does not actually have a Ctrl interface yet.

Change-Id: If0fa0e606dabd5bc89907a56ef18cdbbbdedb4b7
2016-09-09 16:23:18 +02:00
Neels Hofmeyr 56313c84c8 comment: */ports.h: link to wiki + manuals, indicate used ports
Change-Id: I6a7bf04e589ccfaea98f20900a9bfe9dd4808dce
2016-09-09 16:22:39 +02:00
Alexander Couzens ad580ba7c4 add vty call show asciidoc: generate a documentation for counters
For each counter group a ascii doc table is generated
containing all single counter with a reference to a section to
add additional information to the counter

Change-Id: Ia8af883167e5ee631059299b107ea83c8bbffdfb
Reviewed-on: https://gerrit.osmocom.org/70
Reviewed-by: Harald Welte <laforge@gnumonks.org>
Tested-by: Harald Welte <laforge@gnumonks.org>
2016-06-14 10:38:17 +00:00
Holger Hans Peter Freyther 793a2907d5 vty: Make a reservation for the osmo-sip-connector
The osmo-sip-connector is a new application and is a MNCC to SIP
bridge. It is not implementing transcoding or RTP proxying at all.
2016-03-31 16:59:23 +02:00
Neels Hofmeyr f81eb328b6 vty: add ctrl section for Control interface bind address
This may seem like overkill for a mere const char * config item, but it makes
the Control interface VTY commands reusable in any main() scope (inspired by
libosmo-abis' VTY config).

Add API functions ctrl_vty_init() and ctrl_vty_get_bind_addr(), in new files
src/ctrl/control_vty.c and include/osmocom/ctrl/control_vty.h, compiled and/or
installed dependent on ENABLE_VTY.

Using these functions allows configuring a static const char* with the VTY
commands

    ctrl
     bind A.B.C.D

which callers shall subsequently use to bind the Control interface to a
specific local interface address, by passing the return value of
ctrl_vty_get_bind_addr() to control_interface_setup().

Add CTRL_NODE to enum node_type, "eating" RESERVED4_NODE to heed that comment
on avoiding ABI changes.
2016-02-25 11:02:35 +01: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
Neels Hofmeyr 8684714966 Add CSCN ctrl port defs 2016-02-15 12:02:02 +01:00
Neels Hofmeyr 620dfa6be2 add vty port nr for osmo-cscn 2016-02-10 13:28:00 +01:00
Jaroslav Škarvada 2b82c1c6c8 fix FSF address in sources/headers
Signed-off-by: Jaroslav Škarvada <jskarvad@redhat.com>
2015-11-12 13:46:05 +01:00
Jacob Erlbeck 59b90bc444 stats/vty: Add selective show stats command
Currently there is only the 'show stats' command which shows all
counter and stat_item values. This can lead to many lines of output
if there are per-subscriber rate counters.

The new command added by this commit allows it to only show groups of
a certain level (class_id), similar to the 'level' configuration
command for stats reporter.

The new command is

  show stats level (global|peer|subscriber)

Sponsored-by: On-Waves ehf
2015-08-22 01:47:55 +00:00
Neels Hofmeyr 07cf861e25 gtphub: add OSMO_VTY_PORT_GTPHUB.
This is for gtphub, being developed in openbsc.git.

Sponsored-by: On-Waves ehi
2015-11-02 20:24:06 +01:00
Neels Hofmeyr 667e83d71e fix some typos
Sponsored-by: On-Waves ehi
2015-11-02 20:23:34 +01:00
Jacob Erlbeck 34eec7da8d vty: Add reserved nodes to enum node_type
Currently every time a node is added to enum node_type, this
constitutes an ABI change, since _LAST_OSMOVTY_NODE will get
incremented accordingly. In this case, every project that adds new
node type based on that value will have to be recompiled.

This commit adds 4 spare node type values, which can be replaced
one-by-one by new real types until they are exhausted to avoid
this kind of ABI change.

Sponsored-by: On-Waves ehf
2015-11-02 15:39:31 +01:00
Jacob Erlbeck fc9533d6c4 stats: Add osmo_ name prefix to identifiers
Since the the stat_item and stats functions and data types are meant
to be exported, they get an osmo_ prefix.

Sponsored-by: On-Waves ehf

[hfreyther: Prepended the enum values too. This was requested by
Jacob]
2015-11-02 15:39:01 +01:00
Jacob Erlbeck adc900e0e3 stats/vty: Add stats configuration
This commit provides stats configuration similar to the log
configuration.

The following vty commands are added to the config node:
  stats reporter statsd          Create/Modify a statsd reporter
  no stats reporter statsd       Remove a statsd reporter

To actually configure a reporter, the config-stats node is entered
when the "stats reporter" command has succeeded. The following new
vty commands are available there:
  local-ip ADDR          Set the IP address to which we bind locally
  no local-ip            Do not bind to a certain IP address
  remote-ip ADDR         Set the remote IP address to which we connect
  remote-port <1-65535>  Set the remote port to which we connect
  prefix PREFIX          Set the item/counter name prefix
  no prefix              Do not use a prefix
  enable                 Enable the reporter
  disable                Disable the reporter

Sponsored-by: On-Waves ehf
2015-10-29 01:10:06 +01:00
Jacob Erlbeck 45513e6040 stats/vty: Add stats_vty.c
This file will contain the VTY code related to statistics.

This commit adds a minimal file with just as single VTY command:

- show stats    This command shows all statistical values

To enable this and future commands, the main program needs to call
stats_vty_add_cmds().

Sponsored-by: On-Waves ehf
2015-10-29 00:09:04 +01:00
Jacob Erlbeck 7211fe157e stat/vty: Add vty_out_statistics_full to show all statistics
This functions shows the state of all osmo_counters, stat_item
groups, and counter groups.

Sponsored-by: On-Waves ehf
2015-10-28 23:53:46 +01:00
Jacob Erlbeck 738d9e2210 stats: Add vty_out_stat_item_group
This functions dumps a whole stat item group to the VTY.

Sponsored-by: On-Waves ehf
2015-10-28 23:51:12 +01:00
Holger Hans Peter Freyther a9e5252128 vty: Change API to have node installation be done by int
We are mixing enums and hope that no short-enums are used. This
is leading to a lot compiler warnings generated by clang. Change
the API to work with integers.

Porting:
The go_parent_cb implementations in the applications need to be
fixed. The API change leads to a compile time warning.

Fixes:
abis_om2000_vty.c:46:2: warning: implicit conversion from enumeration type 'enum bsc_vty_node' to
      different enumeration type 'enum node_type' [-Wenum-conversion]
        OM2K_NODE,
        ^~~~~~~~~
2015-08-05 04:22:56 +00:00
Holger Hans Peter Freyther 9f0f978c8d vty: Check with the application before writing the config
For the BSC/NITB application we see that people modify the band
without modifying the ARFCN. This creates an unbootable config.
Using the new hook the BSC/NITB can check if the config is
consistent and prevent the config file being written.

Related: SYS#739
2014-12-04 14:39:14 +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
Harald Welte f39aed6942 add port number 4238 for BTS control interface 2014-08-24 16:52:54 +02:00
Harald Welte 28570a4e62 new <osmocom/vty/ports.h> file listing VTY tcp ports
imported from http://openbsc.osmocom.org/trac/wiki/PortNumbers
2014-08-21 15:34:11 +02:00