From b4f5ed6618ea5e1cc62601ab4fd6b395e9db8b99 Mon Sep 17 00:00:00 2001 From: Deon Thomas Date: Sun, 8 May 2022 15:06:12 -0400 Subject: [PATCH 1/2] order ip address output, IPv4 first --- cmd/headscale/cli/nodes.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/cmd/headscale/cli/nodes.go b/cmd/headscale/cli/nodes.go index aafd9b9c..805d2ee0 100644 --- a/cmd/headscale/cli/nodes.go +++ b/cmd/headscale/cli/nodes.go @@ -4,7 +4,6 @@ import ( "fmt" "log" "strconv" - "strings" "time" survey "github.com/AlecAivazis/survey/v2" @@ -13,6 +12,7 @@ import ( "github.com/pterm/pterm" "github.com/spf13/cobra" "google.golang.org/grpc/status" + "inet.af/netaddr" "tailscale.com/types/key" ) @@ -452,6 +452,16 @@ func nodesToPtables( // Shared into this namespace namespace = pterm.LightYellow(machine.Namespace.Name) } + + var IpAddresses string + if netaddr.MustParseIP(machine.IpAddresses[0]).Is4() { + IpAddresses = machine.IpAddresses[0] + IpAddresses += ", " + machine.IpAddresses[1] + } else { + IpAddresses = machine.IpAddresses[1] + IpAddresses += ", " + machine.IpAddresses[0] + } + tableData = append( tableData, []string{ @@ -459,7 +469,7 @@ func nodesToPtables( machine.Name, nodeKey.ShortString(), namespace, - strings.Join(machine.IpAddresses, ", "), + IpAddresses, strconv.FormatBool(ephemeral), lastSeenTime, online, From 6ed79b7bb8217547af814ec6761d0c45f72e35f9 Mon Sep 17 00:00:00 2001 From: Deon Thomas Date: Sun, 8 May 2022 15:21:10 -0400 Subject: [PATCH 2/2] order Ip Address, IPv4 first, cleanup --- cmd/headscale/cli/nodes.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/cmd/headscale/cli/nodes.go b/cmd/headscale/cli/nodes.go index 805d2ee0..9159b32b 100644 --- a/cmd/headscale/cli/nodes.go +++ b/cmd/headscale/cli/nodes.go @@ -4,6 +4,7 @@ import ( "fmt" "log" "strconv" + "strings" "time" survey "github.com/AlecAivazis/survey/v2" @@ -453,13 +454,14 @@ func nodesToPtables( namespace = pterm.LightYellow(machine.Namespace.Name) } - var IpAddresses string - if netaddr.MustParseIP(machine.IpAddresses[0]).Is4() { - IpAddresses = machine.IpAddresses[0] - IpAddresses += ", " + machine.IpAddresses[1] - } else { - IpAddresses = machine.IpAddresses[1] - IpAddresses += ", " + machine.IpAddresses[0] + var IpV4Address string + var IpV6Address string + for _, addr := range machine.IpAddresses { + if netaddr.MustParseIP(addr).Is4() { + IpV4Address = addr + } else { + IpV6Address = addr + } } tableData = append( @@ -469,7 +471,7 @@ func nodesToPtables( machine.Name, nodeKey.ShortString(), namespace, - IpAddresses, + strings.Join([]string{IpV4Address, IpV6Address}, ", "), strconv.FormatBool(ephemeral), lastSeenTime, online,