Compare commits
12 Commits
0.0.201805
...
0.0.201805
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0c976003c8 | ||
|
|
955e89839f | ||
|
|
a4cd0216c0 | ||
|
|
1d7845a600 | ||
|
|
5079298ce2 | ||
|
|
fc3a7635e5 | ||
|
|
2496cdd8e6 | ||
|
|
4365b4583f | ||
|
|
bbf320c477 | ||
|
|
625d59da14 | ||
|
|
2f2eca8947 | ||
|
|
66f6ca3e4a |
6
Gopkg.lock
generated
6
Gopkg.lock
generated
@@ -11,7 +11,7 @@
|
|||||||
"internal/chacha20",
|
"internal/chacha20",
|
||||||
"poly1305"
|
"poly1305"
|
||||||
]
|
]
|
||||||
revision = "1a580b3eff7814fc9b40602fd35256c63b50f491"
|
revision = "ab813273cd59e1333f7ae7bff5d027d4aadf528c"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
@@ -23,7 +23,7 @@
|
|||||||
"ipv4",
|
"ipv4",
|
||||||
"ipv6"
|
"ipv6"
|
||||||
]
|
]
|
||||||
revision = "9ef9f5bb98a1fdc41f8cf6c250a4404b4085e389"
|
revision = "dfa909b99c79129e1100513e5cd36307665e5723"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
@@ -32,7 +32,7 @@
|
|||||||
"cpu",
|
"cpu",
|
||||||
"unix"
|
"unix"
|
||||||
]
|
]
|
||||||
revision = "88eb85aaee56831ad49eaf7aa80d73de9814cde2"
|
revision = "c11f84a56e43e20a78cee75a7c034031ecf57d1f"
|
||||||
|
|
||||||
[solve-meta]
|
[solve-meta]
|
||||||
analyzer-name = "dep"
|
analyzer-name = "dep"
|
||||||
|
|||||||
4
Makefile
4
Makefile
@@ -5,8 +5,6 @@ BINDIR ?= $(PREFIX)/bin
|
|||||||
ifeq ($(shell go env GOOS),linux)
|
ifeq ($(shell go env GOOS),linux)
|
||||||
ifeq ($(wildcard .git),)
|
ifeq ($(wildcard .git),)
|
||||||
$(error Do not build this for Linux. Instead use the Linux kernel module. See wireguard.com/install/ for more info.)
|
$(error Do not build this for Linux. Instead use the Linux kernel module. See wireguard.com/install/ for more info.)
|
||||||
else
|
|
||||||
$(shell printf 'package main\nconst UseTheKernelModuleInstead = 0xdeadbabe\n' > ireallywantobuildon_linux.go)
|
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
@@ -36,7 +34,7 @@ vendor/.created: Gopkg.toml Gopkg.lock | .gopath/.created
|
|||||||
touch $@
|
touch $@
|
||||||
|
|
||||||
wireguard-go: $(wildcard *.go) $(wildcard */*.go) .gopath/.created vendor/.created version.go
|
wireguard-go: $(wildcard *.go) $(wildcard */*.go) .gopath/.created vendor/.created version.go
|
||||||
go build $(GO_BUILD_EXTRA_ARGS) -v $(GO_IMPORT_PATH)
|
go build -v $(GO_IMPORT_PATH)
|
||||||
|
|
||||||
install: wireguard-go
|
install: wireguard-go
|
||||||
@install -v -d "$(DESTDIR)$(BINDIR)" && install -v -m 0755 wireguard-go "$(DESTDIR)$(BINDIR)/wireguard-go"
|
@install -v -d "$(DESTDIR)$(BINDIR)" && install -v -m 0755 wireguard-go "$(DESTDIR)$(BINDIR)/wireguard-go"
|
||||||
|
|||||||
@@ -18,8 +18,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.zx2c4.com/wireguard-go/rwcancel"
|
|
||||||
"errors"
|
"errors"
|
||||||
|
"git.zx2c4.com/wireguard-go/rwcancel"
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
"net"
|
"net"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -563,7 +563,7 @@ func (bind *NativeBind) routineRouteListener(device *Device) {
|
|||||||
var msgn int
|
var msgn int
|
||||||
for {
|
for {
|
||||||
msgn, _, _, _, err = unix.Recvmsg(bind.netlinkSock, msg[:], nil, 0)
|
msgn, _, _, _, err = unix.Recvmsg(bind.netlinkSock, msg[:], nil, 0)
|
||||||
if err == nil || !rwcancel.ErrorIsEAGAIN(err) {
|
if err == nil || !rwcancel.RetryAfterError(err) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if !bind.netlinkCancel.ReadyRead() {
|
if !bind.netlinkCancel.ReadyRead() {
|
||||||
|
|||||||
@@ -7,9 +7,9 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.zx2c4.com/wireguard-go/xchacha20poly1305"
|
|
||||||
"crypto/hmac"
|
"crypto/hmac"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
|
"git.zx2c4.com/wireguard-go/xchacha20poly1305"
|
||||||
"golang.org/x/crypto/blake2s"
|
"golang.org/x/crypto/blake2s"
|
||||||
"golang.org/x/crypto/chacha20poly1305"
|
"golang.org/x/crypto/chacha20poly1305"
|
||||||
"sync"
|
"sync"
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
|
"git.zx2c4.com/wireguard-go/tun"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
@@ -20,7 +21,7 @@ type DummyTUN struct {
|
|||||||
name string
|
name string
|
||||||
mtu int
|
mtu int
|
||||||
packets chan []byte
|
packets chan []byte
|
||||||
events chan TUNEvent
|
events chan tun.TUNEvent
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tun *DummyTUN) File() *os.File {
|
func (tun *DummyTUN) File() *os.File {
|
||||||
@@ -46,7 +47,7 @@ func (tun *DummyTUN) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tun *DummyTUN) Events() chan TUNEvent {
|
func (tun *DummyTUN) Events() chan tun.TUNEvent {
|
||||||
return tun.events
|
return tun.events
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,11 +60,11 @@ func (tun *DummyTUN) Read(d []byte, offset int) (int, error) {
|
|||||||
return len(t), nil
|
return len(t), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateDummyTUN(name string) (TUNDevice, error) {
|
func CreateDummyTUN(name string) (tun.TUNDevice, error) {
|
||||||
var dummy DummyTUN
|
var dummy DummyTUN
|
||||||
dummy.mtu = 0
|
dummy.mtu = 0
|
||||||
dummy.packets = make(chan []byte, 100)
|
dummy.packets = make(chan []byte, 100)
|
||||||
dummy.events = make(chan TUNEvent, 10)
|
dummy.events = make(chan tun.TUNEvent, 10)
|
||||||
return &dummy, nil
|
return &dummy, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,8 +7,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.zx2c4.com/wireguard-go/replay"
|
|
||||||
"crypto/cipher"
|
"crypto/cipher"
|
||||||
|
"git.zx2c4.com/wireguard-go/replay"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|||||||
4
main.go
4
main.go
@@ -7,8 +7,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.zx2c4.com/wireguard-go/tun"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"git.zx2c4.com/wireguard-go/tun"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"runtime"
|
"runtime"
|
||||||
@@ -160,6 +160,8 @@ func main() {
|
|||||||
fmt.Sprintf("(%s) ", interfaceName),
|
fmt.Sprintf("(%s) ", interfaceName),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
logger.Info.Println("Starting wireguard-go version", WireGuardGoVersion)
|
||||||
|
|
||||||
logger.Debug.Println("Debug log enabled")
|
logger.Debug.Println("Debug log enabled")
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -7,8 +7,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.zx2c4.com/wireguard-go/tai64n"
|
|
||||||
"errors"
|
"errors"
|
||||||
|
"git.zx2c4.com/wireguard-go/tai64n"
|
||||||
"golang.org/x/crypto/blake2s"
|
"golang.org/x/crypto/blake2s"
|
||||||
"golang.org/x/crypto/chacha20poly1305"
|
"golang.org/x/crypto/chacha20poly1305"
|
||||||
"golang.org/x/crypto/poly1305"
|
"golang.org/x/crypto/poly1305"
|
||||||
|
|||||||
11
peer.go
11
peer.go
@@ -258,3 +258,14 @@ func (peer *Peer) Stop() {
|
|||||||
|
|
||||||
peer.ZeroAndFlushAll()
|
peer.ZeroAndFlushAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var roamingDisabled bool
|
||||||
|
|
||||||
|
func (peer *Peer) SetEndpointFromPacket(endpoint Endpoint) {
|
||||||
|
if roamingDisabled {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
peer.mutex.Lock()
|
||||||
|
peer.endpoint = endpoint
|
||||||
|
peer.mutex.Unlock()
|
||||||
|
}
|
||||||
|
|||||||
15
receive.go
15
receive.go
@@ -440,10 +440,7 @@ func (device *Device) RoutineHandshake() {
|
|||||||
peer.timersAnyAuthenticatedPacketReceived()
|
peer.timersAnyAuthenticatedPacketReceived()
|
||||||
|
|
||||||
// update endpoint
|
// update endpoint
|
||||||
|
peer.SetEndpointFromPacket(elem.endpoint)
|
||||||
peer.mutex.Lock()
|
|
||||||
peer.endpoint = elem.endpoint
|
|
||||||
peer.mutex.Unlock()
|
|
||||||
|
|
||||||
logDebug.Println(peer, "- Received handshake initiation")
|
logDebug.Println(peer, "- Received handshake initiation")
|
||||||
|
|
||||||
@@ -473,10 +470,7 @@ func (device *Device) RoutineHandshake() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// update endpoint
|
// update endpoint
|
||||||
|
peer.SetEndpointFromPacket(elem.endpoint)
|
||||||
peer.mutex.Lock()
|
|
||||||
peer.endpoint = elem.endpoint
|
|
||||||
peer.mutex.Unlock()
|
|
||||||
|
|
||||||
logDebug.Println(peer, "- Received handshake response")
|
logDebug.Println(peer, "- Received handshake response")
|
||||||
|
|
||||||
@@ -549,10 +543,7 @@ func (peer *Peer) RoutineSequentialReceiver() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// update endpoint
|
// update endpoint
|
||||||
|
peer.SetEndpointFromPacket(elem.endpoint)
|
||||||
peer.mutex.Lock()
|
|
||||||
peer.endpoint = elem.endpoint
|
|
||||||
peer.mutex.Unlock()
|
|
||||||
|
|
||||||
// check if using new keypair
|
// check if using new keypair
|
||||||
if peer.ReceivedWithKeypair(elem.keypair) {
|
if peer.ReceivedWithKeypair(elem.keypair) {
|
||||||
|
|||||||
@@ -40,15 +40,16 @@ func NewRWCancel(fd int) (*RWCancel, error) {
|
|||||||
return &rwcancel, nil
|
return &rwcancel, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
/* https://golang.org/src/crypto/rand/eagain.go */
|
func RetryAfterError(err error) bool {
|
||||||
func ErrorIsEAGAIN(err error) bool {
|
|
||||||
if pe, ok := err.(*os.PathError); ok {
|
if pe, ok := err.(*os.PathError); ok {
|
||||||
if errno, ok := pe.Err.(syscall.Errno); ok && errno == syscall.EAGAIN {
|
err = pe.Err
|
||||||
|
}
|
||||||
|
if errno, ok := err.(syscall.Errno); ok {
|
||||||
|
switch errno {
|
||||||
|
case syscall.EAGAIN, syscall.EINTR:
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if errno, ok := err.(syscall.Errno); ok && errno == syscall.EAGAIN {
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -86,7 +87,7 @@ func (rw *RWCancel) ReadyWrite() bool {
|
|||||||
func (rw *RWCancel) Read(p []byte) (n int, err error) {
|
func (rw *RWCancel) Read(p []byte) (n int, err error) {
|
||||||
for {
|
for {
|
||||||
n, err := unix.Read(rw.fd, p)
|
n, err := unix.Read(rw.fd, p)
|
||||||
if err == nil || !ErrorIsEAGAIN(err) {
|
if err == nil || !RetryAfterError(err) {
|
||||||
return n, err
|
return n, err
|
||||||
}
|
}
|
||||||
if !rw.ReadyRead() {
|
if !rw.ReadyRead() {
|
||||||
@@ -98,7 +99,7 @@ func (rw *RWCancel) Read(p []byte) (n int, err error) {
|
|||||||
func (rw *RWCancel) Write(p []byte) (n int, err error) {
|
func (rw *RWCancel) Write(p []byte) (n int, err error) {
|
||||||
for {
|
for {
|
||||||
n, err := unix.Write(rw.fd, p)
|
n, err := unix.Write(rw.fd, p)
|
||||||
if err == nil || !ErrorIsEAGAIN(err) {
|
if err == nil || !RetryAfterError(err) {
|
||||||
return n, err
|
return n, err
|
||||||
}
|
}
|
||||||
if !rw.ReadyWrite() {
|
if !rw.ReadyWrite() {
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ func expiredNewHandshake(peer *Peer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func expiredZeroKeyMaterial(peer *Peer) {
|
func expiredZeroKeyMaterial(peer *Peer) {
|
||||||
peer.device.log.Debug.Printf(":%s Removing all keys, since we haven't received a new one in %d seconds\n", peer, int((RejectAfterTime * 3).Seconds()))
|
peer.device.log.Debug.Printf("%s: Removing all keys, since we haven't received a new one in %d seconds\n", peer, int((RejectAfterTime * 3).Seconds()))
|
||||||
peer.ZeroAndFlushAll()
|
peer.ZeroAndFlushAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,14 +7,15 @@
|
|||||||
package tun
|
package tun
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.zx2c4.com/wireguard-go/rwcancel"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"git.zx2c4.com/wireguard-go/rwcancel"
|
||||||
"golang.org/x/net/ipv6"
|
"golang.org/x/net/ipv6"
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
|
"syscall"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -54,8 +55,12 @@ func (tun *nativeTun) routineRouteListener(tunIfindex int) {
|
|||||||
|
|
||||||
data := make([]byte, os.Getpagesize())
|
data := make([]byte, os.Getpagesize())
|
||||||
for {
|
for {
|
||||||
|
retry:
|
||||||
n, err := unix.Read(tun.routeSocket, data)
|
n, err := unix.Read(tun.routeSocket, data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if errno, ok := err.(syscall.Errno); ok && errno == syscall.EINTR {
|
||||||
|
goto retry
|
||||||
|
}
|
||||||
tun.errors <- err
|
tun.errors <- err
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -259,7 +264,7 @@ func (tun *nativeTun) doRead(buff []byte, offset int) (int, error) {
|
|||||||
func (tun *nativeTun) Read(buff []byte, offset int) (int, error) {
|
func (tun *nativeTun) Read(buff []byte, offset int) (int, error) {
|
||||||
for {
|
for {
|
||||||
n, err := tun.doRead(buff, offset)
|
n, err := tun.doRead(buff, offset)
|
||||||
if err == nil || !rwcancel.ErrorIsEAGAIN(err) {
|
if err == nil || !rwcancel.RetryAfterError(err) {
|
||||||
return n, err
|
return n, err
|
||||||
}
|
}
|
||||||
if !tun.rwcancel.ReadyRead() {
|
if !tun.rwcancel.ReadyRead() {
|
||||||
|
|||||||
@@ -6,14 +6,15 @@
|
|||||||
package tun
|
package tun
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.zx2c4.com/wireguard-go/rwcancel"
|
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"git.zx2c4.com/wireguard-go/rwcancel"
|
||||||
"golang.org/x/net/ipv6"
|
"golang.org/x/net/ipv6"
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
|
"syscall"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -67,8 +68,12 @@ func (tun *nativeTun) routineRouteListener(tunIfindex int) {
|
|||||||
|
|
||||||
data := make([]byte, os.Getpagesize())
|
data := make([]byte, os.Getpagesize())
|
||||||
for {
|
for {
|
||||||
|
retry:
|
||||||
n, err := unix.Read(tun.routeSocket, data)
|
n, err := unix.Read(tun.routeSocket, data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if errno, ok := err.(syscall.Errno); ok && errno == syscall.EINTR {
|
||||||
|
goto retry
|
||||||
|
}
|
||||||
tun.errors <- err
|
tun.errors <- err
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -257,19 +262,6 @@ func CreateTUN(name string, mtu int) (TUNDevice, error) {
|
|||||||
return nil, fmt.Errorf("error %s", errno.Error())
|
return nil, fmt.Errorf("error %s", errno.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set TUN iface to broadcast mode. TUN inferfaces on freebsd come up in point to point by default
|
|
||||||
ifmodemode := unix.IFF_BROADCAST
|
|
||||||
_, _, errno = unix.Syscall(
|
|
||||||
unix.SYS_IOCTL,
|
|
||||||
uintptr(tunfd),
|
|
||||||
uintptr(_TUNSIFMODE),
|
|
||||||
uintptr(unsafe.Pointer(&ifmodemode)),
|
|
||||||
)
|
|
||||||
|
|
||||||
if errno != 0 {
|
|
||||||
return nil, fmt.Errorf("error %s", errno.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
// Rename tun interface
|
// Rename tun interface
|
||||||
|
|
||||||
// Open control socket
|
// Open control socket
|
||||||
@@ -392,7 +384,7 @@ func (tun *nativeTun) doRead(buff []byte, offset int) (int, error) {
|
|||||||
func (tun *nativeTun) Read(buff []byte, offset int) (int, error) {
|
func (tun *nativeTun) Read(buff []byte, offset int) (int, error) {
|
||||||
for {
|
for {
|
||||||
n, err := tun.doRead(buff, offset)
|
n, err := tun.doRead(buff, offset)
|
||||||
if err == nil || !rwcancel.ErrorIsEAGAIN(err) {
|
if err == nil || !rwcancel.RetryAfterError(err) {
|
||||||
return n, err
|
return n, err
|
||||||
}
|
}
|
||||||
if !tun.rwcancel.ReadyRead() {
|
if !tun.rwcancel.ReadyRead() {
|
||||||
|
|||||||
@@ -12,10 +12,10 @@ package tun
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.zx2c4.com/wireguard-go/rwcancel"
|
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"git.zx2c4.com/wireguard-go/rwcancel"
|
||||||
"golang.org/x/net/ipv6"
|
"golang.org/x/net/ipv6"
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
"net"
|
"net"
|
||||||
@@ -102,7 +102,7 @@ func (tun *nativeTun) routineNetlinkListener() {
|
|||||||
var msgn int
|
var msgn int
|
||||||
for {
|
for {
|
||||||
msgn, _, _, _, err = unix.Recvmsg(tun.netlinkSock, msg[:], nil, 0)
|
msgn, _, _, _, err = unix.Recvmsg(tun.netlinkSock, msg[:], nil, 0)
|
||||||
if err == nil || !rwcancel.ErrorIsEAGAIN(err) {
|
if err == nil || !rwcancel.RetryAfterError(err) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if !tun.netlinkCancel.ReadyRead() {
|
if !tun.netlinkCancel.ReadyRead() {
|
||||||
@@ -334,7 +334,7 @@ func (tun *nativeTun) doRead(buff []byte, offset int) (int, error) {
|
|||||||
func (tun *nativeTun) Read(buff []byte, offset int) (int, error) {
|
func (tun *nativeTun) Read(buff []byte, offset int) (int, error) {
|
||||||
for {
|
for {
|
||||||
n, err := tun.doRead(buff, offset)
|
n, err := tun.doRead(buff, offset)
|
||||||
if err == nil || !rwcancel.ErrorIsEAGAIN(err) {
|
if err == nil || !rwcancel.RetryAfterError(err) {
|
||||||
return n, err
|
return n, err
|
||||||
}
|
}
|
||||||
if !tun.fdCancel.ReadyRead() {
|
if !tun.fdCancel.ReadyRead() {
|
||||||
|
|||||||
@@ -6,9 +6,9 @@
|
|||||||
package tun
|
package tun
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.zx2c4.com/wireguard-go/rwcancel"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"git.zx2c4.com/wireguard-go/rwcancel"
|
||||||
"golang.org/x/net/ipv6"
|
"golang.org/x/net/ipv6"
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
@@ -46,8 +46,12 @@ func (tun *nativeTun) routineRouteListener(tunIfindex int) {
|
|||||||
|
|
||||||
data := make([]byte, os.Getpagesize())
|
data := make([]byte, os.Getpagesize())
|
||||||
for {
|
for {
|
||||||
|
retry:
|
||||||
n, err := unix.Read(tun.routeSocket, data)
|
n, err := unix.Read(tun.routeSocket, data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if errno, ok := err.(syscall.Errno); ok && errno == syscall.EINTR {
|
||||||
|
goto retry
|
||||||
|
}
|
||||||
tun.errors <- err
|
tun.errors <- err
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -90,9 +94,7 @@ func (tun *nativeTun) routineRouteListener(tunIfindex int) {
|
|||||||
|
|
||||||
func errorIsEBUSY(err error) bool {
|
func errorIsEBUSY(err error) bool {
|
||||||
if pe, ok := err.(*os.PathError); ok {
|
if pe, ok := err.(*os.PathError); ok {
|
||||||
if errno, ok := pe.Err.(syscall.Errno); ok && errno == syscall.EBUSY {
|
err = pe.Err
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if errno, ok := err.(syscall.Errno); ok && errno == syscall.EBUSY {
|
if errno, ok := err.(syscall.Errno); ok && errno == syscall.EBUSY {
|
||||||
return true
|
return true
|
||||||
@@ -127,19 +129,6 @@ func CreateTUN(name string, mtu int) (TUNDevice, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set TUN iface to broadcast mode
|
|
||||||
ifmodemode := unix.IFF_BROADCAST
|
|
||||||
_, _, errno := unix.Syscall(
|
|
||||||
unix.SYS_IOCTL,
|
|
||||||
uintptr(tunfile.Fd()),
|
|
||||||
uintptr(_TUNSIFMODE),
|
|
||||||
uintptr(unsafe.Pointer(&ifmodemode)),
|
|
||||||
)
|
|
||||||
|
|
||||||
if errno != 0 {
|
|
||||||
return nil, fmt.Errorf("error %s", errno.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
tun, err := CreateTUNFromFile(tunfile, mtu)
|
tun, err := CreateTUNFromFile(tunfile, mtu)
|
||||||
|
|
||||||
if err == nil && name == "tun" {
|
if err == nil && name == "tun" {
|
||||||
@@ -237,7 +226,7 @@ func (tun *nativeTun) doRead(buff []byte, offset int) (int, error) {
|
|||||||
func (tun *nativeTun) Read(buff []byte, offset int) (int, error) {
|
func (tun *nativeTun) Read(buff []byte, offset int) (int, error) {
|
||||||
for {
|
for {
|
||||||
n, err := tun.doRead(buff, offset)
|
n, err := tun.doRead(buff, offset)
|
||||||
if err == nil || !rwcancel.ErrorIsEAGAIN(err) {
|
if err == nil || !rwcancel.RetryAfterError(err) {
|
||||||
return n, err
|
return n, err
|
||||||
}
|
}
|
||||||
if !tun.rwcancel.ReadyRead() {
|
if !tun.rwcancel.ReadyRead() {
|
||||||
|
|||||||
@@ -7,9 +7,9 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.zx2c4.com/wireguard-go/rwcancel"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"git.zx2c4.com/wireguard-go/rwcancel"
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
package main
|
package main
|
||||||
const WireGuardGoVersion = "0.0.20180524"
|
const WireGuardGoVersion = "0.0.20180531"
|
||||||
|
|||||||
Reference in New Issue
Block a user