summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author崔一鸣 <[email protected]>2018-12-18 18:03:01 +0800
committer崔一鸣 <[email protected]>2018-12-18 21:36:49 +0800
commitbcb8fc0e3eadcb7879e716e6eee00f1381a6deb7 (patch)
tree4202645f1c5bd70694ddb69a119c17d78e229260
parentabaa4322165f523736f9d847d1cffdf438d64968 (diff)
修改dnat代码,方便测试
-rw-r--r--.vscode/ftp-kr.sync.cache.json24
-rw-r--r--README.md11
-rw-r--r--access/src/ip_mgr.cpp34
-rw-r--r--access/src/main.cpp27
-rw-r--r--conf/mgw.conf1
5 files changed, 65 insertions, 32 deletions
diff --git a/.vscode/ftp-kr.sync.cache.json b/.vscode/ftp-kr.sync.cache.json
index e51a704..2330b99 100644
--- a/.vscode/ftp-kr.sync.cache.json
+++ b/.vscode/ftp-kr.sync.cache.json
@@ -24,8 +24,8 @@
},
"mgw.conf": {
"type": "-",
- "size": 2904,
- "lmtime": 1545044207633,
+ "size": 2932,
+ "lmtime": 1545119566656,
"modified": false
},
".mgw.conf.swp": {
@@ -52,7 +52,7 @@
"dnat.cpp": {
"type": "-",
"size": 10637,
- "lmtime": 1545037829816,
+ "lmtime": 1545113098091,
"modified": false
},
"snat.cpp": {
@@ -63,8 +63,8 @@
},
"ip_mgr.cpp": {
"type": "-",
- "size": 35300,
- "lmtime": 1545046217733,
+ "size": 36798,
+ "lmtime": 1545122076494,
"modified": false
},
"vpn_monitor.cpp": {
@@ -93,8 +93,8 @@
},
"main.cpp": {
"type": "-",
- "size": 13756,
- "lmtime": 1544766948983,
+ "size": 14165,
+ "lmtime": 1545122344933,
"modified": false
}
},
@@ -151,8 +151,8 @@
},
"test_maat_redis.cpp": {
"type": "-",
- "size": 4874,
- "lmtime": 1545044351099,
+ "size": 4890,
+ "lmtime": 1545108242866,
"modified": false
},
"test_tun.cpp": {
@@ -219,8 +219,8 @@
},
"README.md": {
"type": "-",
- "size": 26,
- "lmtime": 1540888536383,
+ "size": 3787,
+ "lmtime": 1545052462884,
"modified": false
},
"vendor": {
@@ -338,7 +338,7 @@
".README.md.swp": {
"type": "-",
"size": 4096,
- "lmtime": 1544886363315,
+ "lmtime": 1545052465361,
"modified": false
}
}
diff --git a/README.md b/README.md
index d988e24..a5f2ffd 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,4 @@
-* 简介
- * MGW是Matrix Gate Way的简称,是IP复用接入部分。
+# IP复用文档
* 依赖
* MESA_framework
* .so放在/opt/MESA/lib下
@@ -51,6 +50,7 @@
* 一个{}内有4项,用空格分开, 分别为hub名称,hub密码,hub的dhcp分配的ip范围
* polling_interval: vpn_monitor线程轮询间隔,默认为30s
* [mrl]
+ * default_ip: mrl服务器ip
* port: mrl服务器的端口
* [udp_server]
* ip: 和mrl通信监听的ip,默认为本机ip
@@ -78,4 +78,9 @@
* 解决方法:
* systemctl stop mgw
* journalctl -u mgw.service看下systemd日志
- * sh /opt/mgw/script/systemd/mgw.sh start手动执行脚本看看具体是哪里失败 \ No newline at end of file
+ * sh /opt/mgw/script/systemd/mgw.sh start手动执行脚本看看具体是哪里失败
+ * 包发送给mrl,没有收到回复,最可能的原因是复用的ip没有联网。
+
+
+
+
diff --git a/access/src/ip_mgr.cpp b/access/src/ip_mgr.cpp
index ccad08c..28ef5ec 100644
--- a/access/src/ip_mgr.cpp
+++ b/access/src/ip_mgr.cpp
@@ -17,6 +17,7 @@ struct ip_mgr_handle
MESA_htable_handle dnat_policy_htable; //expire_time: 0
MESA_htable_handle snat_cand_ip_htable; //expire_time: 0
MESA_htable_handle mrl_ip_htable; //expire_time: 0
+ uint32_t default_mrl_ip;
};
struct snat_policy_htable_value
@@ -182,7 +183,9 @@ int ip_mgr_mrl_ip_query(struct ip_mgr_handle *handle, uint32_t back_ip, uint32_t
{
FS_operate(g_fs_handle->handle, g_fs_handle->line_mrl_ip, g_fs_handle->cloumn_cache_miss, FS_OP_ADD, 1);
MGW_LOG_ERROR(logger, "MESA_htable: key not existed, table is %s, back ip is %s", "mrl_ip_htable", back_ip_str);
- return -1;
+ //for test
+ *mrl_ip = handle->default_mrl_ip;
+ return 0;
}
mgw_utils_inet_ntoa(dup_value.mrl_ip, mrl_ip_str);
*mrl_ip = dup_value.mrl_ip;
@@ -300,7 +303,7 @@ static void mrl_ip_htable_data_free_cb(void *data)
static void Maat_snat_policy_start_cb(int update_type, void* args)
{
- printf("call Maat_snat_policy_start_cb, update_type is %d\n", update_type);
+ //printf("call Maat_snat_policy_start_cb, update_type is %d\n", update_type);
struct ip_mgr_handle *handle = (struct ip_mgr_handle *)args;
void *logger = handle->logger;
MGW_LOG_INFO(logger, "Maat_redis: start callback, table is IP_SNAT_POLICY, update_type is %d\n", update_type);
@@ -309,7 +312,7 @@ static void Maat_snat_policy_start_cb(int update_type, void* args)
static void Maat_snat_policy_update_cb(int table_id, const char* table_line, void* args)
{
- printf("call Maat_snat_policy_update_cb, table_line is %s\n", table_line);
+ //printf("call Maat_snat_policy_update_cb, table_line is %s\n", table_line);
struct ip_mgr_handle *handle = (struct ip_mgr_handle *)args;
void *logger = handle->logger;
MGW_LOG_INFO(logger, "Maat_redis: update callback, table is IP_SNAT_POLICY, table line is %s", table_line);
@@ -360,7 +363,7 @@ static void Maat_snat_policy_update_cb(int table_id, const char* table_line, voi
static void Maat_snat_policy_finish_cb(void* args)
{
- printf("call Maat_snat_policy_finish_cb\n");
+ //printf("call Maat_snat_policy_finish_cb\n");
struct ip_mgr_handle *handle = (struct ip_mgr_handle *)args;
void *logger = handle->logger;
MGW_LOG_INFO(logger, "Maat_redis: finish callback, table is SNAT_POLICY");
@@ -380,7 +383,7 @@ static void Maat_snat_policy_finish_cb(void* args)
static void Maat_snat_cand_ip_start_cb(int update_type,void* args)
{
- printf("call Maat_snat_cand_ip_start_cb, update_type is %d\n", update_type);
+ //printf("call Maat_snat_cand_ip_start_cb, update_type is %d\n", update_type);
struct ip_mgr_handle *handle = (struct ip_mgr_handle *)args;
void *logger = handle->logger;
MGW_LOG_INFO(logger, "Maat_redis: start callback, table is IR_CANDIDATE_IP, updata_type is %d\n", update_type);
@@ -503,7 +506,7 @@ static long snat_cand_ip_query_cb_del(void *data, const uchar *key, uint size, v
static void Maat_snat_cand_ip_update_cb(int table_id, const char* table_line, void* args)
{
- printf("call Maat_snat_cand_ip_update_cb, table line is %s\n", table_line);
+ //printf("call Maat_snat_cand_ip_update_cb, table line is %s\n", table_line);
struct ip_mgr_handle *handle = (struct ip_mgr_handle *)args;
void *logger = handle->logger;
MGW_LOG_INFO(logger, "Maat_redis: update callback, table is IR_CANDIDATE_IP, table line is %s", table_line);
@@ -543,7 +546,7 @@ static void Maat_snat_cand_ip_update_cb(int table_id, const char* table_line, vo
static void Maat_snat_cand_ip_finish_cb(void* args)
{
- printf("call Maat_snat_cand_ip_finish_cb\n");
+ //printf("call Maat_snat_cand_ip_finish_cb\n");
struct ip_mgr_handle *handle = (struct ip_mgr_handle *)args;
void *logger = handle->logger;
MGW_LOG_INFO(logger, "Maat_redis: finish callback, table is CAND_IP_TABLE");
@@ -553,7 +556,7 @@ static void Maat_snat_cand_ip_finish_cb(void* args)
static void Maat_dnat_policy_start_cb(int update_type, void* args)
{
- printf("call Maat_dnat_policy_start_cb, update_type is %d\n", update_type);
+ //printf("call Maat_dnat_policy_start_cb, update_type is %d\n", update_type);
struct ip_mgr_handle *handle = (struct ip_mgr_handle *)args;
void *logger = handle->logger;
MGW_LOG_INFO(logger, "Maat_redis: start callback, update_type is %d, table is IP_DNAT_POLICY", update_type);
@@ -562,7 +565,7 @@ static void Maat_dnat_policy_start_cb(int update_type, void* args)
static void Maat_dnat_policy_update_cb(int table_id, const char* table_line, void* args)
{
- printf("call Maat_dnat_policy_update_cb, table line is %s\n", table_line);
+ //printf("call Maat_dnat_policy_update_cb, table line is %s\n", table_line);
struct ip_mgr_handle *handle = (struct ip_mgr_handle *)args;
void *logger = handle->logger;
MGW_LOG_INFO(logger, "Maat_redis: update callback, table is IP_DNAT_POLICY, table line is %s", table_line);
@@ -628,7 +631,7 @@ static void Maat_dnat_policy_update_cb(int table_id, const char* table_line, voi
static void Maat_dnat_policy_finish_cb(void* args)
{
- printf("call Maat_dnat_policy_finish_cb\n");
+ //printf("call Maat_dnat_policy_finish_cb\n");
struct ip_mgr_handle *handle = (struct ip_mgr_handle *)args;
void *logger = handle->logger;
MGW_LOG_INFO(logger, "Maat_redis: finish callback, table is IP_DNAT_POLICY");
@@ -637,7 +640,7 @@ static void Maat_dnat_policy_finish_cb(void* args)
static void Maat_mrl_ip_start_cb(int update_type, void* args)
{
- printf("call Maat_mrl_ip_start_cb, update_type is %d\n", update_type);
+ //printf("call Maat_mrl_ip_start_cb, update_type is %d\n", update_type);
struct ip_mgr_handle *handle = (struct ip_mgr_handle *)args;
void *logger = handle->logger;
MGW_LOG_INFO(logger, "Maat_redis: start callback, table is IP_MRL_IP_INFO, update_type is %d", update_type);
@@ -646,7 +649,7 @@ static void Maat_mrl_ip_start_cb(int update_type, void* args)
static void Maat_mrl_ip_update_cb(int table_id, const char* table_line, void* args)
{
- printf("call Maat_mrl_ip_update_cb, table_line is %s\n", table_line);
+ //printf("call Maat_mrl_ip_update_cb, table_line is %s\n", table_line);
struct ip_mgr_handle *handle = (struct ip_mgr_handle *)args;
void *logger = handle->logger;
MGW_LOG_INFO(logger, "Maat_redis: update callback, table is IP_MRL_IP_INFO, table line is %s", table_line);
@@ -699,7 +702,7 @@ static void Maat_mrl_ip_update_cb(int table_id, const char* table_line, void* ar
static void Maat_mrl_ip_finish_cb(void* args)
{
- printf("call Maat_mrl_ip_finish_cb\n");
+ //printf("call Maat_mrl_ip_finish_cb\n");
struct ip_mgr_handle *handle = (struct ip_mgr_handle *)args;
void *logger = handle->logger;
MGW_LOG_INFO(logger, "Maat_redis: finish callback, table is IP_MRL_IP_INFO");
@@ -787,6 +790,11 @@ static Maat_feather_t Maat_init(const char *profile, const char *section, void
struct ip_mgr_handle *ip_mgr_init(const char *profile, struct field_stat_handle *fs_handle, void *logger)
{
struct ip_mgr_handle *handle = ALLOC(struct ip_mgr_handle, 1);
+ char _default_mrl_ip[MGW_SYMBOL_MAX];
+ char *section = (char *)"mrl";
+ MESA_load_profile_string_def(profile, section, "default_ip", _default_mrl_ip, sizeof(_default_mrl_ip), "192.168.11.242");
+ MGW_LOG_INFO(logger, "MESA_prof_load, [%s]:\n default_ip: %s\n", section, _default_mrl_ip);
+ handle->default_mrl_ip = inet_addr(_default_mrl_ip);
handle->Maat_feather_snat_policy = Maat_init(profile, "Maat_snat_policy", logger);
handle->Maat_feather_dnat_policy = Maat_init(profile, "Maat_dnat_policy", logger);
handle->Maat_feather_snat_cand_ip = Maat_init(profile, "Maat_snat_cand_ip", logger);
diff --git a/access/src/main.cpp b/access/src/main.cpp
index 9545aaf..b0c6dbb 100644
--- a/access/src/main.cpp
+++ b/access/src/main.cpp
@@ -43,9 +43,8 @@ static struct udp_client_handle * udp_client_init(const char *profile, void *log
const char *section = "mrl";
char ip[MGW_SYMBOL_MAX] = "";
uint16_t port;
- MESA_load_profile_string_def(profile, section, "ip", ip, MGW_SYMBOL_MAX, "192.168.10.242");
MESA_load_profile_int_def(profile, section, "port", (int *)&port, 23456);
- MGW_LOG_INFO(logger, "MESA_prof_load, [%s]:\n ip: %s\n port: %d", "mrl", ip, port);
+ MGW_LOG_INFO(logger, "MESA_prof_load, [%s]:\n port: %d", "mrl", port);
int socket_fd = mgw_socket_init();
if(socket_fd < 0)
{
@@ -198,7 +197,7 @@ static struct mgw_handle * mgw_init(char *conf_path)
struct mgw_handle *_mgw_handle = ALLOC(struct mgw_handle, 1);
char *profile = ALLOC(char, MGW_SYMBOL_MAX);
strncpy(profile, conf_path, MGW_SYMBOL_MAX);
- printf("profile is %s\n", profile);
+ //printf("profile is %s\n", profile);
const char *section = "global";
//init srand
@@ -317,10 +316,22 @@ static int send_data_to_mrl(struct udp_client_handle *handle, char *buff, int le
static void mgw_run(struct mgw_handle *handle)
{
//void *logger = handle->logger;
- sleep(10);
struct timespec start_time;
+ /*for test
+ struct timespec start_time1;
+ clock_gettime(CLOCK_MONOTONIC, &start_time1);
+ for test */
while(1)
{
+ /* for test
+ struct timespec end_time;
+ clock_gettime(CLOCK_MONOTONIC, &end_time);
+ long long cost_time;
+ cost_time = end_time.tv_sec - start_time1.tv_sec;
+ printf("cost time is %d\n", cost_time);
+ if(cost_time > 600) break;
+ for test */
+
char buff[MGW_PACKET_MAX];
int len = mgw_tun_read(handle->tun_handle, buff, MGW_PACKET_MAX);
if(len < 0)
@@ -338,12 +349,20 @@ static void mgw_run(struct mgw_handle *handle)
}
if(rtn == MGW_FORWORD)
{
+ //for test
+ int rtn = mgw_tun_write(handle->tun_handle, buff, len);
+ if(rtn < 0 || rtn != len)
+ {
+ continue;
+ }
+ /* normal
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);
diff --git a/conf/mgw.conf b/conf/mgw.conf
index 888cc0e..9f7f67b 100644
--- a/conf/mgw.conf
+++ b/conf/mgw.conf
@@ -46,6 +46,7 @@ hub_list = {hubstandardtest 111111 192.168.30.10 192.168.30.200}
polling_interval = 30
[mrl]
+default_ip = 192.168.11.242
port = 23456
[udp_server]