Skip to content

Commit

Permalink
fix : wireguard kernel mode max route table index
Browse files Browse the repository at this point in the history
  • Loading branch information
kunsonx committed Nov 27, 2023
1 parent 6959cfd commit e062d63
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
7 changes: 4 additions & 3 deletions proxy/wireguard/netlink/help_handle_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ import (
"github.com/vishvananda/netlink"
)

func (h *Handle) EmptyRouteTableIndex(family, from int) (out int, err error) {
r := &netlink.Route{Table: from}
func (h *Handle) EmptyRouteTableIndex(family int) (out int, err error) {
// maximum table index is 1023
r := &netlink.Route{Table: 1023}
for ; r.Table >= 0; r.Table-- {
routeList, fErr := netlink.RouteListFiltered(family, r, netlink.RT_FILTER_TABLE)
if len(routeList) == 0 || fErr != nil {
break
}
}
if r.Table < 0 {
return 0, fmt.Errorf("failed to find available family[%d] from[%d] table index", family, from)
return 0, fmt.Errorf("failed to find available family[%d] table index", family)
}
return r.Table, nil
}
8 changes: 4 additions & 4 deletions proxy/wireguard/tun_kernel_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,17 +218,17 @@ func createKernelTun(localAddresses []netip.Addr, mtu int, handler promiscuousMo
}
}()

ipv4TableIndex := 3000
ipv4TableIndex := -1
if v4Enable {
ipv4TableIndex, err = out.handle.EmptyRouteTableIndex(netlink.FAMILY_V4, ipv4TableIndex)
ipv4TableIndex, err = out.handle.EmptyRouteTableIndex(netlink.FAMILY_V4)
if err != nil {
return nil, err
}
}

ipv6TableIndex := 3000
ipv6TableIndex := -1
if v6Enable {
ipv6TableIndex, err = out.handle.EmptyRouteTableIndex(netlink.FAMILY_V6, ipv6TableIndex)
ipv6TableIndex, err = out.handle.EmptyRouteTableIndex(netlink.FAMILY_V6)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit e062d63

Please sign in to comment.