mirror of
https://github.com/gravitl/netmaker.git
synced 2025-09-05 20:54:18 +08:00
NET-447: Removed proxy related fields and code (#2459)
* remove related fields and code * remover metrics collection from server code * fw update struct * add ext client flag to metrics data * simply nat types * rm proxy update from cli
This commit is contained in:
parent
f4a5520f86
commit
645bc4c126
19 changed files with 138 additions and 708 deletions
|
@ -15,9 +15,7 @@ var (
|
|||
endpoint string
|
||||
name string
|
||||
listenPort int
|
||||
proxyListenPort int
|
||||
mtu int
|
||||
proxyEnabled bool
|
||||
isStatic bool
|
||||
isDefault bool
|
||||
)
|
||||
|
@ -42,9 +40,7 @@ var hostUpdateCmd = &cobra.Command{
|
|||
apiHost.EndpointIP = endpoint
|
||||
apiHost.Name = name
|
||||
apiHost.ListenPort = listenPort
|
||||
apiHost.ProxyListenPort = proxyListenPort
|
||||
apiHost.MTU = mtu
|
||||
apiHost.ProxyEnabled = proxyEnabled
|
||||
apiHost.IsStatic = isStatic
|
||||
apiHost.IsDefault = isDefault
|
||||
}
|
||||
|
@ -57,9 +53,7 @@ func init() {
|
|||
hostUpdateCmd.Flags().StringVar(&endpoint, "endpoint", "", "Endpoint of the Host")
|
||||
hostUpdateCmd.Flags().StringVar(&name, "name", "", "Host name")
|
||||
hostUpdateCmd.Flags().IntVar(&listenPort, "listen_port", 0, "Listen port of the host")
|
||||
hostUpdateCmd.Flags().IntVar(&proxyListenPort, "proxy_listen_port", 0, "Proxy listen port of the host")
|
||||
hostUpdateCmd.Flags().IntVar(&mtu, "mtu", 0, "Host MTU size")
|
||||
hostUpdateCmd.Flags().BoolVar(&proxyEnabled, "proxy", false, "Enable proxy ?")
|
||||
hostUpdateCmd.Flags().BoolVar(&isStatic, "static", false, "Make Host Static ?")
|
||||
hostUpdateCmd.Flags().BoolVar(&isDefault, "default", false, "Make Host Default ?")
|
||||
rootCmd.AddCommand(hostUpdateCmd)
|
||||
|
|
116
config/config.go
116
config/config.go
|
@ -32,68 +32,60 @@ type EnvironmentConfig struct {
|
|||
|
||||
// ServerConfig - server conf struct
|
||||
type ServerConfig struct {
|
||||
CoreDNSAddr string `yaml:"corednsaddr"`
|
||||
APIConnString string `yaml:"apiconn"`
|
||||
APIHost string `yaml:"apihost"`
|
||||
APIPort string `yaml:"apiport"`
|
||||
Broker string `yam:"broker"`
|
||||
ServerBrokerEndpoint string `yaml:"serverbrokerendpoint"`
|
||||
BrokerType string `yaml:"brokertype"`
|
||||
EmqxRestEndpoint string `yaml:"emqxrestendpoint"`
|
||||
NetclientAutoUpdate string `yaml:"netclientautoupdate"`
|
||||
NetclientEndpointDetection string `yaml:"netclientendpointdetection"`
|
||||
MasterKey string `yaml:"masterkey"`
|
||||
DNSKey string `yaml:"dnskey"`
|
||||
AllowedOrigin string `yaml:"allowedorigin"`
|
||||
NodeID string `yaml:"nodeid"`
|
||||
RestBackend string `yaml:"restbackend"`
|
||||
MessageQueueBackend string `yaml:"messagequeuebackend"`
|
||||
DNSMode string `yaml:"dnsmode"`
|
||||
DisableRemoteIPCheck string `yaml:"disableremoteipcheck"`
|
||||
Version string `yaml:"version"`
|
||||
SQLConn string `yaml:"sqlconn"`
|
||||
Platform string `yaml:"platform"`
|
||||
Database string `yaml:"database"`
|
||||
Verbosity int32 `yaml:"verbosity"`
|
||||
AuthProvider string `yaml:"authprovider"`
|
||||
OIDCIssuer string `yaml:"oidcissuer"`
|
||||
ClientID string `yaml:"clientid"`
|
||||
ClientSecret string `yaml:"clientsecret"`
|
||||
FrontendURL string `yaml:"frontendurl"`
|
||||
DisplayKeys string `yaml:"displaykeys"`
|
||||
AzureTenant string `yaml:"azuretenant"`
|
||||
Telemetry string `yaml:"telemetry"`
|
||||
HostNetwork string `yaml:"hostnetwork"`
|
||||
Server string `yaml:"server"`
|
||||
PublicIPService string `yaml:"publicipservice"`
|
||||
MQPassword string `yaml:"mqpassword"`
|
||||
MQUserName string `yaml:"mqusername"`
|
||||
MetricsExporter string `yaml:"metrics_exporter"`
|
||||
BasicAuth string `yaml:"basic_auth"`
|
||||
LicenseValue string `yaml:"license_value"`
|
||||
NetmakerTenantID string `yaml:"netmaker_tenant_id"`
|
||||
IsEE string `yaml:"is_ee"`
|
||||
StunPort int `yaml:"stun_port"`
|
||||
StunList string `yaml:"stun_list"`
|
||||
Proxy string `yaml:"proxy"`
|
||||
DefaultProxyMode ProxyMode `yaml:"defaultproxymode"`
|
||||
TurnServer string `yaml:"turn_server"`
|
||||
TurnApiServer string `yaml:"turn_api_server"`
|
||||
TurnPort int `yaml:"turn_port"`
|
||||
TurnUserName string `yaml:"turn_username"`
|
||||
TurnPassword string `yaml:"turn_password"`
|
||||
UseTurn bool `yaml:"use_turn"`
|
||||
UsersLimit int `yaml:"user_limit"`
|
||||
ClientsLimit int `yaml:"client_limit"`
|
||||
NetworksLimit int `yaml:"network_limit"`
|
||||
HostsLimit int `yaml:"host_limit"`
|
||||
DeployedByOperator bool `yaml:"deployed_by_operator"`
|
||||
}
|
||||
|
||||
// ProxyMode - default proxy mode for server
|
||||
type ProxyMode struct {
|
||||
Set bool
|
||||
Value bool
|
||||
CoreDNSAddr string `yaml:"corednsaddr"`
|
||||
APIConnString string `yaml:"apiconn"`
|
||||
APIHost string `yaml:"apihost"`
|
||||
APIPort string `yaml:"apiport"`
|
||||
Broker string `yam:"broker"`
|
||||
ServerBrokerEndpoint string `yaml:"serverbrokerendpoint"`
|
||||
BrokerType string `yaml:"brokertype"`
|
||||
EmqxRestEndpoint string `yaml:"emqxrestendpoint"`
|
||||
NetclientAutoUpdate string `yaml:"netclientautoupdate"`
|
||||
NetclientEndpointDetection string `yaml:"netclientendpointdetection"`
|
||||
MasterKey string `yaml:"masterkey"`
|
||||
DNSKey string `yaml:"dnskey"`
|
||||
AllowedOrigin string `yaml:"allowedorigin"`
|
||||
NodeID string `yaml:"nodeid"`
|
||||
RestBackend string `yaml:"restbackend"`
|
||||
MessageQueueBackend string `yaml:"messagequeuebackend"`
|
||||
DNSMode string `yaml:"dnsmode"`
|
||||
DisableRemoteIPCheck string `yaml:"disableremoteipcheck"`
|
||||
Version string `yaml:"version"`
|
||||
SQLConn string `yaml:"sqlconn"`
|
||||
Platform string `yaml:"platform"`
|
||||
Database string `yaml:"database"`
|
||||
Verbosity int32 `yaml:"verbosity"`
|
||||
AuthProvider string `yaml:"authprovider"`
|
||||
OIDCIssuer string `yaml:"oidcissuer"`
|
||||
ClientID string `yaml:"clientid"`
|
||||
ClientSecret string `yaml:"clientsecret"`
|
||||
FrontendURL string `yaml:"frontendurl"`
|
||||
DisplayKeys string `yaml:"displaykeys"`
|
||||
AzureTenant string `yaml:"azuretenant"`
|
||||
Telemetry string `yaml:"telemetry"`
|
||||
HostNetwork string `yaml:"hostnetwork"`
|
||||
Server string `yaml:"server"`
|
||||
PublicIPService string `yaml:"publicipservice"`
|
||||
MQPassword string `yaml:"mqpassword"`
|
||||
MQUserName string `yaml:"mqusername"`
|
||||
MetricsExporter string `yaml:"metrics_exporter"`
|
||||
BasicAuth string `yaml:"basic_auth"`
|
||||
LicenseValue string `yaml:"license_value"`
|
||||
NetmakerTenantID string `yaml:"netmaker_tenant_id"`
|
||||
IsEE string `yaml:"is_ee"`
|
||||
StunPort int `yaml:"stun_port"`
|
||||
StunList string `yaml:"stun_list"`
|
||||
TurnServer string `yaml:"turn_server"`
|
||||
TurnApiServer string `yaml:"turn_api_server"`
|
||||
TurnPort int `yaml:"turn_port"`
|
||||
TurnUserName string `yaml:"turn_username"`
|
||||
TurnPassword string `yaml:"turn_password"`
|
||||
UseTurn bool `yaml:"use_turn"`
|
||||
UsersLimit int `yaml:"user_limit"`
|
||||
ClientsLimit int `yaml:"client_limit"`
|
||||
NetworksLimit int `yaml:"network_limit"`
|
||||
HostsLimit int `yaml:"host_limit"`
|
||||
DeployedByOperator bool `yaml:"deployed_by_operator"`
|
||||
}
|
||||
|
||||
// SQLConfig - Generic SQL Config
|
||||
|
|
|
@ -348,11 +348,8 @@ func createExtClient(w http.ResponseWriter, r *http.Request) {
|
|||
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "internal"))
|
||||
return
|
||||
}
|
||||
listenPort := host.ListenPort
|
||||
if host.ProxyEnabled {
|
||||
listenPort = host.ProxyListenPort
|
||||
}
|
||||
extclient.IngressGatewayEndpoint = host.EndpointIP.String() + ":" + strconv.FormatInt(int64(listenPort), 10)
|
||||
listenPort := logic.GetPeerListenPort(host)
|
||||
extclient.IngressGatewayEndpoint = fmt.Sprintf("%s:%d", host.EndpointIP.String(), listenPort)
|
||||
extclient.Enabled = true
|
||||
parentNetwork, err := logic.GetNetwork(networkName)
|
||||
if err == nil { // check if parent network default ACL is enabled (yes) or not (no)
|
||||
|
|
|
@ -30,16 +30,14 @@ func TestMain(m *testing.M) {
|
|||
|
||||
func TestCheckPorts(t *testing.T) {
|
||||
h := models.Host{
|
||||
ID: uuid.New(),
|
||||
EndpointIP: net.ParseIP("192.168.1.1"),
|
||||
ListenPort: 51821,
|
||||
ProxyListenPort: maxPort,
|
||||
ID: uuid.New(),
|
||||
EndpointIP: net.ParseIP("192.168.1.1"),
|
||||
ListenPort: 51821,
|
||||
}
|
||||
testHost := models.Host{
|
||||
ID: uuid.New(),
|
||||
EndpointIP: net.ParseIP("192.168.1.1"),
|
||||
ListenPort: 51830,
|
||||
ProxyListenPort: 51730,
|
||||
ID: uuid.New(),
|
||||
EndpointIP: net.ParseIP("192.168.1.1"),
|
||||
ListenPort: 51830,
|
||||
}
|
||||
//not sure why this initialization is required but without it
|
||||
// RemoveHost returns database is closed
|
||||
|
@ -49,45 +47,17 @@ func TestCheckPorts(t *testing.T) {
|
|||
t.Run("no change", func(t *testing.T) {
|
||||
is := is.New(t)
|
||||
CheckHostPorts(&testHost)
|
||||
t.Log(testHost.ListenPort, testHost.ProxyListenPort)
|
||||
t.Log(h.ListenPort, h.ProxyListenPort)
|
||||
t.Log(testHost.ListenPort)
|
||||
t.Log(h.ListenPort)
|
||||
is.Equal(testHost.ListenPort, 51830)
|
||||
is.Equal(testHost.ProxyListenPort, 51730)
|
||||
})
|
||||
t.Run("same listen port", func(t *testing.T) {
|
||||
is := is.New(t)
|
||||
testHost.ListenPort = 51821
|
||||
CheckHostPorts(&testHost)
|
||||
t.Log(testHost.ListenPort, testHost.ProxyListenPort)
|
||||
t.Log(h.ListenPort, h.ProxyListenPort)
|
||||
t.Log(testHost.ListenPort)
|
||||
t.Log(h.ListenPort)
|
||||
is.Equal(testHost.ListenPort, 51822)
|
||||
is.Equal(testHost.ProxyListenPort, 51730)
|
||||
})
|
||||
t.Run("same proxy port", func(t *testing.T) {
|
||||
is := is.New(t)
|
||||
testHost.ProxyListenPort = 65535
|
||||
CheckHostPorts(&testHost)
|
||||
t.Log(testHost.ListenPort, testHost.ProxyListenPort)
|
||||
t.Log(h.ListenPort, h.ProxyListenPort)
|
||||
is.Equal(testHost.ListenPort, 51822)
|
||||
is.Equal(testHost.ProxyListenPort, minPort)
|
||||
})
|
||||
t.Run("listenport equals proxy port", func(t *testing.T) {
|
||||
is := is.New(t)
|
||||
testHost.ListenPort = maxPort
|
||||
CheckHostPorts(&testHost)
|
||||
t.Log(testHost.ListenPort, testHost.ProxyListenPort)
|
||||
t.Log(h.ListenPort, h.ProxyListenPort)
|
||||
is.Equal(testHost.ListenPort, minPort)
|
||||
is.Equal(testHost.ProxyListenPort, minPort+1)
|
||||
})
|
||||
t.Run("proxyport equals listenport", func(t *testing.T) {
|
||||
is := is.New(t)
|
||||
testHost.ProxyListenPort = 51821
|
||||
CheckHostPorts(&testHost)
|
||||
t.Log(testHost.ListenPort, testHost.ProxyListenPort)
|
||||
t.Log(h.ListenPort, h.ProxyListenPort)
|
||||
is.Equal(testHost.ListenPort, minPort)
|
||||
is.Equal(testHost.ProxyListenPort, 51822)
|
||||
})
|
||||
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"sort"
|
||||
"strconv"
|
||||
|
@ -184,15 +183,6 @@ func CreateHost(h *models.Host) error {
|
|||
}
|
||||
h.HostPass = string(hash)
|
||||
h.AutoUpdate = servercfg.AutoUpdateEnabled()
|
||||
// if another server has already updated proxyenabled, leave it alone
|
||||
if !h.ProxyEnabledSet {
|
||||
log.Println("checking default proxy", servercfg.GetServerConfig().DefaultProxyMode)
|
||||
if servercfg.GetServerConfig().DefaultProxyMode.Set {
|
||||
h.ProxyEnabledSet = true
|
||||
h.ProxyEnabled = servercfg.GetServerConfig().DefaultProxyMode.Value
|
||||
log.Println("set proxy enabled to ", h.ProxyEnabled)
|
||||
}
|
||||
}
|
||||
checkForZombieHosts(h)
|
||||
return UpsertHost(h)
|
||||
}
|
||||
|
@ -228,11 +218,6 @@ func UpdateHost(newHost, currentHost *models.Host) {
|
|||
newHost.ListenPort = currentHost.ListenPort
|
||||
}
|
||||
|
||||
if newHost.ProxyListenPort == 0 {
|
||||
newHost.ProxyListenPort = currentHost.ProxyListenPort
|
||||
}
|
||||
newHost.PublicListenPort = currentHost.PublicListenPort
|
||||
|
||||
}
|
||||
|
||||
// UpdateHostFromClient - used for updating host on server with update recieved from client
|
||||
|
@ -250,18 +235,6 @@ func UpdateHostFromClient(newHost, currHost *models.Host) (sendPeerUpdate bool)
|
|||
currHost.WgPublicListenPort = newHost.WgPublicListenPort
|
||||
sendPeerUpdate = true
|
||||
}
|
||||
if newHost.ProxyListenPort != 0 && currHost.ProxyListenPort != newHost.ProxyListenPort {
|
||||
currHost.ProxyListenPort = newHost.ProxyListenPort
|
||||
sendPeerUpdate = true
|
||||
}
|
||||
if newHost.PublicListenPort != 0 && currHost.PublicListenPort != newHost.PublicListenPort {
|
||||
currHost.PublicListenPort = newHost.PublicListenPort
|
||||
sendPeerUpdate = true
|
||||
}
|
||||
if currHost.ProxyEnabled != newHost.ProxyEnabled {
|
||||
currHost.ProxyEnabled = newHost.ProxyEnabled
|
||||
sendPeerUpdate = true
|
||||
}
|
||||
if currHost.EndpointIP.String() != newHost.EndpointIP.String() {
|
||||
currHost.EndpointIP = newHost.EndpointIP
|
||||
sendPeerUpdate = true
|
||||
|
@ -523,7 +496,6 @@ func CheckHostPorts(h *models.Host) {
|
|||
continue
|
||||
}
|
||||
portsInUse[host.ListenPort] = true
|
||||
portsInUse[host.ProxyListenPort] = true
|
||||
}
|
||||
// iterate until port is not found or max iteration is reached
|
||||
for i := 0; portsInUse[h.ListenPort] && i < maxPort-minPort+1; i++ {
|
||||
|
@ -532,14 +504,7 @@ func CheckHostPorts(h *models.Host) {
|
|||
h.ListenPort = minPort
|
||||
}
|
||||
}
|
||||
// allocate h.ListenPort so it is unavailable to h.ProxyListenPort
|
||||
portsInUse[h.ListenPort] = true
|
||||
for i := 0; portsInUse[h.ProxyListenPort] && i < maxPort-minPort+1; i++ {
|
||||
h.ProxyListenPort++
|
||||
if h.ProxyListenPort > maxPort {
|
||||
h.ProxyListenPort = minPort
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// HostExists - checks if given host already exists
|
||||
|
|
|
@ -1,90 +0,0 @@
|
|||
package metrics
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/gravitl/netmaker/logger"
|
||||
proxy_metrics "github.com/gravitl/netmaker/metrics"
|
||||
"github.com/gravitl/netmaker/models"
|
||||
"golang.zx2c4.com/wireguard/wgctrl"
|
||||
)
|
||||
|
||||
// Collect - collects metrics
|
||||
func Collect(iface, server, network string, peerMap models.PeerMap, proxy bool) (*models.Metrics, error) {
|
||||
var metrics models.Metrics
|
||||
metrics.Connectivity = make(map[string]models.Metric)
|
||||
var wgclient, err = wgctrl.New()
|
||||
if err != nil {
|
||||
fillUnconnectedData(&metrics, peerMap)
|
||||
return &metrics, err
|
||||
}
|
||||
defer wgclient.Close()
|
||||
device, err := wgclient.Device(iface)
|
||||
if err != nil {
|
||||
fillUnconnectedData(&metrics, peerMap)
|
||||
return &metrics, err
|
||||
}
|
||||
// TODO handle freebsd??
|
||||
for i := range device.Peers {
|
||||
currPeer := device.Peers[i]
|
||||
if _, ok := peerMap[currPeer.PublicKey.String()]; !ok {
|
||||
continue
|
||||
}
|
||||
id := peerMap[currPeer.PublicKey.String()].ID
|
||||
address := peerMap[currPeer.PublicKey.String()].Address
|
||||
if id == "" || address == "" {
|
||||
logger.Log(0, "attempted to parse metrics for invalid peer from server", id, address)
|
||||
continue
|
||||
}
|
||||
proxyMetrics := proxy_metrics.GetMetric(server, currPeer.PublicKey.String())
|
||||
var newMetric = models.Metric{
|
||||
NodeName: peerMap[currPeer.PublicKey.String()].Name,
|
||||
}
|
||||
logger.Log(2, "collecting metrics for peer", address)
|
||||
newMetric.TotalReceived = int64(proxyMetrics.TrafficRecieved)
|
||||
newMetric.TotalSent = int64(proxyMetrics.TrafficSent)
|
||||
newMetric.Latency = int64(proxyMetrics.LastRecordedLatency)
|
||||
newMetric.Connected = proxyMetrics.NodeConnectionStatus[id]
|
||||
newMetric.CollectedByProxy = proxy
|
||||
if newMetric.Connected {
|
||||
newMetric.Uptime = 1
|
||||
}
|
||||
// check device peer to see if WG is working if ping failed
|
||||
if !newMetric.Connected {
|
||||
if currPeer.ReceiveBytes > 0 &&
|
||||
currPeer.TransmitBytes > 0 &&
|
||||
time.Now().Before(currPeer.LastHandshakeTime.Add(time.Minute<<1)) {
|
||||
newMetric.Connected = true
|
||||
newMetric.Uptime = 1
|
||||
}
|
||||
}
|
||||
newMetric.TotalTime = 1
|
||||
metrics.Connectivity[id] = newMetric
|
||||
if len(proxyMetrics.NodeConnectionStatus) == 1 {
|
||||
proxy_metrics.ResetMetricsForPeer(server, currPeer.PublicKey.String())
|
||||
} else {
|
||||
proxy_metrics.ResetMetricForNode(server, currPeer.PublicKey.String(), id)
|
||||
}
|
||||
}
|
||||
|
||||
fillUnconnectedData(&metrics, peerMap)
|
||||
return &metrics, nil
|
||||
}
|
||||
|
||||
// == used to fill zero value data for non connected peers ==
|
||||
func fillUnconnectedData(metrics *models.Metrics, peerMap models.PeerMap) {
|
||||
for r := range peerMap {
|
||||
id := peerMap[r].ID
|
||||
if !metrics.Connectivity[id].Connected {
|
||||
newMetric := models.Metric{
|
||||
NodeName: peerMap[r].Name,
|
||||
Uptime: 0,
|
||||
TotalTime: 1,
|
||||
Connected: false,
|
||||
Latency: 999,
|
||||
PercentUp: 0,
|
||||
}
|
||||
metrics.Connectivity[id] = newMetric
|
||||
}
|
||||
}
|
||||
}
|
225
logic/peers.go
225
logic/peers.go
|
@ -15,69 +15,9 @@ import (
|
|||
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
||||
)
|
||||
|
||||
// GetProxyUpdateForHost - gets the proxy update for host
|
||||
func GetProxyUpdateForHost(host *models.Host) (models.ProxyManagerPayload, error) {
|
||||
proxyPayload := models.ProxyManagerPayload{
|
||||
Action: models.ProxyUpdate,
|
||||
}
|
||||
peerConfMap := make(map[string]models.PeerConf)
|
||||
var ingressStatus bool
|
||||
for _, nodeID := range host.Nodes {
|
||||
|
||||
node, err := GetNodeByID(nodeID)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if !node.Connected || node.PendingDelete || node.Action == models.NODE_DELETE {
|
||||
continue
|
||||
}
|
||||
currentPeers, err := GetNetworkNodes(node.Network)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
for _, peer := range currentPeers {
|
||||
if peer.ID == node.ID {
|
||||
//skip yourself
|
||||
continue
|
||||
}
|
||||
if !peer.Connected || peer.PendingDelete || peer.Action == models.NODE_DELETE {
|
||||
continue
|
||||
}
|
||||
peerHost, err := GetHost(peer.HostID.String())
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
var currPeerConf models.PeerConf
|
||||
var found bool
|
||||
if currPeerConf, found = peerConfMap[peerHost.PublicKey.String()]; !found {
|
||||
currPeerConf = models.PeerConf{
|
||||
Proxy: peerHost.ProxyEnabled,
|
||||
PublicListenPort: int32(GetPeerListenPort(peerHost)),
|
||||
ProxyListenPort: GetProxyListenPort(peerHost),
|
||||
NatType: peerHost.NatType,
|
||||
}
|
||||
}
|
||||
|
||||
peerConfMap[peerHost.PublicKey.String()] = currPeerConf
|
||||
}
|
||||
if node.IsIngressGateway {
|
||||
ingressStatus = true
|
||||
_, peerConfMap, err = getExtPeersForProxy(&node, peerConfMap)
|
||||
if err == nil {
|
||||
|
||||
} else if !database.IsEmptyRecord(err) {
|
||||
logger.Log(1, "error retrieving external clients:", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
proxyPayload.IsIngress = ingressStatus
|
||||
proxyPayload.PeerMap = peerConfMap
|
||||
return proxyPayload, nil
|
||||
}
|
||||
|
||||
// GetPeerUpdateForHost - gets the consolidated peer update for the host from all networks
|
||||
func GetPeerUpdateForHost(network string, host *models.Host, allNodes []models.Node, deletedNode *models.Node, deletedClients []models.ExtClient) (models.HostPeerUpdate, error) {
|
||||
func GetPeerUpdateForHost(network string, host *models.Host, allNodes []models.Node,
|
||||
deletedNode *models.Node, deletedClients []models.ExtClient) (models.HostPeerUpdate, error) {
|
||||
if host == nil {
|
||||
return models.HostPeerUpdate{}, errors.New("host is nil")
|
||||
}
|
||||
|
@ -87,13 +27,14 @@ func GetPeerUpdateForHost(network string, host *models.Host, allNodes []models.N
|
|||
hostPeerUpdate := models.HostPeerUpdate{
|
||||
Host: *host,
|
||||
Server: servercfg.GetServer(),
|
||||
HostPeerIDs: make(models.HostPeerMap, 0),
|
||||
ServerVersion: servercfg.GetVersion(),
|
||||
ServerAddrs: []models.ServerAddr{},
|
||||
IngressInfo: models.IngressInfo{
|
||||
ExtPeers: make(map[string]models.ExtClientInfo),
|
||||
FwUpdate: models.FwUpdate{
|
||||
IngressInfo: models.IngressInfo{
|
||||
ExtPeers: make(map[string]models.ExtClientInfo),
|
||||
},
|
||||
EgressInfo: make(map[string]models.EgressInfo),
|
||||
},
|
||||
EgressInfo: make(map[string]models.EgressInfo),
|
||||
PeerIDs: make(models.PeerMap, 0),
|
||||
Peers: []wgtypes.PeerConfig{},
|
||||
NodePeers: []wgtypes.PeerConfig{},
|
||||
|
@ -145,7 +86,7 @@ func GetPeerUpdateForHost(network string, host *models.Host, allNodes []models.N
|
|||
}
|
||||
relayPeer.Endpoint = &net.UDPAddr{
|
||||
IP: relayHost.EndpointIP,
|
||||
Port: getPeerWgListenPort(relayHost),
|
||||
Port: GetPeerListenPort(relayHost),
|
||||
}
|
||||
|
||||
if uselocal {
|
||||
|
@ -216,7 +157,7 @@ func GetPeerUpdateForHost(network string, host *models.Host, allNodes []models.N
|
|||
}
|
||||
}
|
||||
if node.IsIngressGateway && peer.IsEgressGateway {
|
||||
hostPeerUpdate.IngressInfo.EgressRanges = append(hostPeerUpdate.IngressInfo.EgressRanges,
|
||||
hostPeerUpdate.FwUpdate.IngressInfo.EgressRanges = append(hostPeerUpdate.FwUpdate.IngressInfo.EgressRanges,
|
||||
peer.EgressGatewayRanges...)
|
||||
}
|
||||
nodePeerMap[peerHost.PublicKey.String()] = models.PeerRouteInfo{
|
||||
|
@ -231,7 +172,7 @@ func GetPeerUpdateForHost(network string, host *models.Host, allNodes []models.N
|
|||
}
|
||||
if (node.IsRelayed && node.RelayedBy != peer.ID.String()) || (peer.IsRelayed && peer.RelayedBy != node.ID.String()) {
|
||||
// if node is relayed and peer is not the relay, set remove to true
|
||||
if _, ok := hostPeerUpdate.HostPeerIDs[peerHost.PublicKey.String()]; ok {
|
||||
if _, ok := peerIndexMap[peerHost.PublicKey.String()]; ok {
|
||||
continue
|
||||
}
|
||||
peerConfig.Remove = true
|
||||
|
@ -255,7 +196,7 @@ func GetPeerUpdateForHost(network string, host *models.Host, allNodes []models.N
|
|||
}
|
||||
peerConfig.Endpoint = &net.UDPAddr{
|
||||
IP: peerHost.EndpointIP,
|
||||
Port: getPeerWgListenPort(peerHost),
|
||||
Port: GetPeerListenPort(peerHost),
|
||||
}
|
||||
|
||||
if uselocal {
|
||||
|
@ -271,22 +212,14 @@ func GetPeerUpdateForHost(network string, host *models.Host, allNodes []models.N
|
|||
peerConfig.AllowedIPs = allowedips // only append allowed IPs if valid connection
|
||||
}
|
||||
|
||||
peerProxyPort := GetProxyListenPort(peerHost)
|
||||
peerPort := GetPeerListenPort(peerHost)
|
||||
var nodePeer wgtypes.PeerConfig
|
||||
if _, ok := hostPeerUpdate.HostPeerIDs[peerHost.PublicKey.String()]; !ok {
|
||||
hostPeerUpdate.HostPeerIDs[peerHost.PublicKey.String()] = make(map[string]models.IDandAddr)
|
||||
if _, ok := peerIndexMap[peerHost.PublicKey.String()]; !ok {
|
||||
hostPeerUpdate.Peers = append(hostPeerUpdate.Peers, peerConfig)
|
||||
peerIndexMap[peerHost.PublicKey.String()] = len(hostPeerUpdate.Peers) - 1
|
||||
hostPeerUpdate.HostPeerIDs[peerHost.PublicKey.String()][peer.ID.String()] = models.IDandAddr{
|
||||
ID: peer.ID.String(),
|
||||
Address: peer.PrimaryAddress(),
|
||||
Name: peerHost.Name,
|
||||
Network: peer.Network,
|
||||
ProxyListenPort: peerProxyPort,
|
||||
}
|
||||
hostPeerUpdate.HostNetworkInfo[peerHost.PublicKey.String()] = models.HostNetworkInfo{
|
||||
Interfaces: peerHost.Interfaces,
|
||||
ProxyListenPort: peerProxyPort,
|
||||
Interfaces: peerHost.Interfaces,
|
||||
ListenPort: peerPort,
|
||||
}
|
||||
nodePeer = peerConfig
|
||||
} else {
|
||||
|
@ -294,27 +227,20 @@ func GetPeerUpdateForHost(network string, host *models.Host, allNodes []models.N
|
|||
peerAllowedIPs = append(peerAllowedIPs, peerConfig.AllowedIPs...)
|
||||
hostPeerUpdate.Peers[peerIndexMap[peerHost.PublicKey.String()]].AllowedIPs = peerAllowedIPs
|
||||
hostPeerUpdate.Peers[peerIndexMap[peerHost.PublicKey.String()]].Remove = false
|
||||
hostPeerUpdate.HostPeerIDs[peerHost.PublicKey.String()][peer.ID.String()] = models.IDandAddr{
|
||||
ID: peer.ID.String(),
|
||||
Address: peer.PrimaryAddress(),
|
||||
Name: peerHost.Name,
|
||||
Network: peer.Network,
|
||||
ProxyListenPort: GetProxyListenPort(peerHost),
|
||||
}
|
||||
hostPeerUpdate.HostNetworkInfo[peerHost.PublicKey.String()] = models.HostNetworkInfo{
|
||||
Interfaces: peerHost.Interfaces,
|
||||
ProxyListenPort: peerProxyPort,
|
||||
Interfaces: peerHost.Interfaces,
|
||||
ListenPort: peerPort,
|
||||
}
|
||||
nodePeer = hostPeerUpdate.Peers[peerIndexMap[peerHost.PublicKey.String()]]
|
||||
}
|
||||
|
||||
if node.Network == network { // add to peers map for metrics
|
||||
hostPeerUpdate.PeerIDs[peerHost.PublicKey.String()] = models.IDandAddr{
|
||||
ID: peer.ID.String(),
|
||||
Address: peer.PrimaryAddress(),
|
||||
Name: peerHost.Name,
|
||||
Network: peer.Network,
|
||||
ProxyListenPort: peerHost.ProxyListenPort,
|
||||
ID: peer.ID.String(),
|
||||
Address: peer.PrimaryAddress(),
|
||||
Name: peerHost.Name,
|
||||
Network: peer.Network,
|
||||
ListenPort: GetPeerListenPort(peerHost),
|
||||
}
|
||||
hostPeerUpdate.NodePeers = append(hostPeerUpdate.NodePeers, nodePeer)
|
||||
}
|
||||
|
@ -322,6 +248,7 @@ func GetPeerUpdateForHost(network string, host *models.Host, allNodes []models.N
|
|||
var extPeers []wgtypes.PeerConfig
|
||||
var extPeerIDAndAddrs []models.IDandAddr
|
||||
if node.IsIngressGateway {
|
||||
hostPeerUpdate.FwUpdate.IsIngressGw = true
|
||||
extPeers, extPeerIDAndAddrs, err = getExtPeers(&node, &node)
|
||||
if err == nil {
|
||||
for _, extPeerIdAndAddr := range extPeerIDAndAddrs {
|
||||
|
@ -339,15 +266,8 @@ func GetPeerUpdateForHost(network string, host *models.Host, allNodes []models.N
|
|||
hostPeerUpdate.Peers = append(hostPeerUpdate.Peers, extPeers...)
|
||||
for _, extPeerIdAndAddr := range extPeerIDAndAddrs {
|
||||
extPeerIdAndAddr := extPeerIdAndAddr
|
||||
hostPeerUpdate.HostPeerIDs[extPeerIdAndAddr.ID] = make(map[string]models.IDandAddr)
|
||||
hostPeerUpdate.HostPeerIDs[extPeerIdAndAddr.ID][extPeerIdAndAddr.ID] = models.IDandAddr{
|
||||
ID: extPeerIdAndAddr.ID,
|
||||
Address: extPeerIdAndAddr.Address,
|
||||
Name: extPeerIdAndAddr.Name,
|
||||
Network: node.Network,
|
||||
}
|
||||
|
||||
hostPeerUpdate.IngressInfo.ExtPeers[extPeerIdAndAddr.ID] = models.ExtClientInfo{
|
||||
hostPeerUpdate.FwUpdate.IngressInfo.ExtPeers[extPeerIdAndAddr.ID] = models.ExtClientInfo{
|
||||
Masquerade: true,
|
||||
IngGwAddr: net.IPNet{
|
||||
IP: net.ParseIP(node.PrimaryAddress()),
|
||||
|
@ -371,7 +291,8 @@ func GetPeerUpdateForHost(network string, host *models.Host, allNodes []models.N
|
|||
}
|
||||
}
|
||||
if node.IsEgressGateway {
|
||||
hostPeerUpdate.EgressInfo[node.ID.String()] = models.EgressInfo{
|
||||
hostPeerUpdate.FwUpdate.IsEgressGw = true
|
||||
hostPeerUpdate.FwUpdate.EgressInfo[node.ID.String()] = models.EgressInfo{
|
||||
EgressID: node.ID.String(),
|
||||
Network: node.PrimaryNetworkRange(),
|
||||
EgressGwAddr: net.IPNet{
|
||||
|
@ -429,40 +350,15 @@ func GetPeerUpdateForHost(network string, host *models.Host, allNodes []models.N
|
|||
return hostPeerUpdate, nil
|
||||
}
|
||||
|
||||
// getPeerWgListenPort - fetches the wg listen port for the host
|
||||
func getPeerWgListenPort(host *models.Host) int {
|
||||
peerPort := host.ListenPort
|
||||
if host.WgPublicListenPort != 0 {
|
||||
peerPort = host.WgPublicListenPort
|
||||
}
|
||||
return peerPort
|
||||
}
|
||||
|
||||
// GetPeerListenPort - given a host, retrieve it's appropriate listening port
|
||||
func GetPeerListenPort(host *models.Host) int {
|
||||
peerPort := host.ListenPort
|
||||
if host.WgPublicListenPort != 0 {
|
||||
peerPort = host.WgPublicListenPort
|
||||
}
|
||||
if host.ProxyEnabled {
|
||||
if host.PublicListenPort != 0 {
|
||||
peerPort = host.PublicListenPort
|
||||
} else if host.ProxyListenPort != 0 {
|
||||
peerPort = host.ProxyListenPort
|
||||
}
|
||||
}
|
||||
return peerPort
|
||||
}
|
||||
|
||||
// GetProxyListenPort - fetches the proxy listen port
|
||||
func GetProxyListenPort(host *models.Host) int {
|
||||
proxyPort := host.ProxyListenPort
|
||||
if host.PublicListenPort != 0 {
|
||||
proxyPort = host.PublicListenPort
|
||||
}
|
||||
return proxyPort
|
||||
}
|
||||
|
||||
func getExtPeers(node, peer *models.Node) ([]wgtypes.PeerConfig, []models.IDandAddr, error) {
|
||||
var peers []wgtypes.PeerConfig
|
||||
var idsAndAddr []models.IDandAddr
|
||||
|
@ -523,77 +419,16 @@ func getExtPeers(node, peer *models.Node) ([]wgtypes.PeerConfig, []models.IDandA
|
|||
}
|
||||
peers = append(peers, peer)
|
||||
idsAndAddr = append(idsAndAddr, models.IDandAddr{
|
||||
ID: peer.PublicKey.String(),
|
||||
Name: extPeer.ClientID,
|
||||
Address: primaryAddr,
|
||||
ID: peer.PublicKey.String(),
|
||||
Name: extPeer.ClientID,
|
||||
Address: primaryAddr,
|
||||
IsExtClient: true,
|
||||
})
|
||||
}
|
||||
return peers, idsAndAddr, nil
|
||||
|
||||
}
|
||||
|
||||
func getExtPeersForProxy(node *models.Node, proxyPeerConf map[string]models.PeerConf) ([]wgtypes.PeerConfig, map[string]models.PeerConf, error) {
|
||||
var peers []wgtypes.PeerConfig
|
||||
host, err := GetHost(node.HostID.String())
|
||||
if err != nil {
|
||||
logger.Log(0, "error retrieving host for node", node.ID.String(), err.Error())
|
||||
}
|
||||
|
||||
extPeers, err := GetNetworkExtClients(node.Network)
|
||||
if err != nil {
|
||||
return peers, proxyPeerConf, err
|
||||
}
|
||||
for _, extPeer := range extPeers {
|
||||
pubkey, err := wgtypes.ParseKey(extPeer.PublicKey)
|
||||
if err != nil {
|
||||
logger.Log(1, "error parsing ext pub key:", err.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
if host.PublicKey.String() == extPeer.PublicKey ||
|
||||
extPeer.IngressGatewayID != node.ID.String() || !extPeer.Enabled {
|
||||
continue
|
||||
}
|
||||
|
||||
var allowedips []net.IPNet
|
||||
var peer wgtypes.PeerConfig
|
||||
if extPeer.Address != "" {
|
||||
var peeraddr = net.IPNet{
|
||||
IP: net.ParseIP(extPeer.Address),
|
||||
Mask: net.CIDRMask(32, 32),
|
||||
}
|
||||
if peeraddr.IP != nil && peeraddr.Mask != nil {
|
||||
allowedips = append(allowedips, peeraddr)
|
||||
}
|
||||
}
|
||||
|
||||
if extPeer.Address6 != "" {
|
||||
var addr6 = net.IPNet{
|
||||
IP: net.ParseIP(extPeer.Address6),
|
||||
Mask: net.CIDRMask(128, 128),
|
||||
}
|
||||
if addr6.IP != nil && addr6.Mask != nil {
|
||||
allowedips = append(allowedips, addr6)
|
||||
}
|
||||
}
|
||||
|
||||
peer = wgtypes.PeerConfig{
|
||||
PublicKey: pubkey,
|
||||
ReplaceAllowedIPs: true,
|
||||
AllowedIPs: allowedips,
|
||||
}
|
||||
extConf := models.PeerConf{
|
||||
IsExtClient: true,
|
||||
Address: net.ParseIP(extPeer.Address),
|
||||
}
|
||||
proxyPeerConf[peer.PublicKey.String()] = extConf
|
||||
|
||||
peers = append(peers, peer)
|
||||
}
|
||||
return peers, proxyPeerConf, nil
|
||||
|
||||
}
|
||||
|
||||
// GetAllowedIPs - calculates the wireguard allowedip field for a peer of a node based on the peer and node settings
|
||||
func GetAllowedIPs(node, peer *models.Node, metrics *models.Metrics) []net.IPNet {
|
||||
var allowedips []net.IPNet
|
||||
|
|
|
@ -1,83 +0,0 @@
|
|||
package metrics
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/gravitl/netmaker/models"
|
||||
)
|
||||
|
||||
// lock for metrics map
|
||||
var metricsMapLock = &sync.RWMutex{}
|
||||
|
||||
// metrics data map
|
||||
var metricsPeerMap = make(map[string]map[string]*models.ProxyMetric)
|
||||
|
||||
// GetMetricByServer - get metric data of peers by server
|
||||
func GetMetricByServer(server string) map[string]*models.ProxyMetric {
|
||||
metricsMapLock.RLock()
|
||||
defer metricsMapLock.RUnlock()
|
||||
if _, ok := metricsPeerMap[server]; !ok {
|
||||
return nil
|
||||
}
|
||||
return metricsPeerMap[server]
|
||||
}
|
||||
|
||||
// GetMetric - fetches the metric data for the peer
|
||||
func GetMetric(server, peerKey string) models.ProxyMetric {
|
||||
metric := models.ProxyMetric{}
|
||||
peerMetricMap := GetMetricByServer(server)
|
||||
metricsMapLock.RLock()
|
||||
defer metricsMapLock.RUnlock()
|
||||
if peerMetricMap == nil {
|
||||
return metric
|
||||
}
|
||||
if m, ok := peerMetricMap[peerKey]; ok && m != nil {
|
||||
metric = *m
|
||||
}
|
||||
return metric
|
||||
}
|
||||
|
||||
// UpdateMetric - updates metric data for the peer
|
||||
func UpdateMetric(server, peerKey string, metric *models.ProxyMetric) {
|
||||
metricsMapLock.Lock()
|
||||
defer metricsMapLock.Unlock()
|
||||
if metricsPeerMap[server] == nil {
|
||||
metricsPeerMap[server] = make(map[string]*models.ProxyMetric)
|
||||
}
|
||||
metricsPeerMap[server][peerKey] = metric
|
||||
}
|
||||
|
||||
// UpdateMetricByPeer - updates metrics data by peer public key
|
||||
func UpdateMetricByPeer(peerKey string, metric *models.ProxyMetric, onlyTraffic bool) {
|
||||
metricsMapLock.Lock()
|
||||
defer metricsMapLock.Unlock()
|
||||
for server, peerKeyMap := range metricsPeerMap {
|
||||
if peerMetric, ok := peerKeyMap[peerKey]; ok {
|
||||
peerMetric.TrafficRecieved += metric.TrafficRecieved
|
||||
peerMetric.TrafficSent += metric.TrafficSent
|
||||
if !onlyTraffic {
|
||||
peerMetric.LastRecordedLatency = metric.LastRecordedLatency
|
||||
}
|
||||
|
||||
metricsPeerMap[server][peerKey] = peerMetric
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ResetMetricsForPeer - reset metrics for peer
|
||||
func ResetMetricsForPeer(server, peerKey string) {
|
||||
metricsMapLock.Lock()
|
||||
defer metricsMapLock.Unlock()
|
||||
delete(metricsPeerMap[server], peerKey)
|
||||
}
|
||||
|
||||
// ResetMetricForNode - resets node level metrics
|
||||
func ResetMetricForNode(server, peerKey, peerID string) {
|
||||
metric := GetMetric(server, peerKey)
|
||||
delete(metric.NodeConnectionStatus, peerID)
|
||||
UpdateMetric(server, peerKey, &metric)
|
||||
}
|
||||
|
||||
// MetricCollectionInterval - collection interval for metrics
|
||||
const MetricCollectionInterval = time.Second * 25
|
|
@ -16,9 +16,6 @@ type ApiHost struct {
|
|||
Debug bool `json:"debug"`
|
||||
IsStatic bool `json:"isstatic"`
|
||||
ListenPort int `json:"listenport"`
|
||||
LocalListenPort int `json:"locallistenport"`
|
||||
ProxyListenPort int `json:"proxy_listen_port"`
|
||||
PublicListenPort int `json:"public_listen_port" yaml:"public_listen_port"`
|
||||
WgPublicListenPort int `json:"wg_public_listen_port" yaml:"wg_public_listen_port"`
|
||||
MTU int `json:"mtu" yaml:"mtu"`
|
||||
Interfaces []Iface `json:"interfaces" yaml:"interfaces"`
|
||||
|
@ -28,7 +25,6 @@ type ApiHost struct {
|
|||
MacAddress string `json:"macaddress"`
|
||||
InternetGateway string `json:"internetgateway"`
|
||||
Nodes []string `json:"nodes"`
|
||||
ProxyEnabled bool `json:"proxy_enabled" yaml:"proxy_enabled"`
|
||||
IsDefault bool `json:"isdefault" yaml:"isdefault"`
|
||||
IsRelayed bool `json:"isrelayed" bson:"isrelayed" yaml:"isrelayed"`
|
||||
RelayedBy string `json:"relayed_by" bson:"relayed_by" yaml:"relayed_by"`
|
||||
|
@ -60,10 +56,7 @@ func (h *Host) ConvertNMHostToAPI() *ApiHost {
|
|||
a.Name = h.Name
|
||||
a.OS = h.OS
|
||||
a.Nodes = h.Nodes
|
||||
a.ProxyEnabled = h.ProxyEnabled
|
||||
a.PublicListenPort = h.PublicListenPort
|
||||
a.WgPublicListenPort = h.WgPublicListenPort
|
||||
a.ProxyListenPort = h.ProxyListenPort
|
||||
a.PublicKey = h.PublicKey.String()
|
||||
a.Verbosity = h.Verbosity
|
||||
a.Version = h.Version
|
||||
|
@ -95,8 +88,6 @@ func (a *ApiHost) ConvertAPIHostToNMHost(currentHost *Host) *Host {
|
|||
h.IsK8S = currentHost.IsK8S
|
||||
h.IsStatic = a.IsStatic
|
||||
h.ListenPort = a.ListenPort
|
||||
h.ProxyListenPort = a.ProxyListenPort
|
||||
h.PublicListenPort = currentHost.PublicListenPort
|
||||
h.MTU = a.MTU
|
||||
h.MacAddress = currentHost.MacAddress
|
||||
h.PublicKey = currentHost.PublicKey
|
||||
|
@ -106,7 +97,6 @@ func (a *ApiHost) ConvertAPIHostToNMHost(currentHost *Host) *Host {
|
|||
h.Nodes = currentHost.Nodes
|
||||
h.TrafficKeyPublic = currentHost.TrafficKeyPublic
|
||||
h.OS = currentHost.OS
|
||||
h.ProxyEnabled = a.ProxyEnabled
|
||||
h.IsDefault = a.IsDefault
|
||||
h.NatType = currentHost.NatType
|
||||
h.TurnEndpoint = currentHost.TurnEndpoint
|
||||
|
|
|
@ -25,15 +25,11 @@ var OS_Types = struct {
|
|||
|
||||
// NAT_Types - the type of NAT in which a HOST currently resides (simplified)
|
||||
var NAT_Types = struct {
|
||||
Public string
|
||||
Symmetric string
|
||||
Asymmetric string
|
||||
Double string
|
||||
Public string
|
||||
BehindNAT string
|
||||
}{
|
||||
Public: "public",
|
||||
Symmetric: "symmetric",
|
||||
Asymmetric: "asymmetric",
|
||||
Double: "double",
|
||||
Public: "public",
|
||||
BehindNAT: "behind_nat",
|
||||
}
|
||||
|
||||
// WIREGUARD_INTERFACE name of wireguard interface
|
||||
|
@ -54,24 +50,16 @@ type Host struct {
|
|||
Interface string `json:"interface" yaml:"interface"`
|
||||
Debug bool `json:"debug" yaml:"debug"`
|
||||
ListenPort int `json:"listenport" yaml:"listenport"`
|
||||
PublicListenPort int `json:"public_listen_port" yaml:"public_listen_port"`
|
||||
WgPublicListenPort int `json:"wg_public_listen_port" yaml:"wg_public_listen_port"`
|
||||
ProxyListenPort int `json:"proxy_listen_port" yaml:"proxy_listen_port"`
|
||||
MTU int `json:"mtu" yaml:"mtu"`
|
||||
PublicKey wgtypes.Key `json:"publickey" yaml:"publickey"`
|
||||
MacAddress net.HardwareAddr `json:"macaddress" yaml:"macaddress"`
|
||||
TrafficKeyPublic []byte `json:"traffickeypublic" yaml:"traffickeypublic"`
|
||||
InternetGateway net.UDPAddr `json:"internetgateway" yaml:"internetgateway"`
|
||||
Nodes []string `json:"nodes" yaml:"nodes"`
|
||||
IsRelayed bool `json:"isrelayed" yaml:"isrelayed"`
|
||||
RelayedBy string `json:"relayed_by" yaml:"relayed_by"`
|
||||
IsRelay bool `json:"isrelay" yaml:"isrelay"`
|
||||
RelayedHosts []string `json:"relay_hosts" yaml:"relay_hosts"`
|
||||
Interfaces []Iface `json:"interfaces" yaml:"interfaces"`
|
||||
DefaultInterface string `json:"defaultinterface" yaml:"defaultinterface"`
|
||||
EndpointIP net.IP `json:"endpointip" yaml:"endpointip"`
|
||||
ProxyEnabled bool `json:"proxy_enabled" yaml:"proxy_enabled"`
|
||||
ProxyEnabledSet bool `json:"proxy_enabled_updated" yaml:"proxy_enabled_updated"`
|
||||
IsDocker bool `json:"isdocker" yaml:"isdocker"`
|
||||
IsK8S bool `json:"isk8s" yaml:"isk8s"`
|
||||
IsStatic bool `json:"isstatic" yaml:"isstatic"`
|
||||
|
|
|
@ -15,26 +15,26 @@ type Metrics struct {
|
|||
|
||||
// Metric - holds a metric for data between nodes
|
||||
type Metric struct {
|
||||
NodeName string `json:"node_name" bson:"node_name" yaml:"node_name"`
|
||||
Uptime int64 `json:"uptime" bson:"uptime" yaml:"uptime"`
|
||||
TotalTime int64 `json:"totaltime" bson:"totaltime" yaml:"totaltime"`
|
||||
Latency int64 `json:"latency" bson:"latency" yaml:"latency"`
|
||||
TotalReceived int64 `json:"totalreceived" bson:"totalreceived" yaml:"totalreceived"`
|
||||
TotalSent int64 `json:"totalsent" bson:"totalsent" yaml:"totalsent"`
|
||||
ActualUptime time.Duration `json:"actualuptime" bson:"actualuptime" yaml:"actualuptime"`
|
||||
PercentUp float64 `json:"percentup" bson:"percentup" yaml:"percentup"`
|
||||
Connected bool `json:"connected" bson:"connected" yaml:"connected"`
|
||||
CollectedByProxy bool `json:"collected_by_proxy" bson:"collected_by_proxy" yaml:"collected_by_proxy"`
|
||||
NodeName string `json:"node_name" bson:"node_name" yaml:"node_name"`
|
||||
Uptime int64 `json:"uptime" bson:"uptime" yaml:"uptime"`
|
||||
TotalTime int64 `json:"totaltime" bson:"totaltime" yaml:"totaltime"`
|
||||
Latency int64 `json:"latency" bson:"latency" yaml:"latency"`
|
||||
TotalReceived int64 `json:"totalreceived" bson:"totalreceived" yaml:"totalreceived"`
|
||||
TotalSent int64 `json:"totalsent" bson:"totalsent" yaml:"totalsent"`
|
||||
ActualUptime time.Duration `json:"actualuptime" bson:"actualuptime" yaml:"actualuptime"`
|
||||
PercentUp float64 `json:"percentup" bson:"percentup" yaml:"percentup"`
|
||||
Connected bool `json:"connected" bson:"connected" yaml:"connected"`
|
||||
}
|
||||
|
||||
// IDandAddr - struct to hold ID and primary Address
|
||||
type IDandAddr struct {
|
||||
ID string `json:"id" bson:"id" yaml:"id"`
|
||||
Address string `json:"address" bson:"address" yaml:"address"`
|
||||
Name string `json:"name" bson:"name" yaml:"name"`
|
||||
IsServer string `json:"isserver" bson:"isserver" yaml:"isserver" validate:"checkyesorno"`
|
||||
Network string `json:"network" bson:"network" yaml:"network" validate:"network"`
|
||||
ProxyListenPort int `json:"proxy_listen_port" yaml:"proxy_listen_port"`
|
||||
ID string `json:"id" bson:"id" yaml:"id"`
|
||||
Address string `json:"address" bson:"address" yaml:"address"`
|
||||
Name string `json:"name" bson:"name" yaml:"name"`
|
||||
IsServer string `json:"isserver" bson:"isserver" yaml:"isserver" validate:"checkyesorno"`
|
||||
Network string `json:"network" bson:"network" yaml:"network" validate:"network"`
|
||||
ListenPort int `json:"listen_port" yaml:"listen_port"`
|
||||
IsExtClient bool `json:"is_extclient"`
|
||||
}
|
||||
|
||||
// HostInfoMap - map of host public keys to host networking info
|
||||
|
@ -42,16 +42,13 @@ type HostInfoMap map[string]HostNetworkInfo
|
|||
|
||||
// HostNetworkInfo - holds info related to host networking (used for client side peer calculations)
|
||||
type HostNetworkInfo struct {
|
||||
Interfaces []Iface `json:"interfaces" yaml:"interfaces"`
|
||||
ProxyListenPort int `json:"proxy_listen_port" yaml:"proxy_listen_port"`
|
||||
Interfaces []Iface `json:"interfaces" yaml:"interfaces"`
|
||||
ListenPort int `json:"listen_port" yaml:"listen_port"`
|
||||
}
|
||||
|
||||
// PeerMap - peer map for ids and addresses in metrics
|
||||
type PeerMap map[string]IDandAddr
|
||||
|
||||
// HostPeerMap - host peer map for ids and addresses
|
||||
type HostPeerMap map[string]map[string]IDandAddr
|
||||
|
||||
// MetricsMap - map for holding multiple metrics in memory
|
||||
type MetricsMap map[string]Metrics
|
||||
|
||||
|
|
|
@ -15,14 +15,11 @@ type HostPeerUpdate struct {
|
|||
ServerAddrs []ServerAddr `json:"serveraddrs" bson:"serveraddrs" yaml:"serveraddrs"`
|
||||
NodePeers []wgtypes.PeerConfig `json:"peers" bson:"peers" yaml:"peers"`
|
||||
Peers []wgtypes.PeerConfig
|
||||
HostPeerIDs HostPeerMap `json:"hostpeerids" bson:"hostpeerids" yaml:"hostpeerids"`
|
||||
ProxyUpdate ProxyManagerPayload `json:"proxy_update" bson:"proxy_update" yaml:"proxy_update"`
|
||||
EgressInfo map[string]EgressInfo `json:"egress_info" bson:"egress_info" yaml:"egress_info"` // map key is node ID
|
||||
IngressInfo IngressInfo `json:"ingress_info" bson:"ext_peers" yaml:"ext_peers"`
|
||||
PeerIDs PeerMap `json:"peerids" bson:"peerids" yaml:"peerids"`
|
||||
EndpointDetection bool `json:"endpointdetection" yaml:"endpointdetection"`
|
||||
HostNetworkInfo HostInfoMap `json:"host_network_info,omitempty" bson:"host_network_info,omitempty" yaml:"host_network_info,omitempty"`
|
||||
EgressRoutes []EgressNetworkRoutes `json:"egress_network_routes"`
|
||||
FwUpdate FwUpdate `json:"fw_update"`
|
||||
}
|
||||
|
||||
// IngressInfo - struct for ingress info
|
||||
|
@ -69,3 +66,11 @@ type KeyUpdate struct {
|
|||
Network string `json:"network" bson:"network"`
|
||||
Interface string `json:"interface" bson:"interface"`
|
||||
}
|
||||
|
||||
// FwUpdate - struct for firewall updates
|
||||
type FwUpdate struct {
|
||||
IsIngressGw bool `json:"is_ingress_gw"`
|
||||
IsEgressGw bool `json:"is_egress_gw"`
|
||||
IngressInfo IngressInfo `json:"ingress_info"`
|
||||
EgressInfo map[string]EgressInfo `json:"egress_info"`
|
||||
}
|
||||
|
|
|
@ -483,7 +483,6 @@ func (ln *LegacyNode) ConvertToNewNode() (*Host, *Node) {
|
|||
host.HostPass = ln.Password
|
||||
host.Name = ln.Name
|
||||
host.ListenPort = int(ln.ListenPort)
|
||||
host.ProxyListenPort = int(ln.ProxyListenPort)
|
||||
host.MTU = int(ln.MTU)
|
||||
host.PublicKey, _ = wgtypes.ParseKey(ln.PublicKey)
|
||||
host.MacAddress, _ = net.ParseMAC(ln.MacAddress)
|
||||
|
@ -540,7 +539,6 @@ func (n *Node) Legacy(h *Host, s *ServerConfig, net *Network) *LegacyNode {
|
|||
l.Name = h.Name
|
||||
l.NetworkSettings = *net
|
||||
l.ListenPort = int32(h.ListenPort)
|
||||
l.ProxyListenPort = int32(h.ProxyListenPort)
|
||||
l.PublicKey = h.PublicKey.String()
|
||||
l.Endpoint = h.EndpointIP.String()
|
||||
//l.AllowedIPs =
|
||||
|
@ -580,7 +578,6 @@ func (n *Node) Legacy(h *Host, s *ServerConfig, net *Network) *LegacyNode {
|
|||
l.InternetGateway = h.InternetGateway.String()
|
||||
l.Connected = formatBool(n.Connected)
|
||||
//l.PendingDelete = formatBool(n.PendingDelete)
|
||||
l.Proxy = h.ProxyEnabled
|
||||
l.DefaultACL = n.DefaultACL
|
||||
l.OwnerID = n.OwnerID
|
||||
//l.Failover = n.Failover
|
||||
|
|
|
@ -1,68 +0,0 @@
|
|||
package models
|
||||
|
||||
import (
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
||||
)
|
||||
|
||||
// ProxyAction - type for proxy action
|
||||
type ProxyAction string
|
||||
|
||||
const (
|
||||
// default proxy port
|
||||
NmProxyPort = 51722
|
||||
// PersistentKeepaliveInterval - default keepalive for wg peer
|
||||
DefaultPersistentKeepaliveInterval = time.Duration(time.Second * 20)
|
||||
|
||||
// ProxyUpdate - constant for proxy update action
|
||||
ProxyUpdate ProxyAction = "PROXY_UPDATE"
|
||||
// ProxyDeletePeers - constant for proxy delete peers action
|
||||
ProxyDeletePeers ProxyAction = "PROXY_DELETE"
|
||||
// ProxyDeleteAllPeers - constant for proxy delete all peers action
|
||||
ProxyDeleteAllPeers ProxyAction = "PROXY_DELETE_ALL"
|
||||
// NoProxy - constant for no ProxyAction
|
||||
NoProxy ProxyAction = "NO_PROXY"
|
||||
)
|
||||
|
||||
// RelayedConf - struct relayed peers config
|
||||
type RelayedConf struct {
|
||||
RelayedPeerEndpoint *net.UDPAddr `json:"relayed_peer_endpoint"`
|
||||
RelayedPeerPubKey string `json:"relayed_peer_pub_key"`
|
||||
Peers []wgtypes.PeerConfig `json:"relayed_peers"`
|
||||
}
|
||||
|
||||
// PeerConf - struct for peer config in the network
|
||||
type PeerConf struct {
|
||||
Proxy bool `json:"proxy"`
|
||||
PublicListenPort int32 `json:"public_listen_port"`
|
||||
ProxyListenPort int `json:"proxy_listen_port"`
|
||||
IsExtClient bool `json:"is_ext_client"`
|
||||
Address net.IP `json:"address"`
|
||||
IsRelayed bool `json:"is_relayed"`
|
||||
RelayedTo *net.UDPAddr `json:"relayed_to"`
|
||||
NatType string `json:"nat_type"`
|
||||
}
|
||||
|
||||
// ProxyManagerPayload - struct for proxy manager payload
|
||||
type ProxyManagerPayload struct {
|
||||
Action ProxyAction `json:"action"`
|
||||
InterfaceName string `json:"interface_name"`
|
||||
Server string `json:"server"`
|
||||
Peers []wgtypes.PeerConfig `json:"peers"`
|
||||
PeerMap map[string]PeerConf `json:"peer_map"`
|
||||
IsIngress bool `json:"is_ingress"`
|
||||
IsRelayed bool `json:"is_relayed"`
|
||||
RelayedTo *net.UDPAddr `json:"relayed_to"`
|
||||
IsRelay bool `json:"is_relay"`
|
||||
RelayedPeerConf map[string]RelayedConf `json:"relayed_conf"`
|
||||
}
|
||||
|
||||
// Metric - struct for metric data
|
||||
type ProxyMetric struct {
|
||||
NodeConnectionStatus map[string]bool `json:"node_connection_status"`
|
||||
LastRecordedLatency uint64 `json:"last_recorded_latency"`
|
||||
TrafficSent int64 `json:"traffic_sent"` // stored in MB
|
||||
TrafficRecieved int64 `json:"traffic_recieved"` // stored in MB
|
||||
}
|
|
@ -324,21 +324,18 @@ func updateNodeMetrics(currentNode *models.Node, newMetrics *models.Metrics) boo
|
|||
oldMetric := oldMetrics.Connectivity[k]
|
||||
currMetric.TotalTime += oldMetric.TotalTime
|
||||
currMetric.Uptime += oldMetric.Uptime // get the total uptime for this connection
|
||||
if currMetric.CollectedByProxy {
|
||||
|
||||
if currMetric.TotalReceived < oldMetric.TotalReceived {
|
||||
currMetric.TotalReceived += oldMetric.TotalReceived
|
||||
} else {
|
||||
currMetric.TotalReceived += int64(math.Abs(float64(currMetric.TotalReceived) - float64(oldMetric.TotalReceived)))
|
||||
}
|
||||
if currMetric.TotalSent < oldMetric.TotalSent {
|
||||
currMetric.TotalSent += oldMetric.TotalSent
|
||||
} else {
|
||||
if currMetric.TotalReceived < oldMetric.TotalReceived {
|
||||
currMetric.TotalReceived += oldMetric.TotalReceived
|
||||
} else {
|
||||
currMetric.TotalReceived += int64(math.Abs(float64(currMetric.TotalReceived) - float64(oldMetric.TotalReceived)))
|
||||
}
|
||||
if currMetric.TotalSent < oldMetric.TotalSent {
|
||||
currMetric.TotalSent += oldMetric.TotalSent
|
||||
} else {
|
||||
currMetric.TotalSent += int64(math.Abs(float64(currMetric.TotalSent) - float64(oldMetric.TotalSent)))
|
||||
}
|
||||
currMetric.TotalSent += int64(math.Abs(float64(currMetric.TotalSent) - float64(oldMetric.TotalSent)))
|
||||
}
|
||||
|
||||
if currMetric.Uptime == 0 || currMetric.TotalTime == 0 {
|
||||
currMetric.PercentUp = 0
|
||||
} else {
|
||||
|
|
|
@ -96,20 +96,6 @@ func PublishSingleHostPeerUpdate(host *models.Host, allNodes []models.Node, dele
|
|||
if len(peerUpdate.Peers) == 0 { // no peers to send
|
||||
return nil
|
||||
}
|
||||
if host.OS != models.OS_Types.IoT {
|
||||
proxyUpdate, err := logic.GetProxyUpdateForHost(host)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
proxyUpdate.Server = servercfg.GetServer()
|
||||
if host.ProxyEnabled {
|
||||
proxyUpdate.Action = models.ProxyUpdate
|
||||
} else {
|
||||
proxyUpdate.Action = models.NoProxy
|
||||
}
|
||||
|
||||
peerUpdate.ProxyUpdate = proxyUpdate
|
||||
}
|
||||
|
||||
data, err := json.Marshal(&peerUpdate)
|
||||
if err != nil {
|
||||
|
|
|
@ -46,10 +46,6 @@ SERVER_BROKER_ENDPOINT="ws://mq:1883"
|
|||
STUN_PORT="3478"
|
||||
# Logging verbosity level - 1, 2, or 3
|
||||
VERBOSITY="1"
|
||||
# If ON, all new clients will enable proxy by default
|
||||
# If OFF, all new clients will disable proxy by default
|
||||
# If AUTO, stick with the existing logic for NAT detection
|
||||
DEFAULT_PROXY_MODE="off"
|
||||
# Port to access turn server
|
||||
TURN_PORT="3479"
|
||||
# Config for using turn, accepts either true/false
|
||||
|
|
|
@ -310,7 +310,7 @@ save_config() { (
|
|||
local toCopy=("SERVER_HOST" "MASTER_KEY" "TURN_USERNAME" "TURN_PASSWORD" "MQ_USERNAME" "MQ_PASSWORD"
|
||||
"INSTALL_TYPE" "NODE_ID" "DNS_MODE" "NETCLIENT_AUTO_UPDATE" "API_PORT"
|
||||
"CORS_ALLOWED_ORIGIN" "DISPLAY_KEYS" "DATABASE" "SERVER_BROKER_ENDPOINT" "STUN_PORT" "VERBOSITY"
|
||||
"DEFAULT_PROXY_MODE" "TURN_PORT" "USE_TURN" "DEBUG_MODE" "TURN_API_PORT" "REST_BACKEND"
|
||||
"TURN_PORT" "USE_TURN" "DEBUG_MODE" "TURN_API_PORT" "REST_BACKEND"
|
||||
"DISABLE_REMOTE_IP_CHECK" "NETCLIENT_ENDPOINT_DETECTION" "TELEMETRY" "AUTH_PROVIDER" "CLIENT_ID" "CLIENT_SECRET"
|
||||
"FRONTEND_URL" "AZURE_TENANT" "OIDC_ISSUER" "EXPORTER_API_PORT")
|
||||
for name in "${toCopy[@]}"; do
|
||||
|
|
|
@ -90,7 +90,6 @@ func GetServerConfig() config.ServerConfig {
|
|||
if Is_EE {
|
||||
cfg.IsEE = "yes"
|
||||
}
|
||||
cfg.DefaultProxyMode = GetDefaultProxyMode()
|
||||
|
||||
return cfg
|
||||
}
|
||||
|
@ -731,17 +730,6 @@ func GetTurnPassword() string {
|
|||
|
||||
}
|
||||
|
||||
// IsProxyEnabled - is proxy on or off
|
||||
func IsProxyEnabled() bool {
|
||||
var enabled = false //default
|
||||
if os.Getenv("PROXY") != "" {
|
||||
enabled = os.Getenv("PROXY") == "on"
|
||||
} else if config.Config.Server.Proxy != "" {
|
||||
enabled = config.Config.Server.Proxy == "on"
|
||||
}
|
||||
return enabled
|
||||
}
|
||||
|
||||
// GetNetworkLimit - fetches free tier limits on users
|
||||
func GetUserLimit() int {
|
||||
var userslimit int
|
||||
|
@ -794,32 +782,6 @@ func DeployedByOperator() bool {
|
|||
return config.Config.Server.DeployedByOperator
|
||||
}
|
||||
|
||||
// GetDefaultProxyMode - default proxy mode for a server
|
||||
func GetDefaultProxyMode() config.ProxyMode {
|
||||
var (
|
||||
mode config.ProxyMode
|
||||
def string
|
||||
)
|
||||
if os.Getenv("DEFAULT_PROXY_MODE") != "" {
|
||||
def = os.Getenv("DEFAULT_PROXY_MODE")
|
||||
} else if config.Config.Server.DefaultProxyMode.Set {
|
||||
return config.Config.Server.DefaultProxyMode
|
||||
}
|
||||
switch strings.ToUpper(def) {
|
||||
case "ON":
|
||||
mode.Set = true
|
||||
mode.Value = true
|
||||
case "OFF":
|
||||
mode.Set = true
|
||||
mode.Value = false
|
||||
// AUTO or any other value
|
||||
default:
|
||||
mode.Set = false
|
||||
}
|
||||
return mode
|
||||
|
||||
}
|
||||
|
||||
// parseStunList - turn string into slice of StunServers
|
||||
func parseStunList(stunString string) ([]models.StunServer, error) {
|
||||
var err error
|
||||
|
|
Loading…
Add table
Reference in a new issue