mirror of
https://github.com/qdm12/gluetun.git
synced 2026-05-09 20:29:23 +02:00
chore(vpn): find VPN route earlier in MTU update function
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
|||||||
|
|
||||||
"github.com/qdm12/dns/v2/pkg/check"
|
"github.com/qdm12/dns/v2/pkg/check"
|
||||||
"github.com/qdm12/gluetun/internal/constants"
|
"github.com/qdm12/gluetun/internal/constants"
|
||||||
|
"github.com/qdm12/gluetun/internal/netlink"
|
||||||
"github.com/qdm12/gluetun/internal/pmtud"
|
"github.com/qdm12/gluetun/internal/pmtud"
|
||||||
pconstants "github.com/qdm12/gluetun/internal/pmtud/constants"
|
pconstants "github.com/qdm12/gluetun/internal/pmtud/constants"
|
||||||
"github.com/qdm12/gluetun/internal/pmtud/tcp"
|
"github.com/qdm12/gluetun/internal/pmtud/tcp"
|
||||||
@@ -166,6 +167,11 @@ func updateToMaxMTU(ctx context.Context, vpnInterface string,
|
|||||||
return fmt.Errorf("getting VPN gateway IP address: %w", err)
|
return fmt.Errorf("getting VPN gateway IP address: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vpnRoute, err := routing.VPNRoute(vpnInterface)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("getting VPN route: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
link, err := netlinker.LinkByName(vpnInterface)
|
link, err := netlinker.LinkByName(vpnInterface)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("getting VPN interface by name: %w", err)
|
return fmt.Errorf("getting VPN interface by name: %w", err)
|
||||||
@@ -195,7 +201,7 @@ func updateToMaxMTU(ctx context.Context, vpnInterface string,
|
|||||||
logger.Infof("setting VPN interface %s MTU to maximum valid MTU %d", vpnInterface, vpnLinkMTU)
|
logger.Infof("setting VPN interface %s MTU to maximum valid MTU %d", vpnInterface, vpnLinkMTU)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = setTCPMSSOnVPNRoute(vpnInterface, vpnLinkMTU, routing, netlinker)
|
err = setTCPMSSOnVPNRoute(vpnLinkMTU, vpnRoute, netlinker)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = fmt.Errorf("setting safe TCP MSS for MTU %d: %w", vpnLinkMTU, err)
|
err = fmt.Errorf("setting safe TCP MSS for MTU %d: %w", vpnLinkMTU, err)
|
||||||
vpnLinkMTU = originalMTU
|
vpnLinkMTU = originalMTU
|
||||||
@@ -211,14 +217,7 @@ func updateToMaxMTU(ctx context.Context, vpnInterface string,
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func setTCPMSSOnVPNRoute(vpnIntf string, mtu uint32,
|
func setTCPMSSOnVPNRoute(mtu uint32, route netlink.Route, netlinker NetLinker) error {
|
||||||
routing Routing, netlinker NetLinker,
|
|
||||||
) error {
|
|
||||||
route, err := routing.VPNRoute(vpnIntf)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("getting VPN route: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
ipHeaderLength := pconstants.IPv4HeaderLength
|
ipHeaderLength := pconstants.IPv4HeaderLength
|
||||||
if route.Dst.Addr().Is6() {
|
if route.Dst.Addr().Is6() {
|
||||||
ipHeaderLength = pconstants.IPv6HeaderLength
|
ipHeaderLength = pconstants.IPv6HeaderLength
|
||||||
@@ -227,9 +226,5 @@ func setTCPMSSOnVPNRoute(vpnIntf string, mtu uint32,
|
|||||||
overhead := ipHeaderLength + pconstants.BaseTCPHeaderLength + mysteriousOverhead
|
overhead := ipHeaderLength + pconstants.BaseTCPHeaderLength + mysteriousOverhead
|
||||||
mss := mtu - overhead
|
mss := mtu - overhead
|
||||||
route.AdvMSS = mss
|
route.AdvMSS = mss
|
||||||
err = netlinker.RouteReplace(route)
|
return netlinker.RouteReplace(route)
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("replacing VPN route with MSS changed to %d: %w", mss, err)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user