Commit Graph

43 Commits

Author SHA1 Message Date
Max 30b2e348df ctrl: use #define for TRAP id
We always use id = 0 when sending TRAP messages. Let's make this more
obvious by introducing appropriate define.

Change-Id: I33d7d4c6a1885a75a85d6f2f017430e0860b4126
2018-12-03 21:42:51 +00:00
Pau Espin 239ed3b3ee ctrl: Introduce ctrl_cmd_parse3 API
Callers require to know whether the returned ERROR cmd was received or
generated locally, in order to send it or do something with it locally.

Related: OS#3394

Change-Id: Ide9170e5c31967c353f8fe4e8227e64130b91eae
2018-07-16 17:56:25 +00:00
Daniel Willmann 07f075d197 ports.h: Add ctrl port for osmo-gbproxy
Change-Id: I46a1cef3013c9bbf9b5a6d64e83cd84568f2523c
2018-05-29 21:02:16 +02:00
Harald Welte b4186824c2 ctrl: Add doxygen API documentation; generate html from it
Closes: OS#3293
Change-Id: I8dc2f24d4bf557ff7bb0f2f46881f9f8d9d7f86f
2018-05-26 21:58:15 +02:00
Neels Hofmeyr cdbc9afe5d ctrl: fix deferred commands (and hence fix osmo-bts-sysmo 'clock-info' cmd)
The CTRL interface has a ctrl_cmd_def_* API that allows deferring a CTRL
command reply until later. However, the command handling currently fails to
acknowledge this and deallocates the struct ctrl_cmd anyway.

Fix: in struct ctrl_cmd, add a defer pointer to be populated by
ctrl_cmd_def_make(). A cmd thus marked as deferred is not deallocated at the
end of command handling. This fix needs no change in calling code.

(Another idea was to return a different code than CTRL_CMD_HANDLED when the
command is to be deferred, but that would require adjusting each user of
ctrl_cmd_def_make(). The implicit marking is safer and easier.)

Show that handling deferred commands is fixed by adjusting the expectations of
ctrl_test.c's test_deferred_cmd() and removing the now obsolete exit_early
label.

One symptom of the breakage is that osmo-bts-sysmo crashes when asked to report
a trx's clock-info, which is aggravated by the fact that the sysmobts-mgr does
ask osmo-bts-sysmo for a clock-info.

The crash appears since Id583b413f8b8bd16e5cf92a8a9e8663903646381 -- it looked
like just fixing an obvious memory leak, which it did as shown by the unit
test, but deferred ctrl commands actually relied on that leak. Both fixed now.

Related: OS#3120
Change-Id: I24232be7dcf7be79f4def91ddc8b8f8005b56318
2018-04-05 03:11:49 +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 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
Neels Hofmeyr f2e83ad40d add ctrl_cmd_parse2() to return parsing errors
If a control command fails to parse, we so far discard specific error messages
and instead send just "Command parser error".

In ctrl_cmd_parse() we actually compose detailed error replies, but in the end
simply talloc_free() them and return NULL.

A first step to report these errors to the ctrl command issuer is to not return
NULL and instead return the cmd with type = CTRL_TYPE_ERROR. Add
ctrl_cmd_parse2() to return such instead of NULL.

To stay API compatible, provide ctrl_cmd_parse2() to return a cmd on errors.
ctrl_cmd_parse() retains identical behavior but becomes just a simple wrapper
around ctrl_cmd_parse2() which discards the cmd on error.

No need really to deprecate ctrl_cmd_parse() yet; especially as long as
compiler warnings might break jenkins builds.

Change-Id: I5047c9f977d70b03eea77cbcfd2b96d43ea46880
2017-12-18 23:05:50 +00:00
Neels Hofmeyr d53d216944 ctrl: prep test: separate new ctrl_handle_msg() from handle_control_read()
In order to allow unit testing the ctrl iface msgb handling, have a separate
msgb entry point function from the actual fd read function.

An upcoming patch will prove a memory leak in CTRL msgb handling by a unit test
that needs this separation.

Change-Id: Ie09e39db668b866eeb80399b82e7b04b8f5ad7c3
2017-12-18 23:05:49 +00:00
Neels Hofmeyr abdd7a28ed add osmo_talloc_asprintf() and ctrl_cmd_reply_printf()
Add macro to append to a CTRL commands' reply string, ctrl_cmd_reply_printf().
The talloc_asprintf() part of it is generic enough to qualify for a separate
macro, osmo_talloc_asprintf().

The idea is to not have to decide for each bit added to a string whether the
string is already allocated or not, but simply be able to issue printf commands
and let the macro worry about initial allocation or reallocation.

This originally came from osmo-hlr change
I1bd62ae0d4eefde7e1517db15a2155640a1bab58, where it was requested to move this
bit to libosmocore.

Change-Id: Ic9dba0e4a1eb5a7dc3cee2f181b9024ed4fc7005
2017-10-24 10:54:07 +00:00
Neels Hofmeyr ea66852a62 ctrl: allow more nodes than those in enum ctrl_node_type
Add ctrl_interface_setup_dynip2() to add a node_count parameter, which can be
used to define more ctrl nodes without having to merge a patch to libosmocore.

In consequence, also add ctrl_handle_alloc2(), since
ctrl_interface_setup_dynip() uses ctrl_handle_alloc() to allocate the node
slots, and add node_count param to static ctrl_init().

Passing zero as node_count indicates to use the default of _LAST_CTRL_NODE as
before, i.e. to not define more ctrl nodes. Assert that we never allocate less
than _LAST_CTRL_NODE slots.

The current ctrl_interface_setup_dynip() and ctrl_handle_alloc() become simple
wrappers that pass zero as node_count. Their use is still valid and they do not
need to be deprecated.

The API comment to ctrl_interface_setup_dynip2() explains how to define more
node IDs.

This patch was verified to work by osmo-hlr.git change
I98ee6a06b3aa6a67adb868e0b63b0e04eb42eb50 which adds two node IDs for use by
osmo-hlr only.

Change-Id: I1bd62ae0d4eefde7e1517db15a2155640a1bab58
2017-10-23 22:31:01 +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
Harald Welte 31c0fef2fd control_if: Add control interface commands for FSMs
This allows programmatic access to introspection of FSM instances, which
is quite handy from e.g. external test cases: Send a message to the
code, then use the CTRL interface to check if that message has triggered
the right kind of state transition.

Change-Id: I0f80340ee9c61c88962fdd6764a6098a844d0d1e
2017-04-27 09:50:47 +02:00
Harald Welte f85861d6eb control_if: Add helper function for 'local execution' of control command
Sometimes (particularly when testing), we may want to parse+execute an
arbitrary control command simply form a string buffer, rather than from
a msgb.  Let's add a helper for that.

Change-Id: Iaca748e0d942bb2a1ee7c2776b37485e1439eb0c
2017-04-27 09:50:33 +02:00
Harald Welte 79c137c654 control_if: Add API to initialize control interface without TCP port bind
When executing test cases, we don't want to bind to a local TCP port, as
we cannot make assumptions as to which ports are actually free.

Change-Id: I5717f9dd92d1f143f069cecd4b4c8ba3d03b25f8
2017-04-26 13:47:06 +02:00
Harald Welte d6b1f85fd8 ctrl: Allow installation of additional node lookup helpers
The existing code assumes that the main application knows about all
control command nodes and can thus present one lookup function.

As libraries are getting their own control interface handling, this
is too restrictive, and we need a way how library code can dynamically
register more node lookup helpers.   We can now do this by means of a
ctrl_lookup_register() function.

Change-Id: Ib69908d1c57f5bb721d5496e3b4a5258fca450e3
2017-04-26 09:22:19 +00:00
Neels Hofmeyr 7c1ec8c8e7 ctrl_type_vals: explicitly terminate
Don't use CTRL_TYPE_UNKNOWN as value_string[] terminator, use an explicit, more
obvious { 0, NULL } termination. Set an explicit string for CTRL_TYPE_UNKNOWN.
No other value_string[]s to date have such a "hidden" terminator.

BTW, a { 0, "string" } item is not a terminator, only { 0, NULL } is, so we can
set a string for CTRL_TYPE_UNKNOWN == 0.

Also, having a string value for CTRL_TYPE_UNKNOWN is not harmful because all
code paths explicitly check for the CTRL_TYPE_*s that are valid.

Adjust the test expectation.

From the ctrl_type_vals enum, remove the = 0, because it is implicitly 0
anyway.

One motivation to press this fixup: I am trying to add a script that checks
whether all value_string[]s are terminated to our jenkins jobs, and to find
that this one is terminated, it would need to interpret the CTRL_TYPE_UNKNOWN
constant, which would make things far more complex. At this point, all of the
value_string[]s have an explicit termination, and I would like to enforce this
from now on -- for readable code and to not spend more time on the validator.

The patch adding ctrl_type_vals (Icd4e96dd9f00876cb70b43cfcf42ab4f10311b28) was
accepted by another reviewer before I could reconfirm my -1, so this is a fixup
to enable the termination checking script patches.

Related: I2bc93ab4781487e7685cfb63091a489cd126b1a8 (adds script to libosmocore)
         I7fe3678b524d602fc6aa14bc0ed06308df809a3e (uses in jenkins.sh)
	 Icd4e96dd9f00876cb70b43cfcf42ab4f10311b28 (adds ctrl_type_vals)

Change-Id: Ia99f37464c7b36b587da2cc78f52c82725f02cbc
2017-03-15 13:47:20 +00:00
Max 70c7d4160d Use value_string for ctrl_type
Use value_string for enum ctrl_type instead of custom code. Add
corresponding unit tests.

Related: OS#1615
Change-Id: Icd4e96dd9f00876cb70b43cfcf42ab4f10311b28
2017-03-01 16:37:59 +00:00
Neels Hofmeyr fa5dc93fd0 ports.h: rename CSCN to MSC
See OS#1958

Change-Id: I85aee0f8fdfc9c69d0ba9240988c633d3e707f2d
2017-02-24 19:57:48 +00:00
Max fa9e05e7e8 Expand and expose ctrl connection allocation
Add function for allocating CTRL connection to public headers and
replace call to previous static function with it. Add doxygen docs for
this function.

It's useful if we need to allocate ctrl connection but don't need to
bind to any interfaces: when we act as ctrl client.

Related: OS#1615
Change-Id: I522ed809cbebfd3d7dd08b4ed9137b39ff192e32
2017-02-23 17:30:44 +00:00
Max af4bb17a93 Add CTRL port for OsmoHLR
Change-Id: I1328c89ec8e908bf4b4d2c0a398690278369e0f5
Related: OS#1645
2017-02-14 12:13:32 +01: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
Max 8928747a3e CTRL: add write-only helpers
Similar to CTRL_CMD_DEFINE_RO() add helper for control commands which
are not meant to be read, only to set. Similarly, add
CTRL_CMD_DEFINE_WO_NOVRF() for commands which do not perform inbound
data verification.

Change-Id: I66b7990db590c1f8e56326e392e6c1d2eafebd9a
2017-01-16 08:54:17 +00:00
Neels Hofmeyr 694f72d148 Revert "Constify ctrl_cmd struct fields where appropriate"
This reverts commit ed9d6da5df.

The commit is good as such, but it causes many compiler warnings in the OpenBSC
build. We want this to be re-applied as soon as we have patches ready that fix
the fallout in openbsc.git.

See also https://lists.osmocom.org/pipermail/openbsc/2016-October/009802.html

Related: OS#1829
Change-Id: I722ad60232a6ef5b4cb984b92c42851de26b3ccd
2016-10-20 17:53:10 +02:00
Max bc067eb0a2 Add function to send TRAP over Control Interface
Change-Id: Ic0b8d88c4f5c4d42c3f8fb754f8eabf049c9e388
Related: OS#1646
2016-10-12 11:37:49 +00:00
Max ed9d6da5df Constify ctrl_cmd struct fields where appropriate
Change-Id: I3f55c1d4b965d215dc9b16f4b284b7fea4bde9e9
2016-10-11 18:27:22 +02: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
Max d1dcda01f8 Add control interface port for GGSN
Change-Id: Ie7232189fe3265a8631fd3652b2c8c152cdee918
Related: OS#1646
2016-08-08 17:42:17 +00: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 4934309dab add ctrl_interface_setup_dynip() for bind address
Make the ctrl interface bind address configurable, so that it may be made
available on other addresses than 127.0.0.1. The specific aim is to allow
running multiple osmo-nitbs alongside each other (commits in openbsc follow).
2016-02-25 11:02:35 +01:00
Neels Hofmeyr 8684714966 Add CSCN ctrl port defs 2016-02-15 12:02:02 +01:00
Harald Welte f39aed6942 add port number 4238 for BTS control interface 2014-08-24 16:52:54 +02:00
Harald Welte 39c9e7b471 libctrl: Add support for 'deferred control commands'
Sometimes a control interface command cannot be processed
and responded immediately, but we need to process it asynchronously.

In order to support this, we introduce the 'ctrl_cmd_def', which
represents such a deferred command.  It is created by the service
implementing the command using ctrl_cmd_def_make(), and a response is
later sent using ctrl_cmd_def_send().

ctrl_cmd_def_is_zombie() must be called to handle the case where
the control connection has disconnected/died between receiving the
command and sending the response.
2014-08-24 16:52:54 +02:00
Harald Welte 5ddd435919 Convert recently-introduced header files to #pragma once 2014-08-21 15:42:44 +02:00
Harald Welte c7947ed1f6 New <osmocom/ctrl/ports.h> file listing tcp ports for CTRL interface 2014-08-21 15:34:19 +02:00
Harald Welte ae2fcb22cf rename controlif_setup() to ctrl_interface_setup()
which means that all control interface related functions now have
the common ctrl_ prefix.
2014-08-21 15:34:19 +02:00
Harald Welte 528134b01c libctrl: Move bulk of control node lookup inti libosmoctrl
The control interface user now only has to register a very short
node lookup function callback.  This function is optional, and only
required if hierarchical command lookup should be supported.
2014-08-21 15:34:18 +02:00
Harald Welte c78e74e3d0 libctrl: remove 'struct gsm_network' references
libctrl doesn't need any knowledge about the type of the user-private
data that it gets passed upon setup time and includes on callbacks.
2014-08-21 15:34:18 +02:00
Harald Welte d8db92c578 libctrl: remove bsc-specific declaration
this was moved by accident when importing the code from openbsc.
2014-08-21 15:34:18 +02:00
Harald Welte f3c7e85d05 libctrl: remove reference to bsc_replace_string()
... and rather introduce a general osmo_talloc_replace_string() to
libosmocore.
2014-08-21 15:34:17 +02:00
Harald Welte 1238cc64d7 libctrl: remove openbsc headers, convert from make_sock to libosmocore 2014-08-21 15:34:17 +02:00
Harald Welte dda4225153 libctr: rename/move control interface to libosmocore naming scheme 2014-08-21 15:34:17 +02:00