mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-25 23:01:38 +00:00
Merge pull request #16 from neilalexander/notuntap
Allow setting IfName to 'none' to run without TUN/TAP
This commit is contained in:
commit
8a12a88447
@ -212,11 +212,13 @@ func (c *Core) DEBUG_startTun(ifname string, iftapmode bool) {
|
|||||||
func (c *Core) DEBUG_startTunWithMTU(ifname string, iftapmode bool, mtu int) {
|
func (c *Core) DEBUG_startTunWithMTU(ifname string, iftapmode bool, mtu int) {
|
||||||
addr := c.DEBUG_getAddr()
|
addr := c.DEBUG_getAddr()
|
||||||
straddr := fmt.Sprintf("%s/%v", net.IP(addr[:]).String(), 8*len(address_prefix))
|
straddr := fmt.Sprintf("%s/%v", net.IP(addr[:]).String(), 8*len(address_prefix))
|
||||||
err := c.tun.setup(ifname, iftapmode, straddr, mtu)
|
if ifname != "none" {
|
||||||
if err != nil {
|
err := c.tun.setup(ifname, iftapmode, straddr, mtu)
|
||||||
panic(err)
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
go c.tun.read()
|
||||||
}
|
}
|
||||||
go c.tun.read()
|
|
||||||
go c.tun.write()
|
go c.tun.write()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,6 +33,9 @@ func (tun *tunDevice) init(core *Core) {
|
|||||||
func (tun *tunDevice) write() error {
|
func (tun *tunDevice) write() error {
|
||||||
for {
|
for {
|
||||||
data := <-tun.recv
|
data := <-tun.recv
|
||||||
|
if tun.iface == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if tun.iface.IsTAP() {
|
if tun.iface.IsTAP() {
|
||||||
var frame ethernet.Frame
|
var frame ethernet.Frame
|
||||||
frame.Prepare(
|
frame.Prepare(
|
||||||
@ -88,5 +91,8 @@ func (tun *tunDevice) read() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (tun *tunDevice) close() error {
|
func (tun *tunDevice) close() error {
|
||||||
|
if tun.iface == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return tun.iface.Close()
|
return tun.iface.Close()
|
||||||
}
|
}
|
||||||
|
@ -264,7 +264,11 @@ func main() {
|
|||||||
logger.Println("Initializing...")
|
logger.Println("Initializing...")
|
||||||
n := node{}
|
n := node{}
|
||||||
n.init(cfg, logger)
|
n.init(cfg, logger)
|
||||||
logger.Println("Starting tun...")
|
if cfg.IfName != "none" {
|
||||||
|
logger.Println("Starting TUN/TAP...")
|
||||||
|
} else {
|
||||||
|
logger.Println("Not starting TUN/TAP")
|
||||||
|
}
|
||||||
//n.core.DEBUG_startTun(cfg.IfName) // 1280, the smallest supported MTU
|
//n.core.DEBUG_startTun(cfg.IfName) // 1280, the smallest supported MTU
|
||||||
n.core.DEBUG_startTunWithMTU(cfg.IfName, cfg.IfTAPMode, cfg.IfMTU) // Largest supported MTU
|
n.core.DEBUG_startTunWithMTU(cfg.IfName, cfg.IfTAPMode, cfg.IfMTU) // Largest supported MTU
|
||||||
defer func() {
|
defer func() {
|
||||||
|
Loading…
Reference in New Issue
Block a user