mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-05 16:57:51 +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
|
||||
sendPeerUpdate = true
|
||||
}
|
||||
if newHost.WgPublicListenPort != 0 && currHost.WgPublicListenPort != newHost.WgPublicListenPort {
|
||||
currHost.WgPublicListenPort = newHost.WgPublicListenPort
|
||||
sendPeerUpdate = true
|
||||
}
|
||||
if newHost.ProxyListenPort != 0 && currHost.ProxyListenPort != newHost.ProxyListenPort {
|
||||
currHost.ProxyListenPort = newHost.ProxyListenPort
|
||||
sendPeerUpdate = true
|
||||
|
@@ -220,11 +220,12 @@ func GetPeerUpdateForHost(ctx context.Context, network string, host *models.Host
|
||||
}
|
||||
peerConfig.Endpoint = &net.UDPAddr{
|
||||
IP: peerHost.EndpointIP,
|
||||
Port: peerHost.ListenPort,
|
||||
Port: getPeerWgListenPort(peerHost),
|
||||
}
|
||||
|
||||
if uselocal {
|
||||
peerConfig.Endpoint.IP = peer.LocalAddress.IP
|
||||
peerConfig.Endpoint.Port = peerHost.ListenPort
|
||||
}
|
||||
allowedips := GetAllowedIPs(&node, &peer, nil)
|
||||
if peer.IsIngressGateway {
|
||||
@@ -425,9 +426,21 @@ func GetPeerUpdateForHost(ctx context.Context, network string, host *models.Host
|
||||
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
|
||||
|
@@ -19,6 +19,7 @@ type ApiHost struct {
|
||||
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"`
|
||||
DefaultInterface string `json:"defaultinterface" yaml:"defautlinterface"`
|
||||
@@ -60,6 +61,7 @@ func (h *Host) ConvertNMHostToAPI() *ApiHost {
|
||||
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
|
||||
|
@@ -55,6 +55,7 @@ type Host struct {
|
||||
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"`
|
||||
|
Reference in New Issue
Block a user