From 39ae57f49d2b8175a8f12535bba0a857ed914340 Mon Sep 17 00:00:00 2001 From: Quentin McGaw Date: Fri, 28 Jul 2023 07:24:26 +0000 Subject: [PATCH] fix(routing): add outbound subnets routes only for matching ip families --- internal/routing/outbound.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/internal/routing/outbound.go b/internal/routing/outbound.go index f2c81ee3f..cfa2e19ac 100644 --- a/internal/routing/outbound.go +++ b/internal/routing/outbound.go @@ -4,6 +4,7 @@ import ( "fmt" "net/netip" + "github.com/qdm12/gluetun/internal/netlink" "github.com/qdm12/gluetun/internal/subnet" ) @@ -74,11 +75,24 @@ func (r *Routing) removeOutboundSubnets(subnets []netip.Prefix, func (r *Routing) addOutboundSubnets(subnets []netip.Prefix, defaultRoutes []DefaultRoute) (err error) { for i, subnet := range subnets { + subnetIsIPv6 := subnet.Addr().Is6() + subnetRouteAdded := false for _, defaultRoute := range defaultRoutes { + defaultRouteIsIPv6 := defaultRoute.Family == netlink.FamilyV6 + ipFamilyMatch := subnetIsIPv6 == defaultRouteIsIPv6 + if !ipFamilyMatch { + continue + } + err = r.addRouteVia(subnet, defaultRoute.Gateway, defaultRoute.NetInterface, outboundTable) if err != nil { return fmt.Errorf("adding route for subnet %s: %w", subnet, err) } + subnetRouteAdded = true + } + + if !subnetRouteAdded { + continue } ruleSrcNet := netip.Prefix{}