From 506e22f6feb39d793434b473b60c8a20ccd12995 Mon Sep 17 00:00:00 2001 From: Vadim Kochan Date: Mon, 6 Feb 2017 18:23:11 +0200 Subject: trafgen: l3: Make possible to send frames via tun device tun interface does not have Ethernet header so lets push Ethernet header only if device supports this. Signed-off-by: Vadim Kochan Signed-off-by: Tobias Klauser --- trafgen_l3.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'trafgen_l3.c') 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 +#include #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)); -- cgit v1.2.3-54-g00ecf