tun interface does not have Ethernet header so lets push Ethernet
header only if device supports this.

Signed-off-by: Vadim Kochan <vadi...@gmail.com>
---
 trafgen_l3.c    | 15 ++++++++++++---
 trafgen_proto.c |  5 +++++
 trafgen_proto.h |  2 ++
 3 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/trafgen_l3.c b/trafgen_l3.c
index 70aefb9..7c8a786 100644
--- a/trafgen_l3.c
+++ b/trafgen_l3.c
@@ -3,9 +3,10 @@
  * Subject to the GPL, version 2.
  */
 
-#include <linux/if_ether.h>
+#include <net/if_arp.h>
 
 #include "die.h"
+#include "dev.h"
 #include "csum.h"
 #include "built_in.h"
 #include "trafgen_l2.h"
@@ -34,7 +35,11 @@ static struct proto_field ipv4_fields[] = {
 
 static void ipv4_header_init(struct proto_hdr *hdr)
 {
-       proto_lower_default_add(hdr, PROTO_ETH);
+       const char *dev = proto_dev_get();
+
+       /* In case of tun interface we do not need to create Ethernet header */
+       if (dev && device_mtu(dev) && device_type(dev) != ARPHRD_NONE)
+               proto_lower_default_add(hdr, PROTO_ETH);
 
        proto_header_fields_add(hdr, ipv4_fields, array_size(ipv4_fields));
 
@@ -135,7 +140,11 @@ static struct proto_field ipv6_fields[] = {
 
 static void ipv6_header_init(struct proto_hdr *hdr)
 {
-       proto_lower_default_add(hdr, PROTO_ETH);
+       const char *dev = proto_dev_get();
+
+       /* In case of tun interface we do not need to create Ethernet header */
+       if (dev && device_mtu(dev) && device_type(dev) != ARPHRD_NONE)
+               proto_lower_default_add(hdr, PROTO_ETH);
 
        proto_header_fields_add(hdr, ipv6_fields, array_size(ipv6_fields));
 
diff --git a/trafgen_proto.c b/trafgen_proto.c
index 88e0846..5fd9e1c 100644
--- a/trafgen_proto.c
+++ b/trafgen_proto.c
@@ -609,3 +609,8 @@ void proto_field_dyn_apply(struct proto_field *field)
        if (field->hdr->ops->field_changed)
                field->hdr->ops->field_changed(field);
 }
+
+const char *proto_dev_get(void)
+{
+       return ctx.dev;
+}
diff --git a/trafgen_proto.h b/trafgen_proto.h
index 29d68db..d863287 100644
--- a/trafgen_proto.h
+++ b/trafgen_proto.h
@@ -159,4 +159,6 @@ extern void proto_field_set_be32(struct proto_field *field, 
uint32_t val);
 extern void proto_field_func_add(struct proto_field *field,
                                 struct proto_field_func *func);
 
+extern const char *proto_dev_get(void);
+
 #endif /* TRAFGEN_PROTO_H */
-- 
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.

Reply via email to