mirror of
https://github.com/yggdrasil-network/water.git
synced 2025-05-20 00:45:09 +03:00
styling changes
This commit is contained in:
parent
bf1a5d0277
commit
8c63d7a3c7
2 changed files with 26 additions and 29 deletions
|
@ -2,15 +2,17 @@
|
||||||
|
|
||||||
package water
|
package water
|
||||||
|
|
||||||
|
// DevicePermissions determines the owner and group owner for the newly created
|
||||||
|
// interface.
|
||||||
type DevicePermissions struct {
|
type DevicePermissions struct {
|
||||||
// ID of the user which will be granted ownership of the device.
|
// Owner is the ID of the user which will be granted ownership of the
|
||||||
// If set to a negative value, the owner value will not be changed.
|
// device. If set to a negative value, the owner value will not be
|
||||||
// By default, Linux sets the owner to -1, which allows any user.
|
// changed. By default, Linux sets the owner to -1, which allows any user.
|
||||||
Owner uint
|
Owner uint
|
||||||
|
|
||||||
// ID of the group which will be granted access to the device.
|
// 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.
|
// If set to a negative value, the group value will not be changed. By
|
||||||
// By default, Linux sets the group to -1, which allows any group.
|
// default, Linux sets the group to -1, which allows any group.
|
||||||
Group uint
|
Group uint
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,17 +26,19 @@ type PlatformSpecificParams struct {
|
||||||
// used.
|
// used.
|
||||||
Name string
|
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
|
Persist bool
|
||||||
|
|
||||||
// Owner and Group permissions for the device.
|
// Permissions, if non-nil, specifies the owner and group owner for the
|
||||||
// A zero-value of this field, i.e. nil, indicates that no changes to owner
|
// interface. A zero-value of this field, i.e. nil, indicates that no
|
||||||
// or group will be made.
|
// changes to owner or group will be made.
|
||||||
Permissions *DevicePermissions
|
Permissions *DevicePermissions
|
||||||
|
|
||||||
// Support multiqueue tun/tap interface.
|
// MultiQueue specifies whether the multiqueue flag should be set on the
|
||||||
// From version 3.8, Linux supports multiqueue tuntap which can uses multiple
|
// interface. From version 3.8, Linux supports multiqueue tuntap which can
|
||||||
// file descriptors (queues) to parallelize packets sending or receiving.
|
// uses multiple file descriptors (queues) to parallelize packets sending
|
||||||
|
// or receiving.
|
||||||
MultiQueue bool
|
MultiQueue bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,10 +10,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
cIFF_TUN = 0x0001
|
cIFFTUN = 0x0001
|
||||||
cIFF_TAP = 0x0002
|
cIFFTAP = 0x0002
|
||||||
cIFF_NO_PI = 0x1000
|
cIFFNOPI = 0x1000
|
||||||
cIFF_MULTI_QUEUE = 0x0100
|
cIFFMULTIQUEUE = 0x0100
|
||||||
)
|
)
|
||||||
|
|
||||||
type ifReq struct {
|
type ifReq struct {
|
||||||
|
@ -37,9 +37,9 @@ func newTAP(config Config) (ifce *Interface, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var flags uint16
|
var flags uint16
|
||||||
flags = cIFF_TAP | cIFF_NO_PI
|
flags = cIFFTAP | cIFFNOPI
|
||||||
if config.PlatformSpecificParams.MultiQueue {
|
if config.PlatformSpecificParams.MultiQueue {
|
||||||
flags |= cIFF_MULTI_QUEUE
|
flags |= cIFFMULTIQUEUE
|
||||||
}
|
}
|
||||||
name, err := createInterface(file.Fd(), config.Name, flags)
|
name, err := createInterface(file.Fd(), config.Name, flags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -61,9 +61,9 @@ func newTUN(config Config) (ifce *Interface, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var flags uint16
|
var flags uint16
|
||||||
flags = cIFF_TUN | cIFF_NO_PI
|
flags = cIFFTUN | cIFFNOPI
|
||||||
if config.PlatformSpecificParams.MultiQueue {
|
if config.PlatformSpecificParams.MultiQueue {
|
||||||
flags |= cIFF_MULTI_QUEUE
|
flags |= cIFFMULTIQUEUE
|
||||||
}
|
}
|
||||||
name, err := createInterface(file.Fd(), config.Name, flags)
|
name, err := createInterface(file.Fd(), config.Name, flags)
|
||||||
if err != nil {
|
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) {
|
func setDeviceOptions(fd uintptr, config Config) (err error) {
|
||||||
|
|
||||||
// Device Permissions
|
|
||||||
if config.Permissions != nil {
|
if config.Permissions != nil {
|
||||||
|
|
||||||
// Set Owner
|
|
||||||
if err = ioctl(fd, syscall.TUNSETOWNER, uintptr(config.Permissions.Owner)); err != nil {
|
if err = ioctl(fd, syscall.TUNSETOWNER, uintptr(config.Permissions.Owner)); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set Group
|
|
||||||
if err = ioctl(fd, syscall.TUNSETGROUP, uintptr(config.Permissions.Group)); err != nil {
|
if err = ioctl(fd, syscall.TUNSETGROUP, uintptr(config.Permissions.Group)); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set/Clear Persist Device Flag
|
// set clear the persist flag
|
||||||
value := 0
|
value := 0
|
||||||
if config.Persist {
|
if config.Persist {
|
||||||
value = 1
|
value = 1
|
||||||
}
|
}
|
||||||
return ioctl(fd, syscall.TUNSETPERSIST, uintptr(value))
|
return ioctl(fd, syscall.TUNSETPERSIST, uintptr(value))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue