Without IFF_VNET_HDR, tun_get_user() still passes an all-zero header to tun_vnet_hdr_tnl_to_skb(), which then only resets the MAC header. The parser is not inlined, so that costs two nested calls per packet. Reset the MAC header directly, as tap_get_user() already does. The check uses the same copy of the flags that decided whether the header was read. 1.9% fewer instructions per 1400-byte UDP packet written and dropped at the raw table, 1.1% fewer when forwarded (qemu -icount, x86_64). Signed-off-by: Antonio Quartulli --- drivers/net/tun.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/drivers/net/tun.c b/drivers/net/tun.c index 09f31faaced2..a644fab4321f 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -1970,11 +1970,18 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile, break; } - if (tun_vnet_hdr_tnl_to_skb(flags, features, skb, &hdr, - (flags & TUN_TYPE_MASK) == IFF_TAP)) { - atomic_long_inc(&tun->rx_frame_errors); - err = -EINVAL; - goto free_skb; + if (flags & IFF_VNET_HDR) { + bool has_eth = (flags & TUN_TYPE_MASK) == IFF_TAP; + + if (tun_vnet_hdr_tnl_to_skb(flags, features, skb, &hdr, + has_eth)) { + atomic_long_inc(&tun->rx_frame_errors); + err = -EINVAL; + goto free_skb; + } + } else { + /* a zero hdr would only reset the MAC header */ + skb_reset_mac_header(skb); } if ((flags & TUN_TYPE_MASK) == IFF_TAP) -- 2.56.1