5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-22 14:10:28 +00:00

Merge pull request #90 from neilalexander/admin

Add getMulticastInterfaces and getSelf to yggdrasilctl
This commit is contained in:
Arceliar 2018-05-23 17:52:06 -05:00 committed by GitHub
commit fae00e962f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 1 deletions

View File

@ -173,6 +173,13 @@ func (a *admin) init(c *Core, listenaddr string) {
}, nil }, 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) { a.addHandler("getAllowedEncryptionPublicKeys", []string{}, func(in admin_info) (admin_info, error) {
return admin_info{"allowed_box_pubs": a.getAllowedEncryptionPublicKeys()}, nil 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 { func (a *admin) getData_getSelf() *admin_nodeInfo {
table := a.core.switchTable.table.Load().(lookupTable) 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() coords := table.self.getCoords()
self := admin_nodeInfo{ self := admin_nodeInfo{
{"ip", net.IP(addr[:]).String()}, {"ip", net.IP(addr[:]).String()},
{"subnet", fmt.Sprintf("%s/64", net.IP(subnet[:]).String())},
{"coords", fmt.Sprint(coords)}, {"coords", fmt.Sprint(coords)},
} }
return &self return &self

View File

@ -155,6 +155,16 @@ func main() {
fmt.Println("TAP mode:", tap_mode) fmt.Println("TAP mode:", tap_mode)
} }
} }
case "getSelf":
for k, v := range res["self"].(map[string]interface{}) {
fmt.Println("IPv6 address:", k)
if subnet, ok := v.(map[string]interface{})["subnet"].(string); ok {
fmt.Println("IPv6 subnet:", subnet)
}
if coords, ok := v.(map[string]interface{})["coords"].(string); ok {
fmt.Println("Coords:", coords)
}
}
case "addPeer", "removePeer", "addAllowedEncryptionPublicKey", "removeAllowedEncryptionPublicKey": case "addPeer", "removePeer", "addAllowedEncryptionPublicKey", "removeAllowedEncryptionPublicKey":
if _, ok := res["added"]; ok { if _, ok := res["added"]; ok {
for _, v := range res["added"].([]interface{}) { for _, v := range res["added"].([]interface{}) {
@ -187,6 +197,17 @@ func main() {
fmt.Println("-", v) 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: default:
if json, err := json.MarshalIndent(recv["response"], "", " "); err == nil { if json, err := json.MarshalIndent(recv["response"], "", " "); err == nil {
fmt.Println(string(json)) fmt.Println(string(json))