Skip to content

Commit 017479a

Browse files
committed
appneta#235 fix 'first_packet' logic
1 parent e615e96 commit 017479a

File tree

4 files changed

+22
-19
lines changed

4 files changed

+22
-19
lines changed

src/common/sendpacket.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ struct sendpacket_s {
125125
sendpacket_type_t handle_type;
126126
union sendpacket_handle handle;
127127
struct tcpr_ether_addr ether;
128+
#if defined HAVE_QUICK_TX || defined HAVE_NETMAP
129+
int first_packet;
130+
#endif
131+
128132
#ifdef HAVE_QUICK_TX
129133
struct quick_tx* qtx_dev;
130134
#endif /* HAVE_QUICK_TX */

src/send_packets.c

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ fast_edit_packet_dl(struct pcap_pkthdr *pkthdr, u_char **pktdata,
235235
*dst_ptr = htonl(dst_ip);
236236
}
237237

238+
#if defined HAVE_QUICK_TX || defined HAVE_NETMAP
238239
static inline void wake_send_queues(sendpacket_t *sp, tcpreplay_opt_t *options)
239240
{
240241
#ifdef HAVE_QUICK_TX
@@ -247,6 +248,7 @@ static inline void wake_send_queues(sendpacket_t *sp, tcpreplay_opt_t *options)
247248
ioctl(sp->handle.fd, NIOCTXSYNC, NULL); /* flush TX buffer */
248249
#endif
249250
}
251+
#endif /* HAVE_QUICK_TX || HAVE_NETMAP */
250252

251253
static inline void
252254
fast_edit_packet(struct pcap_pkthdr *pkthdr, u_char **pktdata,
@@ -488,7 +490,7 @@ send_packets(tcpreplay_t *ctx, pcap_t *pcap, int idx)
488490
COUNTER iteration = ctx->iteration;
489491
bool unique_ip = options->unique_ip;
490492
bool preload = options->file_cache[idx].cached;
491-
bool top_speed = options->speed.mode == speed_topspeed;
493+
bool top_speed = (options->speed.mode == speed_topspeed);
492494
bool now_is_now = false;
493495

494496
start_us = TIMEVAL_TO_MICROSEC(&ctx->stats.start_time);
@@ -580,7 +582,7 @@ send_packets(tcpreplay_t *ctx, pcap_t *pcap, int idx)
580582
* This also sets skip_length which will avoid timestamping for
581583
* a given number of packets.
582584
*/
583-
calc_sleep_time(ctx, (struct timeval *)&pkthdr.ts, &ctx->stats.last_time, pktlen, sp, packetnum,
585+
calc_sleep_time(ctx, &pkthdr.ts, &ctx->stats.last_time, pktlen, sp, packetnum,
584586
&ctx->stats.end_time, &start_us, &skip_length);
585587

586588
/*
@@ -634,14 +636,12 @@ send_packets(tcpreplay_t *ctx, pcap_t *pcap, int idx)
634636
}
635637
}
636638

637-
if (sp == ctx->intf1 && ctx->first_time_intf1) {
639+
#if defined HAVE_QUICK_TX || defined HAVE_NETMAP
640+
if (sp->first_packet) {
638641
wake_send_queues(sp, options);
639-
ctx->first_time_intf1 = 0;
640-
} else if (sp == ctx->intf2 && ctx->first_time_intf2) {
641-
wake_send_queues(sp, options);
642-
ctx->first_time_intf2 = 0;
642+
sp->first_packet = false;
643643
}
644-
644+
#endif
645645
/* stop sending based on the duration limit... */
646646
if ((end_us > 0 && TIMEVAL_TO_MICROSEC(&now) > end_us) ||
647647
/* ... or stop sending based on the limit -L? */
@@ -699,8 +699,7 @@ send_dual_packets(tcpreplay_t *ctx, pcap_t *pcap1, int cache_file_idx1, pcap_t *
699699
COUNTER start_us;
700700
COUNTER end_us;
701701
COUNTER skip_length = 0;
702-
bool top_speed = options->speed.mode == speed_topspeed ||
703-
(options->speed.mode == speed_mbpsrate && !options->speed.speed);
702+
bool top_speed = (options->speed.mode == speed_topspeed);
704703
bool now_is_now = false;
705704

706705
start_us = TIMEVAL_TO_MICROSEC(&ctx->stats.start_time);
@@ -824,7 +823,7 @@ send_dual_packets(tcpreplay_t *ctx, pcap_t *pcap1, int cache_file_idx1, pcap_t *
824823
* This also sets skip_length which will avoid timestamping for
825824
* a given number of packets.
826825
*/
827-
calc_sleep_time(ctx, (struct timeval *)&pkthdr_ptr->ts, &ctx->stats.last_time, pktlen, sp, packetnum,
826+
calc_sleep_time(ctx, &pkthdr_ptr->ts, &ctx->stats.last_time, pktlen, sp, packetnum,
828827
&ctx->stats.end_time, &start_us, &skip_length);
829828

830829
/*
@@ -875,13 +874,12 @@ send_dual_packets(tcpreplay_t *ctx, pcap_t *pcap1, int cache_file_idx1, pcap_t *
875874
}
876875
}
877876

878-
if (sp == ctx->intf1 && ctx->first_time_intf1) {
877+
#if defined HAVE_QUICK_TX || defined HAVE_NETMAP
878+
if (sp->first_packet) {
879879
wake_send_queues(sp, options);
880-
ctx->first_time_intf1 = 0;
881-
} else if (sp == ctx->intf2 && ctx->first_time_intf2) {
882-
wake_send_queues(sp, options);
883-
ctx->first_time_intf2 = 0;
880+
sp->first_packet = false;
884881
}
882+
#endif
885883

886884
/* get the next packet for this file handle depending on which we last used */
887885
if (sp == ctx->intf2) {
@@ -1077,7 +1075,8 @@ static void calc_sleep_time(tcpreplay_t *ctx, struct timeval *pkt_time,
10771075
*/
10781076
if (options->speed.mode == speed_packetrate && options->speed.pps_multi) {
10791077
ctx->skip_packets = options->speed.pps_multi - 1;
1080-
if (ctx->first_time_intf1) {
1078+
if (ctx->first_time) {
1079+
ctx->first_time = false;
10811080
return;
10821081
}
10831082
}

src/tcpreplay_api.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ tcpreplay_init()
127127
ctx->intf1dlt = -1;
128128
ctx->intf2dlt = -1;
129129
ctx->abort = false;
130+
ctx->first_time = true;
130131
return ctx;
131132
}
132133

src/tcpreplay_api.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,7 @@ typedef struct tcpreplay_s {
188188
/* sleep helpers */
189189
struct timespec nap;
190190
uint32_t skip_packets;
191-
int first_time_intf1;
192-
int first_time_intf2;
191+
bool first_time;
193192

194193
/* counter stats */
195194
tcpreplay_stats_t stats;

0 commit comments

Comments
 (0)