styling changes

This commit is contained in:
Song Gao 2019-01-06 22:03:27 +00:00
parent bf1a5d0277
commit 8c63d7a3c7
2 changed files with 26 additions and 29 deletions

View file

@ -2,15 +2,17 @@
package water
// DevicePermissions determines the owner and group owner for the newly created
// interface.
type DevicePermissions struct {
// ID of the user which will be granted ownership of the device.
// If set to a negative value, the owner value will not be changed.
// By default, Linux sets the owner to -1, which allows any user.
// Owner is the ID of the user which will be granted ownership of the
// device. If set to a negative value, the owner value will not be
// changed. By default, Linux sets the owner to -1, which allows any user.
Owner uint
// ID of the group which will be granted access to the device.
// If set to a negative value, the group value will not be changed.
// By default, Linux sets the group to -1, which allows any group.
// Group is the ID of the group which will be granted access to the device.
// If set to a negative value, the group value will not be changed. By
// default, Linux sets the group to -1, which allows any group.
Group uint
}
@ -24,17 +26,19 @@ type PlatformSpecificParams struct {
// used.
Name string
// Enable or disable persistence mode for the interface device.
// Persist specifies whether persistence mode for the interface device
// should be enabled or disabled.
Persist bool
// Owner and Group permissions for the device.
// A zero-value of this field, i.e. nil, indicates that no changes to owner
// or group will be made.
// Permissions, if non-nil, specifies the owner and group owner for the
// interface. 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 specifies whether the multiqueue flag should be set on the
// interface. From version 3.8, Linux supports multiqueue tuntap which can
// uses multiple file descriptors (queues) to parallelize packets sending
// or receiving.
MultiQueue bool
}

View file

@ -10,10 +10,10 @@ import (
)
const (
cIFF_TUN = 0x0001
cIFF_TAP = 0x0002
cIFF_NO_PI = 0x1000
cIFF_MULTI_QUEUE = 0x0100
cIFFTUN = 0x0001
cIFFTAP = 0x0002
cIFFNOPI = 0x1000
cIFFMULTIQUEUE = 0x0100
)
type ifReq struct {
@ -37,9 +37,9 @@ func newTAP(config Config) (ifce *Interface, err error) {
}
var flags uint16
flags = cIFF_TAP | cIFF_NO_PI
flags = cIFFTAP | cIFFNOPI
if config.PlatformSpecificParams.MultiQueue {
flags |= cIFF_MULTI_QUEUE
flags |= cIFFMULTIQUEUE
}
name, err := createInterface(file.Fd(), config.Name, flags)
if err != nil {
@ -61,9 +61,9 @@ func newTUN(config Config) (ifce *Interface, err error) {
}
var flags uint16
flags = cIFF_TUN | cIFF_NO_PI
flags = cIFFTUN | cIFFNOPI
if config.PlatformSpecificParams.MultiQueue {
flags |= cIFF_MULTI_QUEUE
flags |= cIFFMULTIQUEUE
}
name, err := createInterface(file.Fd(), config.Name, flags)
if err != nil {
@ -93,26 +93,19 @@ func createInterface(fd uintptr, ifName string, flags uint16) (createdIFName str
}
func setDeviceOptions(fd uintptr, config Config) (err error) {
// Device Permissions
if config.Permissions != nil {
// Set Owner
if err = ioctl(fd, syscall.TUNSETOWNER, uintptr(config.Permissions.Owner)); err != nil {
return
}
// Set Group
if err = ioctl(fd, syscall.TUNSETGROUP, uintptr(config.Permissions.Group)); err != nil {
return
}
}
// Set/Clear Persist Device Flag
// set clear the persist flag
value := 0
if config.Persist {
value = 1
}
return ioctl(fd, syscall.TUNSETPERSIST, uintptr(value))
}