--- /dev/null
+/* 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
+)
\ No newline at end of file
+// +build !android,!ios
+
/* SPDX-License-Identifier: MIT
*
* Copyright (C) 2017-2019 WireGuard LLC. All Rights Reserved.
package device
-/* Implementation specific constants */
-
const (
QueueOutboundSize = 1024
QueueInboundSize = 1024
--- /dev/null
+// +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
+)
tun := &NativeTun{
tunFile: file,
events: make(chan TUNEvent, 10),
- errors: make(chan error, 1),
+ errors: make(chan error, 5),
}
name, err := tun.Name()
go tun.routineRouteListener(tunIfindex)
- err = tun.setMTU(mtu)
- if err != nil {
- tun.Close()
- return nil, err
+ if mtu > 0 {
+ err = tun.setMTU(mtu)
+ if err != nil {
+ tun.Close()
+ return nil, err
+ }
}
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
+}