summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitattributes1
-rw-r--r--.github/workflows/build.yml53
-rw-r--r--.gitignore1
-rw-r--r--.travis.yml37
-rw-r--r--AUTHORS1
-rw-r--r--Cmds3
-rw-r--r--Makefile4
-rw-r--r--README.devel9
-rw-r--r--astraceroute.88
-rw-r--r--astraceroute.c59
-rw-r--r--bpfc.c3
-rwxr-xr-xconfigure4
-rw-r--r--cookie.c1
-rw-r--r--curvetun.c2
-rw-r--r--dev.c2
-rw-r--r--flowtop.c3
-rw-r--r--ifpps.c3
-rw-r--r--mausezahn/Makefile2
-rw-r--r--netsniff-ng.c16
-rw-r--r--staging/cli.c13
-rw-r--r--staging/cli.h20
-rw-r--r--staging/dns.c2
-rw-r--r--staging/llist.c2
-rw-r--r--staging/llist.h4
-rw-r--r--staging/mausezahn.c64
-rw-r--r--staging/mops.c5
-rw-r--r--staging/mops.h8
-rw-r--r--staging/mz.h79
-rw-r--r--staging/rcv_rtp.c19
-rw-r--r--staging/rtp.c1
-rw-r--r--trafgen.824
-rw-r--r--trafgen.c85
32 files changed, 327 insertions, 211 deletions
diff --git a/.gitattributes b/.gitattributes
index 86433aa..cfcdd7f 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -8,4 +8,3 @@ netsniff-ng/.gitignore export-ignore
trafgen/.gitignore export-ignore
.gitattributes export-ignore
.gitignore export-ignore
-.travis.yml export-ignore
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
new file mode 100644
index 0000000..a44c0b5
--- /dev/null
+++ b/.github/workflows/build.yml
@@ -0,0 +1,53 @@
+name: Build
+
+on:
+ push:
+ branches:
+ - master
+ pull_request:
+ branches:
+ - master
+
+jobs:
+ build:
+ strategy:
+ matrix:
+ CC: [gcc, clang]
+ runs-on: ubuntu-latest
+
+ steps:
+ - name: Install dependencies
+ run: |
+ sudo apt-get install -y --no-install-recommends libnl-3-dev libnl-genl-3-dev libnl-route-3-dev libnetfilter-conntrack-dev libgeoip-dev liburcu-dev libpcap-dev libnet1-dev libcli-dev libsodium-dev clang
+
+ - name: Check out code
+ uses: actions/checkout@v2
+
+ - name: Build (with all features)
+ run: |
+ CC=${{ matrix.CC }} ./configure
+ make CC=${{ matrix.CC }}
+
+ - name: Build (without GeoIP)
+ run: |
+ make clean
+ CC=${{ matrix.CC }} ./configure --disable-geoip
+ make CC=${{ matrix.CC }}
+
+ - name: Build (without zlib)
+ run: |
+ make clean
+ CC=${{ matrix.CC }} ./configure --disable-zlib
+ make CC=${{ matrix.CC }}
+
+ - name: Build (without GeoIP and zlib)
+ run: |
+ make clean
+ CC=${{ matrix.CC }} ./configure --disable-geoip --disable-zlib
+ make CC=${{ matrix.CC }}
+
+ - name: Build (without libnl)
+ run: |
+ make clean
+ CC=${{ matrix.CC }} ./configure --disable-libnl
+ make CC=${{ matrix.CC }}
diff --git a/.gitignore b/.gitignore
index 906d2af..62af7f2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -61,4 +61,3 @@ config.log
# Excluded from ignorance
!.gitattributes
!.gitignore
-!.travis.yml
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index aca9e1a..0000000
--- a/.travis.yml
+++ /dev/null
@@ -1,37 +0,0 @@
-language: c
-compiler:
- - gcc
- - clang
-sudo: false
-
-env:
- global:
- - secure: "fTrjH4X1FJaCMAZXVW+sQBuKPr2C+w/pEkIl8FVQZvGxsgpw3OQR28stWnT7VhSuRExUqxEmKcIZgJmU9OAlF/K5ZQkNnUdyQgeiNdhPEMhTCQ3eZv8Ar60UVtmvuzWUN4BP1TUHoBCjq4Wxt1t4QN49P1T7RdjEawCfh+OFZ9s="
-
-addons:
- apt:
- packages:
- - libnl-3-dev
- - libnl-genl-3-dev
- - libnl-route-3-dev
- - libnetfilter-conntrack-dev
- - libgeoip-dev
- - liburcu-dev
- - libpcap-dev
- - libnet1-dev
- - libcli-dev
- coverity_scan:
- project:
- name: "netsniff-ng/netsniff-ng"
- description: "Build submitted via Travis CI"
- notification_email: tklauser@distanz.ch
- build_command_prepend: "./configure && make clean"
- build_command: "make"
- branch_pattern: coverity_scan
-
-script:
- - CC=$CC ./configure && make CC=$CC
- - CC=$CC ./configure --disable-geoip && make clean && make CC=$CC
- - CC=$CC ./configure --disable-zlib && make clean && make CC=$CC
- - CC=$CC ./configure --disable-geoip --disable-zlib && make clean && make CC=$CC
- - CC=$CC ./configure --disable-libnl && make clean && make CC=$CC
diff --git a/AUTHORS b/AUTHORS
index 0c3737c..5e9ad69 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -37,6 +37,7 @@ commits in the netsniff-ng repository:
* Quentin Chateau <quentin.chateau@gmail.com>
* Radoslav Bodo <bodik@cesnet.cz>
* Reiner Herrmann <reiner@reiner-h.de>
+ * Rosen Penev <rosenp@gmail.com>
* Stephen Wadeley <swadeley@redhat.com>
* Teguh <info@egeektronic.com>
* Thomas Fleischmann <thomas.fleischmann.08@googlemail.com>
diff --git a/Cmds b/Cmds
index e590b38..3df23b8 100644
--- a/Cmds
+++ b/Cmds
@@ -44,7 +44,8 @@ ifeq ("$(origin PREFIX)", "$(filter $(origin PREFIX), file command line)")
INSTX = echo -e " INST\t$(1)" && install -d $(2) && \
install -C $(1) $(2)/$(shell basename $(1))
else
- INSTX = echo -e " INST\t$(1)" && install -C $(1) $(2)/$(shell basename $(1))
+ INSTX = echo -e " INST\t$(1)" && install -d $(2) && \
+ install -C $(1) $(2)/$(shell basename $(1))
endif
MKDIR = echo -e " MKDIR\t$(1)" && mkdir -p $(1)
diff --git a/Makefile b/Makefile
index 1095ee1..3ca0705 100644
--- a/Makefile
+++ b/Makefile
@@ -15,9 +15,9 @@ endif
VERSION = 0
PATCHLEVEL = 6
-SUBLEVEL = 6
+SUBLEVEL = 8
EXTRAVERSION =
-NAME = Syro
+NAME = Flutternozzle
TOOLS ?= $(CONFIG_TOOLS)
diff --git a/README.devel b/README.devel
index 021b18f..a98a05f 100644
--- a/README.devel
+++ b/README.devel
@@ -1,8 +1,3 @@
-A Travis CI instance for continuous integration testing of netsniff-ng
-can be found here:
-
- https://travis-ci.org/netsniff-ng/netsniff-ng
-
An analysis by the Coverity Scanner is run occasionally against the source of
netsniff-ng. The corresponding scan reports can be found here:
@@ -12,6 +7,4 @@ If you are a project admin, use the command
`make COV_EMAIL=<email> COV_PASSWD=<passwd> coverity'
-to trigger a new scan yourself. Alternatively, the Coverity integration of
-Travis CI can be used by pushing to the branch 'coverity_scan' to trigger a new
-analysis.
+to trigger a new scan yourself.
diff --git a/astraceroute.8 b/astraceroute.8
index fc999aa..80d24f0 100644
--- a/astraceroute.8
+++ b/astraceroute.8
@@ -24,9 +24,9 @@ ISP name. astraceroute also displays timing information and reverse DNS data.
Due to astraceroute's configurability, it is also possible to gather some more
useful information about the hop regarding what it does and does not allow to pass
through. This is done by using clear text strings for probing DPIs or
-``great firewalls'' to determine if they will filter out blacklisted critical
-keywords. This tool might be a good start for further in-depth analysis of such
-systems.
+``great firewalls'' to determine if they will filter out blocked critical
+keywords. This tool might be a good start for further in-depth analysis
+of such systems.
.PP
.SH OPTIONS
.TP
@@ -159,7 +159,7 @@ and do a TCP Xmas probe this time.
In this example, we have a Null probe to the remote host netsniff-ng.org, port
80 (default) and this time, we append the cleartext string "censor-me" into the
packet payload to test if a firewall or DPI will let this string pass. Such a trace
-could be done once without, and once with, a blacklisted string to gather possible
+could be done once without and once with a blocked string to gather possible
information about censorship.
.PP
.SH NOTE
diff --git a/astraceroute.c b/astraceroute.c
index 4567d03..d5711fb 100644
--- a/astraceroute.c
+++ b/astraceroute.c
@@ -51,9 +51,9 @@ struct ctx {
char *host, *port, *dev, *payload, *bind_addr;
size_t totlen, rcvlen;
socklen_t sd_len;
- int init_ttl, max_ttl, dns_resolv, queries, timeout;
- int syn, ack, ecn, fin, psh, rst, urg, tos, nofrag, proto, show;
- int dport, latitude;
+ int init_ttl, max_ttl, dport, queries, timeout;
+ int syn, ack, ecn, fin, psh, rst, urg, tos, nofrag, proto;
+ bool do_geo_lookup, do_dns_resolution, do_show_packet;
};
struct proto_ops {
@@ -65,8 +65,8 @@ struct proto_ops {
size_t min_len_tcp, min_len_icmp;
int (*check)(uint8_t *packet, size_t len, int ttl, int id,
const struct sockaddr *src);
- void (*handler)(uint8_t *packet, size_t len, int dns_resolv,
- int latitude);
+ void (*handler)(uint8_t *packet, size_t len, bool do_dns_resolution,
+ bool do_geo_lookup);
};
static sig_atomic_t sigint = 0;
@@ -76,15 +76,15 @@ static int assemble_ipv4(uint8_t *packet, size_t len, int ttl, int proto,
const struct sockaddr *src);
static int check_ipv4(uint8_t *packet, size_t len, int ttl, int id,
const struct sockaddr *ss);
-static void handle_ipv4(uint8_t *packet, size_t len, int dns_resolv,
- int latitude);
+static void handle_ipv4(uint8_t *packet, size_t len, bool do_dns_resolution,
+ bool do_geo_lookup);
static int assemble_ipv6(uint8_t *packet, size_t len, int ttl, int proto,
const struct ctx *ctx, const struct sockaddr *dst,
const struct sockaddr *src);
static int check_ipv6(uint8_t *packet, size_t len, int ttl, int id,
const struct sockaddr *ss);
-static void handle_ipv6(uint8_t *packet, size_t len, int dns_resolv,
- int latitude);
+static void handle_ipv6(uint8_t *packet, size_t len, bool do_dns_resolution,
+ bool do_geo_lookup);
static const char *short_options = "H:p:nNf:m:b:i:d:q:x:SAEFPURt:Gl:hv46X:ZuL";
static const struct option long_options[] = {
@@ -119,7 +119,8 @@ static const struct option long_options[] = {
{NULL, 0, NULL, 0}
};
-static const char *copyright = "Please report bugs to <netsniff-ng@googlegroups.com>\n"
+static const char *copyright =
+ "Please report bugs at https://github.com/netsniff-ng/netsniff-ng/issues\n"
"Copyright (C) 2011-2013 Daniel Borkmann <dborkma@tik.ee.ethz.ch>\n"
"Swiss federal institute of technology (ETH Zurich)\n"
"License: GNU GPL version 2.0\n"
@@ -513,7 +514,7 @@ static int check_ipv4(uint8_t *packet, size_t len, int ttl __maybe_unused,
}
static void handle_ipv4(uint8_t *packet, size_t len __maybe_unused,
- int dns_resolv, int latitude)
+ bool do_dns_resolution, bool do_geo_lookup)
{
char hbuff[NI_MAXHOST];
struct iphdr *iph = (struct iphdr *) packet;
@@ -534,7 +535,7 @@ static void handle_ipv4(uint8_t *packet, size_t len __maybe_unused,
country = geoip4_country_name(&sd);
city = geoip4_city_name(&sd);
- if (dns_resolv) {
+ if (do_dns_resolution) {
hent = gethostbyaddr(&sd.sin_addr, sizeof(sd.sin_addr), PF_INET);
if (hent)
printf(" %s (%s)", hent->h_name, hbuff);
@@ -550,7 +551,7 @@ static void handle_ipv4(uint8_t *packet, size_t len __maybe_unused,
if (city)
printf(", %s", city);
}
- if (latitude)
+ if (do_geo_lookup)
printf(" (%f/%f)", geoip4_latitude(&sd), geoip4_longitude(&sd));
free(city);
@@ -583,7 +584,7 @@ static int check_ipv6(uint8_t *packet, size_t len, int ttl __maybe_unused,
}
static void handle_ipv6(uint8_t *packet, size_t len __maybe_unused,
- int dns_resolv, int latitude)
+ bool do_dns_resolution, bool do_geo_lookup)
{
char hbuff[NI_MAXHOST];
struct ip6_hdr *ip6h = (struct ip6_hdr *) packet;
@@ -604,7 +605,7 @@ static void handle_ipv6(uint8_t *packet, size_t len __maybe_unused,
country = geoip6_country_name(&sd);
city = geoip6_city_name(&sd);
- if (dns_resolv) {
+ if (do_dns_resolution) {
hent = gethostbyaddr(&sd.sin6_addr, sizeof(sd.sin6_addr), PF_INET6);
if (hent)
printf(" %s (%s)", hent->h_name, hbuff);
@@ -620,7 +621,7 @@ static void handle_ipv6(uint8_t *packet, size_t len __maybe_unused,
if (city)
printf(", %s", city);
}
- if (latitude)
+ if (do_geo_lookup)
printf(" (%f/%f)", geoip6_latitude(&sd), geoip6_longitude(&sd));
free(city);
@@ -910,8 +911,8 @@ static int __probe_remote(struct ctx *ctx, int fd, int fd_cap, int ttl,
af_ops[ctx->proto].handler(pkt_rcv + sizeof(struct ethhdr),
ret - sizeof(struct ethhdr),
- ctx->dns_resolv, ctx->latitude);
- if (ctx->show) {
+ ctx->do_dns_resolution, ctx->do_geo_lookup);
+ if (ctx->do_show_packet) {
struct pkt_buff *pkt;
printf("\n");
@@ -951,9 +952,9 @@ static int __process_ttl(struct ctx *ctx, int fd, int fd_cap, int ttl,
if (ret <= 0)
printf("\r%2d: ?[ no answer]", ttl);
- if (ctx->show == 0)
+ if (!ctx->do_show_packet)
printf("\n");
- if (ctx->show && ret <= 0)
+ if (ctx->do_show_packet && ret <= 0)
printf("\n\n");
fflush(stdout);
@@ -983,7 +984,7 @@ static int main_trace(struct ctx *ctx)
ctx->rcvlen = device_mtu(ctx->dev) - sizeof(struct ethhdr);
if (ctx->totlen >= ctx->rcvlen)
- panic("Packet len exceeds device MTU!\n");
+ panic("packet length (%zu) exceeds device MTU (%zu)\n", ctx->totlen, ctx->rcvlen);
pkt_snd = xmalloc(ctx->totlen);
pkt_rcv = xmalloc(ctx->rcvlen);
@@ -1046,7 +1047,7 @@ int main(int argc, char **argv)
ctx.port = xstrdup(optarg);
break;
case 'n':
- ctx.dns_resolv = 0;
+ ctx.do_dns_resolution = false;
break;
case '4':
ctx.proto = IPPROTO_IP;
@@ -1055,10 +1056,10 @@ int main(int argc, char **argv)
ctx.proto = IPPROTO_IPV6;
break;
case 'Z':
- ctx.show = 1;
+ ctx.do_show_packet = true;
break;
case 'N':
- ctx.dns_resolv = 1;
+ ctx.do_dns_resolution = true;
break;
case 'f':
ctx.init_ttl = atoi(optarg);
@@ -1089,7 +1090,7 @@ int main(int argc, char **argv)
help();
break;
case 'L':
- ctx.latitude = 1;
+ ctx.do_geo_lookup = true;
break;
case 'S':
ctx.syn = 1;
@@ -1142,11 +1143,11 @@ int main(int argc, char **argv)
case 'X':
case 't':
case 'l':
- panic("Option -%c requires an argument!\n",
+ panic("option -%c requires an argument!\n",
optopt);
default:
if (isprint(optopt))
- printf("Unknown option character `0x%X\'!\n", optopt);
+ printf("unknown option character '0x%X'!\n", optopt);
die();
}
default:
@@ -1159,9 +1160,9 @@ int main(int argc, char **argv)
help();
if (!device_up_and_running(ctx.dev))
- panic("Networking device not up and running!\n");
+ panic("networking device %s is not up and running\n", ctx.dev);
if (device_mtu(ctx.dev) <= ctx.totlen)
- panic("Packet larger than device MTU!\n");
+ panic("packet length (%zu) exceeds device MTU (%zu)\n", ctx.totlen, device_mtu(ctx.dev));
register_signal(SIGHUP, signal_handler);
register_signal(SIGINT, signal_handler);
diff --git a/bpfc.c b/bpfc.c
index 562c463..5dd84cf 100644
--- a/bpfc.c
+++ b/bpfc.c
@@ -33,7 +33,8 @@ static const struct option long_options[] = {
{NULL, 0, NULL, 0}
};
-static const char *copyright = "Please report bugs to <netsniff-ng@googlegroups.com>\n"
+static const char *copyright =
+ "Please report bugs at https://github.com/netsniff-ng/netsniff-ng/issues\n"
"Copyright (C) 2011-2013 Daniel Borkmann <dborkma@tik.ee.ethz.ch>,\n"
"Swiss federal institute of technology (ETH Zurich)\n"
"License: GNU GPL version 2.0\n"
diff --git a/configure b/configure
index 510826a..598ae24 100755
--- a/configure
+++ b/configure
@@ -588,7 +588,9 @@ int main(void)
}
EOF
- $CC -o $TMPDIR/pcaptest $TMPDIR/pcaptest.c -lpcap >> config.log 2>&1
+ $CC -o $TMPDIR/pcaptest $TMPDIR/pcaptest.c \
+ $($PKG_CONFIG --libs libpcap 2>> config.log) \
+ >> config.log 2>&1
if [ ! -x $TMPDIR/pcaptest ] ; then
echo "[NO]"
echo "CONFIG_LIBPCAP=0" >> Config
diff --git a/cookie.c b/cookie.c
index 9ee1ac6..567f539 100644
--- a/cookie.c
+++ b/cookie.c
@@ -2,6 +2,7 @@
#include <stdio.h>
#include <string.h>
#include <syslog.h>
+#include <sys/types.h>
#include "cookie.h"
diff --git a/curvetun.c b/curvetun.c
index 61ddc85..7c3cdb5 100644
--- a/curvetun.c
+++ b/curvetun.c
@@ -74,7 +74,7 @@ static const struct option long_options[] = {
};
static const char *copyright =
- "Please report bugs to <netsniff-ng@googlegroups.com>\n"
+ "Please report bugs at https://github.com/netsniff-ng/netsniff-ng/issues\n"
"Copyright (C) 2011-2013 Daniel Borkmann <dborkma@tik.ee.ethz.ch>,\n"
"Swiss federal institute of technology (ETH Zurich)\n"
"License: GNU GPL version 2.0\n"
diff --git a/dev.c b/dev.c
index 2ced495..a4f2b0e 100644
--- a/dev.c
+++ b/dev.c
@@ -82,6 +82,8 @@ static int __device_address6(const char *ifname, struct sockaddr_storage *ss)
panic("Cannot get device addresses for IPv6!\n");
for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
+ if (ifa->ifa_addr == NULL)
+ continue;
family = ifa->ifa_addr->sa_family;
if (family != AF_INET6)
continue;
diff --git a/flowtop.c b/flowtop.c
index 256bd05..62ce14d 100644
--- a/flowtop.c
+++ b/flowtop.c
@@ -225,7 +225,8 @@ static const struct option long_options[] = {
{NULL, 0, NULL, 0}
};
-static const char *copyright = "Please report bugs to <netsniff-ng@googlegroups.com>\n"
+static const char *copyright =
+ "Please report bugs at https://github.com/netsniff-ng/netsniff-ng/issues\n"
"Copyright (C) 2011-2013 Daniel Borkmann <dborkma@tik.ee.ethz.ch>\n"
"Copyright (C) 2011-2012 Emmanuel Roullit <emmanuel.roullit@gmail.com>\n"
"Swiss federal institute of technology (ETH Zurich)\n"
diff --git a/ifpps.c b/ifpps.c
index 3c98643..d112374 100644
--- a/ifpps.c
+++ b/ifpps.c
@@ -93,7 +93,8 @@ static const struct option long_options[] = {
{NULL, 0, NULL, 0}
};
-static const char *copyright = "Please report bugs to <netsniff-ng@googlegroups.com>\n"
+static const char *copyright =
+ "Please report bugs at https://github.com/netsniff-ng/netsniff-ng/issues\n"
"Copyright (C) 2009-2013 Daniel Borkmann <dborkma@tik.ee.ethz.ch>\n"
"Swiss federal institute of technology (ETH Zurich)\n"
"Copyright (C) 2013 Tobias Klauser <tklauser@distanz.ch>\n"
diff --git a/mausezahn/Makefile b/mausezahn/Makefile
index ca16b65..9544565 100644
--- a/mausezahn/Makefile
+++ b/mausezahn/Makefile
@@ -1,6 +1,6 @@
mausezahn-libs = -lcli \
-lnet \
- -lpcap \
+ $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG) --libs libpcap 2> /dev/null ) \
-lrt \
-lpthread \
-lm
diff --git a/netsniff-ng.c b/netsniff-ng.c
index 81e49d1..263078d 100644
--- a/netsniff-ng.c
+++ b/netsniff-ng.c
@@ -121,7 +121,8 @@ static const struct option long_options[] = {
{NULL, 0, NULL, 0}
};
-static const char *copyright = "Please report bugs to <netsniff-ng@googlegroups.com>\n"
+static const char *copyright =
+ "Please report bugs at https://github.com/netsniff-ng/netsniff-ng/issues\n"
"Copyright (C) 2009-2013 Daniel Borkmann <dborkma@tik.ee.ethz.ch>\n"
"Copyright (C) 2009-2012 Emmanuel Roullit <emmanuel.roullit@gmail.com>\n"
"Copyright (C) 2012 Markus Amend <markus@netsniff-ng.org>\n"
@@ -237,16 +238,21 @@ static void dump_rx_stats(struct ctx *ctx, int sock, bool is_v3)
if (update_rx_stats(ctx, sock, is_v3))
return;
- printf("\r%12"PRIu64" packets incoming (%"PRIu64" unread on exit)\n",
+ FILE *fd = stdout;
+ // In case the out device is stdout redirect to stderr
+ if (ctx->device_out && !strncmp("-", ctx->device_out, strlen("-")))
+ fd = stderr;
+
+ fprintf(fd, "\r%12"PRIu64" packets incoming (%"PRIu64" unread on exit)\n",
is_v3 ? ctx->pkts_seen : ctx->pkts_recvd,
is_v3 ? ctx->pkts_recvd - ctx->pkts_seen : 0);
- printf("\r%12"PRIu64" packets passed filter\n",
+ fprintf(fd, "\r%12"PRIu64" packets passed filter\n",
ctx->pkts_recvd - ctx->pkts_drops);
- printf("\r%12"PRIu64" packets failed filter (out of space)\n",
+ fprintf(fd, "\r%12"PRIu64" packets failed filter (out of space)\n",
ctx->pkts_drops);
if (ctx->pkts_recvd > 0)
- printf("\r%12.4lf%% packet droprate\n",
+ fprintf(fd, "\r%12.4lf%% packet droprate\n",
(1.0 * ctx->pkts_drops / ctx->pkts_recvd) * 100.0);
}
diff --git a/staging/cli.c b/staging/cli.c
index 5b5a159..dbfdb55 100644
--- a/staging/cli.c
+++ b/staging/cli.c
@@ -23,6 +23,19 @@
#include "mops.h"
#include "llist.h"
+struct cli_def *gcli;
+
+char mz_username[32];
+char mz_password[32];
+char mz_enable[32];
+char mz_listen_addr[16];
+int mz_port;
+struct mops *clipkt; // actual packet used by CLI thread
+
+int clidev;
+
+int cli_debug;
+
void mz_cli_init(void)
{
amp_head = automops_init();
diff --git a/staging/cli.h b/staging/cli.h
index 1a0156f..2ec153a 100644
--- a/staging/cli.h
+++ b/staging/cli.h
@@ -54,19 +54,19 @@
#define MZ_DEFAULT_ENABLE_PASSWORD "mops"
#define MZ_DEFAULT_PORT 25542 // Towel day and 42
-struct cli_def *gcli;
-
-char mz_username[32];
-char mz_password[32];
-char mz_enable[32];
-char mz_listen_addr[16];
-int mz_port;
-struct mops *clipkt; // actual packet used by CLI thread
+extern struct cli_def *gcli;
+
+extern char mz_username[32];
+extern char mz_password[32];
+extern char mz_enable[32];
+extern char mz_listen_addr[16];
+extern int mz_port;
+extern struct mops *clipkt; // actual packet used by CLI thread
-int clidev;
+extern int clidev;
// =================================================================
-int cli_debug;
+extern int cli_debug;
// Flags from 0x0000 to 0xFFFF
// cli_debug & 8000 => Developer specific debugs
diff --git a/staging/dns.c b/staging/dns.c
index bfa61d8..83227e2 100644
--- a/staging/dns.c
+++ b/staging/dns.c
@@ -89,6 +89,8 @@
"| arcount (or arc) ........... Number of RRs in additional records section 0 / 0\n" \
"\n"
+static u_int8_t gbuf[MAX_PAYLOAD_SIZE]; // This is only a generic global buffer to handover data more easily
+static u_int32_t gbuf_s;
int dns_get_query (char* argval);
int dns_get_answer (char* argval);
diff --git a/staging/llist.c b/staging/llist.c
index d729e46..9ef2d1a 100644
--- a/staging/llist.c
+++ b/staging/llist.c
@@ -40,6 +40,8 @@
*
*/
+struct mz_ll *packet_sequences;
+struct mz_ll *cli_seq; // currently edited packet sequence used by CLI
// Create new list element - may be the first one (list==NULL)
//
diff --git a/staging/llist.h b/staging/llist.h
index 49a87c7..d9e59b8 100644
--- a/staging/llist.h
+++ b/staging/llist.h
@@ -49,8 +49,8 @@ struct mz_ll {
void *data; // points to your data
};
-struct mz_ll *packet_sequences;
-struct mz_ll *cli_seq; // currently edited packet sequence used by CLI
+extern struct mz_ll *packet_sequences;
+extern struct mz_ll *cli_seq; // currently edited packet sequence used by CLI
// prototypes
struct mz_ll * mz_ll_create_new_element(struct mz_ll *list);
diff --git a/staging/mausezahn.c b/staging/mausezahn.c
index 6c36166..7599b74 100644
--- a/staging/mausezahn.c
+++ b/staging/mausezahn.c
@@ -23,7 +23,8 @@
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <stdarg.h>
-
+#include <getopt.h>
+
#include "mz.h"
#include "cli.h"
#include "mops.h"
@@ -32,8 +33,54 @@
#include "die.h"
#include "dev.h"
+enum operating_modes mode;
+
+int ipv6_mode;
+int quiet; // don't even print 'important standard short messages'
+int verbose; // report character
+int simulate; // if 1 then don't really send frames
+
+char path[256];
+char filename[256];
+FILE *fp, *fp2; // global multipurpose file pointer
+
+long double total_d;
+clock_t mz_start, mz_stop;
+
+int mz_rand;
+int bwidth;
+
+int32_t
+ jitter[TIME_COUNT_MAX];
+
+int
+ rtp_log,
+ time0_flag, // If set then time0 has valid data
+ sqnr0_flag;
+
+u_int8_t
+ mz_ssrc[4]; // holds RTP stream identifier for rcv_rtp()
+
+u_int16_t
+ sqnr_cur,
+ sqnr_last,
+ sqnr_next;
+
+u_int32_t
+ gind, // a global index to run through deltaRX, deltaTX, and jitter
+ gind_max; // the amount of entries used in the (ugly oversized) arrays; per default set to TIME_COUNT
+
+struct tx_struct tx; // NOTE: tx elements are considered as default values for MOPS
+
+struct device_struct device_list[MZ_MAX_DEVICES];
+
+int device_list_entries;
+
int verbose_level = 0;
+char mz_default_config_path[256];
+char mz_default_log_path[256];
+
static const char *short_options = "46hqvVSxra:A:b:B:c:d:E:f:F:l:p:P:R:t:T:M:Q:X:";
static void signal_handler(int number)
@@ -177,7 +224,7 @@ static void version(void)
printf("\nmausezahn %s, Git id: %s\n", VERSION_LONG, GITVERSION);
puts("a fast versatile traffic generator\n"
"http://www.netsniff-ng.org\n\n"
- "Please report bugs to <bugs@netsniff-ng.org>\n"
+ "Please report bugs at https://github.com/netsniff-ng/netsniff-ng/issues\n"
"Copyright (C) 2008-2010 Herbert Haas <herbert@perihel.at>,\n"
"Copyright (C) 2011 Daniel Borkmann <dborkma@tik.ee.ethz.ch>,\n"
"Swiss federal institute of technology (ETH Zurich)\n"
@@ -192,9 +239,6 @@ int reset(void)
int i;
time_t t;
- // Determine platform type sizes:
- MZ_SIZE_LONG_INT = sizeof(long int);
-
mz_default_config_path[0] = 0x00;
mz_default_log_path[0] = 0x00;
@@ -404,9 +448,7 @@ int getopts (int argc, char *argv[])
char unit;
opterr = 1; // let getopt print error message if necessary
-
-
- while ((c = getopt(argc, argv, short_options)) != -1)
+ while ((c = getopt_long(argc, argv, short_options, NULL, NULL)) != -1) {
switch (c) {
case '4':
tx.eth_type = 0x0800;
@@ -603,7 +645,7 @@ int getopts (int argc, char *argv[])
fprintf (stderr," mz/getopts: Could not handle arguments properly!\n");
return 1;
}
-
+ }
// ********************************************
// Handle additional arguments
// ********************************************
@@ -617,8 +659,8 @@ int getopts (int argc, char *argv[])
"-- Verbose mode --\n"
"\n");
}
-
- if (argc<2) {
+
+ if (optind+2 < argc) {
help();
}
diff --git a/staging/mops.c b/staging/mops.c
index 599d317..fc00e29 100644
--- a/staging/mops.c
+++ b/staging/mops.c
@@ -46,8 +46,11 @@
#include "mz.h"
#include "mops.h"
+unsigned int min_frame_s;
+unsigned int max_frame_s;
-
+struct automops * amp_head;
+struct mops *mp_head; // This global will point to the head of the mops list
// Creates first element, aka "head" element
// This element can also be used! See mops_alloc_packet!
diff --git a/staging/mops.h b/staging/mops.h
index 96953e6..cf19f09 100644
--- a/staging/mops.h
+++ b/staging/mops.h
@@ -114,8 +114,8 @@
// These are initialized with the definitions MIN_MOPS_FRAME_SIZE and
// MAX_MOPS_FRAME_SIZE above but can be overridden by the user (without
// extending these limits)
-unsigned int min_frame_s;
-unsigned int max_frame_s;
+extern unsigned int min_frame_s;
+extern unsigned int max_frame_s;
struct mops_counter
{
@@ -246,7 +246,7 @@ struct automops {
};
-struct automops * amp_head;
+extern struct automops * amp_head;
struct mops
@@ -688,7 +688,7 @@ struct mops_ext_syslog //TODO
/////////////////////////////////////////////////////////////////
-struct mops *mp_head; // This global will point to the head of the mops list
+extern struct mops *mp_head; // This global will point to the head of the mops list
/////////////////////////////////////////////////////////////////
// MOPS Prototypes:
diff --git a/staging/mz.h b/staging/mz.h
index 5afe57d..33e74e6 100644
--- a/staging/mz.h
+++ b/staging/mz.h
@@ -108,10 +108,8 @@ static inline void verbose_l2(const char *format, ...)
#define IPADDRSIZE 46
-int MZ_SIZE_LONG_INT;
-
-char mz_default_config_path[256];
-char mz_default_log_path[256];
+extern char mz_default_config_path[256];
+extern char mz_default_log_path[256];
struct arp_table_struct {
@@ -161,9 +159,11 @@ struct device_struct
struct pcap *p_arp; // pcap handle
struct arp_table_struct *arp_table; // dedicated ARP table
int ps; // packet socket
-} device_list[MZ_MAX_DEVICES];
+};
-int device_list_entries;
+extern struct device_struct device_list[MZ_MAX_DEVICES];
+
+extern int device_list_entries;
#pragma pack(1)
@@ -272,66 +272,49 @@ enum operating_modes
SYSLOG,
LLDP,
IGMP
-} mode;
-
+};
-int ipv6_mode;
-int quiet; // don't even print 'important standard short messages'
-int verbose; // report character
-int simulate; // if 1 then don't really send frames
+extern enum operating_modes mode;
-char path[256];
-char filename[256];
-FILE *fp, *fp2; // global multipurpose file pointer
+extern int ipv6_mode;
+extern int quiet; // don't even print 'important standard short messages'
+extern int verbose; // report character
+extern int simulate; // if 1 then don't really send frames
-long double total_d;
-clock_t mz_start, mz_stop;
+extern char path[256];
+extern char filename[256];
+extern FILE *fp, *fp2; // global multipurpose file pointer
-enum rtp_display_mode {
- BAR, NCURSES, TEXT
-} rtp_dm;
-
+extern long double total_d;
+extern clock_t mz_start, mz_stop;
-int mz_rand;
-int bwidth;
+extern int mz_rand;
+extern int bwidth;
struct mz_timestamp {
u_int32_t sec;
u_int32_t nsec;
};
-struct mz_timestamp
- tv,
- timeTX[TIME_COUNT_MAX],
- timeRX[TIME_COUNT_MAX];
-
-int32_t
- time0,
- jitter_rfc,
- jitter[TIME_COUNT_MAX];
+extern int32_t
+ jitter[TIME_COUNT_MAX];
-int
+extern int
rtp_log,
time0_flag, // If set then time0 has valid data
sqnr0_flag;
-u_int8_t
+extern u_int8_t
mz_ssrc[4]; // holds RTP stream identifier for rcv_rtp()
-u_int16_t
+extern u_int16_t
sqnr_cur,
sqnr_last,
sqnr_next;
-u_int32_t
- drop, // packet drop count
- dis, // packet disorder count
+extern u_int32_t
gind, // a global index to run through deltaRX, deltaTX, and jitter
- gind_max, // the amount of entries used in the (ugly oversized) arrays; per default set to TIME_COUNT
- gtotal; // counts number of file write cycles (see "got_rtp_packet()")
-
-
-char rtp_filter_str[64];
+ gind_max; // the amount of entries used in the (ugly oversized) arrays; per default set to TIME_COUNT
struct tx_struct
{
@@ -496,15 +479,9 @@ struct tx_struct
rtp_sqnr,
rtp_stmp;
-} tx; // NOTE: tx elements are considered as default values for MOPS
-
-
-
-
-
-u_int8_t gbuf[MAX_PAYLOAD_SIZE]; // This is only a generic global buffer to handover data more easily
-u_int32_t gbuf_s; //
+};
+extern struct tx_struct tx; // NOTE: tx elements are considered as default values for MOPS
// ************************************
//
diff --git a/staging/rcv_rtp.c b/staging/rcv_rtp.c
index 0a91155..f43b92c 100644
--- a/staging/rcv_rtp.c
+++ b/staging/rcv_rtp.c
@@ -39,6 +39,25 @@
#include "mz.h"
#include "mops.h"
+static enum rtp_display_mode {
+ BAR, NCURSES, TEXT
+} rtp_dm;
+
+static int32_t
+ time0,
+ jitter_rfc;
+
+static struct mz_timestamp
+ timeTX[TIME_COUNT_MAX],
+ timeRX[TIME_COUNT_MAX];
+
+static u_int32_t
+ drop, // packet drop count
+ dis, // packet disorder count
+ gtotal; // counts number of file write cycles (see "got_rtp_packet()")
+
+static char rtp_filter_str[64];
+
// Initialize the rcv_rtp process: Read user parameters and initialize globals
int rcv_rtp_init(void)
{
diff --git a/staging/rtp.c b/staging/rtp.c
index 54a195e..da40884 100644
--- a/staging/rtp.c
+++ b/staging/rtp.c
@@ -56,7 +56,6 @@
"|\n"
-
int create_rtp_packet(void)
{
u_int8_t byte1, byte2;
diff --git a/trafgen.8 b/trafgen.8
index 7d31b70..5191872 100644
--- a/trafgen.8
+++ b/trafgen.8
@@ -131,11 +131,15 @@ than one packet is defined in a packet configuration, packets are scheduled for
transmission in a round robin fashion. With this option, they are selected
randomly instread.
.TP
-.B -P <uint>, --cpus <uint>
+.B -P <uint>[-<uint>], --cpus <uint>[-<uint>]
Specify the number of processes trafgen shall
.BR fork (2)
-off. By default trafgen will start as many processes as CPUs that are online and
-pin them to each, respectively. Allowed value must be within interval [1,CPUs].
+off or list exact CPUs to use. By default trafgen will start as many processes
+as CPUs that are online and pin them to each, respectively. A single integer
+within interval [1,CPUs] overrides number of processes, which will be spawned
+starting from the first CPU. A pair of integers within interval [0,CPUs-1], and
+separated using ''-'' represents an interval of CPUs, which will be used to
+spawn worker processes.
.TP
.B -t <time>, --gap <time>
Specify a static inter-packet timegap in seconds, milliseconds, microseconds,
@@ -156,7 +160,7 @@ and TX_RING performance,
Furthermore, the TX_RING interface does not cope with interpacket gaps.
.TP
.B -b <rate>, --rate <rate>
-Specify the packet send rate <num>pps/B/kB/MB/GB/kbit/Mbit/Gbit/KiB/MiB/GiB units.
+Specify the packet send rate <num>pps/kpps/Mpps/B/kB/MB/GB/kbit/Mbit/Gbit/KiB/MiB/GiB units.
Like with the \fB-t\fP/\fB--gap\fP option, the packets are sent in slow mode.
.TP
.B -S <size>, --ring-size <size>
@@ -267,8 +271,8 @@ to write configurations:
byte fill function: fill(<content>, <times>): fill(0xca, 128)
compile-time random: rnd(<times>): rnd(128), rnd()
runtime random numbers: drnd(<times>): drnd(128), drnd()
- compile-time counter: seqinc(<start-val>, <increment>, <times>)
- seqdec(<start-val>, <decrement>, <times>)
+ compile-time counter: seqinc(<start-val>, <times>, <increment>)
+ seqdec(<start-val>, <times>, <decrement>)
runtime counter (1byte): dinc(<min-val>, <max-val>, <increment>)
ddec(<min-val>, <max-val>, <decrement>)
.PP
@@ -910,7 +914,7 @@ The above example rewritten using the header generation functions:
.PP
{
# --- ethernet header ---
- eth(da=00:1b:21:3c:9d:f8, da=90:e2:ba:0a:56:b4)
+ eth(da=00:1b:21:3c:9d:f8, sa=90:e2:ba:0a:56:b4)
# --- ip header ---
ipv4(id=drnd(), mf, ttl=64, sa=192.168.51.1, da=192.168.51.2)
# --- udp header ---
@@ -926,6 +930,9 @@ This is the most simple and, probably, the most common use of trafgen. It
will generate traffic defined in the configuration file ''trafgen.cfg'' and
transmit this via the ''eth0'' networking device. All online CPUs are used.
.TP
+.B trafgen --dev eth0 --conf trafgen.cfg --cpus 2-4
+Instead of using all online CPUs, transmit traffic from CPUs 2, 3, and 4.
+.TP
.B trafgen -e | trafgen -i - -o lo --cpp -n 1
This is an example where we send one packet of the built-in example through
the loopback device. The example configuration is passed via stdin and also
@@ -941,7 +948,8 @@ use the TX_RING, but sendto(2) packet I/O due to ''slow mode''.
.B trafgen --dev wlan0 --rfraw --conf beacon-test.txf -V --cpus 2
As an output device ''wlan0'' is used and put into monitoring mode, thus we
are going to transmit raw 802.11 frames through the air. Use the ''beacon-test.txf''
-configuration file, set trafgen into verbose mode and use only 2 CPUs.
+configuration file, set trafgen into verbose mode and use only 2 CPUs starting
+from CPU 0.
.TP
.B trafgen --dev em1 --conf frag_dos.cfg --rand --gap 1000us
Use trafgen in sendto(2) mode instead of TX_RING mode and sleep after each
diff --git a/trafgen.c b/trafgen.c
index 78be711..569cf06 100644
--- a/trafgen.c
+++ b/trafgen.c
@@ -82,7 +82,8 @@ struct ctx {
struct dev_io *dev_out;
struct dev_io *dev_in;
unsigned long num;
- unsigned int cpus;
+ unsigned int cpu_start;
+ unsigned int cpu_num;
uid_t uid; gid_t gid;
char *device, *rhost;
struct sockaddr_in dest;
@@ -140,7 +141,8 @@ static const struct option long_options[] = {
{NULL, 0, NULL, 0}
};
-static const char *copyright = "Please report bugs to <netsniff-ng@googlegroups.com>\n"
+static const char *copyright =
+ "Please report bugs at https://github.com/netsniff-ng/netsniff-ng/issues\n"
"Copyright (C) 2011-2013 Daniel Borkmann <dborkma@tik.ee.ethz.ch>,\n"
"Swiss federal institute of technology (ETH Zurich)\n"
"License: GNU GPL version 2.0\n"
@@ -194,9 +196,9 @@ static void __noreturn help(void)
" -s|--smoke-test <ipv4> Probe if machine survived fuzz-tested packet\n"
" -n|--num <uint> Number of packets until exit (def: 0)\n"
" -r|--rand Randomize packet selection (def: round robin)\n"
- " -P|--cpus <uint> Specify number of forks(<= CPUs) (def: #CPUs)\n"
+ " -P|--cpus <uint>[-<uint>] Specify number of forks(<= CPUs) (def: #CPUs)\n"
" -t|--gap <time> Set approx. interpacket gap (s/ms/us/ns, def: us)\n"
- " -b|--rate <rate> Send traffic at specified rate (pps/B/kB/MB/GB/kbit/Mbit/Gbit/KiB/MiB/GiB)\n"
+ " -b|--rate <rate> Send traffic at specified rate (pps/kpps/Mpps/B/kB/MB/GB/kbit/Mbit/Gbit/KiB/MiB/GiB)\n"
" -S|--ring-size <size> Manually set mmap size (KiB/MiB/GiB)\n"
" -E|--seed <uint> Manually set srand(3) seed\n"
" -u|--user <userid> Drop privileges and change to userid\n"
@@ -212,6 +214,7 @@ static void __noreturn help(void)
" -h|--help Guess what?!\n\n"
"Examples:\n"
" trafgen --dev eth0 --conf trafgen.cfg\n"
+ " trafgen --dev eth0 --conf trafgen.cfg --cpus 2-4\n"
" trafgen -e | trafgen -i - -o eth0 --cpp -n 1\n"
" trafgen --dev eth0 --conf fuzzing.cfg --smoke-test 10.0.0.1\n"
" trafgen --dev wlan0 --rfraw --conf beacon-test.txf -V --cpus 2\n"
@@ -829,7 +832,7 @@ static unsigned long __wait_and_sum_others(struct ctx *ctx, unsigned int cpu)
unsigned int i;
unsigned long total;
- for (i = 0, total = plen; i < ctx->cpus; i++) {
+ for (i = 0, total = plen; i < ctx->cpu_num; i++) {
if (i == cpu)
continue;
@@ -852,7 +855,7 @@ static void __correct_global_delta(struct ctx *ctx, unsigned int cpu, unsigned l
int cpu_sel;
long long delta_correction = 0;
- for (i = 0, total = ctx->num; i < ctx->cpus; i++) {
+ for (i = 0, total = ctx->num; i < ctx->cpu_num; i++) {
if (i == cpu)
continue;
@@ -870,7 +873,7 @@ static void __correct_global_delta(struct ctx *ctx, unsigned int cpu, unsigned l
if (total < orig)
delta_correction = +1 * ((long long) orig - total);
- for (cpu_sel = -1, i = 0; i < ctx->cpus; i++) {
+ for (cpu_sel = -1, i = 0; i < ctx->cpu_num; i++) {
if (stats[i].cd_packets > 0) {
if ((long long) stats[i].cd_packets +
delta_correction >= 0) {
@@ -928,9 +931,7 @@ static void xmit_packet_precheck(struct ctx *ctx, unsigned int cpu)
static void pcap_load_packets(struct dev_io *dev)
{
- struct packet *pkt;
-
- while ((pkt = dev_io_read(dev)) != 0)
+ while (dev_io_read(dev))
/* nothing to do */;
}
@@ -957,7 +958,7 @@ static void main_loop(struct ctx *ctx, char *confname, bool slow,
unsigned int i;
size_t total_len = 0, total_pkts = 0;
- for (i = 0; i < ctx->cpus; ++i) {
+ for (i = 0; i < ctx->cpu_num; ++i) {
total_len += stats[i].cf_bytes;
total_pkts += stats[i].cf_packets;
}
@@ -1012,7 +1013,7 @@ int main(int argc, char **argv)
uint64_t gap = 0;
unsigned int i;
char *confname = NULL, *ptr;
- unsigned long cpus_tmp, orig_num = 0;
+ unsigned long cpu_n, orig_num = 0;
unsigned long long tx_packets, tx_bytes;
struct ctx ctx;
int min_opts = 5;
@@ -1023,7 +1024,7 @@ int main(int argc, char **argv)
struct timespec delay;
memset(&ctx, 0, sizeof(ctx));
- ctx.cpus = get_number_cpus_online();
+ ctx.cpu_num = get_number_cpus_online();
ctx.uid = getuid();
ctx.gid = getgid();
ctx.qdisc_path = false;
@@ -1057,9 +1058,20 @@ int main(int argc, char **argv)
ctx.verbose = true;
break;
case 'P':
- cpus_tmp = strtoul(optarg, NULL, 0);
- if (cpus_tmp > 0 && cpus_tmp < ctx.cpus)
- ctx.cpus = cpus_tmp;
+ if (slow)
+ break;
+ cpu_n = strtoul(optarg, &ptr, 0);
+ if (ptr && *ptr == '-') {
+ if (cpu_n < 0 || cpu_n >= ctx.cpu_num)
+ break;
+ ctx.cpu_start = cpu_n;
+ cpu_n = strtoul(ptr + 1, NULL, 0);
+ if (cpu_n < ctx.cpu_start || cpu_n >= ctx.cpu_num)
+ ctx.cpu_num -= ctx.cpu_start;
+ else
+ ctx.cpu_num = cpu_n - ctx.cpu_start + 1;
+ } else if (cpu_n > 0 && cpu_n <= ctx.cpu_num)
+ ctx.cpu_num = cpu_n;
break;
case 'd':
case 'o':
@@ -1082,7 +1094,8 @@ int main(int argc, char **argv)
break;
case 's':
slow = true;
- ctx.cpus = 1;
+ ctx.cpu_start = 0;
+ ctx.cpu_num = 1;
ctx.smoke_test = true;
ctx.rhost = xstrdup(optarg);
break;
@@ -1098,8 +1111,10 @@ int main(int argc, char **argv)
if (c == 'i' && strstr(confname, ".pcap")) {
ctx.sh.type = SHAPER_TSTAMP;
ctx.pcap_in = confname;
- } else if (!strncmp("-", confname, strlen("-")))
- ctx.cpus = 1;
+ } else if (!strncmp("-", confname, strlen("-"))) {
+ ctx.cpu_start = 0;
+ ctx.cpu_num = 1;
+ }
break;
case 'u':
ctx.uid = strtoul(optarg, NULL, 0);
@@ -1154,6 +1169,12 @@ int main(int argc, char **argv)
if (strncmp(ptr, "pps", strlen("pps")) == 0) {
shape_type = SHAPER_PKTS;
+ } else if (strncmp(ptr, "kpps", strlen("kpps")) == 0) {
+ shape_type = SHAPER_PKTS;
+ rate *= 1000;
+ } else if (strncmp(ptr, "Mpps", strlen("Mpps")) == 0) {
+ shape_type = SHAPER_PKTS;
+ rate *= 1000 * 1000;
} else if (strncmp(ptr, "B", strlen("B")) == 0) {
shape_type = SHAPER_BYTES;
} else if (strncmp(ptr, "kB", strlen("kB")) == 0) {
@@ -1286,7 +1307,8 @@ int main(int argc, char **argv)
/* Fall back to single core to not mess up correct timing.
* We are slow anyway!
*/
- ctx.cpus = 1;
+ ctx.cpu_start = 0;
+ ctx.cpu_num = 1;
slow = true;
}
@@ -1296,16 +1318,21 @@ int main(int argc, char **argv)
* packets than intended or none at all.
*/
if (ctx.num)
- ctx.cpus = min_t(unsigned int, ctx.num, ctx.cpus);
+ ctx.cpu_num = min_t(unsigned int, ctx.num, ctx.cpu_num);
if (set_irq_aff && dev_io_is_netdev(ctx.dev_out)) {
irq = device_irq_number(ctx.device);
- device_set_irq_affinity_list(irq, 0, ctx.cpus - 1);
+ device_set_irq_affinity_list(irq, ctx.cpu_start,
+ ctx.cpu_start + ctx.cpu_num - 1);
}
- stats = setup_shared_var(ctx.cpus);
+ stats = setup_shared_var(ctx.cpu_num);
+
- for (i = 0; i < ctx.cpus; i++) {
+ if (ctx.verbose)
+ printf("Start %u worker processes on cpus [%u-%u].\n",
+ ctx.cpu_num, ctx.cpu_start, ctx.cpu_start + ctx.cpu_num - 1);
+ for (i = 0; i < ctx.cpu_num; i++) {
pid_t pid = fork();
switch (pid) {
@@ -1314,7 +1341,7 @@ int main(int argc, char **argv)
seed = generate_srand_seed();
srand(seed);
- cpu_affinity(i);
+ cpu_affinity(ctx.cpu_start + i);
main_loop(&ctx, confname, slow, i, invoke_cpp,
cpp_argv, orig_num);
@@ -1324,7 +1351,7 @@ int main(int argc, char **argv)
}
}
- for (i = 0; i < ctx.cpus; i++) {
+ for (i = 0; i < ctx.cpu_num; i++) {
int status;
wait(&status);
@@ -1335,7 +1362,7 @@ int main(int argc, char **argv)
if (set_sock_mem)
reset_system_socket_memory(vals, array_size(vals));
- for (i = 0, tx_packets = tx_bytes = 0; i < ctx.cpus; i++) {
+ for (i = 0, tx_packets = tx_bytes = 0; i < ctx.cpu_num; i++) {
while ((__get_state(i) & CPU_STATS_STATE_RES) == 0)
sched_yield();
@@ -1347,7 +1374,7 @@ int main(int argc, char **argv)
printf("\n");
printf("\r%12llu packets outgoing\n", tx_packets);
printf("\r%12llu bytes outgoing\n", tx_bytes);
- for (i = 0; cpustats && i < ctx.cpus; i++) {
+ for (i = 0; cpustats && i < ctx.cpu_num; i++) {
printf("\r%12lu sec, %lu usec on CPU%d (%llu packets)\n",
stats[i].tv_sec, stats[i].tv_usec, i,
stats[i].tx_packets);
@@ -1355,7 +1382,7 @@ int main(int argc, char **argv)
thread_out:
xunlockme();
- destroy_shared_var(stats, ctx.cpus);
+ destroy_shared_var(stats, ctx.cpu_num);
if (dev_io_is_netdev(ctx.dev_out) && set_irq_aff)
device_restore_irq_affinity_list();