Commit Graph

30 Commits

Author SHA1 Message Date
Pau Espin 8fd95f3e74 hnbap: Avoid calling duplicate getpeername() for each registered HNB
Change-Id: I980de31d1296c3b956146a461609bec76ed3d430
2024-04-16 14:42:37 +02:00
Harald Welte e3cc5ddf1d HNBAP: Support IMSI identity type in hnbgw_tx_ue_register_rej()
Change-Id: I2e00968cbf686f78f5c9655e899963f2b84dd78b
2024-03-29 12:00:06 +01:00
Harald Welte f64cdf85d1 HNBAP: use GSM23003_IMSI_MAX_DIGITS instead of magic number
Change-Id: I2ea0a6a93194da2efb768cd4245767301411eb41
2024-03-29 11:58:26 +01:00
Harald Welte 060619b811 HNBAP: Transmit ErrorIndication in more situations
Whenever we receive a message and cannot decode the most basic IEs,
or receive an unknown/unsupported procedure code, we should respond
with an ErrorIndication in order to inform the peer.

Change-Id: I7aaa66f83f62ee1b5ba5204248e9f4cc754263ed
2024-03-27 21:46:59 +01:00
Harald Welte 4b274a88ea HNBAP: Make sure to respond with correct "reject"
If we receive a procedure (like UE-REGISTER) in a state
where it's not permitted (e.g. HNB not registered), we should
send a UE-REGISTER-REJ with proper cause value, rather than not
sending any response at all.

Change-Id: I300db368a3d1d2fb5967f69f2ed4ac90ecf85e75
2024-03-27 21:46:59 +01:00
Harald Welte b57afbe1a6 HNBAP: Always respond to UE-REGISTER-REQUEST
We always should respond to a UE-REGISTER-REQ. Either it's an ACK
or we must send a REJ.  There should not be any "quiet" error cases
where we don't respond at all:

* send general Error Indication at a point where we cannot decode the
  UE-Identity-IE (which is mandatory in UE-REGISTER-REJECT)
* send UE-REGISTER-REJECT with matching cause value whenever we have
  the decoded UE Identity around

Change-Id: I5338a1324545b2c6d31fb45f1e69fee45842e207
2024-03-27 19:07:01 +01:00
Harald Welte 0a991f9a71 HNBAP: Send HNB-REGISTER-REJ on ASN.1 decoding error
Change-Id: Ic4a40966194a57cccc0eb056233f7e7426d6e8f9
2024-03-27 19:05:36 +01:00
Harald Welte cf75e50314 HNBAP: Use proper cause values during HNB-REGISTER-REQ processing
When we reject the HNB-REGISTER-REQ, let's use an as specific as possible
cause value to let the peer know why we rejected registration.

Change-Id: Iadddd26b751a9fd80c829068792aa93cd538c43d
2024-03-27 19:05:29 +01:00
Harald Welte 5fbd72f80e generalize hnbgw_tx_ue_register_rej_tmsi() to hnbgw_tx_ue_register_rej()
This way the caller can provide the cause value to be used during
reject.

Requires: osmo-iuh I7db92b51847c282d23d568970dfd2bedecdea486
Change-Id: Ic83674523c0326a7ae51fb176bddfd6641ed3ac4
2024-03-27 19:03:26 +01:00
Harald Welte e4d0951a86 New per-hnb rate_ctr and stat_item groups; track uptime
Let's add a per-hnb rate_ctr and stat_item group.  Only one initial
counter (number of Iuh establishments) and one initial stat_item
(uptime/downtime) is implemented.

Related: SYS#6773
Change-Id: I26d7c3657cdaf7c6ba5aa10a0677381ab099f8dd
2024-03-12 21:35:40 +01:00
Harald Welte 101a9c7e21 Set persistent->ctx pointer on HNB REGISTER REQ
The previous commit was missing the assignment of hnb_persistent->ctx
during successful HNB REGISTER REQ.

Related: SYS#6773
Fixes: Change-Id Ife89a7a206836bd89334d19d3cf8c92969dd74de
Change-Id: I18fe0e5aa968a1095c72e6bf32d08b031b342ac6
2024-03-12 21:35:39 +01:00
Harald Welte 7ec5cb7280 Introduce concept of per-HNB persistent data structure
This allows us to add a new "hnb-policy closed", which means we do not
accept any random HNB connection anymore, but only those whose identity
is pre-configured explicitly using administrative means.

Furthermore, this new data structure will allow us (in future patches)
to keep persistent data like uptime / downtime of each HNB.

Related: SYS#6773
Change-Id: Ife89a7a206836bd89334d19d3cf8c92969dd74de
2024-03-12 08:18:12 +00:00
Neels Hofmeyr 11fa15e4d9 tweak lots of logging
Make lots of small tweaks in logging around RUA to SCCP context maps, CN
link selection and HNBAP:

- remove duplicate log context (e.g. LOGHNB() already shows the HNB Id)
- bring more sense into logging categories and levels / reduce noise
- add and clarify the details being logged at what points in time

Related: SYS#6412
Change-Id: I41275d8c3e272177976a9302795884666c35cd06
2023-06-16 04:25:31 +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 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 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 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 8eefcbee92 UE state leak: when HNB re-registers, discard previous UE state
User reports show leaked UE contexts over time, in a scenario where HNB
regularly disconnect and reconnect.

So far, when we receive a HNB REGISTER REQ, we log as "duplicated" and
continue to use the hnb_context unchanged. But it seems obvious that a
HNB that registers does not expect any UE state to remain. It will
obviously not tear down UE contexts (HNBAP or RUA) that have been
established before the HNB REGISTER REQUEST. These hence remain in
osmo-hnbgw indefinitely.

When receiving a HNB REGISTER REQUEST, release all its previous UE
state. Allow the HNB to register with a clean slate.

The aim is to alleviate the observed build-up of apparently orphaned UE
contexts, in order to avoid gradual memory exhaustion.

Related: SYS#6297
Change-Id: I7fa8a04cc3b2dfba263bda5b410961c77fbed332
2023-02-11 03:32:34 +01:00
Neels Hofmeyr 07d01d50a5 fix possible leak of ue_context on UE REGISTER error
Deallocate a recently allocated UE context if the UE REGISTER procedure
fails internally, in two places.

The UE REGISTER error is rather unlikely to happen in practice: it only
occurs when encoding the HNBAP response fails, which only gets checked
input and thus is unlikely to fail.

The same code paths also possibly leak asn1c allocations -- leave those
for another patch.

Related: SYS#6297
Change-Id: Icf4b82f9a904d56332c567f7ccfb24231ee66270
2023-01-18 18:42:50 +01:00
Pau Espin 12bc4afab3 Workaround bug where old hnb_context from same remote addr+port is kept
Under some circumstancies not yet fully known, which seems to
involve bad link quality and high latencies and some specific hNodeB
which reuse its local IP addr+port, it is seen that a 2nd SCTP
connection is created from the same HNB while locally we still keep the
old SCTP connection and its related hnb_context. Hence, when the hNodeB
tries to register again with this new conn, it is rejected all the time
by the HNBGW.

Related: SYS#6113
Change-Id: I33ae901cc37646eca90bf06953e44fcc25f4d6c6
2022-09-29 17:18:56 +02:00
Pau Espin 25cd41f3b5 hnbap: Improve logging around HNBAP HNB Register Request
Change-Id: I279ef563b38fb0dd3e6a72162db91d8503f91af8
2022-09-27 14:57:05 +02:00
Pau Espin 55239c2cca hnbap: Accept duplicated HNB Register Request on same conn
As per what's indicated in 3GPP TS 25.469 8.2.4 Abnormal Conditions:
"""
If the HNB-GW receives a duplicate HNB REGISTER REQUEST (i.e. for an already registered HNB identified by the
unique HNB identity), then the new HNB REGISTER REQUEST shall override the existing registration and the
handling of the new HNB REGISTER REQUEST is according to section 8.2.
"""

Related: SYS#6113
Change-Id: I0250350a14a87498a2c68cd0c726ee2f1e72419d
2022-09-27 14:45:07 +02:00
Harald Welte 96c712570a Don't permit anything but HNB (de)registration until HNB is registered
UE registration or other HNBAP procedures should only happen once the
HNB is registered.

Change-Id: Iaa62ce89f4ffbff868309bfb8b1df7ebcca5c44a
2022-09-13 13:00:01 +02:00
Harald Welte d3382ae952 hnbgw_rx_hnb_deregister: Don't call hnb_context_release()
Don't release the HNB context as there's plenty of code that
assumes there's always a HNB context associated with a SCTP connection.

Instead, simply unset the hnb_registered flag in the context when
processing a HNB_DE-REGISTER.

Related: OS#5676

Change-Id: Id5c4f5c900ea049f54afbf58edb84b4dc00b1dcb
2022-09-13 12:59:57 +02:00
Harald Welte d28771a1b5 cosmetic: Fix typos
it's "successful", not" "successfull".

Change-Id: Ic421ed6835a9ffca6af34779f0ea648bb12e2fe1
2022-09-12 08:15:58 +02:00
Daniel Willmann d129e0c86e hnbgw_hnbap: Fix memory leaks in HNBAP handling
* Use osmo_stream closed_cb to call hnb_context_release() in all cases
* Also call hnbap_free_hnbregisterrequesties() when sending hnb register
  reject

Related: OS#5656
Change-Id: I3ba02b0939413c67bc8088ea1a8f2252fc2bda31
2022-08-23 18:15:02 +02:00
Philipp Maier dddafa60ea hbgw_hnbap: use osmo_plmn_from_bcd instead of gsm48_mcc_mnc_from_bcd
The function gsm48_mcc_mnc_from_bcd is deprecated. Lets use
osmo_plmn_from_bcd instead.

Change-Id: I01406a4cf86d4f3ed162c9df55880941e54d654e
2022-01-14 17:31:25 +01:00
Pau Espin dce3870429 Initial structure + import code from osmo-iuh.git
Imported from osmo-iuh.git 9b4de3f401c890fc2c0dfae9e827daaaadd80db0.

Change-Id: I569d221aeb83d352c1621c44c013a0e4c82fc8a8
2022-01-04 19:48:52 +01:00