Merge pull request #27 from tonyluj/Multiqueue

Add flags cIFF_MULTI_QUEUE
This commit is contained in:
Song Gao 2017-08-24 08:38:48 -07:00 committed by GitHub
commit 6b639456fc
4 changed files with 29 additions and 6 deletions

View file

@ -5,3 +5,4 @@ Sean Purser-Haskell <sean.purserhaskell@gmail.com>
daregod <daregod@yandex.ru> daregod <daregod@yandex.ru>
Lucus Lee <lixin9311@gmail.com> Lucus Lee <lixin9311@gmail.com>
Arroyo Networks, LLC <open.source@arroyonetworks.com> Arroyo Networks, LLC <open.source@arroyonetworks.com>
Tony Lu <tonyluj@gmail.com>

4
if.go
View file

@ -6,6 +6,10 @@ import (
) )
// Interface is a TUN/TAP interface. // 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 { type Interface struct {
isTAP bool isTAP bool
io.ReadWriteCloser io.ReadWriteCloser

View file

@ -31,6 +31,11 @@ type PlatformSpecificParams struct {
// A zero-value of this field, i.e. nil, indicates that no changes to owner // A zero-value of this field, i.e. nil, indicates that no changes to owner
// or group will be made. // or group will be made.
Permissions *DevicePermissions 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 { func defaultPlatformSpecificParams() PlatformSpecificParams {

View file

@ -10,9 +10,10 @@ import (
) )
const ( const (
cIFF_TUN = 0x0001 cIFF_TUN = 0x0001
cIFF_TAP = 0x0002 cIFF_TAP = 0x0002
cIFF_NO_PI = 0x1000 cIFF_NO_PI = 0x1000
cIFF_MULTI_QUEUE = 0x0100
) )
type ifReq struct { type ifReq struct {
@ -34,7 +35,13 @@ func newTAP(config Config) (ifce *Interface, err error) {
if err != nil { if err != nil {
return nil, err 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_MULTI_QUEUE
}
name, err := createInterface(file.Fd(), config.Name, flags)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -52,7 +59,13 @@ func newTUN(config Config) (ifce *Interface, err error) {
if err != nil { if err != nil {
return nil, err 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_MULTI_QUEUE
}
name, err := createInterface(file.Fd(), config.Name, flags)
if err != nil { if err != nil {
return nil, err return nil, err
} }