---
name: ipv6-address-storage
description: >
  Use when storing, comparing, logging, or parsing IP addresses, designing schemas,
  ACLs, rate limits, or geolocation keys. Enforces 128-bit capable storage, RFC 5952
  canonical text, and avoids IPv4-only CHAR(15), 32-bit ints, and split-on-dot parsers.
---

# IPv6 address representation and storage

## Instructions

1. Prefer binary / structured 128-bit types (`in6_addr`, `sockaddr_storage`, or language equivalents) so one field holds IPv4 or IPv6.
2. If strings are required for interchange, canonicalize at write time (RFC 5952) and compare only normalized values.
3. Never parse or compare addresses with ad-hoc string splits on `.` or similar.
4. Migrate `CHAR(15)`, 32-bit integer IP columns, and dotted-decimal-only validators.
5. Test DB/host ACLs with IPv6 literals and prefixes (colons, optional zones) — MySQL/MariaDB-style host ACLs often break when copied from IPv4 patterns.
6. Treat names, not literals, as the stable application interface when possible (`ipv6-name-resolution`).

## Gotchas

- Production IIDs often look "random"; do not eyeball last hextets for identity — use DNS/IPAM labels and canonical compare.
- IPv4-mapped forms (`::ffff:192.0.2.1`), link-local zones (`fe80::1%eth0`), and compressed vs full text are equivalent only after normalization.
- GeoIP, RUM, and rate-limit keys that assume dotted decimal silently fail or mis-bucket IPv6 clients.
- Tabular display may zero-pad for humans; APIs and storage should still use binary or RFC 5952 text.

## Sibling skills

- `ipv6-ready-coding`
- `ipv6-code-review`

## Source

- Hub: https://www.peachymango.org/ipv6
- Draft anchors: `#address-representation`; IP Address Storage; Databases, ACLs, and Security Tools
- https://datatracker.ietf.org/doc/draft-martin-deploying-ipv6-data-center/
