diff --git a/CHANGELOG.md b/CHANGELOG.md index 693fef73..2a08f6dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ ### Changes -- TBD +- Fix wrong behaviour in exit nodes [#1159](https://github.com/juanfont/headscale/pull/1159) ## 0.19.0 (2023-01-29) diff --git a/cmd/headscale/cli/routes.go b/cmd/headscale/cli/routes.go index e5dacb01..231e061a 100644 --- a/cmd/headscale/cli/routes.go +++ b/cmd/headscale/cli/routes.go @@ -3,8 +3,10 @@ package cli import ( "fmt" "log" + "net/netip" "strconv" + "github.com/juanfont/headscale" v1 "github.com/juanfont/headscale/gen/go/headscale/v1" "github.com/pterm/pterm" "github.com/spf13/cobra" @@ -218,6 +220,19 @@ func routesToPtables(routes []*v1.Route) pterm.TableData { tableData := pterm.TableData{{"ID", "Machine", "Prefix", "Advertised", "Enabled", "Primary"}} for _, route := range routes { + var isPrimaryStr string + prefix, err := netip.ParsePrefix(route.Prefix) + if err != nil { + log.Printf("Error parsing prefix %s: %s", route.Prefix, err) + + continue + } + if prefix == headscale.ExitRouteV4 || prefix == headscale.ExitRouteV6 { + isPrimaryStr = "-" + } else { + isPrimaryStr = strconv.FormatBool(route.IsPrimary) + } + tableData = append(tableData, []string{ strconv.FormatUint(route.Id, Base10), @@ -225,7 +240,7 @@ func routesToPtables(routes []*v1.Route) pterm.TableData { route.Prefix, strconv.FormatBool(route.Advertised), strconv.FormatBool(route.Enabled), - strconv.FormatBool(route.IsPrimary), + isPrimaryStr, }) }