[netsniff-ng] Re: [PATCH 13/15] trafgen: parser: Add support of 'dinc' function for proto fields

2016-08-03 Thread Tobias Klauser
On 2016-07-26 at 21:35:18 +0200, Vadim Kochan  wrote:
> Add 'dinc()' function in 'field_expr' rules to be used for dynamically
> incrementing of any specified field:
> 
> SYNTAX := dinc() | dinc(inc) | dinc(min, max) | dinc(inc, min, max)

This should definitely follow the same parameter order as the existing
dinc() function!!!

> EXAMPLES:
> { udp(sport=dinc() }
> { udp(sport=dinc(1) }
> { udp(sport=dinc(5, 100, 125) }

> Signed-off-by: Vadim Kochan 
> ---
>  trafgen_parser.y | 51 +++
>  1 file changed, 51 insertions(+)
> 
> diff --git a/trafgen_parser.y b/trafgen_parser.y
> index 58ac999..7872b7c 100644
> --- a/trafgen_parser.y
> +++ b/trafgen_parser.y
> @@ -74,6 +74,7 @@ enum field_expr_type_t {
>   FIELD_EXPR_MAC,
>   FIELD_EXPR_IP4_ADDR,
>   FIELD_EXPR_IP6_ADDR,
> + FIELD_EXPR_INC,
>  };
>  
>  struct proto_field_expr {
> @@ -85,6 +86,7 @@ struct proto_field_expr {
>   struct in6_addr ip6_addr;
>   long long int number;
>   uint8_t bytes[256];
> + struct proto_field_func func;
>   } val;
>  };
>  
> @@ -125,6 +127,12 @@ static inline void __init_new_csum_slot(struct 
> packet_dyn *slot)
>   slot->slen = 0;
>  }
>  
> +static inline void __init_new_fields_slot(struct packet_dyn *slot)
> +{
> + slot->fields = NULL;
> + slot->flen = 0;
> +}
> +
>  static inline void __setup_new_counter(struct counter *c, uint8_t start,
>  uint8_t stop, uint8_t stepping,
>  int type)
> @@ -167,6 +175,7 @@ static void realloc_packet(void)
>   __init_new_counter_slot(_dyn[packetd_last]);
>   __init_new_randomizer_slot(_dyn[packetd_last]);
>   __init_new_csum_slot(_dyn[packetd_last]);
> + __init_new_fields_slot(_dyn[packetd_last]);
>  }
>  
>  struct packet *current_packet(void)
> @@ -376,6 +385,19 @@ static void proto_field_set(uint32_t fid)
>   field_expr.field = proto_field_by_id(hdr, fid);
>  }
>  
> +static void proto_field_func_setup(struct proto_field *field, struct 
> proto_field_func *func)
> +{
> + struct packet_dyn *pkt_dyn;
> +
> + proto_field_func_add(field->hdr, field->id, func);
> +
> + pkt_dyn = _dyn[packetd_last];
> + pkt_dyn->flen++;
> + pkt_dyn->fields = (struct proto_field **)xrealloc(pkt_dyn->fields, 
> pkt_dyn->flen *
> + sizeof(struct proto_field *));

No need to case the return value of xrealloc()

> + pkt_dyn->fields[pkt_dyn->flen - 1] = field;
> +}
> +
>  static void proto_field_expr_eval(void)
>  {
>   struct proto_field *field = field_expr.field;
> @@ -405,6 +427,14 @@ static void proto_field_expr_eval(void)
>   (uint8_t *)_expr.val.ip6_addr.s6_addr);
>   break;
>  
> + case FIELD_EXPR_INC:
> + if (field_expr.val.func.min > field_expr.val.func.max)
> + panic("dinc(): min(%u) can't be greater than max(%u)\n",
> + field_expr.val.func.min, 
> field_expr.val.func.max);
> +
> + proto_field_func_setup(field, _expr.val.func);
> + break;
> +
>   case FIELD_EXPR_UNKNOWN:
>   default:
>   bug();
> @@ -685,6 +715,26 @@ field_expr
>field_expr.val.ip4_addr = $1; }
>   | ip6_addr { field_expr.type = FIELD_EXPR_IP6_ADDR;
>field_expr.val.ip6_addr = $1; }
> + | K_DINC '(' ')' { field_expr.type = FIELD_EXPR_INC;
> +field_expr.val.func.type = PROTO_FIELD_FUNC_INC;
> +field_expr.val.func.inc = 1; }
> + | K_DINC '(' number ')'
> + { field_expr.type = FIELD_EXPR_INC;
> +   field_expr.val.func.inc = $3; }
> + | K_DINC '(' number delimiter number ')'
> + { field_expr.type = FIELD_EXPR_INC;
> +   field_expr.val.func.type  = PROTO_FIELD_FUNC_INC;
> +   field_expr.val.func.type |= PROTO_FIELD_FUNC_MIN;
> +   field_expr.val.func.inc = 1;
> +   field_expr.val.func.min = $3;
> +   field_expr.val.func.max = $5; }
> + | K_DINC '(' number delimiter number delimiter number ')'
> + { field_expr.type = FIELD_EXPR_INC;
> +   field_expr.val.func.type  = PROTO_FIELD_FUNC_INC;
> +   field_expr.val.func.type |= PROTO_FIELD_FUNC_MIN;
> +   field_expr.val.func.inc = $3;
> +   field_expr.val.func.min = $5;
> +   field_expr.val.func.max = $7; }
>   ;
>  
>  eth_proto
> @@ -1097,6 +1147,7 @@ void cleanup_packets(void)
>   for (i = 0; i < dlen; ++i) {
>   free(packet_dyn[i].cnt);
>   free(packet_dyn[i].rnd);
> + free(packet_dyn[i].fields);
>   }
>  
>   

[netsniff-ng] Re: [PATCH 05/15] trafgen: proto: Increment proto field at runtime

2016-08-03 Thread Tobias Klauser
On 2016-07-26 at 21:35:10 +0200, Vadim Kochan  wrote:
> Extended 'struct packet_dyn' with proto fields which has
> dynamically changing values at runtime.
> 
> Implement incrementing of proto field at runtime with min & max
> parameters, by default if the 'min' parameter is not specified
> then original value is used. For fields which len is greater
> than 4 - last 4 bytes are incremented as unsigned int value.
> 
> Added 'field_changed' callback for proto header which
> may be used for check if csum updating is needed. This callback
> is called after field was changed at runtime.
> 
> Added 'packet_update' callback to let proto header know
> when to apply final proto header changes at runtime (csum update).

The documentation of these callbacks would also make sense where they're
defined.

> Signed-off-by: Vadim Kochan 
> ---
>  trafgen.c   |  9 ++
>  trafgen_conf.h  |  7 
>  trafgen_proto.c | 99 
> +
>  trafgen_proto.h | 26 +++
>  4 files changed, 141 insertions(+)
> 
> diff --git a/trafgen.c b/trafgen.c
> index b76b5d7..553dfa5 100644
> --- a/trafgen.c
> +++ b/trafgen.c
> @@ -619,6 +619,15 @@ static inline void packet_apply_dyn_elements(int idx)
>   apply_randomizer(idx);
>   apply_csum16(idx);
>   }
> +
> + if (packet_dyn_has_fields(_dyn[idx])) {
> + uint32_t i;
> +
> + for (i = 0; i < packet_dyn[idx].flen; i++)
> + proto_field_dyn_apply(packet_dyn[idx].fields[i]);
> +
> + proto_packet_update(idx);
> + }
>  }
>  
>  static void xmit_slowpath_or_die(struct ctx *ctx, unsigned int cpu, unsigned 
> long orig_num)
> diff --git a/trafgen_conf.h b/trafgen_conf.h
> index 934f8fe..7f3616c 100644
> --- a/trafgen_conf.h
> +++ b/trafgen_conf.h
> @@ -49,6 +49,8 @@ struct packet_dyn {
>   size_t rlen;
>   struct csum16 *csum;
>   size_t slen;
> + struct proto_field **fields;
> + uint32_t flen;
>  };
>  
>  static inline bool packet_dyn_has_elems(struct packet_dyn *p)
> @@ -61,6 +63,11 @@ static inline bool packet_dyn_has_only_csums(struct 
> packet_dyn *p)
>   return (p->clen == 0 && p->rlen == 0 && p->slen);
>  }
>  
> +static inline bool packet_dyn_has_fields(struct packet_dyn *p)
> +{
> + return !!p->flen;
> +}
> +
>  extern void compile_packets_str(char *str, bool verbose, unsigned int cpu);
>  extern void compile_packets(char *file, bool verbose, unsigned int cpu,
>   bool invoke_cpp, char *const cpp_argv[]);
> diff --git a/trafgen_proto.c b/trafgen_proto.c
> index ce389ce..069aa00 100644
> --- a/trafgen_proto.c
> +++ b/trafgen_proto.c
> @@ -419,6 +419,19 @@ void protos_init(const char *dev)
>   p->ctx = 
>  }
>  
> +void proto_packet_update(uint32_t idx)
> +{
> + struct packet *pkt = packet_get(idx);
> + ssize_t i;
> +
> + for (i = pkt->headers_count - 1; i >= 0; i--) {
> + struct proto_hdr *hdr = pkt->headers[i];
> +
> + if (hdr->packet_update)
> + hdr->packet_update(hdr);
> + }
> +}
> +
>  void proto_packet_finish(void)
>  {
>   struct proto_hdr **headers = _packet()->headers[0];
> @@ -433,3 +446,89 @@ void proto_packet_finish(void)
>   p->packet_finish(p);
>   }
>  }
> +
> +static inline unsigned int field_inc(struct proto_field *field)
> +{
> + uint32_t val;
> +
> + val = field->func.val - field->func.min;
> + val = (val + field->func.inc) % field->func.max;

Shouldn't this be

val = (val + field->func.inc) % (field->func.max - field->func.min + 1)

to be consistent with apply_counter()?

Also, I think you should probably get rid of as many pointer
dereferences as possible in these runtime functions, i.e. store max and
min in temporary variables.

> + field->func.val = val + field->func.min;
> +
> + return field->func.val;
> +}
> +
> +static void field_inc_func(struct proto_field *field)
> +{
> + if (field->len == 1) {
> + uint8_t val;
> +
> + val = field_inc(field);
> + proto_field_set_u8(field->hdr, field->id, val);

Assignment on declaration please. Or even better:

proto_field_set_u8(field->hdr, field->id, field_inc(field));

> + } else if (field->len == 2) {
> + uint16_t val;
> +
> + val = field_inc(field);
> + proto_field_set_be16(field->hdr, field->id, val);

Same.

> + } else if (field->len == 4) {
> + uint32_t val;
> +
> + val = field_inc(field);
> + proto_field_set_be32(field->hdr, field->id, val);

Same.

> + } else if (field->len > 4) {
> + uint8_t *bytes = __proto_field_get_bytes(field);
> + uint32_t val;
> +
> + bytes += field->len - 4;
> + val = field_inc(field);
> +
> + *(uint32_t *)bytes = bswap_32(val);

This 

[netsniff-ng] Re: [PATCH v2 1/3] configure: Add option to compile tools without libnl dependency

2016-08-03 Thread Vadim Kochan
Ehh, too fast  I need to avoid libnl compilation testing if
CONFIG_LIBNL=0, will resend it, sorry ...

On Wed, Aug 3, 2016 at 11:58 AM, Vadim Kochan  wrote:
> Add command line parsing function which allows to compile tools
> (trafgen, netsniff-ng) without libnl-xxx libraries.
>
> Option --disable-libnl sets CONFIG_LIBNL=0 which means compile tools
> without libnl dependencies.
>
> Signed-off-by: Vadim Kochan 
> ---
>  configure | 47 ---
>  1 file changed, 44 insertions(+), 3 deletions(-)
>
> diff --git a/configure b/configure
> index 105b1ec..61b2e31 100755
> --- a/configure
> +++ b/configure
> @@ -18,8 +18,36 @@ HAVE_LIBGEOIP=0
>  HAVE_LIBZ=0
>  HAVE_TPACKET3=0
>
> +CONFIG_LIBNL=1
> +
>  # use "CROSS_COMPILE= SYSROOT= ./configure && make" for cross 
> compilation
>
> +usage()
> +{
> +   echo "Usage: ./configure [OPTIONS]"
> +   echo -e  "\t-h, --help  - print usage"
> +   echo -ne "\t--disable-libnl - compile without libnl."
> +   echo "Some features (rfraw, nlmsg dissect) will not work in trafgen, 
> netsniff-ng."
> +
> +   exit 0
> +}
> +
> +while [ $# -gt 0 ]
> +do
> +   case "$1" in
> +   -h|--help)
> +   usage
> +   ;;
> +   --disable-libnl)
> +   CONFIG_LIBNL=0
> +   ;;
> +   *)
> +   usage
> +   ;;
> +   esac
> +   shift
> +done
> +
>  [ -z "$CC" ] && CC="${CROSS_COMPILE}gcc"
>  [ -z "$LD" ] && LD="${CROSS_COMPILE}gcc"
>  if [ "x$SYSROOT" != "x" ] ; then
> @@ -194,8 +222,10 @@ EOF
> if [ ! -x $TMPDIR/libnltest ] ; then
> echo "[NO]"
> MISSING_DEFS=1
> -   tools_remove "trafgen"
> -   tools_remove "netsniff-ng"
> +   if [ "$CONFIG_LIBNL" == "1" ]; then
> +   tools_remove "trafgen"
> +   tools_remove "netsniff-ng"
> +   fi
> else
> echo "[YES]"
> fi
> @@ -230,7 +260,9 @@ EOF
> if [ ! -x $TMPDIR/libnlroutetest ] ; then
> echo "[NO]"
> MISSING_DEFS=1
> -   tools_remove "netsniff-ng"
> +   if [ "$CONFIG_LIBNL" == "1" ]; then
> +   tools_remove "netsniff-ng"
> +   fi
> else
> echo "[YES]"
> fi
> @@ -600,6 +632,7 @@ gen_config_hdr()
> local _have_libz=""
> local _have_hwts=""
> local _have_tp3=""
> +   local _config_libnl=""
>
> echo "[*] Generating config.h ..."
>
> @@ -640,6 +673,12 @@ gen_config_hdr()
> _have_tp3="/* HAVE_TPACKET3 is not defined */"
> fi
>
> +   if [ "$CONFIG_LIBNL" == "1" ] ; then
> +   _config_libnl="#define CONFIG_LIBNL 1"
> +   else
> +   _config_libnl="/* CONFIG_LIBNL is not defined */"
> +   fi
> +
> cat > config.h << EOF
>  #ifndef CONFIG_H
>  #define CONFIG_H
> @@ -654,6 +693,7 @@ $_have_libgeoip
>  $_have_libz
>  $_have_hwts
>  $_have_tp3
> +$_config_libnl
>  #endif /* CONFIG_H */
>  EOF
>  }
> @@ -721,6 +761,7 @@ else
> echo "CONFIG_GEOIP=0" >> Config
>  fi
>
> +echo "CONFIG_LIBNL=$CONFIG_LIBNL" >> Config
>  echo "CONFIG_TOOLS=$TOOLS" >> Config
>  echo "CONFIG_OK=1" >> Config
>
> --
> 2.6.3
>

-- 
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 v2 0/3] build: Allow compile trafgen & netsniff-ng without libnl

2016-08-03 Thread Vadim Kochan
It might be useful only if to compile trafgen or netsniff-ng in environment
(or manually w/o needs for rfraw) where is no needed libnl (embedded/switch 
server),
and it would be good to have ability to disable libnl dependency at all even w/o
such features like rfraw dissect/inject & nlmsg dissecting. For example
netsniff-ng might be used just for sniffing, and trafgen - send packets to wired
network only.

Therefor added --no-libnl option in ./confiure script which sets make option &
CPP definition which are used to ignore libnl- related code/modules/libraries.

v2:
1) Reorder commits to be "configure" related changes  1st
2) Changed CONFIG_NO_LIBNL -> CONFIG_LIBNL
3) Changed "configure" option --no-libnl -> --disable-libnl

Tested on the VM Linux setup with and without libnl packages.

Vadim Kochan (3):
  configure: Add option to compile tools without libnl dependency
  trafgen: Allow to compile without libnl
  netsniff-ng: Allow compile without libnl

 configure| 47 ---
 dissector.h  |  4 ++--
 dissector_netlink.c  |  4 
 dissector_netlink.h  |  4 
 dissector_sll.c  |  5 -
 mac80211.c   |  1 -
 mac80211.h   | 15 +++
 netsniff-ng/Makefile | 27 +--
 trafgen/Makefile | 21 +++--
 9 files changed, 105 insertions(+), 23 deletions(-)

-- 
2.6.3

-- 
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 v2 3/3] netsniff-ng: Allow compile without libnl

2016-08-03 Thread Vadim Kochan
There is reason to do not install libnl-xxx packages just
for sniffing packets, for example if netsniff-ng will be compiled
on embedded or switch system.

Hide libnl depended code if CONFIG_LIBNL=0.

In case if user will use --rfraw option the panic message will be printed,
in case if netlink messages will be sniffed the noop dissector will be used.

Signed-off-by: Vadim Kochan 
---
 dissector.h  |  4 ++--
 dissector_netlink.c  |  4 
 dissector_netlink.h  |  4 
 dissector_sll.c  |  5 -
 netsniff-ng/Makefile | 27 +--
 5 files changed, 31 insertions(+), 13 deletions(-)

diff --git a/dissector.h b/dissector.h
index 52f341b..0689247 100644
--- a/dissector.h
+++ b/dissector.h
@@ -10,9 +10,9 @@
 #include 
 #include 
 #include 
-#include 
 #include 
-#include 
+#include 
+#include 
 
 #include "ring.h"
 #include "tprintf.h"
diff --git a/dissector_netlink.c b/dissector_netlink.c
index 2b23a99..640b286 100644
--- a/dissector_netlink.c
+++ b/dissector_netlink.c
@@ -9,7 +9,11 @@
 
 static inline void dissector_init_entry(int type)
 {
+#ifndef CONFIG_LIBNL
+   dissector_set_print_type(_ops, type);
+#else
dissector_set_print_type(_ops, type);
+#endif
 }
 
 static inline void dissector_init_exit(int type)
diff --git a/dissector_netlink.h b/dissector_netlink.h
index 9d30e56..2614250 100644
--- a/dissector_netlink.h
+++ b/dissector_netlink.h
@@ -14,7 +14,11 @@ extern void dissector_cleanup_netlink(void);
 
 static inline struct protocol *dissector_get_netlink_entry_point(void)
 {
+#ifndef CONFIG_LIBNL
+   return _ops;
+#else
return _ops;
+#endif
 }
 
 static inline struct protocol *dissector_get_netlink_exit_point(void)
diff --git a/dissector_sll.c b/dissector_sll.c
index cde0d54..10fd7d9 100644
--- a/dissector_sll.c
+++ b/dissector_sll.c
@@ -3,12 +3,15 @@
  * Subject to the GPL, version 2.
  */
 
+#include 
+
 #include "protos.h"
 #include "pcap_io.h"
 #include "pkt_buff.h"
 #include "dissector.h"
 #include "dissector_sll.h"
 #include "dissector_eth.h"
+#include "dissector_netlink.h"
 #include "lookup.h"
 
 static char *pkt_type2str(uint8_t pkttype)
@@ -56,7 +59,7 @@ static void sll_print_full(struct pkt_buff *pkt)
break;
case LINKTYPE_NETLINK:
case ___constant_swab32(LINKTYPE_NETLINK):
-   pkt->dissector = _ops;
+   pkt->dissector = dissector_get_netlink_entry_point();
break;
default:
tprintf(" [ Unknown protocol ]\n");
diff --git a/netsniff-ng/Makefile b/netsniff-ng/Makefile
index 6f9d0b2..d1d8a85 100644
--- a/netsniff-ng/Makefile
+++ b/netsniff-ng/Makefile
@@ -1,7 +1,4 @@
-netsniff-ng-libs = $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) 
$(PKG_CONFIG) --libs libnl-3.0) \
-   $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) 
$(PKG_CONFIG) --libs libnl-genl-3.0) \
-   $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) 
$(PKG_CONFIG) --libs libnl-route-3.0) \
-   -lpthread
+netsniff-ng-libs = -lpthread
 
 ifeq ($(CONFIG_LIBPCAP), 1)
 netsniff-ng-libs +=-lpcap
@@ -10,6 +7,11 @@ ifeq ($(CONFIG_GEOIP), 1)
 netsniff-ng-libs +=-lGeoIP \
-lz
 endif
+ifeq ($(CONFIG_LIBNL), 1)
+netsniff-ng-libs +=$(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) 
$(PKG_CONFIG) --libs libnl-3.0) \
+   $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) 
$(PKG_CONFIG) --libs libnl-genl-3.0) \
+   $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) 
$(PKG_CONFIG) --libs libnl-route-3.0)
+endif
 
 netsniff-ng-objs = dissector.o \
dissector_sll.o \
@@ -34,7 +36,6 @@ netsniff-ng-objs =dissector.o \
proto_ipv6_no_nxt_hdr.o \
proto_ipv6_routing.o \
proto_lldp.o \
-   proto_nlmsg.o \
proto_none.o \
proto_tcp.o \
proto_udp.o \
@@ -63,7 +64,6 @@ netsniff-ng-objs =dissector.o \
ring.o \
tprintf.o \
timer.o \
-   mac80211.o \
die.o \
sysctl.o \
netsniff-ng.o
@@ -77,11 +77,18 @@ endif
 ifeq ($(CONFIG_HWTSTAMP), 1)
 netsniff-ng-objs +=tstamping.o
 endif
+ifeq ($(CONFIG_LIBNL), 1)
+netsniff-ng-objs +=mac80211.o \
+   proto_nlmsg.o
+endif
+
+netsniff-ng-eflags = -DNEED_TCPDUMP_LIKE_FILTER
 
-netsniff-ng-eflags = $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG) 
--cflags libnl-3.0) \
-$(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG) 
--cflags libnl-genl-3.0) \
-$(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG) 
--cflags libnl-route-3.0) \
--DNEED_TCPDUMP_LIKE_FILTER
+ifeq ($(CONFIG_LIBNL), 1)
+netsniff-ng-eflags 

[netsniff-ng] [PATCH v2 1/3] configure: Add option to compile tools without libnl dependency

2016-08-03 Thread Vadim Kochan
Add command line parsing function which allows to compile tools
(trafgen, netsniff-ng) without libnl-xxx libraries.

Option --disable-libnl sets CONFIG_LIBNL=0 which means compile tools
without libnl dependencies.

Signed-off-by: Vadim Kochan 
---
 configure | 47 ---
 1 file changed, 44 insertions(+), 3 deletions(-)

diff --git a/configure b/configure
index 105b1ec..61b2e31 100755
--- a/configure
+++ b/configure
@@ -18,8 +18,36 @@ HAVE_LIBGEOIP=0
 HAVE_LIBZ=0
 HAVE_TPACKET3=0
 
+CONFIG_LIBNL=1
+
 # use "CROSS_COMPILE= SYSROOT= ./configure && make" for cross 
compilation
 
+usage()
+{
+   echo "Usage: ./configure [OPTIONS]"
+   echo -e  "\t-h, --help  - print usage"
+   echo -ne "\t--disable-libnl - compile without libnl."
+   echo "Some features (rfraw, nlmsg dissect) will not work in trafgen, 
netsniff-ng."
+
+   exit 0
+}
+
+while [ $# -gt 0 ]
+do
+   case "$1" in
+   -h|--help)
+   usage
+   ;;
+   --disable-libnl)
+   CONFIG_LIBNL=0
+   ;;
+   *)
+   usage
+   ;;
+   esac
+   shift
+done
+
 [ -z "$CC" ] && CC="${CROSS_COMPILE}gcc"
 [ -z "$LD" ] && LD="${CROSS_COMPILE}gcc"
 if [ "x$SYSROOT" != "x" ] ; then
@@ -194,8 +222,10 @@ EOF
if [ ! -x $TMPDIR/libnltest ] ; then
echo "[NO]"
MISSING_DEFS=1
-   tools_remove "trafgen"
-   tools_remove "netsniff-ng"
+   if [ "$CONFIG_LIBNL" == "1" ]; then
+   tools_remove "trafgen"
+   tools_remove "netsniff-ng"
+   fi
else
echo "[YES]"
fi
@@ -230,7 +260,9 @@ EOF
if [ ! -x $TMPDIR/libnlroutetest ] ; then
echo "[NO]"
MISSING_DEFS=1
-   tools_remove "netsniff-ng"
+   if [ "$CONFIG_LIBNL" == "1" ]; then
+   tools_remove "netsniff-ng"
+   fi
else
echo "[YES]"
fi
@@ -600,6 +632,7 @@ gen_config_hdr()
local _have_libz=""
local _have_hwts=""
local _have_tp3=""
+   local _config_libnl=""
 
echo "[*] Generating config.h ..."
 
@@ -640,6 +673,12 @@ gen_config_hdr()
_have_tp3="/* HAVE_TPACKET3 is not defined */"
fi
 
+   if [ "$CONFIG_LIBNL" == "1" ] ; then
+   _config_libnl="#define CONFIG_LIBNL 1"
+   else
+   _config_libnl="/* CONFIG_LIBNL is not defined */"
+   fi
+
cat > config.h << EOF
 #ifndef CONFIG_H
 #define CONFIG_H
@@ -654,6 +693,7 @@ $_have_libgeoip
 $_have_libz
 $_have_hwts
 $_have_tp3
+$_config_libnl
 #endif /* CONFIG_H */
 EOF
 }
@@ -721,6 +761,7 @@ else
echo "CONFIG_GEOIP=0" >> Config
 fi
 
+echo "CONFIG_LIBNL=$CONFIG_LIBNL" >> Config
 echo "CONFIG_TOOLS=$TOOLS" >> Config
 echo "CONFIG_OK=1" >> Config
 
-- 
2.6.3

-- 
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 v2 2/3] trafgen: Allow to compile without libnl

2016-08-03 Thread Vadim Kochan
trafgen uses libnl only to inject mac80211 frames but
it might be not needed in some embedded or switch environments,
so lets make possible to disable this feature.

In case if --rfraw option will be used - user will get the panic message.

Signed-off-by: Vadim Kochan 
---
 mac80211.c   |  1 -
 mac80211.h   | 15 +++
 trafgen/Makefile | 21 +++--
 3 files changed, 30 insertions(+), 7 deletions(-)

diff --git a/mac80211.c b/mac80211.c
index f22b600..9aea5a0 100644
--- a/mac80211.c
+++ b/mac80211.c
@@ -24,7 +24,6 @@
 #include 
 #include 
 
-#include "die.h"
 #include "str.h"
 #include "dev.h"
 #include "mac80211.h"
diff --git a/mac80211.h b/mac80211.h
index dea4ae0..692de4c 100644
--- a/mac80211.h
+++ b/mac80211.h
@@ -1,7 +1,22 @@
 #ifndef MAC80211_H
 #define MAC80211_H
 
+#include "die.h"
+#include "config.h"
+
+#ifndef CONFIG_LIBNL
+static inline void enter_rfmon_mac80211(const char *device, char **mondev)
+{
+panic("enter_rfmon_mac80211: CONFIG_LIBNL option needs to be enabled\n");
+}
+
+static inline void leave_rfmon_mac80211(const char *mondev)
+{
+panic("leave_rfmon_mac80211: CONFIG_LIBNL option needs to be enabled\n");
+}
+#else
 extern void enter_rfmon_mac80211(const char *device, char **mondev);
 extern void leave_rfmon_mac80211(const char *mondev);
+#endif /* CONFIG_LIBNL */
 
 #endif /* MAC80211_H */
diff --git a/trafgen/Makefile b/trafgen/Makefile
index 3f78f07..876ed93 100644
--- a/trafgen/Makefile
+++ b/trafgen/Makefile
@@ -1,6 +1,9 @@
-trafgen-libs = $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG) --libs 
libnl-3.0) \
-   $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG) --libs 
libnl-genl-3.0) \
-   -lm
+trafgen-libs = -lm
+
+ifeq ($(CONFIG_LIBNL), 1)
+trafgen-libs +=$(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) 
$(PKG_CONFIG) --libs libnl-3.0) \
+   $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG) --libs 
libnl-genl-3.0)
+endif
 
 trafgen-objs = xmalloc.o \
die.o \
@@ -13,7 +16,6 @@ trafgen-objs =xmalloc.o \
str.o \
sig.o \
sock.o \
-   mac80211.o \
ring_tx.o \
ring.o \
timer.o \
@@ -27,13 +29,20 @@ trafgen-objs =  xmalloc.o \
trafgen_parser.tab.o \
trafgen.o
 
+ifeq ($(CONFIG_LIBNL), 1)
+trafgen-objs += mac80211.o
+endif
+
 trafgen-lex =  trafgen_lexer.yy.o
 
 trafgen-yaac = trafgen_parser.tab.o
 
+trafgen-eflags = -I..
+
+ifeq ($(CONFIG_LIBNL), 1)
 trafgen-eflags = $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG) 
--cflags libnl-3.0) \
-$(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG) 
--cflags libnl-genl-3.0) \
--I..
+$(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG) 
--cflags libnl-genl-3.0)
+endif
 
 trafgen-confs =trafgen_stddef.h
 
-- 
2.6.3

-- 
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] Re: [PATCH 1/3] trafgen: Allow to compile without libnl

2016-08-03 Thread Daniel Borkmann

On 08/03/2016 09:34 AM, Tobias Klauser wrote:
[...]

Form the point of view of compiling nesniff-ng/trafgen there is no
difference of whether an external library "exists" or was explicitely
disabled by the user. I'd really prefer CONFIG_LIBNL for this and I
don't think more fine-grained control (CONFIG_LIBNL_*) will be needed,
as we gain relatively little compared to the amount of #ifdef complexity
we introduce.


Agree, CONFIG_LIBNL is a better choice.

--
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] Re: [PATCH 1/3] trafgen: Allow to compile without libnl

2016-08-03 Thread Vadim Kochan
OK, thank you!

On Wed, Aug 3, 2016 at 10:34 AM, Tobias Klauser  wrote:
> On 2016-08-02 at 22:17:41 +0200, Vadim Kochan  wrote:
>> On Tue, Aug 2, 2016 at 11:23 AM, Tobias Klauser  wrote:
>> > On 2016-07-31 at 23:13:16 +0200, Vadim Kochan  wrote:
>> >> trafgen uses libnl only to inject mac80211 frames but
>> >> it might be not needed in some embedded or switch environments,
>> >> so lets make possible to disable this feature.
>> >>
>> >> In case if --rfraw option will be used - user will get the panic message.
>> >>
>> >> Signed-off-by: Vadim Kochan 
>> >> ---
>> >>  mac80211.c   |  1 -
>> >>  mac80211.h   | 15 +++
>> >>  trafgen/Makefile | 21 +++--
>> >>  3 files changed, 30 insertions(+), 7 deletions(-)
>> >>
>> >> diff --git a/mac80211.c b/mac80211.c
>> >> index f22b600..9aea5a0 100644
>> >> --- a/mac80211.c
>> >> +++ b/mac80211.c
>> >> @@ -24,7 +24,6 @@
>> >>  #include 
>> >>  #include 
>> >>
>> >> -#include "die.h"
>> >>  #include "str.h"
>> >>  #include "dev.h"
>> >>  #include "mac80211.h"
>> >> diff --git a/mac80211.h b/mac80211.h
>> >> index dea4ae0..2780c03 100644
>> >> --- a/mac80211.h
>> >> +++ b/mac80211.h
>> >> @@ -1,7 +1,22 @@
>> >>  #ifndef MAC80211_H
>> >>  #define MAC80211_H
>> >>
>> >> +#include "die.h"
>> >> +#include "config.h"
>> >> +
>> >> +#ifdef CONFIG_NO_LIBNL
>> >> +static inline void enter_rfmon_mac80211(const char *device, char 
>> >> **mondev)
>> >> +{
>> >> +panic("enter_rfmon_mac80211: CONFIG_NO_LIBNL option needs to be 
>> >> disabled\n");
>> >> +}
>> >> +
>> >> +static inline void leave_rfmon_mac80211(const char *mondev)
>> >> +{
>> >> +panic("leave_rfmon_mac80211: CONFIG_NO_LIBNL option needs to be 
>> >> disabled\n");
>> >> +}
>> >
>> > These messages both have a double negative which isn't very easy to
>> > understand. I suggest to call the CONFIG directive CONFIG_LIBNL instead
>> > which is also more in line with the other library CONFIG_* directives we
>> > have.
>> >
>> > Also, you use the CONFIG_NO_LIBNL without setting it anywhere, this is
>> > only done in patch 3/3. Please change the series order to make the
>> > configure change come first.
>>
>> I really think that CONFIG_{DISABLE or ENABLE}_LIBNL might be better
>> because we really enable/disable it,
>> but CONFIG_LIBNL is rather about existence of package, if to use this
>> way then it will be needed (probably) to add C defines for
>> CONFIG_LIBNL_ROUTE, CONFIG_LIBNL_GENL.
>
> Form the point of view of compiling nesniff-ng/trafgen there is no
> difference of whether an external library "exists" or was explicitely
> disabled by the user. I'd really prefer CONFIG_LIBNL for this and I
> don't think more fine-grained control (CONFIG_LIBNL_*) will be needed,
> as we gain relatively little compared to the amount of #ifdef complexity
> we introduce.
>>

-- 
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] Re: [PATCH 04/15] trafgen: proto: Force field id to be index in array

2016-08-03 Thread Tobias Klauser
On 2016-08-02 at 22:26:28 +0200, Vadim Kochan  wrote:
> Yes, bug_on(x) is good point, so I am expecting you will continue
> review the rest patches ?

Yes

-- 
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] Re: [PATCH 1/3] trafgen: Allow to compile without libnl

2016-08-03 Thread Tobias Klauser
On 2016-08-02 at 22:17:41 +0200, Vadim Kochan  wrote:
> On Tue, Aug 2, 2016 at 11:23 AM, Tobias Klauser  wrote:
> > On 2016-07-31 at 23:13:16 +0200, Vadim Kochan  wrote:
> >> trafgen uses libnl only to inject mac80211 frames but
> >> it might be not needed in some embedded or switch environments,
> >> so lets make possible to disable this feature.
> >>
> >> In case if --rfraw option will be used - user will get the panic message.
> >>
> >> Signed-off-by: Vadim Kochan 
> >> ---
> >>  mac80211.c   |  1 -
> >>  mac80211.h   | 15 +++
> >>  trafgen/Makefile | 21 +++--
> >>  3 files changed, 30 insertions(+), 7 deletions(-)
> >>
> >> diff --git a/mac80211.c b/mac80211.c
> >> index f22b600..9aea5a0 100644
> >> --- a/mac80211.c
> >> +++ b/mac80211.c
> >> @@ -24,7 +24,6 @@
> >>  #include 
> >>  #include 
> >>
> >> -#include "die.h"
> >>  #include "str.h"
> >>  #include "dev.h"
> >>  #include "mac80211.h"
> >> diff --git a/mac80211.h b/mac80211.h
> >> index dea4ae0..2780c03 100644
> >> --- a/mac80211.h
> >> +++ b/mac80211.h
> >> @@ -1,7 +1,22 @@
> >>  #ifndef MAC80211_H
> >>  #define MAC80211_H
> >>
> >> +#include "die.h"
> >> +#include "config.h"
> >> +
> >> +#ifdef CONFIG_NO_LIBNL
> >> +static inline void enter_rfmon_mac80211(const char *device, char **mondev)
> >> +{
> >> +panic("enter_rfmon_mac80211: CONFIG_NO_LIBNL option needs to be 
> >> disabled\n");
> >> +}
> >> +
> >> +static inline void leave_rfmon_mac80211(const char *mondev)
> >> +{
> >> +panic("leave_rfmon_mac80211: CONFIG_NO_LIBNL option needs to be 
> >> disabled\n");
> >> +}
> >
> > These messages both have a double negative which isn't very easy to
> > understand. I suggest to call the CONFIG directive CONFIG_LIBNL instead
> > which is also more in line with the other library CONFIG_* directives we
> > have.
> >
> > Also, you use the CONFIG_NO_LIBNL without setting it anywhere, this is
> > only done in patch 3/3. Please change the series order to make the
> > configure change come first.
> 
> I really think that CONFIG_{DISABLE or ENABLE}_LIBNL might be better
> because we really enable/disable it,
> but CONFIG_LIBNL is rather about existence of package, if to use this
> way then it will be needed (probably) to add C defines for
> CONFIG_LIBNL_ROUTE, CONFIG_LIBNL_GENL.

Form the point of view of compiling nesniff-ng/trafgen there is no
difference of whether an external library "exists" or was explicitely
disabled by the user. I'd really prefer CONFIG_LIBNL for this and I
don't think more fine-grained control (CONFIG_LIBNL_*) will be needed,
as we gain relatively little compared to the amount of #ifdef complexity
we introduce.
> 

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