调整edit_addr逻辑
This commit is contained in:
1
clean.sh
1
clean.sh
@@ -1,2 +1,3 @@
|
|||||||
make clean
|
make clean
|
||||||
make distclean
|
make distclean
|
||||||
|
rm tcpburst clean
|
||||||
|
|||||||
@@ -1209,7 +1209,7 @@ static inline int stream_addr_cmp_udp(struct ip *iphdr, struct udphdr *udphdr)
|
|||||||
为了不从新计算校验和,以达到较高的发送速率,
|
为了不从新计算校验和,以达到较高的发送速率,
|
||||||
改地址时,仅对IP地址进行修改,增加和减少的值要相等.
|
改地址时,仅对IP地址进行修改,增加和减少的值要相等.
|
||||||
*/
|
*/
|
||||||
static int stream_edit_addr(u_char *pkt, int differ, struct ip* iphdr)
|
static int stream_edit_addr(struct ip* raw_iphdr, int differ, struct ip* iphdr)
|
||||||
{
|
{
|
||||||
//struct ip *iphdr;
|
//struct ip *iphdr;
|
||||||
struct tcphdr *tcphdr;
|
struct tcphdr *tcphdr;
|
||||||
@@ -1219,24 +1219,10 @@ static int stream_edit_addr(u_char *pkt, int differ, struct ip* iphdr)
|
|||||||
|
|
||||||
//iphdr = (struct ip *)(pkt + 14);
|
//iphdr = (struct ip *)(pkt + 14);
|
||||||
|
|
||||||
if(IPPROTO_TCP == iphdr->ip_p)
|
if(IPPROTO_TCP == raw_iphdr->ip_p || IPPROTO_UDP == raw_iphdr->ip_p)
|
||||||
{
|
{
|
||||||
tcphdr = (struct tcphdr *)(pkt + 14 + iphdr->ip_hl*4);
|
tcphdr = (struct tcphdr *)((char*)iphdr + iphdr->ip_hl*4);
|
||||||
if(stream_addr_cmp_tcp(iphdr, tcphdr) < 0)
|
if(stream_addr_cmp_tcp(raw_iphdr, tcphdr) < 0)
|
||||||
{
|
|
||||||
iphdr->ip_src.s_addr -= differ;
|
|
||||||
iphdr->ip_dst.s_addr += differ;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
iphdr->ip_src.s_addr += differ;
|
|
||||||
iphdr->ip_dst.s_addr -= differ;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(IPPROTO_UDP == iphdr->ip_p)
|
|
||||||
{
|
|
||||||
udphdr = (struct udphdr *)(pkt + 14 + iphdr->ip_hl*4);
|
|
||||||
if(stream_addr_cmp_tcp(iphdr, udphdr) < 0)
|
|
||||||
{
|
{
|
||||||
iphdr->ip_src.s_addr -= differ;
|
iphdr->ip_src.s_addr -= differ;
|
||||||
iphdr->ip_dst.s_addr += differ;
|
iphdr->ip_dst.s_addr += differ;
|
||||||
@@ -1531,6 +1517,7 @@ static const u_char *find_iphdr(const u_char *pkt, size_t pktlen, const u_char *
|
|||||||
//struct ip *iphdr = (struct ip *)(pkt + 14);
|
//struct ip *iphdr = (struct ip *)(pkt + 14);
|
||||||
struct ethhdr * eth = (struct ethhdr *)pkt;
|
struct ethhdr * eth = (struct ethhdr *)pkt;
|
||||||
struct ip *iphdr = NULL;
|
struct ip *iphdr = NULL;
|
||||||
|
struct ip *t_iphdr = NULL;
|
||||||
|
|
||||||
if(1 == flush) /* 原始包已读完, 强制刷新队列中剩余数据包 */
|
if(1 == flush) /* 原始包已读完, 强制刷新队列中剩余数据包 */
|
||||||
{
|
{
|
||||||
@@ -1583,13 +1570,17 @@ static const u_char *find_iphdr(const u_char *pkt, size_t pktlen, const u_char *
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(options.stream_multiple > 0)
|
||||||
|
{
|
||||||
|
memcpy(pbuf, pkt, pktlen);
|
||||||
|
t_iphdr = (struct ip *)(pbuf+((const u_char*)iphdr - pkt));
|
||||||
|
}
|
||||||
if(options.pkt_distance > 0)
|
if(options.pkt_distance > 0)
|
||||||
{
|
{
|
||||||
/* 暂存到队列 */
|
/* 暂存到队列 */
|
||||||
for(i = 0; i < options.stream_multiple; i++)
|
for(i = 0; i < options.stream_multiple; i++)
|
||||||
{
|
{
|
||||||
memcpy(pbuf, pkt, pktlen);
|
stream_edit_addr(iphdr, i+1, t_iphdr);
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1610,9 +1601,8 @@ static const u_char *find_iphdr(const u_char *pkt, size_t pktlen, const u_char *
|
|||||||
/* 如果没有包间距需求, 直接发送N倍数据包即可 */
|
/* 如果没有包间距需求, 直接发送N倍数据包即可 */
|
||||||
for(i = 0; i < options.stream_multiple; i++)
|
for(i = 0; i < options.stream_multiple; i++)
|
||||||
{
|
{
|
||||||
memcpy(pbuf, pkt, pktlen);
|
stream_edit_addr(iphdr, i+1, t_iphdr); /* 在函数内部修改包头IP */
|
||||||
stream_edit_addr(pbuf, i+1, iphdr); /* 在函数内部修改包头IP */
|
stream_burst_send_pkt(sp, pbuf, 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