mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-29 06:35:07 +03:00
Add FreeBSD support in TAP mode
This commit is contained in:
parent
57777b6152
commit
c30792245a
9 changed files with 164 additions and 17 deletions
|
@ -1,5 +1,3 @@
|
|||
// +build openbsd
|
||||
|
||||
package yggdrasil
|
||||
|
||||
import "os/exec"
|
||||
|
@ -7,7 +5,7 @@ import "unsafe"
|
|||
import "syscall"
|
||||
import "golang.org/x/sys/unix"
|
||||
|
||||
import water "github.com/neilalexander/water"
|
||||
import water "github.com/yggdrasil-network/water"
|
||||
|
||||
// This is to catch OpenBSD
|
||||
|
||||
|
@ -28,11 +26,22 @@ func getDefaults() tunDefaultParameters {
|
|||
// the fields in a different order, and the consts below might also have
|
||||
// different values
|
||||
|
||||
/*
|
||||
OpenBSD, net/if_tun.h:
|
||||
|
||||
struct tuninfo {
|
||||
u_int mtu;
|
||||
u_short type;
|
||||
u_short flags;
|
||||
u_int baudrate;
|
||||
};
|
||||
*/
|
||||
|
||||
type tuninfo struct {
|
||||
tun_mtu uint16
|
||||
tun_type uint32
|
||||
tun_flags uint32
|
||||
tun_dummy uint16
|
||||
tun_mtu uint32
|
||||
tun_type uint16
|
||||
tun_flags uint16
|
||||
tun_baudrate uint32
|
||||
}
|
||||
|
||||
const TUNSIFINFO = (0x80000000) | ((12 & 0x1fff) << 16) | uint32(byte('t'))<<8 | 91
|
||||
|
@ -79,7 +88,7 @@ func (tun *tunDevice) setup(ifname string, iftapmode bool, addr string, mtu int)
|
|||
config = water.Config{DeviceType: water.TAP}
|
||||
case !iftapmode || ifname[:8] == "/dev/tun":
|
||||
// config = water.Config{DeviceType: water.TUN}
|
||||
panic("TUN mode is not currently supported on OpenBSD, please use TAP instead")
|
||||
panic("TUN mode is not currently supported on this platform, please use TAP instead")
|
||||
default:
|
||||
panic("TUN/TAP name must be in format /dev/tunX or /dev/tapX")
|
||||
}
|
||||
|
@ -111,7 +120,7 @@ func (tun *tunDevice) setupAddress(addr string) error {
|
|||
//tun.core.log.Printf("TUNGIFINFO: %+v", ti)
|
||||
|
||||
// Set the new MTU
|
||||
ti.tun_mtu = uint16(tun.mtu)
|
||||
ti.tun_mtu = uint32(tun.mtu)
|
||||
|
||||
// Set the new interface flags
|
||||
ti.tun_flags |= syscall.IFF_UP
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue