1、新增build.sh和clean.sh,用于辅助编译
2、更新tcpreplay.c,支持回放MPLS,PPPoE,VLAN封装的数据包
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
tcpburst
|
||||||
3
build.sh
Executable file
3
build.sh
Executable file
@@ -0,0 +1,3 @@
|
|||||||
|
sh ./configure --enable-dynamic-link
|
||||||
|
make
|
||||||
|
cp src/tcpreplay ./tcpburst
|
||||||
128
src/tcpreplay.c
128
src/tcpreplay.c
@@ -1208,15 +1208,15 @@ static inline int stream_addr_cmp_udp(struct ip *iphdr, struct udphdr *udphdr)
|
|||||||
Ϊ<>˲<EFBFBD><CBB2><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD>У<EFBFBD><D0A3><EFBFBD>ͣ<EFBFBD><CDA3>Դﵽ<D4B4>ϸߵķ<DFB5><C4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʣ<EFBFBD>
|
Ϊ<>˲<EFBFBD><CBB2><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD>У<EFBFBD><D0A3><EFBFBD>ͣ<EFBFBD><CDA3>Դﵽ<D4B4>ϸߵķ<DFB5><C4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʣ<EFBFBD>
|
||||||
<20>ĵ<EFBFBD>ַʱ<D6B7><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IP<49><50>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>ģ<DEB8><C4A3><EFBFBD><EFBFBD>Ӻͼ<D3BA><CDBC>ٵ<EFBFBD>ֵҪ<D6B5><D2AA><EFBFBD><EFBFBD>.
|
<20>ĵ<EFBFBD>ַʱ<D6B7><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IP<49><50>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>ģ<DEB8><C4A3><EFBFBD><EFBFBD>Ӻͼ<D3BA><CDBC>ٵ<EFBFBD>ֵҪ<D6B5><D2AA><EFBFBD><EFBFBD>.
|
||||||
*/
|
*/
|
||||||
static int stream_edit_addr(u_char *pkt, int differ)
|
static int stream_edit_addr(u_char *pkt, int differ, struct ip* iphdr)
|
||||||
{
|
{
|
||||||
struct ip *iphdr;
|
//struct ip *iphdr;
|
||||||
struct tcphdr *tcphdr;
|
struct tcphdr *tcphdr;
|
||||||
struct udphdr *udphdr;
|
struct udphdr *udphdr;
|
||||||
|
|
||||||
differ *= 3;
|
differ *= 3;
|
||||||
|
|
||||||
iphdr = (struct ip *)(pkt + 14);
|
//iphdr = (struct ip *)(pkt + 14);
|
||||||
|
|
||||||
if(IPPROTO_TCP == iphdr->ip_p)
|
if(IPPROTO_TCP == iphdr->ip_p)
|
||||||
{
|
{
|
||||||
@@ -1285,7 +1285,8 @@ static int stream_burst_send_pkt_by_marsio(struct mr_sendpath *handle, const u_c
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef MARSIO
|
//#ifdef MARSIO
|
||||||
|
#if 0
|
||||||
static stream_burst_send_pkt_multiple(void *handle, const u_char *pkt, size_t pktlen)
|
static stream_burst_send_pkt_multiple(void *handle, const u_char *pkt, size_t pktlen)
|
||||||
{
|
{
|
||||||
marsio_buff_t *send_mbuf[256];
|
marsio_buff_t *send_mbuf[256];
|
||||||
@@ -1422,7 +1423,97 @@ int stream_burst_send_pkt(void *handle, const u_char *pkt, size_t pktlen)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int stream_burst(sendpacket_t *sp, const u_char *pkt, size_t pktlen, int flush, int cache_file_idx)
|
struct mesa_mpls_hdr
|
||||||
|
{
|
||||||
|
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||||
|
unsigned short mpls_label_low;
|
||||||
|
unsigned char mpls_bls : 1; /* bottom of label stack */
|
||||||
|
unsigned char mpls_exp : 3;
|
||||||
|
unsigned char mpls_label_high : 4;
|
||||||
|
unsigned char mpls_ttl;
|
||||||
|
#elif __BYTE_ORDER == __BIG_ENDIAN
|
||||||
|
unsigned char mpls_ttl;
|
||||||
|
unsigned char mpls_label_high : 4;
|
||||||
|
unsigned char mpls_exp : 3;
|
||||||
|
unsigned char mpls_bls : 1; /* bottom of label stack */
|
||||||
|
unsigned short mpls_label_low;
|
||||||
|
#else
|
||||||
|
#error "Please check <endian.h>"
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
struct mesa_pppoe_session_hdr
|
||||||
|
{
|
||||||
|
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||||
|
unsigned int ver : 4;
|
||||||
|
unsigned int type : 4;
|
||||||
|
#elif __BYTE_ORDER == __BIG_ENDIAN
|
||||||
|
unsigned int type : 4;
|
||||||
|
unsigned int ver : 4;
|
||||||
|
#else
|
||||||
|
#error "Please check <endian.h>"
|
||||||
|
#endif
|
||||||
|
unsigned char code;
|
||||||
|
unsigned short session_id;
|
||||||
|
unsigned short len;
|
||||||
|
/* to do:
|
||||||
|
pppӦ<70>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD>Ϊһ<CEAA><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, Ϊ<>˼<CBBC><F2BBAFB4><EFBFBD>, ǿ<>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD><EFBFBD>PPPOE_SES<45><53><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>,
|
||||||
|
<09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>PPPЭ<50>̹<EFBFBD><CCB9><EFBFBD>, <20>˽ṹ<CBBD><E1B9B9>Ҫ<EFBFBD>Ķ<EFBFBD>.
|
||||||
|
*/
|
||||||
|
unsigned short ppp_protocol;
|
||||||
|
} __attribute__((packed, aligned(1)));
|
||||||
|
|
||||||
|
#define PPP_PROTOCOL_IPv4 (0x0021)
|
||||||
|
|
||||||
|
static const u_char *find_iphdr(const u_char *pkt, size_t pktlen, const u_char *this_layer_data, u_short this_layer_type)
|
||||||
|
{
|
||||||
|
if (pkt == NULL || pktlen <= 0 || this_layer_data == NULL)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if(this_layer_data - pkt >= pktlen)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
u_short proto_type = 0;
|
||||||
|
struct mesa_mpls_hdr *this_mpls_hdr = NULL;
|
||||||
|
struct mesa_pppoe_session_hdr * ppp_hdr= NULL;
|
||||||
|
|
||||||
|
switch (this_layer_type)
|
||||||
|
{
|
||||||
|
|
||||||
|
case ETH_P_IP:
|
||||||
|
case ETH_P_IPV6:
|
||||||
|
return this_layer_data;
|
||||||
|
|
||||||
|
case ETH_P_8021Q:
|
||||||
|
proto_type = *((unsigned short *)((char *)this_layer_data + 2));
|
||||||
|
return find_iphdr(pkt, pktlen, this_layer_data + 4, ntohs(proto_type));
|
||||||
|
|
||||||
|
case ETH_P_MPLS_UC:
|
||||||
|
this_mpls_hdr = (struct mesa_mpls_hdr *)this_layer_data;
|
||||||
|
if (1 != this_mpls_hdr->mpls_bls)
|
||||||
|
{
|
||||||
|
return find_iphdr(pkt, pktlen, this_layer_data + 4, ETH_P_MPLS_UC);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return this_layer_data+4;
|
||||||
|
}
|
||||||
|
|
||||||
|
case ETH_P_PPP_SES:
|
||||||
|
ppp_hdr = (struct mesa_pppoe_session_hdr *)this_layer_data;
|
||||||
|
if (PPP_PROTOCOL_IPv4 == ntohs(ppp_hdr->ppp_protocol))
|
||||||
|
{
|
||||||
|
return this_layer_data+8;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int stream_burst(sendpacket_t *sp, const u_char *pkt, size_t pktlen, int flush, int cache_file_idx)
|
||||||
{
|
{
|
||||||
u_char *pdata;
|
u_char *pdata;
|
||||||
MESA_fixed_qelem_t *q_obj;
|
MESA_fixed_qelem_t *q_obj;
|
||||||
@@ -1435,9 +1526,11 @@ int stream_burst(sendpacket_t *sp, const u_char *pkt, size_t pktlen, int flush,
|
|||||||
}
|
}
|
||||||
|
|
||||||
process_bar_print(pktlen, options.files[cache_file_idx]);
|
process_bar_print(pktlen, options.files[cache_file_idx]);
|
||||||
|
|
||||||
struct ip *iphdr = (struct ip *)(pkt + 14);
|
|
||||||
|
|
||||||
|
//struct ip *iphdr = (struct ip *)(pkt + 14);
|
||||||
|
struct ethhdr * eth = (struct ethhdr *)pkt;
|
||||||
|
struct ip *iphdr = NULL;
|
||||||
|
|
||||||
if(1 == flush) /* ԭʼ<D4AD><CABC><EFBFBD>Ѷ<EFBFBD><D1B6><EFBFBD>, ǿ<><C7BF>ˢ<EFBFBD>¶<EFBFBD><C2B6><EFBFBD><EFBFBD><EFBFBD>ʣ<EFBFBD><CAA3><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD> */
|
if(1 == flush) /* ԭʼ<D4AD><CABC><EFBFBD>Ѷ<EFBFBD><D1B6><EFBFBD>, ǿ<><C7BF>ˢ<EFBFBD>¶<EFBFBD><C2B6><EFBFBD><EFBFBD><EFBFBD>ʣ<EFBFBD><CAA3><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD> */
|
||||||
{
|
{
|
||||||
if(options.pkt_distance > 0)
|
if(options.pkt_distance > 0)
|
||||||
@@ -1456,6 +1549,21 @@ int stream_burst(sendpacket_t *sp, const u_char *pkt, size_t pktlen, int flush,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(pkt != NULL && pktlen > 14)
|
||||||
|
{
|
||||||
|
iphdr=find_iphdr(pkt, pktlen, (pkt + 14), ntohs(eth->h_proto));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (iphdr == NULL)
|
||||||
|
{
|
||||||
|
if ((options.stream_multiple != 0) && (options.verbose != 0))
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Not support encap pkt, cannot find iphdr%d\n");
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ֧<><D6A7>TCP<43><50>UDP, GRE, IPinIPЭ<50><D0AD> */
|
/* ֧<><D6A7>TCP<43><50>UDP, GRE, IPinIPЭ<50><D0AD> */
|
||||||
if((iphdr->ip_p != IPPROTO_TCP)
|
if((iphdr->ip_p != IPPROTO_TCP)
|
||||||
&& (iphdr->ip_p != IPPROTO_UDP)
|
&& (iphdr->ip_p != IPPROTO_UDP)
|
||||||
@@ -1480,7 +1588,7 @@ int stream_burst(sendpacket_t *sp, const u_char *pkt, size_t pktlen, int flush,
|
|||||||
for(i = 0; i < options.stream_multiple; i++)
|
for(i = 0; i < options.stream_multiple; i++)
|
||||||
{
|
{
|
||||||
memcpy(pbuf, pkt, pktlen);
|
memcpy(pbuf, pkt, pktlen);
|
||||||
stream_edit_addr(pbuf, i+1);
|
stream_edit_addr(pbuf, i+1, iphdr);
|
||||||
MESA_fixed_q_join_tail(&pkt_queue[i], pbuf, pktlen);
|
MESA_fixed_q_join_tail(&pkt_queue[i], pbuf, pktlen);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1501,8 +1609,8 @@ int stream_burst(sendpacket_t *sp, const u_char *pkt, size_t pktlen, int flush,
|
|||||||
/* <20><><EFBFBD><EFBFBD>û<EFBFBD>а<EFBFBD><D0B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, ֱ<>ӷ<EFBFBD><D3B7><EFBFBD>N<EFBFBD><4E><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD><EFBFBD> */
|
/* <20><><EFBFBD><EFBFBD>û<EFBFBD>а<EFBFBD><D0B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, ֱ<>ӷ<EFBFBD><D3B7><EFBFBD>N<EFBFBD><4E><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD><EFBFBD> */
|
||||||
for(i = 0; i < options.stream_multiple; i++)
|
for(i = 0; i < options.stream_multiple; i++)
|
||||||
{
|
{
|
||||||
//memcpy(pbuf, pkt, pktlen);
|
memcpy(pbuf, pkt, pktlen);
|
||||||
//stream_edit_addr(pbuf, i+1); /* <20>ں<EFBFBD><DABA><EFBFBD><EFBFBD>ڲ<EFBFBD><DAB2>İ<DEB8>ͷIP */
|
stream_edit_addr(pbuf, i+1, iphdr); /* <20>ں<EFBFBD><DABA><EFBFBD><EFBFBD>ڲ<EFBFBD><DAB2>İ<DEB8>ͷIP */
|
||||||
stream_burst_send_pkt(sp, pkt, pktlen);
|
stream_burst_send_pkt(sp, pkt, pktlen);
|
||||||
pkts_sent ++;
|
pkts_sent ++;
|
||||||
bytes_sent += pktlen;
|
bytes_sent += pktlen;
|
||||||
|
|||||||
Reference in New Issue
Block a user