forked from acouzens/open5gs
remove redundant code
This commit is contained in:
parent
9a0afe035a
commit
f5c203d3ac
|
@ -1,274 +0,0 @@
|
||||||
#ifndef __CORE_NET_H__
|
|
||||||
#define __CORE_NET_H__
|
|
||||||
|
|
||||||
#include "core.h"
|
|
||||||
#include "core_errno.h"
|
|
||||||
#include "core_index.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif /* __cplusplus */
|
|
||||||
|
|
||||||
#if HAVE_ARPA_INET_H
|
|
||||||
#include <arpa/inet.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if HAVE_NETDB_H
|
|
||||||
#include <netdb.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if HAVE_SYS_SOCKET_H
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define MAX_NET_POOL_SIZE 512
|
|
||||||
|
|
||||||
/* Max length of interface name, ex: eth0, ath0 .. */
|
|
||||||
#define MAX_IFNAME_LEN 16
|
|
||||||
|
|
||||||
#define INET_NTOP(src, dst) inet_ntop(AF_INET,(void *)(c_uintptr_t)(src),(dst),INET_ADDRSTRLEN)
|
|
||||||
#define INET6_NTOP(src, dst) inet_ntop(AF_INET6,(void *)(src),(dst),INET6_ADDRSTRLEN)
|
|
||||||
|
|
||||||
/** Network handler */
|
|
||||||
typedef int (*net_handler)(void *net_sl, void *data);
|
|
||||||
|
|
||||||
/** Network socket descriptor */
|
|
||||||
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;
|
|
||||||
|
|
||||||
/** Network socket handler */
|
|
||||||
typedef int (*net_sock_handler)(net_sock_t *net_sock, void *data);
|
|
||||||
|
|
||||||
/** Basic socket library */
|
|
||||||
|
|
||||||
/** Initialize network library */
|
|
||||||
CORE_DECLARE(status_t) net_init(void);
|
|
||||||
|
|
||||||
/** Finalize network library */
|
|
||||||
CORE_DECLARE(status_t) net_final(void);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create network session.
|
|
||||||
* @param net_sock Connected network session.
|
|
||||||
* @param host Host IP address to be connected.
|
|
||||||
* @param lport Local Port number(only for UDP)
|
|
||||||
* @param rport Remote Port number
|
|
||||||
* @param proto Protocol proto
|
|
||||||
* @param type Protocol type
|
|
||||||
* @param flag Option flags to be set for this connection
|
|
||||||
*/
|
|
||||||
CORE_DECLARE(int) net_open(net_sock_t **net_sock,const char *host,
|
|
||||||
const int lport,
|
|
||||||
const int rport,
|
|
||||||
int type, int proto);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create network session.
|
|
||||||
* @param net_sock Connected network session.
|
|
||||||
* @param local_addr Local Host IP address to bind(Network order)
|
|
||||||
* @param remote_host Remote Host IP address to be connected.
|
|
||||||
* @param lport Local Port number(only for UDP)
|
|
||||||
* @param rport Remote Port number
|
|
||||||
* @param proto Protocol proto
|
|
||||||
* @param type Protocol type
|
|
||||||
* @param flag Option flags to be set for this connection
|
|
||||||
*/
|
|
||||||
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, c_uint32_t ppid, const int flag);
|
|
||||||
/**
|
|
||||||
* Read the data from the socket
|
|
||||||
* @param net_sock Socket which created before
|
|
||||||
* @param buffer Buffer which data be saved
|
|
||||||
* @param size Total length of buffer
|
|
||||||
* @param timeout Wait timeout. If 0 , it will block until data ready
|
|
||||||
*/
|
|
||||||
CORE_DECLARE(int) net_read(net_sock_t *net_sock, char *buffer, size_t size,int timeout);
|
|
||||||
|
|
||||||
/** Write the data into the socket
|
|
||||||
* @param net_sock Socket which created before
|
|
||||||
* @param buffer Buffer which data be saved
|
|
||||||
* @param size Total length of buffer
|
|
||||||
*/
|
|
||||||
CORE_DECLARE(int) net_write(net_sock_t *net_sock, char *buffer, size_t size,
|
|
||||||
struct sockaddr_in *dest_addr, int addrlen);
|
|
||||||
|
|
||||||
CORE_DECLARE(int) net_send(net_sock_t *net_sock, char *buffer, size_t size);
|
|
||||||
|
|
||||||
CORE_DECLARE(int) net_sendto(net_sock_t *net_sock, char *buffer, size_t size,
|
|
||||||
c_uint32_t addr, c_uint16_t port);
|
|
||||||
|
|
||||||
|
|
||||||
/** Close the socket
|
|
||||||
* @param net_sock Socket to be closed
|
|
||||||
*/
|
|
||||||
CORE_DECLARE(int) net_close(net_sock_t *net_sock);
|
|
||||||
|
|
||||||
/** Wait the new socket session until given timeout
|
|
||||||
* @param new_accept_sock Newly created socket for new connection
|
|
||||||
* @param net_sock Listend socket before created
|
|
||||||
* @param timeout Wait timeout. If 0, it will be blocked until new connection
|
|
||||||
* received
|
|
||||||
*/
|
|
||||||
CORE_DECLARE(int) net_accept(net_sock_t **new_accept_sock,
|
|
||||||
net_sock_t *net_sock, int timeout);
|
|
||||||
|
|
||||||
/** Create socket and listen to the specified port
|
|
||||||
* @param net_sock Returned socket
|
|
||||||
* @param type Protocol type
|
|
||||||
* @param proto Protocol proto
|
|
||||||
* @param ppid SCTP PPID
|
|
||||||
* @param addr Specific address
|
|
||||||
* @param port Port number
|
|
||||||
*/
|
|
||||||
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
|
|
||||||
* @param proto Protocol proto
|
|
||||||
* @param port Port number
|
|
||||||
*/
|
|
||||||
CORE_DECLARE(int) net_listen(
|
|
||||||
net_sock_t **net_sock, const int type, const int proto,
|
|
||||||
const int port);
|
|
||||||
|
|
||||||
/** Network application protocol */
|
|
||||||
#define MAX_FTP_SESSION_SIZE 10
|
|
||||||
typedef struct {
|
|
||||||
net_sock_t *ctrl_sock; /* Control channel */
|
|
||||||
net_sock_t *data_sock; /* Data channel */
|
|
||||||
int flag;
|
|
||||||
char cmd_buf[256];
|
|
||||||
char resp_buf[256];
|
|
||||||
} net_ftp_t;
|
|
||||||
|
|
||||||
/** Open ftp session.
|
|
||||||
* @param host host name or IP address to connect
|
|
||||||
* @param username User ID or NULL if username is anonymous
|
|
||||||
* @param passwd Password or NULL if no passwd
|
|
||||||
* @param flag Option flags
|
|
||||||
* @param ftp_session Ftp session structure. If connection failed , it will be NULL
|
|
||||||
*/
|
|
||||||
CORE_DECLARE(int) net_ftp_open(const char *host,
|
|
||||||
const char *username,
|
|
||||||
const char *passwd,
|
|
||||||
int flag,
|
|
||||||
net_ftp_t **ftp_session);
|
|
||||||
|
|
||||||
/** Retrieve file using FTP
|
|
||||||
* @param ftp_session Ftp session which created from net_ftp_open
|
|
||||||
* @param remote_filename Remote filename to retrieve
|
|
||||||
* @param local_filename Local filename. If null, the same name as remote will
|
|
||||||
* be used.
|
|
||||||
*/
|
|
||||||
CORE_DECLARE(int) net_ftp_get(net_ftp_t *ftp_session,
|
|
||||||
const char *remote_filename,
|
|
||||||
const char *local_filename);
|
|
||||||
|
|
||||||
/** Upload file using FTP
|
|
||||||
* @param ftp_session Ftp session which created from net_ftp_open
|
|
||||||
* @param local_filename Local filename to upload.
|
|
||||||
* @param remote_filename Remote filename.If null, the same name as local will
|
|
||||||
* be used.
|
|
||||||
*/
|
|
||||||
CORE_DECLARE(int) net_ftp_put(net_ftp_t *ftp_session,
|
|
||||||
const char *local_filename,
|
|
||||||
const char *remote_filename);
|
|
||||||
/** Quit from ftp
|
|
||||||
* @param ftp_session Ftp session which created from net_ftp_open
|
|
||||||
*/
|
|
||||||
CORE_DECLARE(int) net_ftp_quit(net_ftp_t *ftp_session);
|
|
||||||
|
|
||||||
/** Close ftp session
|
|
||||||
* @param ftp_session Ftp session which created from net_ftp_open
|
|
||||||
*/
|
|
||||||
CORE_DECLARE(int) net_ftp_close(net_ftp_t *ftp_session);
|
|
||||||
|
|
||||||
/** Network session pool */
|
|
||||||
CORE_DECLARE(int) net_pool_avail();
|
|
||||||
|
|
||||||
/** Network link interface */
|
|
||||||
typedef struct {
|
|
||||||
int fd;
|
|
||||||
int ioctl_sock;
|
|
||||||
char ifname[MAX_IFNAME_LEN];
|
|
||||||
struct sockaddr hwaddr;
|
|
||||||
} net_link_t;
|
|
||||||
|
|
||||||
/** Network link handler */
|
|
||||||
typedef int (*net_link_handler)(net_link_t *net_sock, void *data);
|
|
||||||
|
|
||||||
|
|
||||||
/** Open network interface */
|
|
||||||
CORE_DECLARE(int) net_link_open(net_link_t **net_link, char *device, int proto);
|
|
||||||
/** Close network interface */
|
|
||||||
CORE_DECLARE(int) net_link_close(net_link_t *net_link);
|
|
||||||
|
|
||||||
/** Enable or disable promisc mode of network interface */
|
|
||||||
CORE_DECLARE(int) net_link_promisc(net_link_t *net_link, int enable);
|
|
||||||
|
|
||||||
/** Write the data into the link */
|
|
||||||
CORE_DECLARE(int) net_link_write(net_link_t *net_link, char *buf, int len);
|
|
||||||
|
|
||||||
/** Reate the data from the link */
|
|
||||||
CORE_DECLARE(int) net_link_read(net_link_t *net_link, char *buffer, int size,
|
|
||||||
int timeout);
|
|
||||||
|
|
||||||
/** Open the specified protocol raw socket */
|
|
||||||
CORE_DECLARE(int) net_raw_open(net_link_t **net_link, int proto);
|
|
||||||
|
|
||||||
/** Clse the specified protocol raw socket */
|
|
||||||
CORE_DECLARE(int) net_raw_close(net_link_t *net_link);
|
|
||||||
|
|
||||||
CORE_DECLARE(int) net_link_sendto(net_link_t *net_link, char *buf, int len,
|
|
||||||
struct sockaddr *dest_addr, int addrlen);
|
|
||||||
|
|
||||||
/** Register net_sock */
|
|
||||||
CORE_DECLARE(int) net_register_sock(net_sock_t *net_sock,
|
|
||||||
net_sock_handler handler, void *data);
|
|
||||||
|
|
||||||
/** Register net_link */
|
|
||||||
CORE_DECLARE(int) net_register_link(net_link_t *net_link,
|
|
||||||
net_link_handler handler, void *data);
|
|
||||||
|
|
||||||
/** Unregister net_sock */
|
|
||||||
CORE_DECLARE(int) net_unregister_sock(net_sock_t *net_sock);
|
|
||||||
|
|
||||||
/** Unregister net_link */
|
|
||||||
CORE_DECLARE(int) net_unregister_link(net_link_t *net_link);
|
|
||||||
|
|
||||||
/** Read the multiple fds and run the registered handler
|
|
||||||
* @param timeout timeout(milliseconds)
|
|
||||||
*/
|
|
||||||
CORE_DECLARE(int) net_fds_read_run(long timeout);
|
|
||||||
|
|
||||||
/** TunTap interface */
|
|
||||||
CORE_DECLARE(int) net_tun_open(net_link_t **net_link, char *name, int is_tap);
|
|
||||||
CORE_DECLARE(int) net_tun_set_ipv4(
|
|
||||||
net_link_t *net_link, c_uint32_t addr, c_uint8_t bits);
|
|
||||||
CORE_DECLARE(int) net_tun_close(net_link_t *net_link);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif /* __cplusplus */
|
|
||||||
|
|
||||||
#endif /* ! __CORE_NET_H__ */
|
|
|
@ -5,8 +5,6 @@
|
||||||
#include "core_time.h"
|
#include "core_time.h"
|
||||||
#include "core_list.h"
|
#include "core_list.h"
|
||||||
|
|
||||||
#define NO_FD_LOCK 1 /* New experimental method */
|
|
||||||
|
|
||||||
#if HAVE_ARPA_INET_H
|
#if HAVE_ARPA_INET_H
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -9,14 +9,6 @@
|
||||||
#define MAX_SOCK_POOL_SIZE 512
|
#define MAX_SOCK_POOL_SIZE 512
|
||||||
#define MAX_SOCK_NODE_POOL_SIZE 512
|
#define MAX_SOCK_NODE_POOL_SIZE 512
|
||||||
|
|
||||||
#if NO_FD_LOCK
|
|
||||||
#define FD_LOCK
|
|
||||||
#define FD_UNLOCK
|
|
||||||
#else
|
|
||||||
#define FD_LOCK mutex_lock(mutex);
|
|
||||||
#define FD_UNLOCK mutex_unlock(mutex);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static int max_fd;
|
static int max_fd;
|
||||||
static list_t fd_list;
|
static list_t fd_list;
|
||||||
static fd_set read_fds;
|
static fd_set read_fds;
|
||||||
|
@ -667,8 +659,6 @@ status_t sock_register(sock_id id, sock_handler handler, void *data)
|
||||||
return CORE_ERROR;
|
return CORE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
FD_LOCK
|
|
||||||
|
|
||||||
if (sock->fd > max_fd)
|
if (sock->fd > max_fd)
|
||||||
{
|
{
|
||||||
max_fd = sock->fd;
|
max_fd = sock->fd;
|
||||||
|
@ -678,8 +668,6 @@ status_t sock_register(sock_id id, sock_handler handler, void *data)
|
||||||
|
|
||||||
list_append(&fd_list, sock);
|
list_append(&fd_list, sock);
|
||||||
|
|
||||||
FD_UNLOCK
|
|
||||||
|
|
||||||
return CORE_OK;
|
return CORE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -687,12 +675,8 @@ status_t sock_unregister(sock_id id)
|
||||||
{
|
{
|
||||||
d_assert(id, return CORE_ERROR,);
|
d_assert(id, return CORE_ERROR,);
|
||||||
|
|
||||||
FD_LOCK
|
|
||||||
|
|
||||||
list_remove(&fd_list, id);
|
list_remove(&fd_list, id);
|
||||||
|
|
||||||
FD_UNLOCK
|
|
||||||
|
|
||||||
return CORE_OK;
|
return CORE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -701,19 +685,15 @@ int sock_is_registered(sock_id id)
|
||||||
sock_t *sock = (sock_t *)id;
|
sock_t *sock = (sock_t *)id;
|
||||||
sock_t *iter = NULL;
|
sock_t *iter = NULL;
|
||||||
|
|
||||||
FD_LOCK
|
|
||||||
|
|
||||||
d_assert(id, return CORE_ERROR,);
|
d_assert(id, return CORE_ERROR,);
|
||||||
for (iter = list_first(&fd_list); iter != NULL; iter = list_next(iter))
|
for (iter = list_first(&fd_list); iter != NULL; iter = list_next(iter))
|
||||||
{
|
{
|
||||||
if (iter == sock)
|
if (iter == sock)
|
||||||
{
|
{
|
||||||
FD_UNLOCK
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FD_UNLOCK
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -810,23 +790,17 @@ static void set_fds(fd_set *fds)
|
||||||
{
|
{
|
||||||
sock_t *sock = NULL;
|
sock_t *sock = NULL;
|
||||||
|
|
||||||
FD_LOCK
|
|
||||||
|
|
||||||
FD_ZERO(fds);
|
FD_ZERO(fds);
|
||||||
for (sock = list_first(&fd_list); sock != NULL; sock = list_next(sock))
|
for (sock = list_first(&fd_list); sock != NULL; sock = list_next(sock))
|
||||||
{
|
{
|
||||||
FD_SET(sock->fd, fds);
|
FD_SET(sock->fd, fds);
|
||||||
}
|
}
|
||||||
|
|
||||||
FD_UNLOCK
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void fd_dispatch(fd_set *fds)
|
static void fd_dispatch(fd_set *fds)
|
||||||
{
|
{
|
||||||
sock_t *sock = NULL;
|
sock_t *sock = NULL;
|
||||||
|
|
||||||
FD_LOCK
|
|
||||||
|
|
||||||
for (sock = list_first(&fd_list); sock != NULL; sock = list_next(sock))
|
for (sock = list_first(&fd_list); sock != NULL; sock = list_next(sock))
|
||||||
{
|
{
|
||||||
if (FD_ISSET(sock->fd, fds))
|
if (FD_ISSET(sock->fd, fds))
|
||||||
|
@ -837,6 +811,4 @@ static void fd_dispatch(fd_set *fds)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FD_UNLOCK
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1642,12 +1642,6 @@ status_t mme_enb_remove(mme_enb_t *enb)
|
||||||
|
|
||||||
enb_ue_remove_in_enb(enb);
|
enb_ue_remove_in_enb(enb);
|
||||||
|
|
||||||
#ifdef NO_FD_LOCK
|
|
||||||
#else
|
|
||||||
#error do not use lock in socket fd
|
|
||||||
if (enb->sock_type == SOCK_STREAM)
|
|
||||||
s1ap_delete(enb->sock);
|
|
||||||
#endif
|
|
||||||
CORE_FREE(enb->addr);
|
CORE_FREE(enb->addr);
|
||||||
|
|
||||||
index_free(&mme_enb_pool, enb);
|
index_free(&mme_enb_pool, enb);
|
||||||
|
@ -1663,12 +1657,10 @@ status_t mme_enb_remove_all()
|
||||||
for (hi = mme_enb_first(); hi; hi = mme_enb_next(hi))
|
for (hi = mme_enb_first(); hi; hi = mme_enb_next(hi))
|
||||||
{
|
{
|
||||||
enb = mme_enb_this(hi);
|
enb = mme_enb_this(hi);
|
||||||
#ifdef NO_FD_LOCK
|
|
||||||
if (enb->sock_type == SOCK_STREAM)
|
if (enb->sock_type == SOCK_STREAM)
|
||||||
s1ap_delete(enb->sock);
|
s1ap_delete(enb->sock);
|
||||||
#else
|
|
||||||
#error do not use lock in socket fd
|
|
||||||
#endif
|
|
||||||
mme_enb_remove(enb);
|
mme_enb_remove(enb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -124,21 +124,7 @@ void mme_state_operational(fsm_t *s, event_t *e)
|
||||||
addr = (c_sockaddr_t *)event_get_param2(e);
|
addr = (c_sockaddr_t *)event_get_param2(e);
|
||||||
d_assert(addr, break, "Null param");
|
d_assert(addr, break, "Null param");
|
||||||
|
|
||||||
#ifdef NO_FD_LOCK
|
|
||||||
enb = mme_enb_find_by_addr(addr);
|
enb = mme_enb_find_by_addr(addr);
|
||||||
#else
|
|
||||||
#error do not use lock in socket fd
|
|
||||||
/*
|
|
||||||
* <Connection Refused>
|
|
||||||
* if socket type is SOCK_STREAM,
|
|
||||||
* I'm not sure whether address is available or not.
|
|
||||||
* So, I'll use 'sock_id' at this point.
|
|
||||||
*/
|
|
||||||
if (mme_enb_sock_type(sock) == SOCK_STREAM)
|
|
||||||
enb = mme_enb_find_by_sock(sock);
|
|
||||||
else
|
|
||||||
enb = mme_enb_find_by_addr(addr);
|
|
||||||
#endif
|
|
||||||
CORE_FREE(addr);
|
CORE_FREE(addr);
|
||||||
|
|
||||||
if (enb)
|
if (enb)
|
||||||
|
|
|
@ -163,11 +163,7 @@ int s1ap_recv_handler(sock_id sock, void *data)
|
||||||
event_set(&e, MME_EVT_S1AP_LO_CONNREFUSED);
|
event_set(&e, MME_EVT_S1AP_LO_CONNREFUSED);
|
||||||
event_set_param1(&e, (c_uintptr_t)sock);
|
event_set_param1(&e, (c_uintptr_t)sock);
|
||||||
event_set_param2(&e, (c_uintptr_t)addr);
|
event_set_param2(&e, (c_uintptr_t)addr);
|
||||||
#ifdef NO_FD_LOCK
|
|
||||||
sock_delete(sock);
|
sock_delete(sock);
|
||||||
#else
|
|
||||||
#error do not use lock in socket fd
|
|
||||||
#endif
|
|
||||||
if (mme_event_send(&e) != CORE_OK)
|
if (mme_event_send(&e) != CORE_OK)
|
||||||
{
|
{
|
||||||
d_error("Event MME_EVT_S1AP_LO_CONNREFUSED failed");
|
d_error("Event MME_EVT_S1AP_LO_CONNREFUSED failed");
|
||||||
|
|
Loading…
Reference in New Issue