1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// Copyright (c) 2026 Erik Lening (hollowpointer) and Contributors
//
// This file is part of Zond Engine, licensed under the GNU Affero General
// Public License, version 3 or later. See the LICENSE file for details, or
// <https://www.gnu.org/licenses/agpl-3.0.html>.
//
// SPDX-License-Identifier: AGPL-3.0-or-later
//! # Addresses, and the shapes they come in
//!
//! The address half of the vocabulary. [`range`] holds contiguous corridors of
//! addresses, [`set`] holds collections of those corridors with the arithmetic
//! a scan needs over them, and [`scoped`] holds a single address together with
//! the interface it is valid on, without which an IPv6 link-local address
//! cannot be connected to at all.
//!
//! What is left at this level is the one classification question more than one of
//! those three has to agree about: whether an address is globally scoped, which
//! decides whether it names its host from anywhere or only from one segment.
//!
//! That is a question about scope rather than about reachability. An address in a
//! globally routed prefix may be firewalled to nothing, and an address in a
//! private one may be the only way to reach a host. Confusing the two is how a
//! scanner reports a host under an address nobody can open a socket to, which is
//! the failure [`scoped`] exists to prevent.
use Ipv6Addr;
pub use ;
pub use ;
pub use ;
/// Whether `ipv6_addr` falls in `2000::/3`, the range IANA currently allocates
/// global unicast from.
///
/// A membership test rather than a routability claim, which the name invites.
/// `2000::/3` is where global unicast is being handed out today. It is not the
/// whole of what the address architecture reserves for it, and it contains
/// several special-purpose prefixes this does not exclude:
///
/// - `2001:db8::/32`, documentation
/// - `2001::/32`, Teredo, which does turn up on consumer segments
/// - `2002::/16`, 6to4
/// - `2001:2::/48`, benchmarking, and `2001:20::/28`, ORCHIDv2
///
/// Excluding them would be wrong for what this is asked. Every caller wants to
/// know whether an address is globally scoped, meaning it names the host from off
/// the segment rather than naming a different machine on every one, as a
/// link-local does. A Teredo or 6to4 address is globally scoped: unusual, and not
/// local. Filtering them here would report a host under a link-local address it
/// cannot be reached at, to avoid one it can.
///
/// Hand-rolled because `Ipv6Addr::is_unicast_global` is unstable in std, and
/// has been for years.
/// Whether `ipv6_addr` names its host from off the segment it is on.
///
/// The question this module exists to answer, and the one more than one of
/// [`range`], [`set`] and [`scoped`] has to agree about. Global unicast or
/// unique-local: the first names a host wherever the internet reaches and the
/// second wherever an organization's routing does, and for deciding which address
/// identifies a host those are one answer. A link-local names a different machine
/// on every segment and is neither.
///
/// [`Host::consider_primary_ip`](crate::model::host::Host::consider_primary_ip)
/// reads it rather than carrying the unique-local half itself.
/// Whether `addr` is in `fc00::/7`, the range reserved for addresses that are
/// unique across an organization but not routed onto the internet.
// ╔════════════════════════════════════════════╗
// ║ ████████╗███████╗███████╗████████╗███████╗ ║
// ║ ╚══██╔══╝██╔════╝██╔════╝╚══██╔══╝██╔════╝ ║
// ║ ██║ █████╗ ███████╗ ██║ ███████╗ ║
// ║ ██║ ██╔══╝ ╚════██║ ██║ ╚════██║ ║
// ║ ██║ ███████╗███████║ ██║ ███████║ ║
// ║ ╚═╝ ╚══════╝╚══════╝ ╚═╝ ╚══════╝ ║
// ╚════════════════════════════════════════════╝