diff options
Diffstat (limited to 'access/src/main.cpp')
| -rw-r--r-- | access/src/main.cpp | 333 |
1 files changed, 139 insertions, 194 deletions
diff --git a/access/src/main.cpp b/access/src/main.cpp index cfdd20a..46b85a1 100644 --- a/access/src/main.cpp +++ b/access/src/main.cpp @@ -1,11 +1,15 @@ #include "mgw_utils.h" #include "vpn_monitor.h" #include "mgw_tun.h" -#include "nat.h" +#include "snat.h" +#include "dnat.h" #include "ip_mgr.h" #include "mgw_socket.h" #include "udp_server.h" + +//rx : receive from mrl +//tx: transmit to mrl struct udp_client_handle { int socket_fd; @@ -18,81 +22,19 @@ struct mgw_handle { void* logger; char *profile; - Maat_feather_t Maat_feather_cand; - Maat_feather_t Maat_feather_policy; - struct mgw_tun_handle *mgw_tun_handle_s; - struct nat_handle *nat_handle_s; - struct ip_mgr_handle *ip_mgr_handle_s; - struct udp_client_handle *udp_client_handle_s; - MESA_htable_handle cand_ip_detail_htable; + struct mgw_tun_handle *tun_handle; + struct snat_handle *_snat_handle; + struct dnat_handle *_dnat_handle; + struct ip_mgr_handle *_ip_mgr_handle; + struct udp_client_handle *_udp_client_handle; MESA_htable_handle ip2user_htable; - struct field_stat_handle *fs_handle; }; -static void wrapped_Maat_set_feather_opt(void *logger, Maat_feather_t feather, enum MAAT_INIT_OPT type, const void* value, int size) -{ - int rtn = Maat_set_feather_opt(feather, type, value, size); - if(unlikely(rtn < 0)) - { - MGW_LOG_ERROR(logger, "Failed at Maat_set_feather_opt, type is %d, rtn is %d", type, rtn); - exit(EXIT_FAILURE); - } -} - -static Maat_feather_t Maat_init(const char *profile, const char *section, void *logger) -{ - // load conf - char table_info_path[MGW_PATH_MAX]; - int max_thread_num; - char Maat_redis_ip[MGW_SYMBOL_MAX]; - int Maat_redis_port; - int Maat_redis_index; - char stat_file_path[MGW_PATH_MAX]; - MESA_load_profile_string_def(profile, section, "table_info_path", table_info_path, sizeof(table_info_path), "./conf/table_info.conf"); - MESA_load_profile_int_def(profile, section, "max_thread_num", &max_thread_num, 1); - MESA_load_profile_string_def(profile, section, "Maat_redis_ip", Maat_redis_ip, sizeof(Maat_redis_ip), "127.0.0.1"); - MESA_load_profile_int_def(profile, section, "Maat_redis_port", &Maat_redis_port, 6379); - MESA_load_profile_int_def(profile, section, "Maat_redis_index", &Maat_redis_index, 1); - MESA_load_profile_string_def(profile, section, "stat_file_path", stat_file_path, sizeof(stat_file_path), "./log/Maat_stat.log"); - MGW_LOG_INFO(logger, "MESA_prof_load, [%s]:\n table_info_path: %s\n max_thread_num: %d\n Maat_redis_ip: %s\n Maat_redis_port: %d\n Maat_redis_index: %d\n" - "stat_file_path: %s", section, table_info_path, max_thread_num, Maat_redis_ip, Maat_redis_port, Maat_redis_index, stat_file_path); - // init Maat - Maat_feather_t feather = NULL; - feather = Maat_feather(max_thread_num, table_info_path, logger); - if(feather == NULL) - { - MGW_LOG_ERROR(logger, "Failed at Maat_feather"); - exit(EXIT_FAILURE); - } - wrapped_Maat_set_feather_opt(logger, feather, MAAT_OPT_INSTANCE_NAME, "mgw", strlen("mgw")+1); - wrapped_Maat_set_feather_opt(logger, feather, MAAT_OPT_REDIS_IP, Maat_redis_ip, strlen(Maat_redis_ip)+1); - wrapped_Maat_set_feather_opt(logger, feather, MAAT_OPT_REDIS_PORT, &Maat_redis_port, sizeof(Maat_redis_port)); - wrapped_Maat_set_feather_opt(logger, feather, MAAT_OPT_REDIS_INDEX, &Maat_redis_index, sizeof(Maat_redis_index)); - //wrapped_Maat_set_feather_opt(logger, feather, MAAT_OPT_STAT_FILE_PATH, stat_file_path, strlen(stat_file_path)+1); - //wrapped_Maat_set_feather_opt(logger, feather, MAAT_OPT_STAT_ON, NULL, 0); - //wrapped_Maat_set_feather_opt(logger, feather, MAAT_OPT_PERF_ON, NULL, 0); - //wrapped_Maat_set_feather_opt(feather, MAAT_OPT_SCANDIR_INTERVAL_MS,&scan_interval_ms, sizeof(scan_interval_ms)); - //wrapped_Maat_set_feather_opt(feather, MAAT_OPT_EFFECT_INVERVAL_MS, &effective_interval_ms, sizeof(effective_interval_ms)); - //wrapped_Maat_set_feather_opt(feather, MAAT_OPT_SCAN_DETAIL, &scan_detail, sizeof(scan_detail)); - //wrapped_Maat_set_feather_opt(feather, MAAT_OPT_ACCEPT_TAGS, accept_tags, strlen(accept_tags)+1); - int rtn = Maat_initiate_feather(feather); - if(unlikely(rtn < 0)) - { - MGW_LOG_ERROR(logger, "Failed at Maat_initiate_feather"); - exit(EXIT_FAILURE); - } - return feather; -} +static struct field_stat_handle *g_fs_handle = NULL; -static void ip2user_htable_data_free_cb(void *data) +void ip2user_htable_data_free_cb(void *data) { - FREE(&data); -} - -static void cand_ip_detail_htable_data_free_cb(void *data) -{ - struct ip_mgr_cand_ip_detail *cand_ip_detail = (struct ip_mgr_cand_ip_detail *)data; - FREE(&cand_ip_detail->vxlan_info); + FS_operate(g_fs_handle->handle, g_fs_handle->line_ip2user, g_fs_handle->cloumn_element_num, FS_OP_ADD, -1); FREE(&data); } @@ -131,6 +73,9 @@ static struct field_stat_handle * fs_init(const char *profile, void *logger) char buff[128]; int value=0; handle = FS_create_handle(); + struct field_stat_handle *fs_handle= ALLOC(struct field_stat_handle, 1); + fs_handle->handle = handle; + FS_set_para(handle, HISTOGRAM_GLOBAL_BINS, FP_HISTOGRAM_BINS, strlen(FP_HISTOGRAM_BINS)+1); FS_set_para(handle, APP_NAME, app_name, strlen(app_name)+1); @@ -147,105 +92,103 @@ static struct field_stat_handle * fs_init(const char *profile, void *logger) FS_set_para(handle, MAX_STAT_FIELD_NUM, &value, sizeof(value)); //field: packet handle status - snprintf(buff, sizeof(buff),"read_from_tun"); - int field_read_from_tun = FS_register(handle, FS_STYLE_FIELD, FS_CALC_CURRENT, buff); + snprintf(buff, sizeof(buff),"tun_read"); + fs_handle->field_tun_read = FS_register(handle, FS_STYLE_FIELD, FS_CALC_CURRENT, buff); - snprintf(buff, sizeof(buff),"write_to_tun"); - int field_write_to_tun = FS_register(handle, FS_STYLE_FIELD, FS_CALC_CURRENT, buff); + snprintf(buff, sizeof(buff),"tun_bypass"); + fs_handle->field_tun_bypass = FS_register(handle, FS_STYLE_FIELD, FS_CALC_CURRENT, buff); + + snprintf(buff, sizeof(buff),"tun_write"); + fs_handle->field_tun_write = FS_register(handle, FS_STYLE_FIELD, FS_CALC_CURRENT, buff); - snprintf(buff, sizeof(buff),"recv_from_mrl"); - int field_recv_from_mrl = FS_register(handle, FS_STYLE_FIELD, FS_CALC_CURRENT, buff); + snprintf(buff, sizeof(buff),"rx_from_mrl"); + fs_handle->field_rx_from_mrl = FS_register(handle, FS_STYLE_FIELD, FS_CALC_CURRENT, buff); - snprintf(buff, sizeof(buff),"send_to_mrl"); - int field_send_to_mrl = FS_register(handle, FS_STYLE_FIELD, FS_CALC_CURRENT, buff); + snprintf(buff, sizeof(buff),"tx_to_mrl"); + fs_handle->field_tx_to_mrl = FS_register(handle, FS_STYLE_FIELD, FS_CALC_CURRENT, buff); - snprintf(buff,sizeof(buff),"snat_succ_rate"); + snprintf(buff,sizeof(buff),"rx_succ_rate"); FS_register_ratio(handle, - field_send_to_mrl, - field_read_from_tun, + fs_handle->field_rx_from_mrl, + fs_handle->field_tun_write, 1, FS_STYLE_FIELD, FS_CALC_CURRENT, buff); - - snprintf(buff,sizeof(buff),"dnat_succ_rate"); + + snprintf(buff,sizeof(buff),"tx_succ_rate"); FS_register_ratio(handle, - field_write_to_tun, - field_recv_from_mrl, + fs_handle->field_tun_read, + fs_handle->field_tx_to_mrl, 1, FS_STYLE_FIELD, FS_CALC_CURRENT, buff); + //column: cache hit/miss, line htable - snprintf(buff,sizeof(buff),"snat"); - int line_snat = FS_register(handle, FS_STYLE_LINE, FS_CALC_CURRENT, buff); + snprintf(buff,sizeof(buff),"snat_rx"); + fs_handle->line_snat_rx = FS_register(handle, FS_STYLE_LINE, FS_CALC_CURRENT, buff); - snprintf(buff,sizeof(buff),"dnat"); - int line_dnat = FS_register(handle, FS_STYLE_LINE, FS_CALC_CURRENT, buff); + snprintf(buff,sizeof(buff),"snat_tx"); + fs_handle->line_snat_tx = FS_register(handle, FS_STYLE_LINE, FS_CALC_CURRENT, buff); + + snprintf(buff,sizeof(buff),"dnat_rx"); + fs_handle->line_dnat_rx = FS_register(handle, FS_STYLE_LINE, FS_CALC_CURRENT, buff); + + snprintf(buff,sizeof(buff),"dnat_tx"); + fs_handle->line_dnat_tx = FS_register(handle, FS_STYLE_LINE, FS_CALC_CURRENT, buff); snprintf(buff,sizeof(buff),"ip2user"); - int line_ip2user = FS_register(handle, FS_STYLE_LINE, FS_CALC_CURRENT, buff); + fs_handle->line_ip2user = FS_register(handle, FS_STYLE_LINE, FS_CALC_CURRENT, buff); + + snprintf(buff,sizeof(buff),"snat_policy"); + fs_handle->line_snat_policy = FS_register(handle, FS_STYLE_LINE, FS_CALC_CURRENT, buff); - snprintf(buff,sizeof(buff),"user_policy"); - int line_user_policy = FS_register(handle, FS_STYLE_LINE, FS_CALC_CURRENT, buff); + snprintf(buff,sizeof(buff),"dnat_policy"); + fs_handle->line_dnat_policy = FS_register(handle, FS_STYLE_LINE, FS_CALC_CURRENT, buff); - snprintf(buff,sizeof(buff),"ip_group"); - int line_ip_group = FS_register(handle, FS_STYLE_LINE, FS_CALC_CURRENT, buff); + snprintf(buff,sizeof(buff),"snat_cand_ip"); + fs_handle->line_snat_cand_ip = FS_register(handle, FS_STYLE_LINE, FS_CALC_CURRENT, buff); - snprintf(buff,sizeof(buff),"ip_detail"); - int line_ip_detail = FS_register(handle, FS_STYLE_LINE, FS_CALC_CURRENT, buff); + snprintf(buff,sizeof(buff),"mrl_ip"); + fs_handle->line_mrl_ip = FS_register(handle, FS_STYLE_LINE, FS_CALC_CURRENT, buff); snprintf(buff,sizeof(buff),"query_num"); - int cloumn_queyr_num = FS_register(handle, FS_STYLE_COLUMN, FS_CALC_CURRENT, buff); + fs_handle->cloumn_query_num = FS_register(handle, FS_STYLE_COLUMN, FS_CALC_CURRENT, buff); snprintf(buff,sizeof(buff),"element_num"); - int cloumn_element_num = FS_register(handle, FS_STYLE_COLUMN, FS_CALC_CURRENT, buff); + fs_handle->cloumn_element_num = FS_register(handle, FS_STYLE_COLUMN, FS_CALC_CURRENT, buff); snprintf(buff,sizeof(buff),"cache_miss"); - int cloumn_cache_miss = FS_register(handle, FS_STYLE_COLUMN, FS_CALC_CURRENT, buff); + fs_handle->cloumn_cache_miss = FS_register(handle, FS_STYLE_COLUMN, FS_CALC_CURRENT, buff); snprintf(buff,sizeof(buff),"cache_hit"); - int cloumn_cache_hit = FS_register(handle, FS_STYLE_COLUMN, FS_CALC_CURRENT, buff); + fs_handle->cloumn_cache_hit = FS_register(handle, FS_STYLE_COLUMN, FS_CALC_CURRENT, buff); snprintf(buff,sizeof(buff),"cache_hit_rate"); FS_register_ratio(handle, - cloumn_cache_hit, - cloumn_queyr_num, + fs_handle->cloumn_cache_hit, + fs_handle->cloumn_query_num, 1, FS_STYLE_COLUMN, FS_CALC_CURRENT, buff); //snat/dnat latency - snprintf(buff,sizeof(buff), "snat(us)"); - int snat_latency = FS_register_histogram(handle, FS_CALC_CURRENT, buff, 1, 30*1000, 3); + snprintf(buff,sizeof(buff), "snat_rx(us)"); + fs_handle->snat_rx_latency = FS_register_histogram(handle, FS_CALC_CURRENT, buff, 1, 30*1000, 3); - snprintf(buff,sizeof(buff), "dnat(us)"); - int dnat_latency = FS_register_histogram(handle, FS_CALC_CURRENT, buff, 1, 30*1000, 3); + snprintf(buff,sizeof(buff), "snat_tx(us)"); + fs_handle->snat_tx_latency = FS_register_histogram(handle, FS_CALC_CURRENT, buff, 1, 30*1000, 3); + + snprintf(buff,sizeof(buff), "dnat_rx(us)"); + fs_handle->dnat_rx_latency = FS_register_histogram(handle, FS_CALC_CURRENT, buff, 1, 30*1000, 3); + + snprintf(buff,sizeof(buff), "dnat_tx(us)"); + fs_handle->dnat_tx_latency = FS_register_histogram(handle, FS_CALC_CURRENT, buff, 1, 30*1000, 3); FS_start(handle); - struct field_stat_handle *fs_handle= ALLOC(struct field_stat_handle, 1); - fs_handle->handle = handle; - //field - fs_handle->field_read_from_tun = field_read_from_tun; - fs_handle->field_write_to_tun = field_write_to_tun; - fs_handle->field_recv_from_mrl = field_recv_from_mrl; - fs_handle->field_send_to_mrl = field_send_to_mrl; - //cloumn and line - fs_handle->cloumn_cache_hit = cloumn_cache_hit; - fs_handle->cloumn_cache_miss = cloumn_cache_miss; - fs_handle->cloumn_element_num = cloumn_element_num; - fs_handle->cloumn_queyr_num = cloumn_queyr_num; - fs_handle->line_snat = line_snat; - fs_handle->line_dnat = line_dnat; - fs_handle->line_ip2user = line_ip2user; - fs_handle->line_user_policy = line_user_policy; - fs_handle->line_ip_group = line_ip_group; - fs_handle->line_ip_detail = line_ip_detail; - //snat/dnat latency - fs_handle->snat_latency = snat_latency; - fs_handle->dnat_latency = dnat_latency; return fs_handle; } @@ -278,35 +221,21 @@ static struct mgw_handle * mgw_init(char *conf_path) //init feild_stat struct field_stat_handle *fs_handle = fs_init(profile, logger); - _mgw_handle->fs_handle = fs_handle; - - //init Maat - Maat_feather_t Maat_feather_cand = Maat_init((const char *)profile, "Maat_cand", logger); - Maat_feather_t Maat_feather_policy = Maat_init((const char *)profile, "Maat_policy", logger); - _mgw_handle->Maat_feather_cand = Maat_feather_cand; - _mgw_handle->Maat_feather_policy = Maat_feather_policy; + g_fs_handle = fs_handle; //init tun - _mgw_handle->mgw_tun_handle_s = mgw_tun_init("tun_mgw", logger); + _mgw_handle->tun_handle = mgw_tun_init("tun_mgw", logger); //init ip_mgr - MESA_htable_handle cand_ip_detail_htable = mgw_utils_create_htable(profile, "cand_ip_detail_htable", (void *)cand_ip_detail_htable_data_free_cb, NULL, logger); - if(cand_ip_detail_htable == NULL) - { - MGW_LOG_ERROR(logger, "Failed at create cand_ip_detail_htable"); - exit(EXIT_FAILURE); - } - _mgw_handle->cand_ip_detail_htable = cand_ip_detail_htable; - struct ip_mgr_handle * _ip_mgr_handle = ip_mgr_init(profile, cand_ip_detail_htable, fs_handle, Maat_feather_cand, Maat_feather_policy, logger); + struct ip_mgr_handle * _ip_mgr_handle = ip_mgr_init(profile, fs_handle, logger); if(unlikely(_ip_mgr_handle == NULL)) { MGW_LOG_ERROR(logger, "Failed at init_ip_mgr"); exit(EXIT_FAILURE); } - _mgw_handle->ip_mgr_handle_s = _ip_mgr_handle; - + _mgw_handle->_ip_mgr_handle = _ip_mgr_handle; - //init nat + //init snat MESA_htable_handle ip2user_htable = mgw_utils_create_htable(profile, "ip2user_htable", (void *)ip2user_htable_data_free_cb, NULL, logger); if(ip2user_htable == NULL) { @@ -314,8 +243,10 @@ static struct mgw_handle * mgw_init(char *conf_path) exit(EXIT_FAILURE); } _mgw_handle->ip2user_htable = ip2user_htable; - _mgw_handle->nat_handle_s = nat_init(profile, ip2user_htable, cand_ip_detail_htable, fs_handle, logger); + _mgw_handle->_snat_handle = snat_init(profile, ip2user_htable, _ip_mgr_handle, fs_handle, logger); + //init_dnat + _mgw_handle->_dnat_handle = dnat_init(profile, _ip_mgr_handle, fs_handle, logger); //create thread_vpn_monitor pthread_t thread_id; @@ -335,8 +266,9 @@ static struct mgw_handle * mgw_init(char *conf_path) struct udp_server_args *_udp_server_args = ALLOC(struct udp_server_args, 1); _udp_server_args->logger = logger; _udp_server_args->profile = profile; - _udp_server_args->_nat_handle = _mgw_handle->nat_handle_s; - _udp_server_args->tun_handle = _mgw_handle->mgw_tun_handle_s; + _udp_server_args->_snat_handle = _mgw_handle->_snat_handle; + _udp_server_args->_dnat_handle = _mgw_handle->_dnat_handle; + _udp_server_args->tun_handle = _mgw_handle->tun_handle; _udp_server_args->fs_handle = fs_handle; rtn = pthread_create(&thread_id, NULL, thread_udp_server, (void *)_udp_server_args); if(unlikely(rtn != 0)) @@ -347,7 +279,7 @@ static struct mgw_handle * mgw_init(char *conf_path) //init udp client socket struct udp_client_handle *_udp_client_handle = udp_client_init(profile, logger); - _mgw_handle->udp_client_handle_s = _udp_client_handle; + _mgw_handle->_udp_client_handle = _udp_client_handle; return _mgw_handle; } @@ -356,75 +288,88 @@ static void mgw_destroy(struct mgw_handle *handle) { MESA_destroy_runtime_log_handle(handle->logger); FREE(&handle->profile); - Maat_burn_feather(handle->Maat_feather_cand); - Maat_burn_feather(handle->Maat_feather_policy); - MESA_htable_destroy(handle->cand_ip_detail_htable, NULL); MESA_htable_destroy(handle->ip2user_htable, NULL); - mgw_tun_destroy(handle->mgw_tun_handle_s); - nat_destroy(handle->nat_handle_s); - ip_mgr_destroy(handle->ip_mgr_handle_s); - FREE(&handle->udp_client_handle_s); - FS_stop(&handle->fs_handle->handle); - FREE(&handle->fs_handle); + mgw_tun_destroy(handle->tun_handle); + snat_destroy(handle->_snat_handle); + dnat_destroy(handle->_dnat_handle); + ip_mgr_destroy(handle->_ip_mgr_handle); + FREE(&handle->_udp_client_handle); + FS_stop(&(g_fs_handle->handle)); + FREE(&g_fs_handle); FREE(&handle); } -static int send_data_to_mrl(struct udp_client_handle *handle, char *buff, int len, MESA_htable_handle cand_ip_detail_htable, - struct ip_mgr_vxlan_info *vxlan_info, uint32_t mrl_ip) +static int send_data_to_mrl(struct udp_client_handle *handle, char *buff, int len, uint32_t mrl_ip) { void *logger = handle->logger; int socket_fd = handle->socket_fd; - char _buff[MGW_PACKET_MAX]; - memcpy(_buff, vxlan_info, sizeof(struct ip_mgr_vxlan_info)); - memcpy(_buff + sizeof(struct ip_mgr_vxlan_info), buff, len); - len += sizeof(struct ip_mgr_vxlan_info); uint16_t dport = htons(handle->dport); - int rtn = mgw_socket_udp_send(socket_fd, _buff, len, mrl_ip, dport); - if (rtn < 0) + int rtn = mgw_socket_udp_send(socket_fd, buff, len, mrl_ip, dport); + if (rtn < 0 || rtn != len) { MGW_LOG_ERROR(logger, "mgw_socket: Failed at send udp data, errno is %d, %s", errno, strerror(errno)); + return rtn; } + MGW_LOG_INFO(logger, "mgw_socket: Succeed at send udp data, send len is %d", rtn); return rtn; } static void mgw_run(struct mgw_handle *handle) { - void *logger = handle->logger; + //void *logger = handle->logger; sleep(10); - struct timespec start_time, end_time; - struct field_stat_handle *fs_handle = handle->fs_handle; - //for test - //struct timespec _start_time; - //clock_gettime(CLOCK_MONOTONIC, &_start_time); - - + struct timespec start_time; while(1) { - clock_gettime(CLOCK_MONOTONIC, &start_time); char buff[MGW_PACKET_MAX]; - int len = mgw_tun_read(handle->mgw_tun_handle_s, buff, MGW_PACKET_MAX); - FS_operate(fs_handle->handle, fs_handle->field_read_from_tun, 0, FS_OP_ADD, 1); - struct ip_mgr_vxlan_info *vxlan_info = NULL; + int len = mgw_tun_read(handle->tun_handle, buff, MGW_PACKET_MAX); + if(len < 0) + { + continue; + } + FS_operate(g_fs_handle->handle, g_fs_handle->field_tun_read, 0, FS_OP_ADD, 1); uint32_t mrl_ip; - int rtn = nat_src_convert(handle->nat_handle_s, handle->ip_mgr_handle_s, buff, len, &vxlan_info, &mrl_ip); - if(rtn == NAT_COVERT_FAILURE) + clock_gettime(CLOCK_MONOTONIC, &start_time); + int rtn = dnat_tx_convert(handle->_dnat_handle, buff, len, &mrl_ip); + mgw_utils_fs_latency_cala(g_fs_handle->handle, start_time, g_fs_handle->dnat_tx_latency); + if(rtn == MGW_DROP) + { + continue; + } + if(rtn == MGW_FORWORD) + { + int rtn = send_data_to_mrl(handle->_udp_client_handle, buff, len, mrl_ip); + if(rtn > 0 && rtn == len) + { + FS_operate(g_fs_handle->handle, g_fs_handle->field_tx_to_mrl, 0, FS_OP_ADD, 1); + } + continue; + } + // rtn=MGW_BYPASS, do sant_src_convert + clock_gettime(CLOCK_MONOTONIC, &start_time); + rtn = snat_tx_convert(handle->_snat_handle, buff, len, &mrl_ip); + mgw_utils_fs_latency_cala(g_fs_handle->handle, start_time, g_fs_handle->snat_tx_latency); + if(rtn == MGW_DROP) { - MGW_LOG_ERROR(logger, "Failed at nat_src_convert"); continue; } - int send_len = send_data_to_mrl(handle->udp_client_handle_s, buff, len, handle->cand_ip_detail_htable, vxlan_info, mrl_ip); - if(send_len > 0) + if(rtn == MGW_FORWORD) { - FS_operate(fs_handle->handle, fs_handle->field_send_to_mrl, 0, FS_OP_ADD, 1); + int rtn = send_data_to_mrl(handle->_udp_client_handle, buff, len, mrl_ip); + if(rtn > 0 && rtn == len) + { + FS_operate(g_fs_handle->handle, g_fs_handle->field_tx_to_mrl, 0, FS_OP_ADD, 1); + } + continue; + } + // rtn=MGW_BYPASS, write to tun + rtn = mgw_tun_write(handle->tun_handle, buff, len); + if(rtn < 0 || rtn != len) + { + continue; } - clock_gettime(CLOCK_MONOTONIC, &end_time); - long long cost_time; - cost_time = (end_time.tv_sec - start_time.tv_sec) * 1000000 + (end_time.tv_nsec - start_time.tv_nsec) / 1000; - FS_operate(fs_handle->handle, fs_handle->snat_latency, 0, FS_OP_SET, cost_time); - - //for test - //if(end_time.tv_sec - _start_time.tv_sec > 60) - //break; + FS_operate(g_fs_handle->handle, g_fs_handle->field_tun_bypass, 0, FS_OP_ADD, 1); + FS_operate(g_fs_handle->handle, g_fs_handle->field_tun_read, 0, FS_OP_ADD, -1); } } |
