new mtu setting and const for default
This commit is contained in:
parent
f03d895ebf
commit
9981510554
2
main.go
2
main.go
|
@ -111,7 +111,7 @@ func Main(configPath string, configTest bool, buildVersion string) {
|
||||||
tun, err := newTun(
|
tun, err := newTun(
|
||||||
config.GetString("tun.dev", ""),
|
config.GetString("tun.dev", ""),
|
||||||
tunCidr,
|
tunCidr,
|
||||||
config.GetInt("tun.mtu", 1300),
|
config.GetInt("tun.mtu", DEFAULT_MTU),
|
||||||
routes,
|
routes,
|
||||||
unsafeRoutes,
|
unsafeRoutes,
|
||||||
config.GetInt("tun.tx_queue", 500),
|
config.GetInt("tun.tx_queue", 500),
|
||||||
|
|
|
@ -6,6 +6,8 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const DEFAULT_MTU = 1300
|
||||||
|
|
||||||
type route struct {
|
type route struct {
|
||||||
mtu int
|
mtu int
|
||||||
route *net.IPNet
|
route *net.IPNet
|
||||||
|
@ -106,6 +108,23 @@ func parseUnsafeRoutes(config *Config, network *net.IPNet) ([]route, error) {
|
||||||
return nil, fmt.Errorf("entry %v in tun.unsafe_routes is invalid", i+1)
|
return nil, fmt.Errorf("entry %v in tun.unsafe_routes is invalid", i+1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rMtu, ok := m["mtu"]
|
||||||
|
if !ok {
|
||||||
|
rMtu = config.GetInt("tun.mtu", DEFAULT_MTU)
|
||||||
|
}
|
||||||
|
|
||||||
|
mtu, ok := rMtu.(int)
|
||||||
|
if !ok {
|
||||||
|
mtu, err = strconv.Atoi(rMtu.(string))
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("entry %v.mtu in tun.unsafe_routes is not an integer: %v", i+1, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if mtu < 500 {
|
||||||
|
return nil, fmt.Errorf("entry %v.mtu in tun.unsafe_routes is below 500: %v", i+1, mtu)
|
||||||
|
}
|
||||||
|
|
||||||
rVia, ok := m["via"]
|
rVia, ok := m["via"]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("entry %v.via in tun.unsafe_routes is not present", i+1)
|
return nil, fmt.Errorf("entry %v.via in tun.unsafe_routes is not present", i+1)
|
||||||
|
|
|
@ -245,6 +245,7 @@ func (c Tun) Activate() error {
|
||||||
nr := netlink.Route{
|
nr := netlink.Route{
|
||||||
LinkIndex: link.Attrs().Index,
|
LinkIndex: link.Attrs().Index,
|
||||||
Dst: r.route,
|
Dst: r.route,
|
||||||
|
MTU: r.mtu,
|
||||||
Scope: unix.RT_SCOPE_LINK,
|
Scope: unix.RT_SCOPE_LINK,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue