Commit Graph

94 Commits

Author SHA1 Message Date
Harald Welte 6176b6e092 bssgp_rx_paging(): Fix parsing of P-TMSI IE in Paging message
This was actually discovered by the following compiler warning in
gcc-6.2.0:

  CC       gprs_bssgp_bss.lo
gprs_bssgp_bss.c: In function ‘bssgp_rx_paging’:
gprs_bssgp_bss.c:544:2: warning: this ‘if’ clause does not guard...
[-Wmisleading-indentation]
  if (TLVP_PRESENT(&tp, BSSGP_IE_TMSI) &&
  ^~
gprs_bssgp_bss.c:548:3: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the ‘if’
   *(pinfo->ptmsi) = ntohl(*(uint32_t *)
   ^

This is an actual bug.  If we recevied a BSSGP Paging Request without
P-TMSI, we might crash or report some random memory as P-TMSI to the
caller in the output data structure.

Change-Id: Ib4f307827cd7cccc91c1415a6fb5428d7cf8416d
2016-11-11 14:49:31 +00:00
Harald Welte 684cf32243 bssgp_vty: Remove dead code and compiler warning
gprs_bssgp_vty.c:48:34: warning: ‘gprs_bssgp_timer_strs’ defined but not used [-Wunused-const-variable=]
 static const struct value_string gprs_bssgp_timer_strs[] = {
                                  ^~~~~~~~~~~~~~~~~~~~~

Change-Id: Ia41ccb7b227c41996cdef51dc6779bfc5b5a8d48
2016-11-11 15:24:29 +01:00
Neels Hofmeyr 8e2f7e87f4 add osmo_gettimeofday as a shim around gettimeofday
This allows feeding a custom time for unit tests by overriding
osmo_gettimeofday.

Change-Id: Ic7a81a6eb51f27fe452962b91f2eae2070d87089
2016-09-22 07:18:39 +02:00
Max 27e8036d41 Fix unaligned access found by addr. sanitizer
gprs_bssgp.c:461:9: runtime error: load of misaligned address
0x62100001a66b for type 'uint32_t', which requires 4 byte alignment

gprs_ns.c:937:16: runtime error: load of misaligned address
0x61d00002a97f for type 'uint16_t', which requires 2 byte alignment
2016-04-24 11:12:41 +02:00
Max 93bc64f99d gb: Add bssgp_pdu_str to libosmogb namespace
[hfreyther: To be used by osmo-pcu]
2016-04-12 10:08:20 -04:00
Max b9bb0b02ac Add missing docs for bssgp bvc reset vty command
Fixes the build failure with extended tests enabled.
2016-04-07 12:38:12 +02:00
Max ea50732df2 Add vty command to explicitly reset given BVCI
It's useful for debugging and is similar to existing reset command for
nsvc.
2016-04-05 22:33:14 +02:00
Max 2c34ab4a80 Improve BSSGP debug output
Print string representation of Cause IE and PDU type instead of
numerical value.
2016-03-17 16:55:11 +01:00
Max c0d9a6c083 Add helper function to convert numerical BSSGP PDU type to string 2016-03-11 22:29:39 +07: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
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
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
Harald Welte 90e614f7cc remove our internal copy of talloc, use system libtalloc
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.
2015-12-05 23:38:18 +01:00
Holger Hans Peter Freyther 495b0dbd24 gprs-ns/stats: When the NSVCI is updated, update the stats counter
The NS object is created with an unknown identity and only after
the reset procedure has progressed (completed?) we know the real
ID for this peer. Before nobody has looked at the idx values (this
could have been seen with the CTRL interface) but with statsd the
wrong NSVCI becomes obvious.

Add routines to update the idx and I don't know if the change of
idx is causing any issues but we will find that out soon.
2015-11-04 14:39:37 +01:00
Jacob Erlbeck fed2a488b9 ns/stats: Fix class_id of "NSVC Peer Statistics" rate_ctr group
Currently the class_id is not set which effectively puts these groups
into the 'subscriber' class.

This commit adds the missing initialisation value.

Sponsored-by: On-Waves ehf
2015-08-22 01:35:24 +00:00
Jacob Erlbeck bc9d9aced8 stats: Limit reporting by class id
This commit adds class_id fields to the rate_ctr and stat_item group
descriptions. The stats reporter code is extended to only process
groups whose class_id does not exceed a per reporter max_class level.

If the class_id is not set, the code assumes 'global' for groups with
idx == 0 and 'subscriber' otherwise.

The following vty command is added to config-stats:

  level (global|peer|subscriber)  Set the maximum group level

Sponsored-by: On-Waves ehf
2015-11-02 15:39:31 +01:00
Jacob Erlbeck fc9533d6c4 stats: Add osmo_ name prefix to identifiers
Since the the stat_item and stats functions and data types are meant
to be exported, they get an osmo_ prefix.

Sponsored-by: On-Waves ehf

[hfreyther: Prepended the enum values too. This was requested by
Jacob]
2015-11-02 15:39:01 +01:00
Jacob Erlbeck 0a1400fc83 ns: Add statistics for some events
The following counters are added to the ns.nsvc counter group:
  lost.alive             The number of missing ALIVE ACK messages
  lost.reset             The number of missing RESET ACK messages

The following items are added to the ns.nsvc stat item group:
  alive.delay            The time in ms between sending ALIVE and
                         receiving the next ALIVE ACK

Sponsored-by: On-Waves ehf
2015-10-28 23:51:24 +01:00
Holger Hans Peter Freyther c136da587f release: Prepare the 0.8.2 release
I have kind of used 0.8.1 by accident already so let us move
to 0.8.2 now.
2015-08-01 20:20:24 +02:00
Jacob Erlbeck c1cb75eff5 bssgp: Fix IMSI buffer size (Coverity)
Currently the size of the IMSI pointer is used instead of the size of
the talloc'ed buffer.

This commit changes the call to gsm48_mi_to_string to use the same
value that has been used with talloc_zero_size(). The length is
changed to 17 since that value is used for GSM_IMSI_LENGTH in
openbsc.

Fixes: Coverity CID 1040663
Sponsored-by: On-Waves ehf
2015-06-19 20:54:28 +02:00
Jacob Erlbeck 9385d1e01b bssgp: Fix bssgp_tx_fc_bvc parameter type
Currently large values for Bmax default MS get sliced since a uint16_t is
used as the type of the corresponding parameter of bssgp_tx_fc_bvc.
GSM 48.018, 11.3.2 which in turn refers to 11.3.5 specifies a maximum
of 6MB (0xffff * 100).

This commit changes the type to uint32_t to cover the full value
range.

Sponsored-by: On-Waves ehf
2015-05-06 17:55:55 +02:00
Jacob Erlbeck 9731935984 bssgp: Fix call to llist_entry in fc_queue_timer_cfg
Currently the DL sometimes hangs and sometimes a lot of messages
(still not able to send PDU) are logged. This is caused by an invalid
timer delay computation, setting msecs either to 0 or to some big value.

This is due to an '&' operator at the wrong place, accessing some
parts in fc instead of the first element of the list.

This commit fixes that issue.

Sponsored-by: On-Waves ehf
2015-04-30 20:02:09 +02:00
Jacob Erlbeck 580af4be00 bssgp: Fix encoding of BVC_FLOW_CONTROL
Currently all 2 byte IE of the message are transmitted in the little
endian byte ordering.

This commit adds htons to the encoding expressions.

Sponsored-by: On-Waves ehf
2015-04-29 15:48:09 +02:00
Jacob Erlbeck 1bda44213e bssgp: Fix output of the VTY 'show bssgp stats' command
The output is terminated by a '\n' instead of VTY_NEWLINE.

This is fixed by the commit.

Sponsored-by: On-Waves ehf
2015-04-29 15:47:25 +02:00
Jacob Erlbeck a84db61673 gprs: Add assertion for msg != NULL to bssgp_msgb_alloc (Coverity)
Currently out-of-memory is not handled by bssgp_msgb_alloc, leading
to SEGV failures if msgb_alloc_headroom returns NULL.

This commit adds an OSMO_ASSERT to catch this case, which improves
the situation only slightly. But bssgp_msgb_alloc is used in many
places without checking the return value, so just adding a
conditional early NULL return would not fix the issue either.

Fixes: Coverity CID 1293377
Sponsored-by: On-Waves ehf
2015-04-10 08:44:35 +02:00
Jacob Erlbeck 8d192d7153 ns: Log when sending fails (Coverity)
Currently the return value of the gprs_ns_tx family of functions is
often ignored. This is not a serious issue, since the successful
delivery of the messages is neither guaranteed nor acknowledged by
the network layer anyway.

Nevertheless this commit adds logging (level INFO) to gprs_ns_tx and
gprs_ns_msgb_alloc. The definition of the latter has been moved from
the header file to gprs_ns.c.

Fixes: Coverity CID 1040678, 1040679, 1040680, 1040681, 1040682,
   1040683, 1040684, 1040686, 1040687, 1040688, 1111545,
   1240203, 1240204
Sponsored-by: On-Waves ehf
2015-04-07 20:10:23 +02:00
Jacob Erlbeck b535e391b0 bssgp: Ensure non-NULL bctx before calling bssgp_rx_ptp (Coverity)
Currently bssgp_rx_ptp might be called with bctx being NULL, when the
NS BVCI is neither BVCI_SIGNALLING nor BVCI_PTM, but the message is
a BVC_RESET or it contains an BVCI IE != BVCI_SIGNALLING where the
BVCI is not known.

This patch ensures that bssgp_rx_ptp will only be called with a
non-NULL bctx. A log message will be issued, if the bctx is NULL when
this was not expected.

Fixes: Coverity CID 1040674
Sponsored-by: On-Waves ehf
2015-04-07 20:10:09 +02:00
Jacob Erlbeck c641591ae9 bssgp: Always expect dup != NULL in bssgp_tx_dl_ud (Coverity)
Currently the implementation of bssgp_tx_dl_ud conditionally adds
some optional IE if dup != NULL. Later on is dereferences dup to
access qos_profile and fc, but this without checking dup in advance.
This may lead to an segmentation violation fault.

This commit changes the value range of the function to only accept
dup != NULL. An assertion will fail otherwise. All other explicit
checks for non-NULL are removed.

Fixes: Coverity CID 1040673
Sponsored-by: On-Waves ehf
2015-04-07 20:09:48 +02:00
Jacob Erlbeck 36153dc61a bssgp: Handle BSSGP STATUS messages
Currently incoming BSSGP STATUS messages are just logged and no other
action is taken. This makes it impossible for higher layers to react
to failures which are indicated by corresponding STATUS messages
unless a timeout is triggered as a result of that failure later on.

This commit adds a bssgp_rx_status() function and calls it on
incoming STATUS messages. That function logs a message, increments the
new BSSGP_CTR_STATUS counter if the bctx context exists and invokes
an NM_STATUS status indication. The latter will allow the application
to handle failures immediately. Since all STATUS messages should be
handled, the function is already called in bssgp_rcvmsg and the
message is no longer handled in (and will not reach) bssgp_rx_sign
and bssgp_rx_ptp.

Ticket: OW#1414
Sponsored-by: On-Waves ehf
2015-03-18 21:54:37 +01:00
Jacob Erlbeck 49ed9beed1 bssgp: Don't reply with STATUS when receiving a PtP STATUS message
Currently each incoming PtP BSSGP STATUS message is handled as 'not
yet implemented' and a BSSGP STATUS message (cause
BSSGP_CAUSE_PROTO_ERR_UNSPEC) is sent back to the peer. This will
cause endless messages loops if both peers use this BSSGP stack
implementation. This does not apply to signalling messages.

This commit changes the implementation of bssgp_rx_ptp() to just do
logging in this case.

Sponsored-by: On-Waves ehf
2015-03-18 21:54:37 +01:00
Jacob Erlbeck 0673b70f7d bssgp: Fix VTY command 'show bssgp nsei N'
Currently this command segfaults (at least when ASAN is enabled),
because when getting the NSEI the index to argv is wrong and out of
bounds.

This patch fixes the offset.

Sponsored-by: On-Waves ehf
2014-11-10 08:40:59 +01:00
Harald Welte 7fa89c2e88 Change license of libosmogb from AGPLv3+ to GPLv2+
The copyright holders Harald Welte, Holger Freyther, Andreas Eversberg
and sysmocom - s.f.m.c. GmbH (represented by Holger and Harald) agree
that the license of libosmogb should be GPLv2+ and not AGPLv3+.

The reason the source files stated AGPLv3+ is due to the history, as
they were moved from OpenBSC to libosmocore at the time we needed to use
them from osmo-pcu.  It was an oversight back then to not re-license
them accordingly.
2014-10-26 20:50:19 +01:00
Jacob Erlbeck b43baf20c5 gprs: Don't discard SUSPEND/RESUME in bssgp_rcvmsg
Currently sending SUSPEND/RESUME messages to this function (like it
is done in the osmo-sgsn) results in STATUS messages complaining
about an unknown BVCI. The reason is, that these messages rely on a
TLLI/RAI pair to identify the context and do not contain an explicit
BVCI.

This patch modifies bssgp_rcvmsg() to only complain about and unknown
BVCI if one is given but a matching context is not found (except for
RESET messages). The ctx argument is removed from the functions
handling SUSPEND and RESUME since it will always be NULL then.

Sponsored-by: On-Waves ehf
2014-10-23 18:53:02 +02:00
Holger Hans Peter Freyther 10dd73cf6a bssgp: Free msgb in case of error when calling into gprs_ns_sendmsg
In the OsmoSGSN we have a crash with a DEAD/BLOCKED GPRS-NS and
segmented SN-UNITDATA. For the caller it is not easy to know if
the passed msg buffer has been freed or not. The most easy solution
is to always take the ownership and either pass it on or free it
in case of an error.

Adjust indirect and direct callers of gprs_ns_sendmsg. I found
the following call-chains with an external msgb parameter.

gprs_ns_sendmsg
  <- _bssgp_tx_dl_ud
     <- bssgp_fc_in
        <- bssgp_tx_dl_ud

Update the test to allocate a real msgb because for the test with
'1000' we will msgb_free it right away.

Sponsored-by: On-Waves ehf
2014-10-10 17:55:13 +02:00
Jacob Erlbeck 6ac70a41ee gprs-ns: Fix reset state handling
Currently the NS-VC's state is updated from within gprs_ns_tx_reset,
which can lead to an inconsistent state when the RESET_ACK is lost.
In this state, the NSE_S_RESET bit is set but the Tns-reset timer is
not started.

This patch moves the state update into gprs_nsvc_reset. This way, the
state flags are consistent with the timer.

Addresses:
  SGSN -> BSS       NS_ALIVE
  BSS -> SGSN       NS_ALIVE_ACK
  BSS -> SGSN       BVC_RESET
  SGSN -> BSS       NS_STATUS, Cause: NS-VC blocked, NS VCI: 0x65
  and there is no BSS->SGSN NS_ALIVE

Ticket: OW#1213
Sponsored-by: On-Waves ehf
2014-10-09 07:52:43 +02:00
Jacob Erlbeck 0540d839ac gprs-ns: Let gprs_nsvc_reset return a value
Currently gprs_nsvc_reset does not return any value.

This patch changes the function to return an integer, where a value
less than zero indicates an error. The value is taken from the
gprs_ns_tx_reset function. In case of failure, an error message is logged.

Sponsored-by: On-Waves ehf
2014-10-09 07:47:20 +02:00
Jan Engelhardt 9ffeb9756a build: remove unused all_includes and use AM_CPPFLAGS
Preprocessor flags are best placed in AM_CPPFLAGS. Remove use of the
unused all_includes variable, which is never set.
2014-10-03 08:48:31 +02:00
Holger Hans Peter Freyther 96af78650d misc: Look into the build directory for generated files
the bits/crc files are not inside the sourcedirectory but will end
in the build directory. Go and look there as well. This somehow
doesn't fail with make distcheck but when building for Yocto Dizzy.
2014-09-25 18:18:49 +02:00
Jacob Erlbeck a39e2deff8 gprs: Set bssgph field in bssgp_msgb_alloc()
Currently the bssgph field is not set when using the bssgp_tx_*
functions. This hinders unit testing of generated messages.

This patch initializes the bssgph field directly after allocation a
new bssgp msgb in bssgp_msgb_alloc() so that it is set by default.

Sponsored-by: On-Waves ehf
2014-09-23 16:30:49 +02:00
Jacob Erlbeck b83b838bd1 gprs: Fix bssgp_rcvmsg to handle signalling msgs with BVCI IE
Currently BSSGP messages with an NS BVCI of 0 (signalling) are
discarded if they aren't RESET messages. Thus valid signalling
messages (e.g. BLOCK) are not handled properly, because the BVCI IE
is ignored if it present. Instead a STATUS message referring to BVCI
0 (instead of the BVCI used in the BLOCK message) is returned.

This patch changes the implementation to use the BVCI contained in
the BVCI IE if that is present in a signalling message.

It fixes BSSGP BLOCK/UNBLOCK for the osmo-sgsn.

Note that signalling messages without an BVCI IE (e.g.
SUSPEND/RESUME) are still rejected.

Ticket: OW#1205
Sponsored-by: On-Waves ehf
2014-09-23 16:29:34 +02:00
Jacob Erlbeck a7165778c6 gprs: Fix and check BVCI in BSSGP STATUS messages
Currently the BVCI is not set in all invocations to bssgp_tx_status()
when the cause is UNKNOWN_BVCI.

This patch adds the argument where it is missing.

It also adds a check for compliance (GSM 08.18, 10.4.14.1) to
bssgp_tx_status() to emit errors when the following requirement is
not fulfilled: The BVCI must be included if (and only if) the cause
is either "BVCI blocked" or "BVCI unknown".

Sponsored-by: On-Waves ehf
2014-09-23 16:27:44 +02:00
Harald Welte 336915aa0a prepare for 0.7.0 release 2014-08-21 15:53:20 +02:00
Holger Hans Peter Freyther 777b056fb4 gprs-ns: Re-initialize the list head and free the unknown_nsvc
Fix re-initialize issue of the GPRS NS. This was found while
working on the GB Proxy tests.

==27800== Invalid write of size 4
==27800==    at 0x403C263: rate_ctr_group_alloc (linuxlist.h:65)
==27800==    by 0x4050974: gprs_nsvc_create (gprs_ns.c:209)
==27800==    by 0x405320D: gprs_ns_instantiate (gprs_ns.c:1330)
==27800==    by 0x804B212: main (gbproxy_test.c:797)
==27800==  Address 0x434173c is 52 bytes inside a block of size 784 free'd
==27800==    at 0x4029DA8: free (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==27800==    by 0x4041BBD: _talloc_free (talloc.c:609)
==27800==    by 0x40432B2: talloc_free (talloc.c:578)
==27800==    by 0x40532D3: gprs_ns_destroy (gprs_ns.c:1363)
==27800==    by 0x804B1FE: main (gbproxy_test.c:791)
2014-07-07 20:00:35 +02:00
Holger Hans Peter Freyther 56cc60dc20 gb: Remove comment about ABI changes from the Makefile
Okay. this comment thing has not worked (I totally forgot about it).
I think either we try to find ABI breakages with tools or we use
 #error macros and check for a version...
2013-11-22 16:05:26 +01:00
Jacob Erlbeck 9b591b7da8 gprs: Fix VTY NSVC initialisation bug by changing gprs_nsvc_create()
Currently the field nsvci_is_valid is set to 0 in the NSVC object
returned by gprs_nsvc_create(). This was a semantic change probably
introduced by commit 5e6d679d. As a result, NSVC created via the VTY
have this flag set to 0 causing RESET_ACK messages to be rejected.

This patch changes the default behaviour of gprs_nsvc_create() to
always set this flag. So it must be set to 0 explicitely if needed
which is more intuitive and thus less error prone.

It fixes breaking connections from the Gbproxy to the SGSN.

Ticket: OW#874
Sponsored-by: On-Waves ehf
2013-11-11 13:04:17 +01:00
Jacob Erlbeck 3d557b18d0 gprs: Ignore NS RESET_ACK and ALIVE_ACK without RESET
Currently those messages are answered by a NS_STATUS message when
received on an uninitialised (no NS_RESET hat been seen yet) NS_VC
which violates GPP TS 08.16 7.3.1 and 7.4.1.

This patch adds checks to gprs_ns_vc_create() and eventually returns
before the error NS_STATUS message is generated.

Sponsored-by: On-Waves ehf
2013-10-30 15:23:18 +01:00
Holger Hans Peter Freyther 9e1cd5a5a5 gprs: Address coverity warning for gprs_ns_tx_status result
Add a #define for the check and use this in this path as well.

Fixes: Coverity CID 1103092
2013-10-25 11:11:51 +02:00
Holger Hans Peter Freyther 726e2729fa gprs: Address coverity warning on unchecked return of gprs_ns_tx_reset_ack
Fixes: Coverity CID 1111545
2013-10-25 11:05:10 +02:00
Holger Hans Peter Freyther 7c91bfdd4e gprs: Address coverity warning on unchecked return of gprs_ns_tx_status
We could consider creating a CHECK MACRO that will print a message
in case of a tx failure.

Fixes: Coverity CID 1111544
2013-10-25 11:02:51 +02:00
Holger Hans Peter Freyther 0cccf40860 gprs: Make sure that the buf is NULL terminated at the end
Fixes: Coverity CID 1107253
2013-10-25 11:00:23 +02:00