Age | Commit message (Collapse) | Author | Files | Lines |
|
This patch is a preparation for the upcoming change making use of
the built-in static_assert(), which is available since C11.
When using built-in static_assert(), gcc v12.2.1 fails:
include/osmocom/core/msgb.h: In function 'msgb_alloc_headroom_c':
include/osmocom/core/msgb.h:532:33: error: expression in static assertion is not constant
532 | osmo_static_assert(size >= headroom, headroom_bigger);
include/osmocom/core/utils.h:86:24: note: in definition of macro 'osmo_static_assert'
86 | static_assert((exp), "(" #exp ") failed")
| ^~~
include/osmocom/core/msgb.h: In function 'msgb_alloc_headroom':
include/osmocom/core/msgb.h:554:33: error: expression in static assertion is not constant
554 | osmo_static_assert(size >= headroom, headroom_bigger);
include/osmocom/core/utils.h:86:24: note: in definition of macro 'osmo_static_assert'
86 | static_assert((exp), "(" #exp ") failed")
| ^~~
These are not really *static* assert()s, because they operate on the
user supplied arguments 'size' and 'headroom', which are not guaranteed
to be integer literals. Neither they trigger compilation failures
as expected, nor do they abort at run-time. They simply do nothing.
Change-Id: I17ef4f3283ce20a5b452b7874c826acfb02a0123
|
|
Those are similar to existing *msgb_alloc*() functions but allows
to change the size of destination msgb provided it fits the
data from source msgb.
Change-Id: I36d4c16241d19f0f73c325be4d0e0bdef6813615
Signed-off-by: Max <msuraev@sysmocom.de>
|
|
The macro msgb_sms() is basically an alias for msgb_l4(). Lets use
msgb_l4() in msgb_l4len() instead of msgb_sms().
Change-Id: I90d4f5c07fbaadd9e022752a2c64c4855f0b4227
|
|
When any of l1h, l2h, l2h or l4h is set to NULL (which is the default
for newly allocated message buffers). Then the msgb_lXhlen() functions
will return the address value of msgb->tail. This can lead to unexpected
results at a later point. We should have an OSMO_ASSERT to catch the
problem early.
Change-Id: I1795c559f190713ebbabfbabf3453ab77da46a49
Related: OS#5645
|
|
Change-Id: Iff666b5fa0b320ae47b6c8c5dfd39debd2d9b8b7
|
|
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
|
|
Underlaying APIs (msgb_alloc) use a uint16_t as a type, which means
until now passing a value > 2^16 would succeed providing a msgb with
less space than requested.
Since those are static inline, there's no symbols used by apps, so we
should be safe enough changing the type to be uint16_t, since change
would only be applied at re-compile time.
Change-Id: I83c8222484e4856c68134a1a9d8cf96eb91af1b8
|
|
Change-Id: I55b68098e1037c74ebe5faa86e34bd4494f5b726
|
|
Nothinh really forbids this case, it's totally fine allocating all space
of msgb as headroom. osmo-pcu actually does that in
gprs_rlcmac_ul_tbf::snd_ul_ud().
Related: OS#4029
Change-Id: Ibe05d08e3169a2603e891f76682a3b352a93ec7a
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
* 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
|
|
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
|
|
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
|
|
It's a common pattern having a list of msgb and having to maintain its
size (for instance, to limit the maximum size of the list). Having the
counter updated at the same time that the msgb is enqueued or dequeued
helps avoiding introducing new bugs by forgetting to update the size
counter at the right places.
Change-Id: I33b501e89a8f29e4aa121696bcbb13d4b83db40f
|
|
Change-Id: I512ff2035ae7a929e6c96df82938cc1ddbcc4e2a
|
|
Change-Id: I27bb2ab59408c9cd1363b3b5acb2263128c55732
|
|
This avoids compiler warnings like
/tmp/work/sysmobts_v2-poky-linux-gnueabi/osmo-pcu/0.4+gitAUTOINC+4c112dc5a6-r1.18/recipe-sysroot/usr/include/osmocom/core/msgb.h: In function 'const char* msgb_hexdump_l2(const msgb*)':
error: invalid conversion from 'void*' to 'const unsigned char*' [-fpermissive]
return osmo_hexdump(msgb_l2(msg), msgb_l2len(msg));
which we've been getting in osmo-pcu builds on some platforms.
Change-Id: I0ec652a1a569ec1507d8411cf1ef87afabcca799
|
|
Change-Id: I98e85397fb541ee0fd711f2e1852f63f3bb87359
|
|
Related: Iaad35f03e3bdfabf3ba82b16e563c0a5d1f03639 (libosmo-netif)
Change-Id: Ia291832ca445d4071f0ed9a01730d945ff691cf7
|
|
In ASCII string based protocols it a printf() version that prints
directly to the message buffer may be useful.
Add function msgb_printf(), make sure that msg buffer bounderies
are not exceeded. If the end of the tail buffer is hit, return
with an error code.
Change-Id: I15e1af68616309555d0ed9ac5da027c9833d42e3
|
|
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
|
|
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
|
|
It's a pity that even with this patch we still are fare away from having
the whole API documented. However, at least we have a more solid
foundation. Updates not only extend the documentation, but also make
sure it is rendered properly in the doxygen HTML.
Change-Id: I1344bd1a6869fb00de7c1899a8db93bba9bafce3
|
|
Introduce msgb_pull_to_l2() which pulls (removes) any msgb contents in
front of the L2 header (msg->l2h).
Change-Id: I7786a1b30f9e7eaa3dcdb3cbb2a85a126588f6cd
|
|
Those work analoguous to msgb_put_*() but pre-pend the given value
into the msg headroom, rather than appending it to the end.
Change-Id: I7de63e9d04c2d2b678f1f20eef37f9be2c4f5ec2
|
|
So far each and every main() scope creates a msgb talloc context and either
passes it to msgb_set_talloc_ctx() or sets tall_msgb_ctx directly (by defining
it extern first).
Remove some code duplication: add one central function that creates the "msgb"
talloc context for all.
Most users of msgb employ a talloc_named_const(), but osmo-bts uses a
talloc_pool() instead. Offer both ways by means of the pool_size argument, and
for both ways make sure the context is called "msgb".
Suggest that msgb users should move to this new function: deprecate
msgb_set_talloc_ctx(). To be able to do so, include core/defs.h in msgb.h.
There's a tradeoff between hiding the msgb talloc context behind API that tries
to guess all use cases versus avoiding code dup. This patch opts against code
dup and boldly assumes that all future use is covered.
Also, the new function suggests to not access tall_msgb_ctx directly, which can
be considered a style improvement.
It seems that not all main scopes that use msgb actually initialize the msgb
ctx. As a fallback for these, explicitly initialize tall_msgb_ctx to NULL.
Change-Id: I747fbbf977c4d2c868c8dead64cfc5fd86eb8d4c
|
|
Change-Id: I72f31ebad693f98eb088a99b83aeb10cf9acc29e
|
|
Currently msgb_trim only checks for len > data_len and returns -1
in that case, allowing the caller to fix it somehow. Using a negative
length will always lead to a corrupt msgb, but this is not being
checked.
This commit adds a check for len < 0 and a conditional call to MSGB_ABORT.
Sponsored-by: On-Waves ehf
|
|
This adds a function that verifies whether a mgsb is consistent.
Sponsored-by: On-Waves ehf
|
|
These functions originate from openbsc/src/gprs but are generic
msgb helper functions.
msgb_copy: This function allocates a new msgb, copies the data
buffer of msg, and adjusts the pointers (incl. l1h-l4h)
accordingly.
msgb_resize_area:
This resizes a sub area of the msgb data and adjusts the
pointers (incl. l1h-l4h) accordingly.
Sponsored-by: On-Waves ehf
|
|
|
|
Submitted-by: Max <max.suraev@fairwaves.co>
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
|
|
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
|
|
Currently it takes 3s to establish a SAPI 3 SACCH connection with
osmo-bts. This is due to the fact, that a broken SABME request is
sent first and and is ignored by the MS. Then, after a T200 timeout
(2s) the SABME command is sent again (this time correctly) and
answered by the MS.
The first SABME message is broken (it has a length field of 3 and
ends with 3 bytes from the tail of the original RSL message),
because of it is expected throughout lapdm.c that msg buffers
containing RSL have msg->l2h == msg->data. Some abis input drivers
fulfill this but IPA doesn't, thus the 3 bytes of the IPA header
are still part of the msg and confuse length computation.
Since internal fields of the msg are modified directly, this is
difficult to see.
This patch adds a new function msgb_pull_to_l3() that explicitely
skips over all headers prepending L3 and therefore resets l1h and
l2h. This function is then used instead of msgb_pull_l2h() which
only worked correctly when msg->l2h == msg->data. In addition,
code manipulating msg->tail and msg->len directly has been replaced
by calls to msgb_trim().
Note that this patch does not fix all issues of this case in the LADP
related code.
Ticket: SYS#192
Sponsored-by: On-Waves ehf
|
|
This function works like osmo_hexdump() and returns a static buffer
containing hex bytes along with markers for the layers.
Note that it uses osmo_hexdump() internally, thus a call to
msgb_hexdump() invalidates the buffer that has been returned by an
earlier call to osmo_hexdump(). In short: don't mix them in a single
call printf().
Sponsored-by: On-Waves ehf
|
|
Doxygen generates quite a lot of warnings on libosmocore. Some of them
are obvious typos - this patch aims to fix such low-hanging fruit.
|
|
msgb_pull returns a pointer to the new begin of the
buffer, unlike msgb_get(), where those functions
were originally taken from.
Signed-off-by: Steve Markgraf <steve@steve-m.de>
|
|
msgb_get() has been wrong all the time, despite the documentation being
correct. If you've used the broken msgb_get() before, you have to
change your code now, sorry.
|
|
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
|
|
The previous commit introduced a new msgb_trim() but the implementation
differed from the specification.
|
|
|
|
|
|
|
|
this ensures struct msgb is the same size as before, which will ensure
binary compatibility
|