Skip to content

Commit

Permalink
Do not show IsPrimary field as false in exit nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
juanfont committed Jan 29, 2023
1 parent 0f65918 commit 640bb94
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
17 changes: 16 additions & 1 deletion cmd/headscale/cli/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -218,14 +220,27 @@ 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),
route.Machine.GivenName,
route.Prefix,
strconv.FormatBool(route.Advertised),
strconv.FormatBool(route.Enabled),
strconv.FormatBool(route.IsPrimary),
isPrimaryStr,
})
}

Expand Down

0 comments on commit 640bb94

Please sign in to comment.