Commit Graph

310 Commits

Author SHA1 Message Date
Harald Welte 8d6ca6933f logging_vty: Fix saving of "logging print file .. last"
Back in 2018 in I393907b3c9e0cc1145e102328adad0a83ee13a9f Neels
introduced "last" as an optional flag to log the file/line number at the
end of the line, rather than at the end of the header.  It seems nobody
has been usingi this feature, or at least never tried to save a related
config file, as there was no code whatsoever that would ever save this
optional "last" flag.

Change-Id: I7b6245256aecc425722242aaabc154ac58ba27a0
2021-01-21 10:23:19 +01:00
Harald Welte cec4bbed73 vty/fsm_vty: Add vty_out_fsm2() + vty_out_fsm_inst2() with prefix
Callers other than "show fsm" / "show fsm-instances" may want to
indent the output.

Change-Id: I10e01ef91116369868cdb878a99634c8681728af
2021-01-20 14:59:03 +00:00
Harald Welte c296e2921a vty: Fix left shifting out of range on signed variable
Fixes following ASan runtime errors while running vty tests:
command.c:730:27: runtime error: left shift of 1 by 31 places cannot be represented in type 'int'

Somehow we didn't catch this one in Ie11ff18d6fd9f6e1e91a51b6156fb6b0b7d3a9a8

Change-Id: I601caf7daa947f3cf391316f1011007ef9188c90
2020-12-21 15:45:45 +01:00
Vadim Yanitskiy 7031ac1dd2 vty/command: add 'hidden only' VTY reference generation mode
Change-Id: I511ce26350cd04bb0f66d130b5286cab84f16df2
Related: SYS#4910
2020-11-17 16:23:11 +07:00
Pau Espin 64c67bb088 vty: Mark cpu_sched_vty commands with attr immediate
Change-Id: I85c80376c13c7dddf34dadd2a6c09caf23fd70ce
2020-11-09 11:24:21 +01:00
Vadim Yanitskiy 0a2d9bdfae vty/command: fix: restrict the expert mode to the current session
Having the expert mode flag stored in the global 'host' structure
was a bad idea, because this way it applies globally.  In other
words, if user Bob activates the expert mode in his dedicated
session (e.g. a telnet connection), then not only him, but all
other users would see the hidden commands in their VTYs.

Moreover, if somebody deactivates the expert mode, it would also
affect the Bob's VTY session.  And finally, terminating a VTY
session would not deactivate the expert mode.

Let's move that flag from the global 'struct host' to 'struct vty'
representing an individual VTY session, so then the expert mode
would only affect the session where it was activated.

In functions related to the XML VTY reference generation we don't
have access to 'struct vty' (there may be no VTY session at all).
Add two additional arguments to vty_dump_nodes(), indicating the
global flag mask and a matching mode.  This would allow to match
the VTY commands in many different ways, e.g. one can dump hidden
commands only, or all commands except the library specific ones.

Change-Id: Iba13f0949061e3dadf9cf92829d15e97074fe4ad
Related: SYS#4910
2020-10-25 16:52:42 +07:00
Vadim Yanitskiy 6760845da6 vty/command: add CMD_ATTR_HIDDEN to CMD_ATTR_PUBLIC_MASK
Otherwise in the expert mode, hidden commands do not get the
associated attribute printed to the XML VTY reference.

Change-Id: I8ded973031beb6d8c7ad55f06641c9651b1d9e71
Related: OS#4910
2020-10-23 20:37:37 +07:00
Vadim Yanitskiy 4165d048f3 vty/command: introduce vty_dump_xml_ref_mode()
This change introduces an enumerated type 'vty_ref_gen_mode' that
(as the name suggests) defines the VTY reference generation mode:

  - DEFAULT - all commands except deprecated and hidden,
  - EXPERT - all commands including hidden, excluding deprecated;

and a new function vty_dump_xml_ref_mode(), that allows to specify
that mode.  The old vty_dump_xml_ref() is now deprecated.

Change-Id: Ie2022a7f9e167e5ceacf15350c037dd43768ff40
Related: SYS#4910
2020-10-23 20:20:23 +07:00
Vadim Yanitskiy efe1342b62 vty/command: make some 'struct cmd_element' pointers const
Change-Id: I4a8b3bada44538a5e5711bbc4dccf8b2cf3e2e08
2020-10-21 20:36:21 +07:00
Vadim Yanitskiy 72b90883f9 vty: introduce the expert mode and a command to enable it
Some VTY commands are intentionally hidden, e.g. because they might
by relatively dangerous if used in production operation.  We equip
such commands with a special attribute - CMD_ATTR_HIDDEN.

The problem is that neiter they appear in the XML VTY reference,
nor in the online VTY help, so it's a bit tricky to invoke them.
This change introduces so-called 'expert' mode, in which hidden
(but not deprecated) commands are getting visible.

In the (telnet) VTY session, this mode can be activated by passing
an additional argument to well-known 'enable' command:

  OsmoApp> enable ?
    [expert-mode]  Enable the expert mode (show hidden commands)
  OsmoApp> enable expert-mode
  OsmoApp#

so then hidden commands will appear together with all the other
commands.  They will be marked with a special '^' flag:

  OsmoApp# list with-flags
    ^ ...  foo-hidden [expert-mode]
    . ...  foo-regular-one
    ! ...  foo-immediate
    ^ u..  app-hidden-unbelievable

For the XML reference generation, additional API needs to be
introduced.  This will be implemented in subsequent patches.

Change-Id: Ie69c2a19b22fb31d7bd7f6412f0aeac86ea5048f
Related: SYS#4910
2020-10-21 06:27:48 +07:00
Vadim Yanitskiy e7bf4354b9 logging: introduce 'systemd-journal' target
This change implements 'systemd-journal' logging target, that is
similar to the existing 'syslog' target.  The key difference is
that 'systemd-journal' allows us to offload rendering of the meta
information, such as location (file name, line number), subsystem,
and logging level, to systemd.  Moreover, we can attach arbitrary,
user-specific fields [1] to the logging messages, so they can be
used for advanced log filtering (e.g. by IMSI/TMSI/TLLI):

  $ journalctl OSMO_SUBSYS=DMSC -f

Since we don't want to make libsystemd a required dependency, this
feature is optional, and needs to be enabled at build-time:

  $ ./configure --enable-systemd-logging

The new logging target can be configured in the same way as any
other one - via the VTY interface, or using the configuration file:

  log systemd-journal [raw]
    logging level set-all notice
    logging filter all 1

Two logging handlers are available: generic and raw.  The first one
behaves similarly to both 'syslog' and 'stderr', i.e. all the meta
information is rendered by libosmocore itself, and then passed to
systemd together with the logging message.  The later is more like
the 'gsmtap' target, so all available meta information is handed
over to systemd in form of fields [1]:

  - CODE_FILE / CODE_LINE - location info,
  - PRIORITY - syslog-compatible logging level,
  - OSMO_SUBSYS - Osmocom-specific sub-system (e.g. DMSC),
  - OSMO_SUBSYS_HEX - same as OSMO_SUBSYS, but encoded in hex,
  - MESSAGE - the logging message itself,

and then can be rendered in any supported format (e.g. JSON).

More details about the API can be found in [2].

[1] https://www.freedesktop.org/software/systemd/man/systemd.journal-fields.html
[2] https://www.freedesktop.org/software/systemd/man/sd-journal.html

Change-Id: I609f5cf438e6ad9038d8fc95f00add6aac29fb23
2020-10-19 15:02:00 +00:00
Pau Espin 5bc9f3854d cosmetic: vty: Fix trailing whitespace
Change-Id: Ieea7d13161440326d58f80f1fbc9f7e3fa5a40af
2020-10-12 15:09:37 +00:00
Pau Espin 715a612aba vty: Fix left shifting out of range on signed variable
Fixes following ASan runtime errors while running vty tests:
src/vty/command.c:3088:27: runtime error: left shift of 1 by 31 places cannot be represented in type 'int'
src/vty/command.c:3136:23: runtime error: left shift of 1 by 31 places cannot be represented in type 'int'

Change-Id: Ie11ff18d6fd9f6e1e91a51b6156fb6b0b7d3a9a8
2020-10-12 15:09:37 +00:00
Philipp Maier a5218ea9b3 command: add library command attribute for libosmo-abis
Change-Id: I0efc57f2cb54798ba207ae6fef9af4771d96bfa9
Related: SYS#4937, OS#1601
2020-10-08 19:08:17 +02:00
Vadim Yanitskiy f1fc9d3af5 vty: fix vty_dump_element(): do not print empty <attributes>
Some attributes like CMD_ATTR_LIB_COMMAND are not being printed
to the XML VTY reference (despite being set), so we should not
print empty "<attributes scope='global'></attributes>".

Change-Id: Ie7e53b080c10564bfef6f0e8ddeb470e46fad387
Related: SYS#4937
2020-10-07 14:17:02 +07:00
Vadim Yanitskiy ef4c597b4a vty/command: restrict the use of '.', '!', and '@' as flags
Change-Id: Icb4acbab0a15de2b0ed7b88fb0e227675317146a
Related: SYS#4937
2020-10-07 14:17:02 +07:00
Vadim Yanitskiy 7e1a78fb03 vty/command: assign flags to CMD_ATTR_{IMMEDIATE,NODE_EXIT}
Change-Id: I77c1ef7ca4c667c769cc53c7ac65c3be5c7e1c86
Related: SYS#4937
2020-10-07 14:17:02 +07:00
Vadim Yanitskiy 75fec3a419 vty/command: print attribute flags in the output of 'list'
Here is an example:

  OsmoAPP(config-foo)# list with-flags
    ...  help
    ...  list
    ...  show running-config
    ...  exit
    ..F  lib-command foo (one|two|three)
    ZB.  lib-command bar [zoo]
    .bf  app-command foo-bar
    z..  app-command zoo .TEXT
    ...  app-command nope

A dot indicates that the associated attribute is not set.

Note that there is no strict relation between rows and index values
of the attributes.  In the example above there could be one or more
hidden flag rows corresponding to attributes that are not assigned
to any of the commands within 'config-foo' node.

If neither of the commands belonging to the current node (where
'list' command is executed) has attributes, the output would
not contain empty dot-rows.

Global attributes (such as CMD_ATTR_IMMEDIATE) are not yet displayed
because we still have not agreed on what kind of symbols to assign
them.  This will be implemented later.

Change-Id: I71cef3ec0fab44c7e11fc353b8bc42268a4ee8f0
Related: SYS#4937
2020-10-07 12:18:10 +07:00
Vadim Yanitskiy 44c4d17d40 vty/command: introduce a command to list attributes
Here is an example of listing all attributes:

  OsmoBSC# show vty-attributes
    Global attributes:
      .  This command is deprecated
      .  This command is hidden
      .  This command applies immediately
      .  This command applies on VTY node exit
    Library specific attributes:
      (no attributes)
    Application specific attributes:
      o  This command applies on A-bis OML link (re)establishment
      r  This command applies on A-bis RSL link (re)establishment

or only a specific kind of attributes:

  OsmoBSC# show vty-attributes application
    Application specific attributes:
      o  This command applies on A-bis OML link (re)establishment
      r  This command applies on A-bis RSL link (re)establishment

Change-Id: I561114d7416e30cc06b7d49c0bc1217a76039c99
Related: SYS#4937
2020-10-07 04:01:48 +07:00
Philipp Maier 608b1a40ff command: add library command attribute for libosmo-sccp
Change-Id: I4439a414af05700cb1ccff7e7e5927ffc194d171
Related: SYS#4937, OS#1601
2020-10-06 16:42:58 +02:00
Vadim Yanitskiy c0745ebc28 vty/command: introduce API for the library specific attributes
See https://lists.osmocom.org/pipermail/openbsc/2020-October/013278.html.

Change-Id: I15184569635b3ef7dfe9eeddcc19bf16cc358f66
Related: SYS#4937
2020-10-06 00:22:26 +07:00
Vadim Yanitskiy 8e7c49649e vty: use install_lib_element() and install_lib_element_ve()
See https://lists.osmocom.org/pipermail/openbsc/2020-October/013278.html.

Change-Id: Ic541126ffd4975daf87199abfafb465e2055e44f
Related: SYS#4937
2020-10-06 00:22:22 +07:00
Vadim Yanitskiy 99d5c2d721 vty/command: add CMD_ATTR_LIB_COMMAND and install() API wrappers
This new attribute would allow to distinguish commands provided
by libraries from commands registered by the application itself,
so vty_dump_element() would print proper description for the
library specific attributes.

All VTY commands defined by the libraries need to use the new API:

  - install_lib_element(), and
  - install_lib_element_ve,

instead of the old functions (respectively):

  - install_element(), and
  - install_element_ve().

See https://lists.osmocom.org/pipermail/openbsc/2020-October/013278.html.

Change-Id: I8baf31ace93c536421893c2aa4e3d9d298dcbcc6
Related: SYS#4937
2020-10-06 00:22:06 +07:00
Vadim Yanitskiy ceb3b39440 vty/command: add global command attribute CMD_ATTR_NODE_EXIT
Change-Id: I56306f4886a72a3525b60225721aa2fcf7c57213
Related: SYS#4937
2020-10-06 00:20:37 +07:00
Vadim Yanitskiy f94355dc68 vty: check for reserved flags in application specific attributes
We agreed to reserve uppercase flag letters for libraries.

Change-Id: If0c332f7c86ff26a4060a14b947445d194a6702e
Related: SYS#4937
2020-10-06 00:14:18 +07:00
Vadim Yanitskiy 024e1957cc vty: check for duplicate flags in application specific attributes
This would facilitate detecting duplicates on early development stages.

Change-Id: I4e27d6e89d3f851b5ea4f00da01e7093afa537b2
Related: SYS#4937
2020-10-04 20:55:39 +00:00
Harald Welte e4d9a2c5eb logging_vty: set osmo_stderr_target to NULL on "no log stderr"
We cannot keep a reference to the old log_target around if we
just destroyed/deleted it.

Change-Id: I98a801cf83347a4422534d020d5ed5e2d1eb5482
2020-09-29 16:58:22 +00:00
Vadim Yanitskiy 7f6c87da2f vty/command: reflect global attributes in the XML reference
Given that commands with either/both of the following attributes:

  - CMD_ATTR_DEPRECATED,
  - CMD_ATTR_HIDDEN,

never end up in the XML reference, only CMD_ATTR_IMMEDIATE would
be reflected for commands taking effect immediately as follows:

  <command id='foo'>
    <!-- Global attributes -->
    <attributes scope='global'>
      <attribute doc='This command applies immediately' />
    </attributes>

    <!-- Application specific attributes -->
    <attributes scope='application'>
      <!-- ... -->
    </attributes>

    <params>
      <!-- ... -->
    </params>
  </command>

Change-Id: I8476c1163c23a9a52641987acf3df0b8c49d8f7b
Related: SYS#4937
2020-09-28 13:03:52 +07:00
Vadim Yanitskiy 349d3480a6 vty: cosmetic: fix missing curly braces in vty_describe_command()
Change-Id: I1585ee70a3db77aa8737f9463c4d0665f4e90d90
2020-09-22 19:29:28 +00:00
Vadim Yanitskiy f909d336c3 vty: cosmetic: s/width/cmd_width/g in vty_describe_command()
Change-Id: Ifcf5f7be925c5421040d3cac2c4c5e4dd497c0f5
2020-09-22 19:29:28 +00:00
Vadim Yanitskiy aade232c54 vty: cosmetic: drop redundant 'break' statements
Change-Id: I54ee7c3c6fe16a413d0e1128c7358ff6e4b76c6a
2020-09-22 19:29:28 +00:00
Vadim Yanitskiy 34e94f3c3a vty: print program specific attributes in the XML reference
Change-Id: I1f35368ba9178e1454f2e3ddfcad9d96576143ef
Related: SYS#4937
2020-09-20 09:57:44 +00:00
Vadim Yanitskiy e0ed147984 vty: fix 'Unsigned compared against 0' generate_cpu_hex_mask()
Change-Id: I49549439d5bbfbb83954ba92957304b03062d003
Fixes: CID#212137
2020-09-11 20:14:34 +07:00
Pau Espin 62be97e89d vty: Fix cpu-sched VTY node name
Durin dev cycle, node was initially called "sched" instead of
"cpu-sched", and when it was renamed, this specific part was missed.

Change-Id: I0709fee12cc8ddc4d57efb4ea40b0b79b7ea4151
2020-08-20 08:40:30 +00:00
Vadim Yanitskiy 478dd1b330 vty/command: cosmetic: swap i and j in vty_dump_element()
It's more convenient to use i in the outer loop, and j, k, etc.
in the inner loops.  Otherwise it looks a bit confusing.

Change-Id: I61ef48fcf977d6a872e288571a4ff2c3dfe3184b
2020-08-18 18:40:22 +07:00
Vadim Yanitskiy b0bbd72b2e vty/command: fix switch / case coding style in vty_go_parent()
Change-Id: I6f7f5af6879d91811be6f0edf3feb2ebae185ac7
2020-08-18 18:34:47 +07:00
Eric Wild dde327275c vty cpu sched: do not assert if sched impossible
Shared code might be used by applications that have no vty, so sched
can't be initialized, do not assert and break everything in this case, a
warning should suffice.

Change-Id: Ic40075df8d4cf9fe8f1d711f899dae9a4b5b0928
2020-08-17 10:14:27 +00:00
Vadim Yanitskiy 1d7ae15625 vty/command: cosmetic: fix formatting of config_help_cmd
Change-Id: I8f784d0cf65fa7813088e3ff76d7213b99b975d0
2020-08-15 07:46:53 +00:00
Vadim Yanitskiy 6f50e21936 vty/command: cosmetic: simplify conditions in in config_list_cmd
Change-Id: Id1c082d102b7156dafb9c5d9197dcdc4d26bff63
2020-08-15 07:46:53 +00:00
Pau Espin eb6882fa52 vty: Introduce support to set cpu-affinity and scheduler policy
Process willing to support this kind of configuration through VTY simply
need to call "osmo_sched_vty_init(tall_ctx);" during startup to register
the commands.
For multithreaded processes, new threads willing to get their
cpu-affinity mask according to VTY config should call
osmo_sched_vty_apply_localthread() (potentially after
setting the thread name through pthread_setname_np()).

Related: SYS#4986
Change-Id: If76a4bd2cc7b3c7adf5d84790a944d78be70e10a
2020-08-10 14:11:18 +00:00
Pau Espin a184701108 vty: Don't match negative values on purely positive ranges
Without this patch, for instance having a range 0-ULONG_MAX would match
if someones types value -3, which would be converted to unsigned but
that's clearly what is expected here from user point of view.

Change-Id: Ia95f6314a2dd3f94d21fc219cf69bb8d39b8e7f0
2020-07-30 21:02:03 +00:00
Pau Espin 9fdc871532 vty: Allow 64 bit values in numeric ranges if system supports it
This fixes commands not being matched due to providing a range with more
than 10 digits.

The last case (passing -4000 matching 0-ULONG_MAX) shows a different bug
which will be fixed in next commit.

Change-Id: I0afa0caabffe36083c36b92ba90696ded00bb7be
2020-07-30 21:02:03 +00:00
Daniel Willmann 1a1de33bf9 stats: Add stats commands related to testing
* Allow to set the reporting interval to 0 for manual reporting
* stats reset command to reset all statistics
* stats report command to manually trigger statistics reporting

Change-Id: I9febcb65650abfd538caedfbca77a787e66d517a
Related: SYS#4877
2020-07-17 16:41:31 +00:00
Harald Welte bebec218a7 vty: Avoid ultra-long multi-line strings cluttering talloc reports
The talloc_asprintf() series includes an unconditional call to
talloc_set_name_const(), turning the entire long constructed string
into the name of the talloc object.  That simply doesn't work when
creating kilobytes-sized VTY reference strings including linefeeds.

Let's add an explicit talloc_set_name_const() to prevent this.

Change-Id: Ibd77684b88cc3572047daa98c9a6b9119fba041b
Closes: OS#4668
2020-07-15 12:23:46 +02:00
Neels Hofmeyr cf70aa0c40 enable vty xml dumping to stdout
Allow dumping the VTY XML reference (for generating manuals) to a normal FILE*
stream instead of a vty output buffer.

We currently generate the VTY reference by starting the client program,
connecting to the VTY telnet and dumping the reference. That is weirdly
convoluted, especially since there has to be a valid config file that
successfully starts up a minimal set of external links before the reference can
be generated. IMO we should have dumped the XML reference to stdout from the
start, and never to a VTY session.

With this patch, it is trivial to generate the XML VTY reference by a
commandline switch. The client program will set up the entire VTY, and
immediately after parsing the cmdline options but before parsing a config file,
just dumps the reference and doesn't even start establishing local ports. That
would allow generating the XML reference on the fly during the build process of
the manuals, without the need of a docker container or somesuch.

A first implementation of such a commandline switch is `osmo-bsc -X`, added in
I316efedb2c1652791434ecf14a1e261367cd2fb7

This patch jumps through a bit of a hoop to still allow dumping to a VTY buffer
without code dup, to still allow dumping the XML reference through telnet VTY,
until all our programs have implemented an -X switch (TM).

Change-Id: Ic74bbdb6dc5ea05f03c791cc70184861e39cd492
2020-05-18 13:55:08 +02:00
Alexander Chemeris dfebf405e5 stats: Support regular stats flush
Reliable monitoring requires regular flush of all stat values, even
if they have not changed. Otherwise (1) the monitoring app has to
maintain state and (2) can go out of sync if it's restarted while
the app is still running.

Change-Id: I04f1e7bdf0d6f20e4f15571e94191de61c47ddad
2020-05-09 08:08:53 +00:00
Alexander Chemeris 161adeec84 stats: Move cfg_stats_interval_cmd() function.
cfg_stats_interval_cmd() function was (probably mistakenly)
inserted between cfg_stats_reporter_statsd_cmd() and
cfg_no_stats_reporter_statsd_cmd() function which makes no sense.
Move it below the cfg_no_stats_reporter_log_cmd() to follow the order
of the osmo_stats_vty_add_cmds() function calls.

Change-Id: I1ecec7025e95cf5ffc21ae3b1c75cf6da8c58de2
2020-05-09 08:08:53 +00:00
Vadim Yanitskiy df4f6085cd tdef_vty: do not enforce enum 'node_type' in osmo_tdef_vty_groups_init()
Some osmo-* applications may need to use their own VTY node as a
parent for the timer configuration commands. Therefore it makes
more sense to use 'unsigned int' instead of 'enum node_type'.

Let's also clarify that osmo_tdef_vty_groups_init() accepts parent
node for configuration commands only: 'parent_node' -> 'parent_cfg_node'.

Change-Id: Ifb4c406c85d76a25fc53fc235484599aa87dc77c
2020-02-06 01:06:14 +07:00
Pau Espin 57d1118c25 logging_vty.c: Avoid acquiring log tgt lock in logging level cmd when not needed
Change-Id: Ia6780221174070cee408625e24513f2c11cc9dfc
2020-01-03 22:16:08 +00:00
Pau Espin 2862f9082e Bump version: 1.2.0.108-c6a8-dirty → 1.3.0
Change-Id: I5698bfe45467a8b0e44549105aaf27b8da500de8
2020-01-02 18:42:30 +01:00