Skip to content

Commit

Permalink
Merge pull request #478 from Exchizz/master
Browse files Browse the repository at this point in the history
Add --skip-pkts and --skip-to-secs to allow skipping packets when replaying
  • Loading branch information
fklassen authored Jun 1, 2024
2 parents 914a62e + 01b46d8 commit 309e6f3
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/send_packets.c
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,16 @@ send_packets(tcpreplay_t *ctx, pcap_t *pcap, int idx)
prev_packet = NULL;
}

/* SKIP PACKETS
* Looping over packets to skip
*/
if(ctx->options->skip_pkts > 0) {
for (uint32_t i = 0; i < ctx->options->skip_pkts && !ctx->abort &&
(pktdata = get_next_packet(options, pcap, &pkthdr, idx, prev_packet)) != NULL; i++) {
}
}


/* MAIN LOOP
* Keep sending while we have packets or until
* we've sent enough packets
Expand All @@ -389,6 +399,11 @@ send_packets(tcpreplay_t *ctx, pcap_t *pcap, int idx)
(pktdata = get_next_packet(options, pcap, &pkthdr, idx, prev_packet)) != NULL) {
struct timespec pkthdr_ts;
TIMEVAL_AS_TIMESPEC_SET(&pkthdr_ts, &pkthdr.ts); // libpcap puts nanosec values in tv_usec

/* Skip packets */
if(timerisset(&(ctx->options->skip_to)) && timercmp(&ctx->options->skip_to, &(pkthdr.ts), >)){
continue; /* Skip packet */
}
now_is_now = false;
packetnum++;
#if defined TCPREPLAY || defined TCPREPLAY_EDIT
Expand Down
3 changes: 3 additions & 0 deletions src/tcpreplay_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ tcpreplay_post_args(tcpreplay_t *ctx, int argc)
options->loopdelay_ms = OPT_VALUE_LOOPDELAY_MS;
options->loopdelay_ns = OPT_VALUE_LOOPDELAY_NS;

options->skip_pkts = OPT_VALUE_SKIP_PKTS;
options->skip_to.tv_sec = OPT_VALUE_SKIP_TO_SECS;

if (HAVE_OPT(LIMIT))
options->limit_send = OPT_VALUE_LIMIT;

Expand Down
4 changes: 4 additions & 0 deletions src/tcpreplay_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ typedef struct tcpreplay_opt_s {
u_int32_t loopdelay_ms;
u_int32_t loopdelay_ns;

/* Skip packets */
u_int32_t skip_pkts;
struct timeval skip_to;

int stats;
bool use_pkthdr_len;

Expand Down
18 changes: 18 additions & 0 deletions src/tcpreplay_opts.def
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,24 @@ flag = {
doc = "";
};

flag = {
name = skip-pkts;
arg-type = number;
arg-range = "0->";
descrip = "Skip X packets into a packet file";
arg-default = 0;
doc = "";
};


flag = {
name = skip-to-secs;
arg-type = number;
descrip = "Skip X seconds since linux epoch into a packet file";
arg-default = 0;
doc = "";
};

flag = {
name = loopdelay-ms;
flags-cant = loopdelay-ns;
Expand Down

0 comments on commit 309e6f3

Please sign in to comment.