From 640bb94119345a93c250b14679fcad8c432d1419 Mon Sep 17 00:00:00 2001 From: Juan Font Date: Sun, 29 Jan 2023 11:55:29 +0000 Subject: [PATCH] Do not show IsPrimary field as false in exit nodes --- CHANGELOG.md | 2 +- cmd/headscale/cli/routes.go | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) 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, }) }