[netsniff-ng] [PATCH 2/3] trafgen: Allow send packets from pcap file

2017-01-31 Thread Vadim Kochan
Add ability to send packets from pcap file if it has
".pcap" extension via "-i,--in" option.

By default packet sending is delayed considering original
packets timestamps if no rate or delay is specified via -b/-t options.

Signed-off-by: Vadim Kochan 
---
 trafgen.c| 155 +--
 trafgen/Makefile |   4 ++
 trafgen_conf.h   |   3 ++
 trafgen_parser.y |   2 +-
 4 files changed, 137 insertions(+), 27 deletions(-)

diff --git a/trafgen.c b/trafgen.c
index 524b260..c0d77a3 100644
--- a/trafgen.c
+++ b/trafgen.c
@@ -5,6 +5,8 @@
  * Subject to the GPL, version 2.
  */
 
+#define _GNU_SOURCE
+
 #include 
 #include 
 #include 
@@ -16,7 +18,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -55,6 +56,7 @@
 #include "ring_tx.h"
 #include "csum.h"
 #include "trafgen_proto.h"
+#include "pcap_io.h"
 
 #ifndef timeval_to_timespec
 #define timeval_to_timespec(tv, ts) { \
@@ -65,14 +67,17 @@
 
 enum shaper_type {
SHAPER_NONE,
+   SHAPER_DELAY,
SHAPER_PKTS,
SHAPER_BYTES,
+   SHAPER_TSTAMP,
 };
 
 struct shaper {
enum shaper_type type;
unsigned long long sent;
unsigned long long rate;
+   struct timeval tstamp;
struct timeval start;
struct timeval end;
struct timespec delay;
@@ -88,6 +93,7 @@ struct ctx {
struct sockaddr_in dest;
struct shaper sh;
char *packet_str;
+   char *pcap_in;
 };
 
 struct cpu_stats {
@@ -556,15 +562,12 @@ static int xmit_smoke_probe(int icmp_sock, struct ctx 
*ctx)
 
 static bool shaper_is_set(struct shaper *sh)
 {
-   if ((sh->delay.tv_sec | sh->delay.tv_nsec) > 0)
-   return true;
-
-   return sh->type != SHAPER_NONE;
+   return sh->type != SHAPER_NONE;
 }
 
 static void shaper_init(struct shaper *sh)
 {
-   if (sh->type == SHAPER_NONE)
+   if (sh->type == SHAPER_NONE || sh->type == SHAPER_DELAY)
return;
 
memset(&sh->delay, 0, sizeof(struct timespec));
@@ -574,6 +577,12 @@ static void shaper_init(struct shaper *sh)
 
 static void shaper_set_delay(struct shaper *sh, time_t sec, long int ns)
 {
+   if (!(sec | ns)) {
+   sh->type = SHAPER_NONE;
+   return;
+   }
+
+   sh->type = SHAPER_DELAY;
sh->delay.tv_sec = sec;
sh->delay.tv_nsec = ns;
 }
@@ -586,23 +595,48 @@ static void shaper_set_rate(struct shaper *sh, unsigned 
long long rate,
sh->type = type;
 }
 
-static void shaper_delay(struct shaper *sh, unsigned long pkt_len)
+static void shaper_set_tstamp(struct shaper *sh, struct timeval *tv)
 {
-   if (sh->type != SHAPER_NONE)
+   sh->tstamp.tv_sec = tv->tv_sec;
+   sh->tstamp.tv_usec = tv->tv_usec;
+}
+
+static void shaper_delay(struct shaper *sh, struct packet *pkt)
+{
+   if (sh->type == SHAPER_BYTES || sh->type == SHAPER_PKTS) {
+   unsigned long pkt_len = pkt->len;
+
sh->sent += sh->type == SHAPER_BYTES ? pkt_len : 1;
 
-   if (sh->sent >= sh->rate && sh->rate > 0) {
-   struct timeval delay_us;
-   struct timeval time_sent;
-   struct timeval time_1s = { .tv_sec = 1 };
+   if (sh->sent >= sh->rate && sh->rate > 0) {
+   struct timeval delay_us;
+   struct timeval time_sent;
+   struct timeval time_1s = { .tv_sec = 1 };
+
+   bug_on(gettimeofday(&sh->end, NULL));
+   timersub(&sh->end, &sh->start, &time_sent);
+
+   if (timercmp(&time_1s, &time_sent, > )) {
+   timersub(&time_1s, &time_sent, &delay_us);
+   timeval_to_timespec(&delay_us, &sh->delay);
+   }
+   }
+   } else if (sh->type == SHAPER_TSTAMP) {
+   struct timeval pkt_diff;
+   struct timeval diff;
 
bug_on(gettimeofday(&sh->end, NULL));
-   timersub(&sh->end, &sh->start, &time_sent);
+   timersub(&sh->end, &sh->start, &diff);
+   timersub(&pkt->tstamp, &sh->tstamp, &pkt_diff);
+
+   if (timercmp(&diff, &pkt_diff, <)) {
+   struct timeval delay;
 
-   if (timercmp(&time_1s, &time_sent, > )) {
-   timersub(&time_1s, &time_sent, &delay_us);
-   timeval_to_timespec(&delay_us, &sh->delay);
+   timersub(&pkt_diff, &diff, &delay);
+   timeval_to_timespec(&delay, &sh->delay);
}
+
+   memcpy(&sh->tstamp, &pkt->tstamp, sizeof(sh->tstamp));
}
 
if ((sh->delay.tv_sec | sh->delay.tv_nsec) > 0) {
@@ -698,7 +732,7 @@ retry:
num--;
 
if (shaper_is_set(&ctx->sh))
-   shaper_delay(&ctx->sh, packets[i].len);
+

[netsniff-ng] [PATCH 3/3] trafgen: man: Add description with pcap file for -i, --in option

2017-01-31 Thread Vadim Kochan
Update -i, --in option with pcap file as input parameter.

Signed-off-by: Vadim Kochan 
---
 trafgen.8 | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/trafgen.8 b/trafgen.8
index e09b7a0..fd9788a 100644
--- a/trafgen.8
+++ b/trafgen.8
@@ -66,10 +66,13 @@ given scenario.
 .PP
 .SH OPTIONS
 .PP
-.SS -i , -c , --in , --conf 
+.SS -i , -c , --in , --conf 
 Defines the input configuration file that can either be passed as a normal 
plain
 text file or via stdin (''-''). Note that currently, if a configuration is
 passed through stdin, only 1 CPU will be used.
+It is also possible to specify PCAP file with .pcap extension via -i,--in 
option,
+by default packets will be sent at rate considering timestamp from PCAP file 
which
+might be reset via -b/-t options.
 .PP
 .SS -o , -d , --out , --dev 
 Defines the outgoing networking device such as eth0, wlan0 and others.
-- 
2.11.0

-- 
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.


[netsniff-ng] [PATCH 1/3] pcap_io: Add function to get packet timestamp

2017-01-31 Thread Vadim Kochan
Add pcap_get_tstamp(...) function to get packet's timestamp considering
different packet types & bytes order.

Signed-off-by: Vadim Kochan 
---
 pcap_io.h | 53 +
 1 file changed, 53 insertions(+)

diff --git a/pcap_io.h b/pcap_io.h
index 4e41362..7bf5fe6 100644
--- a/pcap_io.h
+++ b/pcap_io.h
@@ -373,6 +373,59 @@ static inline void pcap_set_length(pcap_pkthdr_t *phdr, 
enum pcap_type type, u32
}
 }
 
+static inline void pcap_get_tstamp(pcap_pkthdr_t *phdr, enum pcap_type type,
+  struct timeval *tv)
+{
+   switch (type) {
+   case DEFAULT:
+   case DEFAULT_LL:
+   tv->tv_sec = phdr->ppo.ts.tv_sec;
+   tv->tv_usec = phdr->ppo.ts.tv_usec;
+   break;
+
+   case DEFAULT_SWAPPED:
+   case DEFAULT_LL_SWAPPED:
+   tv->tv_sec = ___constant_swab32(phdr->ppo.ts.tv_sec);
+   tv->tv_usec = ___constant_swab32(phdr->ppo.ts.tv_usec);
+   break;
+
+   case NSEC:
+   case NSEC_LL:
+   tv->tv_sec = phdr->ppn.ts.tv_sec;
+   tv->tv_usec = phdr->ppn.ts.tv_nsec / 1000;
+   break;
+
+   case NSEC_SWAPPED:
+   case NSEC_LL_SWAPPED:
+   tv->tv_sec = ___constant_swab32(phdr->ppn.ts.tv_sec);
+   tv->tv_usec = ___constant_swab32(phdr->ppn.ts.tv_nsec) / 1000;
+   break;
+
+   case KUZNETZOV:
+   tv->tv_sec = phdr->ppk.ts.tv_sec;
+   tv->tv_usec = phdr->ppk.ts.tv_usec;
+   break;
+
+   case KUZNETZOV_SWAPPED:
+   tv->tv_sec = ___constant_swab32(phdr->ppk.ts.tv_sec);
+   tv->tv_usec = ___constant_swab32(phdr->ppk.ts.tv_usec);
+   break;
+
+   case BORKMANN:
+   tv->tv_sec = phdr->ppb.ts.tv_sec;
+   tv->tv_usec = phdr->ppb.ts.tv_nsec / 1000;
+   break;
+
+   case BORKMANN_SWAPPED:
+   tv->tv_sec = ___constant_swab32(phdr->ppb.ts.tv_sec);
+   tv->tv_usec = ___constant_swab32(phdr->ppb.ts.tv_nsec) / 1000;
+   break;
+
+   default:
+   bug();
+   }
+}
+
 static inline u32 pcap_get_hdr_length(pcap_pkthdr_t *phdr, enum pcap_type type)
 {
switch (type) {
-- 
2.11.0

-- 
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.


[netsniff-ng] [PATCH 0/3] trafgen: Send packets from pcap file

2017-01-31 Thread Vadim Kochan
Allow to send packets at specified rate from ".pcap" file
which might be speified via -i,--in options.

By default packets will be send at original rate considering packet's
timestamp.

Vadim Kochan (3):
  pcap_io: Add function to get packet timestamp
  trafgen: Allow send packets from pcap file
  trafgen: man: Add description with pcap file for -i, --in option

 pcap_io.h|  53 +++
 trafgen.8|   5 +-
 trafgen.c| 155 +--
 trafgen/Makefile |   4 ++
 trafgen_conf.h   |   3 ++
 trafgen_parser.y |   2 +-
 6 files changed, 194 insertions(+), 28 deletions(-)

-- 
2.11.0

-- 
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.


Re: [netsniff-ng] Mausezahn - virtual nic "unknown physical layer type"

2017-01-31 Thread Vadim Kochan
BTW I did grep over the kernel and looks like it might the 'tun' device.

On Tue, Jan 31, 2017 at 12:38 PM, Vadim Kochan  wrote:
> On Tue, Jan 31, 2017 at 12:36 PM, Vadim Kochan  wrote:
>> On Tue, Jan 31, 2017 at 12:47 AM, Jojonix1-Web  wrote:
>>> Hello dear netsniff team
>>>
>>>
>>>
>>> My name is Jonathan, I am an IT specialist from Germany and I have some
>>> difficulties with Mausezahn.
>>>
>>>
>>>
>>> I am running a virtual server with Ubuntu 14.04 LTS. I wanted to test my
>>> DDoS protection, but Mausezahn is unable to send those frames through the
>>> virtual NIC. There is no problem with the Local Loopback. Is this a known
>>> incident? Is there anything I can do to get it running?
>>>
>>>
>>>
>>> I had updated the pcap files before I tried and tshark is able to scan the
>>> virtual NIC without any troubles.
>>>
>>>
>>>
>>> The error message is:
>>>
>>> libnet_init() failed (unknown physical layer type 0x) Invalid command
>>> line parameters!
>>>
>>>
>>>
>>> I am looking forward to your reply.
>>>
>>>
>>>
>>> Greetings from Germany
>>>
>>> Jonathan
>>>
>>> --
>>> 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.
>>
>> Hi Jonathan,
>>
>> 1st thing which comes to mind is that the link type of this interface
>> is "none" or "void", and
>> libnet can't handle it.
>>
>> Could you please give some details about this interface with 'ip link'
>> and ifconfig output ?
>> Also you can try to use trafgen for DDoS testing.
>>
>> Regards,
>> Vadim Kochan
>
> CC Jonathan

-- 
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.


Re: [netsniff-ng] Mausezahn - virtual nic "unknown physical layer type"

2017-01-31 Thread Vadim Kochan
On Tue, Jan 31, 2017 at 12:36 PM, Vadim Kochan  wrote:
> On Tue, Jan 31, 2017 at 12:47 AM, Jojonix1-Web  wrote:
>> Hello dear netsniff team
>>
>>
>>
>> My name is Jonathan, I am an IT specialist from Germany and I have some
>> difficulties with Mausezahn.
>>
>>
>>
>> I am running a virtual server with Ubuntu 14.04 LTS. I wanted to test my
>> DDoS protection, but Mausezahn is unable to send those frames through the
>> virtual NIC. There is no problem with the Local Loopback. Is this a known
>> incident? Is there anything I can do to get it running?
>>
>>
>>
>> I had updated the pcap files before I tried and tshark is able to scan the
>> virtual NIC without any troubles.
>>
>>
>>
>> The error message is:
>>
>> libnet_init() failed (unknown physical layer type 0x) Invalid command
>> line parameters!
>>
>>
>>
>> I am looking forward to your reply.
>>
>>
>>
>> Greetings from Germany
>>
>> Jonathan
>>
>> --
>> 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.
>
> Hi Jonathan,
>
> 1st thing which comes to mind is that the link type of this interface
> is "none" or "void", and
> libnet can't handle it.
>
> Could you please give some details about this interface with 'ip link'
> and ifconfig output ?
> Also you can try to use trafgen for DDoS testing.
>
> Regards,
> Vadim Kochan

CC Jonathan

-- 
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.


Re: [netsniff-ng] Mausezahn - virtual nic "unknown physical layer type"

2017-01-31 Thread Vadim Kochan
On Tue, Jan 31, 2017 at 12:47 AM, Jojonix1-Web  wrote:
> Hello dear netsniff team
>
>
>
> My name is Jonathan, I am an IT specialist from Germany and I have some
> difficulties with Mausezahn.
>
>
>
> I am running a virtual server with Ubuntu 14.04 LTS. I wanted to test my
> DDoS protection, but Mausezahn is unable to send those frames through the
> virtual NIC. There is no problem with the Local Loopback. Is this a known
> incident? Is there anything I can do to get it running?
>
>
>
> I had updated the pcap files before I tried and tshark is able to scan the
> virtual NIC without any troubles.
>
>
>
> The error message is:
>
> libnet_init() failed (unknown physical layer type 0x) Invalid command
> line parameters!
>
>
>
> I am looking forward to your reply.
>
>
>
> Greetings from Germany
>
> Jonathan
>
> --
> 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.

Hi Jonathan,

1st thing which comes to mind is that the link type of this interface
is "none" or "void", and
libnet can't handle it.

Could you please give some details about this interface with 'ip link'
and ifconfig output ?
Also you can try to use trafgen for DDoS testing.

Regards,
Vadim Kochan

-- 
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.


[netsniff-ng] Mausezahn - virtual nic "unknown physical layer type"

2017-01-31 Thread Jojonix1-Web
Hello dear netsniff team

 

My name is Jonathan, I am an IT specialist from Germany and I have some
difficulties with Mausezahn.

 

I am running a virtual server with Ubuntu 14.04 LTS. I wanted to test my
DDoS protection, but Mausezahn is unable to send those frames through the
virtual NIC. There is no problem with the Local Loopback. Is this a known
incident? Is there anything I can do to get it running?

 

I had updated the pcap files before I tried and tshark is able to scan the
virtual NIC without any troubles.

 

The error message is:

libnet_init() failed (unknown physical layer type 0x) Invalid command
line parameters!

 

I am looking forward to your reply.

 

Greetings from Germany

Jonathan

-- 
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.