HomePhabricator

net: don't accept non-left-contiguous netmasks

Description

net: don't accept non-left-contiguous netmasks

Summary:

A netmask that contains 1-bits after 0-bits (the 1-bits are not
contiguous on the left side) is invalid [1] [2].

The code before this PR used to parse and accept such
non-left-contiguous netmasks. However, a coming change that will alter
`CNetAddr::ip` to have flexible size would make juggling with such
netmasks more difficult, thus drop support for those.

[1] https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing#Subnet_masks
[2] https://tools.ietf.org/html/rfc4632#section-5.1

Partial backport (1/2) of core PR19628:
https://github.com/bitcoin/bitcoin/pull/19628/commits/1ea57ad67406b3aaaef5254bc2fa7e4134f3a6df

Depends on D9172.

Test Plan:

ninja all check-all

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Differential Revision: https://reviews.bitcoinabc.org/D9175

Details

Provenance
Vasil Dimov <vd@FreeBSD.org>Authored on Aug 24 2020, 19:03
FabienCommitted on Feb 5 2021, 17:33
FabienPushed on Feb 5 2021, 17:35
Reviewer
Restricted Project
Differential Revision
D9175: net: don't accept non-left-contiguous netmasks
Parents
rABCb4c94da5b58e: net: save the network type explicitly in CNetAddr
Branches
Unknown
Tags
Unknown