From 2a89f4ae75714be354217014ea03f371795ac4c9 Mon Sep 17 00:00:00 2001 From: Sven Luethi Date: Sat, 13 Jun 2026 00:19:45 +0200 Subject: [PATCH] modified: netbox_dns_bridge/request_handler.py modified: netbox_dns_bridge/signals/netbox_dns_zones.py 1. On zone deletion the catalog zone serial was not incremented, causing clients not to delete the zone until another zone is created/modified. Fixed using post_delete signal. 2. Even with the notify_clients feature disabled, the client IPs were still being tracked. This disables the unnecessary behavior. 3. _track_seen_client function in DNSBaseRequestHandler did not have the 'self' reference parameter, causing calls to fail. Fixed. --- netbox_dns_bridge/request_handler.py | 15 ++++++----- netbox_dns_bridge/signals/netbox_dns_zones.py | 26 +++++++++++++------ 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/netbox_dns_bridge/request_handler.py b/netbox_dns_bridge/request_handler.py index 2b098ba..39000dd 100644 --- a/netbox_dns_bridge/request_handler.py +++ b/netbox_dns_bridge/request_handler.py @@ -17,7 +17,7 @@ from netbox_dns_bridge import catalog_zone_manager as catzm from .models import SeenTransferClients logger = get_logger(__name__) - +SETTINGS = settings.PLUGINS_CONFIG["netbox_dns_bridge"] class DNSBaseRequestHandler(socketserver.BaseRequestHandler): def __init__(self, request, client_address, server) -> None: @@ -144,12 +144,13 @@ class DNSBaseRequestHandler(socketserver.BaseRequestHandler): wire = response.to_wire(multi=False) self._send_response(wire) - def _track_seen_client(source_ip: str, view: View) -> None: - SeenTransferClients.objects.update_or_create( - source_ip=source_ip, - view=view, - defaults={"last_seen": timezone.now()}, - ) + def _track_seen_client(self, source_ip: str, view: View) -> None: + if SETTINGS.get("notify_clients", False): + SeenTransferClients.objects.update_or_create( + source_ip=source_ip, + view=view, + defaults={"last_seen": timezone.now()}, + ) def _handle_soa_request(self, query, soa_rrset, zone, peer, nb_view, dname) -> None: # We assume that the SOA rdataset has at least one record (it usually does). diff --git a/netbox_dns_bridge/signals/netbox_dns_zones.py b/netbox_dns_bridge/signals/netbox_dns_zones.py index ccc5326..0056e8d 100644 --- a/netbox_dns_bridge/signals/netbox_dns_zones.py +++ b/netbox_dns_bridge/signals/netbox_dns_zones.py @@ -1,4 +1,4 @@ -from django.db.models.signals import pre_save, post_save +from django.db.models.signals import pre_save, post_save, post_delete from django.dispatch import receiver from django.db import transaction from django.conf import settings @@ -25,13 +25,17 @@ def zone_pre_save(sender, instance, **kwargs): @receiver(post_save, sender=Zone) def zone_post_save(sender, instance, created, **kwargs): zone = instance - request = current_request.get() - handled_zones = getattr(request, "_handled_zones", set()) - if zone.pk in handled_zones: - return - handled_zones.add(zone.pk) - request._handled_zones = handled_zones + # Quit if this is not the first signal in this session for this zone. + request = current_request.get() + if request is not None: + handled_zones = getattr(request, "_handled_zones", set()) + if zone.pk in handled_zones: + return + handled_zones.add(zone.pk) + request._handled_zones = handled_zones + + # On commit, increment soa serial and if notify is enabled, schedule bg job. def _on_commit(): catzm.increment_soa_serial() @@ -41,8 +45,14 @@ def zone_post_save(sender, instance, created, **kwargs): transaction.on_commit(_on_commit) if created: + # If zone was created, create catz member identifier record for this zone. catzm.update_member_identifier(zone) else: + # Check if zone name has changed and change the catz member identifier if so. old_name = getattr(zone, "_old_name", None) - if old_name != zone.name: + if old_name and zone.name != old_name: catzm.update_member_identifier(zone) + +@receiver(post_delete, sender=Zone) +def zone_post_delete(sender, instance, **kwargs): + catzm.increment_soa_serial()