Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR #478 - skip feature rebase 4.5.0 #858

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/send_packets.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@
* what to do with each packet
*/
void
send_packets(tcpreplay_t *ctx, pcap_t *pcap, int idx)

Check warning on line 336 in src/send_packets.c

View workflow job for this annotation

GitHub Actions / cpp-linter

src/send_packets.c:336:1 [readability-function-cognitive-complexity]

function 'send_packets' has cognitive complexity of 156 (threshold 25)
{
struct timespec now, print_delta, last_pkt_ts;
tcpreplay_opt_t *options = ctx->options;
Expand Down Expand Up @@ -381,6 +381,16 @@
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 @@
(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
Loading