refactor join, fix network add; db retry connect; fix port issue; sqlite default

This commit is contained in:
afeiszli
2021-09-10 15:48:18 -04:00
parent a86047ae85
commit c0490061ee
12 changed files with 183 additions and 184 deletions

View File

@@ -0,0 +1,62 @@
package functions
import (
"github.com/gravitl/netmaker/models"
"net"
)
func getLocalIP(node models.Node) string{
var local string
ifaces, err := net.Interfaces()
if err != nil {
return local
}
_, localrange, err := net.ParseCIDR(node.LocalRange)
if err != nil {
return local
}
found := false
for _, i := range ifaces {
if i.Flags&net.FlagUp == 0 {
continue // interface down
}
if i.Flags&net.FlagLoopback != 0 {
continue // loopback interface
}
addrs, err := i.Addrs()
if err != nil {
return local
}
for _, addr := range addrs {
var ip net.IP
switch v := addr.(type) {
case *net.IPNet:
if !found {
ip = v.IP
local = ip.String()
if node.IsLocal == "yes" {
found = localrange.Contains(ip)
} else {
found = true
}
}
case *net.IPAddr:
if !found {
ip = v.IP
local = ip.String()
if node.IsLocal == "yes" {
found = localrange.Contains(ip)
} else {
found = true
}
}
}
}
}
return local
}