Skip to content
Snippets Groups Projects
Commit 5e7ca0d4 authored by Dmitriy A. Gerasimov's avatar Dmitriy A. Gerasimov
Browse files

[*] Some renames

parent 60ac2517
No related branches found
No related tags found
No related merge requests found
......@@ -97,28 +97,29 @@ static list_addr_element *list_addr_head = NULL;
static ch_vpn_socket_proxy_t * sf_socks = NULL;
static ch_vpn_socket_proxy_t * sf_socks_client = NULL;
static pthread_mutex_t sf_socks_mutex;
static pthread_cond_t sf_socks_cond;
static pthread_mutex_t s_sf_socks_mutex;
static pthread_cond_t s_sf_socks_cond;
static int sf_socks_epoll_fd;
static pthread_t srv_sf_socks_pid;
static pthread_t srv_sf_socks_raw_pid;
static vpn_local_network_t *s_raw_server;
vpn_local_network_t *raw_server;
static const char *s_addr;
void *srv_ch_sf_thread(void * arg);
void *srv_ch_sf_thread_raw(void *arg);
void srv_ch_sf_tun_create();
void srv_ch_sf_tun_destroy();
static void *srv_ch_sf_thread(void * arg);
static void *srv_ch_sf_thread_raw(void *arg);
static void s_tun_create(void);
static void s_tun_destroy(void);
void srv_ch_sf_new(dap_stream_ch_t* ch, void* arg);
void srv_ch_sf_delete(dap_stream_ch_t* ch, void* arg);
void srv_ch_sf_packet_in(dap_stream_ch_t* ch, void* arg);
void srv_ch_sf_packet_out(dap_stream_ch_t* ch, void* arg);
static void s_new(dap_stream_ch_t* ch, void* arg);
static void srv_ch_sf_delete(dap_stream_ch_t* ch, void* arg);
static void srv_ch_sf_packet_in(dap_stream_ch_t* ch, void* arg);
static void srv_ch_sf_packet_out(dap_stream_ch_t* ch, void* arg);
//static int srv_ch_sf_raw_write(uint8_t op_code, const void * data, size_t data_size);
//void srv_stream_sf_disconnect(ch_vpn_socket_proxy_t * sf_sock);
//static void srv_stream_sf_disconnect(ch_vpn_socket_proxy_t * sf_sock);
static const char *s_srv_vpn_addr, *s_srv_vpn_mask;
static char *s_srv_vpn_addr, *s_srv_vpn_mask;
/**
* @brief dap_stream_ch_vpn_init Init actions for VPN stream channel
......@@ -128,20 +129,20 @@ static const char *s_srv_vpn_addr, *s_srv_vpn_mask;
*/
int dap_chain_net_srv_vpn_init(dap_config_t * g_config)
{
const char *s_addr = dap_config_get_item_str(g_config, "vpn", "network_address");
const char *s_mask = dap_config_get_item_str(g_config, "vpn", "network_mask");
if(s_addr && s_mask) {
s_srv_vpn_addr = strdup(s_addr);
s_srv_vpn_mask = strdup(s_mask);
raw_server = calloc(1, sizeof(vpn_local_network_t));
pthread_mutex_init(&raw_server->clients_mutex, NULL);
pthread_mutex_init(&raw_server->pkt_out_mutex, NULL);
pthread_mutex_init(&sf_socks_mutex, NULL);
pthread_cond_init(&sf_socks_cond, NULL);
const char *c_addr = dap_config_get_item_str(g_config, "vpn", "network_address");
const char *c_mask = dap_config_get_item_str(g_config, "vpn", "network_mask");
if(c_addr && c_mask) {
s_srv_vpn_addr = strdup(c_addr);
s_srv_vpn_mask = strdup(c_mask);
s_raw_server = DAP_NEW_Z(vpn_local_network_t);
pthread_mutex_init(&s_raw_server->clients_mutex, NULL);
pthread_mutex_init(&s_raw_server->pkt_out_mutex, NULL);
pthread_mutex_init(&s_sf_socks_mutex, NULL);
pthread_cond_init(&s_sf_socks_cond, NULL);
pthread_create(&srv_sf_socks_raw_pid, NULL, srv_ch_sf_thread_raw, NULL);
pthread_create(&srv_sf_socks_pid, NULL, srv_ch_sf_thread, NULL);
dap_stream_ch_proc_add(SERVICE_CHANNEL_ID, srv_ch_sf_new, srv_ch_sf_delete, srv_ch_sf_packet_in,
dap_stream_ch_proc_add(SERVICE_CHANNEL_ID, s_new, srv_ch_sf_delete, srv_ch_sf_packet_in,
srv_ch_sf_packet_out);
return 0;
}
......@@ -151,43 +152,46 @@ int dap_chain_net_srv_vpn_init(dap_config_t * g_config)
/**
* @brief ch_sf_deinit
*/
void dap_chain_net_srv_vpn_deinit()
void dap_chain_net_srv_vpn_deinit(void)
{
pthread_mutex_destroy(&sf_socks_mutex);
pthread_cond_destroy(&sf_socks_cond);
pthread_mutex_destroy(&s_sf_socks_mutex);
pthread_cond_destroy(&s_sf_socks_cond);
free((char*) s_srv_vpn_addr);
free((char*) s_srv_vpn_mask);
if(raw_server)
free(raw_server);
if(s_raw_server)
free(s_raw_server);
}
void srv_ch_sf_tun_create()
/**
* @brief s_tun_create
*/
static void s_tun_create(void)
{
inet_aton(s_srv_vpn_addr, &raw_server->client_addr);
inet_aton(s_srv_vpn_mask, &raw_server->client_addr_mask);
raw_server->client_addr_host.s_addr = (raw_server->client_addr.s_addr | 0x01000000); // grow up some shit here!
raw_server->client_addr_last.s_addr = raw_server->client_addr_host.s_addr;
inet_aton(s_srv_vpn_addr, &s_raw_server->client_addr);
inet_aton(s_srv_vpn_mask, &s_raw_server->client_addr_mask);
s_raw_server->client_addr_host.s_addr = (s_raw_server->client_addr.s_addr | 0x01000000); // grow up some shit here!
s_raw_server->client_addr_last.s_addr = s_raw_server->client_addr_host.s_addr;
if((raw_server->tun_ctl_fd = open("/dev/net/tun", O_RDWR)) < 0) {
if((s_raw_server->tun_ctl_fd = open("/dev/net/tun", O_RDWR)) < 0) {
log_it(L_ERROR, "Opening /dev/net/tun error: '%s'", strerror(errno));
} else {
int err;
memset(&raw_server->ifr, 0, sizeof(raw_server->ifr));
raw_server->ifr.ifr_flags = IFF_TUN | IFF_NO_PI;
if((err = ioctl(raw_server->tun_ctl_fd, TUNSETIFF, (void *) &raw_server->ifr)) < 0) {
memset(&s_raw_server->ifr, 0, sizeof(s_raw_server->ifr));
s_raw_server->ifr.ifr_flags = IFF_TUN | IFF_NO_PI;
if((err = ioctl(s_raw_server->tun_ctl_fd, TUNSETIFF, (void *) &s_raw_server->ifr)) < 0) {
log_it(L_CRITICAL, "ioctl(TUNSETIFF) error: '%s' ", strerror(errno));
close(raw_server->tun_ctl_fd);
raw_server->tun_ctl_fd = -1;
close(s_raw_server->tun_ctl_fd);
s_raw_server->tun_ctl_fd = -1;
} else {
char buf[256];
log_it(L_NOTICE, "Bringed up %s virtual network interface (%s/%s)", raw_server->ifr.ifr_name,
inet_ntoa(raw_server->client_addr_host), s_srv_vpn_mask);
raw_server->tun_fd = raw_server->tun_ctl_fd; // Looks yes, its so
snprintf(buf, sizeof(buf), "ip link set %s up", raw_server->ifr.ifr_name);
log_it(L_NOTICE, "Bringed up %s virtual network interface (%s/%s)", s_raw_server->ifr.ifr_name,
inet_ntoa(s_raw_server->client_addr_host), s_srv_vpn_mask);
s_raw_server->tun_fd = s_raw_server->tun_ctl_fd; // Looks yes, its so
snprintf(buf, sizeof(buf), "ip link set %s up", s_raw_server->ifr.ifr_name);
int res = system(buf);
snprintf(buf, sizeof(buf), "ip addr add %s/%s dev %s ", inet_ntoa(raw_server->client_addr_host),
snprintf(buf, sizeof(buf), "ip addr add %s/%s dev %s ", inet_ntoa(s_raw_server->client_addr_host),
s_srv_vpn_mask,
raw_server->ifr.ifr_name);
s_raw_server->ifr.ifr_name);
res = system(buf);
res = 0;
}
......@@ -195,13 +199,21 @@ void srv_ch_sf_tun_create()
}
void srv_ch_sf_tun_destroy()
/**
* @brief s_tun_destroy
*/
static void s_tun_destroy(void)
{
close(raw_server->tun_fd);
raw_server->tun_fd = -1;
close(s_raw_server->tun_fd);
s_raw_server->tun_fd = -1;
}
static void callback_trafic(dap_client_remote_t *a_client, dap_stream_ch_t* a_ch)
/**
* @brief s_callback_trafic
* @param a_client
* @param a_ch
*/
static void s_callback_trafic(dap_client_remote_t *a_client, dap_stream_ch_t* a_ch)
{
dap_chain_net_srv_vpn_t *l_ch_vpn = CH_VPN(a_ch);
//dap_stream_ch_vpn_t *l_ch_vpn = (dap_stream_ch_vpn_t*)(a_ch->internal);
......@@ -243,11 +255,11 @@ static void ch_sf_socket_delete(ch_vpn_socket_proxy_t * a_vpn_socket_proxy)
/**
* @brief stream_sf_new Callback to constructor of object of Ch
* @brief s_new Callback to constructor of object of Ch
* @param ch
* @param arg
*/
void srv_ch_sf_new(dap_stream_ch_t* a_stream_ch, void* a_arg)
void s_new(dap_stream_ch_t* a_stream_ch, void* a_arg)
{
(void) a_arg;
......@@ -275,7 +287,7 @@ void srv_ch_sf_new(dap_stream_ch_t* a_stream_ch, void* a_arg)
{
dap_chain_net_srv_t l_srv;
memset(&l_srv, 0, sizeof(dap_chain_net_srv_t));
l_srv.callback_trafic = callback_trafic;
l_srv.callback_trafic = s_callback_trafic;
// debug
l_srv.srv_common.proposal_params.vpn.limit_bytes = 2000;
if(l_cond)
......@@ -310,11 +322,11 @@ void srv_ch_sf_delete(dap_stream_ch_t* ch, void* arg)
LL_APPEND(list_addr_head, el);
// LL_FOREACH(list_addr_head,el) log_it(L_INFO,"addr = %s", inet_ntoa(el->addr));
pthread_mutex_lock(&raw_server->clients_mutex);
pthread_mutex_lock(&s_raw_server->clients_mutex);
HASH_FIND_INT(raw_server->clients, &raw_client_addr, raw_client);
HASH_FIND_INT(s_raw_server->clients, &raw_client_addr, raw_client);
if(raw_client) {
HASH_DEL(raw_server->clients, raw_client);
HASH_DEL(s_raw_server->clients, raw_client);
log_it(L_DEBUG, "ch_sf_delete() %s removed from hash table",
inet_ntoa(ch->stream->session->tun_client_addr));
free(raw_client);
......@@ -322,7 +334,7 @@ void srv_ch_sf_delete(dap_stream_ch_t* ch, void* arg)
log_it(L_DEBUG, "ch_sf_delete() %s is not present in raw sockets hash table",
inet_ntoa(ch->stream->session->tun_client_addr));
pthread_mutex_unlock(&raw_server->clients_mutex);
pthread_mutex_unlock(&s_raw_server->clients_mutex);
}
HASH_ITER(hh, CH_VPN(ch)->socks , cur, tmp)
{
......@@ -365,17 +377,17 @@ static void stream_sf_socket_ready_to_write(dap_stream_ch_t * ch, bool is_ready)
static ch_vpn_pkt_t* srv_ch_sf_raw_read()
{
ch_vpn_pkt_t*ret = NULL;
pthread_mutex_lock(&raw_server->pkt_out_mutex);
if(raw_server->pkt_out_rindex == (sizeof(raw_server->pkt_out) / sizeof(raw_server->pkt_out[0]))) {
raw_server->pkt_out_rindex = 0; // ring the buffer!
pthread_mutex_lock(&s_raw_server->pkt_out_mutex);
if(s_raw_server->pkt_out_rindex == (sizeof(s_raw_server->pkt_out) / sizeof(s_raw_server->pkt_out[0]))) {
s_raw_server->pkt_out_rindex = 0; // ring the buffer!
}
if((raw_server->pkt_out_rindex != raw_server->pkt_out_windex) || (raw_server->pkt_out_size == 0)) {
ret = raw_server->pkt_out[raw_server->pkt_out_rindex];
raw_server->pkt_out_rindex++;
raw_server->pkt_out_size--;
if((s_raw_server->pkt_out_rindex != s_raw_server->pkt_out_windex) || (s_raw_server->pkt_out_size == 0)) {
ret = s_raw_server->pkt_out[s_raw_server->pkt_out_rindex];
s_raw_server->pkt_out_rindex++;
s_raw_server->pkt_out_size--;
} //else
// log_it(L_WARNING, "Packet drop on raw_read() operation, ring buffer is full");
pthread_mutex_unlock(&raw_server->pkt_out_mutex);
pthread_mutex_unlock(&s_raw_server->pkt_out_mutex);
return ret;
}
......@@ -402,7 +414,7 @@ void srv_ch_sf_packet_in(dap_stream_ch_t* ch, void* arg)
if(n_addr.s_addr == 0) { // If the addres still in the network
pthread_mutex_lock(&raw_server->clients_mutex);
pthread_mutex_lock(&s_raw_server->clients_mutex);
int count_free_addr = -1;
list_addr_element *el;
......@@ -418,32 +430,32 @@ void srv_ch_sf_packet_in(dap_stream_ch_t* ch, void* arg)
}
else
{
n_addr.s_addr = ntohl(raw_server->client_addr_last.s_addr);
n_addr.s_addr = ntohl(s_raw_server->client_addr_last.s_addr);
n_addr.s_addr++;
n_addr.s_addr = ntohl(n_addr.s_addr);
}
n_client->addr = n_addr.s_addr;
raw_server->client_addr_last.s_addr = n_addr.s_addr;
s_raw_server->client_addr_last.s_addr = n_addr.s_addr;
ch->stream->session->tun_client_addr.s_addr = n_addr.s_addr;
HASH_ADD_INT(raw_server->clients, addr, n_client);
HASH_ADD_INT(s_raw_server->clients, addr, n_client);
pthread_mutex_unlock(&raw_server->clients_mutex);
pthread_mutex_unlock(&s_raw_server->clients_mutex);
log_it(L_NOTICE, "VPN client address %s leased", inet_ntoa(n_addr));
log_it(L_INFO, "\tgateway %s", inet_ntoa(raw_server->client_addr_host));
log_it(L_INFO, "\tmask %s", inet_ntoa(raw_server->client_addr_mask));
log_it(L_INFO, "\taddr %s", inet_ntoa(raw_server->client_addr));
log_it(L_INFO, "\tlast_addr %s", inet_ntoa(raw_server->client_addr_last));
log_it(L_INFO, "\tgateway %s", inet_ntoa(s_raw_server->client_addr_host));
log_it(L_INFO, "\tmask %s", inet_ntoa(s_raw_server->client_addr_mask));
log_it(L_INFO, "\taddr %s", inet_ntoa(s_raw_server->client_addr));
log_it(L_INFO, "\tlast_addr %s", inet_ntoa(s_raw_server->client_addr_last));
ch_vpn_pkt_t *pkt_out = (ch_vpn_pkt_t*) calloc(1,
sizeof(pkt_out->header) + sizeof(n_addr) + sizeof(raw_server->client_addr_host));
pkt_out->header.sock_id = raw_server->tun_fd;
sizeof(pkt_out->header) + sizeof(n_addr) + sizeof(s_raw_server->client_addr_host));
pkt_out->header.sock_id = s_raw_server->tun_fd;
pkt_out->header.op_code = VPN_PACKET_OP_CODE_VPN_ADDR_REPLY;
pkt_out->header.op_data.data_size = sizeof(n_addr) + sizeof(raw_server->client_addr_host);
pkt_out->header.op_data.data_size = sizeof(n_addr) + sizeof(s_raw_server->client_addr_host);
memcpy(pkt_out->data, &n_addr, sizeof(n_addr));
memcpy(pkt_out->data + sizeof(n_addr), &raw_server->client_addr_host,
sizeof(raw_server->client_addr_host));
memcpy(pkt_out->data + sizeof(n_addr), &s_raw_server->client_addr_host,
sizeof(s_raw_server->client_addr_host));
dap_stream_ch_pkt_write(ch, DATA_CHANNEL_ID, pkt_out,
pkt_out->header.op_data.data_size + sizeof(pkt_out->header));
stream_sf_socket_ready_to_write(ch, true);
......@@ -452,7 +464,7 @@ void srv_ch_sf_packet_in(dap_stream_ch_t* ch, void* arg)
} else { // All the network is filled with clients, can't lease a new address
log_it(L_WARNING, "All the network is filled with clients, can't lease a new address");
ch_vpn_pkt_t *pkt_out = (ch_vpn_pkt_t*) calloc(1, sizeof(pkt_out->header));
pkt_out->header.sock_id = raw_server->tun_fd;
pkt_out->header.sock_id = s_raw_server->tun_fd;
pkt_out->header.op_code = VPN_PACKET_OP_CODE_PROBLEM;
pkt_out->header.op_problem.code = VPN_PROBLEM_CODE_NO_FREE_ADDR;
dap_stream_ch_pkt_write(ch, DATA_CHANNEL_ID, pkt_out,
......@@ -477,13 +489,13 @@ void srv_ch_sf_packet_in(dap_stream_ch_t* ch, void* arg)
sin.sin_addr.s_addr = in_daddr.s_addr;
//if((ret=sendto(CH_SF(ch)->raw_l3_sock , sf_pkt->data,sf_pkt->header.op_data.data_size,0,(struct sockaddr *) &sin, sizeof (sin)))<0){
if((ret = write(raw_server->tun_fd, sf_pkt->data, sf_pkt->header.op_data.data_size)) < 0) {
if((ret = write(s_raw_server->tun_fd, sf_pkt->data, sf_pkt->header.op_data.data_size)) < 0) {
log_it(L_ERROR, "write() returned error %d : '%s'", ret, strerror(errno));
//log_it(L_ERROR,"raw socket ring buffer overflowed");
ch_vpn_pkt_t *pkt_out = (ch_vpn_pkt_t*) calloc(1, sizeof(pkt_out->header));
pkt_out->header.op_code = VPN_PACKET_OP_CODE_PROBLEM;
pkt_out->header.op_problem.code = VPN_PROBLEM_CODE_PACKET_LOST;
pkt_out->header.sock_id = raw_server->tun_fd;
pkt_out->header.sock_id = s_raw_server->tun_fd;
dap_stream_ch_pkt_write(ch, DATA_CHANNEL_ID, pkt_out,
pkt_out->header.op_data.data_size + sizeof(pkt_out->header));
stream_sf_socket_ready_to_write(ch, true);
......@@ -515,7 +527,7 @@ void srv_ch_sf_packet_in(dap_stream_ch_t* ch, void* arg)
if(client_connected == false)
{
log_it(L_WARNING, "Drop Packet! User not connected!"); // Client need send
pthread_mutex_unlock(&sf_socks_mutex);
pthread_mutex_unlock(&s_sf_socks_mutex);
break;
}
int ret;
......@@ -526,7 +538,7 @@ void srv_ch_sf_packet_in(dap_stream_ch_t* ch, void* arg)
HASH_DEL(CH_VPN(ch)->socks, sf_sock);
pthread_mutex_unlock(&( CH_VPN(ch)->mutex));
pthread_mutex_lock(&sf_socks_mutex);
pthread_mutex_lock(&s_sf_socks_mutex);
HASH_DELETE(hh2, sf_socks, sf_sock);
HASH_DELETE(hh_sock, sf_socks_client, sf_sock);
......@@ -540,7 +552,7 @@ void srv_ch_sf_packet_in(dap_stream_ch_t* ch, void* arg)
log_it(L_NOTICE, "Removed sock_id %d from the the epoll fd", remote_sock_id);
//stream_ch_pkt_write_f(ch,'i',"sock_id=%d op_code=0x%02x result=0",sf_pkt->sock_id, sf_pkt->op_code);
}
pthread_mutex_unlock(&sf_socks_mutex);
pthread_mutex_unlock(&s_sf_socks_mutex);
stream_sf_socket_delete(sf_sock);
} else {
......@@ -558,7 +570,7 @@ void srv_ch_sf_packet_in(dap_stream_ch_t* ch, void* arg)
HASH_DEL(CH_VPN(ch)->socks, sf_sock);
pthread_mutex_unlock(&( CH_VPN(ch)->mutex));
pthread_mutex_lock(&sf_socks_mutex);
pthread_mutex_lock(&s_sf_socks_mutex);
HASH_DELETE(hh2, sf_socks, sf_sock);
HASH_DELETE(hh_sock, sf_socks_client, sf_sock);
struct epoll_event ev;
......@@ -571,7 +583,7 @@ void srv_ch_sf_packet_in(dap_stream_ch_t* ch, void* arg)
log_it(L_NOTICE, "Removed sock_id %d from the epoll fd", remote_sock_id);
//stream_ch_pkt_write_f(ch,'i',"sock_id=%d op_code=%uc result=0",sf_pkt->sock_id, sf_pkt->op_code);
}
pthread_mutex_unlock(&sf_socks_mutex);
pthread_mutex_unlock(&s_sf_socks_mutex);
pthread_mutex_unlock(&sf_sock->mutex);
stream_sf_socket_delete(sf_sock);
......@@ -622,7 +634,7 @@ void srv_ch_sf_packet_in(dap_stream_ch_t* ch, void* arg)
sf_sock->ch = ch;
pthread_mutex_init(&sf_sock->mutex, NULL);
pthread_mutex_lock(&sf_socks_mutex);
pthread_mutex_lock(&s_sf_socks_mutex);
pthread_mutex_lock(&( CH_VPN(ch)->mutex));
HASH_ADD_INT(CH_VPN(ch)->socks, id, sf_sock);
log_it(L_DEBUG, "Added %d sock_id with sock %d to the hash table", sf_sock->id,
......@@ -632,7 +644,7 @@ void srv_ch_sf_packet_in(dap_stream_ch_t* ch, void* arg)
sf_sock->sock);
HASH_ADD(hh_sock, sf_socks_client, sock, sizeof(int), sf_sock);
//log_it(L_DEBUG,"Added %d sock_id with sock %d to the socks hash table",sf->id,sf->sock);
pthread_mutex_unlock(&sf_socks_mutex);
pthread_mutex_unlock(&s_sf_socks_mutex);
pthread_mutex_unlock(&( CH_VPN(ch)->mutex));
struct epoll_event ev;
......@@ -725,9 +737,9 @@ void * srv_ch_sf_thread(void * arg)
int s = events[n].data.fd;
ch_vpn_socket_proxy_t * sf = NULL;
pthread_mutex_lock(&sf_socks_mutex);
pthread_mutex_lock(&s_sf_socks_mutex);
HASH_FIND(hh_sock, sf_socks_client, &s, sizeof(s), sf);
pthread_mutex_unlock(&sf_socks_mutex);
pthread_mutex_unlock(&s_sf_socks_mutex);
if(sf) {
if(events[n].events & EPOLLERR) {
log_it(L_NOTICE, "Socket id %d has EPOLLERR flag on", s);
......@@ -786,9 +798,9 @@ void * srv_ch_sf_thread(void * arg)
**/
void* srv_ch_sf_thread_raw(void *arg)
{
srv_ch_sf_tun_create();
s_tun_create();
if(raw_server->tun_fd <= 0) {
if(s_raw_server->tun_fd <= 0) {
log_it(L_CRITICAL, "Tun/tap file descriptor is not initialized");
return NULL;
}
......@@ -812,7 +824,7 @@ void* srv_ch_sf_thread_raw(void *arg)
fd_set fds_read, fds_read_active;
FD_ZERO(&fds_read);
FD_SET(raw_server->tun_fd, &fds_read);
FD_SET(s_raw_server->tun_fd, &fds_read);
FD_SET(get_select_breaker(), &fds_read);
/// Main cycle
do {
......@@ -823,7 +835,7 @@ void* srv_ch_sf_thread_raw(void *arg)
if(FD_ISSET(get_select_breaker(), &fds_read_active)) { // Smth to send
ch_vpn_pkt_t* pkt = srv_ch_sf_raw_read();
if(pkt) {
int write_ret = write(raw_server->tun_fd, pkt->data, pkt->header.op_data.data_size);
int write_ret = write(s_raw_server->tun_fd, pkt->data, pkt->header.op_data.data_size);
if(write_ret > 0) {
//log_it(L_DEBUG, "Wrote out %d bytes to the tun/tap interface", write_ret);
} else {
......@@ -832,8 +844,8 @@ void* srv_ch_sf_thread_raw(void *arg)
}
}
}
if(FD_ISSET(raw_server->tun_fd, &fds_read_active)) {
int read_ret = read(raw_server->tun_fd, tmp_buf, tun_MTU);
if(FD_ISSET(s_raw_server->tun_fd, &fds_read_active)) {
int read_ret = read(s_raw_server->tun_fd, tmp_buf, tun_MTU);
if(read_ret < 0) {
log_it(L_CRITICAL, "Tun/tap read returned '%s' error, code (%d)", strerror(errno), read_ret);
break;
......@@ -849,21 +861,21 @@ void* srv_ch_sf_thread_raw(void *arg)
//log_it(L_DEBUG, "Read IP packet from tun/tap interface daddr=%s saddr=%s total_size = %d "
// , str_daddr, str_saddr, read_ret);
dap_stream_ch_vpn_remote_single_t * raw_client = NULL;
pthread_mutex_lock(&raw_server->clients_mutex);
HASH_FIND_INT(raw_server->clients, &in_daddr.s_addr, raw_client);
pthread_mutex_lock(&s_raw_server->clients_mutex);
HASH_FIND_INT(s_raw_server->clients, &in_daddr.s_addr, raw_client);
// HASH_ADD_INT(CH_SF(ch)->socks, id, sf_sock );
// HASH_DEL(CH_SF(ch)->socks,sf_sock);
if(raw_client) { // Is present in hash table such destination address
ch_vpn_pkt_t *pkt_out = (ch_vpn_pkt_t*) calloc(1, sizeof(pkt_out->header) + read_ret);
pkt_out->header.op_code = VPN_PACKET_OP_CODE_VPN_RECV;
pkt_out->header.sock_id = raw_server->tun_fd;
pkt_out->header.sock_id = s_raw_server->tun_fd;
pkt_out->header.op_data.data_size = read_ret;
memcpy(pkt_out->data, tmp_buf, read_ret);
dap_stream_ch_pkt_write(raw_client->ch, DATA_CHANNEL_ID, pkt_out,
pkt_out->header.op_data.data_size + sizeof(pkt_out->header));
stream_sf_socket_ready_to_write(raw_client->ch, true);
}
pthread_mutex_unlock(&raw_server->clients_mutex);
pthread_mutex_unlock(&s_raw_server->clients_mutex);
}
}/*else {
log_it(L_CRITICAL,"select() has no tun handler in the returned set");
......@@ -876,7 +888,7 @@ void* srv_ch_sf_thread_raw(void *arg)
}
} while(1);
log_it(L_NOTICE, "Raw sockets listen thread is stopped");
srv_ch_sf_tun_destroy();
s_tun_destroy();
return NULL;
}
......@@ -927,10 +939,10 @@ void srv_ch_sf_packet_out(dap_stream_ch_t* ch, void* arg)
HASH_DEL(CH_VPN(ch)->socks, cur);
pthread_mutex_unlock(&( CH_VPN(ch)->mutex));
pthread_mutex_lock(&(sf_socks_mutex));
pthread_mutex_lock(&(s_sf_socks_mutex));
HASH_DELETE(hh2, sf_socks, cur);
HASH_DELETE(hh_sock, sf_socks_client, cur);
pthread_mutex_unlock(&(sf_socks_mutex));
pthread_mutex_unlock(&(s_sf_socks_mutex));
pthread_mutex_unlock(&(cur->mutex));
stream_sf_socket_delete(cur);
......
......@@ -140,6 +140,6 @@ typedef struct dap_chain_net_srv_vpn
#define CH_VPN(a) ((dap_chain_net_srv_vpn_t *) ((a)->internal) )
int dap_chain_net_srv_vpn_init(dap_config_t * g_config);
void dap_chain_net_srv_vpn_deinit();
void dap_chain_net_srv_vpn_deinit(void);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment