mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-18 16:26:38 +00:00
[management] fix network map dns filter (#4547)
This commit is contained in:
@@ -20,29 +20,9 @@ import (
|
|||||||
|
|
||||||
// DNSConfigCache is a thread-safe cache for DNS configuration components
|
// DNSConfigCache is a thread-safe cache for DNS configuration components
|
||||||
type DNSConfigCache struct {
|
type DNSConfigCache struct {
|
||||||
CustomZones sync.Map
|
|
||||||
NameServerGroups sync.Map
|
NameServerGroups sync.Map
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetCustomZone retrieves a cached custom zone
|
|
||||||
func (c *DNSConfigCache) GetCustomZone(key string) (*proto.CustomZone, bool) {
|
|
||||||
if c == nil {
|
|
||||||
return nil, false
|
|
||||||
}
|
|
||||||
if value, ok := c.CustomZones.Load(key); ok {
|
|
||||||
return value.(*proto.CustomZone), true
|
|
||||||
}
|
|
||||||
return nil, false
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetCustomZone stores a custom zone in the cache
|
|
||||||
func (c *DNSConfigCache) SetCustomZone(key string, value *proto.CustomZone) {
|
|
||||||
if c == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
c.CustomZones.Store(key, value)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetNameServerGroup retrieves a cached name server group
|
// GetNameServerGroup retrieves a cached name server group
|
||||||
func (c *DNSConfigCache) GetNameServerGroup(key string) (*proto.NameServerGroup, bool) {
|
func (c *DNSConfigCache) GetNameServerGroup(key string) (*proto.NameServerGroup, bool) {
|
||||||
if c == nil {
|
if c == nil {
|
||||||
@@ -212,14 +192,8 @@ func toProtocolDNSConfig(update nbdns.Config, cache *DNSConfigCache) *proto.DNSC
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, zone := range update.CustomZones {
|
for _, zone := range update.CustomZones {
|
||||||
cacheKey := zone.Domain
|
protoZone := convertToProtoCustomZone(zone)
|
||||||
if cachedZone, exists := cache.GetCustomZone(cacheKey); exists {
|
protoUpdate.CustomZones = append(protoUpdate.CustomZones, protoZone)
|
||||||
protoUpdate.CustomZones = append(protoUpdate.CustomZones, cachedZone)
|
|
||||||
} else {
|
|
||||||
protoZone := convertToProtoCustomZone(zone)
|
|
||||||
cache.SetCustomZone(cacheKey, protoZone)
|
|
||||||
protoUpdate.CustomZones = append(protoUpdate.CustomZones, protoZone)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, nsGroup := range update.NameServerGroups {
|
for _, nsGroup := range update.NameServerGroups {
|
||||||
|
|||||||
@@ -474,15 +474,6 @@ func TestToProtocolDNSConfigWithCache(t *testing.T) {
|
|||||||
t.Errorf("Results should be different for different inputs")
|
t.Errorf("Results should be different for different inputs")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify that the cache contains elements from both configs
|
|
||||||
if _, exists := cache.GetCustomZone("example.com"); !exists {
|
|
||||||
t.Errorf("Cache should contain custom zone for example.com")
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, exists := cache.GetCustomZone("example.org"); !exists {
|
|
||||||
t.Errorf("Cache should contain custom zone for example.org")
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, exists := cache.GetNameServerGroup("group1"); !exists {
|
if _, exists := cache.GetNameServerGroup("group1"); !exists {
|
||||||
t.Errorf("Cache should contain name server group 'group1'")
|
t.Errorf("Cache should contain name server group 'group1'")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -300,7 +300,6 @@ func (a *Account) GetPeerNetworkMap(
|
|||||||
|
|
||||||
if dnsManagementStatus {
|
if dnsManagementStatus {
|
||||||
var zones []nbdns.CustomZone
|
var zones []nbdns.CustomZone
|
||||||
|
|
||||||
if peersCustomZone.Domain != "" {
|
if peersCustomZone.Domain != "" {
|
||||||
records := filterZoneRecordsForPeers(peer, peersCustomZone, peersToConnect)
|
records := filterZoneRecordsForPeers(peer, peersCustomZone, peersToConnect)
|
||||||
zones = append(zones, nbdns.CustomZone{
|
zones = append(zones, nbdns.CustomZone{
|
||||||
|
|||||||
Reference in New Issue
Block a user