Page MenuHomePhabricator

net: change CNetAddr::ip to have flexible size

Authored by Fabien on Feb 4 2021, 20:42.


Group Reviewers
Restricted Project
rABCcbe0b91f3e28: net: change CNetAddr::ip to have flexible size
Before this change `CNetAddr::ip` was a fixed-size array of 16 bytes,
not being able to store larger addresses (e.g. TORv3) and encoded
smaller ones as 16-byte IPv6 addresses.

Change its type to `prevector`, so that it can hold larger addresses and
do not disguise non-IPv6 addresses as IPv6. So the IPv4 address
`` is now encoded as `01020304` instead of

Rename `CNetAddr::ip` to `CNetAddr::m_addr` because it is not an "IP" or
"IP address" (TOR addresses are not IP addresses).

In order to preserve backward compatibility with serialization (where
e.g. `` is serialized as `00000000000000000000FFFF01020304`)
introduce `CNetAddr` dedicated legacy serialize/unserialize methods.

Adjust `CSubNet` accordingly. Still use `CSubNet::netmask[]` of fixed 16
bytes, but use the first 4 for IPv4 (not the last 4). Only allow
subnetting for IPv4 and IPv6.

Completes backport (2/2) of core PR19628:

Depends on D9175.

Test Plan
ninja all check-all

ninja bitcoin-fuzzers

Diff Detail

rABC Bitcoin ABC
Lint Not Applicable
Tests Not Applicable

Event Timeline

Fabien requested review of this revision.Feb 4 2021, 20:42
majcosta requested changes to this revision.Feb 4 2021, 23:05
majcosta added a subscriber: majcosta.
majcosta added inline comments.
813–815 ↗(On Diff #27566)

comments on their own line

This revision now requires changes to proceed.Feb 4 2021, 23:05

Improve some comments layout

This revision is now accepted and ready to land.Feb 5 2021, 17:11