[netsniff-ng] [PATCH 2/2] mausezahn: Support -R to set packet priority

2019-10-01 Thread Petr Machata
Add a command line option -R to specify SO_PRIORITY socket option. This
then sets priority of the generated SKBs, which is handy for testing Qdiscs
and other priority-dependent functionality.

Signed-off-by: Petr Machata 
---
 mausezahn.8 |  6 ++
 staging/layer3.c|  9 +
 staging/mausezahn.c | 18 +-
 staging/mz.h|  1 +
 4 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/mausezahn.8 b/mausezahn.8
index 8379111..71d3aa0 100644
--- a/mausezahn.8
+++ b/mausezahn.8
@@ -79,6 +79,12 @@ Specify IPv6 mode (IPv4 is the default).
 .SS -l 
 Specify the IP address mausezahn should bind to when in interactive mode, 
default: 0.0.0.0.
 .PP
+.SS -R 
+Set priority of sent packets. This configures SO_PRIORITY at the socket through
+which the packets are sent. Usual priority numbers are 0..15, but the value can
+also be a class ID for purposes of Qdisc classification. In that case, a class
+ID such is 1234:5678 would be specified as 0x12345678.
+.PP
 .SS -v
 Verbose mode. Capital \-V is even more verbose.
 .PP
diff --git a/staging/layer3.c b/staging/layer3.c
index 0b17db1..7dabc26 100644
--- a/staging/layer3.c
+++ b/staging/layer3.c
@@ -133,6 +133,15 @@ libnet_t* get_link_context(void)
fprintf(stderr, "%s", errbuf);
exit(EXIT_FAILURE);
  }
+
+   if (tx.prio != 0 &&
+   setsockopt (libnet_getfd (l), SOL_SOCKET, SO_PRIORITY, ,
+  sizeof tx.prio) < 0)
+ {
+   perror("setsockopt SO_PRIORITY");
+   exit(EXIT_FAILURE);
+ }
+
return l;
 }
 
diff --git a/staging/mausezahn.c b/staging/mausezahn.c
index de3a2e2..c38ea46 100644
--- a/staging/mausezahn.c
+++ b/staging/mausezahn.c
@@ -34,7 +34,7 @@
 
 int verbose_level = 0;
 
-static const char *short_options = 
"46hqvVSxra:A:b:B:c:d:E:f:F:l:p:P:t:T:M:Q:X:";
+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)
 {
@@ -113,6 +113,7 @@ static void help(void)
 "  -lListen address to bind to when in 
interactive mode, default: 0.0.0.0\n"
 "  -4IPv4 mode (default)\n"
 "  -6IPv6 mode\n"
+"  -R  Set socket priority\n"
 "  -c Send packet count times, default:1, 
infinite:0\n"
 "  -d Apply delay between transmissions. The 
delay value can be\n"
 "specified in usec (default, no additional 
unit needed), or in\n"
@@ -224,6 +225,7 @@ int reset(void)
tx.packet_mode = 1; // assume we don't care about L2
tx.count = 1;  
tx.delay = DEFAULT_DELAY;  
+   tx.prio = 0;
tx.arg_string[0] = '\0';

// Reset Ethernet parameters of TX:
@@ -398,6 +400,7 @@ int getopts (int argc, char *argv[])
char hexpld[MAX_PAYLOAD_SIZE*2];
int hexpld_specified=0;
long delay;
+   long prio;
char unit;
 
opterr = 1; // let getopt print error message if necessary
@@ -413,6 +416,19 @@ int getopts (int argc, char *argv[])
tx.eth_type = 0x86dd;
ipv6_mode=1;
break;
+case 'R':
+   errno = 0;
+   prio = strtol(optarg, NULL, 0);
+   if (errno) {
+   perror("Couldn't parse priority");
+   return -1;
+   }
+   if (prio < 0 || prio > 0x) {
+   perror("Invalid priority value");
+   return -1;
+   }
+   tx.prio = (int)prio;
+   break;
 case 'h':
help();
break;
diff --git a/staging/mz.h b/staging/mz.h
index 6d98ad0..5afe57d 100644
--- a/staging/mz.h
+++ b/staging/mz.h
@@ -340,6 +340,7 @@ struct tx_struct
int  packet_mode;  // 0 means use LIBNET_LINK_ADV, 1 means 
LIBNET_RAW4
unsigned int count;// 0 means infinite, 1 is default
unsigned int delay;// Delay in microseconds, 0 means no delay 
(default)
+   unsigned int prio; // Socket priority, 0 is default
char arg_string[MAX_PAYLOAD_SIZE];  // Argument-string when -t is used

// Ethernet and 802.3 parameters
-- 
2.20.1

-- 
You received this message because you are subscribed to the Google Groups 
"netsniff-ng" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to netsniff-ng+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/netsniff-ng/6f60695450b6c36131323347de67b7aef094cabe.1569947985.git.petrm%40mellanox.com.


[netsniff-ng] [PATCH 1/2] mausezahn.8: Document -r

2019-10-01 Thread Petr Machata
This option is mentioned further in the man page, but is omitted in the
main section. Add it.

Signed-off-by: Petr Machata 
---
 mausezahn.8 | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/mausezahn.8 b/mausezahn.8
index 44a76ab..8379111 100644
--- a/mausezahn.8
+++ b/mausezahn.8
@@ -98,6 +98,9 @@ Apply delay between transmissions. The delay value can be 
specified in usec
 in seconds (e.g. 100s or 100sec). Note: mops also supports nanosecond delay
 resolution if you need it (see interactive mode).
 .PP
+.SS -r
+Multiply the specified delay with a random value.
+.PP
 .SS -p 
 Pad the raw frame to specified length using zero bytes. Note that for raw
 layer 2 frames the specified length defines the whole frame length, while for
-- 
2.20.1

-- 
You received this message because you are subscribed to the Google Groups 
"netsniff-ng" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to netsniff-ng+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/netsniff-ng/9678df51601aeb17dc8bd32dbb43ffafb7c3e0dc.1569947985.git.petrm%40mellanox.com.


[netsniff-ng] [PATCH] mausezahn: Fix IPv6 address comparison

2018-05-14 Thread Petr Machata
CMP_INT evaluates its arguments more than once, and thus passing a
post-incremented pointer as an argument causes double increments and
hence buffer overruns. This can be observed by erratic behavior of IPv6
address ranges. Fix by moving the increment to loop header.

Signed-off-by: Petr Machata <pe...@mellanox.com>
---
 staging/tools.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/staging/tools.c b/staging/tools.c
index 9d2d1be..72445b6 100644
--- a/staging/tools.c
+++ b/staging/tools.c
@@ -233,8 +233,8 @@ int in6_addr_cmp(struct libnet_in6_addr addr1,
   *p2 = addr2.__u6_addr.__u6_addr32;
int i, val = 0;
 
-   for (i = 0; i < 4; i++) {
-   val = CMP_INT(ntohl(*p1++), ntohl(*p2++));
+   for (i = 0; i < 4; i++, p1++, p2++) {
+   val = CMP_INT(ntohl(*p1), ntohl(*p2));
if (val) {
break;
}
-- 
2.4.11

-- 
You received this message because you are subscribed to the Google Groups 
"netsniff-ng" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to netsniff-ng+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.