2019-05-19 21:02:04 +00:00
|
|
|
package tuntap
|
|
|
|
|
2019-05-20 20:45:33 +00:00
|
|
|
import (
|
2021-05-15 19:54:25 +00:00
|
|
|
//"encoding/hex"
|
|
|
|
//"errors"
|
|
|
|
//"fmt"
|
|
|
|
//"net"
|
2019-05-20 20:45:33 +00:00
|
|
|
|
|
|
|
"github.com/yggdrasil-network/yggdrasil-go/src/admin"
|
|
|
|
)
|
2019-05-19 21:02:04 +00:00
|
|
|
|
|
|
|
func (t *TunAdapter) SetupAdminHandlers(a *admin.AdminSocket) {
|
|
|
|
a.AddHandler("getTunTap", []string{}, func(in admin.Info) (r admin.Info, e error) {
|
|
|
|
defer func() {
|
|
|
|
if err := recover(); err != nil {
|
|
|
|
r = admin.Info{"none": admin.Info{}}
|
|
|
|
e = nil
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
return admin.Info{
|
2019-11-22 16:43:50 +00:00
|
|
|
t.Name(): admin.Info{
|
|
|
|
"mtu": t.mtu,
|
2019-05-19 21:02:04 +00:00
|
|
|
},
|
|
|
|
}, nil
|
|
|
|
})
|
|
|
|
/*
|
2019-05-20 20:45:33 +00:00
|
|
|
// TODO: rewrite this as I'm fairly sure it doesn't work right on many
|
|
|
|
// platforms anyway, but it may require changes to Water
|
|
|
|
a.AddHandler("setTunTap", []string{"name", "[tap_mode]", "[mtu]"}, func(in Info) (Info, error) {
|
|
|
|
// Set sane defaults
|
|
|
|
iftapmode := defaults.GetDefaults().DefaultIfTAPMode
|
|
|
|
ifmtu := defaults.GetDefaults().DefaultIfMTU
|
|
|
|
// Has TAP mode been specified?
|
|
|
|
if tap, ok := in["tap_mode"]; ok {
|
|
|
|
iftapmode = tap.(bool)
|
|
|
|
}
|
|
|
|
// Check we have enough params for MTU
|
|
|
|
if mtu, ok := in["mtu"]; ok {
|
|
|
|
if mtu.(float64) >= 1280 && ifmtu <= defaults.GetDefaults().MaximumIfMTU {
|
|
|
|
ifmtu = int(in["mtu"].(float64))
|
2019-05-19 21:02:04 +00:00
|
|
|
}
|
2019-05-20 20:45:33 +00:00
|
|
|
}
|
|
|
|
// Start the TUN adapter
|
|
|
|
if err := a.startTunWithMTU(in["name"].(string), iftapmode, ifmtu); err != nil {
|
|
|
|
return Info{}, errors.New("Failed to configure adapter")
|
|
|
|
} else {
|
|
|
|
return Info{
|
|
|
|
a.core.router.tun.iface.Name(): Info{
|
|
|
|
"tap_mode": a.core.router.tun.iface.IsTAP(),
|
|
|
|
"mtu": ifmtu,
|
|
|
|
},
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
})
|
2019-05-19 21:02:04 +00:00
|
|
|
*/
|
|
|
|
}
|