Support for MTU parameter #12

This commit is contained in:
octeep 2022-03-28 19:19:59 +01:00
parent b77da8ec20
commit b7dae52958
2 changed files with 17 additions and 2 deletions

View file

@ -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:

16
main.go
View file

@ -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
}