summaryrefslogtreecommitdiffhomepage
path: root/conn_default.go
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-05-22 15:17:35 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2018-05-22 16:21:05 +0200
commitd6b694e1613fd19f8a77ea177d467a60fda4db1d (patch)
tree31d1a14eefc0413063630ad4beeaca4bc80adb13 /conn_default.go
parent794e4948025f108dde3c7d8a4546273d840039ee (diff)
Add OpenBSD tun driver support
Diffstat (limited to 'conn_default.go')
-rw-r--r--conn_default.go64
1 files changed, 37 insertions, 27 deletions
diff --git a/conn_default.go b/conn_default.go
index 739fc83..fc52fbf 100644
--- a/conn_default.go
+++ b/conn_default.go
@@ -140,35 +140,45 @@ func (bind *NativeBind) Send(buff []byte, endpoint Endpoint) error {
return err
}
-func (bind *NativeBind) SetMark(mark uint32) error {
+var fwmarkIoctl int
+
+func init() {
if runtime.GOOS == "freebsd" {
- fd4, err1 := bind.ipv4.SyscallConn()
- fd6, err2 := bind.ipv6.SyscallConn()
- if err1 != nil {
- return err1
- }
- if err2 != nil {
- return err2
- }
- err3 := fd4.Control(func(fd uintptr) {
- err1 = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, 0x1015 /* unix.SO_USER_COOKIE */, int(mark))
- })
- err4 := fd6.Control(func(fd uintptr) {
- err2 = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, 0x1015 /* unix.SO_USER_COOKIE */, int(mark))
- })
- if err1 != nil {
- return err1
- }
- if err2 != nil {
- return err2
- }
- if err3 != nil {
- return err3
- }
- if err4 != nil {
- return err4
- }
+ fwmarkIoctl = 0x1015 /* unix.SO_USER_COOKIE */
+ } else if runtime.GOOS == "openbsd" {
+ fwmarkIoctl = 0x1021 /* unix.SO_RTABLE */
+ }
+}
+
+func (bind *NativeBind) SetMark(mark uint32) error {
+ if fwmarkIoctl == 0 {
return nil
}
+ fd4, err1 := bind.ipv4.SyscallConn()
+ fd6, err2 := bind.ipv6.SyscallConn()
+ if err1 != nil {
+ return err1
+ }
+ if err2 != nil {
+ return err2
+ }
+ err3 := fd4.Control(func(fd uintptr) {
+ err1 = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, fwmarkIoctl, int(mark))
+ })
+ err4 := fd6.Control(func(fd uintptr) {
+ err2 = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, fwmarkIoctl, int(mark))
+ })
+ if err1 != nil {
+ return err1
+ }
+ if err2 != nil {
+ return err2
+ }
+ if err3 != nil {
+ return err3
+ }
+ if err4 != nil {
+ return err4
+ }
return nil
}