Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NET-822: Add extra data for RAC gws resp #2732

Merged
merged 3 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions logic/extpeers.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,3 +438,35 @@ func getExtpeersExtraRoutes(network string) (egressRoutes []models.EgressNetwork
}
return
}

func GetExtclientAllowedIPs(client models.ExtClient) (allowedIPs []string) {
gwnode, err := GetNodeByID(client.IngressGatewayID)
if err != nil {
logger.Log(0,
fmt.Sprintf("failed to get ingress gateway node [%s] info: %v", client.IngressGatewayID, err))
return
}

network, err := GetParentNetwork(client.Network)
if err != nil {
logger.Log(1, "Could not retrieve Ingress Gateway Network", client.Network)
return
}
if IsInternetGw(gwnode) {
egressrange := "0.0.0.0/0"
if gwnode.Address6.IP != nil && client.Address6 != "" {
egressrange += "," + "::/0"
}
allowedIPs = []string{egressrange}
} else {
allowedIPs = []string{network.AddressRange}

if network.AddressRange6 != "" {
allowedIPs = append(allowedIPs, network.AddressRange6)
}
if egressGatewayRanges, err := GetEgressRangesOnNetwork(&client); err == nil {
allowedIPs = append(allowedIPs, egressGatewayRanges...)
}
}
return
}
1 change: 1 addition & 0 deletions models/extclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type ExtClient struct {
Address string `json:"address" bson:"address"`
Address6 string `json:"address6" bson:"address6"`
ExtraAllowedIPs []string `json:"extraallowedips" bson:"extraallowedips"`
AllowedIPs []string `json:"allowed_ips"`
IngressGatewayID string `json:"ingressgatewayid" bson:"ingressgatewayid"`
IngressGatewayEndpoint string `json:"ingressgatewayendpoint" bson:"ingressgatewayendpoint"`
LastModified int64 `json:"lastmodified" bson:"lastmodified"`
Expand Down
1 change: 1 addition & 0 deletions models/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ type UserRemoteGws struct {
Connected bool `json:"connected"`
IsInternetGateway bool `json:"is_internet_gateway"`
GwClient ExtClient `json:"gw_client"`
GwPeerPublicKey string `json:"gw_peer_public_key"`
}

// UserRemoteGwsReq - struct to hold user remote acccess gws req
Expand Down
4 changes: 3 additions & 1 deletion pro/controllers/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,15 @@ func getUserRemoteAccessGws(w http.ResponseWriter, r *http.Request) {

if _, ok := user.RemoteGwIDs[node.ID.String()]; ok {
gws := userGws[node.Network]

extClient.AllowedIPs = logic.GetExtclientAllowedIPs(extClient)
gws = append(gws, models.UserRemoteGws{
GwID: node.ID.String(),
GWName: host.Name,
Network: node.Network,
GwClient: extClient,
Connected: true,
IsInternetGateway: node.IsInternetGateway,
GwPeerPublicKey: host.PublicKey.String(),
})
userGws[node.Network] = gws
delete(user.RemoteGwIDs, node.ID.String())
Expand Down Expand Up @@ -235,6 +236,7 @@ func getUserRemoteAccessGws(w http.ResponseWriter, r *http.Request) {
GWName: host.Name,
Network: node.Network,
IsInternetGateway: node.IsInternetGateway,
GwPeerPublicKey: host.PublicKey.String(),
})
userGws[node.Network] = gws
}
Expand Down