diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-12-11 18:21:11 +0100 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-12-11 18:29:46 +0100 |
commit | c967f15e443a5953429000e50fad2e117992b72d (patch) | |
tree | f4306016fe4224bbc4a0fb8988af6dc23d66f1cc | |
parent | 5ace0fdfe237b2062c060fbe30d6fb40965fb1b9 (diff) |
Separate out mark setting for Windows
-rw-r--r-- | conn_default.go | 46 | ||||
-rw-r--r-- | mark_default.go | 12 | ||||
-rw-r--r-- | mark_unix.go | 57 |
3 files changed, 69 insertions, 46 deletions
diff --git a/conn_default.go b/conn_default.go index 9b2325c..862032d 100644 --- a/conn_default.go +++ b/conn_default.go @@ -8,10 +8,8 @@ package main import ( - "golang.org/x/sys/unix" "net" "os" - "runtime" "syscall" ) @@ -171,47 +169,3 @@ func (bind *NativeBind) Send(buff []byte, endpoint Endpoint) error { } return err } - -var fwmarkIoctl int - -func init() { - switch runtime.GOOS { - case "linux", "android": - fwmarkIoctl = 36 /* unix.SO_MARK */ - case "freebsd": - fwmarkIoctl = 0x1015 /* unix.SO_USER_COOKIE */ - case "openbsd": - fwmarkIoctl = 0x1021 /* unix.SO_RTABLE */ - } -} - -func (bind *NativeBind) SetMark(mark uint32) error { - if fwmarkIoctl == 0 { - return nil - } - if bind.ipv4 != nil { - fd, err := bind.ipv4.SyscallConn() - if err != nil { - return err - } - err = fd.Control(func(fd uintptr) { - err = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, fwmarkIoctl, int(mark)) - }) - if err != nil { - return err - } - } - if bind.ipv6 != nil { - fd, err := bind.ipv6.SyscallConn() - if err != nil { - return err - } - err = fd.Control(func(fd uintptr) { - err = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, fwmarkIoctl, int(mark)) - }) - if err != nil { - return err - } - } - return nil -} diff --git a/mark_default.go b/mark_default.go new file mode 100644 index 0000000..7062606 --- /dev/null +++ b/mark_default.go @@ -0,0 +1,12 @@ +// +build !linux,!openbsd,!freebsd + +/* SPDX-License-Identifier: GPL-2.0 + * + * Copyright (C) 2017-2018 WireGuard LLC. All Rights Reserved. + */ + +package main + +func (bind *NativeBind) SetMark(mark uint32) error { + return nil +} diff --git a/mark_unix.go b/mark_unix.go new file mode 100644 index 0000000..0b9d7e0 --- /dev/null +++ b/mark_unix.go @@ -0,0 +1,57 @@ +// +build android openbsd freebsd + +/* SPDX-License-Identifier: GPL-2.0 + * + * Copyright (C) 2017-2018 WireGuard LLC. All Rights Reserved. + */ + +package main + +import ( + "golang.org/x/sys/unix" + "runtime" +) + +var fwmarkIoctl int + +func init() { + switch runtime.GOOS { + case "linux", "android": + fwmarkIoctl = 36 /* unix.SO_MARK */ + case "freebsd": + fwmarkIoctl = 0x1015 /* unix.SO_USER_COOKIE */ + case "openbsd": + fwmarkIoctl = 0x1021 /* unix.SO_RTABLE */ + } +} + +func (bind *NativeBind) SetMark(mark uint32) error { + if fwmarkIoctl == 0 { + return nil + } + if bind.ipv4 != nil { + fd, err := bind.ipv4.SyscallConn() + if err != nil { + return err + } + err = fd.Control(func(fd uintptr) { + err = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, fwmarkIoctl, int(mark)) + }) + if err != nil { + return err + } + } + if bind.ipv6 != nil { + fd, err := bind.ipv6.SyscallConn() + if err != nil { + return err + } + err = fd.Control(func(fd uintptr) { + err = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, fwmarkIoctl, int(mark)) + }) + if err != nil { + return err + } + } + return nil +} |