Jelajahi Sumber

- sync EndpointDetection on peerupdate
- add EndpointDetection to env config

Tobias Cudnik 2 tahun lalu
induk
melakukan
ec9aa45dbb
5 mengubah file dengan 48 tambahan dan 41 penghapusan
  1. 4 0
      logic/hosts.go
  2. 37 37
      models/host.go
  3. 3 1
      mq/handlers.go
  4. 1 0
      scripts/netmaker.default.env
  5. 3 3
      scripts/nm-quick.sh

+ 4 - 0
logic/hosts.go

@@ -190,6 +190,10 @@ func UpdateHostFromClient(newHost, currHost *models.Host) (sendPeerUpdate bool)
 		currHost.ProxyEnabled = newHost.ProxyEnabled
 		sendPeerUpdate = true
 	}
+	if currHost.EndpointDetection != newHost.EndpointDetection {
+		currHost.EndpointDetection = newHost.EndpointDetection
+		sendPeerUpdate = true
+	}
 	if currHost.EndpointIP.String() != newHost.EndpointIP.String() {
 		currHost.EndpointIP = newHost.EndpointIP
 		sendPeerUpdate = true

+ 37 - 37
models/host.go

@@ -41,44 +41,44 @@ const WIREGUARD_INTERFACE = "netmaker"
 
 // Host - represents a host on the network
 type Host struct {
-	ID                uuid.UUID        `json:"id" yaml:"id"`
-	Verbosity         int              `json:"verbosity" yaml:"verbosity"`
-	FirewallInUse     string           `json:"firewallinuse" yaml:"firewallinuse"`
-	Version           string           `json:"version" yaml:"version"`
-	IPForwarding      bool             `json:"ipforwarding" yaml:"ipforwarding"`
-	DaemonInstalled   bool             `json:"daemoninstalled" yaml:"daemoninstalled"`
-	AutoUpdate        bool             `json:"autoupdate" yaml:"autoupdate"`
-	EndpointDetection bool             `json:"endpointdetection" yaml:"endpointdetection"`
-	HostPass          string           `json:"hostpass" yaml:"hostpass"`
-	Name              string           `json:"name" yaml:"name"`
-	OS                string           `json:"os" yaml:"os"`
-	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"`
+	ID                 uuid.UUID        `json:"id" yaml:"id"`
+	Verbosity          int              `json:"verbosity" yaml:"verbosity"`
+	FirewallInUse      string           `json:"firewallinuse" yaml:"firewallinuse"`
+	Version            string           `json:"version" yaml:"version"`
+	IPForwarding       bool             `json:"ipforwarding" yaml:"ipforwarding"`
+	DaemonInstalled    bool             `json:"daemoninstalled" yaml:"daemoninstalled"`
+	AutoUpdate         bool             `json:"autoupdate" yaml:"autoupdate"`
+	EndpointDetection  bool             `json:"endpointdetection" yaml:"endpointdetection"`
+	HostPass           string           `json:"hostpass" yaml:"hostpass"`
+	Name               string           `json:"name" yaml:"name"`
+	OS                 string           `json:"os" yaml:"os"`
+	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"`
-	IsDefault         bool             `json:"isdefault" yaml:"isdefault"`
-	NatType           string           `json:"nat_type,omitempty" yaml:"nat_type,omitempty"`
-	TurnEndpoint      *netip.AddrPort  `json:"turn_endpoint,omitempty" yaml:"turn_endpoint,omitempty"`
+	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"`
+	IsDefault          bool             `json:"isdefault" yaml:"isdefault"`
+	NatType            string           `json:"nat_type,omitempty" yaml:"nat_type,omitempty"`
+	TurnEndpoint       *netip.AddrPort  `json:"turn_endpoint,omitempty" yaml:"turn_endpoint,omitempty"`
 }
 
 // FormatBool converts a boolean to a [yes|no] string

+ 3 - 1
mq/handlers.go

@@ -440,12 +440,14 @@ func handleHostCheckin(h, currentHost *models.Host) bool {
 	ifaceDelta := len(h.Interfaces) != len(currentHost.Interfaces) ||
 		!h.EndpointIP.Equal(currentHost.EndpointIP) ||
 		(len(h.NatType) > 0 && h.NatType != currentHost.NatType) ||
-		h.DefaultInterface != currentHost.DefaultInterface
+		h.DefaultInterface != currentHost.DefaultInterface ||
+		h.EndpointDetection != currentHost.EndpointDetection
 	if ifaceDelta { // only save if something changes
 		currentHost.EndpointIP = h.EndpointIP
 		currentHost.Interfaces = h.Interfaces
 		currentHost.DefaultInterface = h.DefaultInterface
 		currentHost.NatType = h.NatType
+		currentHost.EndpointDetection = h.EndpointDetection
 		if err := logic.UpsertHost(currentHost); err != nil {
 			logger.Log(0, "failed to update host after check-in", h.Name, h.ID.String(), err.Error())
 			return false

+ 1 - 0
scripts/netmaker.default.env

@@ -19,6 +19,7 @@ NETMAKER_ACCOUNT_ID=
 LICENSE_KEY=
 SERVER_IMAGE_TAG=
 UI_IMAGE_TAG=
+ENDPOINT_DETECTION="disabled"
 # used for HA - identifies this server vs other servers
 NODE_ID="netmaker-server-1"
 METRICS_EXPORTER="off"

+ 3 - 3
scripts/nm-quick.sh

@@ -303,9 +303,9 @@ save_config() { (
 	local toCopy=("SERVER_HOST" "MASTER_KEY" "TURN_USERNAME" "TURN_PASSWORD" "MQ_USERNAME" "MQ_PASSWORD"
 		"INSTALL_TYPE" "NODE_ID" "METRICS_EXPORTER" "PROMETHEUS" "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" "DISABLE_REMOTE_IP_CHECK"
-		"TELEMETRY" "AUTH_PROVIDER" "CLIENT_ID" "CLIENT_SECRET" "FRONTEND_URL" "AZURE_TENANT" "OIDC_ISSUER"
-		"EXPORTER_API_PORT")
+		"DEFAULT_PROXY_MODE" "TURN_PORT" "USE_TURN" "DEBUG_MODE" "TURN_API_PORT" "REST_BACKEND"
+		"DISABLE_REMOTE_IP_CHECK" "ENDPOINT_DETECTION" "TELEMETRY" "AUTH_PROVIDER" "CLIENT_ID" "CLIENT_SECRET"
+		"FRONTEND_URL" "AZURE_TENANT" "OIDC_ISSUER" "EXPORTER_API_PORT")
 	for name in "${toCopy[@]}"; do
 		save_config_item $name "${!name}"
 	done