From c14726aabc03122106e60be7c51cf26521e791a8 Mon Sep 17 00:00:00 2001 From: Tony Lu Date: Tue, 22 Aug 2017 01:08:43 +0800 Subject: [PATCH 1/4] Add flags cIFF_MULTI_QUEUE Signed-off-by: Tony Lu --- params_linux.go | 5 +++++ syscalls_linux.go | 23 ++++++++++++++++++----- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/params_linux.go b/params_linux.go index 41203f6..ffbd3a6 100644 --- a/params_linux.go +++ b/params_linux.go @@ -31,6 +31,11 @@ type PlatformSpecificParams struct { // A zero-value of this field, i.e. nil, indicates that no changes to owner // or group will be made. Permissions *DevicePermissions + + // Support multiqueue tun/tap interface. + // From version 3.8, Linux supports multiqueue tuntap which can uses multiple + // file descriptors (queues) to parallelize packets sending or receiving. + MultiQueue bool } func defaultPlatformSpecificParams() PlatformSpecificParams { diff --git a/syscalls_linux.go b/syscalls_linux.go index 50a945c..a47b8aa 100644 --- a/syscalls_linux.go +++ b/syscalls_linux.go @@ -10,9 +10,10 @@ import ( ) const ( - cIFF_TUN = 0x0001 - cIFF_TAP = 0x0002 - cIFF_NO_PI = 0x1000 + cIFF_TUN = 0x0001 + cIFF_TAP = 0x0002 + cIFF_NO_PI = 0x1000 + cIFF_MULTI_QUEUE = 0x0100 ) type ifReq struct { @@ -34,7 +35,13 @@ func newTAP(config Config) (ifce *Interface, err error) { if err != nil { return nil, err } - name, err := createInterface(file.Fd(), config.Name, cIFF_TAP|cIFF_NO_PI) + + var flags uint16 + flags = cIFF_TUN | cIFF_NO_PI + if config.PlatformSpecificParams.MultiQueue { + flags = cIFF_TUN | cIFF_NO_PI | cIFF_MULTI_QUEUE + } + name, err := createInterface(file.Fd(), config.Name, flags) if err != nil { return nil, err } @@ -52,7 +59,13 @@ func newTUN(config Config) (ifce *Interface, err error) { if err != nil { return nil, err } - name, err := createInterface(file.Fd(), config.Name, cIFF_TUN|cIFF_NO_PI) + + var flags uint16 + flags = cIFF_TUN | cIFF_NO_PI + if config.PlatformSpecificParams.MultiQueue { + flags = cIFF_TUN | cIFF_NO_PI | cIFF_MULTI_QUEUE + } + name, err := createInterface(file.Fd(), config.Name, flags) if err != nil { return nil, err } From 9effada2e6507a9f62f70f87f3372e7cca5a066b Mon Sep 17 00:00:00 2001 From: Tony Lu Date: Thu, 24 Aug 2017 00:18:25 +0800 Subject: [PATCH 2/4] Use |=, instead of repeating flags Signed-off-by: Tony Lu --- syscalls_linux.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/syscalls_linux.go b/syscalls_linux.go index a47b8aa..28ad259 100644 --- a/syscalls_linux.go +++ b/syscalls_linux.go @@ -39,7 +39,7 @@ func newTAP(config Config) (ifce *Interface, err error) { var flags uint16 flags = cIFF_TUN | cIFF_NO_PI if config.PlatformSpecificParams.MultiQueue { - flags = cIFF_TUN | cIFF_NO_PI | cIFF_MULTI_QUEUE + flags |= cIFF_MULTI_QUEUE } name, err := createInterface(file.Fd(), config.Name, flags) if err != nil { @@ -63,7 +63,7 @@ func newTUN(config Config) (ifce *Interface, err error) { var flags uint16 flags = cIFF_TUN | cIFF_NO_PI if config.PlatformSpecificParams.MultiQueue { - flags = cIFF_TUN | cIFF_NO_PI | cIFF_MULTI_QUEUE + flags |= cIFF_MULTI_QUEUE } name, err := createInterface(file.Fd(), config.Name, flags) if err != nil { From 21ef3573b938c6da4e14150429bcb5ba31691227 Mon Sep 17 00:00:00 2001 From: Tony Lu Date: Thu, 24 Aug 2017 02:45:01 +0800 Subject: [PATCH 3/4] Add comment about MultiQueue Signed-off-by: Tony Lu --- if.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/if.go b/if.go index 9f90485..965f2ac 100644 --- a/if.go +++ b/if.go @@ -6,6 +6,10 @@ import ( ) // Interface is a TUN/TAP interface. +// +// MultiQueue(Linux kernel > 3.8): With MultiQueue enabled, user should hold multiple +// interfaces to send/receive packet in parallel. +// Kernel document about MultiQueue: https://www.kernel.org/doc/Documentation/networking/tuntap.txt type Interface struct { isTAP bool io.ReadWriteCloser From 1f021c893ba11acefa494d6ed6ad29ba93d41d96 Mon Sep 17 00:00:00 2001 From: Tony Lu Date: Thu, 24 Aug 2017 02:46:40 +0800 Subject: [PATCH 4/4] Add Tony Lu to CONTRIBUTORS Signed-off-by: Tony Lu --- CONTRIBUTORS | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 3a84f44..ded5b3f 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -4,4 +4,5 @@ KOJIMA Takanori Sean Purser-Haskell daregod Lucus Lee -Arroyo Networks, LLC \ No newline at end of file +Arroyo Networks, LLC +Tony Lu