forked from acouzens/open5gs
update it
This commit is contained in:
parent
e4e8f30248
commit
8c2c204278
|
@ -39,12 +39,17 @@ typedef int (*net_handler)(void *net_sl, void *data);
|
|||
typedef struct {
|
||||
int type;
|
||||
int proto;
|
||||
#define SCTP_S1AP_PPID 18
|
||||
#define SCTP_X2AP_PPID 27
|
||||
c_uint32_t ppid;
|
||||
|
||||
int sock_id;
|
||||
#if 0 /* deprecated */
|
||||
struct sockaddr_in local;
|
||||
#endif
|
||||
struct sockaddr_in remote;
|
||||
int opt;
|
||||
|
||||
int sndrcv_errno;
|
||||
} net_sock_t;
|
||||
|
||||
|
@ -72,7 +77,7 @@ CORE_DECLARE(status_t) net_final(void);
|
|||
CORE_DECLARE(int) net_open(net_sock_t **net_sock,const char *host,
|
||||
const int lport,
|
||||
const int rport,
|
||||
int type, int proto, const int flag);
|
||||
int type, int proto);
|
||||
|
||||
/**
|
||||
* Create network session.
|
||||
|
@ -85,12 +90,12 @@ CORE_DECLARE(int) net_open(net_sock_t **net_sock,const char *host,
|
|||
* @param type Protocol type
|
||||
* @param flag Option flags to be set for this connection
|
||||
*/
|
||||
CORE_DECLARE(int) net_open_with_addr(net_sock_t **net_sock,
|
||||
CORE_DECLARE(int) net_open_ext(net_sock_t **net_sock,
|
||||
const c_uint32_t local_addr,
|
||||
const char *remote_host,
|
||||
const int lport,
|
||||
const int rport,
|
||||
int type, int proto, const int flag);
|
||||
int type, int proto, c_uint32_t ppid, const int flag);
|
||||
/**
|
||||
* Read the data from the socket
|
||||
* @param net_sock Socket which created before
|
||||
|
@ -132,12 +137,13 @@ CORE_DECLARE(int) net_accept(net_sock_t **new_accept_sock,
|
|||
* @param net_sock Returned socket
|
||||
* @param type Protocol type
|
||||
* @param proto Protocol proto
|
||||
* @param port Port number
|
||||
* @param ppid SCTP PPID
|
||||
* @param addr Specific address
|
||||
* @param port Port number
|
||||
*/
|
||||
CORE_DECLARE(int) net_listen_with_addr(
|
||||
net_sock_t **net_sock, const int type, const int proto,
|
||||
const int port, const c_uint32_t addr);
|
||||
CORE_DECLARE(int) net_listen_ext(net_sock_t **net_sock,
|
||||
const int type, const int proto, const c_uint32_t ppid,
|
||||
const c_uint32_t addr, const int port);
|
||||
/** Create socket and listen to the specified port
|
||||
* @param net_sock Returned socket
|
||||
* @param type Protocol type
|
||||
|
|
|
@ -191,7 +191,7 @@ static net_sock_t *net_sock_create(int type, int protocol)
|
|||
rtoinfo.srto_min);
|
||||
|
||||
/* FIXME : Need to configure this param */
|
||||
/* rtoinfo.srto_initial = 3000; */
|
||||
rtoinfo.srto_initial = 3000;
|
||||
rtoinfo.srto_min = 1000;
|
||||
rtoinfo.srto_max = 5000;
|
||||
|
||||
|
@ -269,12 +269,12 @@ int net_resolve_host(const char *host, struct in_addr *addr)
|
|||
return rc;
|
||||
}
|
||||
|
||||
static int _net_open_addr(net_sock_t **net_sock,
|
||||
int net_open_ext(net_sock_t **net_sock,
|
||||
const c_uint32_t local_addr,
|
||||
const char *remote_host,
|
||||
const int lport,
|
||||
const int rport,
|
||||
int type, int proto, const int flag)
|
||||
int type, int proto, c_uint32_t ppid, const int flag)
|
||||
{
|
||||
struct sockaddr_in sock_addr;
|
||||
int rc;
|
||||
|
@ -290,7 +290,7 @@ static int _net_open_addr(net_sock_t **net_sock,
|
|||
}
|
||||
|
||||
/* FIXME : Set socket option */
|
||||
|
||||
memset(&sock_addr, 0, sizeof(sock_addr));
|
||||
sock_addr.sin_family = AF_INET;
|
||||
sock_addr.sin_port = htons(rport);
|
||||
|
||||
|
@ -302,6 +302,7 @@ static int _net_open_addr(net_sock_t **net_sock,
|
|||
|
||||
result_sock->type = type;
|
||||
result_sock->proto = proto;
|
||||
result_sock->ppid = ppid;
|
||||
|
||||
/* Connect to host */
|
||||
if (proto == IPPROTO_UDP ||
|
||||
|
@ -371,28 +372,14 @@ cleanup:
|
|||
int net_open(net_sock_t **net_sock, const char *host,
|
||||
const int lport,
|
||||
const int rport,
|
||||
int type, int proto, const int flag)
|
||||
int type, int proto)
|
||||
{
|
||||
return _net_open_addr(net_sock,
|
||||
return net_open_ext(net_sock,
|
||||
0,
|
||||
host,
|
||||
lport,
|
||||
rport,
|
||||
type, proto, flag);
|
||||
}
|
||||
|
||||
int net_open_with_addr(net_sock_t **net_sock, const c_uint32_t local_addr,
|
||||
const char *remote_host,
|
||||
const int lport,
|
||||
const int rport,
|
||||
int type, int proto, const int flag)
|
||||
{
|
||||
return _net_open_addr(net_sock,
|
||||
local_addr,
|
||||
remote_host,
|
||||
lport,
|
||||
rport,
|
||||
type, proto, flag);
|
||||
type, proto, 0, 0);
|
||||
}
|
||||
|
||||
/** Read data from socket */
|
||||
|
@ -547,8 +534,7 @@ int net_write(net_sock_t *net_sock, char *buffer, size_t size,
|
|||
|
||||
return rc;
|
||||
}
|
||||
else if (net_sock->proto == IPPROTO_UDP ||
|
||||
net_sock->proto == IPPROTO_SCTP)
|
||||
else if (net_sock->proto == IPPROTO_UDP)
|
||||
{
|
||||
rc = sendto(net_sock->sock_id, buffer, size, 0,
|
||||
(struct sockaddr *)dest_addr, addrsize);
|
||||
|
@ -556,6 +542,19 @@ int net_write(net_sock_t *net_sock, char *buffer, size_t size,
|
|||
|
||||
return rc;
|
||||
}
|
||||
else if (net_sock->proto == IPPROTO_SCTP)
|
||||
{
|
||||
rc = sctp_sendmsg(net_sock->sock_id, buffer, size,
|
||||
(struct sockaddr *)dest_addr, addrsize,
|
||||
htonl(net_sock->ppid),
|
||||
0, /* flags, FIXME : SCTP_ADDR_OVER is needed? */
|
||||
0, /* stream_no */
|
||||
0, /* timetolive */
|
||||
0); /* context */
|
||||
if (rc < 0) net_sock->sndrcv_errno = errno;
|
||||
|
||||
return rc;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
|
@ -577,6 +576,7 @@ int net_sendto(net_sock_t *net_sock, char *buffer, size_t size,
|
|||
struct sockaddr_in sock_addr;
|
||||
d_assert(net_sock && buffer, return -1, "Invalid params\n");
|
||||
|
||||
memset(&sock_addr, 0, sizeof(sock_addr));
|
||||
sock_addr.sin_family = AF_INET;
|
||||
sock_addr.sin_port = htons(port);
|
||||
sock_addr.sin_addr.s_addr = ip_addr;
|
||||
|
@ -637,7 +637,6 @@ int net_accept(net_sock_t **new_accept_sock, net_sock_t *net_sock, int timeout)
|
|||
{
|
||||
net_sock_t *node = NULL;
|
||||
pool_alloc_node(&net_pool, &node);
|
||||
d_assert(node, return -1, "Pool Allocation Failed");
|
||||
new_sock = accept(sock, NULL, NULL);
|
||||
|
||||
node->sock_id = new_sock;
|
||||
|
@ -672,9 +671,9 @@ cleanup:
|
|||
}
|
||||
|
||||
/** Listen connection */
|
||||
int net_listen_with_addr(
|
||||
net_sock_t **net_sock, const int type, const int proto,
|
||||
const int port, const c_uint32_t addr)
|
||||
int net_listen_ext(net_sock_t **net_sock,
|
||||
const int type, const int proto, c_uint32_t ppid,
|
||||
const c_uint32_t addr, const int port)
|
||||
{
|
||||
struct sockaddr_in sock_addr;
|
||||
net_sock_t *result_sock = NULL;
|
||||
|
@ -686,6 +685,7 @@ int net_listen_with_addr(
|
|||
return -1;
|
||||
}
|
||||
|
||||
memset(&sock_addr, 0, sizeof(sock_addr));
|
||||
sock_addr.sin_family = AF_INET;
|
||||
sock_addr.sin_port = htons(port);
|
||||
sock_addr.sin_addr.s_addr = addr;
|
||||
|
@ -706,6 +706,7 @@ int net_listen_with_addr(
|
|||
|
||||
result_sock->type = type;
|
||||
result_sock->proto = proto;
|
||||
result_sock->ppid = ppid;
|
||||
|
||||
*net_sock = result_sock;
|
||||
|
||||
|
@ -720,7 +721,7 @@ int net_listen(
|
|||
net_sock_t **net_sock, const int type, const int proto,
|
||||
const int port)
|
||||
{
|
||||
return net_listen_with_addr(net_sock, type, proto, port, INADDR_ANY);
|
||||
return net_listen_ext(net_sock, type, proto, 0, INADDR_ANY, port);
|
||||
}
|
||||
|
||||
|
||||
|
@ -855,7 +856,7 @@ int net_ftp_open(const char *host,
|
|||
|
||||
/* Open control channel */
|
||||
rc = net_open(&session->ctrl_sock, host, 0, port,
|
||||
SOCK_DGRAM, IPPROTO_TCP, 0);
|
||||
SOCK_DGRAM, IPPROTO_TCP);
|
||||
if (rc != 0)
|
||||
{
|
||||
d_error("net_open error(errno = %d) : host = %s, port = %d\n",
|
||||
|
@ -941,7 +942,7 @@ static int net_ftp_opendata(net_ftp_t *ftp_session)
|
|||
INET_NTOP(&ftp_session->ctrl_sock->remote.sin_addr, ip_addr),
|
||||
0,
|
||||
port,
|
||||
SOCK_STREAM, IPPROTO_TCP, 0);
|
||||
SOCK_STREAM, IPPROTO_TCP);
|
||||
if (rc != 0)
|
||||
{
|
||||
d_error("net_open error in net_ftp_opendata(host = %s,port = %d)\n",
|
||||
|
@ -1565,7 +1566,7 @@ int net_fds_read_run(long timeout)
|
|||
/* Timeout */
|
||||
if (rc == 0)
|
||||
{
|
||||
return 0;
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* Dispatch handler */
|
||||
|
|
|
@ -360,7 +360,7 @@ static void netlib1(abts_case *tc, void *data)
|
|||
start_tcp_server();
|
||||
|
||||
rc = net_open(&net_sock, "127.0.0.1", 0,
|
||||
TEST_SERVER_PORT, SOCK_STREAM, IPPROTO_TCP, 0);
|
||||
TEST_SERVER_PORT, SOCK_STREAM, IPPROTO_TCP);
|
||||
ABTS_INT_EQUAL(tc, 0, rc);
|
||||
for (i=0; i< TEST_MAX_NUM; i++)
|
||||
{
|
||||
|
@ -414,7 +414,7 @@ static void netlib2(abts_case *tc, void *data)
|
|||
{
|
||||
net_sock[i] = NULL;
|
||||
rc = net_open(&net_sock[i], "127.0.0.1", 0,TEST_SERVER_PORT + 1,
|
||||
SOCK_STREAM, IPPROTO_TCP, 0);
|
||||
SOCK_STREAM, IPPROTO_TCP);
|
||||
ABTS_INT_EQUAL(tc, -1, rc);
|
||||
ABTS_PTR_NULL(tc, net_sock[i]);
|
||||
}
|
||||
|
@ -425,7 +425,7 @@ static void netlib2(abts_case *tc, void *data)
|
|||
{
|
||||
net_sock[i] = NULL;
|
||||
rc = net_open(&net_sock[i], "127.0.0.1", 0,TEST_SERVER_PORT,
|
||||
SOCK_STREAM, IPPROTO_TCP, 0);
|
||||
SOCK_STREAM, IPPROTO_TCP);
|
||||
ABTS_INT_EQUAL(tc, 0, rc);
|
||||
ABTS_PTR_NOTNULL(tc, net_sock[i]);
|
||||
}
|
||||
|
@ -475,7 +475,7 @@ static void netlib3(abts_case *tc, void *data)
|
|||
{
|
||||
net_sock[i] = NULL;
|
||||
rc = net_open(&net_sock[i], "127.0.0.1", 0,TEST_SERVER_PORT + 1,
|
||||
SOCK_DGRAM, IPPROTO_UDP, 0);
|
||||
SOCK_DGRAM, IPPROTO_UDP);
|
||||
ABTS_INT_EQUAL(tc, 0, rc);
|
||||
ABTS_PTR_NOTNULL(tc, net_sock[i]);
|
||||
}
|
||||
|
@ -493,7 +493,7 @@ static void netlib3(abts_case *tc, void *data)
|
|||
{
|
||||
net_sock[i] = NULL;
|
||||
rc = net_open(&net_sock[i], "127.0.0.1", 0,TEST_SERVER_PORT,
|
||||
SOCK_DGRAM, IPPROTO_UDP, 0);
|
||||
SOCK_DGRAM, IPPROTO_UDP);
|
||||
ABTS_INT_EQUAL(tc, 0, rc);
|
||||
ABTS_PTR_NOTNULL(tc, net_sock[i]);
|
||||
}
|
||||
|
@ -502,7 +502,8 @@ static void netlib3(abts_case *tc, void *data)
|
|||
{
|
||||
sprintf(inputbuf[i],"asdf%d",i);
|
||||
memset(outputbuf[i], 0, sizeof(outputbuf[i]));
|
||||
rc = net_send(net_sock[i], inputbuf[i], strlen(inputbuf[i])+1);
|
||||
rc = net_sendto(net_sock[i], inputbuf[i], strlen(inputbuf[i])+1,
|
||||
inet_addr("127.0.0.1"), TEST_SERVER_PORT);
|
||||
ABTS_INT_EQUAL(tc, strlen(inputbuf[i])+1, rc);
|
||||
rc = 0;
|
||||
while (1)
|
||||
|
@ -544,7 +545,7 @@ static void netlib4(abts_case *tc, void *data)
|
|||
{
|
||||
net_sock[i] = NULL;
|
||||
rc = net_open(&net_sock[i], "127.0.0.1", 0,TEST_SERVER_PORT + 1,
|
||||
SOCK_STREAM, IPPROTO_SCTP, 0);
|
||||
SOCK_STREAM, IPPROTO_SCTP);
|
||||
ABTS_INT_EQUAL(tc, -1, rc);
|
||||
ABTS_PTR_NULL(tc, net_sock[i]);
|
||||
}
|
||||
|
@ -554,7 +555,7 @@ static void netlib4(abts_case *tc, void *data)
|
|||
{
|
||||
net_sock[i] = NULL;
|
||||
rc = net_open(&net_sock[i], "127.0.0.1", 0, TEST_SERVER_PORT,
|
||||
SOCK_STREAM, IPPROTO_SCTP, 0);
|
||||
SOCK_STREAM, IPPROTO_SCTP);
|
||||
ABTS_INT_EQUAL(tc, 0, rc);
|
||||
ABTS_PTR_NOTNULL(tc, net_sock[i]);
|
||||
}
|
||||
|
@ -605,7 +606,7 @@ static void netlib5(abts_case *tc, void *data)
|
|||
{
|
||||
net_sock[i] = NULL;
|
||||
rc = net_open(&net_sock[i], "127.0.0.1", 0, TEST_SERVER_PORT + 1,
|
||||
SOCK_SEQPACKET, IPPROTO_SCTP, 0);
|
||||
SOCK_SEQPACKET, IPPROTO_SCTP);
|
||||
ABTS_INT_EQUAL(tc, 0, rc);
|
||||
ABTS_PTR_NOTNULL(tc, net_sock[i]);
|
||||
}
|
||||
|
@ -623,7 +624,7 @@ static void netlib5(abts_case *tc, void *data)
|
|||
{
|
||||
net_sock[i] = NULL;
|
||||
rc = net_open(&net_sock[i], "127.0.0.1", 0, TEST_SERVER_PORT,
|
||||
SOCK_SEQPACKET, IPPROTO_SCTP, 0);
|
||||
SOCK_SEQPACKET, IPPROTO_SCTP);
|
||||
ABTS_INT_EQUAL(tc, 0, rc);
|
||||
ABTS_PTR_NOTNULL(tc, net_sock[i]);
|
||||
}
|
||||
|
@ -632,7 +633,8 @@ static void netlib5(abts_case *tc, void *data)
|
|||
{
|
||||
sprintf(inputbuf[i],"asdf%d",i);
|
||||
memset(outputbuf[i], 0, sizeof(outputbuf[i]));
|
||||
rc = net_send(net_sock[i], inputbuf[i], strlen(inputbuf[i])+1);
|
||||
rc = net_sendto(net_sock[i], inputbuf[i], strlen(inputbuf[i])+1,
|
||||
inet_addr("127.0.0.1"), TEST_SERVER_PORT);
|
||||
ABTS_INT_EQUAL(tc, strlen(inputbuf[i])+1, rc);
|
||||
rc = 0;
|
||||
while (1)
|
||||
|
|
|
@ -12,7 +12,7 @@ status_t gtp_listen(net_sock_t **sock,
|
|||
char buf[INET_ADDRSTRLEN];
|
||||
int rc;
|
||||
|
||||
rc = net_listen_with_addr(sock, SOCK_DGRAM, IPPROTO_UDP, port, addr);
|
||||
rc = net_listen_ext(sock, SOCK_DGRAM, IPPROTO_UDP, 0, addr, port);
|
||||
if (rc != 0)
|
||||
{
|
||||
d_error("Can't establish GTP[%s:%d] path(%d:%s)",
|
||||
|
|
|
@ -13,9 +13,9 @@ status_t s1ap_listen(void)
|
|||
char buf[INET_ADDRSTRLEN];
|
||||
int rc;
|
||||
|
||||
rc = net_listen_with_addr(&mme_self()->s1ap_sock,
|
||||
SOCK_STREAM, IPPROTO_SCTP, mme_self()->s1ap_port,
|
||||
mme_self()->s1ap_addr);
|
||||
rc = net_listen_ext(&mme_self()->s1ap_sock,
|
||||
SOCK_STREAM, IPPROTO_SCTP, SCTP_S1AP_PPID,
|
||||
mme_self()->s1ap_addr, mme_self()->s1ap_port);
|
||||
if (rc != 0)
|
||||
{
|
||||
d_error("Can't establish S1-ENB(port:%d) path(%d:%s)",
|
||||
|
|
|
@ -17,8 +17,8 @@ net_sock_t *tests1ap_enb_connect(void)
|
|||
|
||||
if (!mme) return NULL;
|
||||
|
||||
rv = net_open_with_addr(&sock, mme->s1ap_addr, "127.0.0.1", 0,
|
||||
mme->s1ap_port, SOCK_SEQPACKET, IPPROTO_SCTP, 0);
|
||||
rv = net_open_ext(&sock, mme->s1ap_addr, "127.0.0.1", 0, mme->s1ap_port,
|
||||
SOCK_SEQPACKET, IPPROTO_SCTP, SCTP_S1AP_PPID, 0);
|
||||
if (rv != CORE_OK) return NULL;
|
||||
|
||||
return sock;
|
||||
|
|
Loading…
Reference in New Issue