Skip to content

Commit

Permalink
Merge pull request #3210 from gravitl/release-v0.26.0
Browse files Browse the repository at this point in the history
Release v0.26.0
  • Loading branch information
abhishek9686 authored Nov 18, 2024
2 parents e33b415 + 0351434 commit efc243b
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 1 deletion.
5 changes: 5 additions & 0 deletions controllers/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,11 @@ func deleteTag(w http.ResponseWriter, r *http.Request) {
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "badrequest"))
return
}
// check if active policy is using the tag
if logic.CheckIfTagAsActivePolicy(tag.ID, tag.Network) {
logic.ReturnErrorResponse(w, r, logic.FormatError(errors.New("tag is currently in use by an active policy"), "badrequest"))
return
}
err = logic.DeleteTag(models.TagID(tagID), true)
if err != nil {
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "internal"))
Expand Down
19 changes: 19 additions & 0 deletions logic/acls.go
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,25 @@ func UpdateDeviceTag(OldID, newID models.TagID, netID models.NetworkID) {
}
}

func CheckIfTagAsActivePolicy(tagID models.TagID, netID models.NetworkID) bool {
acls := listDevicePolicies(netID)
for _, acl := range acls {
for _, srcTagI := range acl.Src {
if srcTagI.ID == models.DeviceAclID {
if tagID.String() == srcTagI.Value {
return true
}
}
}
for _, dstTagI := range acl.Dst {
if dstTagI.ID == models.DeviceAclID {
return true
}
}
}
return false
}

// RemoveDeviceTagFromAclPolicies - remove device tag from acl policies
func RemoveDeviceTagFromAclPolicies(tagID models.TagID, netID models.NetworkID) error {
acls := listDevicePolicies(netID)
Expand Down
3 changes: 3 additions & 0 deletions logic/acls/nodeacls/modify.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ func CreateNodeACL(networkID NetworkID, nodeID NodeID, defaultVal byte) (acls.AC
acls.AclMutex.Lock()
var newNodeACL = make(acls.ACL)
for existingNodeID := range currentNetworkACL {
if currentNetworkACL[existingNodeID] == nil {
currentNetworkACL[existingNodeID] = make(acls.ACL)
}
currentNetworkACL[existingNodeID][acls.AclID(nodeID)] = defaultVal // set the old nodes to default value for new node
newNodeACL[existingNodeID] = defaultVal // set the old nodes in new node ACL to default value
}
Expand Down
32 changes: 31 additions & 1 deletion logic/extpeers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package logic

import (
"encoding/json"
"errors"
"fmt"
"net"
"reflect"
"strings"
"sync"
"time"

"github.com/goombaio/namegenerator"
"github.com/gravitl/netmaker/database"
"github.com/gravitl/netmaker/logger"
"github.com/gravitl/netmaker/logic/acls"
Expand Down Expand Up @@ -281,13 +283,41 @@ func CreateExtClient(extclient *models.ExtClient) error {
}

if extclient.ClientID == "" {
extclient.ClientID = models.GenerateNodeName()
extclient.ClientID, err = GenerateNodeName(extclient.Network)
if err != nil {
return err
}
}

extclient.LastModified = time.Now().Unix()
return SaveExtClient(extclient)
}

// GenerateNodeName - generates a random node name
func GenerateNodeName(network string) (string, error) {
seed := time.Now().UTC().UnixNano()
nameGenerator := namegenerator.NewNameGenerator(seed)
var name string
cnt := 0
for {
if cnt > 10 {
return "", errors.New("couldn't generate random name, try again")
}
cnt += 1
name = nameGenerator.Generate()
if len(name) > 15 {
continue
}
_, err := GetExtClient(name, network)
if err == nil {
// config exists with same name
continue
}
break
}
return name, nil
}

// SaveExtClient - saves an ext client to database
func SaveExtClient(extclient *models.ExtClient) error {
key, err := GetRecordKey(extclient.ClientID, extclient.Network)
Expand Down
7 changes: 7 additions & 0 deletions logic/peers.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,13 @@ func GetPeerUpdateForHost(network string, host *models.Host, allNodes []models.N
peerEndpoint = peerHost.EndpointIPv6
}
}
if node.IsRelay && peer.RelayedBy == node.ID.String() && !peer.IsStatic {
// don't set endpoint on relayed peer
peerEndpoint = nil
}
if isFailOverPeer && peer.FailedOverBy == node.ID && !peer.IsStatic {
peerEndpoint = nil
}

peerConfig.Endpoint = &net.UDPAddr{
IP: peerEndpoint,
Expand Down

0 comments on commit efc243b

Please sign in to comment.