From ef07ccfb880878b708a7529eb5cc5afb9472594b Mon Sep 17 00:00:00 2001 From: Sukchan Lee Date: Sun, 30 May 2021 10:35:01 +0900 Subject: [PATCH] fix the default SBI port (#997, #1008) --- lib/sbi/context.c | 15 ++++++--------- lib/sbi/context.h | 3 +-- lib/sbi/conv.c | 6 +++++- lib/sbi/nnrf-handler.c | 4 ++-- src/nssf/context.c | 2 +- tests/af/context.c | 2 +- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/sbi/context.c b/lib/sbi/context.c index 8d4e18da4..d7c713f25 100644 --- a/lib/sbi/context.c +++ b/lib/sbi/context.c @@ -96,8 +96,7 @@ ogs_sbi_context_t *ogs_sbi_self(void) static int ogs_sbi_context_prepare(void) { - self.http_port = OGS_SBI_HTTP_PORT; - self.https_port = OGS_SBI_HTTPS_PORT; + self.sbi_port = OGS_SBI_HTTP_PORT; self.content_encoding = "gzip"; @@ -153,7 +152,7 @@ int ogs_sbi_context_parse_config(const char *local, const char *remote) const char *key = NULL; const char *pem = NULL; - uint16_t port = self.http_port; + uint16_t port = self.sbi_port; const char *dev = NULL; ogs_sockaddr_t *addr = NULL; @@ -233,10 +232,8 @@ int ogs_sbi_context_parse_config(const char *local, const char *remote) YAML_SEQUENCE_NODE); } else if (!strcmp(sbi_key, "port")) { const char *v = ogs_yaml_iter_value(&sbi_iter); - if (v) { + if (v) port = atoi(v); - self.http_port = port; - } } else if (!strcmp(sbi_key, "dev")) { dev = ogs_yaml_iter_value(&sbi_iter); } else if (!strcmp(sbi_key, "tls")) { @@ -335,7 +332,7 @@ int ogs_sbi_context_parse_config(const char *local, const char *remote) rv = ogs_socknode_probe( ogs_app()->parameter.no_ipv4 ? NULL : &list, ogs_app()->parameter.no_ipv6 ? NULL : &list6, - NULL, self.http_port); + NULL, self.sbi_port); ogs_assert(rv == OGS_OK); node = ogs_list_first(&list); @@ -364,7 +361,7 @@ int ogs_sbi_context_parse_config(const char *local, const char *remote) int family = AF_UNSPEC; int i, num = 0; const char *hostname[OGS_MAX_NUM_OF_HOSTNAME]; - uint16_t port = self.http_port; + uint16_t port = self.sbi_port; const char *key = NULL; const char *pem = NULL; @@ -942,7 +939,7 @@ static ogs_sbi_client_t *find_client_by_fqdn(char *fqdn, int port) ogs_sbi_client_t *client = NULL; rv = ogs_getaddrinfo(&addr, AF_UNSPEC, fqdn, - port ? port : OGS_SBI_HTTPS_PORT, 0); + port ? port : ogs_sbi_self()->sbi_port, 0); if (rv != OGS_OK) { ogs_error("Invalid NFProfile.fqdn"); return NULL; diff --git a/lib/sbi/context.h b/lib/sbi/context.h index a877999f1..b7561aa4c 100644 --- a/lib/sbi/context.h +++ b/lib/sbi/context.h @@ -36,8 +36,7 @@ typedef struct ogs_sbi_client_s ogs_sbi_client_t; typedef struct ogs_sbi_smf_info_s ogs_sbi_smf_info_t; typedef struct ogs_sbi_context_s { - uint32_t http_port; /* SBI HTTP local port */ - uint32_t https_port; /* SBI HTTPS local port */ + uint32_t sbi_port; /* SBI local port */ ogs_list_t server_list; ogs_list_t client_list; diff --git a/lib/sbi/conv.c b/lib/sbi/conv.c index 0899d1f79..183aea95f 100644 --- a/lib/sbi/conv.c +++ b/lib/sbi/conv.c @@ -46,7 +46,11 @@ char *ogs_uridup(bool https, ogs_sockaddr_t *addr, ogs_sbi_header_t *h) p = ogs_slprintf(p, last, "%s", OGS_ADDR(addr, buf)); /* Port number */ - if (OGS_PORT(addr) != OGS_SBI_HTTP_PORT) { + if ((https == true && OGS_PORT(addr) == OGS_SBI_HTTPS_PORT)) { + /* No Port in URI */ + } else if (OGS_PORT(addr) == OGS_SBI_HTTP_PORT) { + /* No Port in URI */ + } else { p = ogs_slprintf(p, last, ":%d", OGS_PORT(addr)); } diff --git a/lib/sbi/nnrf-handler.c b/lib/sbi/nnrf-handler.c index e353a88e9..1c715da10 100644 --- a/lib/sbi/nnrf-handler.c +++ b/lib/sbi/nnrf-handler.c @@ -248,7 +248,7 @@ bool ogs_sbi_nnrf_handle_nf_profile(ogs_sbi_nf_instance_t *nf_instance, if (nf_instance->num_of_ipv4 < OGS_SBI_MAX_NUM_OF_IP_ADDRESS) { rv = ogs_getaddrinfo(&addr, AF_UNSPEC, - node->data, OGS_SBI_HTTPS_PORT, 0); + node->data, ogs_sbi_self()->sbi_port, 0); if (rv != OGS_OK) continue; nf_instance->ipv4[nf_instance->num_of_ipv4] = addr; @@ -263,7 +263,7 @@ bool ogs_sbi_nnrf_handle_nf_profile(ogs_sbi_nf_instance_t *nf_instance, if (nf_instance->num_of_ipv6 < OGS_SBI_MAX_NUM_OF_IP_ADDRESS) { rv = ogs_getaddrinfo(&addr, AF_UNSPEC, - node->data, OGS_SBI_HTTPS_PORT, 0); + node->data, ogs_sbi_self()->sbi_port, 0); if (rv != OGS_OK) continue; nf_instance->ipv6[nf_instance->num_of_ipv6] = addr; diff --git a/src/nssf/context.c b/src/nssf/context.c index 62678a357..39e2e0330 100644 --- a/src/nssf/context.c +++ b/src/nssf/context.c @@ -108,7 +108,7 @@ int nssf_context_parse_config(void) int family = AF_UNSPEC; int i, num = 0; const char *hostname[OGS_MAX_NUM_OF_HOSTNAME]; - uint16_t port = ogs_sbi_self()->http_port; + uint16_t port = ogs_sbi_self()->sbi_port; const char *dev = NULL; ogs_sockaddr_t *addr = NULL; const char *key = NULL, *pem = NULL; diff --git a/tests/af/context.c b/tests/af/context.c index 678aab322..0b6ae35e6 100644 --- a/tests/af/context.c +++ b/tests/af/context.c @@ -267,7 +267,7 @@ static ogs_sbi_client_t *find_client_by_fqdn(char *fqdn, int port) ogs_sbi_client_t *client = NULL; rv = ogs_getaddrinfo(&addr, AF_UNSPEC, fqdn, - port ? port : OGS_SBI_HTTPS_PORT, 0); + port ? port : ogs_sbi_self()->sbi_port, 0); if (rv != OGS_OK) { ogs_error("Invalid NFProfile.fqdn"); return NULL;