mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-06 01:07:41 +08:00
NET-186: Wg public listen port (#2344)
* fetch public listen of wg if present * check if wg pub listen port has been changed on host update * wg public port to host api model for visibility * rm comment
This commit is contained in:
@@ -173,6 +173,10 @@ func UpdateHostFromClient(newHost, currHost *models.Host) (sendPeerUpdate bool)
|
|||||||
currHost.ListenPort = newHost.ListenPort
|
currHost.ListenPort = newHost.ListenPort
|
||||||
sendPeerUpdate = true
|
sendPeerUpdate = true
|
||||||
}
|
}
|
||||||
|
if newHost.WgPublicListenPort != 0 && currHost.WgPublicListenPort != newHost.WgPublicListenPort {
|
||||||
|
currHost.WgPublicListenPort = newHost.WgPublicListenPort
|
||||||
|
sendPeerUpdate = true
|
||||||
|
}
|
||||||
if newHost.ProxyListenPort != 0 && currHost.ProxyListenPort != newHost.ProxyListenPort {
|
if newHost.ProxyListenPort != 0 && currHost.ProxyListenPort != newHost.ProxyListenPort {
|
||||||
currHost.ProxyListenPort = newHost.ProxyListenPort
|
currHost.ProxyListenPort = newHost.ProxyListenPort
|
||||||
sendPeerUpdate = true
|
sendPeerUpdate = true
|
||||||
|
@@ -220,11 +220,12 @@ func GetPeerUpdateForHost(ctx context.Context, network string, host *models.Host
|
|||||||
}
|
}
|
||||||
peerConfig.Endpoint = &net.UDPAddr{
|
peerConfig.Endpoint = &net.UDPAddr{
|
||||||
IP: peerHost.EndpointIP,
|
IP: peerHost.EndpointIP,
|
||||||
Port: peerHost.ListenPort,
|
Port: getPeerWgListenPort(peerHost),
|
||||||
}
|
}
|
||||||
|
|
||||||
if uselocal {
|
if uselocal {
|
||||||
peerConfig.Endpoint.IP = peer.LocalAddress.IP
|
peerConfig.Endpoint.IP = peer.LocalAddress.IP
|
||||||
|
peerConfig.Endpoint.Port = peerHost.ListenPort
|
||||||
}
|
}
|
||||||
allowedips := GetAllowedIPs(&node, &peer, nil)
|
allowedips := GetAllowedIPs(&node, &peer, nil)
|
||||||
if peer.IsIngressGateway {
|
if peer.IsIngressGateway {
|
||||||
@@ -425,9 +426,21 @@ func GetPeerUpdateForHost(ctx context.Context, network string, host *models.Host
|
|||||||
return hostPeerUpdate, nil
|
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
|
// GetPeerListenPort - given a host, retrieve it's appropriate listening port
|
||||||
func GetPeerListenPort(host *models.Host) int {
|
func GetPeerListenPort(host *models.Host) int {
|
||||||
peerPort := host.ListenPort
|
peerPort := host.ListenPort
|
||||||
|
if host.WgPublicListenPort != 0 {
|
||||||
|
peerPort = host.WgPublicListenPort
|
||||||
|
}
|
||||||
if host.ProxyEnabled {
|
if host.ProxyEnabled {
|
||||||
if host.PublicListenPort != 0 {
|
if host.PublicListenPort != 0 {
|
||||||
peerPort = host.PublicListenPort
|
peerPort = host.PublicListenPort
|
||||||
|
@@ -19,6 +19,7 @@ type ApiHost struct {
|
|||||||
LocalListenPort int `json:"locallistenport"`
|
LocalListenPort int `json:"locallistenport"`
|
||||||
ProxyListenPort int `json:"proxy_listen_port"`
|
ProxyListenPort int `json:"proxy_listen_port"`
|
||||||
PublicListenPort int `json:"public_listen_port" yaml:"public_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"`
|
MTU int `json:"mtu" yaml:"mtu"`
|
||||||
Interfaces []Iface `json:"interfaces" yaml:"interfaces"`
|
Interfaces []Iface `json:"interfaces" yaml:"interfaces"`
|
||||||
DefaultInterface string `json:"defaultinterface" yaml:"defautlinterface"`
|
DefaultInterface string `json:"defaultinterface" yaml:"defautlinterface"`
|
||||||
@@ -60,6 +61,7 @@ func (h *Host) ConvertNMHostToAPI() *ApiHost {
|
|||||||
a.Nodes = h.Nodes
|
a.Nodes = h.Nodes
|
||||||
a.ProxyEnabled = h.ProxyEnabled
|
a.ProxyEnabled = h.ProxyEnabled
|
||||||
a.PublicListenPort = h.PublicListenPort
|
a.PublicListenPort = h.PublicListenPort
|
||||||
|
a.WgPublicListenPort = h.WgPublicListenPort
|
||||||
a.ProxyListenPort = h.ProxyListenPort
|
a.ProxyListenPort = h.ProxyListenPort
|
||||||
a.PublicKey = h.PublicKey.String()
|
a.PublicKey = h.PublicKey.String()
|
||||||
a.Verbosity = h.Verbosity
|
a.Verbosity = h.Verbosity
|
||||||
|
@@ -55,6 +55,7 @@ type Host struct {
|
|||||||
Debug bool `json:"debug" yaml:"debug"`
|
Debug bool `json:"debug" yaml:"debug"`
|
||||||
ListenPort int `json:"listenport" yaml:"listenport"`
|
ListenPort int `json:"listenport" yaml:"listenport"`
|
||||||
PublicListenPort int `json:"public_listen_port" yaml:"public_listen_port"`
|
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"`
|
ProxyListenPort int `json:"proxy_listen_port" yaml:"proxy_listen_port"`
|
||||||
MTU int `json:"mtu" yaml:"mtu"`
|
MTU int `json:"mtu" yaml:"mtu"`
|
||||||
PublicKey wgtypes.Key `json:"publickey" yaml:"publickey"`
|
PublicKey wgtypes.Key `json:"publickey" yaml:"publickey"`
|
||||||
|
Reference in New Issue
Block a user