Skip to content

Commit

Permalink
new mtu setting and const for default
Browse files Browse the repository at this point in the history
  • Loading branch information
rawdigits committed Dec 12, 2019
1 parent f03d895 commit 9981510
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
19 changes: 19 additions & 0 deletions tun_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"strconv"
)

const DEFAULT_MTU = 1300

type route struct {
mtu int
route *net.IPNet
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions tun_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down

0 comments on commit 9981510

Please sign in to comment.