summaryrefslogtreecommitdiff
path: root/tunnat/include
diff options
context:
space:
mode:
authorQiuwen Lu <[email protected]>2019-04-09 16:15:25 +0800
committerQiuwen Lu <[email protected]>2019-06-15 11:25:42 +0800
commit248c9861ab765239834e1512384d9eabb48aa39e (patch)
tree8b0575682e3e8ec8455291822eb74532567d7598 /tunnat/include
parent4e79871b6477d4c62db8c20e4ccaed729b040469 (diff)
增加对VLAN二层回流的支持
Diffstat (limited to 'tunnat/include')
-rw-r--r--tunnat/include/tunnat.h16
-rw-r--r--tunnat/include/tunnel.h28
2 files changed, 41 insertions, 3 deletions
diff --git a/tunnat/include/tunnat.h b/tunnat/include/tunnat.h
index 99bda31..6d43514 100644
--- a/tunnat/include/tunnat.h
+++ b/tunnat/include/tunnat.h
@@ -4,6 +4,7 @@
#include <vector>
#include <cassert>
#include <tunnel.h>
+#include <map>
extern "C"
{
@@ -54,6 +55,13 @@ struct TunnatThreadInstance;
#define MR_TUNNAT_DEFAULT_SESSION_EXPIRE_TIME 0
#endif
+enum bridge_mode
+{
+ MR_TUNNAT_BRIDGE_MODE_DISABLE,
+ MR_TUNNAT_BRIDGE_MODE_ONE_ARM,
+ MR_TUNNAT_BRIDGE_MODE_TWO_ARM,
+};
+
/* 全局句柄 */
struct TunnatInstance
{
@@ -98,6 +106,11 @@ struct TunnatInstance
/* 虚拟设备列表(应用侧)*/
std::vector<struct _devs> virtdevs;
+ /* 桥接模式 */
+ enum bridge_mode bridge_mode;
+ /* 单臂桥接VLAN映射表 */
+ std::map<uint16_t, uint16_t> one_arm_bridge_vlan_map;
+
/* 线程运行句柄 */
TunnatThreadInstance * thread_instances[MR_SID_MAX];
@@ -110,6 +123,9 @@ struct TunnatInstance
TunnatInstance() = default;
~TunnatInstance() = default;
+
+public:
+ static struct TunnatInstance * TunnatInstanceGet();
};
class SessionTable;
diff --git a/tunnat/include/tunnel.h b/tunnat/include/tunnel.h
index b804fd9..9f1ee01 100644
--- a/tunnat/include/tunnel.h
+++ b/tunnat/include/tunnel.h
@@ -59,6 +59,7 @@ enum tunnel_type
TUNNEL_TYPE_UNKNOWN,
TUNNEL_TYPE_G_VXLAN,
TUNNEL_TYPE_G_MAC_IN_MAC,
+ TUNNEL_TYPE_VLAN_BRIDGE,
TUNNEL_TYPE_ETHER,
TUNNEL_TYPE_PPP,
TUNNEL_TYPE_HDLC,
@@ -78,17 +79,17 @@ protected:
public:
- enum tunnel_type NextTunType()
+ virtual enum tunnel_type NextTunType()
{
return next_layer_type;
}
- enum tunnel_type ThisTunType()
+ virtual enum tunnel_type ThisTunType()
{
return this_layer_type;
}
- unsigned int ThisTunLength()
+ virtual unsigned int ThisTunLength()
{
return this_layer_length;
}
@@ -167,6 +168,24 @@ public:
class TunQMac : public Tunnel
{};
+class TunVlanBridge : public Tunnel
+{
+public:
+ tunnel_type NextTunType() override { return TUNNEL_TYPE_ETHER; }
+ tunnel_type ThisTunType() override { return TUNNEL_TYPE_VLAN_BRIDGE; }
+ 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;
+ 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);
+
+private:
+ unsigned int vlan_id_;
+};
class TunInnerEther : public Tunnel
{
@@ -287,6 +306,7 @@ public:
protected:
TunVxlan tun_vxlan_object_;
TunQMac tun_qmac_object_;
+ TunVlanBridge tun_vlan_bridge_object_;
TunInnerEther tun_inner_ether_;
TunInnerHDLC tun_inner_hdlc_;
TunInnerPPP tun_inner_ppp_;
@@ -301,6 +321,7 @@ public:
TunnelContainer(const TunnelContainer & orin) :
tun_vxlan_object_(orin.tun_vxlan_object_),
tun_qmac_object_(orin.tun_qmac_object_),
+ tun_vlan_bridge_object_(orin.tun_vlan_bridge_object_),
tun_inner_ether_(orin.tun_inner_ether_),
tun_inner_hdlc_(orin.tun_inner_hdlc_),
tun_inner_ppp_(orin.tun_inner_ppp_),
@@ -314,6 +335,7 @@ public:
{
this->tun_vxlan_object_ = orin.tun_vxlan_object_;
this->tun_qmac_object_ = orin.tun_qmac_object_;
+ this->tun_vlan_bridge_object_ = orin.tun_vlan_bridge_object_;
this->tun_inner_ether_ = orin.tun_inner_ether_;
this->tun_inner_hdlc_ = orin.tun_inner_hdlc_;
this->tun_inner_ppp_ = orin.tun_inner_ppp_;