diff options
| author | Qiuwen Lu <[email protected]> | 2019-06-17 20:18:12 +0800 |
|---|---|---|
| committer | Qiuwen Lu <[email protected]> | 2019-06-17 20:18:12 +0800 |
| commit | 497aaf59a1de41b91d83f6d8c8e5d1dca3ac8c39 (patch) | |
| tree | d4bb97aa2c5f68d5d5aee27289eee706cbbbb5b3 /tunnat | |
| parent | 5a229e06149ec056162bd5ed0cd5e3cfe238e8a3 (diff) | |
增加基于VLAN Offload实现的VlanFlipping接入方式v4.3.11-20190711v4.3.10-20190622
Diffstat (limited to 'tunnat')
| -rw-r--r-- | tunnat/include/tunnat.h | 13 | ||||
| -rw-r--r-- | tunnat/include/tunnel.h | 37 | ||||
| -rw-r--r-- | tunnat/src/core.cc | 41 | ||||
| -rw-r--r-- | tunnat/src/runtime.cc | 8 | ||||
| -rw-r--r-- | tunnat/src/tunnel.cc | 158 |
5 files changed, 204 insertions, 53 deletions
diff --git a/tunnat/include/tunnat.h b/tunnat/include/tunnat.h index 6d43514..e893841 100644 --- a/tunnat/include/tunnat.h +++ b/tunnat/include/tunnat.h @@ -108,8 +108,10 @@ struct TunnatInstance /* 桥接模式 */ enum bridge_mode bridge_mode; - /* 单臂桥接VLAN映射表 */ - std::map<uint16_t, uint16_t> one_arm_bridge_vlan_map; + + /* VLAN Fliping 映射表 */ + bool en_vlan_flipping{false}; + uint16_t vlan_fliping_map[ETHER_MAX_VLAN_ID + 1]{0}; /* 线程运行句柄 */ TunnatThreadInstance * thread_instances[MR_SID_MAX]; @@ -143,6 +145,7 @@ public: /* 统计,原始报文输入类型 */ TUNNAT_STAT_VXLAN_INPUT, TUNNAT_STAT_QMAC_INPUT, + TUNNAT_STAT_VLAN_FLIPING_INPUT, TUNNAT_STAT_BFD_INPUT, TUNNAT_STAT_INNER_ETHER_INPUT, TUNNAT_STAT_INNER_HDLC_INPUT, @@ -162,6 +165,9 @@ public: TUNNAT_STAT_ENCAP_FAIL_NO_SESSION, TUNNAT_STAT_ENCAP_USE_RECENT_SESSION, TUNNAT_STAT_VIRTUAL_LINK_ID_NO_SESSION, + /* VLAN Fliping没有映射 */ + TUNNAT_STAT_VLAN_FLIPING_NO_FLIP_MAP, + TUNNAT_STAT_VLAN_FLIPING_INVALID_VLAN_ID, /* 最大表项 */ TUNNAT_STAT_MAX }; @@ -220,6 +226,7 @@ public: [TUNNAT_STAT_PKT_RAW_INPUT] = "TUNNAT_STAT_PKT_RAW_INPUT", [TUNNAT_STAT_VXLAN_INPUT] = "TUNNAT_STAT_VXLAN_INPUT", [TUNNAT_STAT_QMAC_INPUT] = "TUNNAT_STAT_QMAC_INPUT", + [TUNNAT_STAT_VLAN_FLIPING_INPUT] = "TUNNAT_STAT_VLAN_FLIPING_INPUT", [TUNNAT_STAT_BFD_INPUT] = "TUNNAT_STAT_BFD_INPUT", [TUNNAT_STAT_INNER_ETHER_INPUT] = "TUNNAT_STAT_INNER_ETHER_INPUT", [TUNNAT_STAT_INNER_HDLC_INPUT] = "TUNNAT_STAT_INNER_HDLC_INPUT", @@ -236,6 +243,8 @@ public: [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_VIRTUAL_LINK_ID_NO_SESSION] = "TUNNAT_STAT_VIRTUAL_LINK_ID_NO_SESSION", + [TUNNAT_STAT_VLAN_FLIPING_NO_FLIP_MAP] = "TUNNAT_STAT_VLAN_FLIPING_NO_FLIP_MAP", + [TUNNAT_STAT_VLAN_FLIPING_INVALID_VLAN_ID] = "TUNNAT_STAT_VLAN_FLIPING_INVALID_VLAN_ID", [TUNNAT_STAT_MAX] = "TUNNAT_STAT_MAX" }; diff --git a/tunnat/include/tunnel.h b/tunnat/include/tunnel.h index 9f1ee01..359a1c0 100644 --- a/tunnat/include/tunnel.h +++ b/tunnat/include/tunnel.h @@ -57,9 +57,10 @@ struct AddressInfo enum tunnel_type { TUNNEL_TYPE_UNKNOWN, + TUNNEL_TYPE_END, TUNNEL_TYPE_G_VXLAN, TUNNEL_TYPE_G_MAC_IN_MAC, - TUNNEL_TYPE_VLAN_BRIDGE, + TUNNEL_TYPE_VLAN_FLIPPING, TUNNEL_TYPE_ETHER, TUNNEL_TYPE_PPP, TUNNEL_TYPE_HDLC, @@ -109,6 +110,8 @@ public: return RT_ERR; } + virtual void MbufMetaPreParse(marsio_buff_t * mbuf) {} + virtual void MbufMetaConstruct(marsio_buff_t * mbuf) {} virtual void ReverseAddress() {} virtual int GetAddressInfo(struct AddressInfo & addr_info) { return RT_ERR; } virtual size_t ToHashKey(char * out_hashkey, size_t sz_hash_key) const { assert(0); return 0; } @@ -119,6 +122,12 @@ public: assert(0); return RT_ERR; } + + static int MbufMetaForwardModify(marsio_buff_t * mbuf) + { + assert(0); + return RT_ERR; + } }; @@ -135,7 +144,7 @@ protected: private: static unsigned int __to_vpn_id(const struct g_vxlan_hdr & vxlan_hdr) { - return (unsigned int)((vxlan_hdr.vlan_id_half_low & 0xf) | (vxlan_hdr.vlan_id_half_high & 0xff) << 4); + return (unsigned int)((vxlan_hdr.vlan_id_half_low & 0xfU) | (vxlan_hdr.vlan_id_half_high & 0xffU) << 4); } public: @@ -168,23 +177,32 @@ public: class TunQMac : public Tunnel {}; -class TunVlanBridge : public Tunnel +class TunVlanFlipping : public Tunnel { public: tunnel_type NextTunType() override { return TUNNEL_TYPE_ETHER; } - tunnel_type ThisTunType() override { return TUNNEL_TYPE_VLAN_BRIDGE; } + tunnel_type ThisTunType() override { return TUNNEL_TYPE_VLAN_FLIPPING; } unsigned int ThisTunLength() override { return 0; } int PacketParse(const char * pkt, unsigned int pkt_len) override; int PacketConstruct(const char * pkt, unsigned int pkt_len) override; + + void MbufMetaPreParse(marsio_buff_t * mbuf) override; + void MbufMetaConstruct(marsio_buff_t * mbuf) override; + size_t ToHashKey(char * out_hashkey, size_t sz_hash_key) const override { return 0; } cJSON * ToJSON() const override { return nullptr; } public: static int PacketForwardModify(const char * pkt, unsigned int pkt_len); + static int MbufMetaForwardModify(marsio_buff_t * mbuf); private: unsigned int vlan_id_; + unsigned int vlan_id_map_; + + bool vlan_id_offload_by_nic_{false}; + static uint16_t vlan_flipping_map_lookup(uint16_t le_vlan_id); }; class TunInnerEther : public Tunnel @@ -294,7 +312,11 @@ public: int PacketParse(const char * pkt, unsigned int pkt_len, enum tunnel_type tunnel_type = TUNNEL_TYPE_UNKNOWN); + void MbufMetaPreParse(marsio_buff_t * mbuf, + enum tunnel_type tunnel_type = TUNNEL_TYPE_UNKNOWN); + int PacketConstruct(const char * pkt, unsigned int pkt_len); + void MbufMetaConstruct(marsio_buff_t * mbuf); int GetAddressInfo(struct AddressInfo & addr_info); @@ -303,10 +325,12 @@ public: static int PacketForwardModify(const char * pkt, unsigned int pkt_len, enum tunnel_type tun_type); + static int MbufMetaForwardModify(marsio_buff_t * mbuf, enum tunnel_type tun_type); + protected: TunVxlan tun_vxlan_object_; TunQMac tun_qmac_object_; - TunVlanBridge tun_vlan_bridge_object_; + TunVlanFlipping tun_vlan_bridge_object_; TunInnerEther tun_inner_ether_; TunInnerHDLC tun_inner_hdlc_; TunInnerPPP tun_inner_ppp_; @@ -364,6 +388,7 @@ private: #define MR_TUNNAT_LAYER_MAX 4 using tunnat_link_id_t = uint64_t; + struct TunnelContainerArray { std::array<TunnelContainer, MR_TUNNAT_LAYER_MAX> tun_array; @@ -434,4 +459,4 @@ struct TunnelContainerArray cJSON_AddItemToObject(j_object, "tunnel", j_object_array); return j_object; } -};
\ No newline at end of file +}; diff --git a/tunnat/src/core.cc b/tunnat/src/core.cc index 9de6b91..3c2e97b 100644 --- a/tunnat/src/core.cc +++ b/tunnat/src/core.cc @@ -123,16 +123,23 @@ int tunnat_devices_setup(TunnatInstance * instance) return RT_SUCCESS; } -#define C_I_VLAN_PAIR_MAX 64 +#define C_I_VLAN_PAIR_MAX 2048 -int tunnat_bridge_setup(TunnatInstance * instance) +int tunnat_vlan_flipping_setup(TunnatInstance * instance) { const char * cfgfile = instance->cfgfile.c_str(); - unsigned int __bridge_mode = MR_TUNNAT_BRIDGE_MODE_DISABLE; + unsigned int __enable_vlan_flipping = 0; - MESA_load_profile_uint_def(cfgfile, "bridge", "mode", &__bridge_mode, __bridge_mode); - instance->bridge_mode = static_cast<enum bridge_mode>(__bridge_mode); + /* 是否启用VLAN FLIPPING */ + MESA_load_profile_uint_def(cfgfile, "vlan_flipping", "enable", &__enable_vlan_flipping, 0); + instance->en_vlan_flipping= __enable_vlan_flipping; + if (!instance->en_vlan_flipping) + { + return RT_SUCCESS; + } + + /* 读VLAN FLIPPING映射表 */ for(unsigned int i = 0; i < C_I_VLAN_PAIR_MAX; i++) { char __c_router_cfg_name[MR_SYMBOL_MAX] = {}; @@ -143,12 +150,12 @@ int tunnat_bridge_setup(TunnatInstance * instance) snprintf(__c_router_cfg_name, sizeof(__c_router_cfg_name), "c_router_vlan_id_%u", i); snprintf(__i_router_cfg_name, sizeof(__i_router_cfg_name), "i_router_vlan_id_%u", i); - if (MESA_load_profile_uint_nodef(cfgfile, "bridge", __c_router_cfg_name, &__c_router_cfg_value) < 0) + if (MESA_load_profile_uint_nodef(cfgfile, "vlan_flipping", __c_router_cfg_name, &__c_router_cfg_value) < 0) { break; } - if (MESA_load_profile_uint_nodef(cfgfile, "bridge", __i_router_cfg_name, &__i_router_cfg_value) < 0) + if (MESA_load_profile_uint_nodef(cfgfile, "vlan_flipping", __i_router_cfg_name, &__i_router_cfg_value) < 0) { break; } @@ -156,17 +163,23 @@ int tunnat_bridge_setup(TunnatInstance * instance) auto __u16_c_router_vlan_id = static_cast<uint16_t>(__c_router_cfg_value); auto __u16_i_router_vlan_id = static_cast<uint16_t>(__i_router_cfg_value); - auto vlan_map_item = instance->one_arm_bridge_vlan_map.find(__u16_c_router_vlan_id); - if (vlan_map_item != instance->one_arm_bridge_vlan_map.end()) + if (instance->vlan_fliping_map[__u16_c_router_vlan_id] != 0) + { + MR_WARNING("Duplicated vlan-id-flipping-map found, id = %u, ignore it.", i); + continue; + } + + if (instance->vlan_fliping_map[__u16_i_router_vlan_id] != 0) { - MR_WARNING("Duplicated vlan-id-map found, id = %u, ignore it.", i); + MR_WARNING("Duplicated vlan-id-flipping-map found, id = %u, ignore it.", i); continue; } - instance->one_arm_bridge_vlan_map[__u16_c_router_vlan_id] = __u16_i_router_vlan_id; + instance->vlan_fliping_map[__u16_c_router_vlan_id] = __u16_i_router_vlan_id; + instance->vlan_fliping_map[__u16_i_router_vlan_id] = __u16_c_router_vlan_id; - MR_INFO("One-arm bridge vlan-id map %u: c-subnet-vlan-id %u, i-subnet-vlan-id %u", - i, __u16_c_router_vlan_id, __u16_i_router_vlan_id); + MR_INFO("VLAN-FLIPPING-MAP %u: C-router-vlan-id %u, I-router-vlan-id %u",i, + __u16_c_router_vlan_id, __u16_i_router_vlan_id); } return RT_SUCCESS; @@ -392,7 +405,7 @@ int main(int argc, char * argv[]) goto err_out; if (tunnat_session_setup(g_instance) != RT_SUCCESS) goto err_out; - if (tunnat_bridge_setup(g_instance) != RT_SUCCESS) + if (tunnat_vlan_flipping_setup(g_instance) != RT_SUCCESS) goto err_out; for (unsigned int i = 0; i < g_instance->nr_thread; i++) diff --git a/tunnat/src/runtime.cc b/tunnat/src/runtime.cc index 0fead79..590886a 100644 --- a/tunnat/src/runtime.cc +++ b/tunnat/src/runtime.cc @@ -58,6 +58,7 @@ static int __phy_to_virt_pkt_decap(TunnatInstance * instance, TunnatThreadInstan { TunnelContainer & tun_container = tun_array.tun_array[i]; + tun_container.MbufMetaPreParse(mbuf); int ret = tun_container.PacketParse(pkt_ptr, pkt_len, pkt_tun_type); if (ret < 0) break; @@ -67,6 +68,8 @@ static int __phy_to_virt_pkt_decap(TunnatInstance * instance, TunnatThreadInstan tun_array.sz_array++; tun_array.sz_total_len += tun_container.ThisTunLength(); + + if (pkt_tun_type == TUNNEL_TYPE_END) break; } /* 没有成功解析隧道,转发应用处理 */ @@ -334,7 +337,9 @@ static int __virt_to_phy_pkt_forward(TunnatInstance * instance, TunnatThreadInst /* 回注前原始报文修正 */ char * tun_start = marsio_buff_mtod(mbuf); auto tun_type = static_cast<tunnel_type>(ctrlzone->__encap_type); + TunnelContainer::PacketForwardModify(tun_start, ctrlzone->__encap_len, tun_type); + TunnelContainer::MbufMetaForwardModify(mbuf, tun_type); TUNNAT_THREAD_STAT_ADD(TUNNAT_STAT_FORWARD_TUNNEL_OUTPUT, 1); return RT_SUCCESS; @@ -440,11 +445,12 @@ session_ready: for (int i = tun_array.sz_array - 2; i >= 0; i--) { TunnelContainer & __tun_container = tun_array.tun_array[i]; + __tun_container.MbufMetaConstruct(mbuf); auto __this_tun_length = static_cast<uint16_t>(__tun_container.ThisTunLength()); const char * pkt_ptr = marsio_buff_prepend(mbuf, __this_tun_length); unsigned int pkt_len = marsio_buff_datalen(mbuf); - tun_array.tun_array[i].PacketConstruct(pkt_ptr, pkt_len); + __tun_container.PacketConstruct(pkt_ptr, pkt_len); } (void)__adj_check; diff --git a/tunnat/src/tunnel.cc b/tunnat/src/tunnel.cc index d2f98a0..ce4c080 100644 --- a/tunnat/src/tunnel.cc +++ b/tunnat/src/tunnel.cc @@ -330,45 +330,55 @@ cJSON * TunVxlan::ToJSON() const return j_object; } -int TunVlanBridge::PacketParse(const char * pkt, unsigned int pkt_len) +int TunVlanFlipping::PacketParse(const char * pkt, unsigned int pkt_len) { /* 以太网头部 */ - auto * eth_hdr = (struct ether_hdr *) pkt; - if (eth_hdr->ether_type != htons(ETHER_TYPE_VLAN)) + if (!vlan_id_offload_by_nic_) { - return RT_ERR; + auto * eth_hdr = (struct ether_hdr *) pkt; + if (eth_hdr->ether_type != htons(ETHER_TYPE_VLAN)) + { + return RT_ERR; + } + + unsigned int offset = 0; + pkt += sizeof(struct ether_hdr); + offset += sizeof(struct ether_hdr); + + /* 外层IP头部 */ + auto * vlan_hdr = (struct vlan_hdr *) pkt; + vlan_id_ = rte_cpu_to_le_16(vlan_hdr->vlan_tci); } - unsigned int offset = 0; - pkt += sizeof(struct ether_hdr); - offset += sizeof(struct ether_hdr); + vlan_id_map_ = vlan_flipping_map_lookup(vlan_id_); - /* 外层IP头部 */ - auto * vlan_hdr = (struct vlan_hdr *) pkt; - vlan_id_ = rte_cpu_to_le_16(vlan_hdr->vlan_tci); + /* 不在VLAN Flipping Map中的VLAN,不认为是隧道的一部分 */ + if (!vlan_id_map_) + { + return RT_ERR; + } /* 本节为虚拟隧道,不真正剥去头部,只记住vlan-id */ this->next_layer_type = TUNNEL_TYPE_ETHER; - this->this_layer_type = TUNNEL_TYPE_VLAN_BRIDGE; + this->this_layer_type = TUNNEL_TYPE_VLAN_FLIPPING; this->this_layer_length = 0; - /* 成功 */ + TUNNAT_THREAD_STAT_ADD(TUNNAT_STAT_VLAN_FLIPING_INPUT, 1); return RT_SUCCESS; } -int TunVlanBridge::PacketConstruct(const char * pkt, unsigned int pkt_len) +int TunVlanFlipping::PacketConstruct(const char * pkt, unsigned int pkt_len) { return PacketForwardModify(pkt, pkt_len); } -int TunVlanBridge::PacketForwardModify(const char * pkt, unsigned int pkt_len) +int TunVlanFlipping::PacketForwardModify(const char * pkt, unsigned int pkt_len) { - /* 不启用VLAN查表翻转时,直接返回不变更vlan-id */ - auto * instance = TunnatInstance::TunnatInstanceGet(); - - /* 以太网头部 */ auto * eth_hdr = (struct ether_hdr *) pkt; - if (eth_hdr->ether_type != htons(ETHER_TYPE_VLAN)) return RT_ERR; + if (eth_hdr->ether_type != htons(ETHER_TYPE_VLAN)) + { + return RT_ERR; + } unsigned int offset = 0; pkt += sizeof(struct ether_hdr); @@ -378,18 +388,74 @@ int TunVlanBridge::PacketForwardModify(const char * pkt, unsigned int pkt_len) auto * vlan_hdr = (struct vlan_hdr *) pkt; uint16_t vlan_id = ntohs(vlan_hdr->vlan_tci); - auto target_vlan_ld_iter = instance->one_arm_bridge_vlan_map.find(vlan_id); - if (target_vlan_ld_iter == instance->one_arm_bridge_vlan_map.end()) + uint16_t map_vlan_id = vlan_flipping_map_lookup(vlan_id); + if (!map_vlan_id) { return RT_ERR; } - uint16_t map_vlan_id = target_vlan_ld_iter->second; vlan_hdr->vlan_tci = htons(map_vlan_id); - return RT_SUCCESS; } +int TunVlanFlipping::MbufMetaForwardModify(marsio_buff_t * mbuf) +{ + auto * __mbuf = (struct rte_mbuf *)mbuf; + if (!__mbuf->ol_flags & PKT_RX_VLAN) + { + return 0; + } + + uint16_t vlan_id_fliping = vlan_flipping_map_lookup(__mbuf->vlan_tci); + if (vlan_id_fliping != 0) + { + __mbuf->ol_flags |= PKT_TX_VLAN_PKT; + __mbuf->vlan_tci = vlan_id_fliping; + } + + return 0; +} + + +void TunVlanFlipping::MbufMetaPreParse(marsio_buff_t * mbuf) +{ + auto * __mbuf = (struct rte_mbuf *)mbuf; + if (__mbuf->ol_flags & PKT_RX_VLAN) + { + vlan_id_ = __mbuf->vlan_tci; + vlan_id_offload_by_nic_ = true; + } +} + +void TunVlanFlipping::MbufMetaConstruct(marsio_buff_t * mbuf) +{ + auto * __mbuf = (struct rte_mbuf *)mbuf; + if (vlan_id_offload_by_nic_) + { + __mbuf->ol_flags |= PKT_TX_VLAN_PKT; + __mbuf->vlan_tci = vlan_id_map_; + } +} + +uint16_t TunVlanFlipping::vlan_flipping_map_lookup(uint16_t le_vlan_id) +{ + auto * instance = TunnatInstance::TunnatInstanceGet(); + if (unlikely(le_vlan_id < 1 || le_vlan_id > ETHER_MAX_VLAN_ID)) + { + TUNNAT_THREAD_STAT_ADD(TUNNAT_STAT_VLAN_FLIPING_INVALID_VLAN_ID, 1); + return 0; + } + + uint16_t result = instance->vlan_fliping_map[le_vlan_id]; + if (unlikely(result == 0)) + { + TUNNAT_THREAD_STAT_ADD(TUNNAT_STAT_VLAN_FLIPING_NO_FLIP_MAP, 1); + return 0; + } + + return result; +} + extern "C" { #include <ldbc.h> @@ -586,7 +652,7 @@ int TunnelContainer::PacketParse(const char * pkt, unsigned int pkt_len, ret = tun_qmac_object_.PacketParse(pkt, pkt_len); break; - case TUNNEL_TYPE_VLAN_BRIDGE: + case TUNNEL_TYPE_VLAN_FLIPPING: ret = tun_vlan_bridge_object_.PacketParse(pkt, pkt_len); break; @@ -619,7 +685,7 @@ guess: ret = tun_vlan_bridge_object_.PacketParse(pkt, pkt_len); if (ret >= 0) { - this_layer_type = TUNNEL_TYPE_VLAN_BRIDGE; + this_layer_type = TUNNEL_TYPE_VLAN_FLIPPING; goto out; } @@ -650,7 +716,7 @@ Tunnel * TunnelContainer::tun_object_get() { case TUNNEL_TYPE_G_VXLAN:return &tun_vxlan_object_; case TUNNEL_TYPE_G_MAC_IN_MAC:return &tun_qmac_object_; - case TUNNEL_TYPE_VLAN_BRIDGE: return &tun_vlan_bridge_object_; + case TUNNEL_TYPE_VLAN_FLIPPING: return &tun_vlan_bridge_object_; case TUNNEL_TYPE_ETHER:return &tun_inner_ether_; case TUNNEL_TYPE_PPP:return &tun_inner_ppp_; case TUNNEL_TYPE_HDLC:return &tun_inner_hdlc_; @@ -681,7 +747,7 @@ int TunnelContainer::PacketForwardModify(const char * pkt, unsigned int pkt_len, { case TUNNEL_TYPE_G_VXLAN:return TunVxlan::PacketForwardModify(pkt, pkt_len); case TUNNEL_TYPE_G_MAC_IN_MAC:return TunQMac::PacketForwardModify(pkt, pkt_len); - case TUNNEL_TYPE_VLAN_BRIDGE: return TunVlanBridge::PacketForwardModify(pkt, pkt_len); + case TUNNEL_TYPE_VLAN_FLIPPING: return TunVlanFlipping::PacketForwardModify(pkt, pkt_len); case TUNNEL_TYPE_ETHER:return TunInnerEther::PacketForwardModify(pkt, pkt_len); case TUNNEL_TYPE_HDLC:return TunInnerHDLC::PacketForwardModify(pkt, pkt_len); case TUNNEL_TYPE_PPP:return TunInnerPPP::PacketForwardModify(pkt, pkt_len); @@ -691,11 +757,27 @@ int TunnelContainer::PacketForwardModify(const char * pkt, unsigned int pkt_len, return RT_ERR; } +int TunnelContainer::MbufMetaForwardModify(marsio_buff_t * mbuf, enum tunnel_type tun_type) +{ + switch (tun_type) + { + case TUNNEL_TYPE_VLAN_FLIPPING: return TunVlanFlipping::MbufMetaForwardModify(mbuf); + default: break; + } + + return RT_ERR; +} + int TunnelContainer::PacketConstruct(const char * pkt, unsigned int pkt_len) { return tun_object_->PacketConstruct(pkt, pkt_len); } +void TunnelContainer::MbufMetaConstruct(marsio_buff_t * mbuf) +{ + return tun_object_->MbufMetaConstruct(mbuf); +} + int TunnelContainer::GetAddressInfo(AddressInfo &addr_info) { return tun_object_->GetAddressInfo(addr_info); @@ -725,6 +807,22 @@ bool TunnelContainer::operator==(const TunnelContainer &rhs) return false; } +void TunnelContainer::MbufMetaPreParse(marsio_buff_t * mbuf, tunnel_type tunnel_type) +{ + switch (tunnel_type) + { + case TUNNEL_TYPE_UNKNOWN: + goto guess; + case TUNNEL_TYPE_VLAN_FLIPPING:tun_vlan_bridge_object_.MbufMetaPreParse(mbuf); + break; + default: return; + } + +guess: + tun_vlan_bridge_object_.MbufMetaPreParse(mbuf); + return; +} + int TunInnerIPv4::PacketParse(const char * pkt, unsigned int pkt_len) { struct ipv4_hdr * ipv4_hdr = (struct ipv4_hdr *) pkt; @@ -732,7 +830,7 @@ int TunInnerIPv4::PacketParse(const char * pkt, unsigned int pkt_len) ipv4_addr.dst_in_addr.s_addr = ipv4_hdr->dst_addr; this_layer_type = TUNNEL_TYPE_IPV4; - next_layer_type = TUNNEL_TYPE_UNKNOWN; + next_layer_type = TUNNEL_TYPE_END; this_layer_length = sizeof(struct ipv4_hdr); return 0; } @@ -744,7 +842,7 @@ int TunInnerIPv6::PacketParse(const char * pkt, unsigned int pkt_len) memcpy(&ipv6_addr.dst_in6_addr, ipv6_hdr->dst_addr, sizeof(struct in6_addr)); this_layer_type = TUNNEL_TYPE_IPV6; - next_layer_type = TUNNEL_TYPE_UNKNOWN; + next_layer_type = TUNNEL_TYPE_END; this_layer_length = sizeof(struct ipv6_hdr); return 0; } @@ -771,4 +869,4 @@ int TunInnerHDLC::PacketParse(const char * pkt, unsigned int pkt_len) TUNNAT_THREAD_STAT_ADD(TUNNAT_STAT_INNER_HDLC_INPUT, 1); return 0; -}
\ No newline at end of file +} |
