Do not show IsPrimary field as false in exit nodes

This commit is contained in:
Juan Font 2023-01-29 11:55:29 +00:00
parent 0f65918a25
commit 640bb94119
2 changed files with 17 additions and 2 deletions

View file

@ -4,7 +4,7 @@
### Changes ### Changes
- TBD - Fix wrong behaviour in exit nodes [#1159](https://github.com/juanfont/headscale/pull/1159)
## 0.19.0 (2023-01-29) ## 0.19.0 (2023-01-29)

View file

@ -3,8 +3,10 @@ package cli
import ( import (
"fmt" "fmt"
"log" "log"
"net/netip"
"strconv" "strconv"
"github.com/juanfont/headscale"
v1 "github.com/juanfont/headscale/gen/go/headscale/v1" v1 "github.com/juanfont/headscale/gen/go/headscale/v1"
"github.com/pterm/pterm" "github.com/pterm/pterm"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -218,6 +220,19 @@ func routesToPtables(routes []*v1.Route) pterm.TableData {
tableData := pterm.TableData{{"ID", "Machine", "Prefix", "Advertised", "Enabled", "Primary"}} tableData := pterm.TableData{{"ID", "Machine", "Prefix", "Advertised", "Enabled", "Primary"}}
for _, route := range routes { 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, tableData = append(tableData,
[]string{ []string{
strconv.FormatUint(route.Id, Base10), strconv.FormatUint(route.Id, Base10),
@ -225,7 +240,7 @@ func routesToPtables(routes []*v1.Route) pterm.TableData {
route.Prefix, route.Prefix,
strconv.FormatBool(route.Advertised), strconv.FormatBool(route.Advertised),
strconv.FormatBool(route.Enabled), strconv.FormatBool(route.Enabled),
strconv.FormatBool(route.IsPrimary), isPrimaryStr,
}) })
} }