Skip to content

fix: Fix NAME cache IPv4/IPv6 key collisions and IPv6 SQLite overflow - #3198

Open
digrajpu wants to merge 1 commit into
developfrom
fix/name_cache
Open

fix: Fix NAME cache IPv4/IPv6 key collisions and IPv6 SQLite overflow#3198
digrajpu wants to merge 1 commit into
developfrom
fix/name_cache

Conversation

@digrajpu

@digrajpu digrajpu commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator

The NAME cache was converting SOURCEIP to a plain integer before storing it as a SQLite key. This caused two bugs:

  • Key collision: 0.0.0.1 and ::1 both produce integer 1, so they shared the same cache row and could overwrite each other's hostname.
  • IPv6 failure: Most IPv6 addresses require 128 bits, exceeding SQLite's signed 64-bit integer limit, causing an OverflowError on write.

Fix: Replace the integer key with a family-tagged string (v4:192.0.2.2, v6:2001:db8::1) generated by ip_cache_key() using Python's ipaddress module. This guarantees no cross-family collisions and stores safely as a string in SQLite. Existing caches will cold-repopulate under the new key namespace; operators can use SC4S_CLEAR_NAME_CACHE=yes for a one-time cleanup on upgrade.

@Kawron

Kawron commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

@digrajpu please add description to this PR

@Kawron

Kawron commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator

Code lgtm, but have you tested it manually? I think it will be worth doing to make sure we don't break anything

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants