mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-22 21:10:29 +00:00
AWDL support for macOS/iOS
This commit is contained in:
parent
4f7e8856b8
commit
4622a85c34
@ -3,6 +3,7 @@
|
|||||||
package yggdrasil
|
package yggdrasil
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
@ -113,6 +114,16 @@ func (c *Core) GetSubnetString() string {
|
|||||||
return c.GetSubnet().String()
|
return c.GetSubnet().String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Gets the node's public encryption key.
|
||||||
|
func (c *Core) GetBoxPubKeyString() string {
|
||||||
|
return hex.EncodeToString(c.boxPub[:])
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gets the node's public signing key.
|
||||||
|
func (c *Core) GetSigPubKeyString() string {
|
||||||
|
return hex.EncodeToString(c.sigPub[:])
|
||||||
|
}
|
||||||
|
|
||||||
// Wait for a packet from the router. You will use this when implementing a
|
// Wait for a packet from the router. You will use this when implementing a
|
||||||
// dummy adapter in place of real TUN - when this call returns a packet, you
|
// dummy adapter in place of real TUN - when this call returns a packet, you
|
||||||
// will probably want to give it to the OS to write to TUN.
|
// will probably want to give it to the OS to write to TUN.
|
||||||
|
28
src/yggdrasil/multicast_darwin.go
Normal file
28
src/yggdrasil/multicast_darwin.go
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
// +build darwin
|
||||||
|
|
||||||
|
package yggdrasil
|
||||||
|
|
||||||
|
import "syscall"
|
||||||
|
import "golang.org/x/sys/unix"
|
||||||
|
|
||||||
|
func multicastReuse(network string, address string, c syscall.RawConn) error {
|
||||||
|
var control error
|
||||||
|
var reuseport error
|
||||||
|
var recvanyif error
|
||||||
|
|
||||||
|
control = c.Control(func(fd uintptr) {
|
||||||
|
reuseport = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEPORT, 1)
|
||||||
|
|
||||||
|
// sys/socket.h: #define SO_RECV_ANYIF 0x1104
|
||||||
|
recvanyif = unix.SetsockoptInt(int(fd), syscall.SOL_SOCKET, 0x1104, 1)
|
||||||
|
})
|
||||||
|
|
||||||
|
switch {
|
||||||
|
case reuseport != nil:
|
||||||
|
return reuseport
|
||||||
|
case recvanyif != nil:
|
||||||
|
return recvanyif
|
||||||
|
default:
|
||||||
|
return control
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
// +build linux darwin netbsd freebsd openbsd dragonflybsd
|
// +build linux netbsd freebsd openbsd dragonflybsd
|
||||||
|
|
||||||
package yggdrasil
|
package yggdrasil
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ package yggdrasil
|
|||||||
// See version.go for version metadata format
|
// See version.go for version metadata format
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
@ -88,7 +89,11 @@ func (iface *tcpInterface) init(core *Core, addr string, readTimeout int32) (err
|
|||||||
iface.tcp_timeout = default_tcp_timeout
|
iface.tcp_timeout = default_tcp_timeout
|
||||||
}
|
}
|
||||||
|
|
||||||
iface.serv, err = net.Listen("tcp", addr)
|
ctx := context.Background()
|
||||||
|
lc := net.ListenConfig{
|
||||||
|
Control: iface.tcpContext,
|
||||||
|
}
|
||||||
|
iface.serv, err = lc.Listen(ctx, "tcp", addr)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
iface.calls = make(map[string]struct{})
|
iface.calls = make(map[string]struct{})
|
||||||
iface.conns = make(map[tcpInfo](chan struct{}))
|
iface.conns = make(map[tcpInfo](chan struct{}))
|
||||||
@ -164,7 +169,9 @@ func (iface *tcpInterface) call(saddr string, socksaddr *string, sintf string) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
dialer := net.Dialer{}
|
dialer := net.Dialer{
|
||||||
|
Control: iface.tcpContext,
|
||||||
|
}
|
||||||
if sintf != "" {
|
if sintf != "" {
|
||||||
ief, err := net.InterfaceByName(sintf)
|
ief, err := net.InterfaceByName(sintf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
28
src/yggdrasil/tcp_darwin.go
Normal file
28
src/yggdrasil/tcp_darwin.go
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
// +build darwin
|
||||||
|
|
||||||
|
package yggdrasil
|
||||||
|
|
||||||
|
import (
|
||||||
|
"syscall"
|
||||||
|
|
||||||
|
"golang.org/x/sys/unix"
|
||||||
|
)
|
||||||
|
|
||||||
|
// WARNING: This context is used both by net.Dialer and net.Listen in tcp.go
|
||||||
|
|
||||||
|
func (iface *tcpInterface) tcpContext(network, address string, c syscall.RawConn) error {
|
||||||
|
var control error
|
||||||
|
var recvanyif error
|
||||||
|
|
||||||
|
control = c.Control(func(fd uintptr) {
|
||||||
|
// sys/socket.h: #define SO_RECV_ANYIF 0x1104
|
||||||
|
recvanyif = unix.SetsockoptInt(int(fd), syscall.SOL_SOCKET, 0x1104, 1)
|
||||||
|
})
|
||||||
|
|
||||||
|
switch {
|
||||||
|
case recvanyif != nil:
|
||||||
|
return recvanyif
|
||||||
|
default:
|
||||||
|
return control
|
||||||
|
}
|
||||||
|
}
|
13
src/yggdrasil/tcp_other.go
Normal file
13
src/yggdrasil/tcp_other.go
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
// +build !darwin
|
||||||
|
|
||||||
|
package yggdrasil
|
||||||
|
|
||||||
|
import (
|
||||||
|
"syscall"
|
||||||
|
)
|
||||||
|
|
||||||
|
// WARNING: This context is used both by net.Dialer and net.Listen in tcp.go
|
||||||
|
|
||||||
|
func (iface *tcpInterface) tcpContext(network, address string, c syscall.RawConn) error {
|
||||||
|
return nil
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user