diff --git a/debian/control b/debian/control index 5c1747f9b..f7f90d433 100644 --- a/debian/control +++ b/debian/control @@ -19,6 +19,7 @@ Build-Depends: debhelper (>= 11), libyaml-dev, libmicrohttpd-dev, libcurl4-gnutls-dev, + libnghttp2-dev, Standards-Version: 4.3.0 Rules-Requires-Root: no Homepage: https://open5gs.org diff --git a/docker/centos/7/base/Dockerfile b/docker/centos/7/base/Dockerfile index 3d0656ace..92c91e9f9 100644 --- a/docker/centos/7/base/Dockerfile +++ b/docker/centos/7/base/Dockerfile @@ -26,4 +26,5 @@ RUN yum -y install \ mongo-c-driver-devel \ libmicrohttpd-devel \ libcurl-devel \ + libnghttp2-devel \ iproute diff --git a/docker/centos/latest/base/Dockerfile b/docker/centos/latest/base/Dockerfile index 77448a441..db12baf94 100644 --- a/docker/centos/latest/base/Dockerfile +++ b/docker/centos/latest/base/Dockerfile @@ -31,6 +31,7 @@ RUN dnf -y install \ mongo-c-driver-devel \ libmicrohttpd-devel \ libcurl-devel \ + libnghttp2-devel \ iproute RUN dnf -y install meson diff --git a/docker/debian/latest/base/Dockerfile b/docker/debian/latest/base/Dockerfile index 0180cf961..8d3ac958e 100644 --- a/docker/debian/latest/base/Dockerfile +++ b/docker/debian/latest/base/Dockerfile @@ -27,6 +27,7 @@ RUN apt-get update && \ libyaml-dev \ libmicrohttpd-dev \ libcurl4-gnutls-dev \ + libnghttp2-dev \ iproute2 \ ca-certificates \ netbase \ diff --git a/docker/fedora/latest/base/Dockerfile b/docker/fedora/latest/base/Dockerfile index dc311df09..ad6df0a63 100644 --- a/docker/fedora/latest/base/Dockerfile +++ b/docker/fedora/latest/base/Dockerfile @@ -21,6 +21,7 @@ RUN dnf -y install \ mongo-c-driver-devel \ libmicrohttpd-devel \ libcurl-devel \ + libnghttp2-devel \ iproute RUN dnf -y install meson diff --git a/docker/ubuntu/latest/base/Dockerfile b/docker/ubuntu/latest/base/Dockerfile index 0180cf961..8d3ac958e 100644 --- a/docker/ubuntu/latest/base/Dockerfile +++ b/docker/ubuntu/latest/base/Dockerfile @@ -27,6 +27,7 @@ RUN apt-get update && \ libyaml-dev \ libmicrohttpd-dev \ libcurl4-gnutls-dev \ + libnghttp2-dev \ iproute2 \ ca-certificates \ netbase \ diff --git a/docs/_docs/guide/02-building-open5gs-from-sources.md b/docs/_docs/guide/02-building-open5gs-from-sources.md index c7a1b7e50..b07ed0cc0 100644 --- a/docs/_docs/guide/02-building-open5gs-from-sources.md +++ b/docs/_docs/guide/02-building-open5gs-from-sources.md @@ -44,7 +44,7 @@ $ sudo ip link set ogstun up Install the dependencies for building the source code. ```bash -$ sudo apt install python3-pip python3-setuptools python3-wheel ninja-build build-essential flex bison git libsctp-dev libgnutls28-dev libgcrypt-dev libssl-dev libidn11-dev libmongoc-dev libbson-dev libyaml-dev libmicrohttpd-dev libcurl4-gnutls-dev meson +$ sudo apt install python3-pip python3-setuptools python3-wheel ninja-build build-essential flex bison git libsctp-dev libgnutls28-dev libgcrypt-dev libssl-dev libidn11-dev libmongoc-dev libbson-dev libyaml-dev libnghttp2-dev libmicrohttpd-dev libcurl4-gnutls-dev libnghttp2-dev meson ``` Git clone. @@ -78,7 +78,7 @@ $ cd build $ meson test -v ``` -**Tip:** You can also check the result of `ninja -C build test` with a tool that captures packets. If you are running `wireshark`, select the `loopback` interface and set FILTER to `s1ap || gtpv2 || pfcp || diameter || gtp || ngap || http`. You can see the virtually created packets. [testattach.pcapng]({{ site.url }}{{ site.baseurl }}/assets/pcapng/testattach.pcapng)/[testregistration.pcapng]({{ site.url }}{{ site.baseurl }}/assets/pcapng/testregistration.pcapng) +**Tip:** You can also check the result of `ninja -C build test` with a tool that captures packets. If you are running `wireshark`, select the `loopback` interface and set FILTER to `s1ap || gtpv2 || pfcp || diameter || gtp || ngap || http2.data.data || http2.headers`. You can see the virtually created packets. [testattach.pcapng]({{ site.url }}{{ site.baseurl }}/assets/pcapng/testattach.pcapng)/[testregistration.pcapng]({{ site.url }}{{ site.baseurl }}/assets/pcapng/testregistration.pcapng) {: .notice--info} You need to perform the **installation process**. diff --git a/docs/_docs/platform/03-fedora.md b/docs/_docs/platform/03-fedora.md index 304851cdf..0d0c53431 100644 --- a/docs/_docs/platform/03-fedora.md +++ b/docs/_docs/platform/03-fedora.md @@ -70,7 +70,7 @@ $ ip link show Install the depedencies for building the source code. ```bash -$ sudo dnf install python3 ninja-build gcc flex bison git lksctp-tools-devel libidn-devel gnutls-devel libgcrypt-devel openssl-devel cyrus-sasl-devel libyaml-devel mongo-c-driver-devel libmicrohttpd-devel libcurl-devel iproute +$ sudo dnf install python3 ninja-build gcc flex bison git lksctp-tools-devel libidn-devel gnutls-devel libgcrypt-devel openssl-devel cyrus-sasl-devel libyaml-devel mongo-c-driver-devel libmicrohttpd-devel libcurl-devel libnghttp2-devel iproute ``` Install Meson @@ -104,7 +104,7 @@ $ cd build $ meson test -v ``` -**Tip:** You can also check the result of `ninja -C build test` with a tool that captures packets. If you are running `wireshark`, select the `loopback` interface and set FILTER to `s1ap || gtpv2 || pfcp || diameter || gtp || ngap || http`. You can see the virtually created packets. [testattach.pcapng]({{ site.url }}{{ site.baseurl }}/assets/pcapng/testattach.pcapng)/[testregistration.pcapng]({{ site.url }}{{ site.baseurl }}/assets/pcapng/testregistration.pcapng) +**Tip:** You can also check the result of `ninja -C build test` with a tool that captures packets. If you are running `wireshark`, select the `loopback` interface and set FILTER to `s1ap || gtpv2 || pfcp || diameter || gtp || ngap || http2.data.data || http2.headers`. You can see the virtually created packets. [testattach.pcapng]({{ site.url }}{{ site.baseurl }}/assets/pcapng/testattach.pcapng)/[testregistration.pcapng]({{ site.url }}{{ site.baseurl }}/assets/pcapng/testregistration.pcapng) {: .notice--info} You need to perform the **installation process**. diff --git a/docs/_docs/platform/04-freebsd.md b/docs/_docs/platform/04-freebsd.md index 6c19de680..e18e58c08 100644 --- a/docs/_docs/platform/04-freebsd.md +++ b/docs/_docs/platform/04-freebsd.md @@ -97,7 +97,7 @@ $ cd build $ sudo meson test -v ``` -**Tip:** You can also check the result of `ninja -C build test` with a tool that captures packets. If you are running `wireshark`, select the `loopback` interface and set FILTER to `s1ap || gtpv2 || pfcp || diameter || gtp || ngap || http`. You can see the virtually created packets. [testattach.pcapng]({{ site.url }}{{ site.baseurl }}/assets/pcapng/testattach.pcapng)/[testregistration.pcapng]({{ site.url }}{{ site.baseurl }}/assets/pcapng/testregistration.pcapng) +**Tip:** You can also check the result of `ninja -C build test` with a tool that captures packets. If you are running `wireshark`, select the `loopback` interface and set FILTER to `s1ap || gtpv2 || pfcp || diameter || gtp || ngap || http2.data.data || http2.headers`. You can see the virtually created packets. [testattach.pcapng]({{ site.url }}{{ site.baseurl }}/assets/pcapng/testattach.pcapng)/[testregistration.pcapng]({{ site.url }}{{ site.baseurl }}/assets/pcapng/testregistration.pcapng) {: .notice--info} You need to perform the **installation process**. diff --git a/docs/_docs/platform/05-macosx.md b/docs/_docs/platform/05-macosx.md index 3508118e0..454f4ec3d 100644 --- a/docs/_docs/platform/05-macosx.md +++ b/docs/_docs/platform/05-macosx.md @@ -72,7 +72,7 @@ $ sudo pfctl -e -f /etc/pf.anchors/org.open5gs Install the depedencies for building the source code. ```bash -$ brew install mongo-c-driver gnutls libgcrypt libidn libyaml libmicrohttpd curl pkg-config +$ brew install mongo-c-driver gnutls libgcrypt libidn libyaml libmicrohttpd nghttp2 pkg-config ``` Install Bison and Create soft link. @@ -121,7 +121,7 @@ $ cd build $ sudo meson test -v ``` -**Tip:** You can also check the result of `ninja -C build test` with a tool that captures packets. If you are running `wireshark`, select the `loopback` interface and set FILTER to `s1ap || gtpv2 || pfcp || diameter || gtp || ngap || http`. You can see the virtually created packets. [testattach.pcapng]({{ site.url }}{{ site.baseurl }}/assets/pcapng/testattach.pcapng)/[testregistration.pcapng]({{ site.url }}{{ site.baseurl }}/assets/pcapng/testregistration.pcapng) +**Tip:** You can also check the result of `ninja -C build test` with a tool that captures packets. If you are running `wireshark`, select the `loopback` interface and set FILTER to `s1ap || gtpv2 || pfcp || diameter || gtp || ngap || http2.data.data || http2.headers`. You can see the virtually created packets. [testattach.pcapng]({{ site.url }}{{ site.baseurl }}/assets/pcapng/testattach.pcapng)/[testregistration.pcapng]({{ site.url }}{{ site.baseurl }}/assets/pcapng/testregistration.pcapng) {: .notice--info} You need to perform the **installation process**. diff --git a/lib/app/ogs-context.h b/lib/app/ogs-context.h index dd6da4921..7ec4b3228 100644 --- a/lib/app/ogs-context.h +++ b/lib/app/ogs-context.h @@ -31,6 +31,8 @@ extern "C" { #endif typedef struct ogs_app_context_s { + const char *version; + const char *file; void *document; diff --git a/lib/app/ogs-init.c b/lib/app/ogs-init.c index 53a436873..f5cb8b768 100644 --- a/lib/app/ogs-init.c +++ b/lib/app/ogs-init.c @@ -21,7 +21,9 @@ int __ogs_app_domain; -int ogs_app_initialize(const char *default_config, const char *const argv[]) +int ogs_app_initialize( + const char *version, const char *default_config, + const char *const argv[]) { int rv, opt; ogs_getopt_t options; @@ -39,6 +41,7 @@ int ogs_app_initialize(const char *default_config, const char *const argv[]) ogs_app_setup_log(); ogs_app_context_init(); + ogs_app()->version = version; /************************************************************************** * Stage 1 : Command Line Options @@ -117,7 +120,27 @@ int ogs_app_initialize(const char *default_config, const char *const argv[]) ogs_app()->db_uri = ogs_env_get("DB_URI"); /************************************************************************** - * Stage 6 : Queue, Timer and Poll + * Stage 6 : Print Banner + */ + if (ogs_app()->version) { + ogs_log_print(OGS_LOG_INFO, + "Open5GS daemon %s\n\n", ogs_app()->version); + + ogs_info("Configuration: '%s'", ogs_app()->file); + + if (ogs_app()->logger.file) { + ogs_info("File Logging: '%s'", ogs_app()->logger.file); + + if (ogs_app()->logger.level) + ogs_info("LOG-LEVEL: '%s'", ogs_app()->logger.level); + + if (ogs_app()->logger.domain) + ogs_info("LOG-DOMAIN: '%s'", ogs_app()->logger.domain); + } + } + + /************************************************************************** + * Stage 7 : Queue, Timer and Poll */ ogs_app()->queue = ogs_queue_create(ogs_app()->pool.event); ogs_assert(ogs_app()->queue); diff --git a/lib/app/ogs-init.h b/lib/app/ogs-init.h index b8eccd0c4..e7f366362 100644 --- a/lib/app/ogs-init.h +++ b/lib/app/ogs-init.h @@ -28,7 +28,9 @@ extern "C" { #endif /* __cplusplus */ -int ogs_app_initialize(const char *default_config, const char *const argv[]); +int ogs_app_initialize( + const char *version, const char *default_config, + const char *const argv[]); void ogs_app_terminate(void); int ogs_app_config_read(void); diff --git a/lib/core/ogs-errno.h b/lib/core/ogs-errno.h index 991c9b4e4..678a0a6c9 100644 --- a/lib/core/ogs-errno.h +++ b/lib/core/ogs-errno.h @@ -36,6 +36,7 @@ typedef DWORD ogs_err_t; #define OGS_EACCES ERROR_ACCESS_DENIED #define OGS_EEXIST ERROR_ALREADY_EXISTS #define OGS_EEXIST_FILE ERROR_FILE_EXISTS +#define OGS_ECONNRESET WSAECONNRESET #define OGS_ETIMEDOUT WSAETIMEDOUT #define OGS_ECONNREFUSED WSAECONNREFUSED #define OGS_EBADF WSAEBADF @@ -54,6 +55,7 @@ typedef int ogs_err_t; #define OGS_EACCES EACCES #define OGS_EEXIST EEXIST #define OGS_EEXIST_FILE EEXIST +#define OGS_ECONNRESET ECONNRESET #define OGS_ETIMEDOUT ETIMEDOUT #define OGS_ECONNREFUSED ECONNREFUSED #define OGS_EBADF EBADF diff --git a/lib/core/ogs-kqueue.c b/lib/core/ogs-kqueue.c index 4660f1ec0..cb0efc137 100644 --- a/lib/core/ogs-kqueue.c +++ b/lib/core/ogs-kqueue.c @@ -219,7 +219,70 @@ static int kqueue_process(ogs_pollset_t *pollset, ogs_time_t timeout) short when = 0; if (context->event_list[i].flags & EV_ERROR) { - ogs_warn("kevent() error = 0x%x", context->event_list[i].flags); + switch (context->event_list[i].data) { + + /* Can occur on delete if we are not currently + * watching any events on this fd. That can + * happen when the fd was closed and another + * file was opened with that fd. */ + case ENOENT: + /* Can occur for reasons not fully understood + * on FreeBSD. */ + case EINVAL: + continue; +#if defined(__FreeBSD__) + /* + * This currently occurs if an FD is closed + * before the EV_DELETE makes it out via kevent(). + * The FreeBSD capabilities code sees the blank + * capability set and rejects the request to + * modify an event. + * + * To be strictly correct - when an FD is closed, + * all the registered events are also removed. + * Queuing EV_DELETE to a closed FD is wrong. + * The event(s) should just be deleted from + * the pending changelist. + */ + case ENOTCAPABLE: + continue; +#endif + + /* Can occur on a delete if the fd is closed. */ + case EBADF: + /* XXXX On NetBSD, we can also get EBADF if we + * try to add the write side of a pipe, but + * the read side has already been closed. + * Other BSDs call this situation 'EPIPE'. It + * would be good if we had a way to report + * this situation. */ + continue; + /* These two can occur on an add if the fd was one side + * of a pipe, and the other side was closed. */ + case EPERM: + case EPIPE: + /* Report read events, if we're listening for + * them, so that the user can learn about any + * add errors. (If the operation was a + * delete, then udata should be cleared.) */ + if (context->event_list[i].udata) { + /* The operation was an add: + * report the error as a read. */ + when |= OGS_POLLIN; + break; + } else { + /* The operation was a del: + * report nothing. */ + continue; + } + + /* Other errors shouldn't occur. */ + default: + ogs_error("kevent() error : flags = 0x%x, errno = %d", + context->event_list[i].flags, + (int)context->event_list[i].data); + return OGS_ERROR; + } } else if (context->event_list[i].filter == EVFILT_READ) { when |= OGS_POLLIN; } else if (context->event_list[i].filter == EVFILT_WRITE) { diff --git a/lib/core/ogs-poll.c b/lib/core/ogs-poll.c index e0a4de4d0..6eea1a2bd 100644 --- a/lib/core/ogs-poll.c +++ b/lib/core/ogs-poll.c @@ -43,9 +43,9 @@ ogs_pollset_t *ogs_pollset_create(unsigned int capacity) if (ogs_pollset_actions_initialized == false) { #if defined(HAVE_KQUEUE) - ogs_pollset_actions = ogs_kqueue_actions;; + ogs_pollset_actions = ogs_kqueue_actions; #elif defined(HAVE_EPOLL) - ogs_pollset_actions = ogs_epoll_actions;; + ogs_pollset_actions = ogs_epoll_actions; #else ogs_pollset_actions = ogs_select_actions; #endif diff --git a/lib/core/ogs-socket.c b/lib/core/ogs-socket.c index 726eb01c9..ccf044e0a 100644 --- a/lib/core/ogs-socket.c +++ b/lib/core/ogs-socket.c @@ -173,7 +173,6 @@ ogs_sock_t *ogs_sock_accept(ogs_sock_t *sock) new_fd = accept(sock->fd, &addr.sa, &addrlen); if (new_fd < 0) { - ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, "accept failed"); return NULL; } @@ -185,7 +184,7 @@ ogs_sock_t *ogs_sock_accept(ogs_sock_t *sock) memcpy(&new_sock->remote_addr, &addr, sizeof(new_sock->remote_addr)); - return new_sock;; + return new_sock; } ssize_t ogs_write(ogs_socket_t fd, const void *buf, size_t len) @@ -241,36 +240,20 @@ ssize_t ogs_sendto(ogs_socket_t fd, ssize_t ogs_recv(ogs_socket_t fd, void *buf, size_t len, int flags) { - ssize_t size; - ogs_assert(fd != INVALID_SOCKET); - - size = recv(fd, buf, len, flags); - if (size < 0) { - ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, - "recv(len:%d) failed", (int)len); - } - - return size; + return recv(fd, buf, len, flags); } ssize_t ogs_recvfrom(ogs_socket_t fd, void *buf, size_t len, int flags, ogs_sockaddr_t *from) { - ssize_t size; socklen_t addrlen = sizeof(struct sockaddr_storage); ogs_assert(fd != INVALID_SOCKET); ogs_assert(from); memset(from, 0, sizeof *from); - size = recvfrom(fd, buf, len, flags, &from->sa, &addrlen); - if (size < 0) { - ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, - "recvfrom(len:%d) failed", (int)len); - } - - return size; + return recvfrom(fd, buf, len, flags, &from->sa, &addrlen); } int ogs_closesocket(ogs_socket_t fd) @@ -330,15 +313,15 @@ int ogs_closeonexec(ogs_socket_t fd) int flags; ogs_assert(fd != INVALID_SOCKET); - flags = fcntl(fd, F_GETFL, NULL); + flags = fcntl(fd, F_GETFD, NULL); if (flags < 0) { - ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, "F_GETFL failed"); + ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, "F_GETFD failed"); return OGS_ERROR; } if (!(flags & FD_CLOEXEC)) { - rc = fcntl(fd, F_SETFL, (flags | FD_CLOEXEC)); + rc = fcntl(fd, F_SETFD, (flags | FD_CLOEXEC)); if (rc != OGS_OK) { - ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, "F_SETFL failed"); + ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, "F_SETFD failed"); return OGS_ERROR; } } diff --git a/lib/pfcp/xact.h b/lib/pfcp/xact.h index 916255878..aaf77ef61 100644 --- a/lib/pfcp/xact.h +++ b/lib/pfcp/xact.h @@ -64,7 +64,7 @@ typedef struct ogs_pfcp_xact_s { void *assoc_xact; /**< Associated GTP transaction */ ogs_pkbuf_t *gtpbuf; /**< GTP packet buffer */ - void *assoc_session; /**< Associated SBI session */ + void *assoc_stream; /**< Associated SBI session */ bool epc; /**< EPC or 5GC */ diff --git a/lib/sbi/client.c b/lib/sbi/client.c index f48ef2f46..e7a435093 100644 --- a/lib/sbi/client.c +++ b/lib/sbi/client.c @@ -100,7 +100,7 @@ ogs_sbi_client_t *ogs_sbi_client_add(ogs_sockaddr_t *addr) ogs_trace("ogs_sbi_client_add()"); - ogs_copyaddrinfo(&client->addr, addr); + ogs_copyaddrinfo(&client->node.addr, addr); ogs_list_init(&client->connection_list); @@ -143,8 +143,8 @@ void ogs_sbi_client_remove(ogs_sbi_client_t *client) ogs_assert(client->multi); curl_multi_cleanup(client->multi); - ogs_assert(client->addr); - ogs_freeaddrinfo(client->addr); + ogs_assert(client->node.addr); + ogs_freeaddrinfo(client->node.addr); ogs_pool_free(&client_pool, client); } @@ -156,8 +156,8 @@ ogs_sbi_client_t *ogs_sbi_client_find(ogs_sockaddr_t *addr) ogs_assert(addr); ogs_list_for_each(&ogs_sbi_self()->client_list, client) { - if (ogs_sockaddr_is_equal(client->addr, addr) == true && - OGS_PORT(client->addr) == OGS_PORT(addr)) + if (ogs_sockaddr_is_equal(client->node.addr, addr) == true && + OGS_PORT(client->node.addr) == OGS_PORT(addr)) break; } @@ -310,6 +310,11 @@ static connection_t *connection_add( curl_easy_setopt(conn->easy, CURLOPT_HTTPHEADER, conn->header_list); +#if 1 /* Use HTTP2 */ + curl_easy_setopt(conn->easy, + CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE); +#endif + if (ogs_hash_count(request->http.params)) { request->h.uri = add_params_to_uri(conn->easy, request->h.uri, request->http.params); @@ -509,7 +514,7 @@ static size_t header_cb(void *ptr, size_t size, size_t nmemb, void *data) conn = data; ogs_assert(conn); - if (strncmp(ptr, OGS_SBI_LOCATION, strlen(OGS_SBI_LOCATION)) == 0) { + if (ogs_strncasecmp(ptr, OGS_SBI_LOCATION, strlen(OGS_SBI_LOCATION)) == 0) { /* ptr : "Location: http://xxx/xxx/xxx\r\n" We need to truncate "Location" + ": " + "\r\n" in 'ptr' string */ int len = strlen(ptr) - strlen(OGS_SBI_LOCATION) - 2 - 2; diff --git a/lib/sbi/client.h b/lib/sbi/client.h index 940c8f242..2ba43a8df 100644 --- a/lib/sbi/client.h +++ b/lib/sbi/client.h @@ -41,9 +41,7 @@ extern "C" { typedef int (*ogs_sbi_client_cb_f)(ogs_sbi_response_t *response, void *data); typedef struct ogs_sbi_client_s { - ogs_lnode_t lnode; - - ogs_sockaddr_t *addr; + ogs_socknode_t node; struct { const char *key; diff --git a/lib/sbi/context.c b/lib/sbi/context.c index 8f268c367..5e03908da 100644 --- a/lib/sbi/context.c +++ b/lib/sbi/context.c @@ -684,18 +684,18 @@ void ogs_sbi_nf_instance_build_default( hostname = NULL; ogs_list_for_each(&ogs_sbi_self()->server_list, server) { - ogs_assert(server->addr); + ogs_assert(server->node.addr); /* First FQDN is selected */ if (!hostname) { - hostname = ogs_gethostname(server->addr); + hostname = ogs_gethostname(server->node.addr); if (hostname) continue; } if (nf_instance->num_of_ipv4 < OGS_SBI_MAX_NUM_OF_IP_ADDRESS) { ogs_sockaddr_t *addr = NULL; - ogs_copyaddrinfo(&addr, server->addr); + ogs_copyaddrinfo(&addr, server->node.addr); ogs_assert(addr); if (addr->ogs_sa_family == AF_INET) { @@ -740,11 +740,11 @@ ogs_sbi_nf_service_t *ogs_sbi_nf_service_build_default( hostname = NULL; ogs_list_for_each(&ogs_sbi_self()->server_list, server) { - ogs_assert(server->addr); + ogs_assert(server->node.addr); /* First FQDN is selected */ if (!hostname) { - hostname = ogs_gethostname(server->addr); + hostname = ogs_gethostname(server->node.addr); if (hostname) continue; } @@ -752,7 +752,7 @@ ogs_sbi_nf_service_t *ogs_sbi_nf_service_build_default( if (nf_service->num_of_addr < OGS_SBI_MAX_NUM_OF_IP_ADDRESS) { int port = 0; ogs_sockaddr_t *addr = NULL; - ogs_copyaddrinfo(&addr, server->addr); + ogs_copyaddrinfo(&addr, server->node.addr); ogs_assert(addr); port = OGS_PORT(addr); diff --git a/lib/sbi/context.h b/lib/sbi/context.h index b14292341..b97ecc8be 100644 --- a/lib/sbi/context.h +++ b/lib/sbi/context.h @@ -122,7 +122,7 @@ typedef struct ogs_sbi_xact_s { ogs_sbi_request_t *request; ogs_timer_t *t_response; - ogs_sbi_session_t *assoc_session; + ogs_sbi_stream_t *assoc_stream; uint8_t state; ogs_sbi_object_t *sbi_object; diff --git a/lib/sbi/conv.c b/lib/sbi/conv.c index 514dde046..815d31874 100644 --- a/lib/sbi/conv.c +++ b/lib/sbi/conv.c @@ -75,7 +75,7 @@ char *ogs_sbi_server_uri(ogs_sbi_server_t *server, ogs_sbi_header_t *h) if (server->tls.key && server->tls.pem) https = true; - return ogs_uridup(https, server->addr, h); + return ogs_uridup(https, server->node.addr, h); } char *ogs_sbi_client_uri(ogs_sbi_client_t *client, ogs_sbi_header_t *h) @@ -88,7 +88,7 @@ char *ogs_sbi_client_uri(ogs_sbi_client_t *client, ogs_sbi_header_t *h) if (client->tls.key && client->tls.pem) https = true; - return ogs_uridup(https, client->addr, h); + return ogs_uridup(https, client->node.addr, h); } /** diff --git a/lib/sbi/meson.build b/lib/sbi/meson.build index 2ed9e14cc..d10744d93 100644 --- a/lib/sbi/meson.build +++ b/lib/sbi/meson.build @@ -25,7 +25,10 @@ libsbi_sources = files(''' conv.c message.c + mhd-server.c + nghttp2-server.c server.c + client.c context.c @@ -40,8 +43,9 @@ libsbi_inc = include_directories('.') sbi_cc_flags = ['-DOGS_SBI_COMPILATION'] libgnutls_dep = cc.find_library('gnutls', required : true) +libnghttp2_dep = dependency('libnghttp2', version: '>=1.18.1') libmicrohttpd_dep = dependency('libmicrohttpd', version: '>=0.9.40') -libcurl_dep = dependency('libcurl') +libcurl_dep = dependency('libcurl', version: '>=7.52.1') libsbi = library('ogssbi', sources : libsbi_sources, @@ -53,6 +57,7 @@ libsbi = library('ogssbi', libapp_dep, libsbi_openapi_dep, libgnutls_dep, + libnghttp2_dep, libmicrohttpd_dep, libcurl_dep], install_rpath : libdir, @@ -66,5 +71,6 @@ libsbi_dep = declare_dependency( libapp_dep, libsbi_openapi_dep, libgnutls_dep, + libnghttp2_dep, libmicrohttpd_dep, libcurl_dep]) diff --git a/lib/sbi/message.c b/lib/sbi/message.c index 8fcdb3172..1b4062cb9 100644 --- a/lib/sbi/message.c +++ b/lib/sbi/message.c @@ -428,11 +428,12 @@ int ogs_sbi_parse_request( for (hi = ogs_hash_first(request->http.headers); hi; hi = ogs_hash_next(hi)) { - if (!strcmp(ogs_hash_this_key(hi), OGS_SBI_ACCEPT_ENCODING)) { + if (!ogs_strcasecmp(ogs_hash_this_key(hi), OGS_SBI_ACCEPT_ENCODING)) { message->http.content_encoding = ogs_hash_this_val(hi); - } else if (!strcmp(ogs_hash_this_key(hi), OGS_SBI_CONTENT_TYPE)) { + } else if (!ogs_strcasecmp( + ogs_hash_this_key(hi), OGS_SBI_CONTENT_TYPE)) { message->http.content_type = ogs_hash_this_val(hi); - } else if (!strcmp(ogs_hash_this_key(hi), OGS_SBI_ACCEPT)) { + } else if (!ogs_strcasecmp(ogs_hash_this_key(hi), OGS_SBI_ACCEPT)) { message->http.accept = ogs_hash_this_val(hi); } } @@ -462,9 +463,9 @@ int ogs_sbi_parse_response( for (hi = ogs_hash_first(response->http.headers); hi; hi = ogs_hash_next(hi)) { - if (!strcmp(ogs_hash_this_key(hi), OGS_SBI_CONTENT_TYPE)) { + if (!ogs_strcasecmp(ogs_hash_this_key(hi), OGS_SBI_CONTENT_TYPE)) { message->http.content_type = ogs_hash_this_val(hi); - } else if (!strcmp(ogs_hash_this_key(hi), OGS_SBI_LOCATION)) { + } else if (!ogs_strcasecmp(ogs_hash_this_key(hi), OGS_SBI_LOCATION)) { message->http.location = ogs_hash_this_val(hi); } } @@ -741,6 +742,11 @@ static int parse_json(ogs_sbi_message_t *message, if (!json) return OGS_OK; + if (!content_type) { + ogs_error("No Content-type"); + return OGS_ERROR; + } + ogs_log_print(OGS_LOG_TRACE, "%s", json); item = cJSON_Parse(json); if (!item) { diff --git a/lib/sbi/message.h b/lib/sbi/message.h index aecfd422f..1e08e2e4f 100644 --- a/lib/sbi/message.h +++ b/lib/sbi/message.h @@ -139,6 +139,7 @@ extern "C" { #define OGS_SBI_ACCEPT_ENCODING "Accept-Encoding" #define OGS_SBI_CONTENT_TYPE "Content-Type" #define OGS_SBI_LOCATION "Location" +#define OGS_SBI_EXPECT "Expect" #define OGS_SBI_APPLICATION_TYPE "application" #define OGS_SBI_APPLICATION_JSON_TYPE "json" #define OGS_SBI_APPLICATION_PROBLEM_TYPE "problem+json" @@ -273,12 +274,16 @@ typedef struct ogs_sbi_http_message_s { } ogs_sbi_http_message_t; typedef struct ogs_sbi_request_s { + ogs_lnode_t lnode; + ogs_sbi_header_t h; ogs_sbi_http_message_t http; /* Used in microhttpd */ bool suspended; - ogs_poll_t *poll; + struct { + ogs_poll_t *write; + } poll; } ogs_sbi_request_t; typedef struct ogs_sbi_response_s { diff --git a/lib/sbi/mhd-server.c b/lib/sbi/mhd-server.c new file mode 100644 index 000000000..810d169bd --- /dev/null +++ b/lib/sbi/mhd-server.c @@ -0,0 +1,554 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ogs-app.h" +#include "ogs-sbi.h" + +#include "microhttpd.h" + +#if MHD_VERSION >= 0x00097001 +typedef enum MHD_Result _MHD_Result; +#else +typedef int _MHD_Result; +#endif + +static void server_init(int num_of_session_pool); +static void server_final(void); + +static void server_start(ogs_sbi_server_t *server, + int (*cb)(ogs_sbi_request_t *request, void *data)); +static void server_stop(ogs_sbi_server_t *server); + +static void server_send_response( + ogs_sbi_stream_t *stream, ogs_sbi_response_t *response); + +static ogs_sbi_server_t *server_from_stream(ogs_sbi_stream_t *stream); + +const ogs_sbi_server_actions_t ogs_mhd_server_actions = { + server_init, + server_final, + + server_start, + server_stop, + + server_send_response, + server_from_stream, +}; + +static void run(short when, ogs_socket_t fd, void *data); +static void notify_connection(void *cls, + struct MHD_Connection *connection, + void **socket_context, + enum MHD_ConnectionNotificationCode toe); +static _MHD_Result access_handler( + void *cls, + struct MHD_Connection *connection, + const char *url, + const char *method, + const char *version, + const char *upload_data, + size_t *upload_data_size, + void **con_cls); +static void notify_completed( + void *cls, + struct MHD_Connection *connection, + void **con_cls, + enum MHD_RequestTerminationCode toe); + +static void session_timer_expired(void *data); + +typedef struct ogs_sbi_session_s { + ogs_lnode_t lnode; + + struct MHD_Connection *connection; + + ogs_sbi_request_t *request; + ogs_sbi_server_t *server; + + /* + * If the HTTP client closes the socket without sending an HTTP response, + * there is no way to detect the socket disconnection after MHD_run(). + * + * In this case, the poll instance cannot be removed, so the CPU load + * of the program using MHD is 100%. POLLIN (POLLRDHUP) is still created, + * poll's callback function is still called. + * + * To solve this problem, we've created the timer to check + * whether the user does not use the HTTP response. When the timer expires, + * an assertion occurs and terminates the program. + * + * To avoid the above timer expiration, the user of HTTP server(MHD) + * should send an HTTP response if an HTTP client(CURL) is requested. + */ + ogs_timer_t *timer; + + void *data; +} ogs_sbi_session_t; + +static OGS_POOL(session_pool, ogs_sbi_session_t); + +static void server_init(int num_of_session_pool) +{ + ogs_pool_init(&session_pool, num_of_session_pool); +} + +static void server_final(void) +{ + ogs_pool_final(&session_pool); +} + +static ogs_sbi_session_t *session_add(ogs_sbi_server_t *server, + ogs_sbi_request_t *request, struct MHD_Connection *connection) +{ + ogs_sbi_session_t *sbi_sess = NULL; + + ogs_assert(server); + ogs_assert(request); + ogs_assert(connection); + + ogs_pool_alloc(&session_pool, &sbi_sess); + ogs_assert(sbi_sess); + memset(sbi_sess, 0, sizeof(ogs_sbi_session_t)); + + sbi_sess->server = server; + sbi_sess->request = request; + sbi_sess->connection = connection; + + sbi_sess->timer = ogs_timer_add( + ogs_app()->timer_mgr, session_timer_expired, sbi_sess); + ogs_assert(sbi_sess->timer); + + /* If User does not send HTTP response within deadline, + * Open5GS will assert this program. */ + ogs_timer_start(sbi_sess->timer, + ogs_app()->time.message.sbi.connection_deadline); + + ogs_list_add(&server->session_list, sbi_sess); + + return sbi_sess; +} + +static void session_remove(ogs_sbi_session_t *sbi_sess) +{ + struct MHD_Connection *connection; + ogs_sbi_server_t *server = NULL; + + ogs_assert(sbi_sess); + server = sbi_sess->server; + ogs_assert(server); + + ogs_list_remove(&server->session_list, sbi_sess); + + ogs_assert(sbi_sess->timer); + ogs_timer_delete(sbi_sess->timer); + + connection = sbi_sess->connection; + ogs_assert(connection); + + MHD_resume_connection(connection); + + ogs_pool_free(&session_pool, sbi_sess); +} + +static void session_timer_expired(void *data) +{ + ogs_sbi_session_t *sbi_sess = data; + + ogs_assert(sbi_sess); + + ogs_fatal("An HTTP request was received, " + "but the HTTP response is missing."); + ogs_fatal("Please send the related pcap files for this case."); + + session_remove(sbi_sess); + + ogs_assert_if_reached(); +} + +static void session_remove_all(ogs_sbi_server_t *server) +{ + ogs_sbi_session_t *sbi_sess = NULL, *next_sbi_sess = NULL; + + ogs_assert(server); + + ogs_list_for_each_safe(&server->session_list, next_sbi_sess, sbi_sess) + session_remove(sbi_sess); +} + +static void server_start(ogs_sbi_server_t *server, + int (*cb)(ogs_sbi_request_t *request, void *data)) +{ + char buf[OGS_ADDRSTRLEN]; + ogs_sockaddr_t *addr = NULL; + char *hostname = NULL; + +#if MHD_VERSION >= 0x00095300 + unsigned int mhd_flags = MHD_USE_ERROR_LOG; +#else + unsigned int mhd_flags = MHD_USE_DEBUG; +#endif + const union MHD_DaemonInfo *mhd_info = NULL; +#define MAX_NUM_OF_MHD_OPTION_ITEM 8 + struct MHD_OptionItem mhd_ops[MAX_NUM_OF_MHD_OPTION_ITEM]; + int index = 0; + + ogs_assert(server); + +#if MHD_VERSION >= 0x00095300 + mhd_flags |= MHD_ALLOW_SUSPEND_RESUME; +#elif MHD_VERSION >= 0x00093400 + mhd_flags |= MHD_USE_SUSPEND_RESUME; +#else + mhd_flags |= MHD_USE_PIPE_FOR_SHUTDOWN; +#endif + + /* Setup callback function */ + server->cb = cb; + + mhd_ops[index].option = MHD_OPTION_NOTIFY_COMPLETED; + mhd_ops[index].value = (intptr_t)notify_completed; + mhd_ops[index].ptr_value = server; + index++; + + mhd_ops[index].option = MHD_OPTION_NOTIFY_CONNECTION; + mhd_ops[index].value = (intptr_t)¬ify_connection; + mhd_ops[index].ptr_value = NULL; + index++; + + addr = server->node.addr; + ogs_assert(addr); + if (addr->ogs_sa_family == AF_INET6) + mhd_flags |= MHD_USE_IPv6; + mhd_ops[index].option = MHD_OPTION_SOCK_ADDR; + mhd_ops[index].value = 0; + mhd_ops[index].ptr_value = (void *)&addr->sa; + index++; + + mhd_ops[index].option = MHD_OPTION_END; + mhd_ops[index].value = 0; + mhd_ops[index].ptr_value = NULL; + index++; + + server->mhd = MHD_start_daemon( + mhd_flags, + 0, + NULL, NULL, + access_handler, server, + MHD_OPTION_ARRAY, mhd_ops, + MHD_OPTION_END); + if (!server->mhd) { + ogs_error("Cannot start SBI server"); + return; + } + + /* Setup poll for server listening socket */ + mhd_info = MHD_get_daemon_info(server->mhd, MHD_DAEMON_INFO_LISTEN_FD); + ogs_assert(mhd_info); + + server->node.poll = ogs_pollset_add(ogs_app()->pollset, + OGS_POLLIN, mhd_info->listen_fd, run, server->mhd); + ogs_assert(server->node.poll); + + hostname = ogs_gethostname(addr); + if (hostname) + ogs_info("mhd_server() [%s]:%d", hostname, OGS_PORT(addr)); + else + ogs_info("mhd_server() [%s]:%d", OGS_ADDR(addr, buf), OGS_PORT(addr)); +} + +static void server_stop(ogs_sbi_server_t *server) +{ + ogs_assert(server); + + if (server->node.poll) + ogs_pollset_remove(server->node.poll); + + session_remove_all(server); + + if (server->mhd) { + MHD_stop_daemon(server->mhd); + server->mhd = NULL; + } +} + +static void server_send_response( + ogs_sbi_stream_t *stream, ogs_sbi_response_t *response) +{ + int ret; + int status; + + struct MHD_Connection *connection = NULL; + struct MHD_Response *mhd_response; + struct MHD_Daemon *mhd_daemon = NULL; + const union MHD_ConnectionInfo *mhd_info = NULL; + MHD_socket mhd_socket = INVALID_SOCKET; + + ogs_hash_index_t *hi; + ogs_sbi_request_t *request = NULL; + ogs_sbi_session_t *sbi_sess = NULL; + + sbi_sess = (ogs_sbi_session_t *)stream; + ogs_assert(sbi_sess); + ogs_assert(response); + + connection = sbi_sess->connection; + ogs_assert(connection); + + mhd_info = MHD_get_connection_info( + connection, MHD_CONNECTION_INFO_DAEMON); + ogs_assert(mhd_info); + mhd_daemon = mhd_info->daemon; + ogs_assert(mhd_daemon); + + mhd_info = MHD_get_connection_info( + connection, MHD_CONNECTION_INFO_CONNECTION_FD); + ogs_assert(mhd_info); + mhd_socket = mhd_info->connect_fd; + ogs_assert(mhd_socket != INVALID_SOCKET); + + if (response->http.content) { + mhd_response = MHD_create_response_from_buffer( + response->http.content_length, response->http.content, + MHD_RESPMEM_PERSISTENT); + ogs_assert(mhd_response); + } else { + mhd_response = MHD_create_response_from_buffer( + 0, NULL, MHD_RESPMEM_PERSISTENT); + ogs_assert(mhd_response); + } + + for (hi = ogs_hash_first(response->http.headers); + hi; hi = ogs_hash_next(hi)) { + const char *key = ogs_hash_this_key(hi); + char *val = ogs_hash_this_val(hi); + MHD_add_response_header(mhd_response, key, val); + } + + status = response->status; + request = sbi_sess->request; + ogs_assert(request); + + ogs_sbi_response_free(response); + session_remove(sbi_sess); + + request->poll.write = ogs_pollset_add(ogs_app()->pollset, + OGS_POLLOUT, mhd_socket, run, mhd_daemon); + ogs_assert(request->poll.write); + + ret = MHD_queue_response(connection, status, mhd_response); + if (ret != MHD_YES) { + ogs_fatal("MHD_queue_response_error [%d]", ret); + ogs_assert_if_reached(); + } + MHD_destroy_response(mhd_response); +} + +static void run(short when, ogs_socket_t fd, void *data) +{ + struct MHD_Daemon *mhd_daemon = data; + + ogs_assert(mhd_daemon); + MHD_run(mhd_daemon); +} + +static void notify_connection(void *cls, + struct MHD_Connection *connection, + void **socket_context, + enum MHD_ConnectionNotificationCode toe) +{ + struct MHD_Daemon *mhd_daemon = NULL; + MHD_socket mhd_socket = INVALID_SOCKET; + + const union MHD_ConnectionInfo *mhd_info = NULL; + struct { + ogs_poll_t *read; + } poll; + + switch (toe) { + case MHD_CONNECTION_NOTIFY_STARTED: + mhd_info = MHD_get_connection_info( + connection, MHD_CONNECTION_INFO_DAEMON); + ogs_assert(mhd_info); + mhd_daemon = mhd_info->daemon; + ogs_assert(mhd_daemon); + + mhd_info = MHD_get_connection_info( + connection, MHD_CONNECTION_INFO_CONNECTION_FD); + ogs_assert(mhd_info); + mhd_socket = mhd_info->connect_fd; + ogs_assert(mhd_socket != INVALID_SOCKET); + + poll.read = ogs_pollset_add(ogs_app()->pollset, + OGS_POLLIN, mhd_socket, run, mhd_daemon); + ogs_assert(poll.read); + *socket_context = poll.read; + break; + case MHD_CONNECTION_NOTIFY_CLOSED: + poll.read = ogs_pollset_cycle(ogs_app()->pollset, *socket_context); + if (poll.read) + ogs_pollset_remove(poll.read); + break; + } +} + +static int get_values(ogs_hash_t *hash, + enum MHD_ValueKind kind, const char *key, const char *value) +{ + ogs_assert(hash); + + if (!key || !value) + return MHD_YES; // Ignore connection value if invalid! + + ogs_sbi_header_set(hash, key, value); + + return MHD_YES; +} + +static _MHD_Result access_handler( + void *cls, + struct MHD_Connection *connection, + const char *url, + const char *method, + const char *version, + const char *upload_data, + size_t *upload_data_size, + void **con_cls) +{ + ogs_sbi_server_t *server = NULL; + ogs_sbi_request_t *request = NULL; + ogs_sbi_session_t *sbi_sess = NULL; + + server = cls; + ogs_assert(server); + + request = *con_cls; + + if (request && request->suspended) { + ogs_error("Suspended Request"); + return MHD_YES; + } + + if (!request) { + request = ogs_sbi_request_new(); + ogs_assert(request); + *con_cls = request; + + ogs_assert(request->http.params); + MHD_get_connection_values(connection, MHD_GET_ARGUMENT_KIND, + (MHD_KeyValueIterator)get_values, request->http.params); + + ogs_assert(request->http.headers); + MHD_get_connection_values(connection, MHD_HEADER_KIND, + (MHD_KeyValueIterator)get_values, request->http.headers); + + request->h.method = ogs_strdup(method); + request->h.uri = ogs_strdup(url); + + if (ogs_sbi_header_get(request->http.headers, "Content-Length") || + ogs_sbi_header_get(request->http.headers, "Transfer-Encoding")) { + + // FIXME : check if POST_DATA is on MHD_POSTDATA_KIND + + return MHD_YES; + } + + goto suspend; + } + + if (*upload_data_size != 0) { + size_t offset = 0; + + if (request->http.content == NULL) { + request->http.content_length = *upload_data_size; + request->http.content = + (char*)ogs_malloc(request->http.content_length + 1); + ogs_assert(request->http.content); + } else { + offset = request->http.content_length; + if ((request->http.content_length + + *upload_data_size) > OGS_HUGE_LEN) { + ogs_error("Overflow : Content-Length[%d], upload_data_size[%d]", + (int)request->http.content_length, + (int)*upload_data_size); + *upload_data_size = 0; + return MHD_YES; + } + request->http.content_length += *upload_data_size; + request->http.content = (char *)ogs_realloc( + request->http.content, request->http.content_length + 1); + ogs_assert(request->http.content); + } + + memcpy(request->http.content + offset, upload_data, *upload_data_size); + request->http.content[request->http.content_length] = '\0'; + *upload_data_size = 0; + + return MHD_YES; + } + +suspend: + MHD_suspend_connection(connection); + request->suspended = true; + + sbi_sess = session_add(server, request, connection); + ogs_assert(sbi_sess); + + if (server->cb) { + if (server->cb(request, sbi_sess) != OGS_OK) { + ogs_warn("server callback error"); + ogs_sbi_server_send_error((ogs_sbi_stream_t *)sbi_sess, + OGS_SBI_HTTP_STATUS_INTERNAL_SERVER_ERROR, NULL, + "server callback error", NULL); + + return MHD_YES; + } + } else { + ogs_fatal("server callback is not registered"); + ogs_assert_if_reached(); + } + + return MHD_YES; +} + +static void notify_completed( + void *cls, + struct MHD_Connection *connection, + void **con_cls, + enum MHD_RequestTerminationCode toe) +{ + ogs_sbi_request_t *request = *con_cls; + ogs_poll_t *poll = NULL; + + ogs_assert(request); + poll = ogs_pollset_cycle(ogs_app()->pollset, request->poll.write); + if (poll) + ogs_pollset_remove(poll); + + ogs_sbi_request_free(request); +} + +static ogs_sbi_server_t *server_from_stream(ogs_sbi_stream_t *stream) +{ + ogs_sbi_session_t *sbi_sess = (ogs_sbi_session_t *)stream; + + ogs_assert(sbi_sess); + ogs_assert(sbi_sess->server); + + return sbi_sess->server; +} diff --git a/lib/sbi/nghttp2-server.c b/lib/sbi/nghttp2-server.c new file mode 100644 index 000000000..de29bd128 --- /dev/null +++ b/lib/sbi/nghttp2-server.c @@ -0,0 +1,1232 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ogs-app.h" +#include "ogs-sbi.h" +#include "yuarel.h" + +#include +#include + +#define USE_SEND_DATA_WITH_NO_COPY 1 + +static void server_init(int num_of_stream_pool); +static void server_final(void); + +static void server_start(ogs_sbi_server_t *server, + int (*cb)(ogs_sbi_request_t *request, void *data)); +static void server_stop(ogs_sbi_server_t *server); + +static void server_send_response( + ogs_sbi_stream_t *stream, ogs_sbi_response_t *response); + +static ogs_sbi_server_t *server_from_stream(ogs_sbi_stream_t *data); + +const ogs_sbi_server_actions_t ogs_nghttp2_server_actions = { + server_init, + server_final, + + server_start, + server_stop, + + server_send_response, + server_from_stream, +}; + +struct h2_settings { + uint32_t max_concurrent_streams; + bool enable_push; +}; + +typedef struct ogs_sbi_session_s { + ogs_lnode_t lnode; + + ogs_sock_t *sock; + ogs_sockaddr_t *addr; + struct { + ogs_poll_t *read; + ogs_poll_t *write; + } poll; + + nghttp2_session *session; + ogs_list_t write_queue; + + ogs_sbi_server_t *server; + ogs_list_t stream_list; + int32_t last_stream_id; + + struct h2_settings settings; +} ogs_sbi_session_t; + +typedef struct ogs_sbi_stream_s { + ogs_lnode_t lnode; + + int32_t stream_id; + ogs_sbi_request_t *request; + + ogs_sbi_session_t *session; +} ogs_sbi_stream_t; + +static void session_remove(ogs_sbi_session_t *sbi_sess); +static void session_remove_all(ogs_sbi_server_t *server); + +static void stream_remove(ogs_sbi_stream_t *stream); + +static void accept_handler(short when, ogs_socket_t fd, void *data); +static void recv_handler(short when, ogs_socket_t fd, void *data); + +static int session_set_callbacks(ogs_sbi_session_t *sbi_sess); +static int session_send_preface(ogs_sbi_session_t *sbi_sess); +static int session_send(ogs_sbi_session_t *sbi_sess); +static void session_write_to_buffer( + ogs_sbi_session_t *sbi_sess, ogs_pkbuf_t *pkbuf); + +static OGS_POOL(session_pool, ogs_sbi_session_t); +static OGS_POOL(stream_pool, ogs_sbi_stream_t); + +static void server_init(int num_of_stream_pool) +{ + ogs_pool_init(&session_pool, num_of_stream_pool); + ogs_pool_init(&stream_pool, num_of_stream_pool); +} + +static void server_final(void) +{ + ogs_pool_final(&stream_pool); + ogs_pool_final(&session_pool); +} + +static void server_start(ogs_sbi_server_t *server, + int (*cb)(ogs_sbi_request_t *request, void *data)) +{ + char buf[OGS_ADDRSTRLEN]; + ogs_sock_t *sock = NULL; + ogs_sockaddr_t *addr = NULL; + char *hostname = NULL; + + addr = server->node.addr; + ogs_assert(addr); + + sock = ogs_tcp_server(&server->node); + if (!sock) { + ogs_error("Cannot start SBI server"); + return; + } + + /* Setup callback function */ + server->cb = cb; + + /* Setup poll for server listening socket */ + server->node.poll = ogs_pollset_add(ogs_app()->pollset, + OGS_POLLIN, sock->fd, accept_handler, server); + ogs_assert(server->node.poll); + + hostname = ogs_gethostname(addr); + if (hostname) + ogs_info("nghttp2_server() [%s]:%d", hostname, OGS_PORT(addr)); + else + ogs_info("nghttp2_server() [%s]:%d", + OGS_ADDR(addr, buf), OGS_PORT(addr)); +} + +static void server_stop(ogs_sbi_server_t *server) +{ + ogs_assert(server); + + if (server->node.poll) + ogs_pollset_remove(server->node.poll); + + if (server->node.sock) + ogs_sock_destroy(server->node.sock); + + session_remove_all(server); +} + +static void add_header(nghttp2_nv *nv, const char *key, const char *value) +{ + nv->name = (uint8_t *)key; + nv->namelen = strlen(key); + nv->value = (uint8_t *)value; + nv->valuelen = strlen(value); + nv->flags = NGHTTP2_NV_FLAG_NONE; +} + +static char status_string[600][4] = { + "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", + "100", "101", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", + "200", "201", "202", "203", "204", "205", "206", "", "", "", "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", + "300", "301", "302", "303", "304", "305", "306", "307", "308", "", "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", + "400", "401", "402", "403", "404", "405", "406", "407", "408", "409", + "410", "411", "412", "413", "414", "415", "416", "417", "", "", + "", "421", "", "", "", "", "426", "", "428", "429", "", "431", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", "", "451", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", + "500", "501", "502", "503", "504", "505", "", "", "", "", "", "511", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" +}; + +#define DATE_STRLEN 128 +static char *get_date_string(char *date) +{ + static const char *const days[] = { + "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" + }; + static const char *const mons[] = { + "Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" + }; + + ogs_assert(date); + + struct tm tm; + ogs_gmtime(ogs_time_sec(ogs_time_now()), &tm); + + ogs_snprintf(date, DATE_STRLEN, "%3s, %02u %3s %04u %02u:%02u:%02u GMT", + days[tm.tm_wday % 7], + (unsigned int)tm.tm_mday, + mons[tm.tm_mon % 12], + (unsigned int)(1900 + tm.tm_year), + (unsigned int)tm.tm_hour, + (unsigned int)tm.tm_min, + (unsigned int)tm.tm_sec); + + return date; +} + +static ssize_t response_read_callback(nghttp2_session *session, + int32_t stream_id, + uint8_t *buf, size_t length, + uint32_t *data_flags, + nghttp2_data_source *source, + void *user_data) +{ +#if USE_SEND_DATA_WITH_NO_COPY + int rv; +#endif + + ogs_sbi_response_t *response = NULL; + ogs_sbi_stream_t *stream = NULL; + + ogs_assert(session); + + stream = nghttp2_session_get_stream_user_data(session, stream_id); + if (!stream) { + ogs_error("no stream [%d]", stream_id); + return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE; + } + + ogs_assert(source); + response = source->ptr; + ogs_assert(response); + + ogs_assert(response->http.content); + ogs_assert(response->http.content_length); + +#if USE_SEND_DATA_WITH_NO_COPY + *data_flags |= NGHTTP2_DATA_FLAG_NO_COPY; +#else + memcpy(buf, response->http.content, response->http.content_length); +#endif + + *data_flags |= NGHTTP2_DATA_FLAG_EOF; + +#if USE_SEND_DATA_WITH_NO_COPY + rv = nghttp2_session_get_stream_remote_close(session, stream_id); + if (rv == 0) { + ogs_warn("nghttp2_session_get_stream_remote_close() failed"); + nghttp2_submit_rst_stream( + session, NGHTTP2_FLAG_NONE, stream_id, NGHTTP2_NO_ERROR); + } else if (rv != 1) { + ogs_error("nghttp2_session_get_stream_remote_close() failed[%d]", rv); + } +#endif + + return response->http.content_length; +} + +static void server_send_response( + ogs_sbi_stream_t *stream, ogs_sbi_response_t *response) +{ + ogs_sbi_session_t *sbi_sess = NULL; + ogs_hash_index_t *hi; + nghttp2_nv *nva; + size_t nvlen; + int i, rv; + char datebuf[DATE_STRLEN]; + char srv_version[128]; + char clen[128]; + + ogs_assert(stream); + sbi_sess = stream->session; + ogs_assert(sbi_sess); + ogs_assert(sbi_sess->session); + ogs_assert(response); + + nvlen = 3; /* :status && server && date */ + + for (hi = ogs_hash_first(response->http.headers); + hi; hi = ogs_hash_next(hi)) + nvlen++; + + if (response->http.content && response->http.content_length) + nvlen++; + + nva = ogs_calloc(nvlen, sizeof(nghttp2_nv)); + ogs_assert(nva); + + i = 0; + + ogs_assert(response->status < 600); + ogs_assert(strlen(status_string[response->status]) == 3); + add_header(&nva[i++], ":status", status_string[response->status]); + + ogs_snprintf(srv_version, sizeof(srv_version), + "Open5GS %s", ogs_app()->version ? ogs_app()->version : "TEST"); + add_header(&nva[i++], "server", srv_version); + add_header(&nva[i++], "date", get_date_string(datebuf)); + + if (response->http.content && response->http.content_length) { + ogs_snprintf(clen, sizeof(clen), + "%d", (int)response->http.content_length); + add_header(&nva[i++], "content-length", clen); + } + + for (hi = ogs_hash_first(response->http.headers); + hi; hi = ogs_hash_next(hi)) { + add_header(&nva[i++], ogs_hash_this_key(hi), ogs_hash_this_val(hi)); + } + + if (response->http.content && response->http.content_length) { + nghttp2_data_provider data_prd; + + data_prd.source.ptr = response; + data_prd.read_callback = response_read_callback; + + rv = nghttp2_submit_response(sbi_sess->session, + stream->stream_id, nva, nvlen, &data_prd); + } else { + rv = nghttp2_submit_response(sbi_sess->session, + stream->stream_id, nva, nvlen, NULL); + } + + if (rv != OGS_OK) { + ogs_error("nghttp2_submit_response(%d) failed (%d:%s)", + (int)response->http.content_length, + rv, nghttp2_strerror(rv)); + nghttp2_submit_rst_stream( + sbi_sess->session, NGHTTP2_FLAG_NONE, stream->stream_id, rv); + } + + if (session_send(sbi_sess) != OGS_OK) { + ogs_error("session_send() failed"); + session_remove(sbi_sess); + } + + ogs_sbi_response_free(response); + ogs_free(nva); +} + +static ogs_sbi_server_t *server_from_stream(ogs_sbi_stream_t *stream) +{ + ogs_sbi_session_t *sbi_sess = NULL; + + ogs_assert(stream); + sbi_sess = stream->session; + ogs_assert(sbi_sess); + ogs_assert(sbi_sess->server); + + return sbi_sess->server; +} + +static ogs_sbi_stream_t *stream_add( + ogs_sbi_session_t *sbi_sess, int32_t stream_id) +{ + ogs_sbi_stream_t *stream = NULL; + + ogs_assert(sbi_sess); + + ogs_pool_alloc(&stream_pool, &stream); + ogs_assert(stream); + memset(stream, 0, sizeof(ogs_sbi_stream_t)); + + stream->request = ogs_sbi_request_new(); + ogs_assert(stream->request); + + stream->stream_id = stream_id; + sbi_sess->last_stream_id = stream_id; + + stream->session = sbi_sess; + + return stream; +} + +static void stream_remove(ogs_sbi_stream_t *stream) +{ + ogs_sbi_session_t *sbi_sess = NULL; + + ogs_assert(stream); + sbi_sess = stream->session; + ogs_assert(sbi_sess); + + ogs_list_remove(&sbi_sess->stream_list, stream); + + ogs_assert(stream->request); + ogs_sbi_request_free(stream->request); + + ogs_pool_free(&stream_pool, stream); +} + +static void stream_remove_all(ogs_sbi_session_t *sbi_sess) +{ + ogs_sbi_stream_t *stream = NULL, *next_stream = NULL; + + ogs_assert(sbi_sess); + + ogs_list_for_each_safe(&sbi_sess->stream_list, next_stream, stream) + stream_remove(stream); +} + +static ogs_sbi_session_t *session_add( + ogs_sbi_server_t *server, ogs_sock_t *sock) +{ + ogs_sbi_session_t *sbi_sess = NULL; + + ogs_assert(server); + ogs_assert(sock); + + ogs_pool_alloc(&session_pool, &sbi_sess); + ogs_assert(sbi_sess); + memset(sbi_sess, 0, sizeof(ogs_sbi_session_t)); + + sbi_sess->server = server; + sbi_sess->sock = sock; + + sbi_sess->addr = ogs_calloc(1, sizeof(ogs_sockaddr_t)); + ogs_assert(sbi_sess->addr); + memcpy(sbi_sess->addr, &sock->remote_addr, sizeof(ogs_sockaddr_t)); + + ogs_list_add(&server->session_list, sbi_sess); + + return sbi_sess; +} + +static void session_remove(ogs_sbi_session_t *sbi_sess) +{ + ogs_sbi_server_t *server = NULL; + ogs_poll_t *poll = NULL; + ogs_pkbuf_t *pkbuf = NULL, *next_pkbuf = NULL; + + ogs_assert(sbi_sess); + server = sbi_sess->server; + ogs_assert(server); + + ogs_list_remove(&server->session_list, sbi_sess); + + stream_remove_all(sbi_sess); + + poll = ogs_pollset_cycle(ogs_app()->pollset, sbi_sess->poll.read); + ogs_assert(poll); + ogs_pollset_remove(poll); + + poll = ogs_pollset_cycle(ogs_app()->pollset, sbi_sess->poll.write); + if (poll) + ogs_pollset_remove(poll); + + ogs_list_for_each_safe(&sbi_sess->write_queue, next_pkbuf, pkbuf) + ogs_pkbuf_free(pkbuf); + + ogs_assert(sbi_sess->addr); + ogs_free(sbi_sess->addr); + + ogs_assert(sbi_sess->sock); + ogs_sock_destroy(sbi_sess->sock); + + ogs_pool_free(&session_pool, sbi_sess); +} + +static void session_remove_all(ogs_sbi_server_t *server) +{ + ogs_sbi_session_t *sbi_sess = NULL, *next_sbi_sess = NULL; + + ogs_assert(server); + + ogs_list_for_each_safe(&server->session_list, next_sbi_sess, sbi_sess) + session_remove(sbi_sess); +} + +static void accept_handler(short when, ogs_socket_t fd, void *data) +{ + ogs_sbi_server_t *server = data; + ogs_sbi_session_t *sbi_sess = NULL; + ogs_sock_t *sock = NULL; + ogs_sock_t *new = NULL; + + int on; + + ogs_assert(data); + ogs_assert(fd != INVALID_SOCKET); + + sock = server->node.sock; + + new = ogs_sock_accept(sock); + if (!new) { + ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, "accept() failed"); + return; + } + ogs_assert(new->fd != INVALID_SOCKET); + + on = 1; + if (setsockopt(new->fd, IPPROTO_TCP, TCP_NODELAY, &on, sizeof(on)) != 0) { + ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, + "setsockopt() for SCTP_NODELAY failed"); + ogs_sock_destroy(new); + return; + } + + sbi_sess = session_add(server, new); + ogs_assert(sbi_sess); + + sbi_sess->poll.read = ogs_pollset_add(ogs_app()->pollset, + OGS_POLLIN, new->fd, recv_handler, sbi_sess); + ogs_assert(sbi_sess->poll.read); + + if (session_set_callbacks(sbi_sess) != OGS_OK || + session_send_preface(sbi_sess) != OGS_OK) { + ogs_error("session_add() failed"); + session_remove(sbi_sess); + } +} + +static void recv_handler(short when, ogs_socket_t fd, void *data) +{ + char buf[OGS_ADDRSTRLEN]; + ogs_sockaddr_t *addr = NULL; + + ogs_sbi_session_t *sbi_sess = data; + ogs_pkbuf_t *pkbuf = NULL; + ssize_t readlen; + int n; + + ogs_assert(sbi_sess); + ogs_assert(fd != INVALID_SOCKET); + addr = sbi_sess->addr; + ogs_assert(addr); + + pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); + ogs_assert(pkbuf); + + n = ogs_recv(fd, pkbuf->data, OGS_MAX_SDU_LEN, 0); + if (n > 0) { + ogs_pkbuf_put(pkbuf, n); + + ogs_assert(sbi_sess->session); + readlen = nghttp2_session_mem_recv( + sbi_sess->session, pkbuf->data, pkbuf->len); + if (readlen < 0) { + ogs_error("nghttp2_session_mem_recv() failed (%d:%s)", + (int)readlen, nghttp2_strerror((int)readlen)); + session_remove(sbi_sess); + } + } else { + if (n < 0) { + if (errno != OGS_ECONNRESET) + ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, + "lost connection [%s]:%d", + OGS_ADDR(addr, buf), OGS_PORT(addr)); + } else if (n == 0) { + ogs_debug("connection closed [%s]:%d", + OGS_ADDR(addr, buf), OGS_PORT(addr)); + } + + session_remove(sbi_sess); + } + + ogs_pkbuf_free(pkbuf); +} + +static int on_frame_recv(nghttp2_session *session, + const nghttp2_frame *frame, void *user_data); +static int on_stream_close(nghttp2_session *session, int32_t stream_id, + uint32_t error_code, void *user_data); +static int on_header(nghttp2_session *session, + const nghttp2_frame *frame, + nghttp2_rcbuf *name, nghttp2_rcbuf *value, + uint8_t flags, void *user_data); +static int on_data_chunk_recv(nghttp2_session *session, uint8_t flags, + int32_t stream_id, const uint8_t *data, + size_t len, void *user_data); +static int error_callback(nghttp2_session *session, + const char *msg, size_t len, void *user_data); +static int on_invalid_frame_recv(nghttp2_session *session, + const nghttp2_frame *frame, + int error_code, void *user_data); +static int on_invalid_header(nghttp2_session *session, + const nghttp2_frame *frame, + const uint8_t *name, size_t namelen, + const uint8_t *value, size_t valuelen, + uint8_t flags, void *user_data); +static int on_begin_frame(nghttp2_session *session, + const nghttp2_frame_hd *hd, void *user_data); +static int on_begin_headers(nghttp2_session *session, + const nghttp2_frame *frame, + void *user_data); +#if USE_SEND_DATA_WITH_NO_COPY +static int on_send_data(nghttp2_session *session, nghttp2_frame *frame, + const uint8_t *framehd, size_t length, + nghttp2_data_source *source, void *user_data); +#else +static ssize_t send_callback(nghttp2_session *session, const uint8_t *data, + size_t length, int flags, void *user_data); +#endif + +static int session_set_callbacks(ogs_sbi_session_t *sbi_sess) +{ + int rv; + nghttp2_session_callbacks *callbacks = NULL; + + ogs_assert(sbi_sess); + + rv = nghttp2_session_callbacks_new(&callbacks); + if (rv != 0) { + ogs_error("nghttp2_session_callbacks_new() failed (%d:%s)", + rv, nghttp2_strerror(rv)); + return OGS_ERROR; + } + + nghttp2_session_callbacks_set_on_frame_recv_callback( + callbacks, on_frame_recv); + + nghttp2_session_callbacks_set_on_stream_close_callback( + callbacks, on_stream_close); + + nghttp2_session_callbacks_set_on_header_callback2(callbacks, on_header); + + nghttp2_session_callbacks_set_on_data_chunk_recv_callback( + callbacks, on_data_chunk_recv); + + nghttp2_session_callbacks_set_error_callback(callbacks, error_callback); + + nghttp2_session_callbacks_set_on_invalid_frame_recv_callback( + callbacks, on_invalid_frame_recv); + + nghttp2_session_callbacks_set_on_invalid_header_callback( + callbacks, on_invalid_header); + + nghttp2_session_callbacks_set_on_begin_frame_callback( + callbacks, on_begin_frame); + + nghttp2_session_callbacks_set_on_begin_headers_callback( + callbacks, on_begin_headers); + +#if USE_SEND_DATA_WITH_NO_COPY + nghttp2_session_callbacks_set_send_data_callback(callbacks, on_send_data); +#else + nghttp2_session_callbacks_set_send_callback(callbacks, send_callback); +#endif + + rv = nghttp2_session_server_new(&sbi_sess->session, callbacks, sbi_sess); + if (rv != 0) { + ogs_error("nghttp2_session_callbacks_new() failed (%d:%s)", + rv, nghttp2_strerror(rv)); + return OGS_ERROR; + } + + nghttp2_session_callbacks_del(callbacks); + + return OGS_OK; +} + +static int on_frame_recv(nghttp2_session *session, + const nghttp2_frame *frame, void *user_data) +{ + int rv; + ogs_sbi_session_t *sbi_sess = user_data; + + ogs_sbi_server_t *server = NULL; + ogs_sbi_stream_t *stream = NULL; + ogs_sbi_request_t *request = NULL; + + ogs_assert(sbi_sess); + server = sbi_sess->server; + ogs_assert(server); + ogs_assert(server->cb); + + ogs_assert(session); + ogs_assert(frame); + + stream = nghttp2_session_get_stream_user_data(session, frame->hd.stream_id); + if (!stream) { + if (frame->hd.type == NGHTTP2_SETTINGS) { + sbi_sess->settings.max_concurrent_streams = + nghttp2_session_get_remote_settings( + session, NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS); + sbi_sess->settings.enable_push = + nghttp2_session_get_remote_settings( + session, NGHTTP2_SETTINGS_ENABLE_PUSH); + ogs_debug("MAX_CONCURRENT_STREAMS = %d", + sbi_sess->settings.max_concurrent_streams); + ogs_debug("ENABLE_PUSH = %s", + sbi_sess->settings.enable_push ? "TRUE" : "false"); + + } else if (frame->hd.type == NGHTTP2_GOAWAY) { + rv = nghttp2_submit_goaway( + session, NGHTTP2_FLAG_NONE, sbi_sess->last_stream_id, + NGHTTP2_NO_ERROR, NULL, 0); + if (rv != 0) { + ogs_error("nghttp2_submit_goaway() failed (%d:%s)", + rv, nghttp2_strerror(rv)); + return OGS_ERROR; + } + + session_send(sbi_sess); + } + return 0; + } + + request = stream->request; + ogs_assert(request); + + switch (frame->hd.type) { + case NGHTTP2_HEADERS: + if (frame->headers.cat == NGHTTP2_HCAT_REQUEST) { + const char *expect100 = + ogs_sbi_header_get(request->http.headers, OGS_SBI_EXPECT); + if (expect100 && ogs_strcasecmp(expect100, "100-continue") == 0) { + nghttp2_nv nva; + + add_header(&nva, ":status", status_string[100]); + rv = nghttp2_submit_headers(session, NGHTTP2_FLAG_NONE, + stream->stream_id, NULL, &nva, 1, NULL); + if (rv != 0) { + ogs_error("nghttp2_submit_headers() failed (%d:%s)", + rv, nghttp2_strerror(rv)); + nghttp2_submit_rst_stream( + session, NGHTTP2_FLAG_NONE, stream->stream_id, rv); + return 0; + } + } + } + /* fallthrough */ + OGS_GNUC_FALLTHROUGH; + + case NGHTTP2_DATA: + /* HEADERS or DATA frame with +END_STREAM flag */ + if (frame->hd.flags & NGHTTP2_FLAG_END_STREAM) { + + if (server->cb(request, stream) != OGS_OK) { + ogs_warn("server callback error"); + ogs_sbi_server_send_error(stream, + OGS_SBI_HTTP_STATUS_INTERNAL_SERVER_ERROR, NULL, + "server callback error", NULL); + + return 0; + } + break; + } + default: + break; + } + + return 0; +} + +static int on_stream_close(nghttp2_session *session, int32_t stream_id, + uint32_t error_code, void *user_data) +{ + ogs_sbi_stream_t *stream = NULL; + + ogs_assert(session); + + stream = nghttp2_session_get_stream_user_data(session, stream_id); + if (!stream) { + ogs_error("no stream [%d]", stream_id); + return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE; + } + + if (error_code) { + ogs_error("on_stream_close_callback() failed (%d:%s)", + error_code, nghttp2_strerror(error_code)); + nghttp2_submit_rst_stream( + session, NGHTTP2_FLAG_NONE, stream_id, error_code); + } + + stream_remove(stream); + return 0; +} + +static int on_header(nghttp2_session *session, const nghttp2_frame *frame, + nghttp2_rcbuf *name, nghttp2_rcbuf *value, + uint8_t flags, void *user_data) +{ + ogs_sbi_session_t *sbi_sess = user_data; + ogs_sbi_stream_t *stream = NULL; + ogs_sbi_request_t *request = NULL; + + const char PATH[] = ":path"; + const char METHOD[] = ":method"; + + nghttp2_vec namebuf, valuebuf; + char *namestr = NULL, *valuestr = NULL; + + ogs_assert(session); + ogs_assert(frame); + + if (frame->hd.type != NGHTTP2_HEADERS || + frame->headers.cat != NGHTTP2_HCAT_REQUEST) { + return 0; + } + + stream = nghttp2_session_get_stream_user_data(session, frame->hd.stream_id); + if (!stream) { + ogs_error("no stream [%d]", frame->hd.stream_id); + return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE; + } + + ogs_assert(sbi_sess); + + request = stream->request; + ogs_assert(request); + + ogs_assert(name); + namebuf = nghttp2_rcbuf_get_buf(name); + ogs_assert(namebuf.base); + ogs_assert(namebuf.len); + + ogs_assert(value); + valuebuf = nghttp2_rcbuf_get_buf(value); + ogs_assert(valuebuf.base); + ogs_assert(valuebuf.len); + + namestr = ogs_strndup((const char *)namebuf.base, namebuf.len); + ogs_assert(namestr); + + valuestr = ogs_strndup((const char *)valuebuf.base, valuebuf.len); + ogs_assert(valuestr); + + if (namebuf.len == sizeof(PATH) - 1 && + memcmp(PATH, namebuf.base, namebuf.len) == 0) { + char *saveptr = NULL, *query; +#define MAX_NUM_OF_PARAM_IN_QUERY 16 + struct yuarel_param params[MAX_NUM_OF_PARAM_IN_QUERY+2]; + int j; + + ogs_assert(request->h.uri == NULL); + request->h.uri = ogs_sbi_parse_uri(valuestr, "?", &saveptr); + ogs_assert(request->h.uri); + + memset(params, 0, sizeof(params)); + + query = ogs_sbi_parse_uri(NULL, "?", &saveptr); + if (query && *query && strlen(query)) + yuarel_parse_query(query, '&', params, MAX_NUM_OF_PARAM_IN_QUERY+1); + + j = 0; + while(params[j].key && params[j].val) { + ogs_sbi_header_set(request->http.params, + params[j].key, params[j].val); + j++; + } + + if (j >= MAX_NUM_OF_PARAM_IN_QUERY+1) { + ogs_fatal("Maximum number(%d) of query params reached", + MAX_NUM_OF_PARAM_IN_QUERY); + ogs_assert_if_reached(); + } + + ogs_free(query); + + } else if (namebuf.len == sizeof(METHOD) - 1 && + memcmp(METHOD, namebuf.base, namebuf.len) == 0) { + + ogs_assert(request->h.method == NULL); + request->h.method = ogs_strdup(valuestr); + + } else { + + ogs_sbi_header_set(request->http.headers, namestr, valuestr); + + } + + ogs_free(namestr); + ogs_free(valuestr); + + return 0; +} + +static int on_data_chunk_recv(nghttp2_session *session, uint8_t flags, + int32_t stream_id, const uint8_t *data, + size_t len, void *user_data) +{ + ogs_sbi_stream_t *stream = NULL; + ogs_sbi_request_t *request = NULL; + + ogs_assert(session); + + stream = nghttp2_session_get_stream_user_data(session, stream_id); + if (!stream) { + ogs_error("no stream [%d]", stream_id); + return 0; + } + + request = stream->request; + ogs_assert(request); + + ogs_assert(data); + ogs_assert(len); + ogs_assert(request->http.content == NULL); + + request->http.content_length = len; + request->http.content = (char*)ogs_malloc(request->http.content_length + 1); + ogs_assert(request->http.content); + memcpy(request->http.content, data, len); + request->http.content[request->http.content_length] = '\0'; + + return 0; +} + +static int error_callback(nghttp2_session *session, + const char *msg, size_t len, void *user_data) +{ + char buf[OGS_ADDRSTRLEN]; + ogs_sockaddr_t *addr = NULL; + ogs_sbi_session_t *sbi_sess = user_data; + + ogs_assert(sbi_sess); + addr = sbi_sess->addr; + ogs_assert(addr); + + ogs_assert(msg); + + ogs_error("[%s]:%d http2 error: %.*s", + OGS_ADDR(addr, buf), OGS_PORT(addr), (int)len, msg); + + return 0; +} + +static int on_invalid_frame_recv(nghttp2_session *session, + const nghttp2_frame *frame, + int error_code, void *user_data) +{ + char buf[OGS_ADDRSTRLEN]; + ogs_sockaddr_t *addr = NULL; + + ogs_sbi_session_t *sbi_sess = user_data; + + ogs_assert(sbi_sess); + addr = sbi_sess->addr; + ogs_assert(addr); + + ogs_error("[%s]:%d invalid frame (%d:%s)", + OGS_ADDR(addr, buf), OGS_PORT(addr), + error_code, nghttp2_strerror(error_code)); + return 0; +} + +static int on_invalid_header(nghttp2_session *session, + const nghttp2_frame *frame, + const uint8_t *name, size_t namelen, + const uint8_t *value, size_t valuelen, + uint8_t flags, void *user_data) +{ + char buf[OGS_ADDRSTRLEN]; + ogs_sockaddr_t *addr = NULL; + char *namestr = NULL, *valuestr = NULL; + + ogs_sbi_session_t *sbi_sess = user_data; + + ogs_assert(sbi_sess); + addr = sbi_sess->addr; + ogs_assert(addr); + + namestr = ogs_strndup((const char *)name, namelen); + ogs_assert(namestr); + + valuestr = ogs_strndup((const char *)value, valuelen); + ogs_assert(valuestr); + + ogs_error("[%s]:%d invalid header (%s:%s)", + OGS_ADDR(addr, buf), OGS_PORT(addr), namestr, valuestr); + + ogs_free(namestr); + ogs_free(valuestr); + + return 0; +} + +static int on_begin_frame(nghttp2_session *session, const nghttp2_frame_hd *hd, + void *user_data) +{ + char buf[OGS_ADDRSTRLEN]; + ogs_sockaddr_t *addr = NULL; + ogs_sbi_session_t *sbi_sess = user_data; + + ogs_assert(sbi_sess); + addr = sbi_sess->addr; + ogs_assert(addr); + + ogs_assert(hd); + + if ((hd->type == NGHTTP2_HEADERS) && + (hd->stream_id < sbi_sess->last_stream_id)) { + ogs_error("[%s]:%d invalid stream id(%d) >= last stream id(%d)", + OGS_ADDR(addr, buf), OGS_PORT(addr), + hd->stream_id, sbi_sess->last_stream_id); + return NGHTTP2_ERR_CALLBACK_FAILURE; + } + + return 0; +} + +static int on_begin_headers(nghttp2_session *session, + const nghttp2_frame *frame, void *user_data) +{ + ogs_sbi_session_t *sbi_sess = user_data; + ogs_sbi_stream_t *stream = NULL; + + ogs_assert(sbi_sess); + ogs_assert(session); + ogs_assert(frame); + + if (frame->hd.type != NGHTTP2_HEADERS || + frame->headers.cat != NGHTTP2_HCAT_REQUEST) { + return 0; + } + + stream = stream_add(sbi_sess, frame->hd.stream_id); + ogs_assert(stream); + + nghttp2_session_set_stream_user_data(session, frame->hd.stream_id, stream); + + return 0; +} + +static int session_send_preface(ogs_sbi_session_t *sbi_sess) +{ + int rv; + nghttp2_settings_entry iv[1] = { + { NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS, 100 } + }; + + ogs_assert(sbi_sess); + ogs_assert(sbi_sess->session); + + rv = nghttp2_submit_settings( + sbi_sess->session, NGHTTP2_FLAG_NONE, iv, OGS_ARRAY_SIZE(iv)); + if (rv != 0) { + ogs_error("nghttp2_submit_settings() failed (%d:%s)", + rv, nghttp2_strerror(rv)); + return OGS_ERROR; + } + + return session_send(sbi_sess); +} + +#if USE_SEND_DATA_WITH_NO_COPY +static int on_send_data(nghttp2_session *session, nghttp2_frame *frame, + const uint8_t *framehd, size_t length, + nghttp2_data_source *source, void *user_data) +{ + ogs_sbi_session_t *sbi_sess = user_data; + + ogs_sbi_response_t *response = NULL; + ogs_sbi_stream_t *stream = NULL; + ogs_pkbuf_t *pkbuf = NULL; + size_t padlen = 0; + + ogs_assert(session); + ogs_assert(frame); + + stream = nghttp2_session_get_stream_user_data(session, frame->hd.stream_id); + if (!stream) { + ogs_error("no stream [%d]", frame->hd.stream_id); + return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE; + } + + ogs_assert(sbi_sess); + + ogs_assert(source); + response = source->ptr; + ogs_assert(response); + + ogs_assert(response->http.content); + ogs_assert(response->http.content_length); + + ogs_assert(framehd); + ogs_assert(length); + + pkbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); + ogs_assert(pkbuf); + ogs_pkbuf_put_data(pkbuf, framehd, 9); + + padlen = frame->data.padlen; + + if (padlen > 0) { + ogs_pkbuf_put_u8(pkbuf, padlen-1); + } + + ogs_pkbuf_put_data(pkbuf, + response->http.content, response->http.content_length); + + if (padlen > 0) { + memset(pkbuf->tail, 0, padlen-1); + ogs_pkbuf_put(pkbuf, padlen-1); + } + + session_write_to_buffer(sbi_sess, pkbuf); + + return 0; +} +#else +static ssize_t send_callback(nghttp2_session *session, const uint8_t *data, + size_t length, int flags, void *user_data) +{ + ogs_sbi_session_t *sbi_sess = user_data; + ogs_sock_t *sock = NULL; + ogs_socket_t fd = INVALID_SOCKET; + + ogs_pkbuf_t *pkbuf = NULL; + + ogs_assert(sbi_sess); + sock = sbi_sess->sock; + ogs_assert(sock); + fd = sock->fd; + ogs_assert(fd != INVALID_SOCKET); + + ogs_assert(data); + ogs_assert(length); + + pkbuf = ogs_pkbuf_alloc(NULL, length); + ogs_assert(pkbuf); + ogs_pkbuf_put_data(pkbuf, data, length); + + session_write_to_buffer(sbi_sess, pkbuf); + + return length; +} +#endif + +static int session_send(ogs_sbi_session_t *sbi_sess) +{ +#if USE_SEND_DATA_WITH_NO_COPY + ogs_pkbuf_t *pkbuf = NULL; +#else + int rv; +#endif + + ogs_assert(sbi_sess); + ogs_assert(sbi_sess->session); + +#if USE_SEND_DATA_WITH_NO_COPY + for (;;) { + const uint8_t *data = NULL; + ssize_t data_len; + + data_len = nghttp2_session_mem_send(sbi_sess->session, &data); + if (data_len < 0) { + ogs_error("nghttp2_session_mem_send() failed (%d:%s)", + (int)data_len, nghttp2_strerror((int)data_len)); + return OGS_ERROR; + } + + if (data_len == 0) { + break; + } + + pkbuf = ogs_pkbuf_alloc(NULL, data_len); + ogs_assert(pkbuf); + ogs_pkbuf_put_data(pkbuf, data, data_len); + + session_write_to_buffer(sbi_sess, pkbuf); + } +#else + rv = nghttp2_session_send(sbi_sess->session); + if (rv != 0) { + ogs_error("nghttp_session_send() failed (%d:%s)", + rv, nghttp2_strerror(rv)); + return OGS_ERROR; + } +#endif + + return OGS_OK; +} + +static void session_write_callback(short when, ogs_socket_t fd, void *data) +{ + ogs_sbi_session_t *sbi_sess = data; + ogs_pkbuf_t *pkbuf = NULL; + + ogs_assert(sbi_sess); + + if (ogs_list_empty(&sbi_sess->write_queue) == true) { + ogs_assert(sbi_sess->poll.write); + ogs_pollset_remove(sbi_sess->poll.write); + return; + } + + pkbuf = ogs_list_first(&sbi_sess->write_queue); + ogs_assert(pkbuf); + ogs_list_remove(&sbi_sess->write_queue, pkbuf); + + ogs_send(fd, pkbuf->data, pkbuf->len, 0); + ogs_pkbuf_free(pkbuf); +} + +static void session_write_to_buffer( + ogs_sbi_session_t *sbi_sess, ogs_pkbuf_t *pkbuf) +{ + ogs_sock_t *sock = NULL; + ogs_socket_t fd = INVALID_SOCKET; + + ogs_poll_t *poll = NULL; + + ogs_assert(pkbuf); + + ogs_assert(sbi_sess); + sock = sbi_sess->sock; + ogs_assert(sock); + fd = sock->fd; + ogs_assert(fd != INVALID_SOCKET); + + ogs_list_add(&sbi_sess->write_queue, pkbuf); + + poll = ogs_pollset_cycle(ogs_app()->pollset, sbi_sess->poll.write); + if (!poll) + sbi_sess->poll.write = ogs_pollset_add(ogs_app()->pollset, + OGS_POLLOUT, fd, session_write_callback, sbi_sess); +} diff --git a/lib/sbi/nnrf-handler.c b/lib/sbi/nnrf-handler.c index 630c1b9e6..e22aaa11d 100644 --- a/lib/sbi/nnrf-handler.c +++ b/lib/sbi/nnrf-handler.c @@ -21,7 +21,7 @@ bool ogs_sbi_nnrf_handle_nf_profile(ogs_sbi_nf_instance_t *nf_instance, OpenAPI_nf_profile_t *NFProfile, - ogs_sbi_session_t *session, ogs_sbi_message_t *message) + ogs_sbi_stream_t *stream, ogs_sbi_message_t *message) { int rv; @@ -32,32 +32,32 @@ bool ogs_sbi_nnrf_handle_nf_profile(ogs_sbi_nf_instance_t *nf_instance, if (!NFProfile) { ogs_error("No NFProfile"); - if (session) - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + if (stream) + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, message, "No NFProfile", NULL); return false; } if (!NFProfile->nf_instance_id) { ogs_error("No NFProfile.NFInstanceId"); - if (session) - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + if (stream) + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, message, "NFProfile", "No NFInstanceId"); return false; } if (!NFProfile->nf_type) { ogs_error("No NFProfile.NFType"); - if (session) - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + if (stream) + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, message, "NFProfile", "No NFType"); return false; } if (!NFProfile->nf_status) { ogs_error("No NFProfile.NFStatus"); - if (session) - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + if (stream) + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, message, "NFProfile", "No NFStatus"); return false; } diff --git a/lib/sbi/nnrf-handler.h b/lib/sbi/nnrf-handler.h index c5e0ee8c7..4a09aa78c 100644 --- a/lib/sbi/nnrf-handler.h +++ b/lib/sbi/nnrf-handler.h @@ -26,7 +26,7 @@ extern "C" { bool ogs_sbi_nnrf_handle_nf_profile(ogs_sbi_nf_instance_t *nf_instance, OpenAPI_nf_profile_t *NFProfile, - ogs_sbi_session_t *session, ogs_sbi_message_t *message); + ogs_sbi_stream_t *stream, ogs_sbi_message_t *message); #ifdef __cplusplus } diff --git a/lib/sbi/sbi-private.h b/lib/sbi/sbi-private.h deleted file mode 100644 index dfafa1466..000000000 --- a/lib/sbi/sbi-private.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (C) 2019 by Sukchan Lee - * - * This file is part of Open5GS. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef OGS_SBI_PRIVATE_H -#define OGS_SBI_PRIVATE_H - -#include "yuarel.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* OGS_SBI_PRIVATE_H */ diff --git a/lib/sbi/server.c b/lib/sbi/server.c index aa029c383..e654f8da3 100644 --- a/lib/sbi/server.c +++ b/lib/sbi/server.c @@ -20,158 +20,37 @@ #include "ogs-app.h" #include "ogs-sbi.h" -#include "microhttpd.h" +extern const ogs_sbi_server_actions_t ogs_mhd_server_actions; +extern const ogs_sbi_server_actions_t ogs_nghttp2_server_actions; -#if MHD_VERSION >= 0x00097001 -typedef enum MHD_Result _MHD_Result; -#else -typedef int _MHD_Result; -#endif - -typedef struct ogs_sbi_session_s { - ogs_lnode_t lnode; - - struct MHD_Connection *connection; - - ogs_sbi_request_t *request; - ogs_sbi_server_t *server; - - /* - * The HTTP server(MHD) should send an HTTP response - * if an HTTP client(CURL) is requested. - * - * If the HTTP client closes the socket without sending an HTTP response, - * the CPU load of a program using MHD is 100%. This is because - * POLLIN(POLLRDHUP) is generated. So, the callback function of poll - * continues to be called. - * - * I've created the timer to check whether the user does not use - * the HTTP response. When the timer expires, an assertion occurs and - * terminates the program. - */ - ogs_timer_t *timer; - - void *data; -} ogs_sbi_session_t; +ogs_sbi_server_actions_t ogs_sbi_server_actions; +bool ogs_sbi_server_actions_initialized = false; static OGS_POOL(server_pool, ogs_sbi_server_t); -static OGS_POOL(session_pool, ogs_sbi_session_t); -static void run(short when, ogs_socket_t fd, void *data); -static void notify_connection(void *cls, - struct MHD_Connection *connection, - void **socket_context, - enum MHD_ConnectionNotificationCode toe); -static _MHD_Result access_handler( - void *cls, - struct MHD_Connection *connection, - const char *url, - const char *method, - const char *version, - const char *upload_data, - size_t *upload_data_size, - void **con_cls); -static void notify_completed( - void *cls, - struct MHD_Connection *connection, - void **con_cls, - enum MHD_RequestTerminationCode toe); - -static void session_timer_expired(void *data); - -void ogs_sbi_server_init(int num_of_session_pool) +void ogs_sbi_server_init(int num_of_stream_pool) { + if (ogs_sbi_server_actions_initialized == false) { +#if 1 /* Use HTTP2 */ + ogs_sbi_server_actions = ogs_nghttp2_server_actions; +#else + ogs_sbi_server_actions = ogs_mhd_server_actions; +#endif + } + + ogs_sbi_server_actions.init(num_of_stream_pool); + ogs_list_init(&ogs_sbi_self()->server_list); ogs_pool_init(&server_pool, ogs_app()->pool.nf); - - ogs_pool_init(&session_pool, num_of_session_pool); } + void ogs_sbi_server_final(void) { ogs_sbi_server_remove_all(); ogs_pool_final(&server_pool); - ogs_pool_final(&session_pool); -} -static ogs_sbi_session_t *session_add(ogs_sbi_server_t *server, - ogs_sbi_request_t *request, struct MHD_Connection *connection) -{ - ogs_sbi_session_t *session = NULL; - - ogs_assert(server); - ogs_assert(request); - ogs_assert(connection); - - ogs_pool_alloc(&session_pool, &session); - ogs_assert(session); - memset(session, 0, sizeof(ogs_sbi_session_t)); - - session->server = server; - session->request = request; - session->connection = connection; - - session->timer = ogs_timer_add( - ogs_app()->timer_mgr, session_timer_expired, session); - ogs_assert(session->timer); - - /* If User does not send http response within deadline, - * Open5GS will assert this program. */ - ogs_timer_start(session->timer, - ogs_app()->time.message.sbi.connection_deadline); - - ogs_list_add(&server->suspended_session_list, session); - - return session; -} - -static void session_remove(ogs_sbi_session_t *session) -{ - struct MHD_Connection *connection; - ogs_sbi_server_t *server = NULL; - - ogs_assert(session); - server = session->server; - ogs_assert(server); - - ogs_list_remove(&server->suspended_session_list, session); - - ogs_assert(session->timer); - ogs_timer_delete(session->timer); - - connection = session->connection; - ogs_assert(connection); - - MHD_resume_connection(connection); - - ogs_pool_free(&session_pool, session); -} - -static void session_timer_expired(void *data) -{ - ogs_sbi_session_t *session = NULL; - - session = data; - ogs_assert(session); - - ogs_fatal("An HTTP request was received, " - "but the HTTP response is missing."); - ogs_fatal("Please send the related pcap files for this case."); - - session_remove(session); - - ogs_assert_if_reached(); -} - -static void session_remove_all(ogs_sbi_server_t *server) -{ - ogs_sbi_session_t *session = NULL, *next_session = NULL; - - ogs_assert(server); - - ogs_list_for_each_safe( - &server->suspended_session_list, next_session, session) - session_remove(session); + ogs_sbi_server_actions.cleanup(); } ogs_sbi_server_t *ogs_sbi_server_add(ogs_sockaddr_t *addr) @@ -184,8 +63,7 @@ ogs_sbi_server_t *ogs_sbi_server_add(ogs_sockaddr_t *addr) ogs_assert(server); memset(server, 0, sizeof(ogs_sbi_server_t)); - ogs_list_init(&server->suspended_session_list); - ogs_copyaddrinfo(&server->addr, addr); + ogs_copyaddrinfo(&server->node.addr, addr); ogs_list_add(&ogs_sbi_self()->server_list, server); @@ -198,10 +76,8 @@ void ogs_sbi_server_remove(ogs_sbi_server_t *server) ogs_list_remove(&ogs_sbi_self()->server_list, server); - ogs_sbi_server_stop(server); - - ogs_assert(server->addr); - ogs_freeaddrinfo(server->addr); + ogs_assert(server->node.addr); + ogs_freeaddrinfo(server->node.addr); ogs_pool_free(&server_pool, server); } @@ -214,117 +90,13 @@ void ogs_sbi_server_remove_all(void) ogs_sbi_server_remove(server); } -void ogs_sbi_server_start(ogs_sbi_server_t *server, int (*cb)( - ogs_sbi_server_t *server, ogs_sbi_session_t *session, - ogs_sbi_request_t *request)) -{ - char buf[OGS_ADDRSTRLEN]; - ogs_sockaddr_t *addr = NULL; - -#if MHD_VERSION >= 0x00095300 - unsigned int mhd_flags = MHD_USE_ERROR_LOG; -#else - unsigned int mhd_flags = MHD_USE_DEBUG; -#endif - const union MHD_DaemonInfo *mhd_info = NULL; -#define MAX_NUM_OF_MHD_OPTION_ITEM 8 - struct MHD_OptionItem mhd_ops[MAX_NUM_OF_MHD_OPTION_ITEM]; - int index = 0; - - ogs_assert(server); - -#if MHD_VERSION >= 0x00095300 - mhd_flags |= MHD_ALLOW_SUSPEND_RESUME; -#elif MHD_VERSION >= 0x00093400 - mhd_flags |= MHD_USE_SUSPEND_RESUME; -#else - mhd_flags |= MHD_USE_PIPE_FOR_SHUTDOWN; -#endif - - /* Setup callback function */ - server->cb = cb; - - mhd_ops[index].option = MHD_OPTION_NOTIFY_COMPLETED; - mhd_ops[index].value = (intptr_t)notify_completed; - mhd_ops[index].ptr_value = server; - index++; - - mhd_ops[index].option = MHD_OPTION_NOTIFY_CONNECTION; - mhd_ops[index].value = (intptr_t)¬ify_connection; - mhd_ops[index].ptr_value = NULL; - index++; - - addr = server->addr; - ogs_assert(addr); - if (addr->ogs_sa_family == AF_INET6) - mhd_flags |= MHD_USE_IPv6; - mhd_ops[index].option = MHD_OPTION_SOCK_ADDR; - mhd_ops[index].value = 0; - mhd_ops[index].ptr_value = (void *)&addr->sa; - index++; - - mhd_ops[index].option = MHD_OPTION_END; - mhd_ops[index].value = 0; - mhd_ops[index].ptr_value = NULL; - index++; - - server->mhd = MHD_start_daemon( - mhd_flags, - 0, - NULL, NULL, - access_handler, server, - MHD_OPTION_ARRAY, mhd_ops, - MHD_OPTION_END); - if (!server->mhd) { - ogs_error("Cannot start SBI server"); - return; - } - - /* Setup poll for server listening socket */ - mhd_info = MHD_get_daemon_info(server->mhd, MHD_DAEMON_INFO_LISTEN_FD); - ogs_assert(mhd_info); - - server->poll = ogs_pollset_add(ogs_app()->pollset, - OGS_POLLIN, mhd_info->listen_fd, run, server->mhd); - ogs_assert(server->poll); - - if (addr) { - char *hostname = ogs_gethostname(addr); - if (hostname) - ogs_info("sbi_server() [%s]:%d", - hostname, OGS_PORT(addr)); - else - ogs_info("sbi_server() [%s]:%d", - OGS_ADDR(addr, buf), OGS_PORT(addr)); - } else - ogs_info("sbi_server() [any]:any"); -} - -void ogs_sbi_server_start_all(int (*cb)( - ogs_sbi_server_t *server, ogs_sbi_session_t *session, - ogs_sbi_request_t *request)) +void ogs_sbi_server_start_all( + int (*cb)(ogs_sbi_request_t *request, void *data)) { ogs_sbi_server_t *server = NULL, *next_server = NULL; ogs_list_for_each_safe(&ogs_sbi_self()->server_list, next_server, server) - ogs_sbi_server_start(server, cb); -} - -void ogs_sbi_server_stop(ogs_sbi_server_t *server) -{ - ogs_assert(server); - - if (server->poll) { - ogs_pollset_remove(server->poll); - server->poll = NULL; - } - - session_remove_all(server); - - if (server->mhd) { - MHD_stop_daemon(server->mhd); - server->mhd = NULL; - } + ogs_sbi_server_actions.start(server, cb); } void ogs_sbi_server_stop_all(void) @@ -332,86 +104,22 @@ void ogs_sbi_server_stop_all(void) ogs_sbi_server_t *server = NULL, *next_server = NULL; ogs_list_for_each_safe(&ogs_sbi_self()->server_list, next_server, server) - ogs_sbi_server_stop(server); + ogs_sbi_server_actions.stop(server); } void ogs_sbi_server_send_response( - ogs_sbi_session_t *session, ogs_sbi_response_t *response) + ogs_sbi_stream_t *stream, ogs_sbi_response_t *response) { - int ret; - int status; - - struct MHD_Connection *connection = NULL; - struct MHD_Response *mhd_response; - struct MHD_Daemon *mhd_daemon = NULL; - const union MHD_ConnectionInfo *mhd_info = NULL; - MHD_socket mhd_socket = INVALID_SOCKET; - - ogs_hash_index_t *hi; - ogs_sbi_request_t *request = NULL; - - ogs_assert(response); - - ogs_assert(session); - connection = session->connection; - ogs_assert(connection); - - mhd_info = MHD_get_connection_info( - connection, MHD_CONNECTION_INFO_DAEMON); - ogs_assert(mhd_info); - mhd_daemon = mhd_info->daemon; - ogs_assert(mhd_daemon); - - mhd_info = MHD_get_connection_info( - connection, MHD_CONNECTION_INFO_CONNECTION_FD); - ogs_assert(mhd_info); - mhd_socket = mhd_info->connect_fd; - ogs_assert(mhd_socket != INVALID_SOCKET); - - if (response->http.content) { - mhd_response = MHD_create_response_from_buffer( - response->http.content_length, response->http.content, - MHD_RESPMEM_PERSISTENT); - ogs_assert(mhd_response); - } else { - mhd_response = MHD_create_response_from_buffer( - 0, NULL, MHD_RESPMEM_PERSISTENT); - ogs_assert(mhd_response); - } - - for (hi = ogs_hash_first(response->http.headers); - hi; hi = ogs_hash_next(hi)) { - const char *key = ogs_hash_this_key(hi); - char *val = ogs_hash_this_val(hi); - MHD_add_response_header(mhd_response, key, val); - } - - status = response->status; - request = session->request; - ogs_assert(request); - - ogs_sbi_response_free(response); - session_remove(session); - - request->poll = ogs_pollset_add(ogs_app()->pollset, - OGS_POLLOUT, mhd_socket, run, mhd_daemon); - ogs_assert(request->poll); - - ret = MHD_queue_response(connection, status, mhd_response); - if (ret != MHD_YES) { - ogs_fatal("MHD_queue_response_error [%d]", ret); - ogs_assert_if_reached(); - } - MHD_destroy_response(mhd_response); + ogs_sbi_server_actions.send_response(stream, response); } void ogs_sbi_server_send_problem( - ogs_sbi_session_t *session, OpenAPI_problem_details_t *problem) + ogs_sbi_stream_t *stream, OpenAPI_problem_details_t *problem) { ogs_sbi_message_t message; ogs_sbi_response_t *response = NULL; - ogs_assert(session); + ogs_assert(stream); ogs_assert(problem); memset(&message, 0, sizeof(message)); @@ -422,16 +130,16 @@ void ogs_sbi_server_send_problem( response = ogs_sbi_build_response(&message, problem->status); ogs_assert(response); - ogs_sbi_server_send_response(session, response); + ogs_sbi_server_send_response(stream, response); } -void ogs_sbi_server_send_error(ogs_sbi_session_t *session, +void ogs_sbi_server_send_error(ogs_sbi_stream_t *stream, int status, ogs_sbi_message_t *message, const char *title, const char *detail) { OpenAPI_problem_details_t problem; - ogs_assert(session); + ogs_assert(stream); memset(&problem, 0, sizeof(problem)); @@ -450,7 +158,7 @@ void ogs_sbi_server_send_error(ogs_sbi_session_t *session, problem.title = (char*)title; problem.detail = (char*)detail; - ogs_sbi_server_send_problem(session, &problem); + ogs_sbi_server_send_problem(stream, &problem); if (problem.type) ogs_free(problem.type); @@ -458,206 +166,7 @@ void ogs_sbi_server_send_error(ogs_sbi_session_t *session, ogs_free(problem.instance); } -static void run(short when, ogs_socket_t fd, void *data) +ogs_sbi_server_t *ogs_sbi_server_from_stream(ogs_sbi_stream_t *stream) { - struct MHD_Daemon *mhd_daemon = data; - - ogs_assert(mhd_daemon); - MHD_run(mhd_daemon); -} - -static void notify_connection(void *cls, - struct MHD_Connection *connection, - void **socket_context, - enum MHD_ConnectionNotificationCode toe) -{ - struct MHD_Daemon *mhd_daemon = NULL; - MHD_socket mhd_socket = INVALID_SOCKET; - - const union MHD_ConnectionInfo *mhd_info = NULL; - ogs_poll_t *poll = NULL; - - switch (toe) { - case MHD_CONNECTION_NOTIFY_STARTED: - mhd_info = MHD_get_connection_info( - connection, MHD_CONNECTION_INFO_DAEMON); - ogs_assert(mhd_info); - mhd_daemon = mhd_info->daemon; - ogs_assert(mhd_daemon); - - mhd_info = MHD_get_connection_info( - connection, MHD_CONNECTION_INFO_CONNECTION_FD); - ogs_assert(mhd_info); - mhd_socket = mhd_info->connect_fd; - ogs_assert(mhd_socket != INVALID_SOCKET); - - poll = ogs_pollset_add(ogs_app()->pollset, - OGS_POLLIN, mhd_socket, run, mhd_daemon); - ogs_assert(poll); - *socket_context = poll; - break; - case MHD_CONNECTION_NOTIFY_CLOSED: - poll = *socket_context; - ogs_pollset_remove(poll); - break; - } -} - -static int get_values(ogs_hash_t *hash, - enum MHD_ValueKind kind, const char *key, const char *value) -{ - ogs_assert(hash); - - if (!key || !value) - return MHD_YES; // Ignore connection value if invalid! - - ogs_sbi_header_set(hash, key, value); - - return MHD_YES; -} - -static _MHD_Result access_handler( - void *cls, - struct MHD_Connection *connection, - const char *url, - const char *method, - const char *version, - const char *upload_data, - size_t *upload_data_size, - void **con_cls) -{ - ogs_sbi_server_t *server = NULL; - ogs_sbi_request_t *request = NULL; - ogs_sbi_session_t *session = NULL; - - server = cls; - ogs_assert(server); - - request = *con_cls; - - if (request && request->suspended) { - ogs_error("Suspended Request"); - return MHD_YES; - } - - if (!request) { - request = ogs_sbi_request_new(); - ogs_assert(request); - *con_cls = request; - - ogs_assert(request->http.params); - MHD_get_connection_values(connection, MHD_GET_ARGUMENT_KIND, - (MHD_KeyValueIterator)get_values, request->http.params); - - ogs_assert(request->http.headers); - MHD_get_connection_values(connection, MHD_HEADER_KIND, - (MHD_KeyValueIterator)get_values, request->http.headers); - - request->h.method = ogs_strdup(method); - request->h.uri = ogs_strdup(url); - - if (ogs_sbi_header_get(request->http.headers, "Content-Length") || - ogs_sbi_header_get(request->http.headers, "Transfer-Encoding")) { - - // FIXME : check if POST_DATA is on MHD_POSTDATA_KIND - - return MHD_YES; - } - - goto suspend; - } - - if (*upload_data_size != 0) { - size_t offset = 0; - - if (request->http.content == NULL) { - request->http.content_length = *upload_data_size; - request->http.content = - (char*)ogs_malloc(request->http.content_length + 1); - ogs_assert(request->http.content); - } else { - offset = request->http.content_length; - if ((request->http.content_length + - *upload_data_size) > OGS_HUGE_LEN) { - ogs_error("Overflow : Content-Length[%d], upload_data_size[%d]", - (int)request->http.content_length, - (int)*upload_data_size); - *upload_data_size = 0; - return MHD_YES; - } - request->http.content_length += *upload_data_size; - request->http.content = (char *)ogs_realloc( - request->http.content, request->http.content_length + 1); - ogs_assert(request->http.content); - } - - memcpy(request->http.content + offset, upload_data, *upload_data_size); - request->http.content[request->http.content_length] = '\0'; - *upload_data_size = 0; - - return MHD_YES; - } - -suspend: - MHD_suspend_connection(connection); - request->suspended = true; - - session = session_add(server, request, connection); - ogs_assert(session); - - if (server->cb) { - if (server->cb(server, session, request) != OGS_OK) { - ogs_warn("server callback error"); - ogs_sbi_server_send_error(session, - OGS_SBI_HTTP_STATUS_INTERNAL_SERVER_ERROR, NULL, - "server callback error", NULL); - - return MHD_YES; - } - } else { - ogs_fatal("server callback is not registered"); - ogs_assert_if_reached(); - } - - return MHD_YES; -} - -static void notify_completed( - void *cls, - struct MHD_Connection *connection, - void **con_cls, - enum MHD_RequestTerminationCode toe) -{ - ogs_sbi_request_t *request = *con_cls; - ogs_poll_t *poll = NULL; - - ogs_assert(request); - poll = request->poll; - if (poll) - ogs_pollset_remove(poll); - - ogs_sbi_request_free(request); -} - -void ogs_sbi_session_set_data(ogs_sbi_session_t *session, void *data) -{ - ogs_assert(session); - ogs_assert(data); - - session->data = data; -} - -void *ogs_sbi_session_get_data(ogs_sbi_session_t *session) -{ - ogs_assert(session); - - return session->data; -} - -ogs_sbi_server_t *ogs_sbi_session_get_server(ogs_sbi_session_t *session) -{ - ogs_assert(session); - ogs_assert(session->server); - - return session->server; + return ogs_sbi_server_actions.from_stream(stream); } diff --git a/lib/sbi/server.h b/lib/sbi/server.h index 4a43ec835..9d0229fc7 100644 --- a/lib/sbi/server.h +++ b/lib/sbi/server.h @@ -28,30 +28,36 @@ extern "C" { #endif -typedef struct ogs_sbi_server_s ogs_sbi_server_t; -typedef struct ogs_sbi_session_s ogs_sbi_session_t; +typedef struct ogs_sbi_stream_s ogs_sbi_stream_t; typedef struct ogs_sbi_server_s { - ogs_lnode_t lnode; /* A node of list_t */ - - ogs_sockaddr_t *addr; /* Listen socket address */ + ogs_socknode_t node; struct { const char *key; const char *pem; } tls; - int (*cb)(ogs_sbi_server_t *server, ogs_sbi_session_t *session, - ogs_sbi_request_t *request); - void *data; - - ogs_list_t suspended_session_list; /* MHD suspended list */ - - void *mhd; /* MHD instance */ - ogs_poll_t *poll; /* MHD server poll */ + int (*cb)(ogs_sbi_request_t *request, void *data); + ogs_list_t session_list; + void *mhd; /* Used by MHD */ } ogs_sbi_server_t; +typedef struct ogs_sbi_server_actions_s { + void (*init)(int num_of_stream_pool); + void (*cleanup)(void); + + void (*start)(ogs_sbi_server_t *server, + int (*cb)(ogs_sbi_request_t *request, void *data)); + void (*stop)(ogs_sbi_server_t *server); + + void (*send_response)( + ogs_sbi_stream_t *stream, ogs_sbi_response_t *response); + + ogs_sbi_server_t *(*from_stream)(ogs_sbi_stream_t *stream); +} ogs_sbi_server_actions_t; + void ogs_sbi_server_init(int num_of_connection_pool); void ogs_sbi_server_final(void); @@ -59,26 +65,19 @@ ogs_sbi_server_t *ogs_sbi_server_add(ogs_sockaddr_t *addr); void ogs_sbi_server_remove(ogs_sbi_server_t *server); void ogs_sbi_server_remove_all(void); -void ogs_sbi_server_start(ogs_sbi_server_t *server, int (*cb)( - ogs_sbi_server_t *server, ogs_sbi_session_t *session, - ogs_sbi_request_t *request)); -void ogs_sbi_server_start_all(int (*cb)( - ogs_sbi_server_t *server, ogs_sbi_session_t *session, - ogs_sbi_request_t *request)); -void ogs_sbi_server_stop(ogs_sbi_server_t *server); +void ogs_sbi_server_start_all( + int (*cb)(ogs_sbi_request_t *request, void *data)); void ogs_sbi_server_stop_all(void); void ogs_sbi_server_send_response( - ogs_sbi_session_t *session, ogs_sbi_response_t *response); -void ogs_sbi_server_send_error(ogs_sbi_session_t *session, + ogs_sbi_stream_t *stream, ogs_sbi_response_t *response); +void ogs_sbi_server_send_error(ogs_sbi_stream_t *stream, int status, ogs_sbi_message_t *message, const char *title, const char *detail); void ogs_sbi_server_send_problem( - ogs_sbi_session_t *session, OpenAPI_problem_details_t *problem); + ogs_sbi_stream_t *stream, OpenAPI_problem_details_t *problem); -void ogs_sbi_session_set_data(ogs_sbi_session_t *session, void *data); -void *ogs_sbi_session_get_data(ogs_sbi_session_t *session); -ogs_sbi_server_t *ogs_sbi_session_get_server(ogs_sbi_session_t *session); +ogs_sbi_server_t *ogs_sbi_server_from_stream(ogs_sbi_stream_t *stream); #ifdef __cplusplus } diff --git a/src/amf/amf-sm.c b/src/amf/amf-sm.c index 1123a526d..11c8542cd 100644 --- a/src/amf/amf-sm.c +++ b/src/amf/amf-sm.c @@ -65,7 +65,7 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e) ogs_sbi_object_t *sbi_object = NULL; ogs_sbi_xact_t *sbi_xact = NULL; int state = AMF_UPDATE_SM_CONTEXT_NO_STATE; - ogs_sbi_session_t *session = NULL; + ogs_sbi_stream_t *stream = NULL; ogs_sbi_request_t *sbi_request = NULL; ogs_sbi_nf_instance_t *nf_instance = NULL; @@ -100,14 +100,14 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e) case AMF_EVT_SBI_SERVER: sbi_request = e->sbi.request; ogs_assert(sbi_request); - session = e->sbi.session; - ogs_assert(session); + stream = e->sbi.data; + ogs_assert(stream); rv = ogs_sbi_parse_request(&sbi_message, sbi_request); if (rv != OGS_OK) { /* 'sbi_message' buffer is released in ogs_sbi_parse_request() */ ogs_error("cannot parse HTTP sbi_message"); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, NULL, "cannot parse HTTP sbi_message", NULL); break; } @@ -123,7 +123,7 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e) ogs_assert(api_version); if (strcmp(sbi_message.h.api.version, api_version) != 0) { ogs_error("Not supported version [%s]", sbi_message.h.api.version); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, &sbi_message, "Not supported version", NULL); ogs_sbi_message_free(&sbi_message); break; @@ -136,13 +136,13 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e) CASE(OGS_SBI_RESOURCE_NAME_NF_STATUS_NOTIFY) SWITCH(sbi_message.h.method) CASE(OGS_SBI_HTTP_METHOD_POST) - amf_nnrf_handle_nf_status_notify(session, &sbi_message); + amf_nnrf_handle_nf_status_notify(stream, &sbi_message); break; DEFAULT ogs_error("Invalid HTTP method [%s]", sbi_message.h.method); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_FORBIDDEN, &sbi_message, "Invalid HTTP method", sbi_message.h.method); @@ -152,7 +152,7 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e) DEFAULT ogs_error("Invalid resource name [%s]", sbi_message.h.resource.component[0]); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, &sbi_message, "Invalid resource name", sbi_message.h.resource.component[0]); @@ -170,7 +170,7 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e) DEFAULT ogs_error("Invalid HTTP method [%s]", sbi_message.h.method); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_FORBIDDEN, &sbi_message, "Invalid HTTP method", sbi_message.h.method); @@ -180,7 +180,7 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e) DEFAULT ogs_error("Invalid resource name [%s]", sbi_message.h.resource.component[0]); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, &sbi_message, "Invalid resource name", sbi_message.h.resource.component[0]); @@ -195,9 +195,9 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e) SWITCH(sbi_message.h.method) CASE(OGS_SBI_HTTP_METHOD_POST) rv = amf_namf_comm_handle_n1_n2_message_transfer( - session, &sbi_message); + stream, &sbi_message); if (rv != OGS_OK) { - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, &sbi_message, "No N1N2MessageTransferReqData", NULL); } @@ -206,7 +206,7 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e) DEFAULT ogs_error("Invalid HTTP method [%s]", sbi_message.h.method); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_FORBIDDEN, &sbi_message, "Invalid HTTP method", sbi_message.h.method); END @@ -215,7 +215,7 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e) DEFAULT ogs_error("Invalid resource name [%s]", sbi_message.h.resource.component[2]); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, &sbi_message, "Invalid resource name", sbi_message.h.resource.component[2]); @@ -225,7 +225,7 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e) DEFAULT ogs_error("Invalid resource name [%s]", sbi_message.h.resource.component[0]); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, &sbi_message, "Invalid resource name", sbi_message.h.resource.component[0]); @@ -236,13 +236,13 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e) SWITCH(sbi_message.h.resource.component[1]) CASE(OGS_SBI_RESOURCE_NAME_SM_CONTEXT_STATUS) amf_namf_callback_handle_sm_context_status( - session, &sbi_message); + stream, &sbi_message); break; DEFAULT ogs_error("Invalid resource name [%s]", sbi_message.h.resource.component[1]); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, &sbi_message, "Invalid resource name", sbi_message.h.resource.component[1]); @@ -251,7 +251,7 @@ void amf_state_operational(ogs_fsm_t *s, amf_event_t *e) DEFAULT ogs_error("Invalid API name [%s]", sbi_message.h.service.name); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, &sbi_message, "Invalid API name", sbi_message.h.resource.component[0]); END diff --git a/src/amf/event.h b/src/amf/event.h index c171c71d8..f4535905b 100644 --- a/src/amf/event.h +++ b/src/amf/event.h @@ -26,8 +26,6 @@ extern "C" { #endif -typedef struct ogs_sbi_server_s ogs_sbi_server_t; -typedef struct ogs_sbi_session_s ogs_sbi_session_t; typedef struct ogs_sbi_request_s ogs_sbi_request_t; typedef struct ogs_sbi_response_s ogs_sbi_response_t; typedef struct ogs_sbi_message_s ogs_sbi_message_t; @@ -72,12 +70,7 @@ typedef struct amf_event_s { int timer_id; struct { - /* OGS_EVT_SBI_SERVER */ ogs_sbi_request_t *request; - ogs_sbi_session_t *session; - ogs_sbi_server_t *server; - - /* OGS_EVT_SBI_CLIENT */ ogs_sbi_response_t *response; void *data; diff --git a/src/amf/namf-handler.c b/src/amf/namf-handler.c index 7efe553bc..f33abf80d 100644 --- a/src/amf/namf-handler.c +++ b/src/amf/namf-handler.c @@ -25,7 +25,7 @@ #include "sbi-path.h" int amf_namf_comm_handle_n1_n2_message_transfer( - ogs_sbi_session_t *session, ogs_sbi_message_t *recvmsg) + ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg) { int status; @@ -53,7 +53,7 @@ int amf_namf_comm_handle_n1_n2_message_transfer( OpenAPI_n2_info_content_t *n2InfoContent = NULL; OpenAPI_ref_to_binary_data_t *ngapData = NULL; - ogs_assert(session); + ogs_assert(stream); ogs_assert(recvmsg); N1N2MessageTransferReqData = recvmsg->N1N2MessageTransferReqData; @@ -186,13 +186,13 @@ int amf_namf_comm_handle_n1_n2_message_transfer( response = ogs_sbi_build_response(&sendmsg, status); ogs_assert(response); - ogs_sbi_server_send_response(session, response); + ogs_sbi_server_send_response(stream, response); return OGS_OK; } int amf_namf_callback_handle_sm_context_status( - ogs_sbi_session_t *session, ogs_sbi_message_t *recvmsg) + ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg) { int status = OGS_SBI_HTTP_STATUS_NO_CONTENT; @@ -207,7 +207,7 @@ int amf_namf_callback_handle_sm_context_status( OpenAPI_sm_context_status_notification_t *SmContextStatusNotification; OpenAPI_status_info_t *StatusInfo; - ogs_assert(session); + ogs_assert(stream); ogs_assert(recvmsg); if (!recvmsg->h.resource.component[0]) { @@ -286,7 +286,7 @@ cleanup: response = ogs_sbi_build_response(&sendmsg, status); ogs_assert(response); - ogs_sbi_server_send_response(session, response); + ogs_sbi_server_send_response(stream, response); return OGS_OK; } diff --git a/src/amf/namf-handler.h b/src/amf/namf-handler.h index c5779960b..11e152991 100644 --- a/src/amf/namf-handler.h +++ b/src/amf/namf-handler.h @@ -27,9 +27,9 @@ extern "C" { #include "context.h" int amf_namf_comm_handle_n1_n2_message_transfer( - ogs_sbi_session_t *session, ogs_sbi_message_t *recvmsg); + ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg); int amf_namf_callback_handle_sm_context_status( - ogs_sbi_session_t *session, ogs_sbi_message_t *recvmsg); + ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg); #ifdef __cplusplus } diff --git a/src/amf/nf-sm.c b/src/amf/nf-sm.c index 37c1d7451..fd229b22a 100644 --- a/src/amf/nf-sm.c +++ b/src/amf/nf-sm.c @@ -155,7 +155,7 @@ void amf_nf_state_will_register(ogs_fsm_t *s, amf_event_t *e) case AMF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: client = nf_instance->client; ogs_assert(client); - addr = client->addr; + addr = client->node.addr; ogs_assert(addr); ogs_warn("[%s] Retry to registration with NRF", nf_instance->id); @@ -362,7 +362,7 @@ void amf_nf_state_exception(ogs_fsm_t *s, amf_event_t *e) case AMF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: client = nf_instance->client; ogs_assert(client); - addr = client->addr; + addr = client->node.addr; ogs_assert(addr); ogs_warn("[%s] Retry to registration with NRF", nf_instance->id); diff --git a/src/amf/nnrf-handler.c b/src/amf/nnrf-handler.c index 5845f7b9d..6b3c7a91f 100644 --- a/src/amf/nnrf-handler.c +++ b/src/amf/nnrf-handler.c @@ -91,7 +91,7 @@ void amf_nnrf_handle_nf_status_subscribe( } bool amf_nnrf_handle_nf_status_notify( - ogs_sbi_session_t *session, ogs_sbi_message_t *message) + ogs_sbi_stream_t *stream, ogs_sbi_message_t *message) { ogs_sbi_response_t *response = NULL; OpenAPI_notification_data_t *NotificationData = NULL; @@ -99,13 +99,13 @@ bool amf_nnrf_handle_nf_status_notify( ogs_sbi_nf_instance_t *nf_instance = NULL; bool handled; - ogs_assert(session); + ogs_assert(stream); ogs_assert(message); NotificationData = message->NotificationData; if (!NotificationData) { ogs_error("No NotificationData"); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, message, "No NotificationData", NULL); return false; } @@ -113,21 +113,21 @@ bool amf_nnrf_handle_nf_status_notify( NFProfile = NotificationData->nf_profile; if (!NFProfile) { ogs_error("No NFProfile"); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, message, "No NFProfile", NULL); return false; } if (!NFProfile->nf_instance_id) { ogs_error("No NFProfile.NFInstanceId"); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, message, "No NFProfile", "NFInstanceId"); return false; } if (!NFProfile->nf_instance_id) { ogs_error("No NFProfile.NFInstanceId"); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, message, "No NFProfile", "NFInstanceId"); return false; } @@ -135,7 +135,7 @@ bool amf_nnrf_handle_nf_status_notify( if (NF_INSTANCE_IS_SELF(NFProfile->nf_instance_id)) { ogs_warn("[%s] The notification is not allowed", NFProfile->nf_instance_id); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_FORBIDDEN, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_FORBIDDEN, message, "The notification is not allowed", NFProfile->nf_instance_id); return false; @@ -161,7 +161,7 @@ bool amf_nnrf_handle_nf_status_notify( } handled = ogs_sbi_nnrf_handle_nf_profile( - nf_instance, NFProfile, session, message); + nf_instance, NFProfile, stream, message); if (!handled) { AMF_NF_INSTANCE_CLEAR("NRF-notify", nf_instance); return false; @@ -172,7 +172,7 @@ bool amf_nnrf_handle_nf_status_notify( handled = ogs_sbi_client_associate(nf_instance); if (!handled) { ogs_error("[%s] Cannot associate NF EndPoint", nf_instance->id); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, message, "Cannot find NF EndPoint", nf_instance->id); AMF_NF_INSTANCE_CLEAR("NRF-notify", nf_instance); @@ -186,7 +186,7 @@ bool amf_nnrf_handle_nf_status_notify( AMF_NF_INSTANCE_CLEAR("NRF-notify", nf_instance); } else { ogs_warn("[%s] (NRF-notify) Not found", NFProfile->nf_instance_id); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_NOT_FOUND, message, "Not found", message->h.resource.component[1]); return false; @@ -196,7 +196,7 @@ bool amf_nnrf_handle_nf_status_notify( NotificationData->event); ogs_error("Not supported event [%d:%s]", NotificationData->event, eventstr ? eventstr : "Unknown"); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, message, "Not supported event", eventstr ? eventstr : "Unknown"); return false; @@ -204,7 +204,7 @@ bool amf_nnrf_handle_nf_status_notify( response = ogs_sbi_build_response(message, OGS_SBI_HTTP_STATUS_NO_CONTENT); ogs_assert(response); - ogs_sbi_server_send_response(session, response); + ogs_sbi_server_send_response(stream, response); return true; } diff --git a/src/amf/nnrf-handler.h b/src/amf/nnrf-handler.h index cf754a266..468c11f76 100644 --- a/src/amf/nnrf-handler.h +++ b/src/amf/nnrf-handler.h @@ -32,7 +32,7 @@ void amf_nnrf_handle_nf_status_subscribe( ogs_sbi_subscription_t *subscription, ogs_sbi_message_t *message); bool amf_nnrf_handle_nf_status_notify( - ogs_sbi_session_t *session, ogs_sbi_message_t *message); + ogs_sbi_stream_t *stream, ogs_sbi_message_t *message); void amf_nnrf_handle_nf_discover( ogs_sbi_xact_t *xact, ogs_sbi_message_t *message); diff --git a/src/amf/sbi-path.c b/src/amf/sbi-path.c index 9a7e339a0..6080db3e2 100644 --- a/src/amf/sbi-path.c +++ b/src/amf/sbi-path.c @@ -22,21 +22,19 @@ #include "nausf-build.h" #include "nudm-build.h" -static int server_cb(ogs_sbi_server_t *server, - ogs_sbi_session_t *session, ogs_sbi_request_t *request) +static int server_cb(ogs_sbi_request_t *request, void *data) { amf_event_t *e = NULL; int rv; - ogs_assert(session); ogs_assert(request); + ogs_assert(data); e = amf_event_new(AMF_EVT_SBI_SERVER); ogs_assert(e); - e->sbi.server = server; - e->sbi.session = session; e->sbi.request = request; + e->sbi.data = data; rv = ogs_queue_push(ogs_app()->queue, e); if (rv != OGS_OK) { diff --git a/src/ausf/ausf-sm.c b/src/ausf/ausf-sm.c index 9662892d3..05de2bb8a 100644 --- a/src/ausf/ausf-sm.c +++ b/src/ausf/ausf-sm.c @@ -38,7 +38,7 @@ void ausf_state_operational(ogs_fsm_t *s, ausf_event_t *e) { int rv; - ogs_sbi_session_t *session = NULL; + ogs_sbi_stream_t *stream = NULL; ogs_sbi_request_t *request = NULL; ogs_sbi_nf_instance_t *nf_instance = NULL; @@ -69,21 +69,21 @@ void ausf_state_operational(ogs_fsm_t *s, ausf_event_t *e) case AUSF_EVT_SBI_SERVER: request = e->sbi.request; ogs_assert(request); - session = e->sbi.session; - ogs_assert(session); + stream = e->sbi.data; + ogs_assert(stream); rv = ogs_sbi_parse_request(&message, request); if (rv != OGS_OK) { /* 'message' buffer is released in ogs_sbi_parse_request() */ ogs_error("cannot parse HTTP message"); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, NULL, "cannot parse HTTP message", NULL); break; } if (strcmp(message.h.api.version, OGS_SBI_API_V1) != 0) { ogs_error("Not supported version [%s]", message.h.api.version); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, &message, "Not supported version", NULL); ogs_sbi_message_free(&message); break; @@ -96,13 +96,13 @@ void ausf_state_operational(ogs_fsm_t *s, ausf_event_t *e) CASE(OGS_SBI_RESOURCE_NAME_NF_STATUS_NOTIFY) SWITCH(message.h.method) CASE(OGS_SBI_HTTP_METHOD_POST) - ausf_nnrf_handle_nf_status_notify(session, &message); + ausf_nnrf_handle_nf_status_notify(stream, &message); break; DEFAULT ogs_error("Invalid HTTP method [%s]", message.h.method); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_FORBIDDEN, &message, "Invalid HTTP method", message.h.method); @@ -112,7 +112,7 @@ void ausf_state_operational(ogs_fsm_t *s, ausf_event_t *e) DEFAULT ogs_error("Invalid resource name [%s]", message.h.resource.component[0]); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, &message, "Unknown resource name", message.h.resource.component[0]); @@ -144,7 +144,7 @@ void ausf_state_operational(ogs_fsm_t *s, ausf_event_t *e) if (!ausf_ue) { ogs_error("Not found [%s]", message.h.method); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_NOT_FOUND, &message, "Not found", message.h.method); break; @@ -163,7 +163,7 @@ void ausf_state_operational(ogs_fsm_t *s, ausf_event_t *e) DEFAULT ogs_error("Invalid API name [%s]", message.h.service.name); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, &message, "Invalid API name", message.h.resource.component[0]); END @@ -285,7 +285,7 @@ void ausf_state_operational(ogs_fsm_t *s, ausf_event_t *e) e->ausf_ue = ausf_ue; e->sbi.message = &message; - e->sbi.session = sbi_xact->assoc_session; + e->sbi.data = sbi_xact->assoc_stream; ogs_sbi_xact_remove(sbi_xact); @@ -338,13 +338,13 @@ void ausf_state_operational(ogs_fsm_t *s, ausf_event_t *e) sbi_xact = e->sbi.data; ogs_assert(sbi_xact); - session = sbi_xact->assoc_session; - ogs_assert(session); + stream = sbi_xact->assoc_stream; + ogs_assert(stream); ogs_sbi_xact_remove(sbi_xact); ogs_error("Cannot receive SBI message"); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_GATEWAY_TIMEOUT, NULL, "Cannot receive SBI message", NULL); break; diff --git a/src/ausf/event.h b/src/ausf/event.h index 69326a063..b2ac9ea2f 100644 --- a/src/ausf/event.h +++ b/src/ausf/event.h @@ -26,8 +26,6 @@ extern "C" { #endif -typedef struct ogs_sbi_server_s ogs_sbi_server_t; -typedef struct ogs_sbi_session_s ogs_sbi_session_t; typedef struct ogs_sbi_request_s ogs_sbi_request_t; typedef struct ogs_sbi_response_s ogs_sbi_response_t; typedef struct ogs_sbi_message_s ogs_sbi_message_t; @@ -52,12 +50,7 @@ typedef struct ausf_event_s { int timer_id; struct { - /* OGS_EVT_SBI_SERVER */ ogs_sbi_request_t *request; - ogs_sbi_session_t *session; - ogs_sbi_server_t *server; - - /* OGS_EVT_SBI_CLIENT */ ogs_sbi_response_t *response; void *data; diff --git a/src/ausf/nausf-handler.c b/src/ausf/nausf-handler.c index 5321476b9..2698acaba 100644 --- a/src/ausf/nausf-handler.c +++ b/src/ausf/nausf-handler.c @@ -22,19 +22,19 @@ #include "nausf-handler.h" bool ausf_nausf_auth_handle_authenticate(ausf_ue_t *ausf_ue, - ogs_sbi_session_t *session, ogs_sbi_message_t *recvmsg) + ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg) { OpenAPI_authentication_info_t *AuthenticationInfo = NULL; char *serving_network_name = NULL; ogs_assert(ausf_ue); - ogs_assert(session); + ogs_assert(stream); ogs_assert(recvmsg); AuthenticationInfo = recvmsg->AuthenticationInfo; if (!AuthenticationInfo) { ogs_error("[%s] No AuthenticationInfo", ausf_ue->suci); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, recvmsg, "[%s] No AuthenticationInfo", ausf_ue->suci); return false; } @@ -42,7 +42,7 @@ bool ausf_nausf_auth_handle_authenticate(ausf_ue_t *ausf_ue, serving_network_name = AuthenticationInfo->serving_network_name; if (!serving_network_name) { ogs_error("[%s] No servingNetworkName", ausf_ue->suci); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, recvmsg, "[%s] No servingNetworkName", ausf_ue->suci); return false; } @@ -51,7 +51,7 @@ bool ausf_nausf_auth_handle_authenticate(ausf_ue_t *ausf_ue, ogs_free(ausf_ue->serving_network_name); ausf_ue->serving_network_name = ogs_strdup(serving_network_name); - ausf_sbi_discover_and_send(OpenAPI_nf_type_UDM, ausf_ue, session, + ausf_sbi_discover_and_send(OpenAPI_nf_type_UDM, ausf_ue, stream, AuthenticationInfo->resynchronization_info, ausf_nudm_ueau_build_get); @@ -59,20 +59,20 @@ bool ausf_nausf_auth_handle_authenticate(ausf_ue_t *ausf_ue, } bool ausf_nausf_auth_handle_authenticate_confirmation(ausf_ue_t *ausf_ue, - ogs_sbi_session_t *session, ogs_sbi_message_t *recvmsg) + ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg) { OpenAPI_confirmation_data_t *ConfirmationData = NULL; char *res_star_string = NULL; uint8_t res_star[OGS_KEYSTRLEN(OGS_MAX_RES_LEN)]; ogs_assert(ausf_ue); - ogs_assert(session); + ogs_assert(stream); ogs_assert(recvmsg); ConfirmationData = recvmsg->ConfirmationData; if (!ConfirmationData) { ogs_error("[%s] No ConfirmationData", ausf_ue->suci); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, recvmsg, "[%s] No ConfirmationData", ausf_ue->suci); return false; } @@ -80,7 +80,7 @@ bool ausf_nausf_auth_handle_authenticate_confirmation(ausf_ue_t *ausf_ue, res_star_string = ConfirmationData->res_star; if (!res_star_string) { ogs_error("[%s] No ConfirmationData.resStar", ausf_ue->suci); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, recvmsg, "[%s] No ConfirmationData.resStar", ausf_ue->suci); return false; } @@ -97,7 +97,7 @@ bool ausf_nausf_auth_handle_authenticate_confirmation(ausf_ue_t *ausf_ue, ausf_ue->auth_result = OpenAPI_auth_result_AUTHENTICATION_SUCCESS; } - ausf_sbi_discover_and_send(OpenAPI_nf_type_UDM, ausf_ue, session, NULL, + ausf_sbi_discover_and_send(OpenAPI_nf_type_UDM, ausf_ue, stream, NULL, ausf_nudm_ueau_build_result_confirmation_inform); return true; diff --git a/src/ausf/nausf-handler.h b/src/ausf/nausf-handler.h index 1e8f22271..6349e94a6 100644 --- a/src/ausf/nausf-handler.h +++ b/src/ausf/nausf-handler.h @@ -27,9 +27,9 @@ extern "C" { #endif bool ausf_nausf_auth_handle_authenticate(ausf_ue_t *ausf_ue, - ogs_sbi_session_t *session, ogs_sbi_message_t *recvmsg); + ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg); bool ausf_nausf_auth_handle_authenticate_confirmation(ausf_ue_t *ausf_ue, - ogs_sbi_session_t *session, ogs_sbi_message_t *recvmsg); + ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg); #ifdef __cplusplus } diff --git a/src/ausf/nf-sm.c b/src/ausf/nf-sm.c index f4d0692e9..101a6bdaf 100644 --- a/src/ausf/nf-sm.c +++ b/src/ausf/nf-sm.c @@ -155,7 +155,7 @@ void ausf_nf_state_will_register(ogs_fsm_t *s, ausf_event_t *e) case AUSF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: client = nf_instance->client; ogs_assert(client); - addr = client->addr; + addr = client->node.addr; ogs_assert(addr); ogs_warn("[%s] Retry to registration with NRF", nf_instance->id); @@ -364,7 +364,7 @@ void ausf_nf_state_exception(ogs_fsm_t *s, ausf_event_t *e) case AUSF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: client = nf_instance->client; ogs_assert(client); - addr = client->addr; + addr = client->node.addr; ogs_assert(addr); ogs_warn("[%s] Retry to registration with NRF", nf_instance->id); diff --git a/src/ausf/nnrf-handler.c b/src/ausf/nnrf-handler.c index 5741b0cba..841bf09d4 100644 --- a/src/ausf/nnrf-handler.c +++ b/src/ausf/nnrf-handler.c @@ -89,7 +89,7 @@ void ausf_nnrf_handle_nf_status_subscribe( } bool ausf_nnrf_handle_nf_status_notify( - ogs_sbi_session_t *session, ogs_sbi_message_t *message) + ogs_sbi_stream_t *stream, ogs_sbi_message_t *message) { ogs_sbi_response_t *response = NULL; OpenAPI_notification_data_t *NotificationData = NULL; @@ -97,13 +97,13 @@ bool ausf_nnrf_handle_nf_status_notify( ogs_sbi_nf_instance_t *nf_instance = NULL; bool handled; - ogs_assert(session); + ogs_assert(stream); ogs_assert(message); NotificationData = message->NotificationData; if (!NotificationData) { ogs_error("No NotificationData"); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, message, "No NotificationData", NULL); return false; } @@ -111,21 +111,21 @@ bool ausf_nnrf_handle_nf_status_notify( NFProfile = NotificationData->nf_profile; if (!NFProfile) { ogs_error("No NFProfile"); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, message, "No NFProfile", NULL); return false; } if (!NFProfile->nf_instance_id) { ogs_error("No NFProfile.NFInstanceId"); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, message, "No NFProfile", "NFInstanceId"); return false; } if (!NFProfile->nf_instance_id) { ogs_error("No NFProfile.NFInstanceId"); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, message, "No NFProfile", "NFInstanceId"); return false; } @@ -133,7 +133,7 @@ bool ausf_nnrf_handle_nf_status_notify( if (NF_INSTANCE_IS_SELF(NFProfile->nf_instance_id)) { ogs_warn("The notification is not allowed [%s]", NFProfile->nf_instance_id); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_FORBIDDEN, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_FORBIDDEN, message, "The notification is not allowed", NFProfile->nf_instance_id); return false; @@ -159,7 +159,7 @@ bool ausf_nnrf_handle_nf_status_notify( } handled = ogs_sbi_nnrf_handle_nf_profile( - nf_instance, NFProfile, session, message); + nf_instance, NFProfile, stream, message); if (!handled) { AUSF_NF_INSTANCE_CLEAR("NRF-notify", nf_instance); return false; @@ -170,7 +170,7 @@ bool ausf_nnrf_handle_nf_status_notify( handled = ogs_sbi_client_associate(nf_instance); if (!handled) { ogs_error("[%s] Cannot associate NF EndPoint", nf_instance->id); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, message, "Cannot find NF EndPoint", nf_instance->id); AUSF_NF_INSTANCE_CLEAR("NRF-notify", nf_instance); @@ -184,7 +184,7 @@ bool ausf_nnrf_handle_nf_status_notify( AUSF_NF_INSTANCE_CLEAR("NRF-notify", nf_instance); } else { ogs_warn("[%s] (NRF-notify) Not found", NFProfile->nf_instance_id); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_NOT_FOUND, message, "Not found", message->h.resource.component[1]); return false; @@ -194,7 +194,7 @@ bool ausf_nnrf_handle_nf_status_notify( NotificationData->event); ogs_error("Not supported event [%d:%s]", NotificationData->event, eventstr ? eventstr : "Unknown"); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, message, "Not supported event", eventstr ? eventstr : "Unknown"); return false; @@ -202,7 +202,7 @@ bool ausf_nnrf_handle_nf_status_notify( response = ogs_sbi_build_response(message, OGS_SBI_HTTP_STATUS_NO_CONTENT); ogs_assert(response); - ogs_sbi_server_send_response(session, response); + ogs_sbi_server_send_response(stream, response); return true; } @@ -212,7 +212,7 @@ void ausf_nnrf_handle_nf_discover( { ogs_sbi_object_t *sbi_object = NULL; ogs_sbi_nf_instance_t *nf_instance = NULL; - ogs_sbi_session_t *session = NULL; + ogs_sbi_stream_t *stream = NULL; OpenAPI_search_result_t *SearchResult = NULL; OpenAPI_lnode_t *node = NULL; @@ -221,8 +221,8 @@ void ausf_nnrf_handle_nf_discover( ogs_assert(xact); sbi_object = xact->sbi_object; ogs_assert(sbi_object); - session = xact->assoc_session; - ogs_assert(session); + stream = xact->assoc_stream; + ogs_assert(stream); ogs_assert(message); SearchResult = message->SearchResult; diff --git a/src/ausf/nnrf-handler.h b/src/ausf/nnrf-handler.h index 15b376233..ce03e8f1f 100644 --- a/src/ausf/nnrf-handler.h +++ b/src/ausf/nnrf-handler.h @@ -32,7 +32,7 @@ void ausf_nnrf_handle_nf_status_subscribe( ogs_sbi_subscription_t *subscription, ogs_sbi_message_t *message); bool ausf_nnrf_handle_nf_status_notify( - ogs_sbi_session_t *session, ogs_sbi_message_t *message); + ogs_sbi_stream_t *stream, ogs_sbi_message_t *message); void ausf_nnrf_handle_nf_discover( ogs_sbi_xact_t *xact, ogs_sbi_message_t *message); diff --git a/src/ausf/nudm-handler.c b/src/ausf/nudm-handler.c index 67444eca3..fbb072056 100644 --- a/src/ausf/nudm-handler.c +++ b/src/ausf/nudm-handler.c @@ -33,7 +33,7 @@ static const char *links_member_name(OpenAPI_auth_type_e auth_type) } bool ausf_nudm_ueau_handle_get(ausf_ue_t *ausf_ue, - ogs_sbi_session_t *session, ogs_sbi_message_t *recvmsg) + ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg) { ogs_sbi_server_t *server = NULL; @@ -51,8 +51,8 @@ bool ausf_nudm_ueau_handle_get(ausf_ue_t *ausf_ue, OpenAPI_links_value_schema_t LinksValueSchemeValue; ogs_assert(ausf_ue); - ogs_assert(session); - server = ogs_sbi_session_get_server(session); + ogs_assert(stream); + server = ogs_sbi_server_from_stream(stream); ogs_assert(server); ogs_assert(recvmsg); @@ -60,7 +60,7 @@ bool ausf_nudm_ueau_handle_get(ausf_ue_t *ausf_ue, AuthenticationInfoResult = recvmsg->AuthenticationInfoResult; if (!AuthenticationInfoResult) { ogs_error("[%s] No AuthenticationInfoResult", ausf_ue->suci); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_INTERNAL_SERVER_ERROR, recvmsg, "No AuthenticationInfoResult", ausf_ue->suci); return false; @@ -70,7 +70,7 @@ bool ausf_nudm_ueau_handle_get(ausf_ue_t *ausf_ue, OpenAPI_auth_type_5G_AKA) { ogs_error("[%s] Not supported Auth Method [%d]", ausf_ue->suci, AuthenticationInfoResult->auth_type); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_FORBIDDEN, recvmsg, "Not supported Auth Method", ausf_ue->suci); return false; @@ -80,7 +80,7 @@ bool ausf_nudm_ueau_handle_get(ausf_ue_t *ausf_ue, AuthenticationInfoResult->authentication_vector; if (!AuthenticationVector) { ogs_error("[%s] No AuthenticationVector", ausf_ue->suci); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_INTERNAL_SERVER_ERROR, recvmsg, "No AuthenticationVector", ausf_ue->suci); return false; @@ -89,7 +89,7 @@ bool ausf_nudm_ueau_handle_get(ausf_ue_t *ausf_ue, if (AuthenticationVector->av_type != OpenAPI_av_type_5G_HE_AKA) { ogs_error("[%s] Not supported Auth Method [%d]", ausf_ue->suci, AuthenticationVector->av_type); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_FORBIDDEN, recvmsg, "Not supported Auth Method", ausf_ue->suci); return false; @@ -97,7 +97,7 @@ bool ausf_nudm_ueau_handle_get(ausf_ue_t *ausf_ue, if (!AuthenticationVector->rand) { ogs_error("[%s] No AuthenticationVector.rand", ausf_ue->suci); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_INTERNAL_SERVER_ERROR, recvmsg, "No AuthenticationVector.rand", ausf_ue->suci); return false; @@ -106,7 +106,7 @@ bool ausf_nudm_ueau_handle_get(ausf_ue_t *ausf_ue, if (!AuthenticationVector->xres_star) { ogs_error("[%s] No AuthenticationVector.xresStar", ausf_ue->suci); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_INTERNAL_SERVER_ERROR, recvmsg, "No AuthenticationVector.xresStar", ausf_ue->suci); return false; @@ -114,7 +114,7 @@ bool ausf_nudm_ueau_handle_get(ausf_ue_t *ausf_ue, if (!AuthenticationVector->autn) { ogs_error("[%s] No AuthenticationVector.autn", ausf_ue->suci); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_INTERNAL_SERVER_ERROR, recvmsg, "No AuthenticationVector.autn", ausf_ue->suci); return false; @@ -122,7 +122,7 @@ bool ausf_nudm_ueau_handle_get(ausf_ue_t *ausf_ue, if (!AuthenticationVector->kausf) { ogs_error("[%s] No AuthenticationVector.kausf", ausf_ue->suci); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_INTERNAL_SERVER_ERROR, recvmsg, "No AuthenticationVector.kausf", ausf_ue->suci); return false; @@ -194,7 +194,7 @@ bool ausf_nudm_ueau_handle_get(ausf_ue_t *ausf_ue, response = ogs_sbi_build_response(&sendmsg, OGS_SBI_HTTP_STATUS_CREATED); ogs_assert(response); - ogs_sbi_server_send_response(session, response); + ogs_sbi_server_send_response(stream, response); OpenAPI_list_free(UeAuthenticationCtx._links); OpenAPI_map_free(LinksValueScheme); @@ -206,7 +206,7 @@ bool ausf_nudm_ueau_handle_get(ausf_ue_t *ausf_ue, } bool ausf_nudm_ueau_handle_result_confirmation_inform(ausf_ue_t *ausf_ue, - ogs_sbi_session_t *session, ogs_sbi_message_t *recvmsg) + ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg) { ogs_sbi_message_t sendmsg; ogs_sbi_response_t *response = NULL; @@ -217,21 +217,21 @@ bool ausf_nudm_ueau_handle_result_confirmation_inform(ausf_ue_t *ausf_ue, OpenAPI_auth_event_t *AuthEvent = NULL; ogs_assert(ausf_ue); - ogs_assert(session); + ogs_assert(stream); ogs_assert(recvmsg); AuthEvent = recvmsg->AuthEvent; if (!AuthEvent) { ogs_error("[%s] No AuthEvent", ausf_ue->suci); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, recvmsg, "No AuthEvent", ausf_ue->suci); return false; } if (!recvmsg->http.location) { ogs_error("[%s] No Location", ausf_ue->suci); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, recvmsg, "No Location", ausf_ue->suci); return false; } @@ -262,7 +262,7 @@ bool ausf_nudm_ueau_handle_result_confirmation_inform(ausf_ue_t *ausf_ue, response = ogs_sbi_build_response(&sendmsg, OGS_SBI_HTTP_STATUS_OK); ogs_assert(response); - ogs_sbi_server_send_response(session, response); + ogs_sbi_server_send_response(stream, response); return true; } diff --git a/src/ausf/nudm-handler.h b/src/ausf/nudm-handler.h index 9837c5879..ee42f3aab 100644 --- a/src/ausf/nudm-handler.h +++ b/src/ausf/nudm-handler.h @@ -27,9 +27,9 @@ extern "C" { #endif bool ausf_nudm_ueau_handle_get(ausf_ue_t *ausf_ue, - ogs_sbi_session_t *session, ogs_sbi_message_t *recvmsg); + ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg); bool ausf_nudm_ueau_handle_result_confirmation_inform(ausf_ue_t *ausf_ue, - ogs_sbi_session_t *session, ogs_sbi_message_t *recvmsg); + ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg); #ifdef __cplusplus } #endif diff --git a/src/ausf/sbi-path.c b/src/ausf/sbi-path.c index f73c35d6a..c30190833 100644 --- a/src/ausf/sbi-path.c +++ b/src/ausf/sbi-path.c @@ -19,21 +19,19 @@ #include "sbi-path.h" -static int server_cb(ogs_sbi_server_t *server, - ogs_sbi_session_t *session, ogs_sbi_request_t *request) +static int server_cb(ogs_sbi_request_t *request, void *data) { ausf_event_t *e = NULL; int rv; - ogs_assert(session); ogs_assert(request); + ogs_assert(data); e = ausf_event_new(AUSF_EVT_SBI_SERVER); ogs_assert(e); - e->sbi.server = server; - e->sbi.session = session; e->sbi.request = request; + e->sbi.data = data; rv = ogs_queue_push(ogs_app()->queue, e); if (rv != OGS_OK) { @@ -120,26 +118,26 @@ void ausf_sbi_send(ogs_sbi_nf_instance_t *nf_instance, ogs_sbi_xact_t *xact) } void ausf_sbi_discover_and_send(OpenAPI_nf_type_e target_nf_type, - ausf_ue_t *ausf_ue, ogs_sbi_session_t *session, void *data, + ausf_ue_t *ausf_ue, ogs_sbi_stream_t *stream, void *data, ogs_sbi_request_t *(*build)(ausf_ue_t *ausf_ue, void *data)) { ogs_sbi_xact_t *xact = NULL; ogs_assert(target_nf_type); ogs_assert(ausf_ue); - ogs_assert(session); + ogs_assert(stream); ogs_assert(build); xact = ogs_sbi_xact_add(target_nf_type, &ausf_ue->sbi, data, (ogs_sbi_build_f)build, ausf_timer_sbi_client_wait_expire); ogs_assert(xact); - xact->assoc_session = session; + xact->assoc_stream = stream; if (ogs_sbi_discover_and_send(xact, (ogs_fsm_handler_t)ausf_nf_state_registered, client_cb) != true) { - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_GATEWAY_TIMEOUT, NULL, "Cannot discover", ausf_ue->suci); } diff --git a/src/ausf/sbi-path.h b/src/ausf/sbi-path.h index a1ddc5e07..b4273c320 100644 --- a/src/ausf/sbi-path.h +++ b/src/ausf/sbi-path.h @@ -31,7 +31,7 @@ void ausf_sbi_close(void); void ausf_sbi_send(ogs_sbi_nf_instance_t *nf_instance, ogs_sbi_xact_t *xact); void ausf_sbi_discover_and_send(OpenAPI_nf_type_e target_nf_type, - ausf_ue_t *ausf_ue, ogs_sbi_session_t *session, void *data, + ausf_ue_t *ausf_ue, ogs_sbi_stream_t *stream, void *data, ogs_sbi_request_t *(*build)(ausf_ue_t *ausf_ue, void *data)); #ifdef __cplusplus diff --git a/src/ausf/ue-sm.c b/src/ausf/ue-sm.c index 20183aafa..c80925cd3 100644 --- a/src/ausf/ue-sm.c +++ b/src/ausf/ue-sm.c @@ -55,8 +55,7 @@ void ausf_ue_state_operational(ogs_fsm_t *s, ausf_event_t *e) bool handled; ausf_ue_t *ausf_ue = NULL; - ogs_sbi_server_t *server = NULL; - ogs_sbi_session_t *session = NULL; + ogs_sbi_stream_t *stream = NULL; ogs_sbi_message_t *message = NULL; ogs_assert(s); @@ -77,15 +76,13 @@ void ausf_ue_state_operational(ogs_fsm_t *s, ausf_event_t *e) case AUSF_EVT_SBI_SERVER: message = e->sbi.message; ogs_assert(message); - session = e->sbi.session; - ogs_assert(session); - server = e->sbi.server; - ogs_assert(server); + stream = e->sbi.data; + ogs_assert(stream); SWITCH(message->h.method) CASE(OGS_SBI_HTTP_METHOD_POST) handled = ausf_nausf_auth_handle_authenticate( - ausf_ue, session, message); + ausf_ue, stream, message); if (!handled) { ogs_error("[%s] Cannot handle SBI message", ausf_ue->suci); @@ -94,7 +91,7 @@ void ausf_ue_state_operational(ogs_fsm_t *s, ausf_event_t *e) break; CASE(OGS_SBI_HTTP_METHOD_PUT) handled = ausf_nausf_auth_handle_authenticate_confirmation( - ausf_ue, session, message); + ausf_ue, stream, message); if (!handled) { ogs_error("[%s] Cannot handle SBI message", ausf_ue->suci); @@ -104,7 +101,7 @@ void ausf_ue_state_operational(ogs_fsm_t *s, ausf_event_t *e) DEFAULT ogs_error("[%s] Invalid HTTP method [%s]", ausf_ue->suci, message->h.method); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_FORBIDDEN, message, "Invalid HTTP method", message->h.method); END @@ -117,8 +114,8 @@ void ausf_ue_state_operational(ogs_fsm_t *s, ausf_event_t *e) ausf_ue = e->ausf_ue; ogs_assert(ausf_ue); - session = e->sbi.session; - ogs_assert(session); + stream = e->sbi.data; + ogs_assert(stream); SWITCH(message->h.service.name) CASE(OGS_SBI_SERVICE_NAME_NUDM_UEAU) @@ -132,19 +129,19 @@ void ausf_ue_state_operational(ogs_fsm_t *s, ausf_event_t *e) ausf_ue->suci, message->res_status); } ogs_sbi_server_send_error( - session, message->res_status, + stream, message->res_status, NULL, "HTTP response error", ausf_ue->suci); break; } SWITCH(message->h.resource.component[1]) CASE(OGS_SBI_RESOURCE_NAME_SECURITY_INFORMATION) - ausf_nudm_ueau_handle_get(ausf_ue, session, message); + ausf_nudm_ueau_handle_get(ausf_ue, stream, message); break; CASE(OGS_SBI_RESOURCE_NAME_AUTH_EVENTS) ausf_nudm_ueau_handle_result_confirmation_inform( - ausf_ue, session, message); + ausf_ue, stream, message); break; DEFAULT diff --git a/src/main.c b/src/main.c index 2ff995294..1a76ddb84 100644 --- a/src/main.c +++ b/src/main.c @@ -24,11 +24,9 @@ #include "ogs-app.h" #include "version.h" -static const char *version = "Open5GS daemon " OPEN5GS_VERSION; - static void show_version(void) { - printf("%s\n\n", version); + printf("Open5GS %s\n\n", OPEN5GS_VERSION); } static void show_help(const char *name) @@ -47,23 +45,6 @@ static void show_help(const char *name) "\n", name); } -static void show_running_config(void) -{ - ogs_log_print(OGS_LOG_INFO, "%s\n\n", version); - - ogs_info("Configuration: '%s'", ogs_app()->file); - - if (ogs_app()->logger.file) { - ogs_info("File Logging: '%s'", ogs_app()->logger.file); - - if (ogs_app()->logger.level) - ogs_info("LOG-LEVEL: '%s'", ogs_app()->logger.level); - - if (ogs_app()->logger.domain) - ogs_info("LOG-DOMAIN: '%s'", ogs_app()->logger.domain); - } -} - static int check_signal(int signum) { switch (signum) { @@ -203,7 +184,7 @@ int main(int argc, const char *const argv[]) ogs_signal_init(); ogs_setup_signal_thread(); - rv = ogs_app_initialize(DEFAULT_CONFIG_FILENAME, argv_out); + rv = ogs_app_initialize(OPEN5GS_VERSION, DEFAULT_CONFIG_FILENAME, argv_out); if (rv != OGS_OK) { if (rv == OGS_RETRY) return EXIT_SUCCESS; @@ -212,8 +193,6 @@ int main(int argc, const char *const argv[]) return OGS_ERROR; } - show_running_config(); - rv = app_initialize(argv_out); if (rv != OGS_OK) { if (rv == OGS_RETRY) diff --git a/src/nrf/event.h b/src/nrf/event.h index 89b22e356..cbddb2827 100644 --- a/src/nrf/event.h +++ b/src/nrf/event.h @@ -26,8 +26,6 @@ extern "C" { #endif -typedef struct ogs_sbi_server_s ogs_sbi_server_t; -typedef struct ogs_sbi_session_s ogs_sbi_session_t; typedef struct ogs_sbi_request_s ogs_sbi_request_t; typedef struct ogs_sbi_response_s ogs_sbi_response_t; typedef struct ogs_sbi_message_s ogs_sbi_message_t; @@ -50,12 +48,7 @@ typedef struct nrf_event_s { int timer_id; struct { - /* OGS_EVT_SBI_SERVER */ ogs_sbi_request_t *request; - ogs_sbi_session_t *session; - ogs_sbi_server_t *server; - - /* OGS_EVT_SBI_CLIENT */ ogs_sbi_response_t *response; void *data; diff --git a/src/nrf/nf-sm.c b/src/nrf/nf-sm.c index a364752ff..018891a50 100644 --- a/src/nrf/nf-sm.c +++ b/src/nrf/nf-sm.c @@ -86,7 +86,7 @@ void nrf_nf_state_will_register(ogs_fsm_t *s, nrf_event_t *e) bool handled; ogs_sbi_nf_instance_t *nf_instance = NULL; - ogs_sbi_session_t *session = NULL; + ogs_sbi_stream_t *stream = NULL; ogs_sbi_message_t *message = NULL; ogs_assert(s); @@ -107,8 +107,8 @@ void nrf_nf_state_will_register(ogs_fsm_t *s, nrf_event_t *e) case NRF_EVT_SBI_SERVER: message = e->sbi.message; ogs_assert(message); - session = e->sbi.session; - ogs_assert(session); + stream = e->sbi.data; + ogs_assert(stream); SWITCH(message->h.service.name) CASE(OGS_SBI_SERVICE_NAME_NNRF_NFM) @@ -120,7 +120,7 @@ void nrf_nf_state_will_register(ogs_fsm_t *s, nrf_event_t *e) CASE(OGS_SBI_HTTP_METHOD_PUT) handled = nrf_nnrf_handle_nf_register( - nf_instance, session, message); + nf_instance, stream, message); if (handled == false) OGS_FSM_TRAN(s, nrf_nf_state_exception); break; @@ -128,7 +128,7 @@ void nrf_nf_state_will_register(ogs_fsm_t *s, nrf_event_t *e) DEFAULT ogs_error("[%s] Invalid HTTP method [%s]", nf_instance->id, message->h.method); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_MEHTOD_NOT_ALLOWED, message, "Invalid HTTP method", message->h.method); END @@ -137,7 +137,7 @@ void nrf_nf_state_will_register(ogs_fsm_t *s, nrf_event_t *e) DEFAULT ogs_error("[%s] Invalid resource name [%s]", nf_instance->id, message->h.resource.component[0]); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_MEHTOD_NOT_ALLOWED, message, "Invalid resource name", message->h.resource.component[0]); @@ -147,7 +147,7 @@ void nrf_nf_state_will_register(ogs_fsm_t *s, nrf_event_t *e) DEFAULT ogs_error("[%s] Invalid API name [%s]", nf_instance->id, message->h.service.name); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_MEHTOD_NOT_ALLOWED, message, "Invalid resource name", message->h.service.name); END @@ -158,7 +158,7 @@ void nrf_nf_state_will_register(ogs_fsm_t *s, nrf_event_t *e) default: ogs_error("[%s] Unknown event %s", nf_instance->id, nrf_event_get_name(e)); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_INTERNAL_SERVER_ERROR, message, "Unknown event", nrf_event_get_name(e)); OGS_FSM_TRAN(s, nrf_nf_state_exception); @@ -171,7 +171,7 @@ void nrf_nf_state_registered(ogs_fsm_t *s, nrf_event_t *e) bool handled; ogs_sbi_nf_instance_t *nf_instance = NULL; - ogs_sbi_session_t *session = NULL; + ogs_sbi_stream_t *stream = NULL; ogs_sbi_message_t *message = NULL; ogs_sbi_response_t *response = NULL; @@ -210,8 +210,8 @@ void nrf_nf_state_registered(ogs_fsm_t *s, nrf_event_t *e) case NRF_EVT_SBI_SERVER: message = e->sbi.message; ogs_assert(message); - session = e->sbi.session; - ogs_assert(session); + stream = e->sbi.data; + ogs_assert(stream); SWITCH(message->h.service.name) CASE(OGS_SBI_SERVICE_NAME_NNRF_NFM) @@ -231,7 +231,7 @@ void nrf_nf_state_registered(ogs_fsm_t *s, nrf_event_t *e) } handled = nrf_nnrf_handle_nf_update( - nf_instance, session, message); + nf_instance, stream, message); if (handled == false) OGS_FSM_TRAN(s, nrf_nf_state_exception); break; @@ -240,14 +240,14 @@ void nrf_nf_state_registered(ogs_fsm_t *s, nrf_event_t *e) response = ogs_sbi_build_response( message, OGS_SBI_HTTP_STATUS_NO_CONTENT); ogs_assert(response); - ogs_sbi_server_send_response(session, response); + ogs_sbi_server_send_response(stream, response); OGS_FSM_TRAN(s, nrf_nf_state_de_registered); break; DEFAULT ogs_error("[%s] Invalid HTTP method [%s]", nf_instance->id, message->h.method); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_MEHTOD_NOT_ALLOWED, message, "Invalid HTTP method", message->h.method); END @@ -256,7 +256,7 @@ void nrf_nf_state_registered(ogs_fsm_t *s, nrf_event_t *e) DEFAULT ogs_error("[%s] Invalid resource name [%s]", nf_instance->id, message->h.resource.component[0]); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_MEHTOD_NOT_ALLOWED, message, "Invalid resource name", message->h.resource.component[0]); @@ -266,7 +266,7 @@ void nrf_nf_state_registered(ogs_fsm_t *s, nrf_event_t *e) DEFAULT ogs_error("[%s] Invalid API name [%s]", nf_instance->id, message->h.service.name); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_MEHTOD_NOT_ALLOWED, message, "Invalid resource name", message->h.service.name); END @@ -275,7 +275,7 @@ void nrf_nf_state_registered(ogs_fsm_t *s, nrf_event_t *e) default: ogs_error("[%s] Unknown event %s", nf_instance->id, nrf_event_get_name(e)); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_INTERNAL_SERVER_ERROR, message, "Unknown event", nrf_event_get_name(e)); OGS_FSM_TRAN(s, nrf_nf_state_exception); diff --git a/src/nrf/nnrf-handler.c b/src/nrf/nnrf-handler.c index 6c964d72b..01005d5af 100644 --- a/src/nrf/nnrf-handler.c +++ b/src/nrf/nnrf-handler.c @@ -20,7 +20,7 @@ #include "nnrf-handler.h" bool nrf_nnrf_handle_nf_register(ogs_sbi_nf_instance_t *nf_instance, - ogs_sbi_session_t *session, ogs_sbi_message_t *message) + ogs_sbi_stream_t *stream, ogs_sbi_message_t *message) { int status; bool handled; @@ -29,20 +29,20 @@ bool nrf_nnrf_handle_nf_register(ogs_sbi_nf_instance_t *nf_instance, OpenAPI_nf_profile_t *NFProfile = NULL; ogs_assert(nf_instance); - ogs_assert(session); + ogs_assert(stream); ogs_assert(message); NFProfile = message->NFProfile; if (!NFProfile) { ogs_error("No NFProfile"); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, message, "No NFProfile", NULL); return false; } /* ogs_sbi_nnrf_handle_nf_profile() sends error response */ handled = ogs_sbi_nnrf_handle_nf_profile( - nf_instance, NFProfile, session, message); + nf_instance, NFProfile, stream, message); if (!handled) return false; if (OGS_FSM_CHECK(&nf_instance->sm, nrf_nf_state_will_register)) { @@ -55,31 +55,31 @@ bool nrf_nnrf_handle_nf_register(ogs_sbi_nf_instance_t *nf_instance, response = ogs_sbi_build_response(message, status); ogs_assert(response); - ogs_sbi_server_send_response(session, response); + ogs_sbi_server_send_response(stream, response); return true; } bool nrf_nnrf_handle_nf_update(ogs_sbi_nf_instance_t *nf_instance, - ogs_sbi_session_t *session, ogs_sbi_message_t *message) + ogs_sbi_stream_t *stream, ogs_sbi_message_t *message) { ogs_sbi_response_t *response = NULL; OpenAPI_list_t *PatchItemList = NULL; OpenAPI_lnode_t *node; ogs_assert(nf_instance); - ogs_assert(session); + ogs_assert(stream); ogs_assert(message); SWITCH(message->h.method) CASE(OGS_SBI_HTTP_METHOD_PUT) return nrf_nnrf_handle_nf_register( - nf_instance, session, message); + nf_instance, stream, message); CASE(OGS_SBI_HTTP_METHOD_PATCH) PatchItemList = message->PatchItemList; if (!PatchItemList) { - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, message, "No PatchItemList Array", NULL); return false; } @@ -87,7 +87,7 @@ bool nrf_nnrf_handle_nf_update(ogs_sbi_nf_instance_t *nf_instance, OpenAPI_list_for_each(PatchItemList, node) { OpenAPI_patch_item_t *patch_item = node->data; if (!patch_item) { - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, message, "No PatchItemList", NULL); return false; @@ -97,7 +97,7 @@ bool nrf_nnrf_handle_nf_update(ogs_sbi_nf_instance_t *nf_instance, response = ogs_sbi_build_response( message, OGS_SBI_HTTP_STATUS_NO_CONTENT); ogs_assert(response); - ogs_sbi_server_send_response(session, response); + ogs_sbi_server_send_response(stream, response); break; DEFAULT @@ -110,7 +110,7 @@ bool nrf_nnrf_handle_nf_update(ogs_sbi_nf_instance_t *nf_instance, } bool nrf_nnrf_handle_nf_status_subscribe( - ogs_sbi_session_t *session, ogs_sbi_message_t *message) + ogs_sbi_stream_t *stream, ogs_sbi_message_t *message) { int status; ogs_sbi_response_t *response = NULL; @@ -122,18 +122,18 @@ bool nrf_nnrf_handle_nf_status_subscribe( ogs_uuid_t uuid; char id[OGS_UUID_FORMATTED_LENGTH + 1]; - ogs_assert(session); + ogs_assert(stream); ogs_assert(message); SubscriptionData = message->SubscriptionData; if (!SubscriptionData) { - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, message, "No SubscriptionData", NULL); return false; } if (!SubscriptionData->nf_status_notification_uri) { - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, message, "No SubscriptionData", "NFStatusNotificationURL"); return false; } @@ -163,7 +163,7 @@ bool nrf_nnrf_handle_nf_status_subscribe( addr = ogs_sbi_getaddr_from_uri(subscription->notification_uri); if (!addr) { - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, message, "Invalid URI", subscription->notification_uri); ogs_sbi_subscription_remove(subscription); return false; @@ -195,16 +195,16 @@ bool nrf_nnrf_handle_nf_status_subscribe( response = ogs_sbi_build_response(message, status); ogs_assert(response); - ogs_sbi_server_send_response(session, response); + ogs_sbi_server_send_response(stream, response); return true; } bool nrf_nnrf_handle_nf_status_unsubscribe( - ogs_sbi_session_t *session, ogs_sbi_message_t *message) + ogs_sbi_stream_t *stream, ogs_sbi_message_t *message) { ogs_sbi_subscription_t *subscription = NULL; - ogs_assert(session); + ogs_assert(stream); ogs_assert(message); subscription = ogs_sbi_subscription_find(message->h.resource.component[1]); @@ -215,10 +215,10 @@ bool nrf_nnrf_handle_nf_status_unsubscribe( response = ogs_sbi_build_response( message, OGS_SBI_HTTP_STATUS_NO_CONTENT); ogs_assert(response); - ogs_sbi_server_send_response(session, response); + ogs_sbi_server_send_response(stream, response); } else { ogs_error("Not found [%s]", message->h.resource.component[1]); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_NOT_FOUND, message, "Not found", message->h.resource.component[1]); } @@ -227,7 +227,7 @@ bool nrf_nnrf_handle_nf_status_unsubscribe( } bool nrf_nnrf_handle_nf_list_retrieval( - ogs_sbi_session_t *session, ogs_sbi_message_t *recvmsg) + ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg) { ogs_sbi_message_t sendmsg; ogs_sbi_server_t *server = NULL; @@ -238,8 +238,8 @@ bool nrf_nnrf_handle_nf_list_retrieval( ogs_sbi_links_t *links = NULL; OpenAPI_lnode_t *node = NULL; - ogs_assert(session); - server = ogs_sbi_session_get_server(session); + ogs_assert(stream); + server = ogs_sbi_server_from_stream(stream); ogs_assert(recvmsg); links = ogs_calloc(1, sizeof(*links)); @@ -274,7 +274,7 @@ bool nrf_nnrf_handle_nf_list_retrieval( response = ogs_sbi_build_response(&sendmsg, OGS_SBI_HTTP_STATUS_OK); ogs_assert(response); - ogs_sbi_server_send_response(session, response); + ogs_sbi_server_send_response(stream, response); OpenAPI_list_for_each(links->items, node) { if (!node->data) continue; @@ -288,7 +288,7 @@ bool nrf_nnrf_handle_nf_list_retrieval( } bool nrf_nnrf_handle_nf_profile_retrieval( - ogs_sbi_session_t *session, ogs_sbi_message_t *recvmsg) + ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg) { ogs_sbi_message_t sendmsg; ogs_sbi_response_t *response = NULL; @@ -296,14 +296,14 @@ bool nrf_nnrf_handle_nf_profile_retrieval( OpenAPI_nf_profile_t *NFProfile = NULL; - ogs_assert(session); + ogs_assert(stream); ogs_assert(recvmsg); ogs_assert(recvmsg->h.resource.component[1]); nf_instance = ogs_sbi_nf_instance_find(recvmsg->h.resource.component[1]); if (!nf_instance) { ogs_error("Not found [%s]", recvmsg->h.resource.component[1]); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_NOT_FOUND, recvmsg, "Not found", recvmsg->h.resource.component[1]); return false; @@ -317,7 +317,7 @@ bool nrf_nnrf_handle_nf_profile_retrieval( response = ogs_sbi_build_response(&sendmsg, OGS_SBI_HTTP_STATUS_OK); ogs_assert(response); - ogs_sbi_server_send_response(session, response); + ogs_sbi_server_send_response(stream, response); ogs_sbi_nnrf_free_nf_profile(NFProfile); @@ -325,7 +325,7 @@ bool nrf_nnrf_handle_nf_profile_retrieval( } bool nrf_nnrf_handle_nf_discover( - ogs_sbi_session_t *session, ogs_sbi_message_t *recvmsg) + ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg) { ogs_sbi_message_t sendmsg; ogs_sbi_response_t *response = NULL; @@ -335,18 +335,18 @@ bool nrf_nnrf_handle_nf_discover( OpenAPI_lnode_t *node = NULL; int i; - ogs_assert(session); + ogs_assert(stream); ogs_assert(recvmsg); if (!recvmsg->param.target_nf_type) { ogs_error("No target-nf-type [%s]", recvmsg->h.uri); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, recvmsg, "No target-nf-type", NULL); return false; } if (!recvmsg->param.requester_nf_type) { ogs_error("No requester-nf-type [%s]", recvmsg->h.uri); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, recvmsg, "No requester-nf-type", NULL); return false; } @@ -401,7 +401,7 @@ bool nrf_nnrf_handle_nf_discover( response = ogs_sbi_build_response(&sendmsg, OGS_SBI_HTTP_STATUS_OK); ogs_assert(response); - ogs_sbi_server_send_response(session, response); + ogs_sbi_server_send_response(stream, response); OpenAPI_list_for_each(SearchResult->nf_instances, node) { OpenAPI_nf_profile_t *NFProfile = NULL; diff --git a/src/nrf/nnrf-handler.h b/src/nrf/nnrf-handler.h index 8d76f5f2d..24094ae5b 100644 --- a/src/nrf/nnrf-handler.h +++ b/src/nrf/nnrf-handler.h @@ -28,22 +28,22 @@ extern "C" { #endif bool nrf_nnrf_handle_nf_register(ogs_sbi_nf_instance_t *nf_instance, - ogs_sbi_session_t *session, ogs_sbi_message_t *message); + ogs_sbi_stream_t *stream, ogs_sbi_message_t *message); bool nrf_nnrf_handle_nf_update(ogs_sbi_nf_instance_t *nf_instance, - ogs_sbi_session_t *session, ogs_sbi_message_t *message); + ogs_sbi_stream_t *stream, ogs_sbi_message_t *message); bool nrf_nnrf_handle_nf_status_subscribe( - ogs_sbi_session_t *session, ogs_sbi_message_t *message); + ogs_sbi_stream_t *stream, ogs_sbi_message_t *message); bool nrf_nnrf_handle_nf_status_unsubscribe( - ogs_sbi_session_t *session, ogs_sbi_message_t *message); + ogs_sbi_stream_t *stream, ogs_sbi_message_t *message); bool nrf_nnrf_handle_nf_list_retrieval( - ogs_sbi_session_t *session, ogs_sbi_message_t *message); + ogs_sbi_stream_t *stream, ogs_sbi_message_t *message); bool nrf_nnrf_handle_nf_profile_retrieval( - ogs_sbi_session_t *session, ogs_sbi_message_t *message); + ogs_sbi_stream_t *stream, ogs_sbi_message_t *message); bool nrf_nnrf_handle_nf_discover( - ogs_sbi_session_t *session, ogs_sbi_message_t *message); + ogs_sbi_stream_t *stream, ogs_sbi_message_t *message); #ifdef __cplusplus } diff --git a/src/nrf/nrf-sm.c b/src/nrf/nrf-sm.c index e0f6e5020..5e086376f 100644 --- a/src/nrf/nrf-sm.c +++ b/src/nrf/nrf-sm.c @@ -39,7 +39,7 @@ void nrf_state_final(ogs_fsm_t *s, nrf_event_t *e) void nrf_state_operational(ogs_fsm_t *s, nrf_event_t *e) { int rv; - ogs_sbi_session_t *session = NULL; + ogs_sbi_stream_t *stream = NULL; ogs_sbi_request_t *request = NULL; ogs_sbi_message_t message; ogs_sbi_nf_instance_t *nf_instance = NULL; @@ -66,21 +66,21 @@ void nrf_state_operational(ogs_fsm_t *s, nrf_event_t *e) case NRF_EVT_SBI_SERVER: request = e->sbi.request; ogs_assert(request); - session = e->sbi.session; - ogs_assert(session); + stream = e->sbi.data; + ogs_assert(stream); rv = ogs_sbi_parse_request(&message, request); if (rv != OGS_OK) { /* 'message' buffer is released in ogs_sbi_parse_request() */ ogs_error("cannot parse HTTP message"); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, NULL, "cannot parse HTTP message", NULL); break; } if (strcmp(message.h.api.version, OGS_SBI_API_V1) != 0) { ogs_error("Not supported version [%s]", message.h.api.version); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, &message, "Not supported version", NULL); ogs_sbi_message_free(&message); break; @@ -94,9 +94,9 @@ void nrf_state_operational(ogs_fsm_t *s, nrf_event_t *e) SWITCH(message.h.method) CASE(OGS_SBI_HTTP_METHOD_GET) if (message.h.resource.component[1]) { - nrf_nnrf_handle_nf_profile_retrieval(session, &message); + nrf_nnrf_handle_nf_profile_retrieval(stream, &message); } else { - nrf_nnrf_handle_nf_list_retrieval(session, &message); + nrf_nnrf_handle_nf_list_retrieval(stream, &message); } break; @@ -114,7 +114,7 @@ void nrf_state_operational(ogs_fsm_t *s, nrf_event_t *e) DEFAULT ogs_warn("Not found [%s]", message.h.resource.component[1]); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_NOT_FOUND, &message, "Not found", message.h.resource.component[1]); @@ -147,17 +147,17 @@ void nrf_state_operational(ogs_fsm_t *s, nrf_event_t *e) CASE(OGS_SBI_RESOURCE_NAME_SUBSCRIPTIONS) SWITCH(message.h.method) CASE(OGS_SBI_HTTP_METHOD_POST) - nrf_nnrf_handle_nf_status_subscribe(session, &message); + nrf_nnrf_handle_nf_status_subscribe(stream, &message); break; CASE(OGS_SBI_HTTP_METHOD_DELETE) - nrf_nnrf_handle_nf_status_unsubscribe(session, &message); + nrf_nnrf_handle_nf_status_unsubscribe(stream, &message); break; DEFAULT ogs_error("Invalid HTTP method [%s]", message.h.method); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_FORBIDDEN, &message, "Invalid HTTP method", message.h.method); END @@ -166,7 +166,7 @@ void nrf_state_operational(ogs_fsm_t *s, nrf_event_t *e) DEFAULT ogs_error("Invalid resource name [%s]", message.h.resource.component[0]); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, &message, "Invalid resource name", message.h.resource.component[0]); @@ -180,13 +180,13 @@ void nrf_state_operational(ogs_fsm_t *s, nrf_event_t *e) SWITCH(message.h.method) CASE(OGS_SBI_HTTP_METHOD_GET) - nrf_nnrf_handle_nf_discover(session, &message); + nrf_nnrf_handle_nf_discover(stream, &message); break; DEFAULT ogs_error("Invalid HTTP method [%s]", message.h.method); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_FORBIDDEN, &message, "Invalid HTTP method", message.h.method); END @@ -196,7 +196,7 @@ void nrf_state_operational(ogs_fsm_t *s, nrf_event_t *e) DEFAULT ogs_error("Invalid resource name [%s]", message.h.resource.component[0]); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, &message, "Invalid resource name", message.h.resource.component[0]); @@ -205,7 +205,7 @@ void nrf_state_operational(ogs_fsm_t *s, nrf_event_t *e) DEFAULT ogs_error("Invalid API name [%s]", message.h.service.name); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, &message, "Invalid API name", message.h.resource.component[0]); END diff --git a/src/nrf/sbi-path.c b/src/nrf/sbi-path.c index 1aab75f25..e47e2a1b6 100644 --- a/src/nrf/sbi-path.c +++ b/src/nrf/sbi-path.c @@ -19,21 +19,19 @@ #include "sbi-path.h" -static int server_cb(ogs_sbi_server_t *server, - ogs_sbi_session_t *session, ogs_sbi_request_t *request) +static int server_cb(ogs_sbi_request_t *request, void *data) { nrf_event_t *e = NULL; int rv; - ogs_assert(session); ogs_assert(request); + ogs_assert(data); e = nrf_event_new(NRF_EVT_SBI_SERVER); ogs_assert(e); - e->sbi.server = server; - e->sbi.session = session; e->sbi.request = request; + e->sbi.data = data; rv = ogs_queue_push(ogs_app()->queue, e); if (rv != OGS_OK) { diff --git a/src/smf/event.h b/src/smf/event.h index 2f89cdf73..d99cd1db2 100644 --- a/src/smf/event.h +++ b/src/smf/event.h @@ -33,8 +33,6 @@ typedef struct ogs_pfcp_xact_s ogs_pfcp_xact_t; typedef struct ogs_pfcp_message_s ogs_pfcp_message_t; typedef struct smf_sess_s smf_sess_t; typedef struct smf_upf_s smf_upf_t; -typedef struct ogs_sbi_server_s ogs_sbi_server_t; -typedef struct ogs_sbi_session_s ogs_sbi_session_t; typedef struct ogs_sbi_request_s ogs_sbi_request_t; typedef struct ogs_sbi_response_s ogs_sbi_response_t; typedef struct ogs_sbi_message_s ogs_sbi_message_t; @@ -80,12 +78,7 @@ typedef struct smf_event_s { ogs_pfcp_message_t *pfcp_message; struct { - /* OGS_EVT_SBI_SERVER */ ogs_sbi_request_t *request; - ogs_sbi_session_t *session; - ogs_sbi_server_t *server; - - /* OGS_EVT_SBI_CLIENT */ ogs_sbi_response_t *response; void *data; diff --git a/src/smf/gsm-handler.c b/src/smf/gsm-handler.c index cdeeec807..d354e7bca 100644 --- a/src/smf/gsm-handler.c +++ b/src/smf/gsm-handler.c @@ -25,7 +25,7 @@ #define OGS_LOG_DOMAIN __gsm_log_domain int gsm_handle_pdu_session_establishment_request( - smf_sess_t *sess, ogs_sbi_session_t *session, + smf_sess_t *sess, ogs_sbi_stream_t *stream, ogs_nas_5gs_pdu_session_establishment_request_t * pdu_session_establishment_request) { @@ -37,7 +37,7 @@ int gsm_handle_pdu_session_establishment_request( ogs_nas_ssc_mode_t *ssc_mode = NULL; ogs_assert(sess); - ogs_assert(session); + ogs_assert(stream); ogs_assert(pdu_session_establishment_request); pdu_session_type = &pdu_session_establishment_request->pdu_session_type; @@ -64,7 +64,7 @@ int gsm_handle_pdu_session_establishment_request( extended_protocol_configuration_options); } - smf_sbi_discover_and_send(OpenAPI_nf_type_UDM, sess, session, + smf_sbi_discover_and_send(OpenAPI_nf_type_UDM, sess, stream, (char *)OGS_SBI_RESOURCE_NAME_SM_DATA, smf_nudm_sdm_build_get); return OGS_OK; diff --git a/src/smf/gsm-handler.h b/src/smf/gsm-handler.h index 3a28efadc..6d4c99668 100644 --- a/src/smf/gsm-handler.h +++ b/src/smf/gsm-handler.h @@ -27,7 +27,7 @@ extern "C" { #endif int gsm_handle_pdu_session_establishment_request( - smf_sess_t *sess, ogs_sbi_session_t *session, + smf_sess_t *sess, ogs_sbi_stream_t *stream, ogs_nas_5gs_pdu_session_establishment_request_t * pdu_session_establishment_request); diff --git a/src/smf/gsm-sm.c b/src/smf/gsm-sm.c index 98b14af06..31eef44ad 100644 --- a/src/smf/gsm-sm.c +++ b/src/smf/gsm-sm.c @@ -46,7 +46,7 @@ void smf_gsm_state_operational(ogs_fsm_t *s, smf_event_t *e) ogs_nas_5gs_message_t *nas_message = NULL; - ogs_sbi_session_t *session = NULL; + ogs_sbi_stream_t *stream = NULL; ogs_sbi_message_t *sbi_message = NULL; ogs_assert(s); @@ -67,27 +67,27 @@ void smf_gsm_state_operational(ogs_fsm_t *s, smf_event_t *e) case SMF_EVT_SBI_SERVER: sbi_message = e->sbi.message; ogs_assert(sbi_message); - session = e->sbi.session; - ogs_assert(session); + stream = e->sbi.data; + ogs_assert(stream); SWITCH(sbi_message->h.service.name) CASE(OGS_SBI_SERVICE_NAME_NSMF_PDUSESSION) SWITCH(sbi_message->h.resource.component[2]) CASE(OGS_SBI_RESOURCE_NAME_MODIFY) - smf_nsmf_handle_update_sm_context(sess, session, sbi_message); + smf_nsmf_handle_update_sm_context(sess, stream, sbi_message); break; CASE(OGS_SBI_RESOURCE_NAME_RELEASE) - smf_nsmf_handle_release_sm_context(sess, session, sbi_message); + smf_nsmf_handle_release_sm_context(sess, stream, sbi_message); break; DEFAULT - smf_nsmf_handle_create_sm_context(sess, session, sbi_message); + smf_nsmf_handle_create_sm_context(sess, stream, sbi_message); break; END break; DEFAULT ogs_error("Invalid API name [%s]", sbi_message->h.service.name); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, sbi_message, "Invalid API name", sbi_message->h.service.name); END @@ -102,8 +102,8 @@ void smf_gsm_state_operational(ogs_fsm_t *s, smf_event_t *e) smf_ue = sess->smf_ue; ogs_assert(smf_ue); - session = e->sbi.session; - ogs_assert(session); + stream = e->sbi.data; + ogs_assert(stream); SWITCH(sbi_message->h.service.name) CASE(OGS_SBI_SERVICE_NAME_NUDM_SDM) @@ -113,14 +113,14 @@ void smf_gsm_state_operational(ogs_fsm_t *s, smf_event_t *e) ogs_error("[%s] HTTP response error [%d]", smf_ue->supi, sbi_message->res_status); ogs_sbi_server_send_error( - session, sbi_message->res_status, + stream, sbi_message->res_status, NULL, "HTTP response error", smf_ue->supi); break; } if (smf_nudm_sdm_handle_get( - sess, session, sbi_message) != true) { - ogs_sbi_server_send_error(session, + sess, stream, sbi_message) != true) { + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_INTERNAL_SERVER_ERROR, sbi_message, "HTTP response error", smf_ue->supi); } @@ -129,7 +129,7 @@ void smf_gsm_state_operational(ogs_fsm_t *s, smf_event_t *e) DEFAULT ogs_error("Invalid resource name [%s]", sbi_message->h.resource.component[1]); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, sbi_message, "Invalid resource name", sbi_message->h.resource.component[1]); @@ -166,14 +166,14 @@ void smf_gsm_state_operational(ogs_fsm_t *s, smf_event_t *e) ogs_assert(nas_message); sess = e->sess; ogs_assert(sess); - session = e->sbi.session; - ogs_assert(session); + stream = e->sbi.data; + ogs_assert(stream); smf_ue = sess->smf_ue; ogs_assert(smf_ue); switch (nas_message->gsm.h.message_type) { case OGS_NAS_5GS_PDU_SESSION_ESTABLISHMENT_REQUEST: - rv = gsm_handle_pdu_session_establishment_request(sess, session, + rv = gsm_handle_pdu_session_establishment_request(sess, stream, &nas_message->gsm.pdu_session_establishment_request); if (rv != OGS_OK) { ogs_error("[%s:%d] Cannot handle NAS message", @@ -184,18 +184,18 @@ void smf_gsm_state_operational(ogs_fsm_t *s, smf_event_t *e) case OGS_NAS_5GS_PDU_SESSION_RELEASE_REQUEST: smf_5gc_pfcp_send_session_deletion_request( - sess, session, OGS_PFCP_DELETE_TRIGGER_UE_REQUESTED); + sess, stream, OGS_PFCP_DELETE_TRIGGER_UE_REQUESTED); break; case OGS_NAS_5GS_PDU_SESSION_RELEASE_COMPLETE: - smf_sbi_send_response(session, OGS_SBI_HTTP_STATUS_NO_CONTENT); + smf_sbi_send_response(stream, OGS_SBI_HTTP_STATUS_NO_CONTENT); /* * Race condition for PDU session release complete * - CLIENT : /nsmf-pdusession/v1/sm-contexts/{smContextRef}/modify * - SERVER : /namf-callback/v1/{supi}/sm-context-status/{psi}) * - * smf_sbi_send_response(session, OGS_SBI_HTTP_STATUS_NO_CONTENT); + * smf_sbi_send_response(stream, OGS_SBI_HTTP_STATUS_NO_CONTENT); * smf_sbi_send_sm_context_status_notify(sess); * * When executed as above, @@ -212,7 +212,7 @@ void smf_gsm_state_operational(ogs_fsm_t *s, smf_event_t *e) nas_message->gsm.h.message_type); ogs_assert(strerror); ogs_error("%s", strerror); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, NULL, strerror, NULL); ogs_free(strerror); break; @@ -223,8 +223,8 @@ void smf_gsm_state_operational(ogs_fsm_t *s, smf_event_t *e) case SMF_EVT_NGAP_MESSAGE: sess = e->sess; ogs_assert(sess); - session = e->sbi.session; - ogs_assert(session); + stream = e->sbi.data; + ogs_assert(stream); smf_ue = sess->smf_ue; ogs_assert(smf_ue); pkbuf = e->pkbuf; @@ -234,7 +234,7 @@ void smf_gsm_state_operational(ogs_fsm_t *s, smf_event_t *e) switch (e->ngap.type) { case OpenAPI_n2_sm_info_type_PDU_RES_SETUP_RSP: rv = ngap_handle_pdu_session_resource_setup_response_transfer( - sess, session, pkbuf); + sess, stream, pkbuf); if (rv != OGS_OK) { ogs_error("[%s:%d] Cannot handle NGAP message", smf_ue->supi, sess->psi); @@ -243,7 +243,7 @@ void smf_gsm_state_operational(ogs_fsm_t *s, smf_event_t *e) break; case OpenAPI_n2_sm_info_type_PDU_RES_REL_RSP: - smf_sbi_send_response(session, OGS_SBI_HTTP_STATUS_NO_CONTENT); + smf_sbi_send_response(stream, OGS_SBI_HTTP_STATUS_NO_CONTENT); break; default: diff --git a/src/smf/n4-handler.c b/src/smf/n4-handler.c index b5d088b0d..9568f5909 100644 --- a/src/smf/n4-handler.c +++ b/src/smf/n4-handler.c @@ -101,7 +101,7 @@ void smf_5gc_n4_handle_session_establishment_response( { int i; - ogs_sbi_session_t *session = NULL; + ogs_sbi_stream_t *stream = NULL; uint8_t pfcp_cause_value = OGS_PFCP_CAUSE_REQUEST_ACCEPTED; uint8_t offending_ie_value = 0; @@ -111,8 +111,8 @@ void smf_5gc_n4_handle_session_establishment_response( ogs_assert(xact); ogs_assert(rsp); - session = xact->assoc_session; - ogs_assert(session); + stream = xact->assoc_stream; + ogs_assert(stream); ogs_pfcp_xact_commit(xact); @@ -184,7 +184,7 @@ void smf_5gc_n4_handle_session_establishment_response( ogs_assert(up_f_seid); sess->upf_n4_seid = be64toh(up_f_seid->seid); - smf_sbi_discover_and_send(OpenAPI_nf_type_AMF, sess, session, NULL, + smf_sbi_discover_and_send(OpenAPI_nf_type_AMF, sess, stream, NULL, smf_namf_comm_build_n1_n2_message_transfer); #if 0 @@ -198,13 +198,13 @@ void smf_5gc_n4_handle_session_modification_response( { int status = 0; uint64_t flags = 0; - ogs_sbi_session_t *session = NULL; + ogs_sbi_stream_t *stream = NULL; ogs_assert(xact); ogs_assert(rsp); - session = xact->assoc_session; - ogs_assert(session); + stream = xact->assoc_stream; + ogs_assert(stream); flags = xact->modify_flags; ogs_assert(flags); @@ -265,7 +265,7 @@ void smf_5gc_n4_handle_session_modification_response( if (status != OGS_SBI_HTTP_STATUS_OK) { char *strerror = ogs_msprintf( "PFCP Cause [%d] : Not Accepted", rsp->cause.u8); - smf_sbi_send_sm_context_update_error(session, status, strerror, + smf_sbi_send_sm_context_update_error(stream, status, strerror, NULL, NULL, NULL); ogs_free(strerror); return; @@ -274,19 +274,19 @@ void smf_5gc_n4_handle_session_modification_response( ogs_assert(sess); if (sess->upf_n3_addr == NULL && sess->upf_n3_addr6 == NULL) { - smf_sbi_send_sm_context_update_error(session, status, "No UP F_TEID", + smf_sbi_send_sm_context_update_error(stream, status, "No UP F_TEID", NULL, NULL, NULL); return; } if (flags & OGS_PFCP_MODIFY_ACTIVATE) { /* ACTIVATED Is NOT Inlcuded in RESPONSE */ - smf_sbi_send_sm_context_updated_data(sess, session, 0); + smf_sbi_send_sm_context_updated_data(sess, stream, 0); } else if (flags & OGS_PFCP_MODIFY_DEACTIVATE) { /* Only ACTIVING & DEACTIVATED is Included */ smf_sbi_send_sm_context_updated_data( - sess, session, OpenAPI_up_cnx_state_DEACTIVATED); + sess, stream, OpenAPI_up_cnx_state_DEACTIVATED); } } @@ -297,7 +297,7 @@ void smf_5gc_n4_handle_session_deletion_response( int status = 0; int trigger; - ogs_sbi_session_t *session = NULL; + ogs_sbi_stream_t *stream = NULL; ogs_sbi_message_t sendmsg; ogs_sbi_response_t *response = NULL; @@ -305,8 +305,8 @@ void smf_5gc_n4_handle_session_deletion_response( ogs_assert(xact); ogs_assert(rsp); - session = xact->assoc_session; - ogs_assert(session); + stream = xact->assoc_stream; + ogs_assert(stream); trigger = xact->delete_trigger; ogs_assert(trigger); @@ -332,7 +332,7 @@ void smf_5gc_n4_handle_session_deletion_response( if (status != OGS_SBI_HTTP_STATUS_OK) { char *strerror = ogs_msprintf( "PFCP Cause [%d] : Not Accepted", rsp->cause.u8); - ogs_sbi_server_send_error(session, status, NULL, NULL, NULL); + ogs_sbi_server_send_error(stream, status, NULL, NULL, NULL); ogs_free(strerror); return; } @@ -341,7 +341,7 @@ void smf_5gc_n4_handle_session_deletion_response( if (trigger == OGS_PFCP_DELETE_TRIGGER_UE_REQUESTED) { - smf_sbi_send_sm_context_updated_data_in_session_deletion(sess, session); + smf_sbi_send_sm_context_updated_data_in_session_deletion(sess, stream); } else { @@ -350,7 +350,7 @@ void smf_5gc_n4_handle_session_deletion_response( response = ogs_sbi_build_response( &sendmsg, OGS_SBI_HTTP_STATUS_NO_CONTENT); ogs_assert(response); - ogs_sbi_server_send_response(session, response); + ogs_sbi_server_send_response(stream, response); SMF_SESS_CLEAR(sess); } diff --git a/src/smf/nas-path.c b/src/smf/nas-path.c index 1ec87fa88..06c5c2ef4 100644 --- a/src/smf/nas-path.c +++ b/src/smf/nas-path.c @@ -20,7 +20,7 @@ #include "nas-path.h" void nas_5gs_send_to_gsm( - smf_sess_t *sess, ogs_sbi_session_t *session, ogs_pkbuf_t *pkbuf) + smf_sess_t *sess, ogs_sbi_stream_t *stream, ogs_pkbuf_t *pkbuf) { int rv; smf_event_t *e = NULL; @@ -31,7 +31,7 @@ void nas_5gs_send_to_gsm( e = smf_event_new(SMF_EVT_5GSM_MESSAGE); ogs_assert(e); e->sess = sess; - e->sbi.session = session; + e->sbi.data = stream; e->pkbuf = pkbuf; rv = ogs_queue_push(ogs_app()->queue, e); if (rv != OGS_OK) { diff --git a/src/smf/nas-path.h b/src/smf/nas-path.h index f63a08acf..4a8973fc3 100644 --- a/src/smf/nas-path.h +++ b/src/smf/nas-path.h @@ -27,7 +27,7 @@ extern "C" { #endif void nas_5gs_send_to_gsm( - smf_sess_t *sess, ogs_sbi_session_t *session, ogs_pkbuf_t *pkbuf); + smf_sess_t *sess, ogs_sbi_stream_t *stream, ogs_pkbuf_t *pkbuf); #ifdef __cplusplus } diff --git a/src/smf/nf-sm.c b/src/smf/nf-sm.c index 29dc57269..d076178f3 100644 --- a/src/smf/nf-sm.c +++ b/src/smf/nf-sm.c @@ -155,7 +155,7 @@ void smf_nf_state_will_register(ogs_fsm_t *s, smf_event_t *e) case SMF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: client = nf_instance->client; ogs_assert(client); - addr = client->addr; + addr = client->node.addr; ogs_assert(addr); ogs_warn("[%s] Retry to registration with NRF", nf_instance->id); @@ -365,7 +365,7 @@ void smf_nf_state_exception(ogs_fsm_t *s, smf_event_t *e) case SMF_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: client = nf_instance->client; ogs_assert(client); - addr = client->addr; + addr = client->node.addr; ogs_assert(addr); ogs_warn("[%s] Retry to registration with NRF", nf_instance->id); diff --git a/src/smf/ngap-handler.c b/src/smf/ngap-handler.c index 565353da1..2d69c38bd 100644 --- a/src/smf/ngap-handler.c +++ b/src/smf/ngap-handler.c @@ -22,7 +22,7 @@ #include "pfcp-path.h" int ngap_handle_pdu_session_resource_setup_response_transfer( - smf_sess_t *sess, ogs_sbi_session_t *session, ogs_pkbuf_t *pkbuf) + smf_sess_t *sess, ogs_sbi_stream_t *stream, ogs_pkbuf_t *pkbuf) { smf_ue_t *smf_ue = NULL; smf_bearer_t *qos_flow = NULL; @@ -44,7 +44,7 @@ int ngap_handle_pdu_session_resource_setup_response_transfer( NGAP_AssociatedQosFlowList_t *associatedQosFlowList = NULL; ogs_assert(pkbuf); - ogs_assert(session); + ogs_assert(stream); ogs_assert(sess); smf_ue = sess->smf_ue; @@ -56,7 +56,7 @@ int ngap_handle_pdu_session_resource_setup_response_transfer( if (rv != OGS_OK) { ogs_error("[%s:%d] Cannot decode NGAP message", smf_ue->supi, sess->psi); - smf_sbi_send_sm_context_update_error(session, + smf_sbi_send_sm_context_update_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, "No N2 SM Info Type", smf_ue->supi, NULL, NULL); goto cleanup; @@ -74,7 +74,7 @@ int ngap_handle_pdu_session_resource_setup_response_transfer( "[%s:%d] Unknown NGAP_UPTransportLayerInformation.present [%d]", smf_ue->supi, sess->psi, uPTransportLayerInformation->present); - smf_sbi_send_sm_context_update_error(session, + smf_sbi_send_sm_context_update_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, "Unknown NGAP_UPTransportLayerInformation.present", smf_ue->supi, NULL, NULL); @@ -94,7 +94,7 @@ int ngap_handle_pdu_session_resource_setup_response_transfer( if (!qos_flow) { ogs_error("[%s:%d] No QoS flow", smf_ue->supi, sess->psi); - smf_sbi_send_sm_context_update_error(session, + smf_sbi_send_sm_context_update_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, "No QoS flow", smf_ue->supi, NULL, NULL); goto cleanup; @@ -103,7 +103,7 @@ int ngap_handle_pdu_session_resource_setup_response_transfer( gTPTunnel = uPTransportLayerInformation->choice.gTPTunnel; if (!gTPTunnel) { ogs_error("[%s:%d] No GTPTunnel", smf_ue->supi, sess->psi); - smf_sbi_send_sm_context_update_error(session, + smf_sbi_send_sm_context_update_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, "No GTPTunnel", smf_ue->supi, NULL, NULL); goto cleanup; @@ -134,10 +134,10 @@ int ngap_handle_pdu_session_resource_setup_response_transfer( if (far_update) { smf_5gc_pfcp_send_qos_flow_modification_request( - qos_flow, session, OGS_PFCP_MODIFY_ACTIVATE); + qos_flow, stream, OGS_PFCP_MODIFY_ACTIVATE); } else { /* ACTIVATED Is NOT Inlcuded in RESPONSE */ - smf_sbi_send_sm_context_updated_data(sess, session, 0); + smf_sbi_send_sm_context_updated_data(sess, stream, 0); } rv = OGS_OK; diff --git a/src/smf/ngap-handler.h b/src/smf/ngap-handler.h index a967bf0b4..97c0e607f 100644 --- a/src/smf/ngap-handler.h +++ b/src/smf/ngap-handler.h @@ -27,7 +27,7 @@ extern "C" { #endif int ngap_handle_pdu_session_resource_setup_response_transfer( - smf_sess_t *sess, ogs_sbi_session_t *session, ogs_pkbuf_t *pkbuf); + smf_sess_t *sess, ogs_sbi_stream_t *stream, ogs_pkbuf_t *pkbuf); #ifdef __cplusplus } diff --git a/src/smf/ngap-path.c b/src/smf/ngap-path.c index c97fe7801..3d818f6dd 100644 --- a/src/smf/ngap-path.c +++ b/src/smf/ngap-path.c @@ -20,7 +20,7 @@ #include "ngap-path.h" void ngap_send_to_n2sm(smf_sess_t *sess, - ogs_sbi_session_t *session, int type, ogs_pkbuf_t *pkbuf) + ogs_sbi_stream_t *stream, int type, ogs_pkbuf_t *pkbuf) { int rv; smf_event_t *e = NULL; @@ -31,7 +31,7 @@ void ngap_send_to_n2sm(smf_sess_t *sess, e = smf_event_new(SMF_EVT_NGAP_MESSAGE); ogs_assert(e); e->sess = sess; - e->sbi.session = session; + e->sbi.data = stream; e->pkbuf = pkbuf; e->ngap.type = type; rv = ogs_queue_push(ogs_app()->queue, e); diff --git a/src/smf/ngap-path.h b/src/smf/ngap-path.h index c09b32b6b..d5f535a92 100644 --- a/src/smf/ngap-path.h +++ b/src/smf/ngap-path.h @@ -27,7 +27,7 @@ extern "C" { #endif void ngap_send_to_n2sm(smf_sess_t *sess, - ogs_sbi_session_t *session, int type, ogs_pkbuf_t *pkbuf); + ogs_sbi_stream_t *stream, int type, ogs_pkbuf_t *pkbuf); #ifdef __cplusplus } diff --git a/src/smf/nnrf-handler.c b/src/smf/nnrf-handler.c index 7f03283f0..e9aa5627e 100644 --- a/src/smf/nnrf-handler.c +++ b/src/smf/nnrf-handler.c @@ -89,7 +89,7 @@ void smf_nnrf_handle_nf_status_subscribe( } bool smf_nnrf_handle_nf_status_notify( - ogs_sbi_session_t *session, ogs_sbi_message_t *message) + ogs_sbi_stream_t *stream, ogs_sbi_message_t *message) { ogs_sbi_response_t *response = NULL; OpenAPI_notification_data_t *NotificationData = NULL; @@ -97,13 +97,13 @@ bool smf_nnrf_handle_nf_status_notify( ogs_sbi_nf_instance_t *nf_instance = NULL; bool handled; - ogs_assert(session); + ogs_assert(stream); ogs_assert(message); NotificationData = message->NotificationData; if (!NotificationData) { ogs_error("No NotificationData"); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, message, "No NotificationData", NULL); return false; } @@ -111,21 +111,21 @@ bool smf_nnrf_handle_nf_status_notify( NFProfile = NotificationData->nf_profile; if (!NFProfile) { ogs_error("No NFProfile"); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, message, "No NFProfile", NULL); return false; } if (!NFProfile->nf_instance_id) { ogs_error("No NFProfile.NFInstanceId"); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, message, "No NFProfile", "NFInstanceId"); return false; } if (!NFProfile->nf_instance_id) { ogs_error("No NFProfile.NFInstanceId"); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, message, "No NFProfile", "NFInstanceId"); return false; } @@ -133,7 +133,7 @@ bool smf_nnrf_handle_nf_status_notify( if (NF_INSTANCE_IS_SELF(NFProfile->nf_instance_id)) { ogs_warn("[%s] The notification is not allowed", NFProfile->nf_instance_id); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_FORBIDDEN, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_FORBIDDEN, message, "The notification is not allowed", NFProfile->nf_instance_id); return false; @@ -159,7 +159,7 @@ bool smf_nnrf_handle_nf_status_notify( } handled = ogs_sbi_nnrf_handle_nf_profile( - nf_instance, NFProfile, session, message); + nf_instance, NFProfile, stream, message); if (!handled) { SMF_NF_INSTANCE_CLEAR("NRF-notify", nf_instance); return false; @@ -170,7 +170,7 @@ bool smf_nnrf_handle_nf_status_notify( handled = ogs_sbi_client_associate(nf_instance); if (!handled) { ogs_error("[%s] Cannot associate NF EndPoint", nf_instance->id); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, message, "Cannot find NF EndPoint", nf_instance->id); SMF_NF_INSTANCE_CLEAR("NRF-notify", nf_instance); @@ -184,7 +184,7 @@ bool smf_nnrf_handle_nf_status_notify( SMF_NF_INSTANCE_CLEAR("NRF-notify", nf_instance); } else { ogs_warn("[%s] (NRF-notify) Not found", NFProfile->nf_instance_id); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_NOT_FOUND, message, "Not found", message->h.resource.component[1]); return false; @@ -194,7 +194,7 @@ bool smf_nnrf_handle_nf_status_notify( NotificationData->event); ogs_error("Not supported event [%d:%s]", NotificationData->event, eventstr ? eventstr : "Unknown"); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, message, "Not supported event", eventstr ? eventstr : "Unknown"); return false; @@ -202,7 +202,7 @@ bool smf_nnrf_handle_nf_status_notify( response = ogs_sbi_build_response(message, OGS_SBI_HTTP_STATUS_NO_CONTENT); ogs_assert(response); - ogs_sbi_server_send_response(session, response); + ogs_sbi_server_send_response(stream, response); return true; } @@ -212,7 +212,7 @@ void smf_nnrf_handle_nf_discover( { ogs_sbi_object_t *sbi_object = NULL; ogs_sbi_nf_instance_t *nf_instance = NULL; - ogs_sbi_session_t *session = NULL; + ogs_sbi_stream_t *stream = NULL; OpenAPI_search_result_t *SearchResult = NULL; OpenAPI_lnode_t *node = NULL; @@ -221,8 +221,8 @@ void smf_nnrf_handle_nf_discover( ogs_assert(xact); sbi_object = xact->sbi_object; ogs_assert(sbi_object); - session = xact->assoc_session; - ogs_assert(session); + stream = xact->assoc_stream; + ogs_assert(stream); ogs_assert(message); SearchResult = message->SearchResult; diff --git a/src/smf/nnrf-handler.h b/src/smf/nnrf-handler.h index 0614dfb67..7a537f6f6 100644 --- a/src/smf/nnrf-handler.h +++ b/src/smf/nnrf-handler.h @@ -32,7 +32,7 @@ void smf_nnrf_handle_nf_status_subscribe( ogs_sbi_subscription_t *subscription, ogs_sbi_message_t *message); bool smf_nnrf_handle_nf_status_notify( - ogs_sbi_session_t *session, ogs_sbi_message_t *message); + ogs_sbi_stream_t *stream, ogs_sbi_message_t *message); void smf_nnrf_handle_nf_discover( ogs_sbi_xact_t *xact, ogs_sbi_message_t *message); diff --git a/src/smf/nsmf-handler.c b/src/smf/nsmf-handler.c index 7c004a5ec..e562a8671 100644 --- a/src/smf/nsmf-handler.c +++ b/src/smf/nsmf-handler.c @@ -24,7 +24,7 @@ #include "nsmf-handler.h" bool smf_nsmf_handle_create_sm_context( - smf_sess_t *sess, ogs_sbi_session_t *session, ogs_sbi_message_t *message) + smf_sess_t *sess, ogs_sbi_stream_t *stream, ogs_sbi_message_t *message) { smf_ue_t *smf_ue = NULL; @@ -39,7 +39,7 @@ bool smf_nsmf_handle_create_sm_context( OpenAPI_plmn_id_nid_t *servingNetwork = NULL; OpenAPI_ref_to_binary_data_t *n1SmMsg = NULL; - ogs_assert(session); + ogs_assert(stream); ogs_assert(message); ogs_assert(sess); @@ -52,7 +52,7 @@ bool smf_nsmf_handle_create_sm_context( smf_ue->supi, sess->psi); n1smbuf = gsm_build_pdu_session_establishment_reject(sess, OGS_5GSM_CAUSE_INVALID_MANDATORY_INFORMATION); - smf_sbi_send_sm_context_create_error(session, + smf_sbi_send_sm_context_create_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, "No SmContextCreateData", smf_ue->supi, n1smbuf); return false; @@ -63,7 +63,7 @@ bool smf_nsmf_handle_create_sm_context( ogs_error("[%s:%d] No sNssai", smf_ue->supi, sess->psi); n1smbuf = gsm_build_pdu_session_establishment_reject(sess, OGS_5GSM_CAUSE_INVALID_MANDATORY_INFORMATION); - smf_sbi_send_sm_context_create_error(session, + smf_sbi_send_sm_context_create_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, "No sNssai", smf_ue->supi, n1smbuf); return false; @@ -75,7 +75,7 @@ bool smf_nsmf_handle_create_sm_context( smf_ue->supi, sess->psi); n1smbuf = gsm_build_pdu_session_establishment_reject(sess, OGS_5GSM_CAUSE_INVALID_MANDATORY_INFORMATION); - smf_sbi_send_sm_context_create_error(session, + smf_sbi_send_sm_context_create_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, "No servingNetwork", smf_ue->supi, n1smbuf); return false; @@ -86,7 +86,7 @@ bool smf_nsmf_handle_create_sm_context( ogs_error("[%s:%d] No UeLocation", smf_ue->supi, sess->psi); n1smbuf = gsm_build_pdu_session_establishment_reject(sess, OGS_5GSM_CAUSE_INVALID_MANDATORY_INFORMATION); - smf_sbi_send_sm_context_create_error(session, + smf_sbi_send_sm_context_create_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, "No UeLocation", smf_ue->supi, n1smbuf); return false; @@ -100,7 +100,7 @@ bool smf_nsmf_handle_create_sm_context( ogs_error("[%s:%d] No NrLocation", smf_ue->supi, sess->psi); n1smbuf = gsm_build_pdu_session_establishment_reject(sess, OGS_5GSM_CAUSE_INVALID_MANDATORY_INFORMATION); - smf_sbi_send_sm_context_create_error(session, + smf_sbi_send_sm_context_create_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, "No UeLocation", smf_ue->supi, n1smbuf); return false; @@ -111,7 +111,7 @@ bool smf_nsmf_handle_create_sm_context( ogs_error("[%s:%d] No n1SmMsg", smf_ue->supi, sess->psi); n1smbuf = gsm_build_pdu_session_establishment_reject(sess, OGS_5GSM_CAUSE_INVALID_MANDATORY_INFORMATION); - smf_sbi_send_sm_context_create_error(session, + smf_sbi_send_sm_context_create_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, "No n1SmMsg", smf_ue->supi, n1smbuf); return false; @@ -123,7 +123,7 @@ bool smf_nsmf_handle_create_sm_context( smf_ue->supi, sess->psi, n1SmMsg->content_id); n1smbuf = gsm_build_pdu_session_establishment_reject(sess, OGS_5GSM_CAUSE_INVALID_MANDATORY_INFORMATION); - smf_sbi_send_sm_context_create_error(session, + smf_sbi_send_sm_context_create_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, "No N1 SM Content", smf_ue->supi, n1smbuf); return false; @@ -134,7 +134,7 @@ bool smf_nsmf_handle_create_sm_context( smf_ue->supi, sess->psi); n1smbuf = gsm_build_pdu_session_establishment_reject(sess, OGS_5GSM_CAUSE_INVALID_MANDATORY_INFORMATION); - smf_sbi_send_sm_context_create_error(session, + smf_sbi_send_sm_context_create_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, "No SmContextStatusNotification", smf_ue->supi, n1smbuf); return false; @@ -147,7 +147,7 @@ bool smf_nsmf_handle_create_sm_context( SmContextCreateData->sm_context_status_uri); n1smbuf = gsm_build_pdu_session_establishment_reject(sess, OGS_5GSM_CAUSE_INVALID_MANDATORY_INFORMATION); - smf_sbi_send_sm_context_create_error(session, + smf_sbi_send_sm_context_create_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, "Invalid URI", SmContextCreateData->sm_context_status_uri, n1smbuf); return false; @@ -195,13 +195,13 @@ bool smf_nsmf_handle_create_sm_context( */ n1smbuf = ogs_pkbuf_copy(n1smbuf); ogs_assert(n1smbuf); - nas_5gs_send_to_gsm(sess, session, n1smbuf); + nas_5gs_send_to_gsm(sess, stream, n1smbuf); return true; } bool smf_nsmf_handle_update_sm_context( - smf_sess_t *sess, ogs_sbi_session_t *session, ogs_sbi_message_t *message) + smf_sess_t *sess, ogs_sbi_stream_t *stream, ogs_sbi_message_t *message) { int i; smf_ue_t *smf_ue = NULL; @@ -216,7 +216,7 @@ bool smf_nsmf_handle_update_sm_context( ogs_pkbuf_t *n1smbuf = NULL; ogs_pkbuf_t *n2smbuf = NULL; - ogs_assert(session); + ogs_assert(stream); ogs_assert(message); ogs_assert(sess); @@ -227,7 +227,7 @@ bool smf_nsmf_handle_update_sm_context( if (!SmContextUpdateData) { ogs_error("[%s:%d] No SmContextUpdateData", smf_ue->supi, sess->psi); - smf_sbi_send_sm_context_update_error(session, + smf_sbi_send_sm_context_update_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, "No SmContextUpdateData", smf_ue->supi, NULL, NULL); return false; @@ -261,7 +261,7 @@ bool smf_nsmf_handle_update_sm_context( ogs_error("[%s:%d] No n1SmMsg", smf_ue->supi, sess->psi); n1smbuf = gsm_build_pdu_session_release_reject(sess, OGS_5GSM_CAUSE_INVALID_MANDATORY_INFORMATION); - smf_sbi_send_sm_context_update_error(session, + smf_sbi_send_sm_context_update_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, "No n1SmMsg", smf_ue->supi, n1smbuf, NULL); return false; @@ -273,7 +273,7 @@ bool smf_nsmf_handle_update_sm_context( smf_ue->supi, sess->psi, n1SmMsg->content_id); n1smbuf = gsm_build_pdu_session_release_reject(sess, OGS_5GSM_CAUSE_INVALID_MANDATORY_INFORMATION); - smf_sbi_send_sm_context_update_error(session, + smf_sbi_send_sm_context_update_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, "No N1 SM Content", smf_ue->supi, n1smbuf, NULL); return false; @@ -286,7 +286,7 @@ bool smf_nsmf_handle_update_sm_context( */ n1smbuf = ogs_pkbuf_copy(n1smbuf); ogs_assert(n1smbuf); - nas_5gs_send_to_gsm(sess, session, n1smbuf); + nas_5gs_send_to_gsm(sess, stream, n1smbuf); return true; @@ -298,7 +298,7 @@ bool smf_nsmf_handle_update_sm_context( if (!SmContextUpdateData->n2_sm_info_type) { ogs_error("[%s:%d] No n2SmInfoType", smf_ue->supi, sess->psi); - smf_sbi_send_sm_context_update_error(session, + smf_sbi_send_sm_context_update_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, "No n2SmInfoType", smf_ue->supi, NULL, NULL); return false; @@ -308,7 +308,7 @@ bool smf_nsmf_handle_update_sm_context( if (!n2SmMsg || !n2SmMsg->content_id) { ogs_error("[%s:%d] No N2SmInfo.content_id", smf_ue->supi, sess->psi); - smf_sbi_send_sm_context_update_error(session, + smf_sbi_send_sm_context_update_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, "No n2SmInfo.content_id", smf_ue->supi, NULL, NULL); return false; @@ -317,7 +317,7 @@ bool smf_nsmf_handle_update_sm_context( n2smbuf = ogs_sbi_find_part_by_content_id(message, n2SmMsg->content_id); if (!n2smbuf) { ogs_error("[%s:%d] No N2 SM Content", smf_ue->supi, sess->psi); - smf_sbi_send_sm_context_update_error(session, + smf_sbi_send_sm_context_update_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, "No N2 SM Content", smf_ue->supi, NULL, NULL); return false; @@ -331,12 +331,12 @@ bool smf_nsmf_handle_update_sm_context( n2smbuf = ogs_pkbuf_copy(n2smbuf); ogs_assert(n2smbuf); ngap_send_to_n2sm( - sess, session, SmContextUpdateData->n2_sm_info_type, n2smbuf); + sess, stream, SmContextUpdateData->n2_sm_info_type, n2smbuf); } else { if (!SmContextUpdateData->up_cnx_state) { ogs_error("[%s:%d] No upCnxState", smf_ue->supi, sess->psi); - smf_sbi_send_sm_context_update_error(session, + smf_sbi_send_sm_context_update_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, "No upCnxState", smf_ue->supi, NULL, NULL); return false; @@ -349,7 +349,7 @@ bool smf_nsmf_handle_update_sm_context( * Handle DEACTIVATED ********************************************************/ smf_5gc_pfcp_send_session_modification_request( - sess, session, OGS_PFCP_MODIFY_DEACTIVATE); + sess, stream, OGS_PFCP_MODIFY_DEACTIVATE); } else if (SmContextUpdateData->up_cnx_state == OpenAPI_up_cnx_state_ACTIVATING) { @@ -424,7 +424,7 @@ bool smf_nsmf_handle_update_sm_context( response = ogs_sbi_build_response(&sendmsg, OGS_SBI_HTTP_STATUS_OK); ogs_assert(response); - ogs_sbi_server_send_response(session, response); + ogs_sbi_server_send_response(stream, response); for (i = 0; i < sendmsg.num_of_part; i++) if (sendmsg.part[i].pkbuf) @@ -435,7 +435,7 @@ bool smf_nsmf_handle_update_sm_context( smf_ue->supi, sess->psi, SmContextUpdateData->up_cnx_state); ogs_error("%s", strerror); - smf_sbi_send_sm_context_update_error(session, + smf_sbi_send_sm_context_update_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, strerror, NULL, NULL, NULL); ogs_free(strerror); @@ -447,11 +447,11 @@ bool smf_nsmf_handle_update_sm_context( } bool smf_nsmf_handle_release_sm_context( - smf_sess_t *sess, ogs_sbi_session_t *session, ogs_sbi_message_t *message) + smf_sess_t *sess, ogs_sbi_stream_t *stream, ogs_sbi_message_t *message) { OpenAPI_sm_context_release_data_t *SmContextReleaseData = NULL; - ogs_assert(session); + ogs_assert(stream); ogs_assert(message); ogs_assert(sess); @@ -482,7 +482,7 @@ bool smf_nsmf_handle_release_sm_context( } } - smf_5gc_pfcp_send_session_deletion_request(sess, session, + smf_5gc_pfcp_send_session_deletion_request(sess, stream, OGS_PFCP_DELETE_TRIGGER_AMF_RELEASE_SM_CONTEXT); return true; diff --git a/src/smf/nsmf-handler.h b/src/smf/nsmf-handler.h index 89e5e4f96..3583ed4a5 100644 --- a/src/smf/nsmf-handler.h +++ b/src/smf/nsmf-handler.h @@ -27,11 +27,11 @@ extern "C" { #endif bool smf_nsmf_handle_create_sm_context( - smf_sess_t *sess, ogs_sbi_session_t *session, ogs_sbi_message_t *message); + smf_sess_t *sess, ogs_sbi_stream_t *stream, ogs_sbi_message_t *message); bool smf_nsmf_handle_update_sm_context( - smf_sess_t *sess, ogs_sbi_session_t *session, ogs_sbi_message_t *message); + smf_sess_t *sess, ogs_sbi_stream_t *stream, ogs_sbi_message_t *message); bool smf_nsmf_handle_release_sm_context( - smf_sess_t *sess, ogs_sbi_session_t *session, ogs_sbi_message_t *message); + smf_sess_t *sess, ogs_sbi_stream_t *stream, ogs_sbi_message_t *message); #ifdef __cplusplus } diff --git a/src/smf/nudm-handler.c b/src/smf/nudm-handler.c index 50a26500d..6086522e6 100644 --- a/src/smf/nudm-handler.c +++ b/src/smf/nudm-handler.c @@ -20,7 +20,7 @@ #include "nudm-handler.h" #include "pfcp-path.h" -bool smf_nudm_sdm_handle_get(smf_sess_t *sess, ogs_sbi_session_t *session, +bool smf_nudm_sdm_handle_get(smf_sess_t *sess, ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg) { char buf1[OGS_ADDRSTRLEN]; @@ -55,10 +55,10 @@ bool smf_nudm_sdm_handle_get(smf_sess_t *sess, ogs_sbi_session_t *session, OpenAPI_lnode_t *node = NULL, *node2 = NULL; ogs_assert(sess); - ogs_assert(session); + ogs_assert(stream); smf_ue = sess->smf_ue; ogs_assert(smf_ue); - server = ogs_sbi_session_get_server(session); + server = ogs_sbi_server_from_stream(stream); ogs_assert(server); ogs_assert(recvmsg); @@ -257,7 +257,7 @@ bool smf_nudm_sdm_handle_get(smf_sess_t *sess, ogs_sbi_session_t *session, response = ogs_sbi_build_response(&sendmsg, OGS_SBI_HTTP_STATUS_CREATED); ogs_assert(response); - ogs_sbi_server_send_response(session, response); + ogs_sbi_server_send_response(stream, response); ogs_free(sendmsg.http.location); @@ -334,7 +334,7 @@ bool smf_nudm_sdm_handle_get(smf_sess_t *sess, ogs_sbi_session_t *session, dl_pdr->precedence = 0xffffffff; ul_pdr->precedence = 0xffffffff; - smf_5gc_pfcp_send_session_establishment_request(sess, session); + smf_5gc_pfcp_send_session_establishment_request(sess, stream); return true; } diff --git a/src/smf/nudm-handler.h b/src/smf/nudm-handler.h index 455385941..95cb8c192 100644 --- a/src/smf/nudm-handler.h +++ b/src/smf/nudm-handler.h @@ -26,7 +26,7 @@ extern "C" { #endif -bool smf_nudm_sdm_handle_get(smf_sess_t *sess, ogs_sbi_session_t *session, +bool smf_nudm_sdm_handle_get(smf_sess_t *sess, ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg); #ifdef __cplusplus diff --git a/src/smf/pfcp-path.c b/src/smf/pfcp-path.c index 929de44a1..54e0c451b 100644 --- a/src/smf/pfcp-path.c +++ b/src/smf/pfcp-path.c @@ -180,7 +180,7 @@ static void sess_5gc_timeout(ogs_pfcp_xact_t *xact, void *data) { smf_ue_t *smf_ue = NULL; smf_sess_t *sess = NULL; - ogs_sbi_session_t *session = NULL; + ogs_sbi_stream_t *stream = NULL; uint8_t type; char *strerror = NULL; @@ -189,8 +189,8 @@ static void sess_5gc_timeout(ogs_pfcp_xact_t *xact, void *data) sess = data; ogs_assert(sess); - session = xact->assoc_session; - ogs_assert(session); + stream = xact->assoc_stream; + ogs_assert(stream); smf_ue = sess->smf_ue; ogs_assert(smf_ue); @@ -202,14 +202,14 @@ static void sess_5gc_timeout(ogs_pfcp_xact_t *xact, void *data) case OGS_PFCP_SESSION_MODIFICATION_REQUEST_TYPE: strerror = ogs_msprintf("[%s:%d] No PFCP session modification response", smf_ue->supi, sess->psi); - smf_sbi_send_sm_context_update_error(session, + smf_sbi_send_sm_context_update_error(stream, OGS_SBI_HTTP_STATUS_GATEWAY_TIMEOUT, strerror, NULL, NULL, NULL); break; case OGS_PFCP_SESSION_DELETION_REQUEST_TYPE: strerror = ogs_msprintf("[%s:%d] No PFCP session deletion response", smf_ue->supi, sess->psi); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_GATEWAY_TIMEOUT, NULL, strerror, NULL); ogs_free(strerror); break; @@ -243,7 +243,7 @@ static void sess_epc_timeout(ogs_pfcp_xact_t *xact, void *data) } void smf_5gc_pfcp_send_session_establishment_request( - smf_sess_t *sess, ogs_sbi_session_t *session) + smf_sess_t *sess, ogs_sbi_stream_t *stream) { int rv; ogs_pkbuf_t *n4buf = NULL; @@ -251,7 +251,7 @@ void smf_5gc_pfcp_send_session_establishment_request( ogs_pfcp_xact_t *xact = NULL; ogs_assert(sess); - ogs_assert(session); + ogs_assert(stream); memset(&h, 0, sizeof(ogs_pfcp_header_t)); h.type = OGS_PFCP_SESSION_ESTABLISHMENT_REQUEST_TYPE; @@ -263,14 +263,14 @@ void smf_5gc_pfcp_send_session_establishment_request( xact = ogs_pfcp_xact_local_create( sess->pfcp_node, &h, n4buf, sess_5gc_timeout, sess); ogs_expect_or_return(xact); - xact->assoc_session = session; + xact->assoc_stream = stream; rv = ogs_pfcp_xact_commit(xact); ogs_expect(rv == OGS_OK); } void smf_5gc_pfcp_send_session_modification_request( - smf_sess_t *sess, ogs_sbi_session_t *session, uint64_t flags) + smf_sess_t *sess, ogs_sbi_stream_t *stream, uint64_t flags) { int rv; ogs_pkbuf_t *n4buf = NULL; @@ -278,7 +278,7 @@ void smf_5gc_pfcp_send_session_modification_request( ogs_pfcp_xact_t *xact = NULL; ogs_assert(sess); - ogs_assert(session); + ogs_assert(stream); memset(&h, 0, sizeof(ogs_pfcp_header_t)); h.type = OGS_PFCP_SESSION_MODIFICATION_REQUEST_TYPE; @@ -290,7 +290,7 @@ void smf_5gc_pfcp_send_session_modification_request( xact = ogs_pfcp_xact_local_create( sess->pfcp_node, &h, n4buf, sess_5gc_timeout, sess); ogs_expect_or_return(xact); - xact->assoc_session = session; + xact->assoc_stream = stream; xact->modify_flags = flags | OGS_PFCP_MODIFY_SESSION; rv = ogs_pfcp_xact_commit(xact); @@ -298,7 +298,7 @@ void smf_5gc_pfcp_send_session_modification_request( } void smf_5gc_pfcp_send_qos_flow_modification_request(smf_bearer_t *qos_flow, - ogs_sbi_session_t *session, uint64_t flags) + ogs_sbi_stream_t *stream, uint64_t flags) { int rv; ogs_pkbuf_t *n4buf = NULL; @@ -310,7 +310,7 @@ void smf_5gc_pfcp_send_qos_flow_modification_request(smf_bearer_t *qos_flow, sess = qos_flow->sess; ogs_assert(sess); - ogs_assert(session); + ogs_assert(stream); memset(&h, 0, sizeof(ogs_pfcp_header_t)); h.type = OGS_PFCP_SESSION_MODIFICATION_REQUEST_TYPE; @@ -323,7 +323,7 @@ void smf_5gc_pfcp_send_qos_flow_modification_request(smf_bearer_t *qos_flow, sess->pfcp_node, &h, n4buf, sess_5gc_timeout, qos_flow); ogs_expect_or_return(xact); - xact->assoc_session = session; + xact->assoc_stream = stream; xact->modify_flags = flags; rv = ogs_pfcp_xact_commit(xact); @@ -331,7 +331,7 @@ void smf_5gc_pfcp_send_qos_flow_modification_request(smf_bearer_t *qos_flow, } void smf_5gc_pfcp_send_session_deletion_request( - smf_sess_t *sess, ogs_sbi_session_t *session, int trigger) + smf_sess_t *sess, ogs_sbi_stream_t *stream, int trigger) { int rv; ogs_pkbuf_t *n4buf = NULL; @@ -339,7 +339,7 @@ void smf_5gc_pfcp_send_session_deletion_request( ogs_pfcp_xact_t *xact = NULL; ogs_assert(sess); - ogs_assert(session); + ogs_assert(stream); ogs_assert(trigger); memset(&h, 0, sizeof(ogs_pfcp_header_t)); @@ -352,7 +352,7 @@ void smf_5gc_pfcp_send_session_deletion_request( xact = ogs_pfcp_xact_local_create( sess->pfcp_node, &h, n4buf, sess_5gc_timeout, sess); ogs_expect_or_return(xact); - xact->assoc_session = session; + xact->assoc_stream = stream; xact->delete_trigger = trigger; rv = ogs_pfcp_xact_commit(xact); diff --git a/src/smf/pfcp-path.h b/src/smf/pfcp-path.h index 51bfc1a96..ebddbf549 100644 --- a/src/smf/pfcp-path.h +++ b/src/smf/pfcp-path.h @@ -30,13 +30,13 @@ int smf_pfcp_open(void); void smf_pfcp_close(void); void smf_5gc_pfcp_send_session_establishment_request( - smf_sess_t *sess, ogs_sbi_session_t *session); + smf_sess_t *sess, ogs_sbi_stream_t *stream); void smf_5gc_pfcp_send_session_modification_request( - smf_sess_t *sess, ogs_sbi_session_t *session, uint64_t flags); + smf_sess_t *sess, ogs_sbi_stream_t *stream, uint64_t flags); void smf_5gc_pfcp_send_qos_flow_modification_request(smf_bearer_t *qos_flow, - ogs_sbi_session_t *session, uint64_t flags); + ogs_sbi_stream_t *stream, uint64_t flags); void smf_5gc_pfcp_send_session_deletion_request( - smf_sess_t *sess, ogs_sbi_session_t *session, int trigger); + smf_sess_t *sess, ogs_sbi_stream_t *stream, int trigger); void smf_epc_pfcp_send_session_establishment_request( smf_sess_t *sess, void *gtp_xact); diff --git a/src/smf/sbi-path.c b/src/smf/sbi-path.c index 4a646af2e..a73ee0c38 100644 --- a/src/smf/sbi-path.c +++ b/src/smf/sbi-path.c @@ -21,21 +21,19 @@ #include "ngap-path.h" #include "sbi-path.h" -static int server_cb(ogs_sbi_server_t *server, - ogs_sbi_session_t *session, ogs_sbi_request_t *request) +static int server_cb(ogs_sbi_request_t *request, void *data) { smf_event_t *e = NULL; int rv; - ogs_assert(session); ogs_assert(request); + ogs_assert(data); e = smf_event_new(SMF_EVT_SBI_SERVER); ogs_assert(e); - e->sbi.server = server; - e->sbi.session = session; e->sbi.request = request; + e->sbi.data = data; rv = ogs_queue_push(ogs_app()->queue, e); if (rv != OGS_OK) { @@ -122,7 +120,7 @@ void smf_sbi_send(ogs_sbi_nf_instance_t *nf_instance, ogs_sbi_xact_t *xact) } void smf_sbi_discover_and_send(OpenAPI_nf_type_e target_nf_type, - smf_sess_t *sess, ogs_sbi_session_t *session, void *data, + smf_sess_t *sess, ogs_sbi_stream_t *stream, void *data, ogs_sbi_request_t *(*build)(smf_sess_t *sess, void *data)) { ogs_sbi_xact_t *xact = NULL; @@ -134,40 +132,40 @@ void smf_sbi_discover_and_send(OpenAPI_nf_type_e target_nf_type, smf_ue = sess->smf_ue; ogs_assert(smf_ue); - ogs_assert(session); + ogs_assert(stream); ogs_assert(build); xact = ogs_sbi_xact_add(target_nf_type, &sess->sbi, data, (ogs_sbi_build_f)build, smf_timer_sbi_client_wait_expire); ogs_assert(xact); - xact->assoc_session = session; + xact->assoc_stream = stream; if (ogs_sbi_discover_and_send(xact, (ogs_fsm_handler_t)smf_nf_state_registered, client_cb) != true) { - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_GATEWAY_TIMEOUT, NULL, "Cannot discover", smf_ue->supi); } } -void smf_sbi_send_response(ogs_sbi_session_t *session, int status) +void smf_sbi_send_response(ogs_sbi_stream_t *stream, int status) { ogs_sbi_message_t sendmsg; ogs_sbi_response_t *response = NULL; - ogs_assert(session); + ogs_assert(stream); memset(&sendmsg, 0, sizeof(sendmsg)); response = ogs_sbi_build_response(&sendmsg, status); ogs_assert(response); - ogs_sbi_server_send_response(session, response); + ogs_sbi_server_send_response(stream, response); } void smf_sbi_send_sm_context_create_error( - ogs_sbi_session_t *session, + ogs_sbi_stream_t *stream, int status, const char *title, const char *detail, ogs_pkbuf_t *n1smbuf) { @@ -178,7 +176,7 @@ void smf_sbi_send_sm_context_create_error( OpenAPI_problem_details_t problem; OpenAPI_ref_to_binary_data_t n1SmMsg; - ogs_assert(session); + ogs_assert(stream); memset(&problem, 0, sizeof(problem)); problem.status = status; @@ -203,14 +201,14 @@ void smf_sbi_send_sm_context_create_error( response = ogs_sbi_build_response(&sendmsg, problem.status); ogs_assert(response); - ogs_sbi_server_send_response(session, response); + ogs_sbi_server_send_response(stream, response); if (n1smbuf) ogs_pkbuf_free(n1smbuf); } void smf_sbi_send_sm_context_updated_data(smf_sess_t *sess, - ogs_sbi_session_t *session, OpenAPI_up_cnx_state_e up_cnx_state) + ogs_sbi_stream_t *stream, OpenAPI_up_cnx_state_e up_cnx_state) { int status; @@ -220,7 +218,7 @@ void smf_sbi_send_sm_context_updated_data(smf_sess_t *sess, OpenAPI_sm_context_updated_data_t SmContextUpdatedData; ogs_assert(sess); - ogs_assert(session); + ogs_assert(stream); memset(&sendmsg, 0, sizeof(sendmsg)); @@ -236,11 +234,11 @@ void smf_sbi_send_sm_context_updated_data(smf_sess_t *sess, response = ogs_sbi_build_response(&sendmsg, status); ogs_assert(response); - ogs_sbi_server_send_response(session, response); + ogs_sbi_server_send_response(stream, response); } void smf_sbi_send_sm_context_updated_data_in_session_deletion( - smf_sess_t *sess, ogs_sbi_session_t *session) + smf_sess_t *sess, ogs_sbi_stream_t *stream) { int i; @@ -252,7 +250,7 @@ void smf_sbi_send_sm_context_updated_data_in_session_deletion( OpenAPI_ref_to_binary_data_t n2SmInfo; ogs_assert(sess); - ogs_assert(session); + ogs_assert(stream); memset(&sendmsg, 0, sizeof(sendmsg)); @@ -296,14 +294,14 @@ void smf_sbi_send_sm_context_updated_data_in_session_deletion( response = ogs_sbi_build_response(&sendmsg, OGS_SBI_HTTP_STATUS_OK); ogs_assert(response); - ogs_sbi_server_send_response(session, response); + ogs_sbi_server_send_response(stream, response); for (i = 0; i < sendmsg.num_of_part; i++) ogs_pkbuf_free(sendmsg.part[i].pkbuf); } void smf_sbi_send_sm_context_update_error( - ogs_sbi_session_t *session, + ogs_sbi_stream_t *stream, int status, const char *title, const char *detail, ogs_pkbuf_t *n1smbuf, ogs_pkbuf_t *n2smbuf) { @@ -315,7 +313,7 @@ void smf_sbi_send_sm_context_update_error( OpenAPI_ref_to_binary_data_t n1SmMsg; OpenAPI_ref_to_binary_data_t n2SmInfo; - ogs_assert(session); + ogs_assert(stream); memset(&problem, 0, sizeof(problem)); problem.status = status; @@ -353,7 +351,7 @@ void smf_sbi_send_sm_context_update_error( response = ogs_sbi_build_response(&sendmsg, problem.status); ogs_assert(response); - ogs_sbi_server_send_response(session, response); + ogs_sbi_server_send_response(stream, response); if (n1smbuf) ogs_pkbuf_free(n1smbuf); diff --git a/src/smf/sbi-path.h b/src/smf/sbi-path.h index 1220cbb05..7a0681dd1 100644 --- a/src/smf/sbi-path.h +++ b/src/smf/sbi-path.h @@ -34,21 +34,21 @@ void smf_sbi_close(void); void smf_sbi_send(ogs_sbi_nf_instance_t *nf_instance, ogs_sbi_xact_t *xact); void smf_sbi_discover_and_send(OpenAPI_nf_type_e target_nf_type, - smf_sess_t *sess, ogs_sbi_session_t *session, void *data, + smf_sess_t *sess, ogs_sbi_stream_t *stream, void *data, ogs_sbi_request_t *(*build)(smf_sess_t *sess, void *data)); -void smf_sbi_send_response(ogs_sbi_session_t *session, int status); +void smf_sbi_send_response(ogs_sbi_stream_t *stream, int status); void smf_sbi_send_sm_context_create_error( - ogs_sbi_session_t *session, + ogs_sbi_stream_t *stream, int status, const char *title, const char *detail, ogs_pkbuf_t *n1smbuf); void smf_sbi_send_sm_context_updated_data(smf_sess_t *sess, - ogs_sbi_session_t *session, OpenAPI_up_cnx_state_e up_cnx_state); + ogs_sbi_stream_t *stream, OpenAPI_up_cnx_state_e up_cnx_state); void smf_sbi_send_sm_context_updated_data_in_session_deletion( - smf_sess_t *sess, ogs_sbi_session_t *session); + smf_sess_t *sess, ogs_sbi_stream_t *stream); void smf_sbi_send_sm_context_update_error( - ogs_sbi_session_t *session, + ogs_sbi_stream_t *stream, int status, const char *title, const char *detail, ogs_pkbuf_t *n1smbuf, ogs_pkbuf_t *n2smbuf); diff --git a/src/smf/smf-sm.c b/src/smf/smf-sm.c index da875c97a..f6cf6de60 100644 --- a/src/smf/smf-sm.c +++ b/src/smf/smf-sm.c @@ -61,7 +61,7 @@ void smf_state_operational(ogs_fsm_t *s, smf_event_t *e) ogs_pfcp_xact_t *pfcp_xact = NULL; ogs_pfcp_message_t pfcp_message; - ogs_sbi_session_t *session = NULL; + ogs_sbi_stream_t *stream = NULL; ogs_sbi_request_t *sbi_request = NULL; ogs_sbi_nf_instance_t *nf_instance = NULL; @@ -259,14 +259,14 @@ void smf_state_operational(ogs_fsm_t *s, smf_event_t *e) case SMF_EVT_SBI_SERVER: sbi_request = e->sbi.request; ogs_assert(sbi_request); - session = e->sbi.session; - ogs_assert(session); + stream = e->sbi.data; + ogs_assert(stream); rv = ogs_sbi_parse_request(&sbi_message, sbi_request); if (rv != OGS_OK) { /* 'sbi_message' buffer is released in ogs_sbi_parse_request() */ ogs_error("cannot parse HTTP sbi_message"); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, NULL, "cannot parse HTTP sbi_message", NULL); break; } @@ -282,7 +282,7 @@ void smf_state_operational(ogs_fsm_t *s, smf_event_t *e) ogs_assert(api_version); if (strcmp(sbi_message.h.api.version, api_version) != 0) { ogs_error("Not supported version [%s]", sbi_message.h.api.version); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, &sbi_message, "Not supported version", NULL); ogs_sbi_message_free(&sbi_message); break; @@ -295,13 +295,13 @@ void smf_state_operational(ogs_fsm_t *s, smf_event_t *e) CASE(OGS_SBI_RESOURCE_NAME_NF_STATUS_NOTIFY) SWITCH(sbi_message.h.method) CASE(OGS_SBI_HTTP_METHOD_POST) - smf_nnrf_handle_nf_status_notify(session, &sbi_message); + smf_nnrf_handle_nf_status_notify(stream, &sbi_message); break; DEFAULT ogs_error("Invalid HTTP method [%s]", sbi_message.h.method); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_FORBIDDEN, &sbi_message, "Invalid HTTP method", sbi_message.h.method); @@ -311,7 +311,7 @@ void smf_state_operational(ogs_fsm_t *s, smf_event_t *e) DEFAULT ogs_error("Invalid resource name [%s]", sbi_message.h.resource.component[0]); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, &sbi_message, "Invalid resource name", sbi_message.h.resource.component[0]); @@ -329,7 +329,7 @@ void smf_state_operational(ogs_fsm_t *s, smf_event_t *e) if (!sbi_message.h.resource.component[1]) { ogs_error("No smContextRef [%s]", sbi_message.h.resource.component[2]); - smf_sbi_send_sm_context_update_error(session, + smf_sbi_send_sm_context_update_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, "No smContextRef", sbi_message.h.resource.component[2], @@ -342,7 +342,7 @@ void smf_state_operational(ogs_fsm_t *s, smf_event_t *e) if (!sess) { ogs_warn("Not found [%s]", sbi_message.h.uri); - smf_sbi_send_sm_context_update_error(session, + smf_sbi_send_sm_context_update_error(stream, OGS_SBI_HTTP_STATUS_NOT_FOUND, "Not found", sbi_message.h.uri, NULL, NULL); } @@ -356,7 +356,7 @@ void smf_state_operational(ogs_fsm_t *s, smf_event_t *e) DEFAULT ogs_error("Invalid HTTP method [%s]", sbi_message.h.method); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, &sbi_message, "Invalid HTTP method", sbi_message.h.method); break; @@ -380,7 +380,7 @@ void smf_state_operational(ogs_fsm_t *s, smf_event_t *e) DEFAULT ogs_error("Invalid resource name [%s]", sbi_message.h.resource.component[0]); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, &sbi_message, "Invalid resource name", sbi_message.h.resource.component[0]); @@ -389,7 +389,7 @@ void smf_state_operational(ogs_fsm_t *s, smf_event_t *e) DEFAULT ogs_error("Invalid API name [%s]", sbi_message.h.service.name); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, &sbi_message, "Invalid API name", sbi_message.h.service.name); END @@ -524,7 +524,7 @@ void smf_state_operational(ogs_fsm_t *s, smf_event_t *e) e->sess = sess; e->sbi.message = &sbi_message; - e->sbi.session = sbi_xact->assoc_session; + e->sbi.data = sbi_xact->assoc_stream; ogs_sbi_xact_remove(sbi_xact); @@ -576,13 +576,13 @@ void smf_state_operational(ogs_fsm_t *s, smf_event_t *e) sbi_xact = e->sbi.data; ogs_assert(sbi_xact); - session = sbi_xact->assoc_session; - ogs_assert(session); + stream = sbi_xact->assoc_stream; + ogs_assert(stream); ogs_sbi_xact_remove(sbi_xact); ogs_error("Cannot receive SBI message"); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_GATEWAY_TIMEOUT, NULL, "Cannot receive SBI message", NULL); break; @@ -606,8 +606,8 @@ void smf_state_operational(ogs_fsm_t *s, smf_event_t *e) case SMF_EVT_5GSM_MESSAGE: sess = e->sess; ogs_assert(sess); - session = e->sbi.session; - ogs_assert(session); + stream = e->sbi.data; + ogs_assert(stream); pkbuf = e->pkbuf; ogs_assert(pkbuf); @@ -635,8 +635,8 @@ void smf_state_operational(ogs_fsm_t *s, smf_event_t *e) case SMF_EVT_NGAP_MESSAGE: sess = e->sess; ogs_assert(sess); - session = e->sbi.session; - ogs_assert(session); + stream = e->sbi.data; + ogs_assert(stream); pkbuf = e->pkbuf; ogs_assert(pkbuf); ogs_assert(e->ngap.type); diff --git a/src/udm/event.h b/src/udm/event.h index e67ff6a8d..5d24a9650 100644 --- a/src/udm/event.h +++ b/src/udm/event.h @@ -26,8 +26,6 @@ extern "C" { #endif -typedef struct ogs_sbi_server_s ogs_sbi_server_t; -typedef struct ogs_sbi_session_s ogs_sbi_session_t; typedef struct ogs_sbi_request_s ogs_sbi_request_t; typedef struct ogs_sbi_response_s ogs_sbi_response_t; typedef struct ogs_sbi_message_s ogs_sbi_message_t; @@ -52,12 +50,7 @@ typedef struct udm_event_s { int timer_id; struct { - /* OGS_EVT_SBI_SERVER */ ogs_sbi_request_t *request; - ogs_sbi_session_t *session; - ogs_sbi_server_t *server; - - /* OGS_EVT_SBI_CLIENT */ ogs_sbi_response_t *response; void *data; diff --git a/src/udm/nf-sm.c b/src/udm/nf-sm.c index 67663a722..aa229b4d1 100644 --- a/src/udm/nf-sm.c +++ b/src/udm/nf-sm.c @@ -155,7 +155,7 @@ void udm_nf_state_will_register(ogs_fsm_t *s, udm_event_t *e) case UDM_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: client = nf_instance->client; ogs_assert(client); - addr = client->addr; + addr = client->node.addr; ogs_assert(addr); ogs_warn("[%s] Retry to registration with NRF", nf_instance->id); @@ -364,7 +364,7 @@ void udm_nf_state_exception(ogs_fsm_t *s, udm_event_t *e) case UDM_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: client = nf_instance->client; ogs_assert(client); - addr = client->addr; + addr = client->node.addr; ogs_assert(addr); ogs_warn("[%s] Retry to registration with NRF", nf_instance->id); diff --git a/src/udm/nnrf-handler.c b/src/udm/nnrf-handler.c index 5910f16f2..19468cd69 100644 --- a/src/udm/nnrf-handler.c +++ b/src/udm/nnrf-handler.c @@ -89,7 +89,7 @@ void udm_nnrf_handle_nf_status_subscribe( } bool udm_nnrf_handle_nf_status_notify( - ogs_sbi_session_t *session, ogs_sbi_message_t *message) + ogs_sbi_stream_t *stream, ogs_sbi_message_t *message) { ogs_sbi_response_t *response = NULL; OpenAPI_notification_data_t *NotificationData = NULL; @@ -97,13 +97,13 @@ bool udm_nnrf_handle_nf_status_notify( ogs_sbi_nf_instance_t *nf_instance = NULL; bool handled; - ogs_assert(session); + ogs_assert(stream); ogs_assert(message); NotificationData = message->NotificationData; if (!NotificationData) { ogs_error("No NotificationData"); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, message, "No NotificationData", NULL); return false; } @@ -111,21 +111,21 @@ bool udm_nnrf_handle_nf_status_notify( NFProfile = NotificationData->nf_profile; if (!NFProfile) { ogs_error("No NFProfile"); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, message, "No NFProfile", NULL); return false; } if (!NFProfile->nf_instance_id) { ogs_error("No NFProfile.NFInstanceId"); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, message, "No NFProfile", "NFInstanceId"); return false; } if (!NFProfile->nf_instance_id) { ogs_error("No NFProfile.NFInstanceId"); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, message, "No NFProfile", "NFInstanceId"); return false; } @@ -133,7 +133,7 @@ bool udm_nnrf_handle_nf_status_notify( if (NF_INSTANCE_IS_SELF(NFProfile->nf_instance_id)) { ogs_warn("The notification is not allowed [%s]", NFProfile->nf_instance_id); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_FORBIDDEN, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_FORBIDDEN, message, "The notification is not allowed", NFProfile->nf_instance_id); return false; @@ -159,7 +159,7 @@ bool udm_nnrf_handle_nf_status_notify( } handled = ogs_sbi_nnrf_handle_nf_profile( - nf_instance, NFProfile, session, message); + nf_instance, NFProfile, stream, message); if (!handled) { UDM_NF_INSTANCE_CLEAR("NRF-notify", nf_instance); return false; @@ -170,7 +170,7 @@ bool udm_nnrf_handle_nf_status_notify( handled = ogs_sbi_client_associate(nf_instance); if (!handled) { ogs_error("[%s] Cannot associate NF EndPoint", nf_instance->id); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, message, "Cannot find NF EndPoint", nf_instance->id); UDM_NF_INSTANCE_CLEAR("NRF-notify", nf_instance); @@ -184,7 +184,7 @@ bool udm_nnrf_handle_nf_status_notify( UDM_NF_INSTANCE_CLEAR("NRF-notify", nf_instance); } else { ogs_warn("[%s] (NRF-notify) Not found", NFProfile->nf_instance_id); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_NOT_FOUND, message, "Not found", message->h.resource.component[1]); return false; @@ -194,7 +194,7 @@ bool udm_nnrf_handle_nf_status_notify( NotificationData->event); ogs_error("Not supported event [%d:%s]", NotificationData->event, eventstr ? eventstr : "Unknown"); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, message, "Not supported event", eventstr ? eventstr : "Unknown"); return false; @@ -202,7 +202,7 @@ bool udm_nnrf_handle_nf_status_notify( response = ogs_sbi_build_response(message, OGS_SBI_HTTP_STATUS_NO_CONTENT); ogs_assert(response); - ogs_sbi_server_send_response(session, response); + ogs_sbi_server_send_response(stream, response); return true; } @@ -212,7 +212,7 @@ void udm_nnrf_handle_nf_discover( { ogs_sbi_object_t *sbi_object = NULL; ogs_sbi_nf_instance_t *nf_instance = NULL; - ogs_sbi_session_t *session = NULL; + ogs_sbi_stream_t *stream = NULL; OpenAPI_search_result_t *SearchResult = NULL; OpenAPI_lnode_t *node = NULL; @@ -221,8 +221,8 @@ void udm_nnrf_handle_nf_discover( ogs_assert(xact); sbi_object = xact->sbi_object; ogs_assert(sbi_object); - session = xact->assoc_session; - ogs_assert(session); + stream = xact->assoc_stream; + ogs_assert(stream); ogs_assert(message); SearchResult = message->SearchResult; diff --git a/src/udm/nnrf-handler.h b/src/udm/nnrf-handler.h index cd18f8fd4..a628b7a86 100644 --- a/src/udm/nnrf-handler.h +++ b/src/udm/nnrf-handler.h @@ -32,7 +32,7 @@ void udm_nnrf_handle_nf_status_subscribe( ogs_sbi_subscription_t *subscription, ogs_sbi_message_t *message); bool udm_nnrf_handle_nf_status_notify( - ogs_sbi_session_t *session, ogs_sbi_message_t *message); + ogs_sbi_stream_t *stream, ogs_sbi_message_t *message); void udm_nnrf_handle_nf_discover( ogs_sbi_xact_t *xact, ogs_sbi_message_t *message); diff --git a/src/udm/nudm-handler.c b/src/udm/nudm-handler.c index 2721f4494..67c8170d0 100644 --- a/src/udm/nudm-handler.c +++ b/src/udm/nudm-handler.c @@ -22,7 +22,7 @@ #include "nudm-handler.h" bool udm_nudm_ueau_handle_get( - udm_ue_t *udm_ue, ogs_sbi_session_t *session, ogs_sbi_message_t *recvmsg) + udm_ue_t *udm_ue, ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg) { OpenAPI_authentication_info_request_t *AuthenticationInfoRequest = NULL; OpenAPI_resynchronization_info_t *ResynchronizationInfo = NULL; @@ -30,13 +30,13 @@ bool udm_nudm_ueau_handle_get( char *ausf_instance_id = NULL; ogs_assert(udm_ue); - ogs_assert(session); + ogs_assert(stream); ogs_assert(recvmsg); AuthenticationInfoRequest = recvmsg->AuthenticationInfoRequest; if (!AuthenticationInfoRequest) { ogs_error("[%s] No AuthenticationInfoRequest", udm_ue->suci); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, recvmsg, "No AuthenticationInfoRequest", udm_ue->suci); return false; } @@ -44,7 +44,7 @@ bool udm_nudm_ueau_handle_get( serving_network_name = AuthenticationInfoRequest->serving_network_name; if (!AuthenticationInfoRequest) { ogs_error("[%s] No servingNetworkName", udm_ue->suci); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, recvmsg, "No servingNetworkName", udm_ue->suci); return false; } @@ -56,7 +56,7 @@ bool udm_nudm_ueau_handle_get( ausf_instance_id = AuthenticationInfoRequest->ausf_instance_id; if (!AuthenticationInfoRequest) { ogs_error("[%s] No ausfInstanceId", udm_ue->suci); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, recvmsg, "No ausfInstanceId", udm_ue->suci); return false; } @@ -68,7 +68,7 @@ bool udm_nudm_ueau_handle_get( ResynchronizationInfo = AuthenticationInfoRequest->resynchronization_info; if (!ResynchronizationInfo) { - udm_sbi_discover_and_send(OpenAPI_nf_type_UDR, udm_ue, session, NULL, + udm_sbi_discover_and_send(OpenAPI_nf_type_UDR, udm_ue, stream, NULL, udm_nudr_dr_build_authentication_subscription); } else { @@ -80,7 +80,7 @@ bool udm_nudm_ueau_handle_get( if (!ResynchronizationInfo->rand) { ogs_error("[%s] No RAND", udm_ue->suci); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, recvmsg, "No RAND", udm_ue->suci); return false; @@ -88,7 +88,7 @@ bool udm_nudm_ueau_handle_get( if (!ResynchronizationInfo->auts) { ogs_error("[%s] No AUTS", udm_ue->suci); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, recvmsg, "No AUTS", udm_ue->suci); return false; @@ -106,7 +106,7 @@ bool udm_nudm_ueau_handle_get( ogs_log_hexdump(OGS_LOG_ERROR, udm_ue->rand, sizeof(udm_ue)->rand); ogs_log_hexdump(OGS_LOG_ERROR, rand, sizeof(rand)); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, recvmsg, "Invalid RAND", udm_ue->suci); return false; @@ -120,7 +120,7 @@ bool udm_nudm_ueau_handle_get( ogs_log_hexdump(OGS_LOG_ERROR, mac_s, OGS_MAC_S_LEN); ogs_log_hexdump(OGS_LOG_ERROR, auts + OGS_SQN_LEN, OGS_MAC_S_LEN); ogs_log_hexdump(OGS_LOG_ERROR, sqn_ms, OGS_SQN_LEN); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_UNAUTHORIZED, recvmsg, "Re-sync MAC failed", udm_ue->suci); return false; @@ -152,7 +152,7 @@ bool udm_nudm_ueau_handle_get( ogs_uint64_to_buffer(sqn, OGS_SQN_LEN, udm_ue->sqn); udm_sbi_discover_and_send(OpenAPI_nf_type_UDR, - udm_ue, session, udm_ue->sqn, + udm_ue, stream, udm_ue->sqn, udm_nudr_dr_build_authentication_subscription); } @@ -160,15 +160,15 @@ bool udm_nudm_ueau_handle_get( } bool udm_nudm_ueau_handle_result_confirmation_inform( - udm_ue_t *udm_ue, ogs_sbi_session_t *session, ogs_sbi_message_t *message) + udm_ue_t *udm_ue, ogs_sbi_stream_t *stream, ogs_sbi_message_t *message) { ogs_assert(udm_ue); - ogs_assert(session); + ogs_assert(stream); ogs_assert(message); if (!message->AuthEvent) { ogs_error("[%s] No AuthEvent", udm_ue->suci); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, message, "No AuthEvent", udm_ue->suci); return false; } @@ -176,33 +176,33 @@ bool udm_nudm_ueau_handle_result_confirmation_inform( udm_ue->auth_event = OpenAPI_auth_event_copy( udm_ue->auth_event, message->AuthEvent); - udm_sbi_discover_and_send(OpenAPI_nf_type_UDR, udm_ue, session, NULL, + udm_sbi_discover_and_send(OpenAPI_nf_type_UDR, udm_ue, stream, NULL, udm_nudr_dr_build_update_authentication_status); return true; } bool udm_nudm_uecm_handle_registration( - udm_ue_t *udm_ue, ogs_sbi_session_t *session, ogs_sbi_message_t *message) + udm_ue_t *udm_ue, ogs_sbi_stream_t *stream, ogs_sbi_message_t *message) { OpenAPI_amf3_gpp_access_registration_t *Amf3GppAccessRegistration = NULL; OpenAPI_guami_t *Guami = NULL; ogs_assert(udm_ue); - ogs_assert(session); + ogs_assert(stream); ogs_assert(message); Amf3GppAccessRegistration = message->Amf3GppAccessRegistration; if (!Amf3GppAccessRegistration) { ogs_error("[%s] No Amf3GppAccessRegistration", udm_ue->supi); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, message, "No Amf3GppAccessRegistration", udm_ue->supi); return false; } if (!Amf3GppAccessRegistration->dereg_callback_uri) { ogs_error("[%s] No dregCallbackUri", udm_ue->supi); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, message, "No dregCallbackUri", udm_ue->supi); return false; } @@ -210,35 +210,35 @@ bool udm_nudm_uecm_handle_registration( Guami = Amf3GppAccessRegistration->guami; if (!Guami) { ogs_error("[%s] No Guami", udm_ue->supi); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, message, "No Guami", udm_ue->supi); return false; } if (!Guami->amf_id) { ogs_error("[%s] No Guami.AmfId", udm_ue->supi); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, message, "No Guami.AmfId", udm_ue->supi); return false; } if (!Guami->plmn_id) { ogs_error("[%s] No PlmnId", udm_ue->supi); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, message, "No PlmnId", udm_ue->supi); return false; } if (!Guami->plmn_id->mnc) { ogs_error("[%s] No PlmnId.Mnc", udm_ue->supi); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, message, "No PlmnId.Mnc", udm_ue->supi); return false; } if (!Guami->plmn_id->mcc) { ogs_error("[%s] No PlmnId.Mcc", udm_ue->supi); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, message, "No PlmnId.Mcc", udm_ue->supi); return false; } @@ -255,20 +255,20 @@ bool udm_nudm_uecm_handle_registration( udm_ue->amf_3gpp_access_registration, message->Amf3GppAccessRegistration); - udm_sbi_discover_and_send(OpenAPI_nf_type_UDR, udm_ue, session, NULL, + udm_sbi_discover_and_send(OpenAPI_nf_type_UDR, udm_ue, stream, NULL, udm_nudr_dr_build_update_amf_context); return true; } bool udm_nudm_sdm_handle_subscription_provisioned( - udm_ue_t *udm_ue, ogs_sbi_session_t *session, ogs_sbi_message_t *recvmsg) + udm_ue_t *udm_ue, ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg) { ogs_sbi_message_t sendmsg; ogs_sbi_response_t *response = NULL; ogs_assert(udm_ue); - ogs_assert(session); + ogs_assert(stream); ogs_assert(recvmsg); SWITCH(recvmsg->h.resource.component[1]) @@ -277,7 +277,7 @@ bool udm_nudm_sdm_handle_subscription_provisioned( response = ogs_sbi_build_response(&sendmsg, OGS_SBI_HTTP_STATUS_OK); ogs_assert(response); - ogs_sbi_server_send_response(session, response); + ogs_sbi_server_send_response(stream, response); break; diff --git a/src/udm/nudm-handler.h b/src/udm/nudm-handler.h index ffdd09404..c7a447e2e 100644 --- a/src/udm/nudm-handler.h +++ b/src/udm/nudm-handler.h @@ -27,15 +27,15 @@ extern "C" { #endif bool udm_nudm_ueau_handle_get( - udm_ue_t *udm_ue, ogs_sbi_session_t *session, ogs_sbi_message_t *recvmsg); + udm_ue_t *udm_ue, ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg); bool udm_nudm_ueau_handle_result_confirmation_inform( - udm_ue_t *udm_ue, ogs_sbi_session_t *session, ogs_sbi_message_t *message); + udm_ue_t *udm_ue, ogs_sbi_stream_t *stream, ogs_sbi_message_t *message); bool udm_nudm_uecm_handle_registration( - udm_ue_t *udm_ue, ogs_sbi_session_t *session, ogs_sbi_message_t *message); + udm_ue_t *udm_ue, ogs_sbi_stream_t *stream, ogs_sbi_message_t *message); bool udm_nudm_sdm_handle_subscription_provisioned( - udm_ue_t *udm_ue, ogs_sbi_session_t *session, ogs_sbi_message_t *recvmsg); + udm_ue_t *udm_ue, ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg); #ifdef __cplusplus } diff --git a/src/udm/nudr-handler.c b/src/udm/nudr-handler.c index 45d5ebf93..586da99f4 100644 --- a/src/udm/nudr-handler.c +++ b/src/udm/nudr-handler.c @@ -20,7 +20,7 @@ #include "nudr-handler.h" bool udm_nudr_dr_handle_subscription_authentication( - udm_ue_t *udm_ue, ogs_sbi_session_t *session, ogs_sbi_message_t *recvmsg) + udm_ue_t *udm_ue, ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg) { ogs_sbi_server_t *server = NULL; @@ -59,8 +59,8 @@ bool udm_nudr_dr_handle_subscription_authentication( OpenAPI_authentication_vector_t AuthenticationVector; ogs_assert(udm_ue); - ogs_assert(session); - server = ogs_sbi_session_get_server(session); + ogs_assert(stream); + server = ogs_sbi_server_from_stream(stream); ogs_assert(server); ogs_assert(recvmsg); @@ -73,7 +73,7 @@ bool udm_nudr_dr_handle_subscription_authentication( AuthenticationSubscription = recvmsg->AuthenticationSubscription; if (!AuthenticationSubscription) { ogs_error("[%s] No AuthenticationSubscription", udm_ue->suci); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_INTERNAL_SERVER_ERROR, recvmsg, "No AuthenticationSubscription", udm_ue->suci); return false; @@ -84,7 +84,7 @@ bool udm_nudr_dr_handle_subscription_authentication( ogs_error("[%s] Not supported Auth Method [%d]", udm_ue->suci, AuthenticationSubscription->authentication_method); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_FORBIDDEN, recvmsg, "Not supported Auth Method", udm_ue->suci); return false; @@ -93,14 +93,14 @@ bool udm_nudr_dr_handle_subscription_authentication( if (!AuthenticationSubscription->enc_permanent_key) { ogs_error("[%s] No encPermanentKey", udm_ue->suci); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_INTERNAL_SERVER_ERROR, recvmsg, "No encPermanentKey", udm_ue->suci); return false; } if (!AuthenticationSubscription->enc_opc_key) { ogs_error("[%s] No encPermanentKey", udm_ue->suci); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_INTERNAL_SERVER_ERROR, recvmsg, "No encPermanentKey", udm_ue->suci); return false; @@ -108,21 +108,21 @@ bool udm_nudr_dr_handle_subscription_authentication( if (!AuthenticationSubscription->authentication_management_field) { ogs_error("[%s] No authenticationManagementField", udm_ue->suci); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_INTERNAL_SERVER_ERROR, recvmsg, "No authenticationManagementField", udm_ue->suci); return false; } if (!AuthenticationSubscription->sequence_number) { ogs_error("[%s] No SequenceNumber", udm_ue->suci); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_INTERNAL_SERVER_ERROR, recvmsg, "No SequenceNumber", udm_ue->suci); return false; } if (!AuthenticationSubscription->sequence_number->sqn) { ogs_error("[%s] No SequenceNumber.sqn", udm_ue->suci); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_INTERNAL_SERVER_ERROR, recvmsg, "No SequenceNumber.sqn", udm_ue->suci); return false; @@ -205,13 +205,13 @@ bool udm_nudr_dr_handle_subscription_authentication( response = ogs_sbi_build_response(&sendmsg, OGS_SBI_HTTP_STATUS_OK); ogs_assert(response); - ogs_sbi_server_send_response(session, response); + ogs_sbi_server_send_response(stream, response); return true; DEFAULT ogs_error("Invalid HTTP method [%s]", recvmsg->h.method); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_FORBIDDEN, recvmsg, "Invalid HTTP method", recvmsg->h.method); END @@ -235,7 +235,7 @@ bool udm_nudr_dr_handle_subscription_authentication( response = ogs_sbi_build_response(&sendmsg, OGS_SBI_HTTP_STATUS_CREATED); ogs_assert(response); - ogs_sbi_server_send_response(session, response); + ogs_sbi_server_send_response(stream, response); ogs_free(sendmsg.http.location); OpenAPI_auth_event_free(sendmsg.AuthEvent); @@ -251,7 +251,7 @@ bool udm_nudr_dr_handle_subscription_authentication( } bool udm_nudr_dr_handle_subscription_context( - udm_ue_t *udm_ue, ogs_sbi_session_t *session, ogs_sbi_message_t *recvmsg) + udm_ue_t *udm_ue, ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg) { ogs_sbi_server_t *server = NULL; @@ -264,8 +264,8 @@ bool udm_nudr_dr_handle_subscription_context( OpenAPI_amf3_gpp_access_registration_t *Amf3GppAccessRegistration = NULL; ogs_assert(udm_ue); - ogs_assert(session); - server = ogs_sbi_session_get_server(session); + ogs_assert(stream); + server = ogs_sbi_server_from_stream(stream); ogs_assert(server); ogs_assert(recvmsg); @@ -275,14 +275,14 @@ bool udm_nudr_dr_handle_subscription_context( Amf3GppAccessRegistration = udm_ue->amf_3gpp_access_registration; if (!Amf3GppAccessRegistration) { ogs_error("[%s] No Amf3GppAccessRegistration", udm_ue->supi); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, recvmsg, "No Amf3GppAccessRegistration", udm_ue->supi); return false; } if (!Amf3GppAccessRegistration->amf_instance_id) { ogs_error("[%s] No amfInstanceId", udm_ue->supi); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, recvmsg, "No amfInstanceId", udm_ue->supi); return false; } @@ -315,7 +315,7 @@ bool udm_nudr_dr_handle_subscription_context( response = ogs_sbi_build_response(&sendmsg, status); ogs_assert(response); - ogs_sbi_server_send_response(session, response); + ogs_sbi_server_send_response(stream, response); ogs_free(sendmsg.http.location); OpenAPI_amf3_gpp_access_registration_free( @@ -331,7 +331,7 @@ bool udm_nudr_dr_handle_subscription_context( } bool udm_nudr_dr_handle_subscription_provisioned( - udm_ue_t *udm_ue, ogs_sbi_session_t *session, ogs_sbi_message_t *recvmsg) + udm_ue_t *udm_ue, ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg) { ogs_sbi_server_t *server = NULL; @@ -339,8 +339,8 @@ bool udm_nudr_dr_handle_subscription_provisioned( ogs_sbi_response_t *response = NULL; ogs_assert(udm_ue); - ogs_assert(session); - server = ogs_sbi_session_get_server(session); + ogs_assert(stream); + server = ogs_sbi_server_from_stream(stream); ogs_assert(server); ogs_assert(recvmsg); @@ -357,7 +357,7 @@ bool udm_nudr_dr_handle_subscription_provisioned( response = ogs_sbi_build_response(&sendmsg, recvmsg->res_status); ogs_assert(response); - ogs_sbi_server_send_response(session, response); + ogs_sbi_server_send_response(stream, response); OpenAPI_access_and_mobility_subscription_data_free( sendmsg.AccessAndMobilitySubscriptionData); @@ -368,7 +368,7 @@ bool udm_nudr_dr_handle_subscription_provisioned( response = ogs_sbi_build_response(&sendmsg, recvmsg->res_status); ogs_assert(response); - ogs_sbi_server_send_response(session, response); + ogs_sbi_server_send_response(stream, response); break; @@ -383,7 +383,7 @@ bool udm_nudr_dr_handle_subscription_provisioned( response = ogs_sbi_build_response(&sendmsg, recvmsg->res_status); ogs_assert(response); - ogs_sbi_server_send_response(session, response); + ogs_sbi_server_send_response(stream, response); OpenAPI_session_management_subscription_data_free( sendmsg.SessionManagementSubscriptionData); diff --git a/src/udm/nudr-handler.h b/src/udm/nudr-handler.h index 3c20871f1..2049158ea 100644 --- a/src/udm/nudr-handler.h +++ b/src/udm/nudr-handler.h @@ -27,11 +27,11 @@ extern "C" { #endif bool udm_nudr_dr_handle_subscription_authentication( - udm_ue_t *udm_ue, ogs_sbi_session_t *session, ogs_sbi_message_t *recvmsg); + udm_ue_t *udm_ue, ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg); bool udm_nudr_dr_handle_subscription_context( - udm_ue_t *udm_ue, ogs_sbi_session_t *session, ogs_sbi_message_t *recvmsg); + udm_ue_t *udm_ue, ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg); bool udm_nudr_dr_handle_subscription_provisioned( - udm_ue_t *udm_ue, ogs_sbi_session_t *session, ogs_sbi_message_t *recvmsg); + udm_ue_t *udm_ue, ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg); #ifdef __cplusplus } diff --git a/src/udm/sbi-path.c b/src/udm/sbi-path.c index ea3e2cfb4..40b30402f 100644 --- a/src/udm/sbi-path.c +++ b/src/udm/sbi-path.c @@ -19,21 +19,19 @@ #include "sbi-path.h" -static int server_cb(ogs_sbi_server_t *server, - ogs_sbi_session_t *session, ogs_sbi_request_t *request) +static int server_cb(ogs_sbi_request_t *request, void *data) { udm_event_t *e = NULL; int rv; - ogs_assert(session); ogs_assert(request); + ogs_assert(data); e = udm_event_new(UDM_EVT_SBI_SERVER); ogs_assert(e); - e->sbi.server = server; - e->sbi.session = session; e->sbi.request = request; + e->sbi.data = data; rv = ogs_queue_push(ogs_app()->queue, e); if (rv != OGS_OK) { @@ -130,26 +128,26 @@ void udm_sbi_send(ogs_sbi_nf_instance_t *nf_instance, ogs_sbi_xact_t *xact) } void udm_sbi_discover_and_send(OpenAPI_nf_type_e target_nf_type, - udm_ue_t *udm_ue, ogs_sbi_session_t *session, void *data, + udm_ue_t *udm_ue, ogs_sbi_stream_t *stream, void *data, ogs_sbi_request_t *(*build)(udm_ue_t *udm_ue, void *data)) { ogs_sbi_xact_t *xact = NULL; ogs_assert(target_nf_type); ogs_assert(udm_ue); - ogs_assert(session); + ogs_assert(stream); ogs_assert(build); xact = ogs_sbi_xact_add(target_nf_type, &udm_ue->sbi, data, (ogs_sbi_build_f)build, udm_timer_sbi_client_wait_expire); ogs_assert(xact); - xact->assoc_session = session; + xact->assoc_stream = stream; if (ogs_sbi_discover_and_send(xact, (ogs_fsm_handler_t)udm_nf_state_registered, client_cb) != true) { - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_GATEWAY_TIMEOUT, NULL, "Cannot discover", udm_ue->suci); } diff --git a/src/udm/sbi-path.h b/src/udm/sbi-path.h index 18ce48cea..a661add52 100644 --- a/src/udm/sbi-path.h +++ b/src/udm/sbi-path.h @@ -33,7 +33,7 @@ void udm_sbi_close(void); void udm_sbi_send(ogs_sbi_nf_instance_t *nf_instance, ogs_sbi_xact_t *xact); void udm_sbi_discover_and_send(OpenAPI_nf_type_e target_nf_type, - udm_ue_t *udm_ue, ogs_sbi_session_t *session, void *data, + udm_ue_t *udm_ue, ogs_sbi_stream_t *stream, void *data, ogs_sbi_request_t *(*build)(udm_ue_t *udm_ue, void *data)); #ifdef __cplusplus diff --git a/src/udm/udm-sm.c b/src/udm/udm-sm.c index 412de4812..e09135c72 100644 --- a/src/udm/udm-sm.c +++ b/src/udm/udm-sm.c @@ -39,7 +39,7 @@ void udm_state_operational(ogs_fsm_t *s, udm_event_t *e) int rv; const char *api_version = NULL; - ogs_sbi_session_t *session = NULL; + ogs_sbi_stream_t *stream = NULL; ogs_sbi_request_t *request = NULL; ogs_sbi_nf_instance_t *nf_instance = NULL; @@ -70,14 +70,14 @@ void udm_state_operational(ogs_fsm_t *s, udm_event_t *e) case UDM_EVT_SBI_SERVER: request = e->sbi.request; ogs_assert(request); - session = e->sbi.session; - ogs_assert(session); + stream = e->sbi.data; + ogs_assert(stream); rv = ogs_sbi_parse_request(&message, request); if (rv != OGS_OK) { /* 'message' buffer is released in ogs_sbi_parse_request() */ ogs_error("cannot parse HTTP message"); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, NULL, "cannot parse HTTP message", NULL); break; } @@ -92,7 +92,7 @@ void udm_state_operational(ogs_fsm_t *s, udm_event_t *e) if (strcmp(message.h.api.version, api_version) != 0) { ogs_error("Not supported version [%s]", message.h.api.version); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, &message, "Not supported version", NULL); ogs_sbi_message_free(&message); break; @@ -105,13 +105,13 @@ void udm_state_operational(ogs_fsm_t *s, udm_event_t *e) CASE(OGS_SBI_RESOURCE_NAME_NF_STATUS_NOTIFY) SWITCH(message.h.method) CASE(OGS_SBI_HTTP_METHOD_POST) - udm_nnrf_handle_nf_status_notify(session, &message); + udm_nnrf_handle_nf_status_notify(stream, &message); break; DEFAULT ogs_error("Invalid HTTP method [%s]", message.h.method); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_FORBIDDEN, &message, "Invalid HTTP method", message.h.method); END @@ -120,7 +120,7 @@ void udm_state_operational(ogs_fsm_t *s, udm_event_t *e) DEFAULT ogs_error("Invalid resource name [%s]", message.h.resource.component[0]); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, &message, "Unknown resource name", message.h.resource.component[0]); @@ -132,7 +132,7 @@ void udm_state_operational(ogs_fsm_t *s, udm_event_t *e) CASE(OGS_SBI_SERVICE_NAME_NUDM_SDM) if (!message.h.resource.component[0]) { ogs_error("Not found [%s]", message.h.method); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_NOT_FOUND, &message, "Not found", message.h.method); break; @@ -140,7 +140,7 @@ void udm_state_operational(ogs_fsm_t *s, udm_event_t *e) if (!message.h.resource.component[1]) { ogs_error("Invalid resource name [%s]", message.h.method); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, &message, "Invalid resource name", message.h.method); break; @@ -163,7 +163,7 @@ void udm_state_operational(ogs_fsm_t *s, udm_event_t *e) if (!udm_ue) { ogs_error("Not found [%s]", message.h.method); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_NOT_FOUND, &message, "Not found", message.h.method); break; @@ -182,7 +182,7 @@ void udm_state_operational(ogs_fsm_t *s, udm_event_t *e) DEFAULT ogs_error("Invalid API name [%s]", message.h.service.name); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, &message, "Invalid API name", message.h.service.name); END @@ -313,7 +313,7 @@ void udm_state_operational(ogs_fsm_t *s, udm_event_t *e) e->udm_ue = udm_ue; e->sbi.message = &message; - e->sbi.session = sbi_xact->assoc_session; + e->sbi.data = sbi_xact->assoc_stream; ogs_sbi_xact_remove(sbi_xact); @@ -374,13 +374,13 @@ void udm_state_operational(ogs_fsm_t *s, udm_event_t *e) sbi_xact = e->sbi.data; ogs_assert(sbi_xact); - session = sbi_xact->assoc_session; - ogs_assert(session); + stream = sbi_xact->assoc_stream; + ogs_assert(stream); ogs_sbi_xact_remove(sbi_xact); ogs_error("Cannot receive SBI message"); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_GATEWAY_TIMEOUT, NULL, "Cannot receive SBI message", NULL); break; diff --git a/src/udm/ue-sm.c b/src/udm/ue-sm.c index 8ff8b1b9a..09457d231 100644 --- a/src/udm/ue-sm.c +++ b/src/udm/ue-sm.c @@ -38,7 +38,7 @@ void udm_ue_state_operational(ogs_fsm_t *s, udm_event_t *e) bool handled; udm_ue_t *udm_ue = NULL; - ogs_sbi_session_t *session = NULL; + ogs_sbi_stream_t *stream = NULL; ogs_sbi_message_t *message = NULL; ogs_assert(s); @@ -59,8 +59,8 @@ void udm_ue_state_operational(ogs_fsm_t *s, udm_event_t *e) case UDM_EVT_SBI_SERVER: message = e->sbi.message; ogs_assert(message); - session = e->sbi.session; - ogs_assert(session); + stream = e->sbi.data; + ogs_assert(stream); SWITCH(message->h.service.name) CASE(OGS_SBI_SERVICE_NAME_NUDM_UEAU) @@ -68,16 +68,16 @@ void udm_ue_state_operational(ogs_fsm_t *s, udm_event_t *e) CASE(OGS_SBI_HTTP_METHOD_POST) SWITCH(message->h.resource.component[1]) CASE(OGS_SBI_RESOURCE_NAME_SECURITY_INFORMATION) - udm_nudm_ueau_handle_get(udm_ue, session, message); + udm_nudm_ueau_handle_get(udm_ue, stream, message); break; CASE(OGS_SBI_RESOURCE_NAME_AUTH_EVENTS) udm_nudm_ueau_handle_result_confirmation_inform( - udm_ue, session, message); + udm_ue, stream, message); break; DEFAULT ogs_error("[%s] Invalid resource name [%s]", udm_ue->suci, message->h.resource.component[1]); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, message, "Invalid resource name", message->h.method); END @@ -86,7 +86,7 @@ void udm_ue_state_operational(ogs_fsm_t *s, udm_event_t *e) DEFAULT ogs_error("[%s] Invalid HTTP method [%s]", udm_ue->suci, message->h.method); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_FORBIDDEN, message, "Invalid HTTP method", message->h.method); END @@ -97,13 +97,13 @@ void udm_ue_state_operational(ogs_fsm_t *s, udm_event_t *e) CASE(OGS_SBI_HTTP_METHOD_PUT) SWITCH(message->h.resource.component[1]) CASE(OGS_SBI_RESOURCE_NAME_REGISTRATIONS) - udm_nudm_uecm_handle_registration(udm_ue, session, message); + udm_nudm_uecm_handle_registration(udm_ue, stream, message); break; DEFAULT ogs_error("[%s] Invalid resource name [%s]", udm_ue->suci, message->h.resource.component[1]); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, message, "Invalid HTTP method", message->h.method); END @@ -111,7 +111,7 @@ void udm_ue_state_operational(ogs_fsm_t *s, udm_event_t *e) DEFAULT ogs_error("[%s] Invalid HTTP method [%s]", udm_ue->suci, message->h.method); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_FORBIDDEN, message, "Invalid HTTP method", message->h.method); END @@ -125,19 +125,19 @@ void udm_ue_state_operational(ogs_fsm_t *s, udm_event_t *e) CASE(OGS_SBI_RESOURCE_NAME_SMF_SELECT_DATA) CASE(OGS_SBI_RESOURCE_NAME_SM_DATA) udm_sbi_discover_and_send( - OpenAPI_nf_type_UDR, udm_ue, session, message, + OpenAPI_nf_type_UDR, udm_ue, stream, message, udm_nudr_dr_build_query_subscription_provisioned); break; CASE(OGS_SBI_RESOURCE_NAME_UE_CONTEXT_IN_SMF_DATA) udm_nudm_sdm_handle_subscription_provisioned( - udm_ue, session, message); + udm_ue, stream, message); break; DEFAULT ogs_error("[%s] Invalid resource name [%s]", udm_ue->suci, message->h.resource.component[1]); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, message, "Invalid resource name", message->h.method); END @@ -145,7 +145,7 @@ void udm_ue_state_operational(ogs_fsm_t *s, udm_event_t *e) DEFAULT ogs_error("[%s] Invalid HTTP method [%s]", udm_ue->supi, message->h.method); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_NOT_FOUND, message, "Invalid HTTP method", message->h.method); END @@ -153,7 +153,7 @@ void udm_ue_state_operational(ogs_fsm_t *s, udm_event_t *e) DEFAULT ogs_error("Invalid API name [%s]", message->h.service.name); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, message, "Invalid API name", message->h.service.name); END @@ -165,8 +165,8 @@ void udm_ue_state_operational(ogs_fsm_t *s, udm_event_t *e) udm_ue = e->udm_ue; ogs_assert(udm_ue); - session = e->sbi.session; - ogs_assert(session); + stream = e->sbi.data; + ogs_assert(stream); SWITCH(message->h.service.name) CASE(OGS_SBI_SERVICE_NAME_NUDR_DR) @@ -185,13 +185,13 @@ void udm_ue_state_operational(ogs_fsm_t *s, udm_event_t *e) udm_ue->suci, message->res_status); } ogs_sbi_server_send_error( - session, message->res_status, + stream, message->res_status, NULL, "HTTP response error", udm_ue->suci); break; } udm_nudr_dr_handle_subscription_authentication( - udm_ue, session, message); + udm_ue, stream, message); break; CASE(OGS_SBI_RESOURCE_NAME_CONTEXT_DATA) @@ -199,23 +199,23 @@ void udm_ue_state_operational(ogs_fsm_t *s, udm_event_t *e) ogs_error("[%s] HTTP response error [%d]", udm_ue->suci, message->res_status); ogs_sbi_server_send_error( - session, message->res_status, + stream, message->res_status, NULL, "HTTP response error", udm_ue->suci); break; } udm_nudr_dr_handle_subscription_context( - udm_ue, session, message); + udm_ue, stream, message); break; DEFAULT SWITCH(message->h.resource.component[3]) CASE(OGS_SBI_RESOURCE_NAME_PROVISIONED_DATA) handled = udm_nudr_dr_handle_subscription_provisioned( - udm_ue, session, message); + udm_ue, stream, message); if (!handled) { ogs_sbi_server_send_error( - session, message->res_status, + stream, message->res_status, NULL, "HTTP response error", udm_ue->suci); } break; @@ -236,7 +236,7 @@ void udm_ue_state_operational(ogs_fsm_t *s, udm_event_t *e) DEFAULT ogs_error("Invalid API name [%s]", message->h.service.name); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, message, "Invalid API name", message->h.resource.component[0]); END diff --git a/src/udr/event.h b/src/udr/event.h index 84ceca74c..761c2ff12 100644 --- a/src/udr/event.h +++ b/src/udr/event.h @@ -26,8 +26,6 @@ extern "C" { #endif -typedef struct ogs_sbi_server_s ogs_sbi_server_t; -typedef struct ogs_sbi_session_s ogs_sbi_session_t; typedef struct ogs_sbi_request_s ogs_sbi_request_t; typedef struct ogs_sbi_response_s ogs_sbi_response_t; typedef struct ogs_sbi_message_s ogs_sbi_message_t; @@ -50,12 +48,7 @@ typedef struct udr_event_s { int timer_id; struct { - /* OGS_EVT_SBI_SERVER */ ogs_sbi_request_t *request; - ogs_sbi_session_t *session; - ogs_sbi_server_t *server; - - /* OGS_EVT_SBI_CLIENT */ ogs_sbi_response_t *response; void *data; diff --git a/src/udr/nf-sm.c b/src/udr/nf-sm.c index 8d180e341..0bfa978a5 100644 --- a/src/udr/nf-sm.c +++ b/src/udr/nf-sm.c @@ -155,7 +155,7 @@ void udr_nf_state_will_register(ogs_fsm_t *s, udr_event_t *e) case UDR_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: client = nf_instance->client; ogs_assert(client); - addr = client->addr; + addr = client->node.addr; ogs_assert(addr); ogs_warn("[%s] Retry to registration with NRF", nf_instance->id); @@ -364,7 +364,7 @@ void udr_nf_state_exception(ogs_fsm_t *s, udr_event_t *e) case UDR_TIMER_NF_INSTANCE_REGISTRATION_INTERVAL: client = nf_instance->client; ogs_assert(client); - addr = client->addr; + addr = client->node.addr; ogs_assert(addr); ogs_warn("[%s] Retry to registration with NRF", nf_instance->id); diff --git a/src/udr/nnrf-handler.c b/src/udr/nnrf-handler.c index fee1aa4e7..7ec96899f 100644 --- a/src/udr/nnrf-handler.c +++ b/src/udr/nnrf-handler.c @@ -89,7 +89,7 @@ void udr_nnrf_handle_nf_status_subscribe( } bool udr_nnrf_handle_nf_status_notify( - ogs_sbi_session_t *session, ogs_sbi_message_t *message) + ogs_sbi_stream_t *stream, ogs_sbi_message_t *message) { ogs_sbi_response_t *response = NULL; OpenAPI_notification_data_t *NotificationData = NULL; @@ -97,13 +97,13 @@ bool udr_nnrf_handle_nf_status_notify( ogs_sbi_nf_instance_t *nf_instance = NULL; bool handled; - ogs_assert(session); + ogs_assert(stream); ogs_assert(message); NotificationData = message->NotificationData; if (!NotificationData) { ogs_error("No NotificationData"); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, message, "No NotificationData", NULL); return false; } @@ -111,21 +111,21 @@ bool udr_nnrf_handle_nf_status_notify( NFProfile = NotificationData->nf_profile; if (!NFProfile) { ogs_error("No NFProfile"); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, message, "No NFProfile", NULL); return false; } if (!NFProfile->nf_instance_id) { ogs_error("No NFProfile.NFInstanceId"); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, message, "No NFProfile", "NFInstanceId"); return false; } if (!NFProfile->nf_instance_id) { ogs_error("No NFProfile.NFInstanceId"); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, message, "No NFProfile", "NFInstanceId"); return false; } @@ -133,7 +133,7 @@ bool udr_nnrf_handle_nf_status_notify( if (NF_INSTANCE_IS_SELF(NFProfile->nf_instance_id)) { ogs_warn("The notification is not allowed [%s]", NFProfile->nf_instance_id); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_FORBIDDEN, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_FORBIDDEN, message, "The notification is not allowed", NFProfile->nf_instance_id); return false; @@ -159,7 +159,7 @@ bool udr_nnrf_handle_nf_status_notify( } handled = ogs_sbi_nnrf_handle_nf_profile( - nf_instance, NFProfile, session, message); + nf_instance, NFProfile, stream, message); if (!handled) { UDR_NF_INSTANCE_CLEAR("NRF-notify", nf_instance); return false; @@ -170,7 +170,7 @@ bool udr_nnrf_handle_nf_status_notify( handled = ogs_sbi_client_associate(nf_instance); if (!handled) { ogs_error("[%s] Cannot associate NF EndPoint", nf_instance->id); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, message, "Cannot find NF EndPoint", nf_instance->id); UDR_NF_INSTANCE_CLEAR("NRF-notify", nf_instance); @@ -184,7 +184,7 @@ bool udr_nnrf_handle_nf_status_notify( UDR_NF_INSTANCE_CLEAR("NRF-notify", nf_instance); } else { ogs_warn("[%s] (NRF-notify) Not found", NFProfile->nf_instance_id); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_NOT_FOUND, message, "Not found", message->h.resource.component[1]); return false; @@ -194,7 +194,7 @@ bool udr_nnrf_handle_nf_status_notify( NotificationData->event); ogs_error("Not supported event [%d:%s]", NotificationData->event, eventstr ? eventstr : "Unknown"); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, message, "Not supported event", eventstr ? eventstr : "Unknown"); return false; @@ -202,7 +202,7 @@ bool udr_nnrf_handle_nf_status_notify( response = ogs_sbi_build_response(message, OGS_SBI_HTTP_STATUS_NO_CONTENT); ogs_assert(response); - ogs_sbi_server_send_response(session, response); + ogs_sbi_server_send_response(stream, response); return true; } diff --git a/src/udr/nnrf-handler.h b/src/udr/nnrf-handler.h index bbb289a1d..a7890bf1b 100644 --- a/src/udr/nnrf-handler.h +++ b/src/udr/nnrf-handler.h @@ -32,7 +32,7 @@ void udr_nnrf_handle_nf_status_subscribe( ogs_sbi_subscription_t *subscription, ogs_sbi_message_t *message); bool udr_nnrf_handle_nf_status_notify( - ogs_sbi_session_t *session, ogs_sbi_message_t *message); + ogs_sbi_stream_t *stream, ogs_sbi_message_t *message); #ifdef __cplusplus } diff --git a/src/udr/nudr-handler.c b/src/udr/nudr-handler.c index 43f635984..da839cb2b 100644 --- a/src/udr/nudr-handler.c +++ b/src/udr/nudr-handler.c @@ -22,7 +22,7 @@ #include "nudr-handler.h" bool udr_nudr_dr_handle_subscription_authentication( - ogs_sbi_session_t *session, ogs_sbi_message_t *recvmsg) + ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg) { int rv; @@ -44,13 +44,13 @@ bool udr_nudr_dr_handle_subscription_authentication( OpenAPI_list_t *PatchItemList = NULL; OpenAPI_lnode_t *node = NULL; - ogs_assert(session); + ogs_assert(stream); ogs_assert(recvmsg); supi = recvmsg->h.resource.component[1]; if (!supi) { ogs_error("No SUPI"); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, recvmsg, "No SUPI", NULL); return false; } @@ -58,7 +58,7 @@ bool udr_nudr_dr_handle_subscription_authentication( if (strncmp(supi, OGS_ID_SUPI_TYPE_IMSI, strlen(OGS_ID_SUPI_TYPE_IMSI)) != 0) { ogs_error("[%s] Unknown SUPI Type", supi); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_FORBIDDEN, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_FORBIDDEN, recvmsg, "Unknwon SUPI Type", supi); return false; } @@ -66,7 +66,7 @@ bool udr_nudr_dr_handle_subscription_authentication( rv = ogs_dbi_auth_info(supi, &auth_info); if (rv != OGS_OK) { ogs_warn("[%s] Cannot find SUPI in DB", supi); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_NOT_FOUND, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_NOT_FOUND, recvmsg, "Cannot find SUPI Type", supi); return false; } @@ -113,7 +113,7 @@ bool udr_nudr_dr_handle_subscription_authentication( response = ogs_sbi_build_response( &sendmsg, OGS_SBI_HTTP_STATUS_OK); ogs_assert(response); - ogs_sbi_server_send_response(session, response); + ogs_sbi_server_send_response(stream, response); return true; @@ -124,7 +124,7 @@ bool udr_nudr_dr_handle_subscription_authentication( PatchItemList = recvmsg->PatchItemList; if (!PatchItemList) { - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, recvmsg, "No PatchItemList Array", NULL); return false; @@ -138,7 +138,7 @@ bool udr_nudr_dr_handle_subscription_authentication( } if (!sqn_string) { - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, recvmsg, "No PatchItemList", NULL); return false; @@ -151,7 +151,7 @@ bool udr_nudr_dr_handle_subscription_authentication( rv = ogs_dbi_update_sqn(supi, sqn); if (rv != OGS_OK) { ogs_fatal("[%s] Cannot update SQN", supi); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_INTERNAL_SERVER_ERROR, recvmsg, "Cannot update SQN", supi); return false; @@ -160,7 +160,7 @@ bool udr_nudr_dr_handle_subscription_authentication( rv = ogs_dbi_increment_sqn(supi); if (rv != OGS_OK) { ogs_fatal("[%s] Cannot increment SQN", supi); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_INTERNAL_SERVER_ERROR, recvmsg, "Cannot increment SQN", supi); return false; @@ -171,13 +171,13 @@ bool udr_nudr_dr_handle_subscription_authentication( response = ogs_sbi_build_response( &sendmsg, OGS_SBI_HTTP_STATUS_NO_CONTENT); ogs_assert(response); - ogs_sbi_server_send_response(session, response); + ogs_sbi_server_send_response(stream, response); return true; DEFAULT ogs_error("Invalid HTTP method [%s]", recvmsg->h.method); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_MEHTOD_NOT_ALLOWED, recvmsg, "Invalid HTTP method", recvmsg->h.method); END @@ -190,7 +190,7 @@ bool udr_nudr_dr_handle_subscription_authentication( if (!AuthEvent) { ogs_error("[%s] No AuthEvent", supi); ogs_sbi_server_send_error( - session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, recvmsg, "No AuthEvent", supi); return false; } @@ -199,7 +199,7 @@ bool udr_nudr_dr_handle_subscription_authentication( rv = ogs_dbi_increment_sqn(supi); if (rv != OGS_OK) { ogs_fatal("[%s] Cannot increment SQN", supi); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_INTERNAL_SERVER_ERROR, recvmsg, "Cannot increment SQN", supi); return false; @@ -208,13 +208,13 @@ bool udr_nudr_dr_handle_subscription_authentication( response = ogs_sbi_build_response( &sendmsg, OGS_SBI_HTTP_STATUS_NO_CONTENT); ogs_assert(response); - ogs_sbi_server_send_response(session, response); + ogs_sbi_server_send_response(stream, response); return true; DEFAULT ogs_error("Invalid HTTP method [%s]", recvmsg->h.method); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_MEHTOD_NOT_ALLOWED, recvmsg, "Invalid HTTP method", recvmsg->h.method); END @@ -223,7 +223,7 @@ bool udr_nudr_dr_handle_subscription_authentication( DEFAULT ogs_error("Invalid resource name [%s]", recvmsg->h.resource.component[3]); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_MEHTOD_NOT_ALLOWED, recvmsg, "Unknown resource name", recvmsg->h.resource.component[3]); @@ -233,20 +233,20 @@ bool udr_nudr_dr_handle_subscription_authentication( } bool udr_nudr_dr_handle_subscription_context( - ogs_sbi_session_t *session, ogs_sbi_message_t *recvmsg) + ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg) { ogs_sbi_message_t sendmsg; ogs_sbi_response_t *response = NULL; char *supi = NULL; - ogs_assert(session); + ogs_assert(stream); ogs_assert(recvmsg); supi = recvmsg->h.resource.component[1]; if (!supi) { ogs_error("No SUPI"); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, recvmsg, "No SUPI", NULL); return false; } @@ -254,7 +254,7 @@ bool udr_nudr_dr_handle_subscription_context( if (strncmp(supi, OGS_ID_SUPI_TYPE_IMSI, strlen(OGS_ID_SUPI_TYPE_IMSI)) != 0) { ogs_error("[%s] Unknown SUPI Type", supi); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_FORBIDDEN, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_FORBIDDEN, recvmsg, "Unknwon SUPI Type", supi); return false; } @@ -268,13 +268,13 @@ bool udr_nudr_dr_handle_subscription_context( response = ogs_sbi_build_response( &sendmsg, OGS_SBI_HTTP_STATUS_NO_CONTENT); ogs_assert(response); - ogs_sbi_server_send_response(session, response); + ogs_sbi_server_send_response(stream, response); return true; DEFAULT ogs_error("Invalid HTTP method [%s]", recvmsg->h.method); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_MEHTOD_NOT_ALLOWED, recvmsg, "Invalid HTTP method", recvmsg->h.method); END @@ -283,7 +283,7 @@ bool udr_nudr_dr_handle_subscription_context( DEFAULT ogs_error("Invalid resource name [%s]", recvmsg->h.resource.component[3]); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_MEHTOD_NOT_ALLOWED, recvmsg, "Unknown resource name", recvmsg->h.resource.component[3]); @@ -307,7 +307,7 @@ static OpenAPI_pdu_session_type_e pdu_session_type_from_dbi(uint8_t pdn_type) } bool udr_nudr_dr_handle_subscription_provisioned( - ogs_sbi_session_t *session, ogs_sbi_message_t *recvmsg) + ogs_sbi_stream_t *stream, ogs_sbi_message_t *recvmsg) { int rv, i; @@ -317,13 +317,13 @@ bool udr_nudr_dr_handle_subscription_provisioned( char *supi = NULL; - ogs_assert(session); + ogs_assert(stream); ogs_assert(recvmsg); supi = recvmsg->h.resource.component[1]; if (!supi) { ogs_error("No SUPI"); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, recvmsg, "No SUPI", NULL); return false; } @@ -331,7 +331,7 @@ bool udr_nudr_dr_handle_subscription_provisioned( if (strncmp(supi, OGS_ID_SUPI_TYPE_IMSI, strlen(OGS_ID_SUPI_TYPE_IMSI)) != 0) { ogs_error("[%s] Unknown SUPI Type", supi); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_FORBIDDEN, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_FORBIDDEN, recvmsg, "Unknwon SUPI Type", supi); return false; } @@ -339,14 +339,14 @@ bool udr_nudr_dr_handle_subscription_provisioned( rv = ogs_dbi_subscription_data(supi, &subscription_data); if (rv != OGS_OK) { ogs_error("[%s] Cannot find SUPI in DB", supi); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_NOT_FOUND, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_NOT_FOUND, recvmsg, "Cannot find SUPI Type", supi); return false; } if (!subscription_data.ambr.uplink && !subscription_data.ambr.downlink) { ogs_error("[%s] No UE-AMBR", supi); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_NOT_FOUND, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_NOT_FOUND, recvmsg, "No UE-AMBR", supi); return false; @@ -388,7 +388,7 @@ bool udr_nudr_dr_handle_subscription_provisioned( response = ogs_sbi_build_response(&sendmsg, OGS_SBI_HTTP_STATUS_OK); ogs_assert(response); - ogs_sbi_server_send_response(session, response); + ogs_sbi_server_send_response(stream, response); ogs_free(subscribed_ue_ambr.uplink); ogs_free(subscribed_ue_ambr.downlink); @@ -404,7 +404,7 @@ bool udr_nudr_dr_handle_subscription_provisioned( response = ogs_sbi_build_response(&sendmsg, OGS_SBI_HTTP_STATUS_OK); ogs_assert(response); - ogs_sbi_server_send_response(session, response); + ogs_sbi_server_send_response(stream, response); break; @@ -425,7 +425,7 @@ bool udr_nudr_dr_handle_subscription_provisioned( if (!recvmsg->param.s_nssai_presence) { ogs_error("[%s] Cannot find S_NSSAI", supi); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_NOT_FOUND, recvmsg, "Cannot find S_NSSAI", supi); return false; @@ -594,7 +594,7 @@ bool udr_nudr_dr_handle_subscription_provisioned( response = ogs_sbi_build_response(&sendmsg, OGS_SBI_HTTP_STATUS_OK); ogs_assert(response); - ogs_sbi_server_send_response(session, response); + ogs_sbi_server_send_response(stream, response); if (singleNSSAI.sd) ogs_free(singleNSSAI.sd); @@ -662,7 +662,7 @@ bool udr_nudr_dr_handle_subscription_provisioned( DEFAULT ogs_error("Invalid resource name [%s]", recvmsg->h.resource.component[3]); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_MEHTOD_NOT_ALLOWED, recvmsg, "Unknown resource name", recvmsg->h.resource.component[3]); diff --git a/src/udr/nudr-handler.h b/src/udr/nudr-handler.h index 29de8f608..fdb1e07e1 100644 --- a/src/udr/nudr-handler.h +++ b/src/udr/nudr-handler.h @@ -27,11 +27,11 @@ extern "C" { #endif bool udr_nudr_dr_handle_subscription_authentication( - ogs_sbi_session_t *session, ogs_sbi_message_t *message); + ogs_sbi_stream_t *stream, ogs_sbi_message_t *message); bool udr_nudr_dr_handle_subscription_context( - ogs_sbi_session_t *session, ogs_sbi_message_t *message); + ogs_sbi_stream_t *stream, ogs_sbi_message_t *message); bool udr_nudr_dr_handle_subscription_provisioned( - ogs_sbi_session_t *session, ogs_sbi_message_t *message); + ogs_sbi_stream_t *stream, ogs_sbi_message_t *message); #ifdef __cplusplus } diff --git a/src/udr/sbi-path.c b/src/udr/sbi-path.c index 2e8c55cc8..69358b1b6 100644 --- a/src/udr/sbi-path.c +++ b/src/udr/sbi-path.c @@ -19,21 +19,19 @@ #include "sbi-path.h" -static int server_cb(ogs_sbi_server_t *server, - ogs_sbi_session_t *session, ogs_sbi_request_t *request) +static int server_cb(ogs_sbi_request_t *request, void *data) { udr_event_t *e = NULL; int rv; - ogs_assert(session); ogs_assert(request); + ogs_assert(data); e = udr_event_new(UDR_EVT_SBI_SERVER); ogs_assert(e); - e->sbi.server = server; - e->sbi.session = session; e->sbi.request = request; + e->sbi.data = data; rv = ogs_queue_push(ogs_app()->queue, e); if (rv != OGS_OK) { diff --git a/src/udr/udr-sm.c b/src/udr/udr-sm.c index 6690ed652..fd4fd2342 100644 --- a/src/udr/udr-sm.c +++ b/src/udr/udr-sm.c @@ -41,7 +41,7 @@ void udr_state_operational(ogs_fsm_t *s, udr_event_t *e) { int rv; - ogs_sbi_session_t *session = NULL; + ogs_sbi_stream_t *stream = NULL; ogs_sbi_request_t *request = NULL; ogs_sbi_nf_instance_t *nf_instance = NULL; @@ -69,21 +69,21 @@ void udr_state_operational(ogs_fsm_t *s, udr_event_t *e) case UDR_EVT_SBI_SERVER: request = e->sbi.request; ogs_assert(request); - session = e->sbi.session; - ogs_assert(session); + stream = e->sbi.data; + ogs_assert(stream); rv = ogs_sbi_parse_request(&message, request); if (rv != OGS_OK) { /* 'message' buffer is released in ogs_sbi_parse_request() */ ogs_error("cannot parse HTTP message"); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, NULL, "cannot parse HTTP message", NULL); break; } if (strcmp(message.h.api.version, OGS_SBI_API_V1) != 0) { ogs_error("Not supported version [%s]", message.h.api.version); - ogs_sbi_server_send_error(session, OGS_SBI_HTTP_STATUS_BAD_REQUEST, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, &message, "Not supported version", NULL); ogs_sbi_message_free(&message); break; @@ -96,13 +96,13 @@ void udr_state_operational(ogs_fsm_t *s, udr_event_t *e) CASE(OGS_SBI_RESOURCE_NAME_NF_STATUS_NOTIFY) SWITCH(message.h.method) CASE(OGS_SBI_HTTP_METHOD_POST) - udr_nnrf_handle_nf_status_notify(session, &message); + udr_nnrf_handle_nf_status_notify(stream, &message); break; DEFAULT ogs_error("Invalid HTTP method [%s]", message.h.method); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_FORBIDDEN, &message, "Invalid HTTP method", message.h.method); END @@ -111,7 +111,7 @@ void udr_state_operational(ogs_fsm_t *s, udr_event_t *e) DEFAULT ogs_error("Invalid resource name [%s]", message.h.resource.component[0]); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, &message, "Unknown resource name", message.h.resource.component[0]); @@ -124,11 +124,11 @@ void udr_state_operational(ogs_fsm_t *s, udr_event_t *e) SWITCH(message.h.resource.component[2]) CASE(OGS_SBI_RESOURCE_NAME_AUTHENTICATION_DATA) udr_nudr_dr_handle_subscription_authentication( - session, &message); + stream, &message); break; CASE(OGS_SBI_RESOURCE_NAME_CONTEXT_DATA) - udr_nudr_dr_handle_subscription_context(session, &message); + udr_nudr_dr_handle_subscription_context(stream, &message); break; DEFAULT @@ -137,12 +137,12 @@ void udr_state_operational(ogs_fsm_t *s, udr_event_t *e) SWITCH(message.h.method) CASE(OGS_SBI_HTTP_METHOD_GET) udr_nudr_dr_handle_subscription_provisioned( - session, &message); + stream, &message); break; DEFAULT ogs_error("Invalid HTTP method [%s]", message.h.method); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_FORBIDDEN, &message, "Invalid HTTP method", message.h.method); @@ -151,7 +151,7 @@ void udr_state_operational(ogs_fsm_t *s, udr_event_t *e) DEFAULT ogs_error("Invalid resource name [%s]", message.h.resource.component[2]); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, &message, "Unknown resource name", message.h.resource.component[2]); @@ -161,7 +161,7 @@ void udr_state_operational(ogs_fsm_t *s, udr_event_t *e) DEFAULT ogs_error("Invalid resource name [%s]", message.h.resource.component[0]); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, &message, "Unknown resource name", message.h.resource.component[0]); @@ -170,7 +170,7 @@ void udr_state_operational(ogs_fsm_t *s, udr_event_t *e) DEFAULT ogs_error("Invalid API name [%s]", message.h.service.name); - ogs_sbi_server_send_error(session, + ogs_sbi_server_send_error(stream, OGS_SBI_HTTP_STATUS_BAD_REQUEST, &message, "Invalid API name", message.h.resource.component[0]); END diff --git a/tests/310014/abts-main.c b/tests/310014/abts-main.c index f4d4987c7..e31f8182b 100644 --- a/tests/310014/abts-main.c +++ b/tests/310014/abts-main.c @@ -43,7 +43,7 @@ static void initialize(const char *const argv[]) { int rv; - rv = ogs_app_initialize(NULL, argv); + rv = ogs_app_initialize(NULL, NULL, argv); ogs_assert(rv == OGS_OK); test_app_init(); diff --git a/tests/attach/abts-main.c b/tests/attach/abts-main.c index e71c307c4..ec09c2751 100644 --- a/tests/attach/abts-main.c +++ b/tests/attach/abts-main.c @@ -55,7 +55,7 @@ static void initialize(const char *const argv[]) { int rv; - rv = ogs_app_initialize(NULL, argv); + rv = ogs_app_initialize(NULL, NULL, argv); ogs_assert(rv == OGS_OK); test_epc_init(); diff --git a/tests/common/gtpu.c b/tests/common/gtpu.c index b3a019f32..099cc3ba9 100644 --- a/tests/common/gtpu.c +++ b/tests/common/gtpu.c @@ -51,6 +51,7 @@ ogs_socknode_t *test_gtpu_server(int index, int family) ogs_pkbuf_t *test_gtpu_read(ogs_socknode_t *node) { int rc = 0; + ogs_sockaddr_t from; ogs_pkbuf_t *recvbuf = ogs_pkbuf_alloc(NULL, OGS_MAX_SDU_LEN); ogs_assert(recvbuf); ogs_pkbuf_put(recvbuf, OGS_MAX_SDU_LEN); @@ -59,15 +60,13 @@ ogs_pkbuf_t *test_gtpu_read(ogs_socknode_t *node) ogs_assert(node->sock); while (1) { - rc = ogs_recv(node->sock->fd, recvbuf->data, recvbuf->len, 0); + rc = ogs_recvfrom( + node->sock->fd, recvbuf->data, recvbuf->len, 0, &from); if (rc <= 0) { - if (errno == EAGAIN) { - continue; - } - break; - } else { - break; + ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, + "ogs_recvfrom() failed"); } + break; } recvbuf->len = rc; diff --git a/tests/csfb/abts-main.c b/tests/csfb/abts-main.c index 450a127df..c9cd4e09b 100644 --- a/tests/csfb/abts-main.c +++ b/tests/csfb/abts-main.c @@ -59,7 +59,7 @@ static void initialize(const char *const argv[]) { int rv; - rv = ogs_app_initialize(NULL, argv); + rv = ogs_app_initialize(NULL, NULL, argv); ogs_assert(rv == OGS_OK); test_epc_init(); diff --git a/tests/handover/abts-main.c b/tests/handover/abts-main.c index 5595cffa7..276dec61d 100644 --- a/tests/handover/abts-main.c +++ b/tests/handover/abts-main.c @@ -45,7 +45,7 @@ static void initialize(const char *const argv[]) { int rv; - rv = ogs_app_initialize(NULL, argv); + rv = ogs_app_initialize(NULL, NULL, argv); ogs_assert(rv == OGS_OK); test_app_init(); diff --git a/tests/minimal/abts-main.c b/tests/minimal/abts-main.c index 110b278ee..f9115b036 100644 --- a/tests/minimal/abts-main.c +++ b/tests/minimal/abts-main.c @@ -43,7 +43,7 @@ static void initialize(const char *const argv[]) { int rv; - rv = ogs_app_initialize(NULL, argv); + rv = ogs_app_initialize(NULL, NULL, argv); ogs_assert(rv == OGS_OK); test_5gc_init(); diff --git a/tests/registration/abts-main.c b/tests/registration/abts-main.c index da37e3a3c..7be793dfa 100644 --- a/tests/registration/abts-main.c +++ b/tests/registration/abts-main.c @@ -55,7 +55,7 @@ static void initialize(const char *const argv[]) { int rv; - rv = ogs_app_initialize(NULL, argv); + rv = ogs_app_initialize(NULL, NULL, argv); ogs_assert(rv == OGS_OK); test_5gc_init(); diff --git a/tests/volte/abts-main.c b/tests/volte/abts-main.c index 9cfd2af23..a9f151ce6 100644 --- a/tests/volte/abts-main.c +++ b/tests/volte/abts-main.c @@ -53,7 +53,7 @@ static void initialize(const char *const argv[]) { int rv; - rv = ogs_app_initialize(NULL, argv); + rv = ogs_app_initialize(NULL, NULL, argv); ogs_assert(rv == OGS_OK); test_epc_init();