Commit Graph

111 Commits

Author SHA1 Message Date
Oliver Smith c44b50c147 gbprox_rx_ptp_from_bss: fix dangling pointer
Building with gcc (Debian 12.2.0-14) 12.2.0 and --enable-werror fails
without this during "make distcheck":

../../../src/gb_proxy.c:450:24: error: storing the address of local variable 'tp' in '((struct libgb_msgb_cb *)msg)[2].bssgp_cell_id' [-Werror=dangling-pointer=]
  450 |         msgb_bcid(msg) = (void *)&tp;

This means that gcc now warns (and we turn that into an error) if one
assigns the address of a local (stack) variable to something allocated
on the heap, and doesn't remove that reference before ending the function
(invalidating the stack).

Related: OS#6057
Change-Id: Ie51e37572993cb5dc24ecf13bc300225f09cb744
2023-07-17 07:06:44 +00:00
Daniel Willmann 33dcdad449 Improve log levels
* Set log levels to LOGL_NOTICE by default
* Set log message about pooling being disabled to debug

Change-Id: Ieddf20a5eafaa9738d5d1e9a9aae320e48aa2efc
2022-10-20 15:50:12 +02:00
Max e3b991268b Drop forward declaration of gbprox_relay2peer()
There're no calls to the function before actual declaration so
forward declaration serves no purpose, just pollutes 'git grep' results.

Change-Id: Id8bce05ef347df93202a77b817a10903acaa9d97
2022-10-13 17:13:21 +03:00
Alexander Couzens 96a4427108 implement LL DISCARD with second BVCI
Needs TTCN3 tests

Depends: libosmocore I76dc3b08a63cfd78c9f7657fb58c2ddfa9b4b7e2
Change-Id: Iaa488ee8ac3d85b86c0f360d9d6440f7cda82230
2022-09-28 16:56:33 +02:00
Daniel Willmann 2f30a0c58c gbproxy: Ensure PtP-BVCs are reset when we reset the SGSN SIG-BVC
Related: SYS#5908
Depends-on: If240dd13f0f674693018c93390386b2c8afb97af (libosmocore.git)
Change-Id: I6560d8ce1ee6a0d7d42d625b76f6dd637dedb6c0
2022-03-30 16:40:29 +02:00
Daniel Willmann d71aa6bf20 gbproxy_peer: Add rate counters when forwarding packets fail
Change-Id: I7fa972ba843993dac84241c04d66d5b7e2a0b40f
2022-03-03 18:15:24 +00:00
Daniel Willmann 5ceeb2b321 gbproxy: Only route to an SGSN if the BVC is not blocked
Change-Id: I0b54813c04bae2c63975082ad2dacae8affd3127
2022-03-03 18:15:24 +00:00
Daniel Willmann 28ec0e33fc gbproxy_peer: Free all related BVCs if the cell is freed
Previously the SGSN BVCs would still be present after the related Cell
was freed. This caused some inconsistencies if a BVC with the same BVCI
was established again. The symptoms of this were cells that were attached
to no SGSN or the same one multiple times and crashes.

This patch ensures that the SGSN-side BVCs are also freed when the cell
is freed and that this fact is reflected when handling reset
notifications.

Change-Id: Iedeede8917e2870e0b62a2050ccb331109167017
2021-12-06 16:55:47 +01:00
Daniel Willmann e705b3fb3f gbproxy: Fix crash when FLUSH_LL_ACK does not contain a BVCI IE
The BVCI IE is listed as conditional and is only included if the flush
action indicates that LLC-PDUs are transferred. (3GPP TS 48.018 Ch.
10.4.2).

The code in gbprox_rx_sig_from_bss unconditionally tries to get a BVCI
from a FLUSH_LL message which could result in a segfault if no such IE
is included. Routing towards the SGSN can happen simply based on TLLI (for pooling)
since there is only one signalling BVC towards the SGSN.

Related: OS#5332
Change-Id: I659f9c925bb38b8cf2348b84b976142d8d4693f7
2021-11-25 22:04:56 +01:00
Daniel Willmann af2e9b349c gbproxy: Also try to route STATUS messages with truncated PDU in error
Related: OS#4892
Change-Id: I173eb8ef6257248e3c893c31486575019a3ef873
2021-11-18 16:18:00 +01:00
Daniel Willmann f689a8a007 gbproxy: Fix error return value
OSMO_TLVP_ERR_MAND_IE_MISSING is already negative

Change-Id: I17e438be50324684cebe0852ecab877097bb0cbb
2021-11-18 15:27:37 +01:00
Daniel Willmann f9902c5c05 gbproxy: Remove duplicate struct gprs_ra_id handling
The ra_id as well as the cell_id are already present in struct
gbproxy_cell which is reachable from bvc->cell. Remove the ra_id in
struct gbproxy_bvc and also remove some unused/unneeded code. The FSM
reset_notif callback already takes care of updating the cell.

Related: OS#4894
Change-Id: Ibc9f42a60706612c17e5f8f0468c7faced5ae4c8
2021-11-12 16:32:28 +01:00
Daniel Willmann 0141628144 gbproxy: Only use one struct tlv_parsed for gbproxy_decode_bssgp
Change-Id: I7965a4b68866c619159c524a63e051b0d9cbe80f
2021-11-02 14:51:18 +01:00
Daniel Willmann cfb6f17f51 gbproxy: Increase correct counter when BSSGP decode from SGSN fails
Change-Id: I8936cee105c933987c9af1fac3c91dc26864325b
2021-11-02 14:51:18 +01:00
Daniel Willmann 22311804e9 gbproxy: Move BSSGP decoding into its own function and use it
This code was copied in BSS and SGSN PTP receive functions and also in
the functions that extract the inner PDU-in-error from the STATUS PDU.

Use a central function for less code duplication and better
maintainability.

This also fixes TTCN3 test TC_status_ptp_ul_tlli the c&p omitted the
special handling of UL/DL unitdata.

Related: OS#4892
Change-Id: I882aa97b0f4158affe45e81e4e4701bd36ef89f7
2021-11-02 14:51:18 +01:00
Daniel Willmann 5a14837753 gbproxy: Route STATUS in PtP-BVC by TLLI/TMSI as well
Related: SYS#5235, OS#4892
Change-Id: Ib31c60ba840522719f307df089efeb8f4da1d9ae
2021-10-29 18:28:13 +02:00
Daniel Willmann 6ec5f95748 gbproxy: Add comment, remove unused param in gbproxy_tlli_from_status_pdu
Change-Id: I8fc4c42c11ee38df80fbd316bbe6b1eb243b5323
2021-10-28 16:17:36 +02:00
Daniel Willmann 3d8f599fd1 gbproxy: Route DL STATUS with BVCI on SIG-BVC
Fixes TTCN3 gbproxy test TC_status_sig_dl_bvci

Related: OS#4892
Change-Id: I5928cebea7f39d6648f95dfa1a46437de202f723
2021-10-28 16:17:36 +02:00
Daniel Willmann 885f430965 gbproxy: Improve STATUS handling from SGSN
STATUS with cause bvci blocked or unknown should not be forwarded

Related: OS#4892
Change-Id: I0ab88634fe2eab5299ff4587fcef4177ce5b4831
2021-09-30 16:59:50 +02:00
Daniel Willmann c5dcebdf42 gbproxy: Add comment, improve log message in gbproxy_tlli_from_status_pdu
Change-Id: Idcd2742f451ba5ae79f62395e033924782336cac
2021-09-30 16:57:51 +02:00
Daniel Willmann cbfc7cf0e2 gpproxy: Route BSSGP STATUS with PDU_IN_ERROR containing a TMSI
Derive a foreign TLLI from a TMSI and route the message according to it
Fixes TC_status_sig_ul_tmsi

Related: OS#4892
Change-Id: Iebda9e9fd433cd28c0f657adc4d475d4e6e247ba
2021-09-30 10:30:56 +02:00
Daniel Willmann 7d37cbb605 gbproxy: Route BSSGP STATUS with PDU_IN_ERROR containing a TLLI
Fixes TC_status_sig_ul_tlli

Related: OS#4892
Change-Id: I9d2ec73520ee46ceedda3f7e63035e6a51a65ac2
2021-09-30 10:30:42 +02:00
Daniel Willmann 723bb36829 gbproxy: Improve log message when no bvc is found (include bvci)
Change-Id: I0cb05b2069d7ef86ed0f7921044aaad01121a412
2021-09-29 17:14:35 +00:00
Daniel Willmann 99a46ff383 gbproxy: Use designated initializers for global_ctr_description
This already showed one unused description where only the enum had been removed.

Change-Id: Ifdb822c25236c19dd52a3ea1370c466d66f9d11d
2021-09-29 13:55:41 +00:00
Daniel Willmann c4b913ba5b gbproxy: Fix stats when no BVC could be found
Change-Id: I413b500515b6c4266370b29943b14447b38a66a0
2021-09-29 11:35:06 +02:00
Daniel Willmann dc763fdf39 gbproxy: Avoid sending STATUS on unexpected BLOCK_ACK
Handle SGSN BVCs that are gone from the BSS differently.

The previous patch removed the gbproxy_bvc on the SGSN-side after it was
gone on the BSS-side. This caused a STATUS response to BVC_BLOCK_ACK messages
that should be valid. Instead of removing the BVC this patch marks it as
inactive so we can still handle BVC_BLOCK_ACK correctly, but ignore
other messages - especially BVC_RESET from the SGSN.

Related: SYS#5628. OS#5236
Change-Id: Ic9f34a27412d6e15ca1198ee140f66a076b5c6b6
2021-09-29 11:35:06 +02:00
Daniel Willmann a1304ee8ef gbproxy: Remove SGSN-side BVC after sending BVC-BLOCK
If we keep the bvc around the SGSN could send a BVC-RESET which the
gbproxy would ACK. This will reestablish the BVC only between the gbproxy and
SGSN which can lead to all sorts of issues.

With this patch the gbproxy will respond with a BVC-STATUS cause BVCI
unknown.

Related: SYS#5628
Fixes: OS#5236
Change-Id: Ib14be6425a81b43353708b2708f79e035e501079
2021-09-24 15:54:10 +02:00
Daniel Willmann f024eeb9e7 gbproxy: Forward MS_REGISTR_ENQ/_RESP correctly
We need to save the BSS NSE <-> IMSI mapping to correctly route the
answer.

Related: OS#4472
Change-Id: I1908bbe8db11271dbd3f45b0d9f1bc0bfe48f239
2021-07-09 19:04:56 +02:00
Daniel Willmann 361d0b566a gbproxy: Add usage flag to the imsi_cache
This is only used for the imsi cache entries for now. Further uses will
be added in subsequent commits.

Related: OS#4472
Change-Id: I4a4b8c99eb97f6bb5387d0f26aecd861e07d9914
2021-07-09 19:04:47 +02:00
Pau Espin 5643836076 Use new stat item/ctr getter APIs
Generated with spatch:
"""
@@
expression E1, E2;
@@
- &E2->ctr[E1]
+ rate_ctr_group_get_ctr(E2, E1)
"""

Change-Id: Ibc17979c171b6efa522cfd80fddf3f3c593dbd0b
2021-06-04 18:03:44 +02:00
Daniel Willmann 37518b3409 Don't route messages to an SGSN if it is down
If an SGSN in a pool is down we expect the messages to instead be sent
to a different SGSN in the pool. That SGSN will not necessarily know
what to do with those messages, but it should (implicitly) detach that
UE so that it can reattach at the new SGSN. Otherwise UEs on a failed
SGSN would simply stop working as the messages would never be forwarded
anywhere.

Fixes: OS#4952
Change-Id: I3f794659866e1f31496a39ca631b3b042a60aa27
2021-05-28 17:20:44 +02:00
Pau Espin a42963421f Avoid sending tx_status upon rx of RIM messages
Change-Id: Ib8d580ad437f11f6b0a42e76e28b8c3a6c2a12d7
2021-05-07 13:33:34 +02:00
Daniel Willmann 6701d27313 gb_proxy: Ensure cell info is up to date when receiving PTP-BVC reset
When a BSS resets its BVC and reuses a BVCI with a differente cell id
the SGSN BVC still has the old cell information.

This results in the SGSN receiving a BVC reset for the old cell which in
turn leads to all sorts of issues (probably also with paging) and
conflicting information since the cell info is also present in the
UL-UNITDATA and this is just passed through from the BSS.

Instead of reusing the old BVC on the SGSN side free any existing and create
new ones.

Change-Id: Ia94090a0133340b7b284df6ec5b36546da698b37
2021-04-12 08:17:51 +00:00
Daniel Willmann 1f3470f69a gbproxy: Don't free NSE/BVC0 if SGSN NSE goes down
SGSN NSEs are static and should not be removed. Instead remove all
PtP-BVCs.
BVC0 can't be blocked and will be reset after the NSE becomes available
again. It might be cleaner to remove BVC0 on NS failure and create it
again, but that change is a bit more complicated.

Fixes ttcn3 test after commit f96cac5077 broke them.

Related: OS#4897
Change-Id: Ie0cef38e4423b672f5cba35ae7fc3eb2c4071d5a
2021-03-11 09:53:42 +01:00
Daniel Willmann a16ecc34cc Remove osmo-sgsn relics
* include/osmocom/sgsn -> gbproxy
* (unused) tests specific to osmo-sgsn

Change-Id: I3704760e8936bdd005a3f73727de5f2b3e8774a0
2021-03-10 13:52:07 +01:00
Daniel Willmann f96cac5077 Handle GPRS_NS2_AFF_CAUSE_FAILURE
When a complete NSE becomes unavailable gbproxy should notify the other
side (bss/sgsn).
The current code blocks every PtP-BVC (belonging to that BSS) on all SGSNs if
a BSS goes down.

The BSS-side should not be blocked unless no more SGSN connections are
present. We could also remove all BSS nse and wait for those to reconnect.
This is not yet implemented.

Related: OS#4897
Change-Id: I6354a190ec1090a35c27671c72dab9126d0ad794
2021-03-10 12:14:56 +00:00
Daniel Willmann 38b9c9a9c1 Update the max_sdu_len from NS
Related: OS#4889
Change-Id: Ie26550198db0cc34ca0a882c137c8685a5662f2a
2021-03-10 12:14:56 +00:00
Daniel Willmann 429c43ce45 Remove some outdated TODO/comments
Change-Id: Icd72ed92585f5701d293807022255b06e5641005
2021-03-10 11:27:13 +00:00
Daniel Willmann f8cba65017 gbproxy: Use bssgp2_enc_status when sending STATUS
bssgp_tx_status() is not aware of the MTU and cannot truncate the PDU if
needed. Use the newer bssgp2_enc_status() which supports truncating the
PDU.

Related: OS#4889
Depends: Ic39d918c56399ceb0431299ce938e3bf276f678a (libosmocore.git)
Change-Id: Id5ddb10385655b339b2a4f04651c1da09b3efb62
2021-02-16 16:42:00 +01:00
Daniel Willmann a8b61659e6 Add SDU length for an NSE (== BSSGP PDU size)
Prepare tracking the SDU from NS. Initialize with a conservative default.
The value is not yet updated, that will happen in a later patch.

Related: OS#4889
Depends: I5016b295db6185ec131d83089cf6c806e34ef1b6 (libosmocore.git)
Depends: I9bb82ead27366b7370c9ff968e03ca2113ec11f0 (libosmocore.git)
Change-Id: Ic1080abde942ec5a2ae7cdee0ffe716a2fbddb1e
2021-02-16 16:39:45 +01:00
Daniel Willmann 44fa20182e gbproxy: Use bssgp2_nsi_tx_ptp in gbprox_relay2nse
Use the function provided by bssgp2 instead of setting up the ns2 prim
request ourself.

Related: OS#4889
Change-Id: I0b8926eb903ed972edb2ed7ba3edbb3d77889564
2021-02-12 09:39:50 +00:00
Daniel Willmann 1ac920ba89 Remove trailing whitespace
Change-Id: If8fe9e65056e458e946ff202cf7ae93efc8abf17
2021-02-12 09:39:38 +00:00
Philipp Maier 4499cf49cb gb_proxy: fix wrong usage of bssgp_rim_ri_name()
In some logging statements the function bssgp_rim_ri_name() is used
twice. This is wrong since _name() functions use an internal buffer,
which can not be used twice in the same logging statement, so for the
affected log statements the function bssgp_rim_ri_name_buf() must be
used.

Change-Id: I8b6254a269770ddc141325d67d143f2a8130c519
Related: SYS#5103
2021-02-10 17:57:03 +01:00
Philipp Maier 1c5766b0ec gb_proxy: add support for relaying BSSGP RIM messages
BSSGP RIM messages are routed from a source to a destination cell by a
RIM routing information IE. Add parsing for the routing information and
support for relaying RIM messages to the destination cell/PCU. If the
destination cell/PCU is not directly connected to osmo-gbproxy route the
rim message to the first connected SGSN.

Change-Id: Idd1ea46832e044f0ade15af32250f90517d848d8
Related: SYS#5103
2021-02-10 16:43:33 +00:00
Daniel Willmann 3ea379395f Various comment/whitespace changes
Change-Id: I0eeef3ec16c249d65e9358889d21cc4984b7b51f
2021-02-10 16:41:18 +00:00
Philipp Maier 74882dc258 gb_proxy: extend TLV parser
In BSSGP RIM the routing information IE is appearing twice (source and
destination). The current one dimensional TLV parsing method would only
give us access to the first routing information IE (destination), so
lets increase the dimension to 2, so that we get also IEs that appear
twice.

Change-Id: Ieed7160e3005210a9cdeb5c4db28bc3ed031449c
Related: SYS#5103
2021-02-10 13:34:28 +01:00
Philipp Maier e4597ece46 gb_proxy_peer: Require ra_id and cid in gbproxy_cell_alloc
pass raid and cell id directly as parameter to gbproxy_cell_alloc so
that we do not need to fill tas parameter to gbproxy_cell_alloc so that
we do not need to fill the struct members later.

Change-Id: Ic7deae5ccf839b941d70557d28451d52f32cebbb
Related: SYS#5103
2021-02-09 22:45:27 +01:00
Philipp Maier da3af94bf8 gb_proxy: simplify raid data storage
Instead of storing the raw ra_id in its unparsed binary form, store it
as a parsed struct. Also store the cell-id on cell allocation for later
use.

Change-Id: Ib58b9188e3ce4bd3fdadb03f158d56b29778387c
Related: OS#4894
2021-02-09 13:32:31 +01:00
Oliver Smith 29532c2a06 === Split osmo-gbproxy from osmo-sgsn ===
Adjust the build system, packaging etc. to split osmo-gbproxy into its
own git repository. Remove tests and configs that aren't related to
osmo-gbproxy.

Related: OS#4992
2021-01-29 16:57:29 +01:00
Harald Welte e30985ed92 gbproxy: Avoid depending on any of the SGSN code
The last remaining functin of the SGSN code base we used was
gprs_gb_parse_tlli().

Let's simply copy this function over and become  self-contained.

This would allow migrating osmo-gbproxy to a separate repository.

Change-Id: I6f3f86581b47ad71a3d97f07611a2e2709876d69
2021-01-28 19:14:32 +01:00