aboutsummaryrefslogtreecommitdiffstats
path: root/include/osmocom/core
AgeCommit message (Collapse)AuthorFilesLines
2019-04-10Add _c versions of functions that otherwise return static buffersHarald Welte3-0/+33
We have a habit of returning static buffers from some functions, particularly when generating some kind of string values. This is convenient in terms of memory management, but it comes at the expense of not being thread-safe, and not allowing for two calls of the related function within one printf() statement. Let's introduce _c suffix versions of those functions where the caller passes in a talloc context from which the output buffer shall be allocated. Change-Id: I8481c19b68ff67cfa22abb93c405ebcfcb0ab19b
2019-04-08add osmo_use_count APINeels Hofmeyr1-0/+228
Provide a common implementation of use counting that supports naming each user as well as counting more than just one use per user, depending on the rules the caller implies. In osmo-msc, we were originally using a simple int counter to see whether a connection is still in use or should be discarded. For clarity, we later added names to each user in the form of a bitmask of flags, to figure out exactly which users are still active: for logging and to debug double get / double put bugs. This however is still not adequate, since there may be more than one CM Service Request pending. Also, it is a specialized implementation that is not re-usable. With this generalized implementation, we can: - fix the problem of inadequate counting of multiple concurrent CM Service Requests (more than one use count per user category), - directly use arbitrary names for uses like __func__ or "foo" (no need to define enums and value_string[]s), - re-use the same code for e.g. vlr_subscr and get fairly detailed VLR susbscriber usage logging for free. Change-Id: Ife31e6798b4e728a23913179e346552a7dd338c0
2019-04-08add osmo_sockaddr_str APINeels Hofmeyr1-0/+87
For handling RTP IP addresses and ports, osmo-mgw, osmo-bsc and osmo-msc so far have their own separate shims and code duplication around inet_ntoa(), htons(), sockaddr conversions etc. Unify and standardize with this common API. In the MGW endpoint FSM that was introduced in osmo-bsc and which I would like to re-use for osmo-msc (upcoming patch moving that to osmo-mgw), it has turned out that using char* IP address and uint16_t port number types are a convenient common denominator for logging, MGCP message composition and GSM48. Ongoing osmo-msc work also uses this for MNCC. This is of course potentially useful for any other IP+port combinations besides RTP stream handling. Needless to say that most current implementations will probably stay with their current own conversion code for a long time; for current osmo-{bsc,msc,mgw} work (MGW endpoint FSM) though, I would like to move to this API here. Change-Id: Id617265337f09dfb6ddfe111ef5e578cd3dc9f63
2019-04-03Add _buf() functions to bypass static string buffersHarald Welte2-1/+3
We have a number of static buffers in use in libosmo*. This means the related functions are not usable in a thread-safe way. While we so far don't have many multi-threaded programs in the osmocom universe, the static buffers also prevent us from calling the same e.g. string-ify function twice within a single printf() call. Let's make sure there's an alternative function in all those cases, where the user can pass in a caller-allocated buffer + size, and make the 'classic' function with the static buffer a wrapper around that _buf() variant. Change-Id: Ibf85f79e93244f53b2684ff6f1095c5b41203e05
2019-03-29osmo_escape_str_buf: Always copy, don't return input string pointerHarald Welte1-1/+1
osmo_escape_str_buf() used to have the somewhat odd semantics that if no escaping was needed, it would return the original pointer without making any copy to the output buffer. While this seems like an elegant optimization, it is a very strange behavior and it works differently than all of our other *_buf() functions. Let's unify the API and turn osmo_escape_str_buf() into a strlcpy() if no escaping is needed. Change-Id: I3a02bdb27008a73101c2db41ac04248960ed4064
2019-03-27Doxygen: fix documentation of rate_ctr_for_each_counter()Vadim Yanitskiy1-4/+0
Doxygen was confused by duplicated documentation for both definition and declaration of rate_ctr_for_each_counter(). Moreover, both variants contained some mistakes. Let's avoid this duplication and keep the only (corrected) one. Change-Id: Icca2d4a95bd5f96ae85a86909ec90fb8677cacf3
2019-03-27core/msgb.h: fix incorrect Doxygen parameter descriptionVadim Yanitskiy1-5/+5
core/msgb.h:414: warning: argument 'msgb' of command @param is not found in the argument list of msgb_pull_to_l2(struct msgb *msg) core/msgb.h:399: warning: argument 'msgb' of command @param is not found in the argument list of msgb_pull_to_l3(struct msgb *msg) core/msgb.h:351: warning: argument 'msgb' of command @param is not found in the argument list of msgb_push_u16(struct msgb *msg, uint16_t word) core/msgb.h:361: warning: argument 'msgb' of command @param is not found in the argument list of msgb_push_u32(struct msgb *msg, uint32_t word) core/msgb.h:341: warning: argument 'msgb' of command @param is not found in the argument list of msgb_push_u8(struct msgb *msg, uint8_t word) Change-Id: I5d660933ecfa89c631319eccf9e3d5c1986ec8ff
2019-03-27core/msgb.h: drop meaningless parameter of msgb_eq_* helpersVadim Yanitskiy1-5/+5
Thanks to the following Doxygen warning: msgb.h:XXX: warning: The following parameters of msgb_eq_l2(msg1, msgb2, len) are not documented: parameter 'msgb2' parameter 'len' it was discovered that parameter 'len' is not required at all. It basically doesn't make any sense to pass any length value, because it can be calculated using msgb_length(). Let's drop this parameter. Given that this part of the API was broken so far (see I1079d629abdb8770eef6be7341e586a933cd9cca), it should be more or less safe to do this. Change-Id: Icd9b72eb6bfa9628ff1ed2f948b57058551a4328
2019-03-27core/msgb.h: fix dead msgb2 reference in msgb_eq_* helpersVadim Yanitskiy1-5/+5
Neither Doxygen documentation of the msgb data comparison helpers, nor their actual definitions does refer msgb2. Instead, 'msg2' is referenced in both cases. This was discovered while investigating the following Doxygen warnings: msgb.h:XXX: warning: argument 'msg2' of command @param is not found in the argument list of msgb_eq(msg1, msgb2, len) msgb.h:XXX: warning: The following parameters of msgb_eq_l2(msg1, msgb2, len) are not documented: parameter 'msgb2' parameter 'len' Due to this bug it was impossible to use the affected macros, because 'msg2' was not listed in their parameters. Having the unit test coverage would spot this bug at the beginning! Change-Id: I1079d629abdb8770eef6be7341e586a933cd9cca
2019-03-27core/linuxlist.h: fix white-space and inconsistent alignmentVadim Yanitskiy1-19/+19
- fix trailing white-space; - properly align parameters of functions; - use tabs instead of 8 spaces where possible. Change-Id: Iaf616592a6bd72a1e7e94d8c55475710868beef0
2019-03-27core/linuxlist.h: fix and unify Doxygen documentationVadim Yanitskiy1-99/+96
- drop incorrect \ref and \a references; - add missing documentation to LLIST_HEAD_INIT; - document parameter 'member' of llist_entry(); - turn @argument naming into a valid \param format; - fix 'type *' vs llist_head loop counter confusion; - capitalize and dot-terminate all sentences. Change-Id: Iac67bdb9d5fbf7c222d04858967337f2428d6a94
2019-03-21select: Rename BSC_FD_* constants to OSMO_FD_*Harald Welte1-5/+10
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-19socket: osmo_sock_get_name() Use "const void *" as talloc contextHarald Welte1-1/+1
Change-Id: Ie6877277cddb0a9e049449c260afe3314ba65050
2019-03-07fsm: add osmo_fsm_inst_state_chg_keep_or_start_timer()Neels Hofmeyr1-0/+15
During FSM design for osmo-msc, I noticed that the current behavior that keep_timer=true doesn't guarantee a running timer can make FSM design a bit complex, especially when using osmo_tdef for timeout definitions. A desirable keep_timer=true behavior is one that keeps the previous timer running, but starts a timer if no timer is running yet. The simplest example is: a given state repeatedly transitions back to itself, but wants to set a timeout only on first entering, avoiding to restart the timeout on re-entering. Another example is a repeated transition between two or more states, where the first time we enter this group a timeout should start, but it should not restart from scratch on every transition. When using osmo_tdef timeout definitions for this, so far separate meaningless states have to be introduced that merely set a fixed timeout. To simplify, add osmo_fsm_inst_state_chg_keep_or_start_timer(), and use this in osmo_tdef_fsm_inst_state_chg() when both keep_timer == true *and* T != 0. In tdef_test.ok, the changes show that on first entering state L, the previous T=1 is now kept with a large remaining timeout. When entering state L from O, where no timer was running, this time L's T123 is started. Change-Id: Id647511a4b18e0c4de0e66fb1f35dc9adb9177db
2019-03-06represent negative T-timers as Osmocom-specific X-timersNeels Hofmeyr2-3/+11
fi->T values are int, i.e. can be negative. Do not log them as unsigned, but define a distinct timer class "Xnnnn" for negative T values: i.e. for T == -1, print "Timeout of X1" instead of "Timeout of T4294967295". The negative T timer number space is useful to distinguish freely invented timers from proper 3GPP defined T numbers. So far I was using numbers like T993210 or T9999 for invented T, but X1, X2 etc. is a better solution. This way we can make sure to not accidentally define an invented timer number that actually collides with a proper 3GPP specified timer number that the author was not aware of at the time of writing. Add OSMO_T_FMT and OSMO_T_FMT_ARGS() macros as standardized timer number print format. Use that in fsm.c, tdef_vty.c, and adjust vty tests accordingly. Mention the two timer classes in various API docs and VTY online-docs. Change-Id: I3a59457623da9309fbbda235fe18fadd1636bff6
2019-02-26log: fsm: allow logging the timeout on state changeNeels Hofmeyr1-0/+1
Add a flag that adds timeout info to osmo_fsm_inst state change logging. To not affect unit testing, make this an opt-in feature that is disabled by default -- mostly because osmo_fsm_inst_state_chg_keep_timer() will produce non-deterministic logging depending on timing (logs remaining time). Unit tests that don't verify log output and those that use fake time may also enable this feature. Do so in fsm_test.c. The idea is that in due course we will add osmo_fsm_log_timeouts(true) calls to all of our production applications' main() initialization. Change-Id: I089b81021a1a4ada1205261470da032b82d57872
2019-02-17add OSMO_STRBUF_PRINTF()Neels Hofmeyr1-0/+85
We are using macros like this or different workarounds in libmsc. In the course of implementing inter-MSC handover, I am encountering yet another such situation of appending multiple strings to a limited char buffer. Standardize. Add a unit test to utils_test.c. Change-Id: I2497514e26c5e7a5d88985fc7e58343be1a027b2
2019-02-05bitvec: Add bitvec_tailroom_bits() functionHarald Welte1-0/+6
This is similar to msgb_tailroom(): It returns the amount of space left at the end of the bit vector (compared to the current cursor). The function returns the number of bits left in the bitvec. Change-Id: I8980a6b6d1973b67a2d9ad411c878d956fb428d1
2019-02-05bitvec: Add bitvec_bytes_used() functionHarald Welte1-0/+9
This new bitvec API function returns the number of bytes used in a given bit-vector. Change-Id: Id4bd7f7543f5b0f4f6f876e283bd065039c37646
2019-02-04add osmo_tdef API, originally adopted from osmo-bsc T_defNeels Hofmeyr1-0/+172
Move T_def from osmo-bsc to libosmocore as osmo_tdef. Adjust naming to be more consistent. Upgrade to first class API: - add timer grouping - add generic vty support - add mising API doc - add C test - add VTY transcript tests, also as examples for using the API From osmo_fsm_inst_state_chg() API doc, cross reference to osmo_tdef API. The root reason for moving to libosmocore is that I want to use the mgw_endpoint_fsm in osmo-msc for inter-MSC handover, and hence want to move the FSM to libosmo-mgcp-client. This FSM uses the T_def from osmo-bsc. Though the mgw_endpoint_fsm's use of T_def is minimal, I intend to use the osmo_tdef API in osmo-msc (and probably elsewhere) as well. libosmocore is the most sensible place for this. osmo_tdef provides: - a list of Tnnnn (GSM) timers with description, unit and default value. - vty UI to allow users to configure non-default timeouts. - API to tie T timers to osmo_fsm states and set them on state transitions. - a few standard units (minute, second, millisecond) as well as a custom unit (which relies on the timer's human readable description to indicate the meaning of the value). - conversion for standard units: for example, some GSM timers are defined in minutes, while our FSM definitions need timeouts in seconds. Conversion is for convenience only and can be easily avoided via the custom unit. By keeping separate osmo_tdef arrays, several groups of timers can be kept separately. The VTY tests in tests/tdef/ showcase different schemes: - tests/vty/tdef_vty_test_config_root.c: Keep several timer definitions in separately named groups: showcase the osmo_tdef_vty_groups*() API. Each timer group exists exactly once. - tests/vty/tdef_vty_test_config_subnode.c: Keep a single list of timers without separate grouping. Put this list on a specific subnode below the CONFIG_NODE. There could be several separate subnodes with timers like this, i.e. continuing from this example, sets timers could be separated by placing timers in specific config subnodes instead of using the global group name. - tests/vty/tdef_vty_test_dynamic.c: Dynamically allocate timer definitions per each new created object. Thus there can be an arbitrary number of independent timer definitions, one per allocated object. T_def was introduced during the recent osmo-bsc refactoring for inter-BSC handover, and has proven useful: - without osmo_tdef, each invocation of osmo_fsm_inst_state_chg() needs to be programmed with the right timeout value, for all code paths that invoke this state change. It is a likely source of errors to get one of them wrong. By defining a T timer exactly for an FSM state, the caller can merely invoke the state change and trust on the original state definition to apply the correct timeout. - it is helpful to have a standardized config file UI to provide user configurable timeouts, instead of inventing new VTY commands for each separate application of T timer numbers. Change-Id: Ibd6b1ed7f1bd6e1f2e0fde53352055a4468f23e5
2019-02-04socket.h: add missing includeMax1-2/+7
socket.h uses INET6_ADDRSTRLEN without including arpa/inet.h where it's defined which might break external users of socket.h Fix this by adding missing include. The error was introduced in 64b51eb68bd272b6b1f2cefa2b33e9dd74024d0c Change-Id: I2883addcb81cec038577e401e356e8f07a947d4c
2019-01-29osmo_fsm_state_name: make robust against NULL fiNeels Hofmeyr1-1/+1
Change-Id: I61d4f7dfada2763948f330745ac886405d889a12
2019-01-28add osmo_hexdump_buf() and testNeels Hofmeyr1-0/+3
Add osmo_hexdump_buf() as an all-purpose hexdump function, which all other osmo_hexdump_*() implementations now call. It absorbs the static _osmo_hexdump(). Add tests for osmo_hexdump_buf(). Rationale: recently during patch review, a situation came up where two hexdumps in a single printf would have been useful. Now I've faced a similar situation again, in ongoing development. So I decided it is time to provide this API. The traditional osmo_hexdump() API returns a non-const char*, which should probably have been a const instead. Particularly this new function may return a string constant "" if the buf is NULL or empty, so return const char*. That is why the older implementations calling osmo_hexdump_buf() separately return the buffer instead of the const return value directly. Change-Id: I590595567b218b24e53c9eb1fd8736c0324d371d
2019-01-21Rename msgb_wrap_with_TL()Max1-1/+1
This resolves an issue introduced in 84fb5bb6a09a6a358f98c654c84c3b99a0f24eef when msgb_wrap_with_TL() was introduced as an inline function with *exactly the same name* as in osmo-msc.git and openbsc.git. We *NEVER* do something like this. Functions moved from applications to library *MUST* always be renamed. This has been the case for almost a decade now. With this subsequent change we make sure the libosmocore function has a different name and doesn't clash. After this commit, old openbsc.git and osmo-bsc.git should again build fine. Change-Id: If1e851ac605c8d2fde3da565b0bd674ea6350c2e
2019-01-17socket: add define for socket name lengthPhilipp Maier1-0/+2
The function osmo_sock_get_name_buf() can be used to write a string representation to a user provided memory. Unfortunately the proper length for the user provided memory is not obvious. To make using osmo_sock_get_name_buf() more practical, add a define constant that defines the length of the required memory. Also use this define in socket.c. Change-Id: If8be8c2c0d4935da17ab13b2c2127b719ceefbcc
2019-01-14gsm23003: add osmo_imei_str_valid()Oliver Smith1-0/+2
Verify 14 digit and 15 digit IMEI strings. OsmoHLR will use the 14 digit version to check IMEIs before writing them to the DB. Place the Luhn checksum code in a dedicated osmo_luhn() function, so it can be used elsewhere. Related: OS#2541 Change-Id: Id2d2a3a93b033bafc74c62e15297034bf4aafe61
2019-01-03add LOGPFSMSL(), LOGPFSMSLSRC()Neels Hofmeyr1-6/+30
Using an FSM instace's logging context is very useful. Sometimes it makes sense to log something on a different logging category than the FSM definition's default category. For example, an MSC conn has aspects concerning MM, CC, RR, MGCP, ..., and currently all of those log on DMM. This came up in I358cfbaf0f44f25148e8b9bafcb9257b1952b35a, where I want to log an MGCP event using a ran_conn context, and used the conn->fi->id. That of course omits context like the current conn FSM state... I remember at least one other place where I recently added logging using some fi->id as context, so it might turn out useful in various places. Change-Id: I11b182a03f5ecb6df7cd8f260757d3626c8e945d
2019-01-03LOGPFSM*: guard against fi == NULLNeels Hofmeyr1-4/+4
The LOGPFSM macros are in such wide use that they should guard against a NULL fi pointer. In case of NULL, default to subsys = DLGLOBAL, loglevel = LOGL_ERROR and state = "fi=NULL". Change-Id: I9eaf8b7e2cf1e450ae626cb2fc928862008f6233
2019-01-03add API doc for LOGPFSM* macrosNeels Hofmeyr1-0/+31
Change-Id: I3bf6500889aa58195f50a726dec0876c0c2baec3
2018-12-23define LOGPFSM fmt only once, in LOGPFSMLSRCNeels Hofmeyr1-7/+4
Instead of duplicating the fmt and args in LOGPFSML and LOGPFSMLSRC, rather make LOGPFSML invoke LOGPFSMLSRC with __FILE__ and __LINE__. This is a cosmetic preparation for more tweaks coming up. Change-Id: I2f23c57ebfdb5355919c06ac5ded7732e3b17a97
2018-12-19add to osmo_sock_get_name*() APINeels Hofmeyr1-0/+3
Basically, I am applying code review that I would have given had I not been on vacation when the last osmo_sock_get_name* stuff was merged. osmo_sock_get_name2() is so far a static internal function. However, it is nothing like osmo_sock_get_name(), so instead rename it to osmo_sock_get_ip_and_port(). Also make it public API, no need to hide it. I'm adding an "and" in the name to hopefully clarify: "ip_port" vs. "ip_and_port" -- there already are _get_X_ip_port() functions that only return the port string, despite "ip" in the name. Add new public osmo_sock_get_name2(), which is like osmo_sock_get_name(), except it uses a static string instead of talloc, and omits the braces. This is most convenient for log statement formats, avoiding dyn allocations. Add new osmo_sock_get_name_buf(), which is like osmo_sock_get_name2() but writes to a caller provided char buffer. Use osmo_sock_get_name_buf() in the implementation of osmo_sock_get_name(), but use another (non-static) local string buffer, because adding braces is too complex without talloc_snprintf(). Rationale: I want to improve the logging of socket errors, e.g. change DLMGCP ERROR Failed to read: 111/Connection refused (mgcp_client.c:720) to DLMGCP ERROR Failed to read: r=10.0.99.2:2427<->l=10.0.99.2:2728: 111='Connection refused' (mgcp_client.c:721) but it is just not handy to compose logging with the current API: - osmo_sock_get_name() requires a talloc_free(). - all the others require output buffers. - the only way to conveniently compose a logging string and, - notably, the only trivial way to skip the string composition if the logging level is currently muted, is to have a function that returns a static string: the new osmo_sock_get_name2(). - (I think the osmo_sock_get_{local,remote}_* convenience wrappers should never have been added, because they encourage the caller to invoke the same code twice, for IP addr and port, and throw away one half each time.) Related: Iae728192f499330d16836d9435648f6b8ed213b6 (osmo-mgw) Change-Id: I8ad89ac447c9c582742e70d082072bdd40a5a398
2018-12-13stats.h: Fix build on MacOSPau Espin Pedrol1-2/+2
Otherwise struct osmo_stats_config is not defined and compiler fails. Related: OS#3722 Change-Id: I037c3ca141ecee2d457e0a881a56e32ee24cec4d
2018-12-12msgb: add test helpersMax1-0/+139
It's often handy to compare certain msgb layer to a given array and print the position where they differ. Add simple pretty-printer and corresponding L* wrappers. Change-Id: I3bc95f2f5ab6e3f4b502647fb3e0aaaf1f7c4cf5
2018-12-10add osmo_bcd2str()Neels Hofmeyr1-0/+2
Add a standalone bcd-to-string conversion function with generic parameters. Add a regression test in utils_test.c. So far there is no single universal implementation that converts a BCD to a string. I could only find gsm48_mi_to_string(), which also interprets surrounding bytes, MI type and TMSI as non-BCD value. The idea is to use this function from gsm48_mi_to_string() and similar implementations in subsequent commits. Root cause: in osmo-msc, I want to have an alternative MI-to-string function for composing an FSM name, which needs the BCD part of gsm48_mi_to_string() but not the TMSI part. Change-Id: I86b09d37ceef33331c1a56046a5443127d6c6be0
2018-12-10Constify llist_count() parameterMax1-1/+1
Counting list entires should not alter the list content: let's make this obvious from type signature. Change-Id: I414e67a3de733fab407161b3264d3b89070ba537
2018-12-10timer: Fix clockid_t undefined on MacOS < 10.12Pau Espin Pedrol2-0/+5
Related: OS#3722 Change-Id: If466a64bd44dcb8ae8a9b7f82bc9c9435ba3e640
2018-12-07Add osmo_sockaddr_in_to_str_and_uint()Max1-0/+3
It's similar to osmo_sockaddr_to_str_and_uint() but does not require odd typecasting for AF_INET case. Make osmo_sockaddr_to_str_and_uint() into wrapper around new function and make sure to check for address family before typecasting. Also use proper return type. Change-Id: Ie384483124d407a960ab6732e6a7fd90554389d2
2018-12-03Update msgb Lx helpersMax1-1/+17
* add missing L1 and L4 hexdump * add msgb_l4() for consistency and convert msgb_sms() into simple alias Those will be used in follow-up patches for msgb debug/test helpers. Change-Id: I8d6dd1b1ff3aa98a452711c692ca7dee0449203b
2018-11-19Move msgb_push helpers to public headerMax1-0/+9
The msgb_wrap_with_TL() is generally useful so it make sense to make it public to facilitate code re-use. Other helpers can be implemented as trivial wrappers over existing tlv.h functions. Update headers and code accordingly. Change-Id: I37e91d031fba28cf1c6735b8069b0265746f55e6
2018-11-07core/msgb.h: introduce msgb_l4len() helperVadim Yanitskiy1-0/+12
There is already a group of similar functions for L1, L2 and L3, but L4 was missing. The L4 is usually used for parsing of complex L3 messages, such as SS/USSD and SMS. This change introduces a similar halper for L4. Change-Id: I755f2d654bbdad2a8b4f94df9023bdd370b07ae6
2018-10-26add osmo_sock_get_{local,remote}_ip{,_port}()Oliver Smith1-0/+6
Return only the IP or port of either the local or remote connection, not the whole set of IP and port of both the local and remote connection like osmo_sock_get_name() does it. This is needed for OS#2841, where we only want to print the remote IP. Related: OS#2841 Change-Id: I6803c204771c59a2002bc6a0e6b79c83c35f87e1
2018-10-07GSMTAP: fix typos in commentsShinjo Park1-2/+2
Change-Id: I2e710141ee90ddc8b5336d5f81e99bd918d10106
2018-10-07GSMTAP: add definitions for LTE NAS subtypesShinjo Park1-0/+8
Wireshark GSMTAP dissector has LTE NAS subtypes for plain NAS messages and NAS messages with security header. This commit adds definition for these subtypes. Change-Id: I49d15fb13299c1bcbe0fb7e50bf222294c7a49ef
2018-10-07GSMTAP: add definitions for new LTE RRC channelsShinjo Park1-10/+25
Later release of 3GPP TS 36.331 added new LTE RRC channels. This commit additionally defines LTE RRC message types existing in Release V15.3.0. Change-Id: Ifa48b2227be15af04c9a4702d2025abcc660f0df
2018-09-13logging vty: write: check logging levels validityNeels Hofmeyr1-0/+1
Change-Id: If683b1272ad2d5b402b91c52c496aa7975bc6315
2018-09-13logging vty: rewrite 'logging level' vty cmd generationNeels Hofmeyr2-4/+14
Completely drop the implementations of log_vty_command_{str,description}(). These functions have been public API once, marked as deprecated since c65c5b4ea075ef6cef11fff9442ae0b15c1d6af7 (March 2017). I considered to keep them, or reduce them to useless stubs, but it is quite silly, really. These functions are completely and utterly useless outside of libosmocore. Any program linking these deserves to fail. Re-implement vty logging level command gen, in logging_vty.c. logging.c is simply the wrong place for that. Introduce logging_internal.h to share logging definitions to logging_vty.c without publishing as API. Introduce static gen_logging_level_cmd_strs() to compose a list of category arguments with their descriptions for VTY commands. Use osmo_talloc_asprintf() instead of the previous error prone and chaotic strlen() counting method. Do not dynamically generate log level arguments, just keep static strings. We are super unlikely to ever change the log levels we have. No changes in logging_vty_test.vty: proves that there is no functional change. All of this, besides introducing basic sanity, is cosmetic preparation to be able to re-use the generic command generation code for arbitrary commands with category or level args (for deprecated and new keywords). Rationale: I want to hide 'all' and 'everything' from the VTY command documentation, by means of deprecating. I first tried to simply define a deprecated 'logging level CAT everything' command: logging level (all|rsl|rr|...) (debug|info|notice|error|fatal) logging level CAT everything # <- deprecated and hidden But unfortunately, command matching doesn't work as intended when the CAT argument reflects a valid category; I want it to invoke the deprecated function as soon as the 'everything' keyword follows, but it stays stuck to the "valid" command when the category argument matches an explicit keyword in that list, and will throw an error on the following 'everything' keyword. I.e.: logging level rsl everything % Unknown command # <-- leads to config file parse error logging level unknown_string everything % Ignoring deprecated 'everything' # <-- works only for invalid categories So I need to define 'everything' separately, again with a list of each valid category instead of a generic CAT arg. Change-Id: I3b083f27e3d751ccec258880ae7676e9af959a63
2018-09-07add osmo_str_tolower() and _toupper() with testNeels Hofmeyr1-2/+13
We already have osmo_str2lower() and osmo_str2upper(), but these lack: * proper destination buffer bounds checking, * ability to call directly as printf() argument. Deprecate osmo_str2upper() and osmo_str2lower() because of missing bounds checking. Introduce osmo_str_tolower_buf(), osmo_str_toupper_buf() to provide bounds-safe conversion, also able to safely convert a buffer in-place. Introduce osmo_str_tolower(), osmo_str_toupper() that call the above _buf() equivalents using a static buffer[128] and returning the resulting string directly, convenient for direct printing. Possibly truncated but always safe. Add unit tests to utils_test.c. Replace all libosmocore uses of now deprecated osmo_str2lower(). Naming: the ctype.h API is called tolower() and toupper(), so just prepend 'osmo_str_' and don't separate 'to_lower'. Change-Id: Ib0ee1206b9f31d7ba25c31f8008119ac55440797
2018-09-05core/utils.h: move includes to the topVadim Yanitskiy1-3/+2
Having all inculdes listed in one place is a common good practice, which prevents one from adding duplicates. Change-Id: I3f52189d5e8f9afafc39525e95385a085f8f850a
2018-09-05core/utils.h: drop duplicate '<stdbool.h>' includeVadim Yanitskiy1-1/+0
Change-Id: I0979ddda91c4c0aa080b714cf2a698d7634f5091
2018-09-03Add RSPRO support to IPA and logging definitionsHarald Welte1-1/+2
Change-Id: Iee79f5273f32cb9ce4bd7a984e7f0625542e776f