4783 Commits

Author SHA1 Message Date
Sukchan Lee
4012f572ed [SBI] Send GOAWAY on shutdown for all sessions to prevent RST (#3470)
When another NF restarts, curl reuses the existing connection, which in
curl 8.9.1 causes the nghttp2 server to send an RST. This commit sends a
GOAWAY frame to every active session on shutdown, ensuring a graceful
termination and avoiding RST errors.

Previous versions such as curl 7.81.0 did not exhibit this behavior.
2025-03-04 14:32:57 +09:00
Sukchan Lee
d187ce245b [SBI] Fix NF recovery failure on NF restart (#3740)
Previously, nf_instance pointers were stored in nf_type_array and
service_type_array. This led to dangling pointers when an NF instance
was removed via ogs_sbi_nf_instance_remove(), causing incomplete cleanup
and improper recovery on UDR or other NF restarts. The issue resulted in
the system falling back to nf_instance->client with the default port 80,
leading to connection failures.

To resolve the problem, nf_instance_id is now stored instead of the
pointer. The validity of an NF instance is verified using
ogs_sbi_nf_instance_find(nf_instance_id), which ensures proper cleanup
and correct recovery.
2025-03-04 14:32:57 +09:00
Sukchan Lee
6c67863971 [SEC] Fix crash when max_num_of_ostreams < 2 2025-02-28 16:44:17 +09:00
Bostjan Meglic
6fe6b88d9b [all] fix possible null dereference when using ProblemDetails
In case that NF do not send ProblemDetails in the response.
Do not assume that ProblemDetails is always present, to prevent null
pointer dereferencing.
2025-02-28 16:15:16 +09:00
Sukchan Lee
8cae6112cc [SEC] Fix crash in eNBDirectInformationTransfer due to missing Inter_SystemInformationTransferType
This commit resolves an issue where the system would crash
when Inter_SystemInformationTransferType was not present.
2025-02-28 14:27:10 +09:00
jmasterfunk84
8bdfdcf5df [AUSF] Cleanup ausf_ue when it is not found in UDM (#3743)
* Remove ausf_ue when unknown in UDM

* cover both error cases
2025-02-28 07:08:03 +09:00
jmasterfunk84
f98d0a780d [AUSF] Check length of SUCI_or_SUPI before trying to process (#3742)
* Check length of supi/suci

* check all the things
2025-02-28 07:07:24 +09:00
Sukchan Lee
1b21eba81e [UPF] Fixes: Crash in upf_sess_set_ue_ip when PDN type is invalid (#3727)
When receiving a PFCP Session Establishment Request with an invalid PDN type(0),
the UPF would crash due to a failed assertion.

This commit improves error handling by:

- Removing the session_type assertion check that caused the crash
- Changing warning log to error log for better visibility
- Returning CAUSE_SERVICE_NOT_SUPPORTED instead of proceeding
  with invalid type

This prevents potential DoS attacks through malformed PFCP messages.
2025-02-24 20:54:35 +09:00
Bostjan Meglic
6a2225bb68 [SBI] retrieve all currently registered NF's on app startup
Before this, there were 2 different ways to search for neighbouring
NF's:

a) in the case AMF was started _before_ UDM, AMF would create
subscription to NRF to notify it when a UDM would (un)register. In this
case, NF instance would remain in AMF's context indefinitely.

b) in the case AMF was started _after_ UDM, AMF would have to use NF
discovery mechanism to search for NF's. In this case, NF instance would
remain in AMF's context for the duration of Search's validity (defaults
to 30 seconds). After validity expires, NF would expire. This means that
for heavy traffic situations, AMF would constantly issue discovery
requests.

[SBI] save only wanted NF instances on NF List Retrieval

When retrieving a list of NF Instances from NRF, save only the NF's that
we want. Check the NF instance against our subscription list for either
the NF type or NF Service.
This can still cause a DoS on NRF when NF starts in case there are 100's
of NF's in the network, but prevents using too much memory on NF.
2025-02-20 20:13:18 +09:00
Spencer Sevilla
ba05380f5b also adding a default config option for newly generated sbi connections 2025-02-14 20:03:09 +09:00
Spencer Sevilla
68c6310717 add option to support curl binding local interface/ip for sbi calls 2025-02-14 20:03:09 +09:00
Bostjan Meglic
b32b1e981b [PFCP] fix crash for when PFCP NodeId is FQDN
Test scenario:
- start 5G core
- wait for 5 minutes after SMF establishes PFCP association to UPF (DNS
query refresh interval)
- register UE and establish PDU session
- crash

[upf] DEBUG: upf_state_operational(): UPF_EVT_N4_MESSAGE (../src/upf/upf-sm.c:51)
[upf] DEBUG: upf_pfcp_state_associated(): UPF_EVT_N4_MESSAGE (../src/upf/pfcp-sm.c:185)
[upf] INFO: [Added] Number of UPF-Sessions is now 1 (../src/upf/context.c:217)
[upf] DEBUG: Session Establishment Request (../src/upf/n4-handler.c:66)
[gtp] INFO: gtp_connect() [127.0.0.8]:2152 (../lib/gtp/path.c:60)
[upf] INFO: UE F-SEID[UP:0x1230 CP:0x5817] APN[local] PDN-Type[1] IPv4[10.46.0.2] IPv6[] (../src/upf/context.c:532)
[upf] INFO: UE F-SEID[UP:0x1230 CP:0x5817] APN[local] PDN-Type[1] IPv4[10.46.0.2] IPv6[] (../src/upf/context.c:532)
[upf] DEBUG: Session Establishment Response (../src/upf/n4-build.c:36)
[pfcp] FATAL: ogs_pfcp_sendto: should not be reached. (../lib/pfcp/path.c:158)
[core] FATAL: backtrace() returned 12 addresses (../lib/core/ogs-abort.c:37)
/open5gs/build/src/upf/../../lib/pfcp/libogspfcp.so.2(ogs_pfcp_sendto+0x1c8) [0x7f73c5ac0888]
/open5gs/build/src/upf/../../lib/pfcp/libogspfcp.so.2(ogs_pfcp_xact_commit+0x170) [0x7f73c5ac3510]
/open5gs/./build/src/upf/open5gs-upfd(+0x109eb) [0x55d7f20f99eb]
/open5gs/./build/src/upf/open5gs-upfd(+0x12351) [0x55d7f20fb351]
/open5gs/build/src/upf/../../lib/core/libogscore.so.2(ogs_fsm_dispatch+0x24) [0x7f73c5b57574]
/open5gs/./build/src/upf/open5gs-upfd(+0xc445) [0x55d7f20f5445]
/open5gs/build/src/upf/../../lib/core/libogscore.so.2(ogs_fsm_dispatch+0x24) [0x7f73c5b57574]
/open5gs/./build/src/upf/open5gs-upfd(+0x77fb) [0x55d7f20f07fb]
/open5gs/build/src/upf/../../lib/core/libogscore.so.2(+0xfb05) [0x7f73c5b4cb05]
/lib/x86_64-linux-gnu/libc.so.6(+0x9ca94) [0x7f73c551ea94]
/lib/x86_64-linux-gnu/libc.so.6(__clone+0x44) [0x7f73c55aba34]
2025-02-13 22:44:43 +09:00
Juan Pontón Rodríguez
f1e1f4a2a9 Update context.c 2025-02-13 20:20:34 +09:00
Sukchan Lee
8715915469 [UDM/UDR] Follow up on #3690 2025-02-11 07:04:42 +09:00
jmasterfunk84
600a7629ad [UDM][UDR] Add support for nssai resource in nudm-sdm (#3690)
* [UDM][UDR] Add support for nssai resource in nudm-sdm

* Resolve Memory Issue

* Protect from multiple field entries, remove macros

* remove request_from_server, make use of xact state

* typo....

* definition cleanup
2025-02-11 07:03:06 +09:00
Sukchan Lee
90afca821b Merge branch 'main' into home-routed 2025-02-09 11:15:55 +09:00
Sukchan Lee
056b50c9c8 [AMF] Fix crash on duplicate PDU session requests due to NULL SUPI (#3710)
When a duplicate PDU session establishment is received, the AMF logs a
warning and proceeds to update the SM context via the SBI interface. This
process eventually calls amf_nsmf_pdusession_build_create_sm_context(), which
uses the SUPI to build the SBI URI header. If the SUPI is NULL, then the header's
resource component becomes NULL. This leads to a call to ogs_uridup() that
asserts on the NULL value, causing a crash.

This commit adds a check before invoking the SBI update. If the SUPI is NULL,
the update is skipped and a warning is logged. This prevents the invalid URI
build process and avoids the subsequent crash in ogs_uridup().
2025-02-06 21:26:06 +09:00
Sukchan Lee
e31e9965f0 [AMF] Fix AMF crash during UE handover by handling unexpected SBI responses (#3707)
During handover between two gNBs, the AMF enters an invalid state when it
receives an unexpected SBI response from the UDM in the process of sending
a smf-select-data request. This bug could lead to an AMF crash as the state
machine in gmm_state_registration encountered an unknown state.

The fix adds explicit handling for SBI messages with resource names such as
AM_DATA, SMF_SELECT_DATA, UE_CONTEXT_IN_SMF_DATA, and SDM_SUBSCRIPTIONS.
If the HTTP response status is not OK, CREATED, or NO_CONTENT, a warning
is logged and the message is ignored. This prevents the AMF from transitioning
into an abnormal state and improves overall stability during frequent handovers.
2025-02-06 20:56:04 +09:00
Sukchan Lee
07cb42110e [DBI] Improve YAML policy config by adding SUPI range filtering
Previously, policies were configured via YAML files without MongoDB.
This update enhances the YAML approach by adding the 'supi_range' key to
filter policies based on UE SUPI ranges. When both 'supi_range' and
'plmn_id' are provided, both conditions must be met.

Note that PLMN-ID filtering will be deprecated in a future release.
2025-02-05 21:56:15 +09:00
Bostjan Meglic
e5545669fc [AMF] fix saving SDM subscription client info 2025-02-04 21:16:18 +09:00
Sukchan Lee
59f64970dd Update cifuzz 2025-02-04 21:09:20 +09:00
Sukchan Lee
bbfd462406 [PFCP] Fix the compile error (#3689) 2025-02-03 08:50:40 +09:00
Sukchan Lee
9c36fa5ccd [MME] Fix crash related to eNodeB context handling during indirect tunnel responses
Replace enb_ue with source_ue to correctly reference the target eNodeB
context during handover. Added null checks and assertions to ensure proper
session cleanup in both mme-s11-handler.c and s1ap-handler.c.
2025-02-02 11:48:17 +09:00
Sukchan Lee
350bc271fa [SEC] Fix PFCP Message Length Validation in ogs_pfcp_recvfrom (#3689)
This commit modifies the message length check in ogs_pfcp_recvfrom.
Previously, the condition only verified that the received size was less than
the expected length, which could allow messages that are too long to be
processed.

The condition now requires an exact match between the received
size and the expected total PFCP message length, ensuring proper message
validation.
2025-02-02 11:25:14 +09:00
Sukchan Lee
32cf4daf3a [SEC] Improve PFCP Message Validation to Prevent Fragmentation Attacks (#3689)
This commit adds additional checks in the PFCP receive callback to ensure
that a complete PFCP message is received before parsing. A minimum header
length check and a total message length validation are now performed. This
prevents incomplete, fragmented messages from being processed and avoids
potential parsing errors and DoS conditions.
2025-02-02 10:42:31 +09:00
Sukchan Lee
b1462f7236 [UDM] Handle maximum SDM subscription limit gracefully (#3688)
Previously, the function `udm_nudm_sdm_handle_subscription_create()` would
trigger a fatal assertion failure if the maximum number of SDM subscriptions
was reached.

This commit adds error handling to check if the subscription pool allocation
fails.

If `udm_sdm_subscription_add()` returns NULL, an appropriate error message is
logged, and a 400 Bad Request response is sent back to the client instead of
causing a crash.
2025-02-01 12:35:33 +09:00
Sukchan Lee
81f69b436c [DOCS] Update installation guide (#3681)
to conditionally install `libidn-dev` or `libidn11-dev`,
depending on availability, and clarify common dependencies for Debian/Ubuntu.
2025-01-22 17:53:36 +09:00
Sukchan Lee
3f38d66790 Merge branch 'main' into home-routed 2025-01-19 17:11:20 +09:00
Sukchan Lee
df11b05a1e Replaced deprecated libidn11-dev with libidn-dev across the project.
This update improves compatibility with newer distributions by modifying
dependency declarations in control files, Dockerfiles, and documentation.
2025-01-19 12:21:51 +09:00
Sukchan Lee
aaa950e6cf [SBI] Guard OpenSSL keylog callback with version check
Wrap SSL_CTX_set_keylog_callback calls with an OpenSSL version check
to ensure compatibility with versions older than 1.1.1.

This prevents compilation issues on earlier OpenSSL releases,
such as those found on Ubuntu 18.04(bionic).
2025-01-19 12:18:52 +09:00
Sukchan Lee
9c370ff89a [PFCP] Reduce DNS spam for FQDN nodes (#3431) (#3664)
Each received PFCP message triggered ogs_pfcp_node_find(), causing a DNS
resolution if node_id was FQDN. Under heavy traffic, this could lead to
excessive DNS queries.

- Implement a 300-second refresh interval to avoid repeated DNS lookups.
- Store last_dns_refresh in each node to defer new queries until needed.
- Treat config-based nodes with no Node ID as UNKNOWN, matching them by IP
  alone until ogs_pfcp_node_merge() updates their ID.
- Validate IPv4, IPv6, or FQDN types in ogs_pfcp_node_merge() and reject
  invalid IDs.
- Provide inline code comments for clarity and maintainability.
2025-01-18 12:15:00 +09:00
Bostjan Meglic
ba6a84d1b3 [pfcp] remove unused memory pool 2025-01-16 18:05:25 +09:00
Bostjan Meglic
78a993c486 [pfcp] fix use-after-free error
Variable was used after it was free'd (put back into the
application's memory pool, but still).
2025-01-16 18:05:25 +09:00
Bostjan Meglic
49d2f76fe1 [pfcp] fix return value
Return value should be a pointer to sockaddr instead of status code.
2025-01-16 18:05:25 +09:00
Sukchan Lee
2e68706f1e [AMF] prevent crash on npcf-am-policy-control SBI response handling (#3671)
This commit addresses an Open5GS bug where the AMF process crashes
when receiving npcf-am-policy-control service responses during UE handovers.
The crash was occurring in the gmm_state_authentication() function
when the AMF encountered an unexpected SBI (Service Based Interface) message
from the PCF related to AM Policy Control requests.

Added a new case block in gmm_state_authentication() to explicitly handle
messages with the service name OGS_SBI_SERVICE_NAME_NPCF_AM_POLICY_CONTROL.
2025-01-16 17:19:44 +09:00
Sukchan Lee
13585a34e3 [Metrics] Added PFCP related measurement 2025-01-12 11:47:12 +09:00
Sukchan Lee
d181ab54cc [PFCP] Refactor PFCP address handling (#3431)
- Replace direct usage of OGS_ADDR/OGS_PORT macros with
  ogs_sockaddr_to_string_static() for consistent IPv4/IPv6 logging.
- Remove redundant stack buffer allocations for address printing.
- Update PFCP node address handling to use addr_list and related
  merges, avoiding obsolete sa_list references.
- Use ogs_pfcp_extract_node_id() and related APIs to safely extract
  PFCP Node ID, improving error handling and reducing stack usage.
2025-01-11 20:33:02 +09:00
Sukchan Lee
8ff1d1b666 [CORE] Refactor ogs_sockaddr_strdup to use static buffer and rename
- Changed ogs_sockaddr_strdup to ogs_sockaddr_to_string_static
- Replaced dynamic allocation with a static buffer
- Updated source and header files accordingly
2025-01-11 20:33:02 +09:00
Sukchan Lee
df079b48d8 [PFCP] Add ogs_pfcp_get_node_id function with util modules (#3431)
Created util.h and util.c to implement the ogs_pfcp_get_node_id function,
which retrieves the node_id from a PFCP message. Utilized the
ogs_pfcp_status_e enum for enhanced error handling, distinguishing
between success, absence, and error states.
2025-01-11 20:33:02 +09:00
Sukchan Lee
ff917e9436 [GTP/PFCP] Enable server to bind to multiple addresses via FQDN resolution (#3431)
Modified the `ogs_gtp/pfcp_context_parse_config` function to iterate through
all configured GTP/PFCP server addresses. When a Fully Qualified Domain
Name (FQDN) resolves to multiple IP addresses, the server now binds and
listens on each IP address individually.

These modifications enhance the flexibility and reliability of the GTP/PFCP
server within Open5GS, allowing it to handle multiple network
interfaces and redundant IP configurations as required.
2025-01-11 20:33:02 +09:00
Sukchan Lee
04ec945e1d [SBI] Follow up on #3655 2025-01-11 20:24:30 +09:00
Bostjan Meglic
90cd67fcca [AMF,SMF] Prevent mapped HPLMN SST to always be set
In case that mapped HPLMN SST was not set by the UE in the request to
Establish PDU Session, AMF/SMF would assume it is set to 0 (since the
recent change to allow SST value 0).
2025-01-11 20:22:46 +09:00
Bostjan Meglic
c331207233 [all] allow value of 0 for S-NSSAI SST
3GPP TS 23.003: 28.4.2 Format of the S-NSSAI

The SST field may have standardized and non-standardized values. Values
0 to 127 belong to the standardized SST range and they are defined in
3GPP TS 23.501 [119]. Values 128 to 255 belong to the Operator-specific
range.
2025-01-11 20:22:46 +09:00
Sukchan Lee
34a9816c7b [SMF] Update comments for PR #3660 2025-01-09 21:02:37 +09:00
herlesupreeth
a38530f4f5 [SMF] Update QoS parameters even when only PFs needs to be added to QoS Flow 2025-01-09 21:00:16 +09:00
Sukchan Lee
fce22ca069 Fix the example configuration for AMF-TLS 2025-01-02 22:08:38 +09:00
Sukchan Lee
f04497ac31 [SBI] Allow direct NRF communication in Model C by configuring delegation modes (#3399)
Introduce client_delegated_config to manage delegation settings for NRF and SCP
separately. This ensures that in Model C, all NRF-related procedures
(registration, heartbeat, deregistration, etc.) communicate directly with the
NRF without routing through the SCP. This change aligns Open5GS behavior with
3GPP standards, providing consistent direct communication for both discovery
and management in Model C, and maintaining indirect communication in Model D.

- Direct Communication with NRF
```
sbi:
  client:
    nrf:
      - uri: http://127.0.0.10:7777
```

- Indirect Communication by Delegating to SCP
```
sbi:
  client:
    scp:
      - uri: http://127.0.0.200:7777
```

- Indirect Communication without Delegation
```
sbi:
  client:
    nrf:
      - uri: http://127.0.0.10:7777
    scp:
      - uri: http://127.0.0.200:7777
    delegated:
      nrf:
        nfm: no    # Directly communicate NRF management functions
        disc: no   # Directly communicate NRF discovery
      scp:
        next: no   # Do not delegate to SCP for next-hop
```

- Indirect Communication with Delegated Discovery
```
sbi:
  client:
    nrf:
      - uri: http://127.0.0.10:7777
    scp:
      - uri: http://127.0.0.200:7777
    delegated:
      nrf:
        nfm: no    # Directly communicate NRF management functions
        disc: yes  # Delegate discovery to SCP
      scp:
        next: yes  # Delegate to SCP for next-hop communications
```

- Default delegation: all communications are delegated to the SCP
```
sbi:
  client:
    nrf:
      - uri: http://127.0.0.10:7777
    scp:
      - uri: http://127.0.0.200:7777
    # No 'delegated' section; defaults to AUTO delegation
```
2025-01-02 17:49:40 +09:00
Sukchan Lee
be5a7e1ded [SBI] Added support for custom port numbers in SBI configuration with FQDN.(#3385)
This update allows the parsing and handling of user-defined port numbers
in the `advertise` field or explicitly in the `server` configuration for
SBI. Users can now specify non-default ports for both binding and
advertising while maintaining compatibility with existing configurations.
The feature includes logic to handle FQDNs with embedded port numbers
(e.g., `example.com:8080`) and ensures proper memory management during
parsing. Updated the client association logic to utilize custom ports
when specified.

Examples:
- Bind to the address on the eth0 and advertise as open5gs-amf.svc.local
```
  sbi:
    server:
      - dev:eth0
        advertise: open5gs-amf.svc.local
```

- Specify a custom port number 7777 while binding to the given address
```
  sbi:
    server:
      - address: amf.localdomain
        port: 7777
```

- Bind to 127.0.0.5 and advertise as open5gs-amf.svc.local
```
  sbi:
    server:
      - address: 127.0.0.5
        port: 7777
        advertise: open5gs-amf.svc.local
```

- Bind to port 7777 but advertise with a different port number 8888
```
  sbi:
    server:
      - address: 127.0.0.5
        port: 7777
        advertise: open5gs-amf.svc.local:8888
```
2024-12-31 22:04:55 +09:00
Sukchan Lee
3f6f2a8846 [SBI] Enable SSL Key Logging for Enhanced Debugging and Analysis (#3647)
- Add `sslkeylogfile` configuration options to `*.yaml.in` in NFs.
- Update `open5gs-common.dirs` to include `var/log/open5gs/tls` directory
- Extend `ogs_sbi_context_s` structure in `context.h` to include `sslkeylog`
- Modify `context.c` to parse and handle `sslkeylogfile` settings
- Update `server.c` and `server.h` to manage the `sslkeylog` field
  in server structures
- Update `ogs_sbi_client_add` and `ogs_sbi_client_remove` functions to handle
  `sslkeylog` field.
- Adjust `meson.build` to create the TLS log directory during installation

This commit introduces SSL key logging functionality to Open5GS,
enabling the capture of SSL/TLS keys. This feature is essential
for debugging encrypted traffic and allows integration with tools
like Wireshark for decrypting TLS sessions.
2024-12-30 21:21:41 +09:00
Sukchan Lee
35a14b595d Merge branch 'sctp-fix' 2024-12-27 09:25:24 +09:00