mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-05 08:47:35 +08:00
NET-1224:add egressGW ip for setroutes (#2933)
* add egressGW ip for setroutes * fix peer endpoint selection --------- Co-authored-by: abhishek9686 <abhi281342@gmail.com>
This commit is contained in:
@@ -475,6 +475,9 @@ func getExtpeersExtraRoutes(network string) (egressRoutes []models.EgressNetwork
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, extPeer := range extPeers {
|
for _, extPeer := range extPeers {
|
||||||
|
if len(extPeer.ExtraAllowedIPs) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
egressRoutes = append(egressRoutes, getExtPeerEgressRoute(extPeer)...)
|
egressRoutes = append(egressRoutes, getExtPeerEgressRoute(extPeer)...)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
@@ -173,9 +173,11 @@ func GetPeerUpdateForHost(network string, host *models.Host, allNodes []models.N
|
|||||||
}
|
}
|
||||||
if peer.IsEgressGateway {
|
if peer.IsEgressGateway {
|
||||||
hostPeerUpdate.EgressRoutes = append(hostPeerUpdate.EgressRoutes, models.EgressNetworkRoutes{
|
hostPeerUpdate.EgressRoutes = append(hostPeerUpdate.EgressRoutes, models.EgressNetworkRoutes{
|
||||||
NodeAddr: node.Address,
|
EgressGwAddr: peer.Address,
|
||||||
NodeAddr6: node.Address6,
|
EgressGwAddr6: peer.Address6,
|
||||||
EgressRanges: peer.EgressGatewayRanges,
|
NodeAddr: node.Address,
|
||||||
|
NodeAddr6: node.Address6,
|
||||||
|
EgressRanges: peer.EgressGatewayRanges,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if peer.IsIngressGateway {
|
if peer.IsIngressGateway {
|
||||||
@@ -213,16 +215,15 @@ func GetPeerUpdateForHost(network string, host *models.Host, allNodes []models.N
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//1. check currHost has ipv4 endpoint and peerhost has ipv4 then set ipv4 endpoint for peer
|
||||||
|
// 2. check currHost has ipv6 endpoint and peerhost has ipv6 then set ipv6 endpoint for peer
|
||||||
|
|
||||||
//if host is ipv4 only or ipv4+ipv6, set the peer endpoint to ipv4 address, if host is ipv6 only, set the peer endpoint to ipv6 address
|
//if host is ipv4 only or ipv4+ipv6, set the peer endpoint to ipv4 address, if host is ipv6 only, set the peer endpoint to ipv6 address
|
||||||
peerEndpoint := peerHost.EndpointIP
|
var peerEndpoint net.IP
|
||||||
if ipv4 := host.EndpointIP.To4(); ipv4 != nil {
|
if host.EndpointIP != nil && peerHost.EndpointIP != nil {
|
||||||
peerEndpoint = peerHost.EndpointIP
|
peerEndpoint = peerHost.EndpointIP
|
||||||
} else {
|
} else if host.EndpointIPv6 != nil && peerHost.EndpointIPv6 != nil {
|
||||||
//if peer host's ipv6 address is empty, it means that peer is an IPv4 only host
|
peerEndpoint = peerHost.EndpointIPv6
|
||||||
//IPv4 only host could not communicate with IPv6 only host
|
|
||||||
if peerHost.EndpointIPv6 != nil && peerHost.EndpointIPv6.String() != "" {
|
|
||||||
peerEndpoint = peerHost.EndpointIPv6
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
peerConfig.Endpoint = &net.UDPAddr{
|
peerConfig.Endpoint = &net.UDPAddr{
|
||||||
|
@@ -44,9 +44,11 @@ type EgressInfo struct {
|
|||||||
|
|
||||||
// EgressNetworkRoutes - struct for egress network routes for adding routes to peer's interface
|
// EgressNetworkRoutes - struct for egress network routes for adding routes to peer's interface
|
||||||
type EgressNetworkRoutes struct {
|
type EgressNetworkRoutes struct {
|
||||||
NodeAddr net.IPNet `json:"node_addr"`
|
EgressGwAddr net.IPNet `json:"egress_gw_addr" yaml:"egress_gw_addr"`
|
||||||
NodeAddr6 net.IPNet `json:"node_addr6"`
|
EgressGwAddr6 net.IPNet `json:"egress_gw_addr6" yaml:"egress_gw_addr6"`
|
||||||
EgressRanges []string `json:"egress_ranges"`
|
NodeAddr net.IPNet `json:"node_addr"`
|
||||||
|
NodeAddr6 net.IPNet `json:"node_addr6"`
|
||||||
|
EgressRanges []string `json:"egress_ranges"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// PeerRouteInfo - struct for peer info for an ext. client
|
// PeerRouteInfo - struct for peer info for an ext. client
|
||||||
|
Reference in New Issue
Block a user