1821 Commits

Author SHA1 Message Date
Sukchan Lee
b7cd0d6a7c Follow-up on #4105 2025-10-17 09:17:02 +09:00
jmasterfunk84
a90544f312 [UDM][UDR] Add support for dataset-names resource (#4105)
* Enable datasets in UDM

* Remove developer comment
2025-10-17 09:16:28 +09:00
Bostjan Meglic
40351e5a38 [ue-info] consolidate separate function pointers into custom endpoints
Instead of predetermined endpoints in the metrics library, each NF can
now set it's own endpoints on which it listens for requests to dump info
(UE/PDU/gNB/eNB).
2025-10-17 08:30:45 +09:00
Bostjan Meglic
37c74da44f [ue-info] consolidate page/page size for ue-info API interface
Remove function pointers to set page/page sizes per info type
(UE/PDU/gNB/eNB info). Instead, call dumpers functions with this
information as function arguments.
2025-10-17 08:30:45 +09:00
Sukchan Lee
fd897f35a3 MME: handle EPS Bearer Context Status mismatch when active_flag=0 (#4112)
When the UE sends a Tracking Area Update (TAU) Request with active_flag=0,
the MME previously sent TAU Accept without verifying the EPS Bearer Context
Status (EBCS). This caused stale bearer sessions to remain in the MME even
if the UE had already released them.

According to 3GPP TS 24.301 §5.5.3.2, the MME should release any bearer
not reported in the UE’s EBCS when active_flag=0. This patch introduces
mme_send_delete_session_or_tau_accept(), which compares the UE’s EBCS bitmask
with the MME session list and deletes any missing default bearer session
before sending TAU Accept.

If no mismatch is found, TAU Accept is sent immediately. The Delete Session
response triggers TAU Accept when deletions are required. This ensures that
the TAU Accept message reflects the UE’s current bearer context accurately.

Also includes:
 - Added OGS_GTP_DELETE_SEND_TAU_ACCEPT handling in mme-s11-handler.c
 - Simplified EBCS structure (uint16_t value) for bitmask comparison
 - Updated TAU-related tests with realistic EBI bitmasks (0x20, 0x60)

This change aligns TAU handling with 3GPP 24.301 and prevents bearer
mismatch issues between UE and EPC during TAU.
2025-10-16 21:46:38 +09:00
Juraj Elias
794c63276e Open5GS JSON API for accessing UE, gNB, eNB, PDU data (#4093)
Open5GS has a lightweight HTTP server (already used for `/metrics`) embedded in each NF.
New optional JSON endpoints were added:

| NF  | Endpoint | Content |
| --- | --- | --- |
| **SMF** | `/pdu-info` | All currently connected UEs + their PDU sessions (IMSI/SUPI, DNN, IPs, S-NSSAI, QoS, state, etc.) |
| **AMF** | `/gnb-info` | All currently connected gNBs and their supported TAs, PLMNs, SCTP info, number of UEs |
| **AMF** | `/ue-info` | All currently connected NR UEs and their info, active gNB, tai, security, slices, am_policy |
| **MME** | `/enb-info` | All currently connected eNBs and their supported TAs, PLMNs, SCTP info, number of UEs |
| **MME** | `/ue-info` | All currently connected LTE UEs and their info, active eNB, tai, pdn info |

They are exposed on the same HTTP port used by Prometheus metrics (default `:9090`).

To reduce processor load when there are a large number of devices, the API includes a pager that limits output.

`/ue-info?page=0&page_size=100`

page in the range 0-n (0 is default),

`page=-1` to avoid paging

`page_size=100` (default and MAX)
2025-10-01 21:52:54 +09:00
Sukchan Lee
0bf649226b [SBI] Prevent UAF/double-free by using pool ID in timer callbacks (#4074)
- Use ogs_pool_id_calloc() / ogs_pool_id_free() instead of ogs_pool_alloc() / ogs_pool_free()
  to assign stable pool IDs to connection_t and ogs_sbi_session_t.
- Pass pool ID to ogs_timer_add() instead of raw pointer.
- In connection_timer_expired() and session_timer_expired(), resolve object via
  ogs_pool_find_by_id() and safely return if the object has already been freed.
- Add safety checks and error logs for invalid IDs and missing objects.

This prevents use-after-free or double-free crashes when timer callbacks
are triggered after the object has been freed under heavy load.
2025-09-17 21:50:47 +09:00
Sukchan Lee
edfdd3d126 Follow-up on (#4044) 2025-09-14 10:36:00 +09:00
hug0lin
fc42f3039c Open5GS connected UEs, APN/DNN, IP addresses (#4044)
Added additional fields: snssai, qos flow, pdu, and UE state. For 5G (for LTE, the pdu state is currently unknown).

curl -s http://127.0.0.4:9090/connected-ues |jq .
 {
    "supi": "imsi-999700000083810",                 // 5G RAT
    "pdu": [
      {
        "psi": 1,
        "dnn": "internet",
        "ipv4": "10.45.0.2",
        "snssai": {
          "sst": 1,
          "sd": "ffffff"
        },
        "qos_flows": [
          {
            "qfi": 1,
            "5qi": 9
          }
        ],
        "pdu_state": "inactive"
      }
    ],
    "ue_activity": "idle"
  },
{
    "supi": "001010000056492",            // LTE RAT
    "pdu": [
      {
        "ebi": 5,
        "apn": "internet",
        "ipv4": "10.45.0.3",
        "qos_flows": [
          {
            "ebi": 5,
            "qci": 9
          }
        ],
        "pdu_state": "unknown"
      }
    ],
    "ue_activity": "unknown"
  },

Added other outputs related to the connected gNBs/eNBs to AMF and MME, so we should have the basic tools for the 4G/5G core operation.

curl -s http://127.0.0.4:9090/connected-ues |jq .
curl -s http://127.0.0.5:9090/connected-gnbs | jq .
curl -s http://127.0.0.2:9090/connected-enb |jq .

curl -s http://127.0.0.5:9090/connected-gnbs |jq .
[
  {
    "gnb_id": 100,
    "plmn": "99970",
    "network": {
      "amf_name": "efire-amf0",
      "ngap_port": 38412
    },
    "ng": {
      "setup_success": true,
      "sctp": {
        "peer": "[192.168.168.100]:60110",
        "max_out_streams": 2,
        "next_ostream_id": 1
      }
    },
    "supported_ta_list": [
      {
        "tac": "000001",
        "bplmns": [
          {
            "plmn": "99970",
            "snssai": [
              {
                "sst": 1,
                "sd": "ffffff"
              }
            ]
          },
          {
            "plmn": "99971",
            "snssai": [
              {
                "sst": 2,
                "sd": "000000"
              }
            ]
          }
        ]
      },
      {
        "tac": "000051",
        "bplmns": [
          {
            "plmn": "00101",
            "snssai": [
              {
                "sst": 2,
                "sd": "123456"
              }
            ]
          }
        ]
      },
    ],
    "num_connected_ues": 0
  }
]

curl -s http://127.0.0.2:9090/connected-enbs |jq .
[
  {
    "enb_id": 264040,
    "plmn": "99970",
    "network": {
      "mme_name": "efire-mme0"
    },
    "s1": {
      "setup_success": true,
      "sctp": {
        "peer": "[192.168.168.254]:36412",
        "max_out_streams": 10,
        "next_ostream_id": 1
      }
    },
    "supported_ta_list": [
      {
        "tac": "000001",
        "plmn": "99970"
      }
    ],
    "num_connected_ues": 1
  }
]

curl -s http://127.0.0.4:9090/connected-ues |jq .
[
  {
    "supi": "imsi-999700000083810",
    "pdu": [
      {
        "psi": 1,
        "dnn": "internet",
        "ipv4": "10.45.0.2",
        "snssai": {
          "sst": 1,
          "sd": "ffffff"
        },
        "qos_flows": [
          {
            "qfi": 1,
            "5qi": 9
          }
        ],
        "pdu_state": "inactive"
      }
    ],
    "ue_activity": "idle"
  },
  {
    "supi": "imsi-999700000021635",
    "pdu": [
      {
        "psi": 1,
        "dnn": "ims",
        "ipv4": "10.45.0.124",
        "ipv6": "2001:db8:cafe:79::7a",
        "snssai": {
          "sst": 1,
          "sd": "ffffff"
        },
        "qos_flows": [
          {
            "qfi": 1,
            "5qi": 5
          }
        ],
        "pdu_state": "active"
      }
    ],
    "ue_activity": "active"
  }
]
2025-09-13 10:02:01 +09:00
Pau Espin Pedrol
62f961bfbf [MME] emm-handler: Interpret unused Attach Type as EPS Attach
3GPP TS 24.301:
"All other values are unused and shall be interpreted as "EPS attach", if received by the
network".
2025-09-08 22:23:23 +09:00
Pau Espin Pedrol
5d7d3e755f [MME] Fix several values in OGS_NAS_ATTACH_TYPE_*
Values for Emergency Attach and Reserved were wrong.
2025-09-08 22:23:23 +09:00
Pau Espin Pedrol
f7889f2be3 [5G-NAS] Avoid parse failure with Packet Filter match-all type 2025-08-24 10:43:22 +09:00
Pau Espin Pedrol
b11350f969 [5G-NAS] Improve QoS Rules parsing
The older version of the code was wrong (or at least not exactly
correct) in many (corner) cases.

* Split the parsing of Packet Filter List into its own helper function
  to simplify the code
* Improve error logging to provide more info on which QoS rule failed.
* Add some extra logic checking match between 'Length of QoS rule' and
  existance of m+1 and m+2 bytes.
* Correct logic checking expected/unexpected presence of m+1 and m+2
  octets based on Rule Operation Code according to specs.
2025-08-24 10:43:22 +09:00
Pau Espin Pedrol
1bdbaa4ef2 cosmetic: lib/nas/5gs/types.c: Fix trailing whitespace 2025-08-24 10:43:22 +09:00
Sukchan Lee
fb3cba40e5 [HR] V-UPF: preserve PSC on N2 indirect (Access->Access) without QER (#2194)
Home-Routed roaming: during Xn/N2 handover the source gNB may forward
remaining DL data to the core using UL PDU Session Information (PSC).
On the V-UPF the PSC was lost on the indirect path because OHR+OHC
removed the incoming GTP-U header (and its extensions) and we did not
recreate PSC when no QER/QFI was provisioned by the V-SMF.

This change makes the V-UPF rebuild a DL PSC for the target gNB even
when QER is absent, limited to the Access->Access indirect path
(source gNB -> V-UPF -> target gNB).

Why this is needed in HR:
- In HR deployments the V-SMF typically does not provision QER/QFI for
  the temporary indirect path. Without recreating PSC from recvhdr, the
  extension header disappears after OHR+OHC and the target gNB cannot
  see the QFI during handover buffering/forwarding.
2025-08-15 11:07:56 +09:00
Sukchan Lee
f23d7a5e95 [DIAM] Enhance Exception Handling in all Rx Callbacks
Add robust error checks and logging to MME, SMF, PCRF, and HSS
Diameter callback functions. Prevent assertion failures by
handling unexpected or late messages gracefully.
2025-08-02 15:15:06 +09:00
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