Commit Graph

112 Commits

Author SHA1 Message Date
Harald Welte 319a77e519 ctrl: Don't expose write_queue in ctrl_cmd_send() api
ctrl_cmd_send() should always have taken a 'struct ctrl_connection'
as argument, not directly its write_queue member.

Let's offer a ctrl_cmd_send2() which fixes the problem, and deprecate
the old ctrl_cmd_send().

Related: OS#5751
Change-Id: Ic81af56e7ea6921ba39168727ef64c308e9c6754
2024-03-02 18:59:16 +01:00
Pau Espin aca2c724ae Bump version: 1.8.0.252-13c29 → 1.9.0
Change-Id: I6f8eccbccb73c6c094f13f2d4bdee931cf5b9010
2023-09-12 13:15:54 +02:00
Harald Welte c9527763c2 Makefile.am: Make libraries depend on .map files
Without this, an update to the .map file doesn't re-trigger a re-link of
the library.

Change-Id: If0ea6f41730a28b04562d45efa6ca376abaf3f6b
2023-03-06 17:07:48 +00:00
Vadim Yanitskiy 64277a0217 doxygen: fix various typos in commands \param and \returns
Change-Id: If87cec3739449c6a54e24fb2cb81e746d8244da2
2023-02-28 18:48:56 +00:00
Pau Espin 5f15e4199c Bump version: 1.7.0.119-b31a-dirty → 1.8.0
Change-Id: I5e953cedc041371a9c192f58348b673a787f542e
2023-02-07 11:20:42 +01:00
Pau Espin 88955fb550 Fix all references to config.h
config.h is created in $(top_buildir)/config.h.
Let's make sure all CPPFLAGS add correct -Ipath includes,
and that all code includes the correct file.

Change-Id: Ie9ea38bb009bc715b01cde4d66d181f7bec2e7bd
2023-01-18 19:04:36 +01:00
Pau Espin a50ed5fda8 Makefile.am: Remove unexsiting all_includes variable
Change-Id: I9bc7de6f85558e55265c6cc965bc7fe97a6736ee
2023-01-18 19:04:36 +01:00
Pau Espin d4c3dc8d59 Move src/*.{c,h} to src/core/
This way we have all libosmocore.so in an own subdir instead of having
lots of files in the parent dir, which also contains subdirs to other
libraries.
This also matches the schema under include/osmocom/.

Change-Id: I6c76fafebdd5e961aed88bbecd2c16bc69d580e2
2023-01-18 17:14:06 +01:00
Pau Espin e709bd4814 ctrl: error if program forgot to initialize the ctr handler before installing cmds
Change-Id: Icf3873f33470499fed3150ff51922a36aa0f023e
2023-01-11 15:33:41 +00:00
Max 3f79ce8f23 ctrl: add optional port to bind command
So far ctrl interface did not allow to specify port to bind to.
Let's fix this and make it consistent with the way vty bind works.

N. B: the functions which ignore port configured via vty are marked as deprecated,
the sw which uses them should be ported to either newly added ctrl_init_default()
or simplified ctrl_interface_setup()

The similar change for vty interface will be addressed via separate patch series.

Related: OS#5809
Change-Id: I0fd87fd41fd3ac975273968d24f477daa3cd3aa9
2022-12-20 14:23:04 +03:00
Vadim Yanitskiy 8fbaad6903 */Makefile.am: do not mix up AM_CFLAGS with AM_CPPFLAGS
Change-Id: I2c1d5f9c61714f487fbbe60603b2682f2c0a4c6b
2022-11-10 16:07:03 +00:00
Pau Espin a1584d237b Bump version: 1.6.0.132-0239-dirty → 1.7.0
Change-Id: Idb0d20aa4336a69cb100e140fb1fa9e7ac25b984
2022-06-28 17:00:51 +02: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 c7deaf28aa Bump version: 1.5.1.282-ab5e-dirty → 1.6.0
Change-Id: Ia3ac0a36b9e898996f596c6d2787e03cd59bfc11
2021-11-16 13:08:23 +01:00
Neels Hofmeyr 34907fe6e1 revisit some calls of strtol(), stroul(), strtoull()
Replace some with atoi(), where the VTY has already validated correct
range of the argument.

Replace others with the new osmo_str_to_int() or osmo_str_to_int64()
functions, possibly covering more detection of invalid number strings.

Leave those strtol() callers that depend on endptr to provide the next
string token.

Related: SYS#5542
Change-Id: I0ebb06e751c28f7d1cdf328de29cd227a2449391
2021-10-04 11:24:59 +00:00
Neels Hofmeyr a16b50c5e8 CTRL: expose stat_item groups on CTRL
Expose all stat items as RO variables of the form

  stat_item.last.group_name.N.item_name
  stat_item.last.group_name.by_name.idx_name.item_name

For (possibly contrived) example:

  stat_item.last.trunk.0.endpoints:used
  stat_item.last.trunk.by_name.virtual-0.endpoints:used

Include the 'last' token to ease future extension, like 'max'.
Put this token in the beginning, similarly to rate_ctr variables, which
begin with 'per_sec', 'per_hour', ...

Related: SYS#5542
Related: I178dcf4516606aa561d47b06061b8a416d3c40cf (osmo-ttcn3-hacks)
Related: Ic1b35b7406547f92818afe399a2383d154576409 (osmo-ttcn3-hacks)
Change-Id: Idace66b37492fe96b2f2e133a69cac7960ca279c
2021-09-14 10:28:05 +02:00
Philipp Maier b6fd8edae9 control_cmd: fix typo
Change-Id: I9deaee42aeb0ab0549cc7c4f180ad9c216b9df39
2021-06-16 20:31:58 +00:00
Pau Espin d1b0716242 ctrl: Support recovering from short write
osmo_wqueue has support for it, so simply handle it correctly in the
callback (updating buffer and returning -EAGAIN).

Related: OS#5169
Change-Id: I6cbc7ec6ae6832e61cddf4402332ba09b142a7d4
2021-06-15 16:29:44 +00:00
Pau Espin f5b8ed14a9 ctrl: Pre-calculate required size before allocating msgb
This commit fixes crash when response is more than ~4096 chars.
Furthermore, we now allocate only the required memory, not 4096 for all
messages, which usually don't require it.
Test needs to be adapted since it assumed there was more available space
at the end of the msgb.

Related: OS#5169
Change-Id: I0b8f370f7b08736207f9efed13a0663b5e482824
2021-06-15 16:29:44 +00:00
Pau Espin 7b894a7de0 Use new stat item/ctr getter APIs
Generated with spatch:
"""
@@
expression E1, E2;
@@
- &E2->ctr[E1]
+ rate_ctr_group_get_ctr(E2, E1)
"""

"""
@@
expression E1, E2, E3;
@@
- E2->items[E1]
+ osmo_stat_item_group_get_item(E2, E1)
"""

Change-Id: I41297a8df68e28dfc6016330ac82b0ed5dd0ebc1
2021-06-04 18:19:37 +02:00
Pau Espin Pedrol f286fdc87e Bump version: 1.4.0.535-e387-dirty → 1.5.0
Change-Id: I3bc0826c0000be4d76235ed6b5be86d216ea2e4d
2021-02-23 14:03:31 +01:00
Pau Espin 377645d600 ctrl_connection: Initialize write_queue.bfd.fd to -1 during allocation
Otherwise fd is set to 0 by default, let's avoid accidentally closing
it if something goes wrong.

Change-Id: I98f744d2880fbb883719cdf1d3eb31f2b22a13b6
2021-01-29 11:21:09 +00:00
Pau Espin Pedrol 9584cd718a ctrl: Allow handling CTRL get/set replies in user defined code
Prior to this patch, it was not possible to gather SET/GET reply
information when implementing a CTRL client using libosmocontrol. This
is specially important when using the GET command, since one wants to
receive the queried value.
CTRL traps can also be handled this way by extending this patch in the
future if needed.

Change-Id: Id3c4631cd32c13e78e11b6e8194b8c16307ec4f1
2021-01-06 12:32:36 +00: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
Pau Espin 922d276035 Bump version: 1.1.0.107-afce-dirty → 1.2.0
Change-Id: I05dd1f2725e05f856f1d27c9201a0005de101b8f
2019-08-06 18:02:02 +02:00
Harald Welte 1688699c3f select: Rename BSC_FD_* constants to OSMO_FD_*
The naming of these constants dates back to when the code was private
within OpenBSC.  Everything else was renamed (bsc_fd -> osmo_fd) at
the time, but somehow the BSC_FD_* defines have been missed at the
time.

Keep compatibility #defines around, but allow us to migrate the
applications to a less confusing naming meanwhile.

Change-Id: Ifae33ed61a7cf0ae54ad487399e7dd2489986436
2019-03-21 16:02:01 +00:00
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
Max a66de71f8e ctrl: print textual error on IPA parsing failure
Change-Id: I49bb613b416d549f554fd9d23cd37b63954324db
2018-11-26 10:15:02 +01:00
Stefan Sperling e484d42bf2 add support for ipaccess messages on the ctrl interface
In ctrl_handle_msg(), check for IPACCESS protocol messages and respond
to such messages in the same way as ipa_ccm_rcvmsg_base() does. This will
allow the TTCN3 IPA "chopped ping" test to pass on control interfaces.

Change-Id: I9d7137c830981ccad03806b30b776e2b1f1b4699
Related: OS#2010
2018-10-15 11:53:20 +00:00
Alexander Couzens 49865053bc ctrl/vty: fsm: use correct element when iterating over fsm->proc.children
Fixes crashes when using vty `show fsm-instances all`
when fsm children are present.

Change-Id: I4ae0bee7f7f57ec6675cfb52ca6cf0d523d15362
2018-07-29 14:35:00 +00:00
Pau Espin 924ef0bc72 Bump version: 0.11.0.91-9d4a3-dirty → 0.12.0
Change-Id: I7e66432f37e13fd4c31389e3d89593fa0981e58f
2018-07-27 17:31:47 +02:00
Pau Espin 59e6059447 ctrl: ctrl_handle_msg: Avoid sending back received ERROR msgs
Change-Id: I396fd1e7548beea31b2b7aa9f764edb765b02941
2018-07-16 17:56:25 +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
Pau Espin 40ad91330d ctrl: Fix parsing of ERROR recvd msgs with id=err
Our implementation generates ERROR CTRL messages with ID=error when it
is unable to parse a CMD. However, it doesn't account for them when
trying to receive and parse this kind of message. As a result, it will
return an ERROR message with a different description. This commit fixes
the old behaviour to success at parsing and returning the received
description to the caller.

Change-Id: I564ab1a7e845388f87accda44fbf165e5adc2480
2018-07-12 18:47:57 +00:00
Pau Espin 55088b76ce ctrl: Log CMD TYPE on invalid ID number
Change-Id: Ia890d4b841ef02342cc1cf7f5926866b040dc8ab
2018-07-12 18:47:57 +00: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
Harald Welte ed6057841d ctrl: Introduce libosmoctrl.map to avoid unintended exports
There are some symbols for use between control_cmd.c and control_if.c,
which are not supposed to be exported publicly.  Let's make sure we
keep those symbols local.

Change-Id: Ia85f36a9c4b2ebf4003718e0a230959638370320
2018-05-26 21:58:11 +02:00
Harald Welte 3b8921fae2 cosmetic: Whitespace fixes in control_if.c
Change-Id: I24666d0b90a355e9fdefd280d48900b8cac1de64
2018-05-26 10:22:22 +00:00
Pau Espin 686eba9bfc control_if: Avoid heap-use-after-free in osmo_wqueue_bfd_cb
Imagine following scenario:
1- client connects to CTRL iface, a new conn is created with POLL_READ
enabled.
2- A non-related event happens which triggers a TRAP to be sent. As a
result, the wqueue for the conn has now enabled POLL_WRITE, and message
will be sent next time we go through osmo_main_select().
3- At the same time, we receive the GET cmd from the CTRL client, which
means POLL_READ event will be also triggered next time we call
osmo_main_select().
4- osmo_main_select triggers osmo_wqueue_bfd_cb with both READ/WRITE
flags set.
5- The read_cb of wqueue is executed first. The handler closes the CTRL
conn for some reason, freeing the osmo_fd struct and returns.
6- osmo_qeueue_bfd_cb keeps using the already freed osmo_fd and calls
write_cb.

So in step 6 we get a heap-use-after-free catched by AddressSanitizer:

20180424135406115 DLCTRL <0018> control_if.c:506 accept()ed new CTRL connection from (r=10.42.42.1:53910<->l=10.42.42.7:4249)
20180424135406116 DLCTRL <0018> control_cmd.c:378 Command: GET bts.0.oml-connection-state
20180424135406117 DLINP <0013> bts_ipaccess_nanobts.c:417 Identified BTS 1/0/0
20180424135406118 DNM <0005> abis_nm.c:1628 Get Attr (bts=0)
20180424135406118 DNM <0005> abis_nm.c:1628 Get Attr (bts=0)
20180424135406118 DCTRL <000e> osmo_bsc_ctrl.c:158 BTS connection (re)established, sending TRAP.
20180424135406119 DLCTRL <0018> control_if.c:173 close()d CTRL connection (r=10.42.42.1:53910<->l=10.42.42.7:4249)
=================================================================
==12301==ERROR: AddressSanitizer: heap-use-after-free on address 0x611000003e04 at pc 0x7f23091c3a2f bp 0x7ffc0cb73ff0 sp 0x7ffc0cb73fe8
READ of size 4 at 0x611000003e04 thread T0
    #0 0x7f23091c3a2e in osmo_wqueue_bfd_cb /home/osmocom-build/jenkins/workspace/osmo-gsm-tester_build-osmo-bsc/libosmocore/src/write_queue.c:65
    #1 0x7f23091ad5d8 in osmo_fd_disp_fds /home/osmocom-build/jenkins/workspace/osmo-gsm-tester_build-osmo-bsc/libosmocore/src/select.c:216
    #2 0x7f23091ad5d8 in osmo_select_main /home/osmocom-build/jenkins/workspace/osmo-gsm-tester_build-osmo-bsc/libosmocore/src/select.c:256
    #3 0x56538bdb7a26 in main /home/osmocom-build/jenkins/workspace/osmo-gsm-tester_build-osmo-bsc/osmo-bsc/src/osmo-bsc/osmo_bsc_main.c:532
    #4 0x7f23077532e0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202e0)
    #5 0x56538bdb8999 in _start (/home/jenkins/workspace/osmo-gsm-tester_run-prod/trial-896/inst/osmo-bsc/bin/osmo-bsc+0x259999)

Fixes: OS#3206

Change-Id: I84d10caaadcfa6bd46ba8756ca89aa0badcfd2e3
2018-05-04 18:29:26 +02:00
Pau Espin 13154ffabd Bump version: 0.10.2.284-bc47-dirty → 0.11.0
Remark: For libosmogb and libosmogsm, LIBVERSION was
already bumped in c4fce1425e.

Change-Id: Ib4fa53a9bb9954ae48d0a610ba9a81dd8e8b4ef6
2018-05-03 15:47:11 +02:00
Neels Hofmeyr 7c0031fc80 cosmetic: flatten ctrl_handle_msg()
Change-Id: I3a711f5c974b7f56e27b333d390d1a706fb57007
2018-04-05 03:11:52 +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
Harald Welte 5995281fd6 CTRL: Ensure peer/connection info is always printed the same way
Now that we use osmo_sock_get_name() to print connection information
at disconnect, let's use the same also at accept() time.

Furthermore, let's call it CTRL connection everywhere for consistency.

Change-Id: I33ee7d0ed853c5b2a4ae4e8ef945f8f27753cdea
2017-12-22 18:05:48 +01:00
Harald Welte 29e2798ec5 control_if: Log the disconnect of a CTRL client
We are logging new CTRL connections at LOGL_INFO, so we should
also log disconnects for symmetry.

Change-Id: Id30aa76a5a3dab32d6b4121ce6fdf56d71dfc2ba
2017-12-22 18:05:45 +01:00
Harald Welte f360b42ca1 control_if: Close control connection socket/fd on read/write == 0
When read() or write() system calls return '0' on a stream socket,
it means that the connection has been closed ("EOF").  We must
accordingly close this socket and remove all related state.

Before this patch, every new CTRL connection would introduce a leak
of both some memory/state, as well as a file descriptor :(

Change-Id: I4fb70e5f123b37dece29f156c5f430c875e7cbaf
2017-12-22 16:48:14 +01:00
Neels Hofmeyr a5e2162cf1 ctrl: separate handling of GET_REPLY, SET_REPLY and TRAP
So far, error reporting just says "Trap/Reply", more accurately report 'GET
REPLY', 'SET REPLY' and 'TRAP' as appropriate.

Change-Id: Ic25a251502499aeda4e2952ec4190a1fa0bebb01
2017-12-20 15:50:30 +00:00
Neels Hofmeyr 3da9aa6b67 ctrl: tighten CTRL input parsing
Validate that incoming CTRL commands...
- have decimal IDs,
- return error on trailing characters,
- have invalid characters in variable identifiers,
- send detailed error messages as reply to the requestor.

Adjust ctrl_test.{c,ok}, which best show the change in behavior.

Message handling causes log messages on stderr; previously, stderr was empty.
Add '[ignore]' in testsuite.at so that the nonempty stderr doesn't cause test
failures.

Change-Id: I96a9b6b6a3a5e0b80513aa9eaa727ae8c9c7d7a1
2017-12-20 15:50:24 +00:00
Neels Hofmeyr c0b0b62305 ctrl: on parse errors, return a detailed message to sender
The recently added ctrl_cmd_parse2() returns non-NULL cmd with error messages
upon parsing errors. In handle_control_read(), use ctrl_cmd_parse2() and send
those back to the CTRL command sender as reply.

Retain the previous "Command parser error" reply only in case ctrl_cmd_parse2()
should return NULL, which shouldn't actually happen at all.

Change-Id: Ie35a02555b76913bb12734a76fc40fde7ffb244d
2017-12-18 23:05:50 +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 f2c10f1082 ctrl: fix mem leak when handling GET_REPLY and SET_REPLY
In ctrl_handle_msg() (code recently propagated from handle_control_read()),
talloc_free() the parsed ctrl_cmd in all code paths. In particular, a free was
missing in case ctrl_cmd_handle() returns CTRL_CMD_HANDLED.

CTRL_CMD_HANDLED is triggered by GET_REPLY / SET_REPLY parsing, as show by
ctrl_test.c. With the memleak fixed, adjust expected test output and make a
detected mem leak abort the test immediately.

Change-Id: Id583b413f8b8bd16e5cf92a8a9e8663903646381
2017-12-18 23:05:50 +00:00