From 9981510554c6296781cac2930f8779dcf4eb42ff Mon Sep 17 00:00:00 2001 From: Ryan Huber Date: Thu, 12 Dec 2019 18:01:46 +0000 Subject: [PATCH] new mtu setting and const for default --- main.go | 2 +- tun_common.go | 19 +++++++++++++++++++ tun_linux.go | 1 + 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index c1bc7d8..a7eaee5 100644 --- a/main.go +++ b/main.go @@ -111,7 +111,7 @@ func Main(configPath string, configTest bool, buildVersion string) { tun, err := newTun( config.GetString("tun.dev", ""), tunCidr, - config.GetInt("tun.mtu", 1300), + config.GetInt("tun.mtu", DEFAULT_MTU), routes, unsafeRoutes, config.GetInt("tun.tx_queue", 500), diff --git a/tun_common.go b/tun_common.go index 57855fa..760a313 100644 --- a/tun_common.go +++ b/tun_common.go @@ -6,6 +6,8 @@ import ( "strconv" ) +const DEFAULT_MTU = 1300 + type route struct { mtu int 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) } + 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"] if !ok { return nil, fmt.Errorf("entry %v.via in tun.unsafe_routes is not present", i+1) diff --git a/tun_linux.go b/tun_linux.go index a527abf..9ae35f7 100644 --- a/tun_linux.go +++ b/tun_linux.go @@ -245,6 +245,7 @@ func (c Tun) Activate() error { nr := netlink.Route{ LinkIndex: link.Attrs().Index, Dst: r.route, + MTU: r.mtu, Scope: unix.RT_SCOPE_LINK, }