Skip to content

Commit

Permalink
Prevent multiple interfaces with --netmap option. Ensure that TX loop…
Browse files Browse the repository at this point in the history
… can be interrupted. This closes appneta#79
  • Loading branch information
fklassen committed Jul 23, 2014
1 parent 1bc471e commit 13f4d3a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
1 change: 1 addition & 0 deletions docs/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Seg fault on some IPv6 files when using -C option with tcprewrite (#83)
- Support for PF_RING DNA version of libpcap (#82)
- Fix segfault when using '-F pad' (#80)
- Disallow netmap on multiple interfaces (#79)
- Fix build for FreeBSD version 8.4 (#78)

06/19/2014 Version 4.0.5-beta1
Expand Down
22 changes: 14 additions & 8 deletions src/common/sendpacket.c
Original file line number Diff line number Diff line change
Expand Up @@ -458,19 +458,19 @@ sendpacket(sendpacket_t *sp, const u_char *data, size_t len, struct pcap_pkthdr
case SP_TYPE_NETMAP:
#ifdef HAVE_NETMAP
txring = NETMAP_TXRING(sp->nm_if, 0);
avail = get_netmap_buf_avail(txring);
while (avail == 0) {
while ((avail = get_netmap_buf_avail(txring)) == 0) {
struct pollfd pfd;

/* send TX interrupt signal just in case */
ioctl(sp->handle.fd, NIOCTXSYNC, NULL);

if (sp->abort)
return retcode;

pfd.fd = sp->handle.fd;
pfd.events = POLLOUT;
pfd.revents = 0;
if (poll(&pfd, 1, 1000) <= 0) {
if (sp->abort)
return retcode;

dbgx(2, "netmap timeout empty=%d avail=%u bufsize=%d\n",
NETMAP_TX_RING_EMPTY(txring),
avail, txring->nr_buf_size);
Expand All @@ -483,7 +483,6 @@ sendpacket(sendpacket_t *sp, const u_char *data, size_t len, struct pcap_pkthdr
* of the TX queue.
*/
ioctl(sp->handle.fd, NIOCTXSYNC, NULL);
avail = get_netmap_buf_avail(txring);

dbgx(2, "netmap poll empty=%d avail=%u bufsize=%d\n",
NETMAP_TX_RING_EMPTY(txring),
Expand All @@ -495,6 +494,7 @@ sendpacket(sendpacket_t *sp, const u_char *data, size_t len, struct pcap_pkthdr
*/
cur = txring->cur;
slot = &txring->slot[cur];
slot->flags = 0;
p = NETMAP_BUF(txring, slot->buf_idx);
memcpy(p, data, min(len, txring->nr_buf_size));
slot->len = len;
Expand Down Expand Up @@ -1116,14 +1116,20 @@ sendpacket_open_netmap(const char *device, char *errbuf)
goto NM_DO_IOCTL_FAILED;
#endif
}

if(sp->abort)
goto NETMAP_ABORT;

notice("done!");

return sp;

NM_DO_IOCTL_FAILED:
snprintf (errbuf, SENDPACKET_ERRBUF_SIZE, "nm_do_ioctl: %s", strerror (errno));
NETMAP_IF_NOT_RUNNING:
fprintf(stderr, " failed!!\nSwitching network driver for %s to normal mode... ",
notice("failed!");
NETMAP_ABORT:
fprintf(stderr, " Switching network driver for %s to normal mode... ",
sp->device);
fflush(NULL);
munmap(sp->mmap_addr, sp->mmap_size);
Expand All @@ -1136,7 +1142,7 @@ sendpacket_open_netmap(const char *device, char *errbuf)
OPEN_FAILED:
safe_free(sp);

notice("failed!");
notice("done!");
return NULL;
}
#endif /* HAVE_NETMAP */
Expand Down
1 change: 1 addition & 0 deletions src/signal_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ abort_handler(int signo)
if (signo == SIGINT && ctx) {
notice(" User interrupt...");
ctx->abort = true;
tcpreplay_abort(ctx);
}
}

10 changes: 10 additions & 0 deletions src/tcpreplay_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,16 @@ tcpreplay_post_args(tcpreplay_t *ctx, int argc)

if (HAVE_OPT(NETMAP)) {
#ifdef HAVE_NETMAP
if (HAVE_OPT(INTF2)) {
tcpreplay_seterr(ctx, "%s", "multiple interfaces not supported in netmap mode");
ret = -1;
goto out;
}
if (HAVE_OPT(CACHEFILE)) {
tcpreplay_seterr(ctx, "%s", "--cachefile option not supported in netmap mode");
ret = -1;
goto out;
}
options->netmap = 1;
ctx->sp_type = SP_TYPE_NETMAP;
#else
Expand Down

0 comments on commit 13f4d3a

Please sign in to comment.