From 3eab064e3fadaf2a6a128f167ad04ca0319b4e17 Mon Sep 17 00:00:00 2001 From: Anton Ivanov Date: Tue, 3 Oct 2017 10:08:05 +0100 Subject: VPP-1001 - update AF Packet Driver to for modern kernels 1. Add VNET headers support for checksumming - required to operate correctly on any recent Linux 2. Bypass QDISC on transmit - improves performance by ~ 5%. Enabled only if the macro is detected - apparently not present on archaic distributions. This still does not solve all issues with TSO - it can be fixed only by going to tpacket v3 and dynamic rx ring as well as significant changes in the TX (sendmmsg?). Change-Id: Iea14ade12586c0a8da49e6dd1012108a08bc85b3 Signed-off-by: Anton Ivanov --- src/vnet/devices/af_packet/af_packet.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'src/vnet/devices/af_packet/af_packet.c') diff --git a/src/vnet/devices/af_packet/af_packet.c b/src/vnet/devices/af_packet/af_packet.c index 32696014727..fbcd488ac9b 100644 --- a/src/vnet/devices/af_packet/af_packet.c +++ b/src/vnet/devices/af_packet/af_packet.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -128,6 +129,7 @@ static int create_packet_v2_sock (int host_if_index, tpacket_req_t * rx_req, tpacket_req_t * tx_req, int *fd, u8 ** ring) { + af_packet_main_t *apm = &af_packet_main; int ret, err; struct sockaddr_ll sll; int ver = TPACKET_V2; @@ -141,7 +143,31 @@ create_packet_v2_sock (int host_if_index, tpacket_req_t * rx_req, ret = VNET_API_ERROR_SYSCALL_ERROR_1; goto error; } - + int opt = 1; + if (setsockopt (*fd, SOL_PACKET, PACKET_VNET_HDR, &opt, sizeof (opt)) != 0) + { + DBG_SOCK ("Failed to enable vnet headers on the socket"); + if ((apm->flags & AF_PACKET_USES_VNET_HEADERS) != 0) + { + /* Should never happen - vnet was already enabled once, + * but we fail to reenable it on a new interface + **/ + ret = VNET_API_ERROR_SYSCALL_ERROR_1; + goto error; + } + } + else + { + apm->flags |= AF_PACKET_USES_VNET_HEADERS; + } +#ifdef PACKET_QDISC_BYPASS + opt = 1; + if (setsockopt (*fd, SOL_PACKET, PACKET_QDISC_BYPASS, &opt, sizeof (opt)) != + 0) + { + DBG_SOCK ("Failed to bypass Linux QDISC"); + } +#endif if ((err = setsockopt (*fd, SOL_PACKET, PACKET_VERSION, &ver, sizeof (ver))) < 0) { @@ -150,7 +176,7 @@ create_packet_v2_sock (int host_if_index, tpacket_req_t * rx_req, goto error; } - int opt = 1; + opt = 1; if ((err = setsockopt (*fd, SOL_PACKET, PACKET_LOSS, &opt, sizeof (opt))) < 0) { -- cgit 1.2.3-korg