tun: import mobile particularities
This commit is contained in:
parent
b8e85267cf
commit
68f0721c6a
16
device/queueconstants_android.go
Normal file
16
device/queueconstants_android.go
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
/* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
* Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package device
|
||||||
|
|
||||||
|
/* Reduce memory consumption for Android */
|
||||||
|
|
||||||
|
const (
|
||||||
|
QueueOutboundSize = 1024
|
||||||
|
QueueInboundSize = 1024
|
||||||
|
QueueHandshakeSize = 1024
|
||||||
|
MaxSegmentSize = 2200
|
||||||
|
PreallocatedBuffersPerPool = 4096
|
||||||
|
)
|
@ -1,3 +1,5 @@
|
|||||||
|
// +build !android,!ios
|
||||||
|
|
||||||
/* SPDX-License-Identifier: MIT
|
/* SPDX-License-Identifier: MIT
|
||||||
*
|
*
|
||||||
* Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
|
* Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
|
||||||
@ -5,8 +7,6 @@
|
|||||||
|
|
||||||
package device
|
package device
|
||||||
|
|
||||||
/* Implementation specific constants */
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
QueueOutboundSize = 1024
|
QueueOutboundSize = 1024
|
||||||
QueueInboundSize = 1024
|
QueueInboundSize = 1024
|
18
device/queueconstants_ios.go
Normal file
18
device/queueconstants_ios.go
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
// +build ios
|
||||||
|
|
||||||
|
/* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
* Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package device
|
||||||
|
|
||||||
|
/* Fit within memory limits for iOS's Network Extension API, which has stricter requirements */
|
||||||
|
|
||||||
|
const (
|
||||||
|
QueueOutboundSize = 1024
|
||||||
|
QueueInboundSize = 1024
|
||||||
|
QueueHandshakeSize = 1024
|
||||||
|
MaxSegmentSize = 1700
|
||||||
|
PreallocatedBuffersPerPool = 1024
|
||||||
|
)
|
@ -171,7 +171,7 @@ func CreateTUNFromFile(file *os.File, mtu int) (TUNDevice, error) {
|
|||||||
tun := &NativeTun{
|
tun := &NativeTun{
|
||||||
tunFile: file,
|
tunFile: file,
|
||||||
events: make(chan TUNEvent, 10),
|
events: make(chan TUNEvent, 10),
|
||||||
errors: make(chan error, 1),
|
errors: make(chan error, 5),
|
||||||
}
|
}
|
||||||
|
|
||||||
name, err := tun.Name()
|
name, err := tun.Name()
|
||||||
@ -200,10 +200,12 @@ func CreateTUNFromFile(file *os.File, mtu int) (TUNDevice, error) {
|
|||||||
|
|
||||||
go tun.routineRouteListener(tunIfindex)
|
go tun.routineRouteListener(tunIfindex)
|
||||||
|
|
||||||
err = tun.setMTU(mtu)
|
if mtu > 0 {
|
||||||
if err != nil {
|
err = tun.setMTU(mtu)
|
||||||
tun.Close()
|
if err != nil {
|
||||||
return nil, err
|
tun.Close()
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return tun, nil
|
return tun, nil
|
||||||
|
@ -443,3 +443,25 @@ func CreateTUNFromFile(file *os.File, mtu int) (TUNDevice, error) {
|
|||||||
|
|
||||||
return tun, nil
|
return tun, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CreateUnmonitoredTUNFromFD(tunFd int) (TUNDevice, string, error) {
|
||||||
|
file := os.NewFile(uintptr(tunFd), "/dev/tun")
|
||||||
|
tun := &NativeTun{
|
||||||
|
tunFile: file,
|
||||||
|
fd: file.Fd(),
|
||||||
|
events: make(chan TUNEvent, 5),
|
||||||
|
errors: make(chan error, 5),
|
||||||
|
nopi: true,
|
||||||
|
}
|
||||||
|
var err error
|
||||||
|
tun.fdCancel, err = rwcancel.NewRWCancel(int(tun.fd))
|
||||||
|
if err != nil {
|
||||||
|
return nil, "", err
|
||||||
|
}
|
||||||
|
name, err := tun.Name()
|
||||||
|
if err != nil {
|
||||||
|
tun.fdCancel.Cancel()
|
||||||
|
return nil, "", err
|
||||||
|
}
|
||||||
|
return tun, name, nil
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user