2019-05-19 22:02:04 +01:00
|
|
|
package tuntap
|
|
|
|
|
2019-05-20 21:45:33 +01:00
|
|
|
import (
|
2021-05-16 19:51:09 +01:00
|
|
|
"encoding/json"
|
2019-05-20 21:45:33 +01:00
|
|
|
|
|
|
|
"github.com/yggdrasil-network/yggdrasil-go/src/admin"
|
|
|
|
)
|
2019-05-19 22:02:04 +01:00
|
|
|
|
2021-05-16 19:51:09 +01:00
|
|
|
type GetTUNRequest struct{}
|
2021-05-16 20:00:45 +01:00
|
|
|
type GetTUNResponse map[string]uint64
|
2021-05-16 19:51:09 +01:00
|
|
|
|
|
|
|
func (t *TunAdapter) getTUNHandler(req *GetTUNRequest, res *GetTUNResponse) error {
|
|
|
|
res = &GetTUNResponse{
|
|
|
|
t.Name(): t.MTU(),
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2019-05-19 22:02:04 +01:00
|
|
|
|
2021-05-16 19:51:09 +01:00
|
|
|
func (t *TunAdapter) SetupAdminHandlers(a *admin.AdminSocket) {
|
|
|
|
_ = a.AddHandler("getTunTap", []string{}, func(in json.RawMessage) (interface{}, error) {
|
|
|
|
req := &GetTUNRequest{}
|
|
|
|
res := &GetTUNResponse{}
|
|
|
|
if err := json.Unmarshal(in, &req); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if err := t.getTUNHandler(req, res); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return res, nil
|
2019-05-19 22:02:04 +01:00
|
|
|
})
|
|
|
|
}
|