Commit Graph

149 Commits

Author SHA1 Message Date
Oliver Smith 8cd268ef8a contrib/jenkins.sh: add PFCP variable
Related: OS#6013
Change-Id: Iacc6a0267d4896d0149f5e00d77951cdfc281e4e
2023-05-10 08:47:05 +00:00
Neels Hofmeyr 63f3abf54c add non-installed libhnbgw.la for test linkage
To ease linking C tests, introduce a libhnbgw.la that contains all of
osmo-hnbgw except the main() and friends.

(I wrote a test that I was going to add, but it turned out to be
obsolete -- now at least we may keep this preparation to add C tests
more easily.)

Change-Id: Id2a706a30fb459005c676bb29c196cf3a582fa01
2023-05-08 15:29:03 +02:00
Neels Hofmeyr 0484441530 move main() to separate file
Conform to recent osmocom practice by having an osmo_hnbgw_main.c file
for main() and its immediate infrastructure.

Prepares for adding a non-installed libhnbgw.la -- which must not
contain a main() function -- so that linking regression tests is easy.

Separating to a new file seems appropriate because hnbgw.c has gathered
a bunch of stuff that is not strictly main() related / might be useful
to access in a C test.

Change-Id: I5f26a6b68f0d380617d73371f40f3b9055cac362
2023-05-08 15:20:26 +02:00
Neels Hofmeyr d12aecf33d ranap_rab_ass_test.c: clarify talloc contexts
Change-Id: I4256e0d94a7e7fbba236aa92c44229c12cf17313
2023-05-07 00:19:17 +02:00
Neels Hofmeyr f1d4e3b7dd simplify: one g_hnbgw as global state and root ctx
So far we jump through hoops everywhere to pass around osmo-hnbgw's
global singleton state to all code paths. Some files choose to spawn a
static "global" pointer. And we also have the talloc root tall_hnb_ctx.

Simplify:
- Have a single global g_hnbgw pointer. Drop all function args and
  backpointers to the global state.
- Use that global g_hnbgw as talloc root context, instead of passing a
  separate tall_hnb_ctx around.

(Cosmetic preparation for separate osmo_hnbgw_main.c file)

Change-Id: I3d54a5bb30c16a990c6def2a0ed207f60a95ef5d
2023-05-07 00:18:34 +02:00
Neels Hofmeyr 28e8d8a0b2 comment typo fix in ranap_rab_ass.c
Change-Id: I28b4c966c399acbff46faa36f0f05cda7356e44e
2023-05-07 00:08:20 +02:00
Neels Hofmeyr 6639eb910a drop ctrl_test_runner.py
Unused and contains no actual tests.

Change-Id: If3d6614334b692e49efcc45d1e4fb29a00c68602
2023-05-07 00:08:18 +02:00
Neels Hofmeyr c204f7e809 actually run vty-tests: osmotestconfig.py
Change-Id: Id60e5dfb22b7cea33c53388d339838add101de44
2023-05-06 05:56:02 +02:00
Neels Hofmeyr 3d26d73a1c vty: fix doc strings for 'show {hnb,ue}'
Fixes: OS#5987
Change-Id: I79f8b13a9f22fb8311017005cc0a3ac3a7e78983
2023-05-06 05:55:48 +02:00
Neels Hofmeyr 0b2983d1af eliminate function hnb_contexts()
It's really just a bloated llist_count() wrapper.
(Cosmetic preparation for separate osmo_hnbgw_main.c file)

Change-Id: Icd4100ddeb98f4dc2e2ec6de2d44a4b861a66078
2023-05-06 03:53:20 +00:00
Neels Hofmeyr 52f9e327bb drop empty hnbgw_rua_init()
Change-Id: I8e3ff452242d8baa527c2a61d182bbe9786341e3
2023-05-06 03:53:20 +00:00
Neels Hofmeyr 83697f832e ps_rab_ass_fsm.h: fix dup of FSM event enum
Change-Id: I20d5fc6d52d08b185ef3aa4f7a59fa0ebb202b18
2023-05-06 03:53:20 +00:00
Neels Hofmeyr fdc78ce29b rab_ass_fsm.c: fix asn1 memleak when replacing GTP address
This fix is really weird: by *removing* a FREE() call, fix a leak of the
replaced transportLayerAddress. (An in-code comment says some more.)

Also remove the other FREE() call that turns out to not be necessary.

This has been verified with a ttcn3 test that is not yet submitted,
which ensures an empty talloc_asn1_ctx at the end of every test
(osmo-ttcn3-hacks I2948ee6f167369a2252f85b493e9653b93c7e4e9 ).

Change-Id: I315d04a07b7dfd4dce26e5b5f871318e27e2bdf6
2023-05-06 03:53:20 +00:00
Neels Hofmeyr fc800ca49b actually run vty-tests: osmotestvty.py
Change-Id: Iab84af37488b5ec1000162d945f909f9ab05dad8
2023-05-05 02:23:11 +02:00
Neels Hofmeyr ece0f81e30 actually run vty-tests: VTY transcript tests
There have been VTY transcript tests around for a long time, but we are
not running them.

Change-Id: Ie9fc8f29b84e1dffea000fea11e0afe285c1df39
2023-05-05 02:23:11 +02:00
Neels Hofmeyr cc3cf24322 fix log msg typo 'Unsupportedccept'
Change-Id: I8e334ec84809b69bfff36f95adf21f6e6ae041e1
2023-05-01 00:25:36 +00:00
Neels Hofmeyr 929ac4efdf less code dup in mem free of hnbgw_rx_ue_register_req()
Related: SYS#6297
Change-Id: I433127f90bf6f82baf33c516f327f84d081ad69c
2023-05-01 00:25:36 +00:00
Neels Hofmeyr 3f92103c62 fix asn1 leak in hnbgw_rua_rx()
Related: SYS#6297
Change-Id: I7392e0bb07c2cb02c1a12f8e19acb142cd101f77
2023-04-27 16:39:06 +00:00
Neels Hofmeyr 0d2251ef7d fix asn1 leaks in ps_rab_ass_resp_send_if_ready()
Related: SYS#6297
Change-Id: Icdb6eef0d1fde849c0b9121cc96d8221e72d45c8
2023-04-27 16:39:06 +00:00
Neels Hofmeyr 5437aeaca4 fix asn1 leak in error path of hnbgw_tx_ue_register_acc_tmsi()
Related: SYS#6297
Change-Id: Iad1519aea36d8b6fef51fedb22a861ad1bc462fc
2023-04-27 16:39:06 +00:00
Neels Hofmeyr e33d7321df fix asn1 leak in error path of hnbgw_tx_ue_register_acc()
Related: SYS#6297
Change-Id: Iaaf7a393ef1fcad619687e2eb2dcc31f0aec0e96
2023-04-27 16:39:06 +00:00
Neels Hofmeyr 7f219856c9 fix asn1 leak in handle_cn_ranap()
Related: SYS#6297
Change-Id: I307f65ae083aba16f75510bcd0a7d1f124e62be4
2023-04-27 16:39:06 +00:00
Neels Hofmeyr 0188391a19 place asn1 context under hnb_ctx for better visibility
Include talloc_asn1_context in 'show talloc-context application'. It
belongs there IMO.

Related: SYS#6297
Change-Id: Iffc320c64713b225b57211da4fb95a868bf1f369
2023-04-27 16:39:06 +00:00
Neels Hofmeyr 4a4a675fec fix vty: show talloc-context all
Without "null tracking" enabled, the VTY 'show talloc-ctx all' shows
nothing at all.

Since the talloc_asn1_ctx is "created in NULL ctx", it was not visible
in any talloc reports before this patch.

This patch uncovers a slur of leaks, which accumulate in
talloc_asn1_ctx. Fixes follow.

Related: SYS#6297
Change-Id: I5cb4e9a3b393100877f03d68a09acf5817c5a878
2023-04-27 16:39:06 +00:00
Oliver Smith 39683d0c6f debian: set compat level to 10
Related: OS#5958
Change-Id: I5d26ab03aacf3b8ef8c1c4c669c12090fd0b7899
2023-04-25 16:48:22 +02:00
Oliver Smith 8fd4159ea9 hnbgw_mgw_setup: use mgcp_client_pool_empty()
Don't fall back to the legacy config if the pool is configured but no
connection to any pool member can be established.

Depends: osmo-mgw I009483ac9dfd6627e414f14d43b89f40ea4644db
Related: OS#5993
Change-Id: Icf3f3f0524c9d27f645c68851aaf9c6f33842927
2023-04-04 16:32:37 +02:00
Vadim Yanitskiy 612d3255b8 tests: do not depend on undefined $(BUILT_SOURCES)
Change-Id: I7536be8aa3f0ab39f183e00cf4382636038db4b7
2023-03-30 02:55:06 +07:00
Vadim Yanitskiy 3ebdd301c9 tests: make 'vty-test' target depend on osmo-hnbgw binary
Change-Id: Iaaa1dd622fde460a250c11eb97cf0b25469e55c4
2023-03-30 02:53:41 +07:00
Vadim Yanitskiy a973a93527 tests: use -no-install libtool flag to avoid ./lt-* scripts
This option should be used for any executables which are used only
for testing, or for generating other files and are consequently never
installed.  By specifying this option, we are telling Libtool that
the executable it links will only ever be executed from where it is
built in the build tree.  Libtool is usually able to considerably
speed up the link process for such executables.

Change-Id: Id5f88c331cf1dfd3f38120b4ef59ced9a563d4f0
2023-03-30 02:51:40 +07:00
Vadim Yanitskiy a65c57a159 tests: use check_PROGRAMS for tests, not noinst_PROGRAMS
Change-Id: I616ed6920af98502424e4eab6cffde5d39d9698e
2023-03-30 02:50:26 +07:00
Neels Hofmeyr 0b10b5799f vty: 'show ue': show which HNB the UE is registered on
Change-Id: Ife54a105a5a011678d6a03d0032c7622c3079a28
2023-03-24 04:14:59 +01:00
Neels Hofmeyr bc92608e60 log: in new RUA,SCCP FSM IDs, indicate CS/PS
During tests without an SGSN, I noticed SCCP connections failing, and I
also noticed that I couldn't tell if they were CS or PS related. Add a
"CS"/"PS" indicator to FSM instance IDs for RUA and SCCP.

Change-Id: I5b8242196af3b08eaf64ca5ac1c257a97a5d02cb
2023-03-24 04:14:59 +01:00
Neels Hofmeyr be7df7c1a7 release UE Contexts on SCTP_RESTART
When receiving SCTP_RESTART for a given HNB, directly clear the UE
Contexts.

(The HNB typically connects via HNBAP shortly after this causing a UE
Context clearing too, but UE state should always be cleared on
SCTP_RESTART, no matter what.)

Change-Id: I583922193ba73e17ab85152005535188c2762b85
2023-03-24 04:14:59 +01:00
Neels Hofmeyr 01389592b2 release UE Contexts on HNB (Re-)Register
Whenever a HNB reconnects, we want to discard all previous UE state and
any active connections.

In one HNB reconnect scenario, we receive SCTP_RESTART. This sets
hnb_registered == false, which in turn skipped the UE cleanup step in
hnbgw_rx_hnb_register_req(), leaking UE Contexts.

Remove all weird conditions like that, and simply clear out all UE state
whenever a HNB registers, period.

Change-Id: I370966d2d76fd263714e727918fcc1ea2f2315fa
2023-03-24 04:14:59 +01:00
Neels Hofmeyr 9425640d7f map_sccp: on timeout during WAIT_CC, send N-DISCONNECT to SCCP-SCOC
When waiting for CC expires, we should tell the SCCP-SCOC that we've
stopped waiting: send N-DISCONNECT, instead of nothing.

Change-Id: Ie94fcee4e2507a55449050aab96307199aed99a2
2023-03-24 04:14:56 +01:00
Philipp Maier c6cef24546 mgw_fsm: refactor helper function handle_rab_release()
the function handle_rab_release() is difficult to read and it is not
immediately clear what happens and why. Lets split this up and add some
comments to improve this.

Related: OS#5916
Change-Id: I3595502b98ea5febbde7f2fab3999e2533766b48
2023-03-21 09:46:33 +01:00
Philipp Maier 065a719294 mgw_fsm: use __func__ to mention function name in log line
Change-Id: I23050fc5f644340dfbd0323eef6309cff6fc4515
2023-03-21 09:46:33 +01:00
Philipp Maier cc7d2b1313 mgw_fsm: fix log line
The function name mentioned in the log line does not match the actual
function name.

Change-Id: Iefc005f10e3c8f165c5686781747460a10ada1e0
2023-03-21 09:43:36 +01:00
Philipp Maier 1c4b05d026 mgw_fsm: fix typo
Change-Id: I16ee37bbfda01b541ad7a6f5269689c4b9e92c8c
2023-03-20 16:43:42 +01:00
Neels Hofmeyr 9e051548d6 debug log: log received RANAP message types on DCN, DHNB
Change-Id: Ib295e49f2c53164c5787002797145b3e6de5546b
2023-03-09 03:24:30 +01:00
Neels Hofmeyr 7992ce0163 tweak LOGHNB()
Add braces around context part.

In the HNBGW_Tests.ttcn output, I see this:

 DRUA DEBUG TTCN3 HNodeB transmitting RUA DirectTransfer

which reads like the hNodeB would transmit a RUA to us. Instead, this is
us sending RUA to the hNodeB, which is much clearer like this:

 DRUA DEBUG (TTCN3 HNodeB) transmitting RUA DirectTransfer

This matches the way we typically show context info in osmo logging.

Change-Id: If6f0c3ae81c737b7488fa93c435179dcf27a5c94
2023-03-09 03:24:30 +01:00
Neels Hofmeyr b5dfba79ca fix regression: unbreak PFCP: PS RAB via UPF proxying
Fix PS RAB Assignment operation:
- add #include "config.h"
- fix uncompilable code in ENABLE_PFCP sections.

A series of oversights made me completely break PFCP / UPF operation for
PS RAB Assignments in this commit:
 'context map: introduce RUA and SCCP FSMs to fix leaks'
 ed424d5be4
 I6ff7e36532ff57c6f2d3e7e419dd22ef27dafd19

- In my HNBGW_Tests.ttcn, I used osmo-hnbgw-with-pfcp.cfg, but failed to
  set mp_enable_pfcp_tests := true in HNBGW_Tests.cfg.

- Hence I was under the impression that I was testing PFCP via UPF when
  really I wasn't. So I did not notice that:

- in the new files context_map_rua.c and context_map_sccp.c, the
  ENABLE_PFCP macro was always unset because I forgot to
  #include "config.h".

- Hence I did not notice that the moved PFCP RAB code was never once
  compiled or run.

My bad, that was really dumb.

Related: SYS#6297
Change-Id: I5df5073f0092ecdfd73d5d08207ca4042154eab1
2023-03-09 03:24:30 +01:00
Neels Hofmeyr 0fdb5c3f09 sccp_sap_up(): ignore PCSTATE.ind
Silence the error log about "unknown" PCSTATE prim.

Todo / coming up: instead of ignoring, detect a Destination Unavailable
from prim->u.pcstate and disconnect all conns with that particular CN
link.

Depends: libosmo-sccp If381f537ab91af1feef7f0e51921217f27e18e6a
Change-Id: I547387a5cc14ccb506be04ac785e6807fc4e6a96
2023-02-24 15:19:24 +01:00
Neels Hofmeyr 311bfb5983 log osmo_fsm timeouts
set osmo_fsm_log_timeouts(true);

Change-Id: Ic1ca03f06fbdef5a3fbe503e4414a780eb3e0fcc
2023-02-24 15:19:24 +01:00
Neels Hofmeyr ed424d5be4 context map: introduce RUA and SCCP FSMs to fix leaks
Refactor the entire RUA <-> SCCP connection-oriented message forwarding:
- conquer confusion about hnbgw_context_map release behavior, and
- eradicate SCCP connection leaks.

Finer points:

== Context map state ==
So far, we had a single context map state and some flags to keep track
of both the RUA and the SCCP connections. It was easy to miss connection
cleanup steps, especially on the SCCP side.
Instead, the two FSMs clearly define the RUA and SCCP conn states
separately, and each side takes care of its own release needs for all
possible scenarios.
- When both RUA and SCCP are released, the context map is discarded.
- A context map can stay around to wait for proper SCCP release, even if
  the RUA side has lost the HNB connection.
- Completely drop the async "context mapper garbage collection", because
  the FSMs clarify the release and free steps, synchronously.
- We still keep a (simplified) enum for global context map state, but
  this is only used so that VTY reporting remains mostly unchanged.

== Context map cleanup confusion ==
The function context_map_hnb_released() was the general cleanup function
for a context map. Instead, add separate context_map_free().

== Free context maps separately from HNB ==
When a HNB releases, talloc_steal() the context maps out of the HNB
specific hnb_ctx, so that they are not freed along with the HNB state,
possibly leaving SCCP connections afloat.
(It is still nice to normally keep context maps as talloc children of
their respective hnb_ctx, so talloc reports show which belongs to
which.)

So far, context map handling found the global hnb_gw pointer via
map->hnb_ctx->gw. But in fact, a HNB may disappear at any point in time.
Instead, use a separate hnb_gw pointer in map->gw.

== RUA procedure codes vs. SCCP prims ==
So far, the RUA rx side composed SCCP prims to pass on:

 RUA rx ---SCCP-prim--> RANAP handling ---SCCP-prim--> SCCP tx

That is a source of confusion: a RUA procedure code should not translate
1:1 to SCCP prims, especially for RUA id-Disconnect (see release charts
below).
Instead, move SCCP prim composition over to the SCCP side, using FSM
events to forward:

 RUA rx --event--> RUA FSM --event--> SCCP FSM --SCCP-prim--> SCCP tx
         +RANAP             +RANAP              +RANAP

 RUA tx <--RUA---- RUA FSM <--event-- SCCP FSM <--event-- SCCP rx
          +RANAP             +RANAP              +RANAP

Hence choose the correct prim according to the SCCP FSM state.
- in hnbgw_rua.c, use RUA procedure codes, not prim types.
- via the new FSM events' data args, pass msgb containing RANAP PDUs.

== Fix SCCP Release behavior ==
So far, the normal conn release behavior was

 HNB                 HNBGW                   CN
  | --id-Disconnect--> | ---SCCP-Released--> |  Iu-ReleaseComplete
  |                    | <--SCCP-RLC-------- |  (no data)

Instead, the SCCP release is now in accordance with 3GPP TS 48.006 9.2
'Connection release':

 The MSC sends a SCCP released message. This message shall not contain
 any user data field.

i.e.:

 HNB                 HNBGW                    CN
  | --id-Disconnect--> | ---Data-Form-1(!)--> |  Iu-ReleaseComplete
  |                    | <--SCCP-Released---- |  (no data)
  |                    | ---SCCP-RLC--------> |  (no data)

(Side note, the final SCCP Release Confirm step is taken care of
implicitly by libosmo-sigtran's sccp_scoc.c FSM.)

If the CN fails to respond with SCCP-Released, on new X31 timeout,
osmo-hnbgw will send an SCCP Released to the CN as fallback.

== Memory model for message dispatch ==
So far, an osmo_scu_prim aka "oph" was passed between RUA and SCCP
handling code, and the final dispatch freed it. Every error path had to
take care not to leak any oph.
Instead, use a much easier and much more leakage proof memory model,
inspired by fixeria:
- on rx, dispatch RANAP msgb that live in OTC_SELECT.
- no code path needs to msgb_free() -- the msgb is discarded via
  OTC_SELECT when handling is done, error or no error.
- any code path may also choose to store the msgb for async dispatch,
  using talloc_steal(). The user plane mapping via MGW and UPF do that.
- if any code path does msgb_free(), that would be no problem either
  (but none do so now, for simplicity).

== Layer separation ==
Dispatch *all* connection-oriented RUA tx via the RUA FSM and SCCP tx
via the SCCP FSM, do not call rua_tx_dt() or osmo_sccp_user_sap_down()
directly.

== Memory model for decoded ranap_message IEs ==
Use a talloc destructor to make sure that the ranap_message IEs are
always implicitly freed upon talloc_free(), so that no code path can
possibly forget to do so.

== Implicit cleanup by talloc ==
Use talloc scoping to remove a bunch of explicit cleanup code. For
example, make a chached message a talloc child of its handler:
  talloc_steal(mgw_fsm_priv, message);
  mgw_fsm_priv->ranap_rab_ass_req_message = message;
and later implicitly free 'message' by only freeing the handler:
  talloc_free(mgw_fsm_priv)

Related: SYS#6297
Change-Id: I6ff7e36532ff57c6f2d3e7e419dd22ef27dafd19
2023-02-24 15:19:24 +01:00
Neels Hofmeyr e67c4b324c add design charts for new context map FSMs
Planning new connection-oriented RUA and SCCP FSMs to
- conquer confusion about hnbgw_context_map release behavior, and
- eradicate SCCP connection leaks.

Related: SYS#6297
Change-Id: I661bf65d79972a732c52732934095e8bfcd99694
2023-02-23 02:03:20 +01:00
Neels Hofmeyr 29f82a7b48 cosmetic: regroup members of hnbgw_context_map
Change the order in the struct definition so that the items for RUA and
for SCCP are grouped together. Tweak comments.

Change-Id: I84424617996d8e1a6814aa122e63454c0666b724
2023-02-23 02:03:07 +01:00
Neels Hofmeyr 52b2a9e6b0 use RUA procedure code for rua_to_scu() arg
Instead of osmo_scu_prim_type, use RUA_ProcedureCode to tell
rua_to_scu() the RUA message type being handled.

Cosmetically prepare for upcoming patch that completely moves
osmo_scu_prim composition from rua_to_scu() to a new context map SCCP
FSM.

Related: I6ff7e36532ff57c6f2d3e7e419dd22ef27dafd19
Change-Id: I28735945844f732e7bd7f09db1f453c608415b84
2023-02-23 01:57:21 +01:00
Neels Hofmeyr 62d50a1fe8 rua_to_scu(): drop dead code for connection-less
From rua_to_scu(), drop dead code for connection-less messages. In fact,
rua_to_scu() is only used for connection-oriented messages. Clarify
that.

Change-Id: Id03c412cde066a6b2bbc26cb6b87053aa2408cba
2023-02-23 01:43:16 +01:00
Neels Hofmeyr 1e277db2cc fix deprecation: use ranap_cn_rx_co_decode2()
Change-Id: I867cbf174beab1eefddc682c1420737e49f9e50d
2023-02-23 01:17:11 +01:00