forked from acouzens/open5gs
continue to refine
This commit is contained in:
parent
f384bdef3d
commit
d4023da087
|
@ -1,28 +1,26 @@
|
|||
#include "ogs-sctp.h"
|
||||
|
||||
#include "app/context.h"
|
||||
#include "mme_event.h"
|
||||
|
||||
#include "s1ap_path.h"
|
||||
|
||||
static void accept_handler(short when, ogs_socket_t fd, void *data);
|
||||
|
||||
void s1ap_server(ogs_socknode_t *node, int type)
|
||||
ogs_sock_t *s1ap_server(ogs_socknode_t *node)
|
||||
{
|
||||
char buf[OGS_ADDRSTRLEN];
|
||||
ogs_sock_t *sock = NULL;
|
||||
|
||||
ogs_assert(node);
|
||||
|
||||
ogs_socknode_set_option(node, &context_self()->config.sockopt);
|
||||
ogs_socknode_set_poll(node, mme_self()->pollset,
|
||||
OGS_POLLIN, accept_handler, node);
|
||||
|
||||
sock = ogs_sctp_server(type, node);
|
||||
sock = ogs_sctp_server(SOCK_STREAM, node);
|
||||
ogs_assert(sock);
|
||||
|
||||
ogs_info("s1ap_server() [%s]:%d",
|
||||
OGS_ADDR(node->addr, buf), OGS_PORT(node->addr));
|
||||
|
||||
return sock;
|
||||
}
|
||||
|
||||
static void accept_handler(short when, ogs_socket_t fd, void *data)
|
||||
|
@ -38,8 +36,7 @@ static void accept_handler(short when, ogs_socket_t fd, void *data)
|
|||
ogs_assert(fd != INVALID_SOCKET);
|
||||
|
||||
new = ogs_sock_accept(sock);
|
||||
if (new)
|
||||
{
|
||||
if (new) {
|
||||
int rv;
|
||||
ogs_sockaddr_t *addr = NULL;
|
||||
mme_event_t *e = NULL;
|
||||
|
@ -61,9 +58,7 @@ static void accept_handler(short when, ogs_socket_t fd, void *data)
|
|||
ogs_free(e->enb_addr);
|
||||
mme_event_free(e);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, "accept() failed");
|
||||
}
|
||||
}
|
||||
|
@ -84,8 +79,7 @@ void s1ap_recv_handler(short when, ogs_socket_t fd, void *data)
|
|||
|
||||
pkbuf = ogs_pkbuf_alloc(NULL, MAX_SDU_LEN);
|
||||
#if DEPRECATED
|
||||
if (pkbuf == NULL)
|
||||
{
|
||||
if (pkbuf == NULL) {
|
||||
char tmp_buf[MAX_SDU_LEN];
|
||||
|
||||
d_fatal("Can't allocate pkbuf");
|
||||
|
@ -99,20 +93,17 @@ void s1ap_recv_handler(short when, ogs_socket_t fd, void *data)
|
|||
ogs_pkbuf_put(pkbuf, MAX_SDU_LEN);
|
||||
size = ogs_sctp_recvmsg(
|
||||
sock, pkbuf->data, pkbuf->len, NULL, &sinfo, &flags);
|
||||
if (size < 0)
|
||||
{
|
||||
if (size < 0) {
|
||||
ogs_error("ogs_sctp_recvmsg(%d) failed(%d:%s)",
|
||||
size, errno, strerror(errno));
|
||||
return;
|
||||
}
|
||||
|
||||
if (flags & MSG_NOTIFICATION)
|
||||
{
|
||||
if (flags & MSG_NOTIFICATION) {
|
||||
union sctp_notification *not =
|
||||
(union sctp_notification *)pkbuf->data;
|
||||
|
||||
switch(not->sn_header.sn_type)
|
||||
{
|
||||
switch(not->sn_header.sn_type) {
|
||||
case SCTP_ASSOC_CHANGE :
|
||||
{
|
||||
ogs_debug("SCTP_ASSOC_CHANGE:"
|
||||
|
@ -123,8 +114,7 @@ void s1ap_recv_handler(short when, ogs_socket_t fd, void *data)
|
|||
not->sn_assoc_change.sac_inbound_streams,
|
||||
not->sn_assoc_change.sac_outbound_streams);
|
||||
|
||||
if (not->sn_assoc_change.sac_state == SCTP_COMM_UP)
|
||||
{
|
||||
if (not->sn_assoc_change.sac_state == SCTP_COMM_UP) {
|
||||
ogs_debug("SCTP_COMM_UP");
|
||||
|
||||
addr = ogs_calloc(1, sizeof(ogs_sockaddr_t));
|
||||
|
@ -145,10 +135,8 @@ void s1ap_recv_handler(short when, ogs_socket_t fd, void *data)
|
|||
ogs_free(e->enb_addr);
|
||||
mme_event_free(e);
|
||||
}
|
||||
}
|
||||
else if (not->sn_assoc_change.sac_state == SCTP_SHUTDOWN_COMP ||
|
||||
not->sn_assoc_change.sac_state == SCTP_COMM_LOST)
|
||||
{
|
||||
} else if (not->sn_assoc_change.sac_state == SCTP_SHUTDOWN_COMP ||
|
||||
not->sn_assoc_change.sac_state == SCTP_COMM_LOST) {
|
||||
|
||||
if (not->sn_assoc_change.sac_state == SCTP_SHUTDOWN_COMP)
|
||||
ogs_debug("SCTP_SHUTDOWN_COMP");
|
||||
|
@ -196,39 +184,29 @@ void s1ap_recv_handler(short when, ogs_socket_t fd, void *data)
|
|||
break;
|
||||
}
|
||||
case SCTP_PEER_ADDR_CHANGE:
|
||||
{
|
||||
ogs_warn("SCTP_PEER_ADDR_CHANGE:[T:%d, F:0x%x, S:%d]",
|
||||
not->sn_paddr_change.spc_type,
|
||||
not->sn_paddr_change.spc_flags,
|
||||
not->sn_paddr_change.spc_error);
|
||||
break;
|
||||
}
|
||||
case SCTP_REMOTE_ERROR:
|
||||
{
|
||||
ogs_warn("SCTP_REMOTE_ERROR:[T:%d, F:0x%x, S:%d]",
|
||||
not->sn_remote_error.sre_type,
|
||||
not->sn_remote_error.sre_flags,
|
||||
not->sn_remote_error.sre_error);
|
||||
break;
|
||||
}
|
||||
case SCTP_SEND_FAILED :
|
||||
{
|
||||
ogs_error("SCTP_SEND_FAILED:[T:%d, F:0x%x, S:%d]",
|
||||
not->sn_send_failed.ssf_type,
|
||||
not->sn_send_failed.ssf_flags,
|
||||
not->sn_send_failed.ssf_error);
|
||||
break;
|
||||
}
|
||||
default :
|
||||
{
|
||||
ogs_error("Discarding event with unknown flags:0x%x type:0x%x",
|
||||
flags, not->sn_header.sn_type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (flags & MSG_EOR)
|
||||
{
|
||||
} else if (flags & MSG_EOR) {
|
||||
ogs_pkbuf_trim(pkbuf, size);
|
||||
|
||||
addr = ogs_calloc(1, sizeof(ogs_sockaddr_t));
|
||||
|
@ -249,9 +227,7 @@ void s1ap_recv_handler(short when, ogs_socket_t fd, void *data)
|
|||
}
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
ogs_assert_if_reached();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
#include "ogs-sctp.h"
|
||||
|
||||
#include "app/context.h"
|
||||
#include "mme_event.h"
|
||||
|
||||
#include "s1ap_path.h"
|
||||
|
||||
int s1ap_usrsctp_recv_handler(struct socket *sock,
|
||||
|
@ -11,22 +8,24 @@ int s1ap_usrsctp_recv_handler(struct socket *sock,
|
|||
|
||||
static ogs_sockaddr_t *usrsctp_remote_addr(union sctp_sockstore *store);
|
||||
|
||||
void s1ap_server(ogs_socknode_t *node, int type)
|
||||
ogs_sock_t *s1ap_server(ogs_socknode_t *node)
|
||||
{
|
||||
char buf[OGS_ADDRSTRLEN];
|
||||
ogs_sock_t *sock = NULL;
|
||||
|
||||
ogs_assert(node);
|
||||
|
||||
ogs_socknode_set_option(node, &context_self()->config.sockopt);
|
||||
ogs_socknode_set_poll(node, mme_self()->pollset,
|
||||
OGS_POLLIN, s1ap_usrsctp_recv_handler, node);
|
||||
|
||||
sock = ogs_sctp_server(type, node);
|
||||
/* FIXME : libsctp 0.9.3.0 is not properly working in SOCK_STREAM */
|
||||
sock = ogs_sctp_server(SOCK_SEQPACKET, node);
|
||||
ogs_assert(sock);
|
||||
|
||||
ogs_info("s1ap_server() [%s]:%d",
|
||||
OGS_ADDR(node->addr, buf), OGS_PORT(node->addr));
|
||||
|
||||
return sock;
|
||||
}
|
||||
|
||||
int s1ap_usrsctp_recv_handler(struct socket *sock,
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "ogs-sctp.h"
|
||||
|
||||
#include "app/context.h"
|
||||
#include "mme_event.h"
|
||||
|
||||
#include "nas_security.h"
|
||||
|
@ -9,21 +10,19 @@
|
|||
#include "s1ap_build.h"
|
||||
#include "s1ap_path.h"
|
||||
|
||||
static int s1ap_server_list(ogs_list_t *list, int type);
|
||||
|
||||
int s1ap_open(void)
|
||||
{
|
||||
int rv;
|
||||
#if HAVE_USRSCTP != 1
|
||||
int type = SOCK_STREAM;
|
||||
#else
|
||||
int type = SOCK_SEQPACKET;
|
||||
#endif
|
||||
ogs_socknode_t *node = NULL;
|
||||
|
||||
rv = s1ap_server_list(&mme_self()->s1ap_list, type);
|
||||
ogs_assert(rv == OGS_OK);
|
||||
rv = s1ap_server_list(&mme_self()->s1ap_list6, type);
|
||||
ogs_assert(rv == OGS_OK);
|
||||
ogs_list_for_each(&mme_self()->s1ap_list, node) {
|
||||
ogs_socknode_set_option(node, &context_self()->config.sockopt);
|
||||
s1ap_server(node);
|
||||
}
|
||||
|
||||
ogs_list_for_each(&mme_self()->s1ap_list6, node) {
|
||||
ogs_socknode_set_option(node, &context_self()->config.sockopt);
|
||||
s1ap_server(node);
|
||||
}
|
||||
|
||||
return OGS_OK;
|
||||
}
|
||||
|
@ -34,18 +33,6 @@ void s1ap_close()
|
|||
ogs_socknode_remove_all(&mme_self()->s1ap_list6);
|
||||
}
|
||||
|
||||
static int s1ap_server_list(ogs_list_t *list, int type)
|
||||
{
|
||||
ogs_socknode_t *snode = NULL;
|
||||
|
||||
ogs_assert(list);
|
||||
|
||||
ogs_list_for_each(list, snode)
|
||||
s1ap_server(snode, type);
|
||||
|
||||
return OGS_OK;
|
||||
}
|
||||
|
||||
int s1ap_send(ogs_sock_t *sock, ogs_pkbuf_t *pkbuf,
|
||||
ogs_sockaddr_t *addr, uint16_t stream_no)
|
||||
{
|
||||
|
|
|
@ -13,9 +13,7 @@ extern "C" {
|
|||
int s1ap_open();
|
||||
void s1ap_close();
|
||||
|
||||
void s1ap_server(ogs_socknode_t *node, int type);
|
||||
void s1ap_closesocket(ogs_sock_t *sock);
|
||||
void s1ap_delete(ogs_socknode_t *node);
|
||||
ogs_sock_t *s1ap_server(ogs_socknode_t *node);
|
||||
void s1ap_recv_handler(short when, ogs_socket_t fd, void *data);
|
||||
|
||||
int s1ap_send(ogs_sock_t *sock,
|
||||
|
|
Loading…
Reference in New Issue