Commit Graph

139 Commits

Author SHA1 Message Date
Neels Hofmeyr e4b84738b5 vty: move struct vty_parent_node to private API
Change-Id: Id2070f03b09feea966c5342361d409551e557d38
2023-05-06 03:49:08 +00:00
Neels Hofmeyr 67d84d2131 vty: fix vty->index for implicit go_parent_node
After this patch, most vty_go_parent() functions are really obsolete, as
originally intended: A vty_go_parent() is only needed if the program
requires an action to run on VTY node exit.

vty_transcript_test.vty shows the fixed behavior.

For details, see preceding patch
"vty: show bug in implicit go_parent_node"
I2472daed7436a1947655b06d34eb217e595bc7f3

Change-Id: Id408c678d18ba19b1c1394c3fb657536153d2094
2023-05-06 03:49:08 +00:00
Pau Espin 4fc6118bb3 Split include/Makefile.am content into subdirs
When someone is modifying a given library there's no need to be looking
at a common file contains tons of lines from different libraries.
Furthermore, this removes the need of "nobase" autofoo prefix, hence
following the usual directive of having one Makefile per directory.

Change-Id: I785891c2f89114bf8303c799094b637d3d25ac71
2023-01-18 18:29:34 +01:00
arehbein ee7b8c5273 libosmocore: Deprecate APIs telnet_init(_dynip)()
Related: OS#5809
Change-Id: Ibd05d3bc2736256aa45e9e7ec15a98bd14a10454
2023-01-09 21:18:15 +00:00
Harald Welte 8d5fc1db44 vty/logging.h: Avoid -Werror=pragmas error in C++ code
The newly-introdiced pragma to disable strict-prototypes checking works
in C, but creates a -Werror=pragmas error in C++ code:

In file included from osmo-trx.cpp:45:
/build/deps/install/stow/libosmocore/include/osmocom/vty/logging.h:10:32: error: option
‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++ [-Werror=pragmas]
 #pragma GCC diagnostic ignored "-Wstrict-prototypes"

So let's also suppress those errors for that one line of code...

Change-Id: I85596cf4538d7a8c522f4bce1620a2d19e2a910e
2022-11-07 10:08:09 +01:00
Harald Welte be912e7c1d Disable -Wstrict-prototypes for logging_vty_add_cmds()
Since March 15th 2017, libosmocore API logging_vty_add_cmds() had its
parameter removed (c65c5b4ea0). However,
its declaration in C file didn't contain "(void)", which meant the
number of parameters is undefined and thus compiler doesn't complain.

However, in recent Change-Id I84fd99442d0cc400fa562fa33623c142649230e2
we changed the declaration to '(void)' to allow building with
-Wstrict-prototypes.  This caused downstream build-failures of osmo-mgw (1.4.0)
and osmo-e1-recorder (master).

So let's make one very small-scoped exception here.

Change-Id: Iadb54848b67db937b640dc2102dddb6e708a6a9f
2022-11-06 10:57:52 +01:00
Harald Welte e61d459cef Support building with -Werror=strict-prototypes / -Werror=old-style-definition
Unfortunately "-std=c99" is not sufficient to make gcc ignore code that
uses constructs of earlier C standards, which were abandoned in C99.

See https://lwn.net/ml/fedora-devel/Y1kvF35WozzGBpc8@redhat.com/ for
some related discussion.

Change-Id: I84fd99442d0cc400fa562fa33623c142649230e2
2022-11-03 12:44:28 +01:00
Harald Welte 729a2c8e9a allocate VTY port number 4270 for osmo-isdntap
osmo-isdntap is a ISDN protocol + call tracing utility currently under
development, see https://gitea.osmocom.org/retronetworking/osmo-isdntap

Change-Id: I25ca4565e326ee9b0b32eeabc4a76756e2fde4ac
2022-10-16 17:14:08 +02:00
Harald Welte 3b007f86ac vty: Add a 'skip-zero' version of 'show stats' and 'show rate-counters'
In many cases, a lot of the counters are zero, and we're likely
not interested in those, but only the non-zero counters.  Add a version
of the 'show stats' command which dumps only those items with a non-zero
total value.

Change-Id: Ie4df1c139e3c82deca1dd3cdab5d3909e0513684
2022-04-28 06:05:29 +00:00
Neels Hofmeyr 1d1ab74fdf ports.h: add osmo-pfcp-tool ports
Related: SYS#5599
Change-Id: I8a5f437d934b9bda11ea593b50bd18c7d5d71ce9
2022-01-21 00:55:51 +01:00
Neels Hofmeyr 13fa00e183 PFCP: add DLPFCP and osmo-upf port numbers
Related: SYS#5599
Change-Id: I0a46b147ec6a76d909df28136cfd2b764b2c75ea
2022-01-21 00:55:51 +01:00
Oliver Smith 04bfb7165b treewide: remove FSF address
Remove the paragraph about writing to the Free Software Foundation's
mailing address. The FSF has changed addresses in the past, and may do
so again. In 2021 this is not useful, let's rather have a bit less
boilerplate at the start of source files.

Change-Id: I5050285e75cf120407a1d883e99b3c4bcae8ffd7
2021-12-14 12:44:03 +01:00
Pau Espin 0a9430ee48 {ctrl,vty}/ports.h: Allocate ports for osmo-hnodeb
Change-Id: I6514d040d88d145a321075911368645868e6280e
2021-10-21 12:53:33 +02:00
Alexander Couzens 06929166de vty: add vty_out_uptime() print the uptime to the vty
vty_out_uptime() calculates the time difference to a given timespec
and print it in a human readable format (days, hours,
minutes, seconds) to the vty.

Related: OS#5028
Change-Id: I264a3f49096b96646e0a1f5366623ac20d860793
2021-09-23 13:12:34 +02:00
Eric Wild 11a58a1b34 vty: allow flushing
It was so far sufficient to wait for the buffers to drain at some
random point in time, but this is not always the case, sometimes it is
important that the output is flushed immediately.

Change-Id: If984b9ad2eba9f400bc29a7aa8825e241fd1d2a9
2021-09-10 14:50:26 +02:00
Oliver Smith 6a138891da vty/ports: move pcap server/client ports
Resolve conflict with other Osmocom software by moving ports:

osmo-pcap-client 4237 -> 4227
osmo-pcap-server 4238 -> 4228

Remove wrong previous comments that claimed 4240 and 4241 were used.

Related: OS#5203
Related: osmo-pcap I3b18b1fbbca2799f868f28104e2f5d513f93d46c
Change-Id: I098f211370bba61995ce424ab64029bdd4c49e2d
2021-08-06 16:13:34 +02:00
Oliver Smith d8f8919a58 vty/ports: prepare formatting for a long define
Add one more tab between the define and the port number, to prepare for
longer defines in the next patch.

Related: OS#5203
Change-Id: I46655e33651814f41a1fea93406a83334d2fc529
2021-08-06 16:11:16 +02:00
Philipp Maier 466be65176 command: fix sourcecode formatting
Change-Id: Icc75c3b45821c24360e0fdb4a29077994e73ae05
2021-07-27 07:34:32 +00:00
Philipp Maier eabc6fd4b1 vty: make function cmd_range_match() public
Certain control interface commands also may require to verfy a range in
their verify function. cmd_range_match() from the VTY does exactly that
and the range can be specified as string, the same way as we would
specify it in the VTY.

Change-Id: I53fc207677f52b1dc748b01d58424839cdba807c
related: SYS#5369
2021-06-18 12:31:01 +00:00
Pau Espin 645aec8237 vty: Introduce API vty_read_config_filep
This new API doesn't use host_config_set(), and allows passing a FILE*
from any source, not only a filesystem path.

Related: SYS#5369
Change-Id: I720ac04386261628c0798a1bfcaa91e2490a86c3
2021-05-18 14:56:52 +02:00
Pau Espin ebb6c1fc4d vty: Implement missing public API host_config_file()
The API was defined in the header file but not implemented.

Change-Id: I69de9864fa7cd421557b9fc630beefea6d90b4cc
2021-05-17 18:54:23 +02:00
Harald Welte a0fb37627f TODO-RELEASE: Request increasing _LAST_OSMOVTY_NODE next release
We've used up all but one "library reserved" VTY nodes at this point,
and we should definitely add some more reserved nodes in the next
libosmovty ABI version / release.

Change-Id: Idfe1e7d97f3f29fc219e80dcb6ce6bb768733adf
2021-03-05 17:06:38 +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
Alexander Couzens 412bc3494d gprs_ns2: add new vty2
Change-Id: I163279cf57e84198dc8c53e1c109f5a9474670e9
2020-12-22 16:36:19 +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
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 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 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
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 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 e566bddaff vty: introduce and use VTY_CMD_USR_ATTR_NUM
Change-Id: Ib4327835f5be264ef67a01d8f4733dd2d091eaf1
Related: SYS#4937
2020-10-06 21:01:08 +00: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 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 4a96b7c7b9 vty/command: introduce new attribute CMD_ATTR_IMMEDIATE
This attribute indicates that a VTY command applies immediately.

Change-Id: Ia185dfd0c89214dc893af70736ff01dca3a7627e
Related: SYS#4937
2020-09-28 12:44:33 +07:00
Vadim Yanitskiy 7f1ecd9eb4 vty: add program specific attributes to VTY commands
Change-Id: I2c6c7b317b2b28ce70784c0cabd1b913e721be02
Related: SYS#4937
2020-09-20 09:57:44 +00:00
Harald Welte 9a21d2af0e Add VTY + CTRL ports for upcoming OsmoSMLC
We will soon have a minimal Serving Mobile Location Center.

Change-Id: Ic7e9c2196a03502cfd3d880a3090a5be80773945
2020-08-21 17:59:53 +02:00
Vadim Yanitskiy 523c4e0f44 vty/command: cosmetic: drop redundant line break
Change-Id: Ia7c85b7862fbb191b5746fc333cf0c34bc79a533
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
Alexander Couzens 99c538e4be vty: add a define VTY_IPV46_CMD to require a IPv4/6 address
Allow to use this define in vty definitions when a IPV4/6 address
is required as argument.

Change-Id: I86e399aea86b68b48e627f11e1de48fdfad16525
2020-07-28 13:58:48 +02:00
Harald Welte db974f372b vty/ports.h: Add VTY port for osmo-e1d
Change-Id: Ia19b870146334b4ab749f12dc87fb628c1cdcca9
2020-06-29 10:42:02 +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
Harald Welte e616cbad62 ports.h: Add 4268 for UECUPS VTY
Change-Id: I6c53654f06fac6b6b196be88178a918d38e91e46
2020-04-17 10:37:53 +02: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
Neels Hofmeyr 70ce871532 vty_app_info.is_config_node: add OSMO_DEPRECATED
Although this OSMO_DEPRECATED doesn't seem to generate a warning when compiling
code that sets .is_config_node = foo, it seems a good idea to add the
deprecation tag.

It is deprecated since commit "vty: track parent nodes also for telnet sessions"
I2b32b4fe20732728db6e9cdac7e484d96ab86dc5

Change-Id: I800507b27cb0d536c1a4c203d7f7b90eec05a69c
2019-11-24 19:59:35 +01:00
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
Pau Espin 097b5099c4 tdef_vty.h: Add missing header dependencies
enum node_type is defined in osmocom/vty/command.h
va_list is defined in stdarg.h

Change-Id: Ia439a7097ae7a9765e229e5f66e07af3fe490ecc
2019-09-07 22:29:06 +00:00
Harald Welte 581a34da60 tdef: Fix license: GPLv2+ instead of AGPLv3+
libosmo{core,gsm,vty} code is GPLv2+.  The tdef code originated in
osmo-msc.git and was moved here without changing the license. That
was a mistake, it always was meant to be under GPLv2-or-later after
moving to libosmocore.git.

Copyright is with sysmocom, so I as the managing director can
approve the license change.

Change-Id: Ie483ff6f6ea0a56c477649677b4b163c49df11d7
2019-05-27 23:26:45 +02:00
Harald Welte 3e323a29d2 Add VTY and CTRL port numbers for OsmoCBC (Cell Broadcast Centre)
Change-Id: I2075420048b43973c800ba0fc389f4b559437233
2019-05-08 13:50:15 +00:00