summaryrefslogtreecommitdiff
path: root/tunnat/include
diff options
context:
space:
mode:
authorQiuwen Lu <[email protected]>2017-06-23 10:03:21 +0800
committerQiuwen Lu <[email protected]>2017-06-23 10:03:21 +0800
commitbfae3e5ecb79dfda104024cce92aff8c3107cb97 (patch)
tree80677e33a60a8ff643cbee761e8d1e479be1bd8d /tunnat/include
parent546f82d073e3bf7e6cb569ab61d1ed59e44ecb07 (diff)
TUNNAT:增加有历史记录的主动发包功能。
Diffstat (limited to 'tunnat/include')
-rw-r--r--tunnat/include/tunnat.h10
-rw-r--r--tunnat/include/tunnel.h114
2 files changed, 86 insertions, 38 deletions
diff --git a/tunnat/include/tunnat.h b/tunnat/include/tunnat.h
index 49f56d3..07be3d1 100644
--- a/tunnat/include/tunnat.h
+++ b/tunnat/include/tunnat.h
@@ -84,9 +84,15 @@ public:
TUNNAT_STAT_INNER_ETHER_INPUT,
TUNNAT_STAT_INNER_HDLC_INPUT,
TUNNAT_STAT_INNER_PPP_INPUT,
+ /* 统计,输出请求类型 */
+ TUNNAT_STAT_FORWARD_RAW_OUTPUT,
+ TUNNAT_STAT_FORWARD_TUNNEL_OUTPUT,
+ TUNNAT_STAT_ENCAP_OUTPUT,
/* 统计,会话表表项计数 */
TUNNAT_STAT_SESSION_ADD,
TUNNAT_STAT_SESSION_REMOVE,
+ /* 统计,关键失败事件 */
+ TUNNAT_STAT_ENCAP_FAIL_NO_SESSION,
/* 最大表项 */
TUNNAT_STAT_MAX
};
@@ -148,8 +154,12 @@ public:
[TUNNAT_STAT_INNER_ETHER_INPUT] = "TUNNAT_STAT_INNER_ETHER_INPUT",
[TUNNAT_STAT_INNER_HDLC_INPUT] = "TUNNAT_STAT_INNER_HDLC_INPUT",
[TUNNAT_STAT_INNER_PPP_INPUT] = "TUNNAT_STAT_INNER_PPP_INPUT",
+ [TUNNAT_STAT_FORWARD_RAW_OUTPUT] = "TUNNAT_STAT_FORWARD_RAW_OUTPUT",
+ [TUNNAT_STAT_FORWARD_TUNNEL_OUTPUT] = "TUNNAT_STAT_FORWARD_TUNNEL_OUTPUT",
+ [TUNNAT_STAT_ENCAP_OUTPUT] = "TUNNAT_STAT_ENCAP_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_MAX] = "TUNNAT_STAT_MAX"
};
diff --git a/tunnat/include/tunnel.h b/tunnat/include/tunnel.h
index 033674e..a3af3d7 100644
--- a/tunnat/include/tunnel.h
+++ b/tunnat/include/tunnel.h
@@ -34,39 +34,6 @@ enum tunnel_type
TUNNEL_TYPE_IPV6
};
-#if 1
-
-
-#endif
-
-#if 0
-struct g_vxlan_hdr
-{
-#if defined (__LITTLE_ENDIAN_BITFIELD)
- uint32_t flags : 8,
- res_high : 24;
- uint32_t vlan_id : 12,
- link_layer_type : 4,
- online_test : 1,
- link_id : 6,
- dir : 1,
- res_low : 8;
-#elif defined (__BIG_ENDIAN_BITFIELD)
- uint64_t res_low : 8,
- dir : 1,
- link_id : 6,
- online_test : 1,
- link_layer_type : 4,
- vlan_id : 12,
- res_high : 24,
- flags : 8;
-#else
-#error "Please fix <asm/byteorder.h>"
-#endif
-
-} __attribute__((__packed__));
-#endif
-
class Tunnel
{
protected:
@@ -109,9 +76,15 @@ public:
return RT_ERR;
}
+ virtual void ReverseAddress()
+ {
+ return;
+ }
+
static int PacketForwardModify(const char * pkt, unsigned int pkt_len)
{
- return 0;
+ assert(0);
+ return RT_ERR;
}
};
@@ -121,14 +94,23 @@ class TunVxlan : public Tunnel
protected:
struct ether_hdr ether_hdr_;
struct vlan_hdr vlan_hdr_;
+ struct ipv4_hdr ipv4_hdr_;
+ struct udp_hdr udp_hdr_;
+ struct g_vxlan_hdr vxlan_hdr_;
+
struct in_addr src_in_addr_;
struct in_addr dst_in_addr_;
- struct g_vxlan_hdr vxlan_hdr_;
public:
int PacketParse(const char * pkt, unsigned int pkt_len);
int PacketConstruct(const char * pkt, unsigned int pkt_len);
int GetAddressInfo(struct AddressInfo & addr_info);
+
+ void ReverseAddress()
+ {
+ return;
+ }
+
static int PacketForwardModify(const char * pkt, unsigned int pkt_len);
};
@@ -143,6 +125,13 @@ protected:
public:
int PacketParse(const char * pkt, unsigned int pkt_len);
+ int PacketConstruct(const char * pkt, unsigned int pkt_len);
+
+ void ReverseAddress()
+ {
+ std::swap<ether_addr>(ether_hdr_.s_addr, ether_hdr_.d_addr);
+ }
+
static int PacketForwardModify(const char * pkt, unsigned int pkt_len);
};
@@ -153,7 +142,18 @@ protected:
struct in_addr dst_in_addr_;
public:
int PacketParse(const char * pkt, unsigned int pkt_len);
- int GetAddressInfo(struct AddressInfo & addr_info);
+
+ int GetAddressInfo(struct AddressInfo & addr_info)
+ {
+ addr_info.src_in_addr = src_in_addr_;
+ addr_info.dst_in_addr = dst_in_addr_;
+ return RT_SUCCESS;
+ }
+
+ void ReverseAddress()
+ {
+ std::swap<in_addr>(src_in_addr_, dst_in_addr_);
+ }
};
class TunInnerIPv6 : public Tunnel
@@ -170,6 +170,10 @@ class TunInnerPPP : public Tunnel
{
public:
int PacketParse(const char * pkt, unsigned int pkt_len);
+ void ReverseAddress()
+ {
+ return;
+ }
};
class TunInnerHDLC : public Tunnel
@@ -192,6 +196,8 @@ public:
int GetAddressInfo(struct AddressInfo & addr_info);
+ void ReverseAddress();
+
static int PacketForwardModify(const char * pkt, unsigned int pkt_len,
enum tunnel_type tun_type);
@@ -203,12 +209,39 @@ protected:
TunInnerPPP tun_inner_ppp_;
TunInnerIPv4 tun_inner_ipv4_;
TunInnerIPv6 tun_inner_ipv6_;
-
- Tunnel * tun_object_;
+
enum tunnel_type this_layer_type;
+ Tunnel * tun_object_;
public:
TunnelContainer() : tun_object_(nullptr) {}
+ TunnelContainer(const TunnelContainer & orin) :
+ tun_vxlan_object_(orin.tun_vxlan_object_),
+ tun_qmac_object_(orin.tun_qmac_object_),
+ tun_inner_ether_(orin.tun_inner_ether_),
+ tun_inner_hdlc_(orin.tun_inner_hdlc_),
+ tun_inner_ipv4_(orin.tun_inner_ipv4_),
+ tun_inner_ipv6_(orin.tun_inner_ipv6_),
+ this_layer_type(orin.this_layer_type),
+ tun_object_(tun_object_get())
+ {}
+
+ TunnelContainer & operator=(const TunnelContainer & orin)
+ {
+ this->tun_vxlan_object_ = orin.tun_vxlan_object_;
+ this->tun_qmac_object_ = orin.tun_qmac_object_;
+ this->tun_inner_ether_ = orin.tun_inner_ether_;
+ this->tun_inner_hdlc_ = orin.tun_inner_hdlc_;
+ this->tun_inner_ipv4_ = orin.tun_inner_ipv4_;
+ this->tun_inner_ipv6_ = orin.tun_inner_ipv6_;
+ this->this_layer_type = orin.this_layer_type;
+ tun_object_ = tun_object_get();
+
+ return *this;
+ }
+
+private:
+ Tunnel * tun_object_get();
};
#define MR_TUNNAT_LAYER_MAX 4
@@ -232,4 +265,9 @@ struct TunnelContainerArray
TunnelContainerArray() : sz_array(0), sz_total_len(0) {}
void Reset() { sz_array = 0, sz_total_len = 0; }
+ void ReverseAddress()
+ {
+ for (unsigned i = 0; i < sz_array; i++)
+ tun_array[i].ReverseAddress();
+ }
}; \ No newline at end of file