Commit Graph

1564 Commits

Author SHA1 Message Date
Jacob Erlbeck a89d22c0f0 log: Add conditional logging based on log_check_level
Currently the LOGP/DEBUGP arguments are always evaluated even if
no logging will happen at all. This can be expensive, for instance
if hexdumps or pretty printed object names are generated. This causes
high base load especially on embedded devices and is a major part of
CPU usage e.g. of the osmo-pcu.

This commit uses the log_check_level function to avoid the evaluation
of the parameters if it is known in advance, that no logging entry
will be generated.

Sponsored-by: On-Waves ehf
2016-02-29 14:30:14 +01:00
Jacob Erlbeck de6dd72dbb log: Add log_check_level function
This commit adds this predicate function which can be used to
avoid the execution of code if a certain log level is not enabled.

The function will only return 0 (false), if it is sure that a logging
call for the same facility and level will not produce any output.
This safety criterion shall ensure, that no logging output is lost
due to the use of this predicate as a guard. On the other hand, even
if the predicate returns != 0 (true), no logging output might get
generated by a similar logging command.

Note that the current implementation is not focussed on performance,
which could be improved by using a lookup table instead of iterating
through every target.

Sponsored-by: On-Waves ehf
2016-02-29 14:30:14 +01:00
Neels Hofmeyr f20f5fd508 comment typo 2016-02-29 09:56:39 +01:00
Neels Hofmeyr cda988527f fix gsm_7bit_decode API comment: septets, not octets 2016-02-29 09:56:26 +01:00
Max 6a5ef46dd0 Add byte printing macros
It's sometimes handy for debugging to be able to immediately see which
bits are set in a given byte. Generalize macro used for that in bitvec
tests and make it available for the rest of the library.
2016-02-25 22:35:44 +01: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 96172f0100 vty: add bind command for telnet vty line
Add VTY command
    line vty
     bind A.B.C.D

The command merely stores the configured IP-address, which can then be used by
the calling main program to set the telnet port of the VTY line. (Commits in
openbsc and osmo-iuh will follow up on this.)

Add function vty_get_bind_addr() to publish the address in the vty.h API.

Add static vty_bind_addr to store.

For allocation/freeing reasons, a NULL address defaults to 127.0.0.1.

BTW, I decided against allowing keywords 'any' and 'localhost' in place of an
actual IP address to make sure a written config is always identical to the
parsed config.
2016-02-25 11:02:34 +01:00
Max cc00bf8779 Extend L1SAP PH-DATA with presence information
Previously the presence of header and data blocks were communicated
in-band which decreases code readability and makes it unnecessary hard
to add support for new hardware.

Note: OsmoBTS have to be modified to take advantage of extended
ph_data_param structure.
2016-02-22 11:08:44 +01:00
Jacob Erlbeck f78ec5ce0d gb: Add bssgp_msgb_copy function
This function originates from openbsc/src/gprs but is just specific
to BSSGP/Gb on the same level like bssgp_msgb_alloc.

This commit puts the former gprs_msgb_copy function beside
bssgp_msgb_alloc.

Renamed function:

  gprs_msgb_copy -> bssgp_msgb_copy

Sponsored-by: On-Waves ehf
2016-02-22 10:20:49 +01:00
Holger Hans Peter Freyther ab0eb96dd9 bitvec: Untested speculative UBAN fix for the new routine
int << 31 does not seem to be defined, let's try to make it an
unsigned variable and see if that is pleasing the system.

Fixes:
bitvec.c:219:15: runtime error: left shift of 1 by 31 places cannot be represented in type 'int'
2016-02-18 20:28:25 +01:00
Max 5c18e26bc2 Add T4 bit map compression routines
Add bit map encoder and decoder functions: decoder is fully functional
while encoder is good enough for testing - no backtracking to find
the best possible compression is implemented. If somebody is willing to
implement MS side of EDGE than this has to be expanded.
Add corresponding tests.
N. B: the encoding is implemented according to ETSI TS 44.060 which is
slightly different from T4 used for fax according to CCITT G31D (RFC 804).

Ticket: OW#2407
Sponsored-by: On-Waves ehf

Signed-off-by: Max <msuraev@sysmocom.de>
2016-02-18 19:45:44 +01:00
Max 0a59e9899f Expand bitvec interface
Add bit filling, shifting and other functions necessary for bit
compression implementation. Add corresponding tests.
2016-02-18 19:45:40 +01:00
Neels Hofmeyr 8684714966 Add CSCN ctrl port defs 2016-02-15 12:02:02 +01:00
Neels Hofmeyr 620dfa6be2 add vty port nr for osmo-cscn 2016-02-10 13:28:00 +01:00
Holger Hans Peter Freyther 5710804a42 bivec: Fix the output of the testcase
osmo_hexdump_nospc/osmo_hexdump is an old school C routine with a
static internal array. This means that printf will most likely one
of the two strings twice. For Linux/glibc this is the first string
(for whatever reason?) and for FreeBSD it is the last call of the
osmo_hexdump_nospc. We could have noticed by both strings being
of the same length besides the different length input. The second
issue is that we cast a hexstring to uint8_t and dump the string
as hex. So the two strings should not match at all.

Fix it by printing the hex string as plain hex and separating the
two printf calls. Update the test output.
2016-01-30 16:19:33 +01:00
Holger Hans Peter Freyther a9301a1a1f bitvec: Test and fix regression for C++->C conversion
bitvec_read_field/bitvec_write_field in the PCU used a C++ reference
and when porting to C it was decided to pass the parameter by value
and this lost the "back propagation" of the new index. Change the
parameter to be an in/out parameter and this way do not have a silent
semantic break in the osmo-pcu (where we copy the reference in csn.1
by value) and have a true compile failure.

Add Max's simple test for bitvec_unhex function leaving the checking
of bitvec_read_field and the side effect in the datastructure about
the number of bits still open.
2016-01-30 10:54:43 +01:00
Max 912bc6ff50 Add doxygen comments to clarify function use 2016-01-30 10:18:38 +01:00
Holger Hans Peter Freyther 2745b48940 bitvec: Fix build on older gcc
bitvec.c: In function 'bitvec_unhex':
bitvec.c:389: error: 'for' loop initial declarations are only allowed in C99 mode
bitvec.c:389: note: use option -std=c99 or -std=gnu99 to compile your code
2016-01-27 17:08:02 +01:00
Max a15f05f1b4 Add bitvec-related functions from Osmo-PCU
Allocation, pack/unpack, field access and helper routines used
extensively by Osmo-PCU. Whenever memory allocation happens, alocator
context is passed explicitly by caller.
2016-01-26 11:01:23 +01:00
Holger Hans Peter Freyther fdb4667609 test: Fix compiler warnings on 64bit systems
Use %td to print ptrdiff_t use %zu to print size_t,
include time.h on FreeBSD. Some more compiler warnings are
left but they require more thinking.
2015-11-09 16:46:03 +00:00
Holger Hans Peter Freyther ee6652b4bc ipa: recv is declared in different headers on BSD
Include the headers mentioned by the manpage

ipa.c:346:9: warning: implicit declaration of function 'recv' is invalid in C99
      [-Wimplicit-function-declaration]
                ret = recv(fd, msg->tail, needed, 0);
2015-11-09 16:21:19 +00:00
Holger Hans Peter Freyther d56c3cbb2c vty: Use NULL to have a null pointer instead of '\0'
'\0' gets translated to zero but the argument to vector_set is
a pointer and it gets converted to a pointer.

vty.c:985:21: warning: expression which evaluates to zero treated as a null pointer constant of type
      'void *' [-Wnon-literal-null-conversion]
                vector_set(vline, '\0');
                                  ^~~~
vty.c:1095:21: warning: expression which evaluates to zero treated as a null pointer constant of type
      'void *' [-Wnon-literal-null-conversion]
                vector_set(vline, '\0');
                                  ^~~~
vty.c:1097:21: warning: expression which evaluates to zero treated as a null pointer constant of type
      'void *' [-Wnon-literal-null-conversion]
                vector_set(vline, '\0');
                                  ^~~~
2015-11-09 16:16:00 +00:00
Max 61816048ce Ignore test binaries 2016-01-22 23:23:54 +01:00
Max e49af08f5b bitvec: Fix interface to consistently use unsigned int
Use unsigned int for the length throughout the interface. We will
never have a a negative length.

Sponsored-by: On-Waves ehf
2016-01-22 23:22:48 +01:00
Max 08621a8ebb bitvec: Fix unaligned memory access in osmo_revbytebits_buf
The undefined behavior sanitizer found the 32bit load from an
unaligned memory address. This will cause an exception on ARMv5te
and a manual fix-up.

[hfreyther: On armv6, x86 the usage of memcpy leads to shorter
amount of instructions but on armv5te the memcpy is not expanded
leading to a branch. Use the version of max until we have the time
to benchmark it]

Sponsored-by: On-Waves ehf
2016-01-22 23:21:58 +01:00
Max cf37c4cd29 Fix sporadic out-of-bounds error
This code dealing with bit shifting sometimes gets 1 byte beyond array
boundary while calculating index. This is now explicitly checked and prevented.

Ticket: OW#1198
Sponsored-by: On-Waves ehf
2016-01-22 23:08:12 +01:00
Holger Hans Peter Freyther fb7e683575 kasumi: Fix build with gcc5 that changed behavior of inline
GCC 5 has changed inline semantics (https://gcc.gnu.org/gcc-5/porting_to.html)
and apparently that now fails to link.
2016-01-21 15:50:04 +01:00
Holger Hans Peter Freyther e7c18dd59f debian: Avoid linking with -Bsymbolic-functions
Our tests want to be able to change symbols from the library and
even by using --wrap=XYZ it is not possible right now. One option
would be to use static linking but that is not always enabled, the
other is to skip tests on Ubuntu and the third one is to disable
that linking mode. This means that the dynamic linker needs to
spend some more time but we do spend this time on all other distros
and this looks acceptable.
2016-01-18 13:52:59 +01:00
Neels Hofmeyr f6d9f3759c comment typo 2016-01-18 10:44:36 +01:00
Jacob Erlbeck 17b3c3aca1 msgb/test: Add test case for error cases
Include a test for msgb_trim.

Sponsored-by: On-Waves ehf
2016-01-15 18:12:49 +01:00
Jacob Erlbeck ff42b26520 msgb: Assert len >= 0 in msgb_trim
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
2016-01-15 18:11:58 +01:00
Jacob Erlbeck 0a053ec506 msgb/test: Add tests for msgb_resize_area and msgb_copy
Sponsored-by: On-Waves ehf
2016-01-15 18:11:20 +01:00
Jacob Erlbeck cbefa08559 msgb/test: Add functions to catch and check exceptions
Currently the msgb error handling cannot be fully tested, since in
many cases osmo_panic will be called. This will in turn call abort().
Using an osmo_panic_handler that just returns will not help, since
many msgb functions rely on MSGB_ABORT to not return at all.

This commit uses an alternative osmo_panic_raise handler that just
calls longjmp to return to the test function.

Since some of this activity is logged to stderr where the strings may
contain variable parts like pointer addresses, stderr checking is
disabled in testsuite.at.

Sponsored-by: On-Waves ehf
2016-01-15 18:10:05 +01:00
Jacob Erlbeck 7cd8a1b063 msgb/test: Add test for msgb message buffers
This tests several API functions of the msgb by checking the
invariant and by dumping resulting message buffers as hex.

Sponsored-by: On-Waves ehf

Conflicts:
	tests/Makefile.am
2016-01-15 18:09:06 +01:00
Jacob Erlbeck 5f349be820 bitvec: Add get/set byte sequences
The new functions bitvec_get_bytes and bitvec_set_bytes copy
byte sequences from bitvecs to uint8_t arrays and vice versa.
While the bytes in the bitvecs do not need to be aligned, the uint8_t
arrays always are. In case the bytes in the bitvec are aligned, the
implementation uses memcpy.

Note that the implementation like the other existing functions assume
MSB first encoding.

[hfreyther: Squash the comment fix into this commit as well]

Sponsored-by: On-Waves ehf
2016-01-15 14:51:32 +01:00
Jacob Erlbeck 8114294bf2 gsm: Add APN conversion functions
These functions are currently part of openbsc but also needed by
other projects.

The function have been renamed as follows:

  gprs_apn_to_str -> osmo_apn_to_str
  gprs_str_to_apn -> osmo_apn_from_str

Sponsored-by: On-Waves ehf
2016-01-15 14:46:19 +01:00
Harald Welte 51660a6ade update TODO-RELEASE regarding the talloc change.
Shipping our own private copy of talloc was a good idea in 2008,
when it was not readily available on most target platforms.  Today,
the situation is quite different, as it is a standard library on
major Linux distributions.
2016-01-06 19:28:21 +01:00
Harald Welte c959afdcd9 osmo_prim_op_names should be extern 2015-12-25 17:14:07 +01:00
Neels Hofmeyr 42fff58a45 Fix some recently added formats on 64bit
86ec311896 adds compiler warnings on 64bit. The build is clean otherwise,
so let's keep it that way.
2015-12-24 16:17:21 +01:00
Harald Welte a2db75f28c Add osmo_prim_op_names[] symbol and _SAP_SS7_BASE define 2015-12-23 14:11:54 +01:00
Jacob Erlbeck 8db1134c72 msgb: Add msgb_test_invariant function
This adds a function that verifies whether a mgsb is consistent.

Sponsored-by: On-Waves ehf
2015-12-21 16:22:57 +01:00
Jacob Erlbeck 86ec311896 msgb: Let msgb_hexdump be more tolerant
This patch makes msgb_hexdump accept out of range lXh pointers and
shows info about them instead of aborting the dump entirely.

Sponsored-by: On-Waves ehf
2015-12-21 16:14:50 +01:00
Jacob Erlbeck cdd05f0ed4 msgb: Add msgb_resize_area and msgb_copy
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
2015-12-21 16:14:23 +01:00
Neels Hofmeyr 9e57a5a697 some comments / fixed typos 2015-12-21 11:25:05 +01:00
Harald Welte 1a87c1b189 LaPDm: Refuse SUSPEND/RESUME/RECONNECT in BTS mode
The primitives for SUSPEND, RESUME and RECONNECT are only permitted on
the MS side of the LAPDm link, not on the BTS side.  So we should check
for this and reject, accordingly.
2015-12-19 17:06:57 +01:00
Jacob Erlbeck cc6ac4cdc4 ns: Force a defined state when sending NS RESET
Currently the state is assumed to remain the same while the reset
procedure is active. While this works correctly in general, a single
unexpected BLOCK_ACK or UNBLOCK_ACK can change the state but will not
stop the reset procedure. The leads to repeated RESET messages, where
the corresponding RESET_ACK is ignored. This is a stable state which
can only be left by manual intervention or by reception of a RESET
message from the peer.

This commit changes the RESET timeout handler to set the state to
BLOCKED/RESET when sending the new NS RESET message.

Note that this should ensure a clean restart even if the state has been
screwed up. It does not fix the handling of BLOCK_ACK or UNBLOCK_ACK
in abnormal cases.

Addresses:
 gprs_ns.c:349 NSEI=8895 Tx NS RESET (NSVCI=8895, cause=O&M intervention)
 gprs_ns.c:878 NSVCI=8895 Rx NS RESET ACK (NSEI=8895, NSVCI=8895)
 gprs_ns.c:887 NS RESET ACK Discarding unexpected message for NS-VCI 8895 from SGSN NSEI=8895

Ticket: OW#1551
Sponsored-by: On-Waves ehf
2015-12-17 14:16:50 +01:00
Holger Hans Peter Freyther 5ab8e2cdfc stats: Fix compiler warning about losing const
stats_statsd.c: In function ‘osmo_stats_reporter_statsd_send_item’:
stats_statsd.c:154:15: warning: initialization discards ‘const’ qualifier from pointer target type
  char *unit = desc->unit;
               ^
2015-12-17 14:13:22 +01:00
Jacob Erlbeck 0975a7f36c ns/stats: Add missing osmo_stat_item_group_free to gprs_nsvc_delete
The stat item group is not removed by gprs_nsvc_delete which will
corrupt the group list.

Addresses:
  valgrind tests/gbproxy/gbproxy_test
  [...]
  ==4541== Invalid write of size 4
  ==4541==    at 0x4071ACA: __llist_add (linuxlist.h:65)
  ==4541==    by 0x4071ACA: llist_add (linuxlist.h:81)
  ==4541==    by 0x4071ACA: osmo_stat_item_group_alloc
  (stat_item.c:112)
  ==4541==    by 0x407EDFD: gprs_nsvc_create (gprs_ns.c:244)
  ==4541==    by 0x408109D: gprs_ns_instantiate (gprs_ns.c:1388)
  ==4541==    by 0x804CFD3: test_gbproxy_ident_changes
  (gbproxy_test.c:1501)
  ==4541==    by 0x805FBD3: main (gbproxy_test.c:5803)

Sponsored-by: On-Waves ehf
2015-12-17 14:01:16 +01:00
Holger Hans Peter Freyther 62f80fccb8 talloc: Depend on libtalloc-dev being present as well 2015-12-14 20:31:20 +01:00