Commit Graph

1805 Commits

Author SHA1 Message Date
Pau Espin Pedrol
4e21cff6e6 sbi: Fix typo in log debug msg 2025-07-30 22:09:32 +09:00
Sukchan Lee
60a9707b8e Merge branch 'r2.7.6' 2025-07-21 16:52:07 +09:00
Sukchan Lee
a850c4d1d2 Revert "[SMF] Refactor core address‐resolution to robustly support both IP literals and hostnames (#4008)"
This reverts commit 64bb567aa2.
2025-07-21 16:51:41 +09:00
Sukchan Lee
64bb567aa2 [SMF] Refactor core address‐resolution to robustly support both IP literals and hostnames (#4008)
This change revises the existing ogs_addaddrinfo() function to handle
partial failures without aborting the process, ensure proper cleanup
of any nodes allocated before an error, and emit more informative logs
(including getaddrinfo() errors and situations where no usable addresses
 are returned).

By introducing “tail” and “first_new” pointers, new entries can be appended
to an existing list and safely detached if memory allocation fails mid‐stream.

On top of that, a new helper API, ogs_sockaddr_from_ip_or_fqdn(), was added.

It automatically detects whether its input is a numeric IPv4/IPv6 literal
or a hostname (using AI_NUMERICHOST when appropriate), then delegates
resolution to ogs_addaddrinfo().

Errors are logged at the error level but do not trigger a fatal exit,
and any partial lists are cleaned up before returning.

Finally, the SMF configuration parser in context.c was updated to use
this new API for “p-cscf” entries, allowing both raw IP addresses
and DNS names in smf.yaml.

Corresponding adjustments were made in context.h (to change the p_cscf
and p_cscf6 arrays to mutable char pointers) and in the cleanup routine
smf_context_final() to free any dynamically allocated strings.

Together, these improvements eliminate duplicate parsing logic,
streamline configuration handling, and increase the overall resilience
of address resolution across Open5GS.
2025-07-21 16:47:47 +09:00
Sukchan Lee
753523033d [SMF] Refactor core address‐resolution to robustly support both IP literals and hostnames (#4008)
This change revises the existing ogs_addaddrinfo() function to handle
partial failures without aborting the process, ensure proper cleanup
of any nodes allocated before an error, and emit more informative logs
(including getaddrinfo() errors and situations where no usable addresses
 are returned).

By introducing “tail” and “first_new” pointers, new entries can be appended
to an existing list and safely detached if memory allocation fails mid‐stream.

On top of that, a new helper API, ogs_sockaddr_from_ip_or_fqdn(), was added.

It automatically detects whether its input is a numeric IPv4/IPv6 literal
or a hostname (using AI_NUMERICHOST when appropriate), then delegates
resolution to ogs_addaddrinfo().

Errors are logged at the error level but do not trigger a fatal exit,
and any partial lists are cleaned up before returning.

Finally, the SMF configuration parser in context.c was updated to use
this new API for “p-cscf” entries, allowing both raw IP addresses
and DNS names in smf.yaml.

Corresponding adjustments were made in context.h (to change the p_cscf
and p_cscf6 arrays to mutable char pointers) and in the cleanup routine
smf_context_final() to free any dynamically allocated strings.

Together, these improvements eliminate duplicate parsing logic,
streamline configuration handling, and increase the overall resilience
of address resolution across Open5GS.
2025-07-21 16:44:45 +09:00
Sukchan Lee
f21bc06054 Merge branch 'main' into home-routed 2025-07-12 08:13:15 +09:00
Sukchan Lee
345800ba94 [SMF] Improve robustness of PCO parsing and building by replacing fatal assertions with error handling (#3969)
Previously, malformed Protocol Configuration Options (PCO) data would trigger
ogs_assert failures in both the generic parser and SMF build routines,
causing the SMF process to abort unconditionally.

This commit replaces those fatal assertions with conditional checks:

In ogs_pco_parse(), switch from ogs_assert(size == data_len) to
ogs_expect(size == data_len), allowing the function to return gracefully.

In SMF's PCO build (smf_pco_build) and all downstream build paths
(including GN, GSM, S5C modules), replace ogs_assert(pco_len > 0)
with explicit if (pco_len <= 0) checks that:

Ensure that malformed or incomplete PCOs no longer crash the process,
but instead are handled cleanly so the network function can continue operating.
2025-07-09 21:28:08 +09:00
Sukchan Lee
94cf8ee0e0 [HR] Implement handling of UE-initiated PDU Session Modification (#2194)
This commit consolidates the entire ue-mod feature branch
into a single update on top of the latest home-routed code.
2025-06-30 10:07:06 +09:00
Sukchan Lee
932101b919 Merge branch 'main' into home-routed 2025-06-30 10:02:57 +09:00
Sukchan Lee
67ba7f92bb [SBI] guard against NULL http->content in parse_multipart (#3942)
In lib/sbi/message.c parse_multipart(), http->content may be NULL.
This occurs on empty-body multipart POSTs and causes a segfault.

Add guard to check http->content, log an error, and return OGS_ERROR.
2025-06-28 10:12:54 +09:00
Sukchan Lee
f64a65843a [SBI] use CURL_AT_LEAST_VERSION for MAX_CONCURRENT_STREAMS check
In lib/sbi/client.c, the conditional compilation for
CURLMOPT_MAX_CONCURRENT_STREAMS was using #ifdef, which does not
ensure the option is set when the symbol is undefined.

Replace the check with #if CURL_AT_LEAST_VERSION(7,67,0) so that the
client applies the max concurrent streams setting on supported
libcurl versions. This fixes pool.event always showing the default
value and enables dynamic adjustment according to pool.stream.
2025-06-27 11:10:01 +09:00
Sukchan Lee
8852fbada0 Merge branch 'main' into home-routed 2025-06-17 17:34:46 +09:00
Sukchan Lee
52ca325ed5 [AMF] Follow-up on #3880 2025-06-17 17:34:18 +09:00
mitmitmitm
a538e31bed [SMF] If GTPU conf has advert addr, use it in up2cp FAR
SMF constructs up2cp FAR's outer_header_creation with |ogs_gtp_self()->gtpu_ip|
as DST IP address. Therefore, set |ogs_gtp_self()->gtpu_ip| to GTPU advertise
address. If advertise addr is not set, fall back to socket address as usual.
2025-06-10 17:06:27 +09:00
Sukchan Lee
f0005164a2 Merge branch 'main' into home-routed 2025-06-01 16:54:26 +09:00
Sukchan Lee
78bdd63984 [AMF] Follow-up on #3380 2025-05-31 20:51:41 +09:00
Matej Gradišar
799103257b [AMF] Fix UE context transfer when only NRF is client (#3880)
* [AMF] Fix UE context transfer when only NRF is client

If UE context transfer is initiated and the new AMF does not get the
old AMF from NRF or no UE context is retrieved from the old AMF,
we do not want to reject UE registration. Send identity request instead.
Test "transfer-error-case" is added into the commit.

* [tests] Unite tests for UE context transfer

All tests for UE context transfer with different configs are placed
into test folder transfer.

* [tests] Make two binaries for UE context transfer tests

For each test config a different test binary is created.
2025-05-31 20:51:06 +09:00
Pau Espin Pedrol
e93bc6b5c8 [SBI] Log error code description upon query failure
Sometimes (eg res=16) the conn->error buffer is left empty by curl, so
also logging the name of the error code provides some extra useful
information.
2025-05-29 06:02:21 +09:00
Sukchan Lee
3c1117d4fd [SBI] Fix parsing and serialization of _links "item" array (#3897)
Previously, Open5GS assumed the _links map contained an array under the key
"items". However, the 3GPP specification (TS29.510 section 4.9.4 and TS29.501
Table 6.1.6.2.25-1) defines this member name as "item".

As a result, when interacting with vendor NRF implementations that use "item",
Open5GS could not find the array and logged "No items", causing JSON errors.

This change updates both serialization and parsing in lib/sbi/custom/links.c:

- In ogs_sbi_links_convertToJSON(), replace the property name "items" with
  "item" when building JSON.
- In ogs_sbi_links_parseFromJSON(), retrieve the array under "item" and adjust
  the error message to "No item" if the member is missing.

With these corrections, Open5GS will correctly handle NRF responses using "item"
and remain compliant with the indirect communication model defined by 3GPP.
2025-05-18 14:32:39 +09:00
Sukchan Lee
3e6b7e961d Merge branch 'main' into home-routed 2025-05-10 12:08:47 +09:00
Sukchan Lee
78ea40881c [ipfw2] override errx() to prevent exit on error (#3840)
In ipfw2.c errx() would call exit(), aborting the UPF thread on rule parse
errors. Add a macro mapping errx() to ogs_log_message() so errors are logged.
We no longer call exit() and the main loop continues on error.
2025-05-09 16:47:42 +09:00
Sukchan Lee
3a91d2aa3f [SBI] Guard against missing poll.write in session_write_callback to prevent shutdown assertion (#3893, #3807, #2411, #2312)
Prior to this change, `session_write_callback()` unconditionally asserted that
`sbi_sess->poll.write` was non-NULL when the write queue drained, then removed
it from the poll set. In edge cases—particularly when using curl 8.x with
external epoll and `SIGPIPE` disabled—a late `EPOLLOUT` or errant write-ready
notification could arrive after `poll.write` had already been cleared. This
triggered the assertion in `nghttp2-server.c:1765`, aborting the process on
shutdown or session teardown.

This commit replaces the hard assertion with a runtime guard. If `poll.write`
is present, it is removed and reset to NULL as before. If it is already NULL,
we emit an warning log (`ogs_warn`) instead of aborting. This ensures any stray
write events after cleanup are safely ignored, allowing a clean exit without
crashing.

- Wrap `ogs_pollset_remove()` and pointer clear in `if (sbi_sess->poll.write)`
- Log an warning when `poll.write` is unexpectedly absent
- Preserve original behavior when `poll.write` is valid

This change resolves the fatal assertion observed on process exit after the
EPOLLERR/SIGPIPE fix and improves overall shutdown robustness.
2025-05-09 16:03:50 +09:00
Sukchan Lee
aab6940cd5 [AMF] improve HTTP/2 timeout handling and error logging (#3862, #3863)
- Check ran_ue existence and abort if NG context has already been removed
- Detect deassociated RAN-UE (invalid amf_ue_id) and
  break to avoid further processing
- Validate AMF-UE ID matches ran_ue->amf_ue_id and skip on mismatch
2025-05-06 15:47:17 +09:00
Sukchan Lee
3706479582 [ipfw] guard token parsing loop against buffer overflow
The token parsing loop in ogs_ipfw_compile_rule() lacked a bound on the
number of tokens stored in the 'av' array. This could overflow the stack
buffer when parsing overly long flow descriptions. Add a check to ensure
'i' remains below MAX_NUM_OF_TOKEN-2 before assigning to 'av[i]'.
2025-05-05 07:55:45 +09:00
Sukchan Lee
ca61a901d5 Implement PDU Session Release for Home-Routed Roaming and fix N4 step ordering in 4.3.4.2
- Add support for PDU Session Release in 3GPP TS 23.502 section 4.3.4.3
  Note: PCF-initiated release flow for Home-Routed Roaming is not implemented;
- Fix N4 release step ordering in 3GPP TS 23.502 section 4.3.4.2 UE or network requested PDU Session Release for Non-Roaming and Roaming with Local Breakout
2025-05-02 21:28:25 +09:00
Pallavi Das
fba00abd75 Typos Fix 2025-04-27 08:14:54 +09:00
Pallavi Das
cd80aa432e Typos Fix 2025-04-19 20:45:25 +09:00
shellwayxw
90cb00ced3 Always make fqdn a NULL terminated string 2025-04-17 17:14:15 +09:00
shellwayxw
31d3f575d2 Fix stack overflow in ogs_pfcp_extract_node_id() 2025-04-17 17:14:15 +09:00
shellwayxw
726b588d76 Fix integer overflow in PFCP ogs_pfcp_parse_sdf_filter() 2025-04-17 17:14:15 +09:00
Sukchan Lee
d66d6f868a Merge branch 'main' into home-routed 2025-04-06 18:37:36 +09:00
Sukchan Lee
46f74c8019 Merge branch 'main' into home-routed 2025-04-06 18:36:57 +09:00
Sukchan Lee
9217889f8a [HSS,S6A] Add two Supported-Features AVPs to ULA for 5G-NSA roaming (#3832)
This commit adds support for two Supported-Features AVPs in the
UpdateLocationAnswer (ULA) to enable 5G-NSA roaming. The first AVP
includes subscriber restrictions, while the second AVP signals that NR
as Secondary RAT is supported. Updates include modifications to
lib/diameter/s6a/message.c, lib/diameter/s6a/message.h, and
src/hss/hss-s6a-path.c.
2025-04-06 17:01:54 +09:00
Sukchan Lee
bf1cb6a024 [HSS/DBI] Follow-up on #3829 2025-04-05 18:26:32 +09:00
Farzaneh_sz
51acc388a6 get ifc data from db and insert in cx user data 2025-04-05 18:24:32 +09:00
Sukchan Lee
b326b99f28 [CORE] Fix busy loop and blocking in curl with EPOLLERR handling in Open5GS 2.7.x (#3807, #2411, #2312)
In Open5GS 2.7.x, when using curl 8.x with external epoll, an issue occurred
where the peer connection was closed, triggering EPOLLERR. At this point,
POLL_OUT should have been set to trigger the write event handler, invoking
`event_cb()` and calling `curl_multi_socket_action`. This would allow
`curl_multi_info_read` to execute without blocking.

However, when `event_cb()` wasn't invoked, `curl_multi_socket_action` was
not called, causing `curl_multi_info_read` to block. This resulted in a busy
loop in epoll, continuously checking for the closed peer connection.

This issue specifically affects Open5GS 2.7.x with curl 8.x, and is observed
on Ubuntu versions starting from **noble** and later. It does not occur on
Ubuntu Jammy.

The solution involves globally ignoring SIGPIPE and fixing the epoll logic
to ensure POLL_OUT is triggered when EPOLLERR occurs, allowing `curl_multi_socket_action`
to be invoked and `curl_multi_info_read` to run non-blocking. This resolves
the busy loop and connection issues caused by peer disconnects when using
curl 8.x and external epoll.

This fix improves the stability and performance of Open5GS when used with
curl 8.x and Ubuntu versions **noble** and above.
2025-03-30 21:46:31 +09:00
Sukchan Lee
ae6cedf8e8 Revert "[SBI] replace calls to free_<nf>_info() with OpenAPI_<nf>_info_free()"
This reverts commit 7ad40395a0.
2025-03-26 10:04:06 +09:00
Sukchan Lee
704083db3b [SBI] Fix improper inclusion of callback headers in non-callback requests (#3798)
This commit fixes an issue where the callback header (3gpp-Sbi-Callback)
was incorrectly added in non-callback requests. Specifically, for registration
(PUT) and subscription requests in the AMF and SMF modules, the callback
header was included even though these are not asynchronous notifications.

Changes include:
- Removing the callback header assignment in src/amf/nudm-build.c and
  src/smf/nudm-build.c for registration and subscription requests.
- Removing the callback header in NRF subscription-related builds in
  lib/sbi/nnrf-build.c where it was not required.
- Adding the callback header only for actual notification or callback
  operations (e.g. in src/amf/nsmf-build.c for N1/N2 transfer failure and
  in src/nrf/nnrf-build.c for NF status notifications).
- Introducing a new callback macro in lib/sbi/message.h for
  Namf_Communication_onN1N2TransferFailure.

This aligns the implementation with the standard, ensuring that callback
headers are only included in genuine callback/notification messages.
2025-03-25 14:50:20 +09:00
Sukchan Lee
708f789792 [UPF/SGWU] fix: validate f_teid_len to avoid TEID swap bug on restart (#3747, #3574)
When UPF/SGW-U is restarted, missing f_teid_len validation causes an error.
This patch adds checks for f_teid_len > 0 in ogs_pfcp_pdr_swap_teid and
in the SGW-U and N4 handler functions.
2025-03-23 11:21:03 +09:00
Bostjan Meglic
fa3edde329 [NAS] add support for 30-seconds unit for GPRS3 timer 2025-03-21 17:52:12 +09:00
Sukchan Lee
10b161fbb9 [AMF] Refactor AMF Region ID Handling (#3778)
- Changed amf_region_id type from uint16_t to uint8_t in context.h.
- Updated context.c to use ogs_amf_region_id() for extracting and comparing
  the region ID.
2025-03-16 12:22:39 +09:00
Bostjan Meglic
9e6b86b84e [AMF] fix AmfInfo when AMF Set Id was configured beyond 4
AMF Set Id is 10 bits long. Previously only the 2 bits from field "set2"
were used.
2025-03-16 12:12:18 +09:00
Bostjan Meglic
49c5a280da [AMF,SBI] add support for TAI ranges in AmfInfo
- fix an out-of-array-bounds-write to nf_info->amf.nr_tai during list1
TAI parsing, in case that sum of ranges of TAC's was bigger than 16
(OGS_MAX_NUM_OF_TAI).
- add checks for out-of-array-bounds
- fix indents
- fix error check
- subjectively prettify the code

[sbi] DEBUG: ogs_sbi_nf_state_will_register(): ENTRY (../lib/sbi/nf-sm.c:208)
[sbi] ERROR: CHECK CONFIGURATION: No Start/End in TacRange (../lib/sbi/nnrf-build.c:1094)
[sbi] FATAL: ogs_nnrf_nfm_build_nf_profile: Assertion `AmfInfo' failed. (../lib/sbi/nnrf-build.c:342)
[core] FATAL: backtrace() returned 13 addresses (../lib/core/ogs-abort.c:37)

Example configuration with which to trigger AMF crash before the fix:

guami:
  - plmn_id:
      mcc: "001"
      mnc: "01"
    amf_id:
      pointer: 31
      region: 2
      set: 1
  - plmn_id:
      mcc: "999"
      mnc: "93"
    amf_id:
      pointer: 31
      region: 2
      set: 1
  - plmn_id:
      mcc: "010"
      mnc: "310"
    amf_id:
      pointer: 32
      region: 2
      set: 1
tai:
  - plmn_id:
      mcc: "001"
      mnc: "01"
    tac:
      - 1
      - 5-6
  - plmn_id:
      mcc: "999"
      mnc: "93"
    tac:
      - 1
      - 11
  - plmn_id:
      mcc: "010"
      mnc: "310"
    tac:
      - 1011
      - 1020-1030
2025-03-16 12:12:18 +09:00
Bostjan Meglic
8f008c8440 [SBI] replace manual free's with calls to OpenAPI_<struct>_free() 2025-03-16 12:12:18 +09:00
Bostjan Meglic
7ad40395a0 [SBI] replace calls to free_<nf>_info() with OpenAPI_<nf>_info_free() 2025-03-16 12:12:18 +09:00
Sukchan Lee
e3dd98cd29 [PFCP] Prevent buffer overflow in PFCP context by using safe string copy (#3775)
Replace unsafe strcpy calls with ogs_cpystrn in both ogs_pfcp_dev_add()
and ogs_pfcp_subnet_add() to ensure proper length checking.

This change prevents potential buffer overflows when handling ifname
and dnn fields, which could otherwise lead to unintended overwrites
(e.g., fd and num_of_range).
2025-03-12 17:50:17 +09:00
Sukchan Lee
1abc3b6d5f [SMF] Separate EPC-only attach config to avoid NRF register timeout
Previously, sample.yaml was used for both 5GC and EPC attach tests.
Because SMF had SBI configured, it sent a register PUT to NRF even in
EPC-only tests (where nrf/scp was not run), leading to a missing HTTP
response and connection timer expiry.

Now, attach.yaml is used for EPC, preventing the unwanted NRF registration.
2025-03-10 09:53:00 +09:00
jmasterfunk84
ec7c9a80c1 Ignore MIP-H-A-H 2025-03-07 10:23:01 +09:00
Sukchan Lee
cb2359dca0 [PFCP] Validate F-TEID parameters to prevent UPF/SGWU crash (#3747)
This commit introduces robust validation for the F-TEID information element
in the PFCP message handling. Previously, malformed F-TEID values (such as
a zero length, zero TEID, or a TEID exceeding the pool size) could lead
to an assertion failure and crash the UPF.

The changes ensure that:
- The F-TEID length is greater than zero, confirming the IE is present.
- The TEID is a non-zero value, as a valid TEID must be positive.
- The TEID does not exceed the allowed pool size (max_ue * 4 * 16).

If any of these conditions are not met, an error is logged with the F-TEID
length and TEID value, and the function returns an error code
(OGS_PFCP_CAUSE_MANDATORY_IE_INCORRECT), preventing further processing
of the malformed message.
2025-03-07 10:14:57 +09:00
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