mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-06 12:33:44 +02:00
.
This commit is contained in:
parent
105023bd87
commit
9c37fc1a5f
3 changed files with 19 additions and 0 deletions
|
@ -13,12 +13,19 @@
|
||||||
|
|
||||||
package zerotier
|
package zerotier
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
// MulticastGroup represents a normal Ethernet multicast or broadcast address plus 32 additional ZeroTier-specific bits
|
// MulticastGroup represents a normal Ethernet multicast or broadcast address plus 32 additional ZeroTier-specific bits
|
||||||
type MulticastGroup struct {
|
type MulticastGroup struct {
|
||||||
MAC MAC
|
MAC MAC
|
||||||
ADI uint32
|
ADI uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// String returns MAC#ADI
|
||||||
|
func (mg *MulticastGroup) String() string {
|
||||||
|
return fmt.Sprintf("%s#%.8x", mg.MAC.String(), mg.ADI)
|
||||||
|
}
|
||||||
|
|
||||||
// Less returns true if this MulticastGroup is less than another.
|
// Less returns true if this MulticastGroup is less than another.
|
||||||
func (mg *MulticastGroup) Less(mg2 *MulticastGroup) bool {
|
func (mg *MulticastGroup) Less(mg2 *MulticastGroup) bool {
|
||||||
return (mg.MAC < mg2.MAC || (mg.MAC == mg2.MAC && mg.ADI < mg2.ADI))
|
return (mg.MAC < mg2.MAC || (mg.MAC == mg2.MAC && mg.ADI < mg2.ADI))
|
||||||
|
|
|
@ -196,6 +196,7 @@ func (n *Network) SetLocalSettings(ls *NetworkLocalSettings) { n.updateConfig(ni
|
||||||
|
|
||||||
// MulticastSubscribe subscribes to a multicast group
|
// MulticastSubscribe subscribes to a multicast group
|
||||||
func (n *Network) MulticastSubscribe(mg *MulticastGroup) {
|
func (n *Network) MulticastSubscribe(mg *MulticastGroup) {
|
||||||
|
n.node.log.Printf("%.16x joined multicast group %s", mg.String())
|
||||||
k := mg.key()
|
k := mg.key()
|
||||||
n.multicastSubscriptionsLock.Lock()
|
n.multicastSubscriptionsLock.Lock()
|
||||||
if _, have := n.multicastSubscriptions[k]; have {
|
if _, have := n.multicastSubscriptions[k]; have {
|
||||||
|
@ -209,6 +210,7 @@ func (n *Network) MulticastSubscribe(mg *MulticastGroup) {
|
||||||
|
|
||||||
// MulticastUnsubscribe removes a subscription to a multicast group
|
// MulticastUnsubscribe removes a subscription to a multicast group
|
||||||
func (n *Network) MulticastUnsubscribe(mg *MulticastGroup) {
|
func (n *Network) MulticastUnsubscribe(mg *MulticastGroup) {
|
||||||
|
n.node.log.Printf("%.16x left multicast group %s", mg.String())
|
||||||
n.multicastSubscriptionsLock.Lock()
|
n.multicastSubscriptionsLock.Lock()
|
||||||
delete(n.multicastSubscriptions, mg.key())
|
delete(n.multicastSubscriptions, mg.key())
|
||||||
n.multicastSubscriptionsLock.Unlock()
|
n.multicastSubscriptionsLock.Unlock()
|
||||||
|
@ -297,6 +299,7 @@ func (n *Network) updateConfig(nc *NetworkConfig, ls *NetworkLocalSettings) {
|
||||||
k := ipNetToKey(&ip)
|
k := ipNetToKey(&ip)
|
||||||
wantAssignedIPs[k] = true
|
wantAssignedIPs[k] = true
|
||||||
if _, have := haveAssignedIPs[k]; !have {
|
if _, have := haveAssignedIPs[k]; !have {
|
||||||
|
n.node.log.Printf("%.16x adding managed IP %s", n.ID, ip.String())
|
||||||
n.tap.AddIP(&ip)
|
n.tap.AddIP(&ip)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -304,6 +307,7 @@ func (n *Network) updateConfig(nc *NetworkConfig, ls *NetworkLocalSettings) {
|
||||||
}
|
}
|
||||||
for k, ip := range haveAssignedIPs {
|
for k, ip := range haveAssignedIPs {
|
||||||
if _, want := wantAssignedIPs[k]; !want {
|
if _, want := wantAssignedIPs[k]; !want {
|
||||||
|
n.node.log.Printf("%.16x removing managed IP %s", n.ID, ip.String())
|
||||||
n.tap.RemoveIP(ip)
|
n.tap.RemoveIP(ip)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -324,6 +328,7 @@ func (n *Network) updateConfig(nc *NetworkConfig, ls *NetworkLocalSettings) {
|
||||||
k := r.key()
|
k := r.key()
|
||||||
wantManagedRoutes[k] = true
|
wantManagedRoutes[k] = true
|
||||||
if _, have := haveManagedRoutes[k]; !have {
|
if _, have := haveManagedRoutes[k]; !have {
|
||||||
|
n.node.log.Printf("%.16x adding managed route %s", n.ID, r.Target.String())
|
||||||
n.tap.AddRoute(&r)
|
n.tap.AddRoute(&r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -331,6 +336,7 @@ func (n *Network) updateConfig(nc *NetworkConfig, ls *NetworkLocalSettings) {
|
||||||
}
|
}
|
||||||
for k, r := range haveManagedRoutes {
|
for k, r := range haveManagedRoutes {
|
||||||
if _, want := wantManagedRoutes[k]; !want {
|
if _, want := wantManagedRoutes[k]; !want {
|
||||||
|
n.node.log.Printf("%.16x removing managed route %s", n.ID, r.Target.String())
|
||||||
n.tap.RemoveRoute(r)
|
n.tap.RemoveRoute(r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -540,6 +540,7 @@ func (n *Node) AddStaticRoot(id *Identity, addrs []InetAddress) {
|
||||||
|
|
||||||
// RemoveStaticRoot removes a statically defined root server from this node.
|
// RemoveStaticRoot removes a statically defined root server from this node.
|
||||||
func (n *Node) RemoveStaticRoot(id *Identity) {
|
func (n *Node) RemoveStaticRoot(id *Identity) {
|
||||||
|
n.log.Printf("removing static root %s", id.String())
|
||||||
ids := C.CString(id.String())
|
ids := C.CString(id.String())
|
||||||
C.ZT_Node_removeStaticRoot(unsafe.Pointer(n.zn), ids)
|
C.ZT_Node_removeStaticRoot(unsafe.Pointer(n.zn), ids)
|
||||||
C.free(unsafe.Pointer(ids))
|
C.free(unsafe.Pointer(ids))
|
||||||
|
@ -550,6 +551,7 @@ func (n *Node) RemoveStaticRoot(id *Identity) {
|
||||||
// to use if (or until) one can be fetched via DNS.
|
// to use if (or until) one can be fetched via DNS.
|
||||||
func (n *Node) AddDynamicRoot(dnsName string, locator []byte) {
|
func (n *Node) AddDynamicRoot(dnsName string, locator []byte) {
|
||||||
dn := C.CString(dnsName)
|
dn := C.CString(dnsName)
|
||||||
|
n.log.Printf("adding dynamic root %s", dnsName)
|
||||||
if len(locator) > 0 {
|
if len(locator) > 0 {
|
||||||
C.ZT_Node_setDynamicRoot(unsafe.Pointer(n.zn), dn, unsafe.Pointer(&locator[0]), C.uint(len(locator)))
|
C.ZT_Node_setDynamicRoot(unsafe.Pointer(n.zn), dn, unsafe.Pointer(&locator[0]), C.uint(len(locator)))
|
||||||
} else {
|
} else {
|
||||||
|
@ -560,6 +562,7 @@ func (n *Node) AddDynamicRoot(dnsName string, locator []byte) {
|
||||||
|
|
||||||
// RemoveDynamicRoot removes a dynamic root from this node.
|
// RemoveDynamicRoot removes a dynamic root from this node.
|
||||||
func (n *Node) RemoveDynamicRoot(dnsName string) {
|
func (n *Node) RemoveDynamicRoot(dnsName string) {
|
||||||
|
n.log.Printf("removing dynamic root %s", dnsName)
|
||||||
dn := C.CString(dnsName)
|
dn := C.CString(dnsName)
|
||||||
C.ZT_Node_removeDynamicRoot(unsafe.Pointer(n.zn), dn)
|
C.ZT_Node_removeDynamicRoot(unsafe.Pointer(n.zn), dn)
|
||||||
C.free(unsafe.Pointer(dn))
|
C.free(unsafe.Pointer(dn))
|
||||||
|
@ -730,6 +733,9 @@ func (n *Node) stateObjectGet(objType int, id [2]uint64) ([]byte, bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Node) handleTrace(traceMessage string) {
|
func (n *Node) handleTrace(traceMessage string) {
|
||||||
|
if len(traceMessage) > 0 {
|
||||||
|
n.log.Print("TRACE: " + traceMessage)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Node) handleUserMessage(originAddress, messageTypeID uint64, data []byte) {
|
func (n *Node) handleUserMessage(originAddress, messageTypeID uint64, data []byte) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue