diff options
| author | Qiuwen Lu <[email protected]> | 2017-10-01 13:37:24 +0800 |
|---|---|---|
| committer | Qiuwen Lu <[email protected]> | 2017-10-01 13:37:24 +0800 |
| commit | c9ec0afedeb770148a257c49f87ea1cc09d35e57 (patch) | |
| tree | 5e47bc0b7d6a88f602e56b78d6b749408e903752 /tunnat | |
| parent | 65d0501efd03c95ba2832c87e84f1b6cf03d40d7 (diff) | |
增加Tunnat有上下文发包流程中选最近专用设备的功能;修正Service线程绑定设置。
- 原实现在处理有上下文发包流程中,根据二元组查找session失败时,直接丢弃。现改为选择最近的专用设备session。
- 修正service辅助线程绑定在master线程的Bug。
Diffstat (limited to 'tunnat')
| -rw-r--r-- | tunnat/include/session.h | 3 | ||||
| -rw-r--r-- | tunnat/include/tunnat.h | 4 | ||||
| -rw-r--r-- | tunnat/src/runtime.cc | 19 | ||||
| -rw-r--r-- | tunnat/src/session.cc | 22 |
4 files changed, 43 insertions, 5 deletions
diff --git a/tunnat/include/session.h b/tunnat/include/session.h index 01353d2..1fa47da 100644 --- a/tunnat/include/session.h +++ b/tunnat/include/session.h @@ -35,6 +35,8 @@ class SessionTable public: SessionEntry * Query(SessionKey & key); SessionEntry * QueryDualDirect(SessionKey & key); + SessionEntry * QueryRecent(); + int Add(SessionKey & key, SessionEntry & entry); int Init(unsigned int nr_max_sessions, unsigned int nr_slots, unsigned int expire_time); @@ -43,4 +45,5 @@ protected: static int htable_comp_fun_cb(const uchar * key1, uint size1, const uchar * key2, uint size2); static int htable_free_fun_cb(void *data); static int htable_expire_notify_cb(void *data, int eliminate_type); + static int htable_iterate_recent(const uchar * key, uint size, void * data, void *user); };
\ No newline at end of file diff --git a/tunnat/include/tunnat.h b/tunnat/include/tunnat.h index 5a2fcfd..ff07d43 100644 --- a/tunnat/include/tunnat.h +++ b/tunnat/include/tunnat.h @@ -96,6 +96,7 @@ public: TUNNAT_STAT_SESSION_REMOVE, /* 统计,关键失败事件 */ TUNNAT_STAT_ENCAP_FAIL_NO_SESSION, + TUNNAT_STAT_ENCAP_USE_RECENT_SESSION, /* 最大表项 */ TUNNAT_STAT_MAX }; @@ -159,13 +160,14 @@ public: [TUNNAT_STAT_INNER_PPP_INPUT] = "TUNNAT_STAT_INNER_PPP_INPUT", [TUNNAT_STAT_FORWARD_OUTPUT] = "TUNNAT_STAT_FORWARD_OUTPUT", [TUNNAT_STAT_ENCAP_OUTPUT] ="TUNNAT_STAT_ENCAP_OUTPUT", - [TUNNAT_STAT_DIRECT_OUTPUT] ="TUNNAT_STAT_DROP_OUTPUT", + [TUNNAT_STAT_DIRECT_OUTPUT] ="TUNNAT_STAT_DIRECT_OUTPUT", [TUNNAT_STAT_FORWARD_RAW_OUTPUT] = "TUNNAT_STAT_FORWARD_RAW_OUTPUT", [TUNNAT_STAT_FORWARD_TUNNEL_OUTPUT] = "TUNNAT_STAT_FORWARD_TUNNEL_OUTPUT", [TUNNAT_STAT_NO_SESSION_OUTPUT] = "TUNNAT_STAT_NO_SESSION_OUTPUT", [TUNNAT_STAT_SESSION_ADD] = "TUNNAT_STAT_SESSION_ADD", [TUNNAT_STAT_SESSION_REMOVE] = "TUNNAT_STAT_SESSION_REMOVE", [TUNNAT_STAT_ENCAP_FAIL_NO_SESSION] = "TUNNAT_STAT_ENCAP_FAIL_NO_SESSION", + [TUNNAT_STAT_ENCAP_USE_RECENT_SESSION] = "TUNNAT_STAT_ENCAP_USE_RECENT_SESSION", [TUNNAT_STAT_MAX] = "TUNNAT_STAT_MAX" }; diff --git a/tunnat/src/runtime.cc b/tunnat/src/runtime.cc index 8edc2cf..28672d1 100644 --- a/tunnat/src/runtime.cc +++ b/tunnat/src/runtime.cc @@ -266,12 +266,23 @@ static int __virt_to_phy_pkt_encap(TunnatInstance * instance, TunnatThreadInstan /* 双向查询 */ SessionEntry * ss_entry = th_instance->ss_table->QueryDualDirect(ss_key); - if (ss_entry == NULL) + if (ss_entry != NULL) goto session_realy; + + /* 没有查询到,使用最近的一次隧道数据,随便找到一个专用设备回注 */ + ss_entry = th_instance->ss_table->QueryRecent(); + if (ss_entry != NULL) { - TUNNAT_THREAD_STAT_ADD(TUNNAT_STAT_ENCAP_FAIL_NO_SESSION, 1); - return RT_ERR; + TUNNAT_THREAD_STAT_ADD(TUNNAT_STAT_ENCAP_USE_RECENT_SESSION, 1); + goto session_realy; } - + + /* 还没有查询到,报告失败 */ + TUNNAT_THREAD_STAT_ADD(TUNNAT_STAT_ENCAP_FAIL_NO_SESSION, 1); + return RT_ERR; + +session_realy: + + /* 已经查找到隧道上下文,构建隧道报文 */ TunnelContainerArray & tun_array = ss_entry->tun_array; /* 逆序构建报文隧道,最内层隧道不构建 */ diff --git a/tunnat/src/session.cc b/tunnat/src/session.cc index bcd76ee..4924b72 100644 --- a/tunnat/src/session.cc +++ b/tunnat/src/session.cc @@ -27,6 +27,18 @@ reverse_dir: } return ss_entry; +}
+
+SessionEntry * SessionTable::QueryRecent()
+{ + SessionEntry * ss_entry = NULL; + + /* 查找最近使用的隧道配置 */ + MESA_htable_iterate_bytime(ht_table_, ITERATE_TYPE_NEWEST_FIRST, + htable_iterate_recent, (void *)ss_entry); + + if (ss_entry == NULL) return NULL;
+ return ss_entry;
} int SessionTable::Add(SessionKey & key, SessionEntry & entry) @@ -114,4 +126,14 @@ int SessionTable::htable_free_fun_cb(void * data) int SessionTable::htable_expire_notify_cb(void *data, int eliminate_type) { return 1; +}
+
+int SessionTable::htable_iterate_recent(const uchar * key, uint size, void * data, void * user)
+{ + (void)key; + (void)size; + + SessionEntry ** __entry_ret = (SessionEntry **)user; + *__entry_ret = (SessionEntry *)data;
+ return ITERATE_CB_RET_BREAK_FLAG;
}
\ No newline at end of file |
