Skip to content

Render IPv4-embedded inet6 values as inet_out does - #280

Merged
serprex merged 1 commit into
ClickHouse:mainfrom
RaphaelFakhri:fix-inet-mapped-ipv4-text
Oct 28, 2026
Merged

serprex merged 1 commit into
ClickHouse:mainfrom
RaphaelFakhri:fix-inet-mapped-ipv4-text

Conversation

@RaphaelFakhri

Copy link
Copy Markdown
Contributor

Streamed inet and cidr values don't match PostgreSQL inet_out when an IPv6 address embeds an IPv4 address. inet_out prints the last 32 bits of an IPv4-mapped (::ffff:a.b.c.d) or IPv4-compatible (::a.b.c.d) address as a dotted quad. The WAL decoder printed them as hex groups, and both types land in a ClickHouse String column.

Value inet_out Streamed before
'::ffff:192.168.0.1'::inet ::ffff:192.168.0.1 ::ffff:c0a8:1
'::ffff:192.168.0.1/120'::inet ::ffff:192.168.0.1/120 ::ffff:c0a8:1/120
'::192.168.0.1'::inet ::192.168.0.1 ::c0a8:1

write_ipv6 now follows the encapsulated IPv4 check in inet_net_ntop_ipv6 (src/port/inet_net_ntop.c): when the longest zero run starts the address and covers six groups, or five groups followed by ffff, the last four bytes print as a dotted quad. PostgreSQL's third branch (best.len == 7) can't be reached at group 6, because that group falls inside the zero run. Other addresses render as before.

Testing

  • inet_ipv6_embedded_ipv4_keeps_dotted_quad checks the rows above, plus ::fffe:c0a8:1, which must stay hex. It fails on main and passes with this change.
  • cargo test --lib codecs::inet, cargo fmt --all -- --check and cargo clippy --lib --tests -- -D warnings pass.

Fixes #279

inet_out prints the last 32 bits of an IPv4-compatible (::a.b.c.d) or
IPv4-mapped (::ffff:a.b.c.d) address as a dotted quad. The decoder
rendered them as hex groups, so a streamed ::ffff:192.168.0.1 reached
ClickHouse as ::ffff:c0a8:1.

Optimize out allocating Vec, & work with constant sized chunks

Co-Authored-By: serprex <159546+serprex@users.noreply.github.com>
@serprex
serprex force-pushed the fix-inet-mapped-ipv4-text branch from 9836f16 to 219d20c Compare October 28, 2026 11:17
@serprex
serprex merged commit 8848f9b into ClickHouse:main Oct 28, 2026
5 checks passed
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.

Streamed IPv4-mapped inet6 values render as hex instead of a dotted quad

3 participants