dyndns: return `nochg` when nothing changed

Open
#1,308 0 comments 1 reaction 0 assignees View on GitHub

Maintainers usually reply within 14 days

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
62/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
api, documentation

Research direction

Start with DynDNS12UpdateView.get in api/desecapi/views/dyndns.py and PDNSChangeTracker in api/desecapi/pdns_change_tracker.py, then check RRset.save_records and RRsetSerializer.update to confirm an unchanged request fires no signal. Add a has_changes check to the tracker and return nochg instead of good when nothing changed. Done means an unchanged update returns nochg, a real change still returns good, and the dyndns docs describe both responses.

Written by the indexing model from the issue text.

Description

api enhancement
Current behaviour

DynDNS12UpdateView.get (api/desecapi/views/dyndns.py:384) always answers good, even when the
request did not change any record. Clients cannot tell a real update from a no-op heartbeat.

dyndns2 defines nochg for this case. ddclient supposedly warns and backs off on nochg, so that's good for our infrastructure.

We could also add per-domain tracking of nochg events, and rate limit them more aggressively / reach out to fix config etc.

Observation

The information is already available when the response is built. On an unchanged request:

  • RRset.save_records (api/desecapi/models/records.py:198) deletes nothing and inserts nothing, so no RR signal fires;
  • RRsetSerializer.update (api/desecapi/serializers/records.py:573) only saves the RRset when the TTL differs, otherwise it bumps touched via a queryset update(), which fires no signal;
  • hence PDNSChangeTracker records nothing and _compute_changes() is empty, so no pdns call and no AXFR.

PDNSChangeTracker.__enter__ resets the tracking dicts; but __exit__ does not clear them, so they can be inspected after the with block.

Suggested change
  1. Add a read-only has_changes property to PDNSChangeTracker (api/desecapi/pdns_change_tracker.py), e.g. any(self._rr_set_additions.values()) or any(self._rr_set_modifications.values()) or any(self._rr_set_deletions.values()) or self._domain_additions or self._domain_deletions (or store the result of _compute_changes() in __exit__).
  2. In DynDNS12UpdateView.get, keep the tracker in a variable and branch on it:
    with PDNSChangeTracker() as tracker:  # requires adding `return self` to `__enter__`
        serializer.save()
    return Response("good" if tracker.has_changes else "nochg", content_type="text/plain")
    
  3. Docs: "If successful, the server will return a response with status 200 OK and a body of either good (records were changed) or nochg (the records already had the requested values), as per the dyndns2 protocol specification."
Detection note

A real address change always deletes at least one RR before inserting the new ones, so the tracker registers it via post_delete even though bulk_create emits no post_save. Creating the RRset on a first update and TTL-only changes fire RRset signals directly. All of these stay good.

Dominant language
Python
Stars
678
Forks
74
Avg merge
7d 23h
Merged PRs (30d)
1

Getting set up

  • Ships a Dockerfile or Docker Compose file
  • No pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from desec-io/desec-stack

All issues in desec-io/desec-stack

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.