Add trusted subnets to weave status

`weave status` now displays the list of specified trusted subnets, and
`weave staus connections` shows the encryption state of individual
connections.
This commit is contained in:
Adam Harrison committed 2015-12-14 12:13:16 +00:00
1 parent 059cc65b55
commit 4e41d4d451
2 files changed
+24 -5

No files matched your search

+19 -1
View File
@@ -2,6 +2,7 @@ package mesh
import ( import (
"fmt" "fmt"
"net"
) )
type Status struct { type Status struct {
@@ -19,6 +20,7 @@ type Status struct {
Connections []LocalConnectionStatus Connections []LocalConnectionStatus
Targets []string Targets []string
OverlayDiagnostics interface{} OverlayDiagnostics interface{}
TrustedSubnets []string
} }
type PeerStatus struct { type PeerStatus struct {
@@ -69,7 +71,8 @@ func NewStatus(router *Router) *Status {
NewBroadcastRouteStatusSlice(router.Routes), NewBroadcastRouteStatusSlice(router.Routes),
NewLocalConnectionStatusSlice(router.ConnectionMaker), NewLocalConnectionStatusSlice(router.ConnectionMaker),
NewTargetSlice(router.ConnectionMaker), NewTargetSlice(router.ConnectionMaker),
router.Overlay.Diagnostics()} router.Overlay.Diagnostics(),
NewTrustedSubnetsSlice(router.TrustedSubnets)}
} }
func NewPeerStatusSlice(peers *Peers) []PeerStatus { func NewPeerStatusSlice(peers *Peers) []PeerStatus {
@@ -147,6 +150,13 @@ func NewLocalConnectionStatusSlice(cm *ConnectionMaker) []LocalConnectionStatus
} }
lc, _ := conn.(*LocalConnection) lc, _ := conn.(*LocalConnection)
info := fmt.Sprintf("%-6v %v", lc.OverlayConn.DisplayName(), conn.Remote()) info := fmt.Sprintf("%-6v %v", lc.OverlayConn.DisplayName(), conn.Remote())
if lc.Router.UsingPassword() {
if lc.Untrusted() {
info = fmt.Sprintf("%-11v %v", "encrypted", info)
} else {
info = fmt.Sprintf("%-11v %v", "unencrypted", info)
}
}
slice = append(slice, LocalConnectionStatus{conn.RemoteTCPAddr(), conn.Outbound(), state, info}) slice = append(slice, LocalConnectionStatus{conn.RemoteTCPAddr(), conn.Outbound(), state, info})
} }
for address, target := range cm.targets { for address, target := range cm.targets {
@@ -191,3 +201,11 @@ func NewTargetSlice(cm *ConnectionMaker) []string {
} }
return <-resultChan return <-resultChan
} }
func NewTrustedSubnetsSlice(trustedSubnets []*net.IPNet) []string {
trustedSubnetStrs := []string{}
for _, trustedSubnet := range trustedSubnets {
trustedSubnetStrs = append(trustedSubnetStrs, trustedSubnet.String())
}
return trustedSubnetStrs
}
+5 -4
View File
@@ -27,11 +27,11 @@ var rootTemplate = template.New("root").Funcs(map[string]interface{}{
} }
return count return count
}, },
"upstreamServers": func(servers []string) string { "printList": func(list []string) string {
if len(servers) == 0 { if len(list) == 0 {
return "none" return "none"
} }
return strings.Join(servers, ", ") return strings.Join(list, ", ")
}, },
"printIPAMRanges": func(router weave.NetworkRouterStatus, status ipam.Status) string { "printIPAMRanges": func(router weave.NetworkRouterStatus, status ipam.Status) string {
var buffer bytes.Buffer var buffer bytes.Buffer
@@ -153,6 +153,7 @@ var statusTemplate = defTemplate("status", `\
Targets: {{len .Router.Targets}} Targets: {{len .Router.Targets}}
Connections: {{len .Router.Connections}}{{with printConnectionCounts .Router.Connections}} ({{.}}){{end}} Connections: {{len .Router.Connections}}{{with printConnectionCounts .Router.Connections}} ({{.}}){{end}}
Peers: {{len .Router.Peers}}{{with printPeerConnectionCounts .Router.Peers}} (with {{.}} connections){{end}} Peers: {{len .Router.Peers}}{{with printPeerConnectionCounts .Router.Peers}} (with {{.}} connections){{end}}
TrustedSubnets: {{printList .Router.TrustedSubnets}}
{{if .IPAM}}\ {{if .IPAM}}\
Service: ipam Service: ipam
@@ -176,7 +177,7 @@ var statusTemplate = defTemplate("status", `\
Service: dns Service: dns
Domain: {{.DNS.Domain}} Domain: {{.DNS.Domain}}
Upstream: {{upstreamServers .DNS.Upstream}} Upstream: {{printList .DNS.Upstream}}
TTL: {{.DNS.TTL}} TTL: {{.DNS.TTL}}
Entries: {{countDNSEntries .DNS.Entries}} Entries: {{countDNSEntries .DNS.Entries}}
{{end}}\ {{end}}\