diff --git a/src/send_packets.c b/src/send_packets.c index 788341b4..59585eb0 100644 --- a/src/send_packets.c +++ b/src/send_packets.c @@ -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 @@ -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 diff --git a/src/tcpreplay_api.c b/src/tcpreplay_api.c index 453b92d7..38b16bd0 100644 --- a/src/tcpreplay_api.c +++ b/src/tcpreplay_api.c @@ -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; diff --git a/src/tcpreplay_api.h b/src/tcpreplay_api.h index 6cff96b7..782f9269 100644 --- a/src/tcpreplay_api.h +++ b/src/tcpreplay_api.h @@ -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; diff --git a/src/tcpreplay_opts.def b/src/tcpreplay_opts.def index e3536fde..12e6e79a 100644 --- a/src/tcpreplay_opts.def +++ b/src/tcpreplay_opts.def @@ -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;