Skip to content

Commit

Permalink
disallow node acting using inet gw to act as inet gw
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishek9686 committed Feb 26, 2024
1 parent 36d5ab2 commit 331ef1a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
4 changes: 2 additions & 2 deletions pro/controllers/inet_gws.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func createInternetGw(w http.ResponseWriter, r *http.Request) {
logic.ReturnErrorResponse(w, r, logic.FormatError(errors.New("only linux nodes can be made internet gws"), "badrequest"))
return
}
err = proLogic.ValidateInetGwReq(node, request)
err = proLogic.ValidateInetGwReq(node, request, false)
if err != nil {
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "badrequest"))
return
Expand Down Expand Up @@ -109,7 +109,7 @@ func updateInternetGw(w http.ResponseWriter, r *http.Request) {
logic.ReturnErrorResponse(w, r, logic.FormatError(errors.New("node is not a internet gw"), "badrequest"))
return
}
err = proLogic.ValidateInetGwReq(node, request)
err = proLogic.ValidateInetGwReq(node, request, true)
if err != nil {
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "badrequest"))
return
Expand Down
13 changes: 10 additions & 3 deletions pro/logic/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"golang.org/x/exp/slog"
)

func ValidateInetGwReq(inetNode models.Node, req models.InetNodeReq) error {
func ValidateInetGwReq(inetNode models.Node, req models.InetNodeReq, update bool) error {
for _, clientNodeID := range req.InetNodeClientIDs {
clientNode, err := logic.GetNodeByID(clientNodeID)
if err != nil {
Expand All @@ -26,9 +26,16 @@ func ValidateInetGwReq(inetNode models.Node, req models.InetNodeReq) error {
if clientNode.IsInternetGateway {
return fmt.Errorf("node %s acting as internet gateway cannot use another internet gateway", clientHost.Name)
}
if clientNode.InternetGwID != "" && clientNode.InternetGwID != inetNode.ID.String() {
return fmt.Errorf("node %s is already using a internet gateway", clientHost.Name)
if update {
if clientNode.InternetGwID != "" && clientNode.InternetGwID != inetNode.ID.String() {
return fmt.Errorf("node %s is already using a internet gateway", clientHost.Name)
}
} else {
if clientNode.InternetGwID != "" {
return fmt.Errorf("node %s is already using a internet gateway", clientHost.Name)
}
}

if clientNode.IsRelayed {
return fmt.Errorf("node %s is being relayed", clientHost.Name)
}
Expand Down

0 comments on commit 331ef1a

Please sign in to comment.