1
0
mirror of https://github.com/zerotier/ZeroTierOne.git synced 2025-03-12 04:36:29 -07:00

Fix some JSON names, regularize use of IP/port info in service code.

This commit is contained in:
Adam Ierymenko 2020-07-31 15:32:09 -07:00
parent 7c929099b3
commit 9da0b43d2d
No known key found for this signature in database
GPG Key ID: C8877CF2D7A5D7F3
8 changed files with 90 additions and 38 deletions

@ -0,0 +1,26 @@
/*
* Copyright (c)2013-2020 ZeroTier, Inc.
*
* Use of this software is governed by the Business Source License included
* in the LICENSE.TXT file in the project's root directory.
*
* Change Date: 2025-01-01
*
* On the date above, in accordance with the Business Source License, use
* of this software will be governed by version 2.0 of the Apache License.
*/
/****/
package cli
func Controller(basePath, authToken string, args []string, jsonOutput bool) int {
if len(args) < 1 {
Help()
return 1
}
switch args[0] {
}
return 0
}

26
cmd/zerotier/cli/peer.go Normal file

@ -0,0 +1,26 @@
/*
* Copyright (c)2013-2020 ZeroTier, Inc.
*
* Use of this software is governed by the Business Source License included
* in the LICENSE.TXT file in the project's root directory.
*
* Change Date: 2025-01-01
*
* On the date above, in accordance with the Business Source License, use
* of this software will be governed by version 2.0 of the Apache License.
*/
/****/
package cli
func Peer(basePath, authToken string, args []string, jsonOutput bool) int {
if len(args) < 1 {
Help()
return 1
}
switch args[0] {
}
return 0
}

@ -139,9 +139,11 @@ func main() {
case "peers", "listpeers", "lspeers":
exitCode = cli.Peers(basePath, authToken(basePath, *tflag, *tTflag), cmdArgs, *jflag, false)
case "peer":
exitCode = cli.Peer(basePath, authToken(basePath, *tflag, *tTflag), cmdArgs, *jflag)
case "roots":
exitCode = cli.Peers(basePath, authToken(basePath, *tflag, *tTflag), cmdArgs, *jflag, true)
case "controller":
exitCode = cli.Controller(basePath, authToken(basePath, *tflag, *tTflag), cmdArgs, *jflag)
case "set":
exitCode = cli.Set(basePath, authToken(basePath, *tflag, *tTflag), cmdArgs)
case "identity":

@ -98,10 +98,9 @@ func randomUInt() uint {
func TimeMs() int64 { return int64(time.Now().UnixNano()) / int64(1000000) }
// ipNetToKey creates a key that can be used in a map[] from a net.IPNet
func ipNetToKey(ipn *net.IPNet) (k [3]uint64) {
func ipNetToKey(ipn *InetAddress) (k [3]uint64) {
copy(((*[16]byte)(unsafe.Pointer(&k[0])))[:], ipn.IP)
ones, bits := ipn.Mask.Size()
k[2] = (uint64(ones) << 32) | uint64(bits)
k[2] = uint64(ipn.Port)
return
}

@ -64,37 +64,35 @@ func (t *nativeTap) Enabled() bool {
}
// AddIP adds an IP address (with netmask) to this tap
func (t *nativeTap) AddIP(ip *net.IPNet) error {
bits, _ := ip.Mask.Size()
func (t *nativeTap) AddIP(ip *InetAddress) error {
if len(ip.IP) == 16 {
if bits > 128 || bits < 0 {
if ip.Port > 128 || ip.Port < 0 {
return ErrInvalidParameter
}
C.ZT_GoTap_addIp(t.tap, C.int(syscall.AF_INET6), unsafe.Pointer(&ip.IP[0]), C.int(bits))
C.ZT_GoTap_addIp(t.tap, C.int(syscall.AF_INET6), unsafe.Pointer(&ip.IP[0]), C.int(ip.Port))
} else if len(ip.IP) == 4 {
if bits > 32 || bits < 0 {
if ip.Port > 32 || ip.Port < 0 {
return ErrInvalidParameter
}
C.ZT_GoTap_addIp(t.tap, C.int(syscall.AF_INET), unsafe.Pointer(&ip.IP[0]), C.int(bits))
C.ZT_GoTap_addIp(t.tap, C.int(syscall.AF_INET), unsafe.Pointer(&ip.IP[0]), C.int(ip.Port))
}
return ErrInvalidParameter
}
// RemoveIP removes this IP address (with netmask) from this tap
func (t *nativeTap) RemoveIP(ip *net.IPNet) error {
bits, _ := ip.Mask.Size()
func (t *nativeTap) RemoveIP(ip *InetAddress) error {
if len(ip.IP) == 16 {
if bits > 128 || bits < 0 {
if ip.Port > 128 || ip.Port < 0 {
return ErrInvalidParameter
}
C.ZT_GoTap_removeIp(t.tap, C.int(syscall.AF_INET6), unsafe.Pointer(&ip.IP[0]), C.int(bits))
C.ZT_GoTap_removeIp(t.tap, C.int(syscall.AF_INET6), unsafe.Pointer(&ip.IP[0]), C.int(ip.Port))
return nil
}
if len(ip.IP) == 4 {
if bits > 32 || bits < 0 {
if ip.Port > 32 || ip.Port < 0 {
return ErrInvalidParameter
}
C.ZT_GoTap_removeIp(t.tap, C.int(syscall.AF_INET), unsafe.Pointer(&ip.IP[0]), C.int(bits))
C.ZT_GoTap_removeIp(t.tap, C.int(syscall.AF_INET), unsafe.Pointer(&ip.IP[0]), C.int(ip.Port))
return nil
}
return ErrInvalidParameter

@ -72,63 +72,62 @@ func (n *NetworkID) UnmarshalJSON(j []byte) error {
if err != nil {
return err
}
tmp, err := NewNetworkIDFromString(s)
*n = tmp
*n, err = NewNetworkIDFromString(s)
return err
}
// NetworkConfig represents the network's current configuration as distributed by its network controller.
type NetworkConfig struct {
// ID is this network's 64-bit globally unique identifier
ID NetworkID
ID NetworkID `json:"id"`
// MAC is the Ethernet MAC address of this device on this network
MAC MAC
MAC MAC `json:"mac"`
// Name is a short human-readable name set by the controller
Name string
Name string `json:"name"`
// Status is a status code indicating this network's authorization status
Status int
Status int `json:"status"`
// Type is this network's type
Type int
Type int `json:"type"`
// MTU is the Ethernet MTU for this network
MTU int
MTU int `json:"mtu"`
// Bridge is true if this network is allowed to bridge in other devices with different Ethernet addresses
Bridge bool
Bridge bool `json:"bridge"`
// BroadcastEnabled is true if the broadcast (ff:ff:ff:ff:ff:ff) address works (excluding IPv4 ARP which is handled via a special path)
BroadcastEnabled bool
BroadcastEnabled bool `json:"broadcastEnabled"`
// NetconfRevision is the revision number reported by the controller
NetconfRevision uint64
NetconfRevision uint64 `json:"netconfRevision"`
// AssignedAddresses are static IPs assigned by the network controller to this device
AssignedAddresses []net.IPNet
AssignedAddresses []InetAddress `json:"assignedAddresses,omitempty"`
// Routes are static routes assigned by the network controller to this device
Routes []Route
Routes []Route `json:"routes,omitempty"`
}
// NetworkLocalSettings is settings for this network that can be changed locally
type NetworkLocalSettings struct {
// AllowManagedIPs determines whether managed IP assignment is allowed
AllowManagedIPs bool
AllowManagedIPs bool `json:"allowManagedIPs"`
// AllowGlobalIPs determines if managed IPs that overlap with public Internet addresses are allowed
AllowGlobalIPs bool
AllowGlobalIPs bool `json:"allowGlobalIPs"`
// AllowManagedRoutes determines whether managed routes can be set
AllowManagedRoutes bool
AllowManagedRoutes bool `json:"allowManagedRoutes"`
// AllowGlobalRoutes determines if managed routes can overlap with public Internet addresses
AllowGlobalRoutes bool
AllowGlobalRoutes bool `json:"allowGlobalRoutes"`
// AllowDefaultRouteOverride determines if the default (0.0.0.0 or ::0) route on the system can be overridden ("full tunnel" mode)
AllowDefaultRouteOverride bool
AllowDefaultRouteOverride bool `json:"allowDefaultRouteOverride"`
}
// Network is a currently joined network
@ -301,7 +300,7 @@ func (n *Network) updateConfig(nc *NetworkConfig, ls *NetworkLocalSettings) {
// and remove any IPs from the tap that were assigned that are no
// longer wanted. IPs assigned to the tap externally (e.g. by an
// "ifconfig" command) are left alone.
haveAssignedIPs := make(map[[3]uint64]*net.IPNet)
haveAssignedIPs := make(map[[3]uint64]*InetAddress)
wantAssignedIPs := make(map[[3]uint64]bool)
if n.settings.AllowManagedIPs {
for _, ip := range n.config.AssignedAddresses {

@ -416,11 +416,12 @@ func (n *Node) Leave(nwid NetworkID) error {
nw := n.networks[nwid]
delete(n.networks, nwid)
n.networksLock.Unlock()
if nw != nil {
n.infoLog.Printf("leaving network %.16x", nwid)
nw.leaving()
C.ZT_GoNode_leave(n.gn, C.uint64_t(nwid))
}
C.ZT_GoNode_leave(n.gn, C.uint64_t(nwid))
return nil
}
@ -891,7 +892,8 @@ func goVirtualNetworkConfigFunc(gn, _ unsafe.Pointer, nwid C.uint64_t, op C.int,
for i := 0; i < int(ncc.assignedAddressCount); i++ {
a := sockaddrStorageToIPNet(&ncc.assignedAddresses[i])
if a != nil {
nc.AssignedAddresses = append(nc.AssignedAddresses, *a)
_, bits := a.Mask.Size()
nc.AssignedAddresses = append(nc.AssignedAddresses, InetAddress{IP: a.IP, Port: bits})
}
}
for i := 0; i < int(ncc.routeCount); i++ {

@ -33,10 +33,10 @@ type Tap interface {
Enabled() bool
// AddIP assigns an IP address to this tap device
AddIP(ip *net.IPNet) error
AddIP(ip *InetAddress) error
// RemoveIP removes an IP address from this tap
RemoveIP(ip *net.IPNet) error
RemoveIP(ip *InetAddress) error
// IPs returns an array of all IPs currently assigned to this tap including those not assigned by ZeroTier
IPs() ([]net.IPNet, error)