summaryrefslogtreecommitdiffstats
path: root/src/ctrl/control_if.c
Commit message (Collapse)AuthorAgeFilesLines
* select: Rename BSC_FD_* constants to OSMO_FD_*Harald Welte2019-03-211-2/+2
| | | | | | | | | | | | 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
* ctrl: use #define for TRAP idMax2018-12-031-1/+1
| | | | | | | We always use id = 0 when sending TRAP messages. Let's make this more obvious by introducing appropriate define. Change-Id: I33d7d4c6a1885a75a85d6f2f017430e0860b4126
* ctrl: print textual error on IPA parsing failureMax2018-11-261-1/+1
| | | | Change-Id: I49bb613b416d549f554fd9d23cd37b63954324db
* add support for ipaccess messages on the ctrl interfaceStefan Sperling2018-10-151-5/+29
| | | | | | | | | 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
* ctrl: ctrl_handle_msg: Avoid sending back received ERROR msgsPau Espin Pedrol2018-07-161-2/+3
| | | | Change-Id: I396fd1e7548beea31b2b7aa9f764edb765b02941
* ctrl: Add doxygen API documentation; generate html from itHarald Welte2018-05-261-1/+21
| | | | | Closes: OS#3293 Change-Id: I8dc2f24d4bf557ff7bb0f2f46881f9f8d9d7f86f
* cosmetic: Whitespace fixes in control_if.cHarald Welte2018-05-261-3/+3
| | | | Change-Id: I24666d0b90a355e9fdefd280d48900b8cac1de64
* control_if: Avoid heap-use-after-free in osmo_wqueue_bfd_cbPau Espin Pedrol2018-05-041-19/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* cosmetic: flatten ctrl_handle_msg()Neels Hofmeyr2018-04-051-17/+19
| | | | Change-Id: I3a711f5c974b7f56e27b333d390d1a706fb57007
* ctrl: fix deferred commands (and hence fix osmo-bts-sysmo 'clock-info' cmd)Neels Hofmeyr2018-04-051-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* CTRL: Ensure peer/connection info is always printed the same wayHarald Welte2017-12-221-6/+6
| | | | | | | | | 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
* control_if: Log the disconnect of a CTRL clientHarald Welte2017-12-221-1/+4
| | | | | | | We are logging new CTRL connections at LOGL_INFO, so we should also log disconnects for symmetry. Change-Id: Id30aa76a5a3dab32d6b4121ce6fdf56d71dfc2ba
* control_if: Close control connection socket/fd on read/write == 0Harald Welte2017-12-221-1/+9
| | | | | | | | | | | 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
* ctrl: on parse errors, return a detailed message to senderNeels Hofmeyr2017-12-181-11/+23
| | | | | | | | | | | 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
* ctrl: fix mem leak when handling GET_REPLY and SET_REPLYNeels Hofmeyr2017-12-181-2/+1
| | | | | | | | | | | | 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
* ctrl: prep test: separate new ctrl_handle_msg() from handle_control_read()Neels Hofmeyr2017-12-181-17/+26
| | | | | | | | | | 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
* ctrl: make response easier to parseMax2017-11-271-32/+9
| | | | | | | | | | | | | | | | | | | | Previously ctrl request for all counters in group (e. g. 'rate_ctr.abs.msc.0') will result in human-readable description which is not regular enough and is hard to both parse and generate. The ctrl interface is intended for m2m, not for human interaction. Let's simplify things by making response similar to counter group request ('rate_ctr.*'). Reply now looks as follows: GET_REPLY 9084354783926137287 rate_ctr.abs.msc.0 loc_update_type:attach 0;loc_update_type:normal 0; Previously it was: GET_REPLY 9084354783926137287 rate_ctr.abs.msc.0 All counters in msc.0 loc_update_type:attach 0 loc_update_type:normal 0 Change-Id: I7a24cc307450efdcd28168fffe477320c59fcd36 Related: OS#2550
* Improve get_rate_ctr() error handlingMax2017-11-241-1/+1
| | | | | | | Report back expected interval values. Change-Id: I05ca7f716342af4f7424b28216ed6c1bf2bd589f Related: OS#2550
* ctrl: log incorrect interval valuesMax2017-11-241-4/+7
| | | | | | | | This should never happen with the current code, but if it ever does, we should log the error instead of silently returning 0. Change-Id: I544001d3072e5f12a96a67e4178f9b945c5f6b6c Related: OS#2550
* Ctrl: add rate counter group introspectionMax2017-11-241-0/+18
| | | | | | | | | | | | Before user have to know group name and index in advance to request rate counter value. Introduce introspection function which allows user to obtain all the groups and their indexes by requesting 'rate_ctr.*' variable. This simplifies KPI dumping over ctrl interface. Change-Id: Ifad8b4f0360c8bcd123a838676516476e84c246a Related: OS#2550
* Fix/Update copyright notices; Add SPDX annotationHarald Welte2017-11-131-0/+4
| | | | | | | | Let's fix some erroneous/accidential references to wrong license, update copyright information where applicable and introduce a SPDX-License-Identifier to all files. Change-Id: I39af26c6aaaf5c926966391f6565fc5936be21af
* ctrl: allow more nodes than those in enum ctrl_node_typeNeels Hofmeyr2017-10-231-14/+67
| | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Rename 'statistics.c' to 'counter.c'Harald Welte2017-10-151-1/+1
| | | | | | | | | With stat_item, stats.c and stats_statsd.c, it is becoming a bit difficult to understand file naming. Also, the 'statistics.c' file actually only contained osmo_counter handling, so let's rename it to counter.c altogether. Change-Id: I2cfb2310543902b7da46cb15a76e2da317eaed7d
* doxygen: unify use of \file across the boardNeels Hofmeyr2017-06-231-2/+3
| | | | | | | | | | | | | | | | | 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
* doxygen: enable AUTOBRIEF, drop \briefNeels Hofmeyr2017-06-231-6/+6
| | | | | | | | | | 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
* Simplify ctrl cmd lookupMax2017-05-081-21/+19
| | | | | | | Replace if-else ladder & gotos with single switch statement & explicit return to make reading code easier. Change-Id: Ida1b389b571c60c26813cd29e61b3e4423c5df0f
* control_if: Don't use magic number '5' when allocating vectorHarald Welte2017-04-271-1/+1
| | | | | | We have a proper constant for this (_LAST_CTRL_NODE), so let's use it. Change-Id: I46275e644166156cb665da70d2964008f1c6cd88
* control_if: Add control interface commands for FSMsHarald Welte2017-04-271-0/+4
| | | | | | | | | 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
* control_if: Add helper function for 'local execution' of control commandHarald Welte2017-04-271-0/+28
| | | | | | | | 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
* control_if: Add API to initialize control interface without TCP port bindHarald Welte2017-04-261-27/+63
| | | | | | | 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
* ctrl: Allow installation of additional node lookup helpersHarald Welte2017-04-261-0/+41
| | | | | | | | | | | | 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
* fix spelling in API docu, command reply, logging, descriptionsThorsten Alteholz2017-04-231-1/+1
| | | | | | sections: ctrl, gb, gsm, vty Change-Id: Iac211b5cd8504da36b699777b95a2448dd7c3e70
* Handle replies in ctrl_cmd_handle()Max2017-03-011-0/+17
| | | | | | | | | | | | Previously *_REPLY and ERROR messages were not explicitly handled which would lead to sending error in response to them which in turn would prompt other party to send error as well which would result in infinite cycle. Handle it explicitly by logging message id and other relevant data. Change-Id: Id96f3a2fc81fa4549f49556d83f062c6b2f59e28 Related: OS#1615
* Fix client-side ctrl interface helpersMax2017-03-011-40/+1
| | | | | | | | * remove unused ctrl_interface_connect() which is not part of public API * add default read callback to osmo_ctrl_conn_alloc() Change-Id: Iaa209e34a849ce0dfe2e29b482c3208ade1a32a4 Related: OS#1615
* libosmoctrl: Fix typo in ctrl_interface_connect()Harald Welte2017-02-231-1/+1
| | | | | | it's osmo_sock_init_ofd(), not osmo_sock_init_ifd() Change-Id: Ia6a82031a691403f641815862613d99b31a3a159
* Expand and expose ctrl connection allocationMax2017-02-231-5/+51
| | | | | | | | | | | | 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
* Document ctrl_interface_setup_dynip() functionMax2017-02-191-0/+8
| | | | Change-Id: Ie1d5881dda7a9b797d15e9e1eead8281a994d91e
* fix various compiler warnings (on FreeBSD-11.0)Harald Welte2017-02-081-1/+1
| | | | | | | FreeBSD 11.0 uses clang version 3.8.0 which spits various warnings during libosmocore compilation. Let's clean this up a bit. Change-Id: Ic14572e6970bd0b8916604fabf807f1608fa07e5
* Add function to send TRAP over Control InterfaceMax2016-10-121-0/+21
| | | | | Change-Id: Ic0b8d88c4f5c4d42c3f8fb754f8eabf049c9e388 Related: OS#1646
* log CTRL bind address and portNeels Hofmeyr2016-09-231-0/+3
| | | | | | | Log 'CTRL at 1.2.3.4 5678' from ctrl_interface_setup*. All callers can now drop any extra 'CTRL at 1.2.3.4 5678' logging. Change-Id: If449d0514e3d0cc1b346d7452194d931aa090166
* remove unused local variable in get_rate_ctr()Neels Hofmeyr2016-09-191-1/+1
| | | | | | | Unused after 22886d9e320ecf734d2827d825a191b977f70d2c "Fix retrieving rate_ctr over control interface" Change-Id: Ib5411da80c4eb4f905a5ed87c60477eca2cdff42
* remove unused function get_rate_ctr_group()Neels Hofmeyr2016-09-191-37/+0
| | | | | | | Unused after 22886d9e320ecf734d2827d825a191b977f70d2c "Fix retrieving rate_ctr over control interface" Change-Id: I405367ef6ba5833957778a79dd398ce5ea29307e
* Fix retrieving rate_ctr over control interfaceMax2016-06-141-13/+7
| | | | | | | | | | | | Allow getting either particular counter (e. g. rate_ctr.per_hour.e1inp.0.hdlc.abort) or entire rate counter group for a given index (e. g. rate_ctr.per_hour.e1inp.0). Change-Id: I2b0109536170f7b5388d3236df30b98f457aa98d Fixes: OS#1730 Reviewed-on: https://gerrit.osmocom.org/274 Tested-by: Jenkins Builder Reviewed-by: Harald Welte <laforge@gnumonks.org>
* add ctrl_interface_setup_dynip() for bind addressNeels Hofmeyr2016-02-251-1/+9
| | | | | | 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).
* libctrl: Include config.h so we can include netinet/tcp.hHolger Hans Peter Freyther2015-03-181-0/+2
| | | | | | | | | | In e15ac060e7ae78d4c3569d7fc9071bcf49807e05 we tried to fix the nuttx build but we never included "netinet/tcp.h" after it and the compiler warned about the unused "on" parameter which we didn't notice because of the other warnings... Include config.h so we can see if there is a tcp.h and then include it.
* fix libosmocore build for NuttX targetHarald Welte2014-12-041-2/+6
| | | | | | this fixes some compilation issues with libosmocore under NuttX, particularly as some #defines are missing or some header files are slightly different.
* libctrl: Add support for 'deferred control commands'Harald Welte2014-08-241-0/+17
| | | | | | | | | | | | | | 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.
* ctrl: Attempt fix the build on FreeBSD and add include fileHolger Hans Peter Freyther2014-08-211-0/+1
| | | | | IPPROTO_TCP is defined in netinet/in.h. Include it and hope the build is fixed for FreeBSD.
* rename controlif_setup() to ctrl_interface_setup()Harald Welte2014-08-211-2/+2
| | | | | which means that all control interface related functions now have the common ctrl_ prefix.
* libctrl: Move bulk of control node lookup inti libosmoctrlHarald Welte2014-08-211-3/+127
| | | | | | 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.