集成解密流量转发模块
This commit is contained in:
@@ -0,0 +1,125 @@
|
||||
#ifndef DELIVER_PRIVATE_H
|
||||
#define DELIVER_PRIVATE_H
|
||||
|
||||
#include <decrypt-mirroring.h>
|
||||
#include <MESA/field_stat2.h>
|
||||
|
||||
#ifndef MAX_THREAD_NUM
|
||||
#define MAX_THREAD_NUM 128
|
||||
#endif
|
||||
|
||||
#define DELIVER_DEFAULT_MTU 1500
|
||||
#define DELIVER_SENDPKT_BUFLEN 2048
|
||||
|
||||
//runtime log
|
||||
#define DELIVER_MODULE_INIT "deliver_init"
|
||||
#define DELIVER_MODULE_SENDPKT "deliver_sendpkt"
|
||||
#define DELIVER_SENDPKT_START "sendpkt_start"
|
||||
#define DELIVER_SENDPKT_DEBUG "sendpkt_debug"
|
||||
#define DELIVER_RECVPKT_DEBUG "recvpkt_debug"
|
||||
#define DELIVER_SENDPKT_END "sendpkt_end"
|
||||
|
||||
#define DELIVER_FLAG_SENDPKT 0
|
||||
#define DELIVER_FLAG_RECVPKT 1
|
||||
#define DELIVER_FLAG_ENT 2
|
||||
|
||||
//init profile info
|
||||
#define DELIVER_CARDNAME_LEN 128
|
||||
#define DELIVER_CONF_MAXLEN 1024
|
||||
#define DELIVER_CONF_MODE "DELIVER"
|
||||
#define DELIVER_RCV_MAC "reveiver_mac"
|
||||
|
||||
#define PROTO_TYPE_TCP 6
|
||||
#define PROTO_TYPE_UDP 17
|
||||
|
||||
|
||||
//lqueue info
|
||||
#define DELIVER_THREAD_SAFE 1
|
||||
#define DELIVER_USLEEP_TIME 10
|
||||
#define DELIVER_LQUEUE_MAXNUM 100000
|
||||
|
||||
|
||||
//send pkt
|
||||
#define DELIVER_MACADDR_LEN 6
|
||||
#define DELIVER_MACADDR_STR_LEN 18
|
||||
#define DELIVER_ETHER_LEN 14
|
||||
#define TCPHDR_DEFAULT_LEN 20
|
||||
|
||||
//fs2 info
|
||||
#define FS2_COLUMN_NUM 5
|
||||
#define FS2_APPNAME "DELIVER"
|
||||
|
||||
|
||||
enum deliver_fs_colume
|
||||
{
|
||||
FS2_COLUME_RECVPKT=0,
|
||||
FS2_COLUME_RECVBYTE,
|
||||
FS2_COLUME_SENDPKT,
|
||||
FS2_COLUME_SENDBYTE,
|
||||
FS2_COLUME_ERROR,
|
||||
};
|
||||
|
||||
|
||||
struct deliver_fs2_info
|
||||
{
|
||||
screen_stat_handle_t handler;
|
||||
int column_id[FS2_COLUMN_NUM];
|
||||
unsigned long long column_value[MAX_THREAD_NUM][FS2_COLUMN_NUM];
|
||||
};
|
||||
|
||||
struct deliver_comm_info
|
||||
{
|
||||
int threadnum;
|
||||
void* logger;
|
||||
};
|
||||
|
||||
|
||||
struct deliver_pkt_info
|
||||
{
|
||||
int dir;
|
||||
unsigned int seq; //host order
|
||||
unsigned int ack; //host order
|
||||
unsigned int len; //host order,tcp payload len
|
||||
unsigned short ipid; //host order
|
||||
unsigned short win; //host order
|
||||
unsigned char flag;
|
||||
unsigned char ttl;
|
||||
|
||||
};
|
||||
|
||||
struct deliver_session_info
|
||||
{
|
||||
int recv_pkt;
|
||||
int send_pkt;
|
||||
long long recv_byte;
|
||||
long long send_byte;
|
||||
};
|
||||
|
||||
|
||||
struct deliver_pme_info
|
||||
{
|
||||
unsigned char dst_macaddr[DELIVER_MACADDR_LEN];
|
||||
struct deliver_addr_info addr_info;
|
||||
struct deliver_pkt_info pkt_info;
|
||||
struct deliver_session_info session_info;
|
||||
};
|
||||
|
||||
struct deliver_recver_info
|
||||
{
|
||||
unsigned char dst_macaddr[DELIVER_MACADDR_LEN];
|
||||
};
|
||||
|
||||
struct deliver_sendpkt_info
|
||||
{
|
||||
int mtu;
|
||||
int thread_num;
|
||||
int receiver_num;
|
||||
struct ifreq ifr;
|
||||
int* send_socket;
|
||||
char senddevice[DELIVER_CARDNAME_LEN];
|
||||
unsigned char src_macaddr[DELIVER_MACADDR_LEN];
|
||||
struct deliver_recver_info* receiver_info;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
140
plugin/business/decrypt-mirroring/include/internal/sendpkt-inl.h
Normal file
140
plugin/business/decrypt-mirroring/include/internal/sendpkt-inl.h
Normal file
@@ -0,0 +1,140 @@
|
||||
#ifndef DELIVER_SENDPKT_H
|
||||
#define DELIVER_SENDPKT_H
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
|
||||
|
||||
#ifndef ETHER_ADDR_LEN
|
||||
#define ETHER_ADDR_LEN 6
|
||||
#endif
|
||||
|
||||
#define ARPHRD_ETHER 1 /* ethernet hardware format */
|
||||
|
||||
#define SENDPACKET_ETH_H 0xe /* Etherner header: 14 bytes */
|
||||
#define SENDPACKET_IP_H 0x14 /* IP header: 20 bytes */
|
||||
#define SENDPACKET_TCP_H 0x14 /* TCP header: 20 bytes */
|
||||
|
||||
|
||||
struct mesa_ethernet_hdr
|
||||
{
|
||||
unsigned char ether_dhost[ETHER_ADDR_LEN]; /* destination ethernet address */
|
||||
unsigned char ether_shost[ETHER_ADDR_LEN]; /* source ethernet address */
|
||||
unsigned short ether_type; /* packet type ID */
|
||||
};
|
||||
|
||||
|
||||
|
||||
struct mesa_ip4_hdr
|
||||
{
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
u_int8_t ip_hl:4, /* header length */
|
||||
ip_v:4; /* version */
|
||||
#elif __BYTE_ORDER == __BIG_ENDIAN
|
||||
u_int8_t ip_v:4, /* version */
|
||||
ip_hl:4; /* header length */
|
||||
#else
|
||||
#error "Please check <endian.h>"
|
||||
#endif
|
||||
u_int8_t ip_tos; /* type of service */
|
||||
u_int16_t ip_len; /* total length */
|
||||
u_int16_t ip_id; /* identification */
|
||||
u_int16_t ip_off;
|
||||
u_int8_t ip_ttl; /* time to live */
|
||||
u_int8_t ip_p; /* protocol */
|
||||
u_int16_t ip_sum; /* checksum */
|
||||
struct in_addr ip_src, ip_dst; /* source and dest address */
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* IPv6 packet header prototype, add by LiJia 2012-03-19.
|
||||
*/
|
||||
struct mesa_ip6_hdr
|
||||
{
|
||||
u_int8_t ip6_flags[4]; /* version, traffic-class, flow-label */
|
||||
u_int16_t ip6_payload_len; /* payload length, not contain header */
|
||||
u_int8_t ip6_nxt_hdr; /* next header, same as protocol in IPv4 */
|
||||
u_int8_t ip6_hop; /* hop limit, same as TTL in IPv4 */
|
||||
struct in6_addr ip6_src; /* source address */
|
||||
struct in6_addr ip6_dst; /* dest address */
|
||||
};
|
||||
|
||||
|
||||
#ifndef TH_FIN
|
||||
#define TH_FIN 0x01
|
||||
#endif
|
||||
#ifndef TH_SYN
|
||||
#define TH_SYN 0x02
|
||||
#endif
|
||||
#ifndef TH_RST
|
||||
#define TH_RST 0x04
|
||||
#endif
|
||||
#ifndef TH_PUSH
|
||||
#define TH_PUSH 0x08
|
||||
#endif
|
||||
#ifndef TH_ACK
|
||||
#define TH_ACK 0x10
|
||||
#endif
|
||||
#ifndef TH_URG
|
||||
#define TH_URG 0x20
|
||||
#endif
|
||||
|
||||
|
||||
struct mesa_tcp_hdr
|
||||
{
|
||||
u_int16_t th_sport; /* source port */
|
||||
u_int16_t th_dport; /* destination port */
|
||||
u_int32_t th_seq; /* sequence number */
|
||||
u_int32_t th_ack; /* acknowledgement number */
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
u_int8_t th_x2:4, /* (unused) */
|
||||
th_off:4; /* data offset */
|
||||
#elif __BYTE_ORDER == __BIG_ENDIAN
|
||||
u_int8_t th_off:4, /* data offset */
|
||||
th_x2:4; /* (unused) */
|
||||
#else
|
||||
#error "Please check <endian.h>"
|
||||
#endif
|
||||
u_int8_t th_flags; /* control flags */
|
||||
u_int16_t th_win; /* window */
|
||||
u_int16_t th_sum; /* checksum */
|
||||
u_int16_t th_urp; /* urgent pointer */
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* UDP packet header prototype.
|
||||
*/
|
||||
struct mesa_udp_hdr
|
||||
{
|
||||
u_int16_t uh_sport; /* soure port */
|
||||
u_int16_t uh_dport; /* destination port */
|
||||
u_int16_t uh_ulen; /* length */
|
||||
u_int16_t uh_sum; /* checksum */
|
||||
};
|
||||
|
||||
unsigned int deliver_rand(void);
|
||||
unsigned int deliver_rand_range(unsigned int start, unsigned int end);
|
||||
int deliver_get_dev_mac(const char *device, unsigned char mac[6]);
|
||||
int deliver_mac_pton(const char *str, int delim, char *mac);
|
||||
int deliver_do_checksum(unsigned char *buf, int protocol, int len);
|
||||
int deliver_build_ethernet(unsigned char *dst, unsigned char *src, unsigned short type,
|
||||
const unsigned char *payload, int payload_s, unsigned char *buf);
|
||||
int deliver_build_ethhdr(unsigned char *dst, unsigned char *src, unsigned short type,unsigned char *buf);
|
||||
int deliver_build_ipv6(unsigned char traffic_class, unsigned int flow_lable,
|
||||
unsigned short len, unsigned char next_header, unsigned char hop,
|
||||
const struct in6_addr *src, const struct in6_addr *dst,
|
||||
const char *payload, int payload_s, unsigned char *buf);
|
||||
int deliver_build_ipv4(unsigned short carry_layer_len, unsigned char tos, unsigned short id,
|
||||
unsigned short frag, unsigned char ttl, unsigned char prot, unsigned int src, unsigned int dst,
|
||||
const char *payload,int payload_s, unsigned char *buf);
|
||||
int deliver_build_tcp(unsigned short sp, unsigned short dp, unsigned int seq, unsigned int ack,
|
||||
unsigned char th_flags, unsigned short win, unsigned short urg,
|
||||
const char *payload, int payload_s, unsigned char *buf);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user