From 5d876011185f74b6e7598119c6cfc228f2cd4bcd Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Wed, 23 May 2018 22:13:52 +0100 Subject: [PATCH 1/2] Add getMulticastInterfaces and getSelf to yggdrasilctl --- src/yggdrasil/admin.go | 12 +++++++++++- yggdrasilctl.go | 21 +++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/yggdrasil/admin.go b/src/yggdrasil/admin.go index a2b5944d..5bf9d3fa 100644 --- a/src/yggdrasil/admin.go +++ b/src/yggdrasil/admin.go @@ -173,6 +173,13 @@ func (a *admin) init(c *Core, listenaddr string) { }, nil } }) + a.addHandler("getMulticastInterfaces", []string{}, func(in admin_info) (admin_info, error) { + var intfs []string + for _, v := range a.core.multicast.interfaces { + intfs = append(intfs, v.Name) + } + return admin_info{"multicast_interfaces": intfs}, nil + }) a.addHandler("getAllowedEncryptionPublicKeys", []string{}, func(in admin_info) (admin_info, error) { return admin_info{"allowed_box_pubs": a.getAllowedEncryptionPublicKeys()}, nil }) @@ -414,10 +421,13 @@ func (a *admin) startTunWithMTU(ifname string, iftapmode bool, ifmtu int) error func (a *admin) getData_getSelf() *admin_nodeInfo { table := a.core.switchTable.table.Load().(lookupTable) - addr := a.core.router.addr + addr := (*a.core.GetAddress())[:] + subnet := (*a.core.GetSubnet())[:] + subnet = append(subnet, 0, 0, 0, 0, 0, 0, 0, 0) coords := table.self.getCoords() self := admin_nodeInfo{ {"ip", net.IP(addr[:]).String()}, + {"subnet", fmt.Sprintf("%s/64", net.IP(subnet[:]).String())}, {"coords", fmt.Sprint(coords)}, } return &self diff --git a/yggdrasilctl.go b/yggdrasilctl.go index 7a6654a6..c15a28c2 100644 --- a/yggdrasilctl.go +++ b/yggdrasilctl.go @@ -155,6 +155,16 @@ func main() { fmt.Println("TAP mode:", tap_mode) } } + case "getSelf": + for k, v := range res["self"].(map[string]interface{}) { + fmt.Println("address:", k) + if subnet, ok := v.(map[string]interface{})["subnet"].(string); ok { + fmt.Println("subnet:", subnet) + } + if coords, ok := v.(map[string]interface{})["coords"].(string); ok { + fmt.Println("coords:", coords) + } + } case "addPeer", "removePeer", "addAllowedEncryptionPublicKey", "removeAllowedEncryptionPublicKey": if _, ok := res["added"]; ok { for _, v := range res["added"].([]interface{}) { @@ -187,6 +197,17 @@ func main() { fmt.Println("-", v) } } + case "getMulticastInterfaces": + if _, ok := res["multicast_interfaces"]; !ok { + fmt.Println("No multicast interfaces found") + } else if res["multicast_interfaces"] == nil { + fmt.Println("No multicast interfaces found") + } else { + fmt.Println("Multicast peer discovery is active on:") + for _, v := range res["multicast_interfaces"].([]interface{}) { + fmt.Println("-", v) + } + } default: if json, err := json.MarshalIndent(recv["response"], "", " "); err == nil { fmt.Println(string(json)) From cae589d2d335c06a2471c522697927d0e9666b44 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Wed, 23 May 2018 22:21:37 +0100 Subject: [PATCH 2/2] More nice --- yggdrasilctl.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/yggdrasilctl.go b/yggdrasilctl.go index c15a28c2..5cea7745 100644 --- a/yggdrasilctl.go +++ b/yggdrasilctl.go @@ -157,12 +157,12 @@ func main() { } case "getSelf": for k, v := range res["self"].(map[string]interface{}) { - fmt.Println("address:", k) + fmt.Println("IPv6 address:", k) if subnet, ok := v.(map[string]interface{})["subnet"].(string); ok { - fmt.Println("subnet:", subnet) + fmt.Println("IPv6 subnet:", subnet) } if coords, ok := v.(map[string]interface{})["coords"].(string); ok { - fmt.Println("coords:", coords) + fmt.Println("Coords:", coords) } } case "addPeer", "removePeer", "addAllowedEncryptionPublicKey", "removeAllowedEncryptionPublicKey":