mirror of
https://github.com/open5gs/open5gs.git
synced 2025-10-24 00:23:47 +00:00
[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
```
This commit is contained in:
@@ -59,18 +59,31 @@ amf:
|
||||
################################################################################
|
||||
# SBI Server
|
||||
################################################################################
|
||||
# o Override SBI address to be advertised to NRF
|
||||
# o Bind to the address on the eth0 and advertise as open5gs-amf.svc.local
|
||||
# sbi:
|
||||
# server:
|
||||
# - dev:eth0
|
||||
# advertise: open5gs-amf.svc.local
|
||||
#
|
||||
# o Specify a custom port number 7777 while binding to the given address
|
||||
# sbi:
|
||||
# server:
|
||||
# - address: localhost
|
||||
# advertise:
|
||||
# - 127.0.0.99
|
||||
# - ::1
|
||||
# - address: amf.localdomain
|
||||
# port: 7777
|
||||
#
|
||||
# o 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
|
||||
#
|
||||
# o 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
|
||||
#
|
||||
################################################################################
|
||||
# SBI Client
|
||||
|
||||
@@ -22,18 +22,31 @@ ausf:
|
||||
################################################################################
|
||||
# SBI Server
|
||||
################################################################################
|
||||
# o Override SBI address to be advertised to NRF
|
||||
# o Bind to the address on the eth0 and advertise as open5gs-ausf.svc.local
|
||||
# sbi:
|
||||
# server:
|
||||
# - dev:eth0
|
||||
# advertise: open5gs-ausf.svc.local
|
||||
#
|
||||
# o Specify a custom port number 7777 while binding to the given address
|
||||
# sbi:
|
||||
# server:
|
||||
# - address: localhost
|
||||
# advertise:
|
||||
# - 127.0.0.99
|
||||
# - ::1
|
||||
# - address: ausf.localdomain
|
||||
# port: 7777
|
||||
#
|
||||
# o Bind to 127.0.0.11 and advertise as open5gs-ausf.svc.local
|
||||
# sbi:
|
||||
# server:
|
||||
# - address: 127.0.0.11
|
||||
# port: 7777
|
||||
# advertise: open5gs-ausf.svc.local
|
||||
#
|
||||
# o Bind to port 7777 but advertise with a different port number 8888
|
||||
# sbi:
|
||||
# server:
|
||||
# - address: 127.0.0.11
|
||||
# port: 7777
|
||||
# advertise: open5gs-ausf.svc.local:8888
|
||||
#
|
||||
################################################################################
|
||||
# SBI Client
|
||||
|
||||
@@ -22,18 +22,31 @@ bsf:
|
||||
################################################################################
|
||||
# SBI Server
|
||||
################################################################################
|
||||
# o Override SBI address to be advertised to NRF
|
||||
# o Bind to the address on the eth0 and advertise as open5gs-bsf.svc.local
|
||||
# sbi:
|
||||
# server:
|
||||
# - dev:eth0
|
||||
# advertise: open5gs-bsf.svc.local
|
||||
#
|
||||
# o Specify a custom port number 7777 while binding to the given address
|
||||
# sbi:
|
||||
# server:
|
||||
# - address: localhost
|
||||
# advertise:
|
||||
# - 127.0.0.99
|
||||
# - ::1
|
||||
# - address: bsf.localdomain
|
||||
# port: 7777
|
||||
#
|
||||
# o Bind to 127.0.0.15 and advertise as open5gs-bsf.svc.local
|
||||
# sbi:
|
||||
# server:
|
||||
# - address: 127.0.0.15
|
||||
# port: 7777
|
||||
# advertise: open5gs-bsf.svc.local
|
||||
#
|
||||
# o Bind to port 7777 but advertise with a different port number 8888
|
||||
# sbi:
|
||||
# server:
|
||||
# - address: 127.0.0.15
|
||||
# port: 7777
|
||||
# advertise: open5gs-bsf.svc.local:8888
|
||||
#
|
||||
################################################################################
|
||||
# SBI Client
|
||||
|
||||
@@ -21,18 +21,31 @@ nrf:
|
||||
################################################################################
|
||||
# SBI Server
|
||||
################################################################################
|
||||
# o Override SBI address to be advertised to NRF
|
||||
# o Bind to the address on the eth0 and advertise as open5gs-nrf.svc.local
|
||||
# sbi:
|
||||
# server:
|
||||
# - dev:eth0
|
||||
# advertise: open5gs-nrf.svc.local
|
||||
#
|
||||
# o Specify a custom port number 7777 while binding to the given address
|
||||
# sbi:
|
||||
# server:
|
||||
# - address: localhost
|
||||
# advertise:
|
||||
# - 127.0.0.99
|
||||
# - ::1
|
||||
# - address: nrf.localdomain
|
||||
# port: 7777
|
||||
#
|
||||
# o Bind to 127.0.0.10 and advertise as open5gs-nrf.svc.local
|
||||
# sbi:
|
||||
# server:
|
||||
# - address: 127.0.0.10
|
||||
# port: 7777
|
||||
# advertise: open5gs-nrf.svc.local
|
||||
#
|
||||
# o Bind to port 7777 but advertise with a different port number 8888
|
||||
# sbi:
|
||||
# server:
|
||||
# - address: 127.0.0.10
|
||||
# port: 7777
|
||||
# advertise: open5gs-nrf.svc.local:8888
|
||||
#
|
||||
################################################################################
|
||||
# HTTPS scheme with TLS
|
||||
|
||||
@@ -25,18 +25,31 @@ nssf:
|
||||
################################################################################
|
||||
# SBI Server
|
||||
################################################################################
|
||||
# o Override SBI address to be advertised to NRF
|
||||
# o Bind to the address on the eth0 and advertise as open5gs-nssf.svc.local
|
||||
# sbi:
|
||||
# server:
|
||||
# - dev:eth0
|
||||
# advertise: open5gs-nssf.svc.local
|
||||
#
|
||||
# o Specify a custom port number 7777 while binding to the given address
|
||||
# sbi:
|
||||
# server:
|
||||
# - address: localhost
|
||||
# advertise:
|
||||
# - 127.0.0.99
|
||||
# - ::1
|
||||
# - address: nssf.localdomain
|
||||
# port: 7777
|
||||
#
|
||||
# o Bind to 127.0.0.14 and advertise as open5gs-nssf.svc.local
|
||||
# sbi:
|
||||
# server:
|
||||
# - address: 127.0.0.14
|
||||
# port: 7777
|
||||
# advertise: open5gs-nssf.svc.local
|
||||
#
|
||||
# o Bind to port 7777 but advertise with a different port number 8888
|
||||
# sbi:
|
||||
# server:
|
||||
# - address: 127.0.0.14
|
||||
# port: 7777
|
||||
# advertise: open5gs-nssf.svc.local:8888
|
||||
#
|
||||
################################################################################
|
||||
# SBI Client
|
||||
|
||||
@@ -148,18 +148,31 @@ pcf:
|
||||
################################################################################
|
||||
# SBI Server
|
||||
################################################################################
|
||||
# o Override SBI address to be advertised to NRF
|
||||
# o Bind to the address on the eth0 and advertise as open5gs-pcf.svc.local
|
||||
# sbi:
|
||||
# server:
|
||||
# - dev:eth0
|
||||
# advertise: open5gs-pcf.svc.local
|
||||
#
|
||||
# o Specify a custom port number 7777 while binding to the given address
|
||||
# sbi:
|
||||
# server:
|
||||
# - address: localhost
|
||||
# advertise:
|
||||
# - 127.0.0.99
|
||||
# - ::1
|
||||
# - address: pcf.localdomain
|
||||
# port: 7777
|
||||
#
|
||||
# o Bind to 127.0.0.13 and advertise as open5gs-pcf.svc.local
|
||||
# sbi:
|
||||
# server:
|
||||
# - address: 127.0.0.13
|
||||
# port: 7777
|
||||
# advertise: open5gs-pcf.svc.local
|
||||
#
|
||||
# o Bind to port 7777 but advertise with a different port number 8888
|
||||
# sbi:
|
||||
# server:
|
||||
# - address: 127.0.0.13
|
||||
# port: 7777
|
||||
# advertise: open5gs-pcf.svc.local:8888
|
||||
#
|
||||
################################################################################
|
||||
# SBI Client
|
||||
|
||||
@@ -63,18 +63,31 @@ scp:
|
||||
################################################################################
|
||||
# SBI Server
|
||||
################################################################################
|
||||
# o Override SBI address to be advertised to NRF
|
||||
# o Bind to the address on the eth0 and advertise as open5gs-scp.svc.local
|
||||
# sbi:
|
||||
# server:
|
||||
# - dev:eth0
|
||||
# advertise: open5gs-scp.svc.local
|
||||
#
|
||||
# o Specify a custom port number 7777 while binding to the given address
|
||||
# sbi:
|
||||
# server:
|
||||
# - address: localhost
|
||||
# advertise:
|
||||
# - 127.0.0.99
|
||||
# - ::1
|
||||
# - address: scp.localdomain
|
||||
# port: 7777
|
||||
#
|
||||
# o Bind to 127.0.0.200 and advertise as open5gs-scp.svc.local
|
||||
# sbi:
|
||||
# server:
|
||||
# - address: 127.0.0.200
|
||||
# port: 7777
|
||||
# advertise: open5gs-scp.svc.local
|
||||
#
|
||||
# o Bind to port 7777 but advertise with a different port number 8888
|
||||
# sbi:
|
||||
# server:
|
||||
# - address: 127.0.0.200
|
||||
# port: 7777
|
||||
# advertise: open5gs-scp.svc.local:8888
|
||||
#
|
||||
################################################################################
|
||||
# SBI Client
|
||||
|
||||
@@ -186,18 +186,31 @@ smf:
|
||||
################################################################################
|
||||
# SBI Server
|
||||
################################################################################
|
||||
# o Override SBI address to be advertised to NRF
|
||||
# o Bind to the address on the eth0 and advertise as open5gs-smf.svc.local
|
||||
# sbi:
|
||||
# server:
|
||||
# - dev:eth0
|
||||
# advertise: open5gs-smf.svc.local
|
||||
#
|
||||
# o Specify a custom port number 7777 while binding to the given address
|
||||
# sbi:
|
||||
# server:
|
||||
# - address: localhost
|
||||
# advertise:
|
||||
# - 127.0.0.99
|
||||
# - ::1
|
||||
# - address: smf.localdomain
|
||||
# port: 7777
|
||||
#
|
||||
# o Bind to 127.0.0.4 and advertise as open5gs-smf.svc.local
|
||||
# sbi:
|
||||
# server:
|
||||
# - address: 127.0.0.4
|
||||
# port: 7777
|
||||
# advertise: open5gs-smf.svc.local
|
||||
#
|
||||
# o Bind to port 7777 but advertise with a different port number 8888
|
||||
# sbi:
|
||||
# server:
|
||||
# - address: 127.0.0.4
|
||||
# port: 7777
|
||||
# advertise: open5gs-smf.svc.local:8888
|
||||
#
|
||||
################################################################################
|
||||
# SBI Client
|
||||
|
||||
@@ -81,18 +81,31 @@ udm:
|
||||
################################################################################
|
||||
# SBI Server
|
||||
################################################################################
|
||||
# o Override SBI address to be advertised to NRF
|
||||
# o Bind to the address on the eth0 and advertise as open5gs-udm.svc.local
|
||||
# sbi:
|
||||
# server:
|
||||
# - dev:eth0
|
||||
# advertise: open5gs-udm.svc.local
|
||||
#
|
||||
# o Specify a custom port number 7777 while binding to the given address
|
||||
# sbi:
|
||||
# server:
|
||||
# - address: localhost
|
||||
# advertise:
|
||||
# - 127.0.0.99
|
||||
# - ::1
|
||||
# - address: udm.localdomain
|
||||
# port: 7777
|
||||
#
|
||||
# o Bind to 127.0.0.12 and advertise as open5gs-udm.svc.local
|
||||
# sbi:
|
||||
# server:
|
||||
# - address: 127.0.0.12
|
||||
# port: 7777
|
||||
# advertise: open5gs-udm.svc.local
|
||||
#
|
||||
# o Bind to port 7777 but advertise with a different port number 8888
|
||||
# sbi:
|
||||
# server:
|
||||
# - address: 127.0.0.12
|
||||
# port: 7777
|
||||
# advertise: open5gs-udm.svc.local:8888
|
||||
#
|
||||
################################################################################
|
||||
# SBI Client
|
||||
|
||||
@@ -23,18 +23,31 @@ udr:
|
||||
################################################################################
|
||||
# SBI Server
|
||||
################################################################################
|
||||
# o Override SBI address to be advertised to NRF
|
||||
# o Bind to the address on the eth0 and advertise as open5gs-udr.svc.local
|
||||
# sbi:
|
||||
# server:
|
||||
# - dev:eth0
|
||||
# advertise: open5gs-udr.svc.local
|
||||
#
|
||||
# o Specify a custom port number 7777 while binding to the given address
|
||||
# sbi:
|
||||
# server:
|
||||
# - address: localhost
|
||||
# advertise:
|
||||
# - 127.0.0.99
|
||||
# - ::1
|
||||
# - address: udr.localdomain
|
||||
# port: 7777
|
||||
#
|
||||
# o Bind to 127.0.0.20 and advertise as open5gs-udr.svc.local
|
||||
# sbi:
|
||||
# server:
|
||||
# - address: 127.0.0.20
|
||||
# port: 7777
|
||||
# advertise: open5gs-udr.svc.local
|
||||
#
|
||||
# o Bind to port 7777 but advertise with a different port number 8888
|
||||
# sbi:
|
||||
# server:
|
||||
# - address: 127.0.0.20
|
||||
# port: 7777
|
||||
# advertise: open5gs-udr.svc.local:8888
|
||||
#
|
||||
################################################################################
|
||||
# SBI Client
|
||||
|
||||
@@ -823,9 +823,38 @@ int ogs_sbi_context_parse_server_config(
|
||||
}
|
||||
|
||||
addr = NULL;
|
||||
/* ----- Process advertise (Host+Port Parsing Logic) ----- */
|
||||
for (i = 0; i < num_of_advertise; i++) {
|
||||
rv = ogs_addaddrinfo(&addr, family, advertise[i], port, 0);
|
||||
uint16_t adv_port = port; /* Default to server's port */
|
||||
char *hostbuf = NULL;
|
||||
const char *colon_pos = strchr(advertise[i], ':');
|
||||
|
||||
if (colon_pos) {
|
||||
/* If a colon exists, split host and port */
|
||||
size_t host_len = colon_pos - advertise[i];
|
||||
|
||||
/* Allocate memory for the host part */
|
||||
hostbuf = (char *)ogs_malloc(host_len + 1);
|
||||
ogs_assert(hostbuf);
|
||||
|
||||
/* Copy the host part into hostbuf */
|
||||
memcpy(hostbuf, advertise[i], host_len);
|
||||
hostbuf[host_len] = '\0';
|
||||
|
||||
/* Parse the port part */
|
||||
adv_port = (uint16_t)atoi(colon_pos + 1);
|
||||
} else {
|
||||
/* If no colon, treat the entire string as the host */
|
||||
hostbuf = ogs_strdup(advertise[i]);
|
||||
ogs_assert(hostbuf);
|
||||
}
|
||||
|
||||
/* Add the parsed address info */
|
||||
rv = ogs_addaddrinfo(&addr, family, hostbuf, adv_port, 0);
|
||||
ogs_assert(rv == OGS_OK);
|
||||
|
||||
/* Free the allocated memory */
|
||||
ogs_free(hostbuf);
|
||||
}
|
||||
|
||||
node = ogs_list_first(&list);
|
||||
@@ -1752,11 +1781,8 @@ void ogs_sbi_nf_instance_build_default(ogs_sbi_nf_instance_t *nf_instance)
|
||||
ogs_assert(advertise);
|
||||
|
||||
/* First FQDN is selected */
|
||||
if (!hostname) {
|
||||
if (!hostname)
|
||||
hostname = ogs_gethostname(advertise);
|
||||
if (hostname)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (nf_instance->num_of_ipv4 < OGS_SBI_MAX_NUM_OF_IP_ADDRESS) {
|
||||
ogs_sockaddr_t *addr = NULL;
|
||||
@@ -1826,11 +1852,8 @@ ogs_sbi_nf_service_t *ogs_sbi_nf_service_build_default(
|
||||
ogs_assert(advertise);
|
||||
|
||||
/* First FQDN is selected */
|
||||
if (!hostname) {
|
||||
if (!hostname)
|
||||
hostname = ogs_gethostname(advertise);
|
||||
if (hostname)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (nf_service->num_of_addr < OGS_SBI_MAX_NUM_OF_IP_ADDRESS) {
|
||||
bool is_port = true;
|
||||
@@ -1943,6 +1966,7 @@ static void nf_service_associate_client(ogs_sbi_nf_service_t *nf_service)
|
||||
{
|
||||
ogs_sbi_client_t *client = NULL;
|
||||
ogs_sockaddr_t *addr = NULL, *addr6 = NULL;
|
||||
uint16_t port = 0;
|
||||
|
||||
ogs_assert(nf_service->scheme);
|
||||
|
||||
@@ -1950,15 +1974,28 @@ static void nf_service_associate_client(ogs_sbi_nf_service_t *nf_service)
|
||||
if (nf_service->num_of_addr) {
|
||||
addr = nf_service->addr[0].ipv4;
|
||||
addr6 = nf_service->addr[0].ipv6;
|
||||
|
||||
/*
|
||||
* Added support for using custom port numbers with FQDN.
|
||||
*
|
||||
* This code checks if a user-defined port number is provided in the
|
||||
* NFService structure. If the is_port flag is set, the port is
|
||||
* assigned the specified value.
|
||||
*
|
||||
* This ensures that services using non-default ports can be accessed
|
||||
* correctly, regardless of whether TLS is enabled or not.
|
||||
*/
|
||||
if (nf_service->addr[0].is_port)
|
||||
port = nf_service->addr[0].port;
|
||||
}
|
||||
|
||||
if (nf_service->fqdn || addr || addr6) {
|
||||
client = ogs_sbi_client_find(
|
||||
nf_service->scheme, nf_service->fqdn, 0, addr, addr6);
|
||||
nf_service->scheme, nf_service->fqdn, port, addr, addr6);
|
||||
if (!client) {
|
||||
ogs_debug("%s: ogs_sbi_client_add()", OGS_FUNC);
|
||||
client = ogs_sbi_client_add(
|
||||
nf_service->scheme, nf_service->fqdn, 0, addr, addr6);
|
||||
nf_service->scheme, nf_service->fqdn, port, addr, addr6);
|
||||
if (!client) {
|
||||
ogs_error("%s: ogs_sbi_client_add() failed", OGS_FUNC);
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user