mirror of
https://github.com/gravitl/netmaker.git
synced 2025-11-11 09:10:53 +08:00
add egress ranges to ingress info
This commit is contained in:
parent
f2ad89fe93
commit
4c373af9ec
2 changed files with 15 additions and 10 deletions
|
|
@ -201,7 +201,7 @@ func GetProxyUpdateForHost(host *models.Host) (models.ProxyManagerPayload, error
|
||||||
if host.IsRelayed {
|
if host.IsRelayed {
|
||||||
relayHost, err := GetHost(host.RelayedBy)
|
relayHost, err := GetHost(host.RelayedBy)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
relayEndpoint, err := net.ResolveUDPAddr("udp", fmt.Sprintf("%s:%d", relayHost.EndpointIP, getPeerListenPort(relayHost)))
|
relayEndpoint, err := net.ResolveUDPAddr("udp", fmt.Sprintf("%s:%d", relayHost.EndpointIP, GetPeerListenPort(relayHost)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Log(1, "failed to resolve relay node endpoint: ", err.Error())
|
logger.Log(1, "failed to resolve relay node endpoint: ", err.Error())
|
||||||
}
|
}
|
||||||
|
|
@ -219,7 +219,7 @@ func GetProxyUpdateForHost(host *models.Host) (models.ProxyManagerPayload, error
|
||||||
relayedHost := relayedHost
|
relayedHost := relayedHost
|
||||||
payload, err := GetPeerUpdateForHost(&relayedHost)
|
payload, err := GetPeerUpdateForHost(&relayedHost)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
relayedEndpoint, udpErr := net.ResolveUDPAddr("udp", fmt.Sprintf("%s:%d", relayedHost.EndpointIP, getPeerListenPort(&relayedHost)))
|
relayedEndpoint, udpErr := net.ResolveUDPAddr("udp", fmt.Sprintf("%s:%d", relayedHost.EndpointIP, GetPeerListenPort(&relayedHost)))
|
||||||
if udpErr == nil {
|
if udpErr == nil {
|
||||||
relayPeersMap[relayedHost.PublicKey.String()] = models.RelayedConf{
|
relayPeersMap[relayedHost.PublicKey.String()] = models.RelayedConf{
|
||||||
RelayedPeerEndpoint: relayedEndpoint,
|
RelayedPeerEndpoint: relayedEndpoint,
|
||||||
|
|
@ -259,14 +259,14 @@ func GetProxyUpdateForHost(host *models.Host) (models.ProxyManagerPayload, error
|
||||||
if currPeerConf, found = peerConfMap[peerHost.PublicKey.String()]; !found {
|
if currPeerConf, found = peerConfMap[peerHost.PublicKey.String()]; !found {
|
||||||
currPeerConf = models.PeerConf{
|
currPeerConf = models.PeerConf{
|
||||||
Proxy: peerHost.ProxyEnabled,
|
Proxy: peerHost.ProxyEnabled,
|
||||||
PublicListenPort: int32(getPeerListenPort(peerHost)),
|
PublicListenPort: int32(GetPeerListenPort(peerHost)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if peerHost.IsRelayed && peerHost.RelayedBy != host.ID.String() {
|
if peerHost.IsRelayed && peerHost.RelayedBy != host.ID.String() {
|
||||||
relayHost, err := GetHost(peerHost.RelayedBy)
|
relayHost, err := GetHost(peerHost.RelayedBy)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
relayTo, err := net.ResolveUDPAddr("udp", fmt.Sprintf("%s:%d", relayHost.EndpointIP, getPeerListenPort(relayHost)))
|
relayTo, err := net.ResolveUDPAddr("udp", fmt.Sprintf("%s:%d", relayHost.EndpointIP, GetPeerListenPort(relayHost)))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
currPeerConf.IsRelayed = true
|
currPeerConf.IsRelayed = true
|
||||||
currPeerConf.RelayedTo = relayTo
|
currPeerConf.RelayedTo = relayTo
|
||||||
|
|
@ -375,7 +375,7 @@ func GetPeerUpdateForHost(host *models.Host) (models.HostPeerUpdate, error) {
|
||||||
}
|
}
|
||||||
peerConfig.Endpoint = &net.UDPAddr{
|
peerConfig.Endpoint = &net.UDPAddr{
|
||||||
IP: peerHost.EndpointIP,
|
IP: peerHost.EndpointIP,
|
||||||
Port: getPeerListenPort(peerHost),
|
Port: GetPeerListenPort(peerHost),
|
||||||
}
|
}
|
||||||
|
|
||||||
if uselocal {
|
if uselocal {
|
||||||
|
|
@ -410,6 +410,10 @@ func GetPeerUpdateForHost(host *models.Host) (models.HostPeerUpdate, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if node.IsIngressGateway && peer.IsEgressGateway {
|
||||||
|
hostPeerUpdate.IngressInfo.EgressRanges = append(hostPeerUpdate.IngressInfo.EgressRanges,
|
||||||
|
peer.EgressGatewayRanges...)
|
||||||
|
}
|
||||||
nodePeerMap[peerHost.PublicKey.String()] = models.PeerRouteInfo{
|
nodePeerMap[peerHost.PublicKey.String()] = models.PeerRouteInfo{
|
||||||
PeerAddr: net.IPNet{
|
PeerAddr: net.IPNet{
|
||||||
IP: net.ParseIP(peer.PrimaryAddress()),
|
IP: net.ParseIP(peer.PrimaryAddress()),
|
||||||
|
|
@ -504,7 +508,7 @@ func GetPeerUpdateForHost(host *models.Host) (models.HostPeerUpdate, error) {
|
||||||
return hostPeerUpdate, nil
|
return hostPeerUpdate, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPeerListenPort(host *models.Host) int {
|
func GetPeerListenPort(host *models.Host) int {
|
||||||
peerPort := host.ListenPort
|
peerPort := host.ListenPort
|
||||||
if host.ProxyEnabled {
|
if host.ProxyEnabled {
|
||||||
if host.PublicListenPort != 0 {
|
if host.PublicListenPort != 0 {
|
||||||
|
|
@ -574,7 +578,7 @@ func GetPeerUpdate(node *models.Node, host *models.Host) (models.PeerUpdate, err
|
||||||
Port: peerHost.ListenPort,
|
Port: peerHost.ListenPort,
|
||||||
}
|
}
|
||||||
if peerHost.ProxyEnabled {
|
if peerHost.ProxyEnabled {
|
||||||
peerConfig.Endpoint.Port = getPeerListenPort(peerHost)
|
peerConfig.Endpoint.Port = GetPeerListenPort(peerHost)
|
||||||
}
|
}
|
||||||
if uselocal {
|
if uselocal {
|
||||||
peerConfig.Endpoint.IP = peer.LocalAddress.IP
|
peerConfig.Endpoint.IP = peer.LocalAddress.IP
|
||||||
|
|
@ -707,7 +711,7 @@ func GetPeerUpdateLegacy(node *models.Node) (models.PeerUpdate, error) {
|
||||||
if node.LocalAddress.String() != peer.LocalAddress.String() && peer.LocalAddress.IP != nil {
|
if node.LocalAddress.String() != peer.LocalAddress.String() && peer.LocalAddress.IP != nil {
|
||||||
peerHost.EndpointIP = peer.LocalAddress.IP
|
peerHost.EndpointIP = peer.LocalAddress.IP
|
||||||
if peerHost.ListenPort != 0 {
|
if peerHost.ListenPort != 0 {
|
||||||
peerHost.ListenPort = getPeerListenPort(peerHost)
|
peerHost.ListenPort = GetPeerListenPort(peerHost)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
continue
|
continue
|
||||||
|
|
@ -740,7 +744,7 @@ func GetPeerUpdateLegacy(node *models.Node) (models.PeerUpdate, error) {
|
||||||
// or, if port is for some reason zero use the LocalListenPort
|
// or, if port is for some reason zero use the LocalListenPort
|
||||||
// but only do this if LocalListenPort is not zero
|
// but only do this if LocalListenPort is not zero
|
||||||
if ((!setUDPPort) || peerHost.ListenPort == 0) && peerHost.ListenPort != 0 {
|
if ((!setUDPPort) || peerHost.ListenPort == 0) && peerHost.ListenPort != 0 {
|
||||||
peerHost.ListenPort = getPeerListenPort(peerHost)
|
peerHost.ListenPort = GetPeerListenPort(peerHost)
|
||||||
}
|
}
|
||||||
|
|
||||||
endpoint := peerHost.EndpointIP.String() + ":" + strconv.FormatInt(int64(peerHost.ListenPort), 10)
|
endpoint := peerHost.EndpointIP.String() + ":" + strconv.FormatInt(int64(peerHost.ListenPort), 10)
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,8 @@ type HostPeerUpdate struct {
|
||||||
|
|
||||||
// IngressInfo - struct for ingress info
|
// IngressInfo - struct for ingress info
|
||||||
type IngressInfo struct {
|
type IngressInfo struct {
|
||||||
ExtPeers map[string]ExtClientInfo `json:"ext_peers" yaml:"ext_peers"`
|
ExtPeers map[string]ExtClientInfo `json:"ext_peers" yaml:"ext_peers"`
|
||||||
|
EgressRanges []string `json:"egress_ranges" yaml:"egress_ranges"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// EgressInfo - struct for egress info
|
// EgressInfo - struct for egress info
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue