Skip to content

Commit

Permalink
fix(routing): add outbound subnets routes only for matching ip families
Browse files Browse the repository at this point in the history
  • Loading branch information
qdm12 committed Jul 28, 2023
1 parent 9024912 commit 39ae57f
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions internal/routing/outbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"net/netip"

"github.com/qdm12/gluetun/internal/netlink"
"github.com/qdm12/gluetun/internal/subnet"
)

Expand Down Expand Up @@ -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{}
Expand Down

0 comments on commit 39ae57f

Please sign in to comment.