From b7dae5295827a0ebd68e67d567ba25eeae9a01f4 Mon Sep 17 00:00:00 2001 From: octeep Date: Mon, 28 Mar 2022 19:19:59 +0100 Subject: [PATCH] Support for MTU parameter #12 --- README.md | 3 +++ main.go | 16 ++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f20bbe6..17ca618 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,9 @@ DNS = 1.1.1.1 # If you don't know what this is, then you probably don't need it. #PreSharedKey = UItQuvLsyh50ucXHfjF0bbR4IIpVBd74lwKc8uIPXXs= +# MTU is the maximum transmission unit size, By default this is set to 1420. +# MTU = 1234 + # TCPClientTunnel is a tunnel listening on your machine, # and it forwards any TCP traffic received to the specified target via wireguard. # Flow: diff --git a/main.go b/main.go index 163d3f3..c7cc2e1 100644 --- a/main.go +++ b/main.go @@ -32,6 +32,7 @@ type DeviceSetting struct { ipcRequest string dns []netip.Addr deviceAddr *netip.Addr + mtu int } type NetstackDNSResolver struct { @@ -220,6 +221,17 @@ func createIPCRequest(conf Configuration) (*DeviceSetting, error) { } } + mtu := int64(1420) + if mtuOpt, ok := root["mtu"]; ok { + mtu, err = strconv.ParseInt(mtuOpt, 10, 0) + if err != nil { + return nil, err + } + if mtu < 0 { + mtu = 0 + } + } + request := fmt.Sprintf(`private_key=%s public_key=%s endpoint=%s @@ -227,7 +239,7 @@ persistent_keepalive_interval=%d preshared_key=%s allowed_ip=0.0.0.0/0`, selfSK, peerPK, peerEndpoint, keepAlive, preSharedKey) - setting := &DeviceSetting{ipcRequest: request, dns: dns, deviceAddr: &selfEndpoint} + setting := &DeviceSetting{ipcRequest: request, dns: dns, deviceAddr: &selfEndpoint, mtu: int(mtu)} return setting, nil } @@ -366,7 +378,7 @@ func tcpServerRoutine(config map[string]string) (func(*netstack.Net), error) { } func startWireguard(setting *DeviceSetting) (*netstack.Net, error) { - tun, tnet, err := netstack.CreateNetTUN([]netip.Addr{*(setting.deviceAddr)}, setting.dns, 1420) + tun, tnet, err := netstack.CreateNetTUN([]netip.Addr{*(setting.deviceAddr)}, setting.dns, setting.mtu) if err != nil { return nil, err }