diff options
| author | Qiuwen Lu <[email protected]> | 2017-07-28 13:59:20 +0800 |
|---|---|---|
| committer | Qiuwen Lu <[email protected]> | 2017-07-28 13:59:20 +0800 |
| commit | 1ad077a3908be8df837bc2fdbc3d626c22d2131c (patch) | |
| tree | 1d0a344ebc7c2db76993705c8f43d89ae61c27f9 /tunnat | |
| parent | 4df1cfce8fa65b6a48026634eb32951a8b5b4f3d (diff) | |
合并中心测试发现的问题,主要包括VXLAN主动发包格式错误等。
- 修正主动发包时,创建Tunnel Object类型错误的问题。原实现错误地将TunVxLan类型写为Tunnel类型,导致报文构建时执行了基类的虚函数。
- 修正主动发包时,TunVxlan构建报文虚函数中若干字段填写错误的问题,主要包括MAC地址、IP地址颠倒,vlan_id填写错误等问题。
- 增加内存泄露监测测试程序,以测试在内存泄露场景下主进程是否能及时检测并退出程序。
Diffstat (limited to 'tunnat')
| -rw-r--r-- | tunnat/src/runtime.cc | 16 | ||||
| -rw-r--r-- | tunnat/src/tunnel.cc | 24 |
2 files changed, 22 insertions, 18 deletions
diff --git a/tunnat/src/runtime.cc b/tunnat/src/runtime.cc index b4a0d7e..ab4e6f7 100644 --- a/tunnat/src/runtime.cc +++ b/tunnat/src/runtime.cc @@ -295,7 +295,7 @@ static int __virt_to_phy_pkt_no_session(TunnatInstance * instance, TunnatThreadI /* 对于内层是以太报文的 */ if (ctrlzone->g_device_inner_encap_type == TUNNEL_TYPE_ETHER) { - Tunnel OuterVXLAN; + TunVxlan OuterVXLAN; int ret = OuterVXLAN.CtrlZoneParse(ctrlzone); if (ret < 0) return RT_ERR; @@ -343,22 +343,22 @@ static void __virt_to_phy_one_device(TunnatInstance * instance, TunnatThreadInst unsigned int nr_drop_bufs = 0; for (int i = 0; i < nr_mbufs; i++) - { - if (__virt_to_phy_pkt_forward(instance, th_instance, mbufs[i]) == RT_SUCCESS) + { + if (__virt_to_phy_pkt_no_session(instance, th_instance, mbufs[i]) == RT_SUCCESS) { - fwd_mbufs[nr_fwd_mbufs++] = mbufs[i]; + no_session_bufs[nr_no_session_bufs++] = mbufs[i]; continue; } - if (__virt_to_phy_pkt_encap(instance, th_instance, mbufs[i]) == RT_SUCCESS) + if (__virt_to_phy_pkt_forward(instance, th_instance, mbufs[i]) == RT_SUCCESS) { - encap_bufs[nr_encap_bufs++] = mbufs[i]; + fwd_mbufs[nr_fwd_mbufs++] = mbufs[i]; continue; } - if (__virt_to_phy_pkt_no_session(instance, th_instance, mbufs[i]) == RT_SUCCESS) + if (__virt_to_phy_pkt_encap(instance, th_instance, mbufs[i]) == RT_SUCCESS) { - no_session_bufs[nr_no_session_bufs++] = mbufs[i]; + encap_bufs[nr_encap_bufs++] = mbufs[i]; continue; } diff --git a/tunnat/src/tunnel.cc b/tunnat/src/tunnel.cc index da3d22f..a4336f6 100644 --- a/tunnat/src/tunnel.cc +++ b/tunnat/src/tunnel.cc @@ -76,15 +76,17 @@ int TunVxlan::PacketParse(const char * pkt, unsigned int pkt_len) } #define __IP_VERSION_IHL(version, len) (version << 4 | len << 0) -#define __IP_TTL 64
-
-int TunVxlan::CtrlZoneParse(struct mr_tunnat_ctrlzone * ctrlzone)
+#define __IP_TTL 64 + +int TunVxlan::CtrlZoneParse(struct mr_tunnat_ctrlzone * ctrlzone) { /* 以太头填充,暂时不考虑VLAN的情况 */ + /* 反向填写,后面构建报文时会颠倒过来 */ + ether_addr_copy((const struct ether_addr *)&ctrlzone->g_device_mac, - ðer_hdr_.d_addr); - ether_addr_copy((const struct ether_addr *)&ctrlzone->l_device_mac, ðer_hdr_.s_addr); + ether_addr_copy((const struct ether_addr *)&ctrlzone->l_device_mac, + ðer_hdr_.d_addr); ether_hdr_.ether_type = htons(ETHER_TYPE_IPv4); /* IP头部填充 */ @@ -94,8 +96,8 @@ int TunVxlan::CtrlZoneParse(struct mr_tunnat_ctrlzone * ctrlzone) ipv4_hdr_.packet_id = 0; ipv4_hdr_.fragment_offset = 0; ipv4_hdr_.time_to_live = __IP_TTL; - ipv4_hdr_.dst_addr = ctrlzone->g_device_in_addr; - ipv4_hdr_.src_addr = ctrlzone->l_device_in_addr; + ipv4_hdr_.src_addr = ctrlzone->g_device_in_addr; + ipv4_hdr_.dst_addr = ctrlzone->l_device_in_addr; ipv4_hdr_.next_proto_id = IPPROTO_UDP; /* UDP头部填充 */ @@ -104,9 +106,11 @@ int TunVxlan::CtrlZoneParse(struct mr_tunnat_ctrlzone * ctrlzone) udp_hdr_.dgram_cksum = 0; /* VXLAN头部 */ + vxlan_hdr_.flags = 0x8; vxlan_hdr_.dir = ctrlzone->route_dir; vxlan_hdr_.link_id = ctrlzone->g_device_linkpair; - vxlan_hdr_.vlan_id_half_low = ctrlzone->g_device_vpn_id; + vxlan_hdr_.vlan_id_half_high = ((ctrlzone->g_device_vpn_id & 0x0ff0) >> 4) & 0xff; + vxlan_hdr_.vlan_id_half_low = ctrlzone->g_device_vpn_id & 0xf; /* 内层封装形式 */ switch (ctrlzone->g_device_inner_encap_type) @@ -129,8 +133,8 @@ int TunVxlan::CtrlZoneParse(struct mr_tunnat_ctrlzone * ctrlzone) this->this_layer_length = sizeof(struct ether_hdr) + sizeof(struct ipv4_hdr) + sizeof(struct udp_hdr) + sizeof(struct g_vxlan_hdr); -
- return 0;
+ + return 0; } int TunVxlan::PacketConstruct(const char * pkt, unsigned int pkt_len) |
