diff --git a/THIRD-PARTY b/THIRD-PARTY index dedc6f65..1ffd23ca 100644 --- a/THIRD-PARTY +++ b/THIRD-PARTY @@ -1485,7 +1485,7 @@ Apache-2.0 The following npm package may be included in this product: - - ip-address@10.4.0 + - ip-address@10.7.2 This package contains the following license: diff --git a/dist/index.js b/dist/index.js index 0dee821d..8047a758 100644 --- a/dist/index.js +++ b/dist/index.js @@ -49274,6 +49274,8 @@ var require_common2 = __commonJS({ Object.defineProperty(exports2, "__esModule", { value: true }); exports2.isInSubnet = isInSubnet; exports2.isHostInSubnet = isHostInSubnet; + exports2.isGloballyReachable = isGloballyReachable; + exports2.offsetBigInt = offsetBigInt; exports2.isCorrect = isCorrect; exports2.prefixLengthFromMask = prefixLengthFromMask; exports2.assertByteArray = assertByteArray; @@ -49288,8 +49290,34 @@ var require_common2 = __commonJS({ return isHostInSubnet.call(this, address); } function isHostInSubnet(address) { + if (this.binaryZeroPad().length !== address.binaryZeroPad().length) { + return false; + } return this.mask(address.subnetMask) === address.mask(); } + function isGloballyReachable(entries) { + let best = null; + for (let i5 = 0; i5 < entries.length; i5++) { + const entry = entries[i5]; + if (entry.reachable !== null && isHostInSubnet.call(this, entry.subnet) && (best === null || entry.subnet.subnetMask > best.subnet.subnetMask)) { + best = entry; + } + } + return best === null ? true : best.reachable; + } + function offsetBigInt(value, n4, bits, family) { + if (typeof n4 === "number" && !Number.isSafeInteger(n4)) { + throw new address_error_1.AddressError(`${family} offset must be an integer`); + } + if (typeof n4 !== "number" && typeof n4 !== "bigint") { + throw new address_error_1.AddressError(`${family} offset must be an integer`); + } + const result = value + BigInt(n4); + if (result < BigInt(0) || result > (BigInt(1) << BigInt(bits)) - BigInt(1)) { + throw new address_error_1.AddressError(`${family} offset leaves the address space`); + } + return result; + } function isCorrect(defaultBits) { return function isCorrectForm() { if (this.addressMinusSuffix !== this.correctForm()) { @@ -49347,11 +49375,39 @@ var require_constants7 = __commonJS({ "node_modules/ip-address/dist/v4/constants.js"(exports2) { "use strict"; Object.defineProperty(exports2, "__esModule", { value: true }); - exports2.RE_SUBNET_STRING = exports2.RE_ADDRESS = exports2.GROUPS = exports2.BITS = void 0; + exports2.SPECIAL_PURPOSE = exports2.RE_SUBNET_STRING = exports2.RE_ADDRESS = exports2.GROUPS = exports2.BITS = void 0; exports2.BITS = 32; exports2.GROUPS = 4; exports2.RE_ADDRESS = /^(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])$/g; exports2.RE_SUBNET_STRING = /\/\d{1,2}$/; + exports2.SPECIAL_PURPOSE = [ + ["0.0.0.0/8", "This network", false], + ["0.0.0.0/32", "This host on this network", false], + ["10.0.0.0/8", "Private-Use", false], + ["100.64.0.0/10", "Shared Address Space", false], + ["127.0.0.0/8", "Loopback", false], + ["169.254.0.0/16", "Link Local", false], + ["172.16.0.0/12", "Private-Use", false], + ["192.0.0.0/24", "IETF Protocol Assignments", false], + ["192.0.0.0/29", "IPv4 Service Continuity Prefix", false], + ["192.0.0.8/32", "IPv4 dummy address", false], + ["192.0.0.9/32", "Port Control Protocol Anycast", true], + ["192.0.0.10/32", "Traversal Using Relays around NAT Anycast", true], + ["192.0.0.170/32", "NAT64/DNS64 Discovery", false], + ["192.0.0.171/32", "NAT64/DNS64 Discovery", false], + ["192.0.2.0/24", "Documentation (TEST-NET-1)", false], + ["192.31.196.0/24", "AS112-v4", true], + ["192.52.193.0/24", "AMT", true], + ["192.88.99.0/24", "Deprecated (6to4 Relay Anycast)", null], + ["192.88.99.2/32", "6a44-relay anycast address", false], + ["192.168.0.0/16", "Private-Use", false], + ["192.175.48.0/24", "Direct Delegation AS112 Service", true], + ["198.18.0.0/15", "Benchmarking", false], + ["198.51.100.0/24", "Documentation (TEST-NET-2)", false], + ["203.0.113.0/24", "Documentation (TEST-NET-3)", false], + ["240.0.0.0/4", "Reserved", false], + ["255.255.255.255/32", "Limited Broadcast", false] + ]; } }); @@ -49415,6 +49471,10 @@ var require_ipv4 = __commonJS({ } address = address.replace(constants4.RE_SUBNET_STRING, ""); } + const longest = constants4.GROUPS * 4 - 1; + if (address.length > longest) { + throw new address_error_1.AddressError(`IPv4 addresses are at most ${longest} characters.`); + } this.addressMinusSuffix = address; this.parsedAddress = this.parse(address); } @@ -49551,15 +49611,18 @@ var require_ipv4 = __commonJS({ return _Address4.fromHex(integer.toString(16).padStart(8, "0")); } /** - * Return an address from in-addr.arpa form + * Return an address from in-addr.arpa form: the four octets reversed, with + * or without the `.in-addr.arpa` suffix and root dot, in any case. Throws + * `AddressError` unless the reversed labels form a valid IPv4 address, so + * `fromArpa(x.reverseForm())` round-trips {@link reverseForm}. * @param {string} arpaFormAddress - an 'in-addr.arpa' form ipv4 address * @returns {Adress4} * @example - * var address = Address4.fromArpa(42.2.0.192.in-addr.arpa.) + * var address = Address4.fromArpa('42.2.0.192.in-addr.arpa.') * address.correctForm(); // '192.0.2.42' */ static fromArpa(arpaFormAddress) { - const leader = arpaFormAddress.replace(/(\.in-addr\.arpa)?\.$/, ""); + const leader = arpaFormAddress.replace(/(\.in-addr\.arpa)?\.?$/i, ""); const address = leader.split(".").reverse().join("."); return new _Address4(address); } @@ -49622,6 +49685,33 @@ var require_ipv4 = __commonJS({ const adjust = BigInt("1"); return _Address4.fromBigInt(this._startAddress() + adjust); } + /** + * Returns the address `n` addresses after this one (or before, when `n` is + * negative), keeping this address's subnet mask. Throws `AddressError` when + * the result would fall outside the IPv4 address space or `n` is not an + * integer. + * @param {number | bigint} n + * @returns {Address4} + * @example + * new Address4('10.0.0.0/24').offset(1).correctForm(); // '10.0.0.1' + */ + offset(n4) { + return _Address4.fromBigInt(common.offsetBigInt(this.bigInt(), n4, constants4.BITS, "IPv4")).withSubnetMask(this.subnetMask); + } + /** + * Returns the network that follows this address's network: the address after + * {@link endAddress}, with the same subnet mask. Throws `AddressError` when + * this network is the last one in the address space. + * @returns {Address4} + * @example + * new Address4('10.0.0.0/24').nextNetwork().networkForm(); // '10.0.1.0/24' + */ + nextNetwork() { + return _Address4.fromBigInt(common.offsetBigInt(this._endAddress(), 1, constants4.BITS, "IPv4")).withSubnetMask(this.subnetMask); + } + withSubnetMask(subnetMask) { + return new _Address4(`${this.correctForm()}/${subnetMask}`); + } /** * Helper function getting end address. * @returns {bigint} @@ -49685,7 +49775,10 @@ var require_ipv4 = __commonJS({ return _Address4.fromHex(bigInt.toString(16).padStart(8, "0")); } /** - * Convert a byte array to an Address4 object. + * Convert a byte array to an Address4 object. Throws `AddressError` unless + * given exactly 4 integers from 0 to 255. Signed bytes are rejected, so + * this differs from `Address6.fromByteArray`, which folds them; the two + * contracts converge on this stricter form in the next major version. * * To convert from a Node.js `Buffer`, spread it: `Address4.fromByteArray([...buf])`. * @param {Array} bytes - an array of 4 bytes (0-255) @@ -49696,7 +49789,12 @@ var require_ipv4 = __commonJS({ return this.fromUnsignedByteArray(bytes); } /** - * Convert an unsigned byte array to an Address4 object + * Convert an unsigned byte array to an Address4 object. Throws + * `AddressError` unless given exactly 4 bytes, and rejects values outside + * 0 to 255 when parsing the resulting address. + * + * To convert from a Node.js `Buffer`, spread it: + * `Address4.fromUnsignedByteArray([...buf])`. * @param {Array} bytes - an array of 4 unsigned bytes (0-255) * @returns {Address4} */ @@ -49726,7 +49824,8 @@ var require_ipv4 = __commonJS({ return this.binaryZeroPad().slice(start, end2); } /** - * Return the reversed ip6.arpa form of the address + * Return the reversed in-addr.arpa form of the address, e.g. + * `42.2.0.192.in-addr.arpa.` for `192.0.2.42`. * @param {Object} options * @param {boolean} options.omitSuffix - omit the "in-addr.arpa" suffix * @returns {String} @@ -49790,6 +49889,43 @@ var require_ipv4 = __commonJS({ isCGNAT() { return this.isHostInSubnet(CGNAT_V4); } + /** + * Returns true if the address is in one of the documentation ranges + * `192.0.2.0/24`, `198.51.100.0/24`, or `203.0.113.0/24` ([RFC 5737](https://datatracker.ietf.org/doc/html/rfc5737)). + * @returns {boolean} + */ + isDocumentation() { + return DOCUMENTATION_V4.some((subnet) => this.isHostInSubnet(subnet)); + } + /** + * Returns true if the address is in the benchmarking range `198.18.0.0/15` ([RFC 2544](https://datatracker.ietf.org/doc/html/rfc2544)). + * @returns {boolean} + */ + isBenchmarking() { + return this.isHostInSubnet(BENCHMARKING_V4); + } + /** + * Returns true if the address is in the reserved range `240.0.0.0/4` ([RFC 1112](https://datatracker.ietf.org/doc/html/rfc1112)), + * which includes the limited broadcast address. + * @returns {boolean} + */ + isReserved() { + return this.isHostInSubnet(RESERVED_V4); + } + /** + * Returns true if the address is globally reachable: not multicast, and not + * in any block the [IANA IPv4 Special-Purpose Address Registry](https://www.iana.org/assignments/iana-ipv4-special-registry/) + * marks as not globally reachable. That covers everything the individual + * classifiers name (private, loopback, link-local, CGNAT, unspecified, + * broadcast, documentation, benchmarking, reserved) and the blocks they do + * not, such as `0.0.0.0/8` and the IETF protocol assignments in + * `192.0.0.0/24`. This is the single predicate to use where a request must + * not reach an internal or special-purpose destination; see SECURITY.md. + * @returns {boolean} + */ + isGlobal() { + return !this.isMulticast() && common.isGloballyReachable.call(this, SPECIAL_PURPOSE_V4); + } /** * Returns a zero-padded base-2 string representation of the address * @returns {string} @@ -49801,7 +49937,12 @@ var require_ipv4 = __commonJS({ return this._binaryZeroPad; } /** - * Groups an IPv4 address for inclusion at the end of an IPv6 address + * Groups an IPv4 address for inclusion at the end of an IPv6 address. + * + * Returns an HTML fragment: each half of the address is wrapped in a + * `` carrying the group classes an address-inspector UI hovers on. + * The address content is HTML-escaped; anything you concatenate around it + * is your responsibility. * @returns {String} */ groupForV6() { @@ -49821,6 +49962,17 @@ var require_ipv4 = __commonJS({ var UNSPECIFIED_V4 = new Address4("0.0.0.0/32"); var BROADCAST_V4 = new Address4("255.255.255.255/32"); var CGNAT_V4 = new Address4("100.64.0.0/10"); + var DOCUMENTATION_V4 = [ + new Address4("192.0.2.0/24"), + new Address4("198.51.100.0/24"), + new Address4("203.0.113.0/24") + ]; + var BENCHMARKING_V4 = new Address4("198.18.0.0/15"); + var RESERVED_V4 = new Address4("240.0.0.0/4"); + var SPECIAL_PURPOSE_V4 = constants4.SPECIAL_PURPOSE.map(([cidr, , reachable]) => ({ + subnet: new Address4(cidr), + reachable + })); } }); @@ -49829,7 +49981,7 @@ var require_constants8 = __commonJS({ "node_modules/ip-address/dist/v6/constants.js"(exports2) { "use strict"; Object.defineProperty(exports2, "__esModule", { value: true }); - exports2.RE_URL_WITH_PORT = exports2.RE_URL = exports2.RE_ZONE_STRING = exports2.RE_SUBNET_STRING = exports2.RE_BAD_ADDRESS = exports2.RE_BAD_CHARACTERS = exports2.TYPES = exports2.SCOPES = exports2.GROUPS = exports2.BITS = void 0; + exports2.SPECIAL_PURPOSE = exports2.RE_URL_WITH_PORT = exports2.RE_URL = exports2.RE_ZONE_STRING = exports2.RE_SUBNET_STRING = exports2.RE_BAD_ADDRESS = exports2.RE_BAD_CHARACTERS = exports2.TYPES = exports2.SCOPES = exports2.GROUPS = exports2.BITS = void 0; exports2.BITS = 128; exports2.GROUPS = 8; exports2.SCOPES = { @@ -49867,8 +50019,14 @@ var require_constants8 = __commonJS({ "ff00::/8": "Multicast", "fe80::/10": "Link-local unicast", "fc00::/7": "Unique local", + "2001::/32": "Teredo", + "2001:2::/48": "Benchmarking", "2002::/16": "6to4", "2001:db8::/32": "Documentation", + "3fff::/20": "Documentation", + "100::/64": "Discard-only", + "fec0::/10": "Site-local unicast (deprecated)", + "::/96": "IPv4-compatible (deprecated)", "64:ff9b::/96": "NAT64 (well-known)", "64:ff9b:1::/48": "NAT64 (local-use)" }; @@ -49878,6 +50036,33 @@ var require_constants8 = __commonJS({ exports2.RE_ZONE_STRING = /%.*$/; exports2.RE_URL = /^(?:\[([0-9a-f:.]+)\]|([0-9a-f:.]+))(?:[/?#].*)?$/i; exports2.RE_URL_WITH_PORT = /^\[([0-9a-f:.]+)\]:([0-9]{1,5})(?:[/?#].*)?$/i; + exports2.SPECIAL_PURPOSE = [ + ["::1/128", "Loopback Address", false], + ["::/128", "Unspecified Address", false], + ["::ffff:0:0/96", "IPv4-mapped Address", false], + ["64:ff9b::/96", "IPv4-IPv6 Translat.", true], + ["64:ff9b:1::/48", "IPv4-IPv6 Translat.", false], + ["100::/64", "Discard-Only Address Block", false], + ["100:0:0:1::/64", "Dummy IPv6 Prefix", false], + ["2001::/23", "IETF Protocol Assignments", false], + ["2001::/32", "TEREDO", false], + ["2001:1::1/128", "Port Control Protocol Anycast", true], + ["2001:1::2/128", "Traversal Using Relays around NAT Anycast", true], + ["2001:1::3/128", "DNS-SD Service Registration Protocol Anycast", true], + ["2001:2::/48", "Benchmarking", false], + ["2001:3::/32", "AMT", true], + ["2001:4:112::/48", "AS112-v6", true], + ["2001:10::/28", "Deprecated (previously ORCHID)", null], + ["2001:20::/28", "ORCHIDv2", true], + ["2001:30::/28", "Drone Remote ID Protocol Entity Tags (DETs) Prefix", true], + ["2001:db8::/32", "Documentation", false], + ["2002::/16", "6to4", false], + ["2620:4f:8000::/48", "Direct Delegation AS112 Service", true], + ["3fff::/20", "Documentation", false], + ["5f00::/16", "Segment Routing (SRv6) SIDs", false], + ["fc00::/7", "Unique-Local", false], + ["fe80::/10", "Link-Local Unicast", false] + ]; } }); @@ -50125,6 +50310,10 @@ var require_ipv6 = __commonJS({ this.zone = zone[0]; address = address.replace(constants6.RE_ZONE_STRING, ""); } + const longest = this.groups * 5 + 5; + if (address.length > longest) { + throw new address_error_1.AddressError(`IPv6 addresses are at most ${longest} characters.`); + } this.addressMinusSuffix = address; this.parsedAddress = this.parse(this.addressMinusSuffix); } @@ -50179,26 +50368,21 @@ var require_ipv6 = __commonJS({ let host; let port = null; let result; + let error3; const stripped = url.replace(/^[a-z][a-z0-9+.-]*:\/\//i, ""); if (stripped.indexOf("[") !== -1 && stripped.indexOf("]:") !== -1) { + error3 = "failed to parse address with port"; result = constants6.RE_URL_WITH_PORT.exec(stripped); if (result === null) { - return { - error: "failed to parse address with port", - address: null, - port: null - }; + return { error: error3, address: null, port: null }; } host = result[1]; port = result[2]; } else { + error3 = "failed to parse address from URL"; result = constants6.RE_URL.exec(stripped); if (result === null) { - return { - error: "failed to parse address from URL", - address: null, - port: null - }; + return { error: error3, address: null, port: null }; } host = (_a2 = result[1]) !== null && _a2 !== void 0 ? _a2 : result[2]; } @@ -50210,10 +50394,13 @@ var require_ipv6 = __commonJS({ } else { port = null; } - return { - address: new _Address6(host), - port - }; + let address; + try { + address = new _Address6(host); + } catch { + return { error: error3, address: null, port: null }; + } + return { address, port }; } /** * Construct an `Address6` from an address and a hex subnet mask given as @@ -50311,26 +50498,30 @@ var require_ipv6 = __commonJS({ return new _Address6(`::ffff:${address4.correctForm()}/${mask6}`); } /** - * Return an address from ip6.arpa form + * Return an address from ip6.arpa form. A full 32-nibble name gives a /128 + * address; a shorter name, as used for a delegated reverse zone, gives the + * network it covers, with a subnet mask of four bits per nibble, so + * `fromArpa(x.reverseForm())` round-trips {@link reverseForm} for any prefix. * @param {string} arpaFormAddress - an 'ip6.arpa' form address * @returns {Adress6} * @example * var address = Address6.fromArpa(e.f.f.f.3.c.2.6.f.f.f.e.6.6.8.e.1.0.6.7.9.4.e.c.0.0.0.0.1.0.0.2.ip6.arpa.) * address.correctForm(); // '2001:0:ce49:7601:e866:efff:62c3:fffe' + * Address6.fromArpa('8.b.d.0.1.0.0.2.ip6.arpa.').networkForm(); // '2001:db8::/32' */ static fromArpa(arpaFormAddress) { - let address = arpaFormAddress.replace(/(\.ip6\.arpa)?\.$/, ""); - const semicolonAmount = 7; - if (address.length !== 63) { + const nibbles = arpaFormAddress.replace(/(\.ip6\.arpa)?\.?$/i, ""); + if (!/^[0-9a-f](\.[0-9a-f]){0,31}$/i.test(nibbles)) { throw new address_error_1.AddressError("Invalid 'ip6.arpa' form."); } - const parts = address.split(".").reverse(); - for (let i5 = semicolonAmount; i5 > 0; i5--) { - const insertIndex = i5 * 4; - parts.splice(insertIndex, 0, ":"); + const reversed = nibbles.split(".").reverse(); + const subnetMask = reversed.length * 4; + const hex = reversed.join("").padEnd(32, "0"); + const groups = []; + for (let i5 = 0; i5 < constants6.GROUPS; i5++) { + groups.push(hex.slice(i5 * 4, (i5 + 1) * 4)); } - address = parts.join(""); - return new _Address6(address); + return new _Address6(`${groups.join(":")}/${subnetMask}`); } /** * Return the Microsoft UNC transcription of the address @@ -50394,22 +50585,53 @@ var require_ipv6 = __commonJS({ return BigInt(`0b${this.mask() + "1".repeat(constants6.BITS - this.subnetMask)}`); } /** - * The last address in the range given by this address' subnet - * Often referred to as the Broadcast + * The last address in the range given by this address's subnet. IPv6 has + * no broadcast address, so this is an ordinary assignable address (in a + * 64-bit-interface-identifier subnet it falls inside the reserved + * subnet-anycast block of [RFC 2526](https://datatracker.ietf.org/doc/html/rfc2526)). * @returns {Address6} */ endAddress() { return _Address6.fromBigInt(this._endAddress()); } /** - * The last host address in the range given by this address's subnet ie - * the last address prior to the Broadcast Address + * The address one before {@link endAddress}. This is the IPv6 counterpart + * of the IPv4 method that skips the broadcast address; IPv6 has no broadcast, + * so it drops exactly one address and does not model the 128 reserved + * subnet-anycast identifiers of [RFC 2526](https://datatracker.ietf.org/doc/html/rfc2526). * @returns {Address6} */ endAddressExclusive() { const adjust = BigInt("1"); return _Address6.fromBigInt(this._endAddress() - adjust); } + /** + * Returns the address `n` addresses after this one (or before, when `n` is + * negative), keeping this address's subnet mask. Throws `AddressError` when + * the result would fall outside the IPv6 address space or `n` is not an + * integer. + * @param {number | bigint} n + * @returns {Address6} + * @example + * new Address6('2001:db8::/64').offset(1).correctForm(); // '2001:db8::1' + */ + offset(n4) { + return _Address6.fromBigInt(common.offsetBigInt(this.bigInt(), n4, constants6.BITS, "IPv6")).withSubnetMask(this.subnetMask); + } + /** + * Returns the network that follows this address's network: the address after + * {@link endAddress}, with the same subnet mask. Throws `AddressError` when + * this network is the last one in the address space. + * @returns {Address6} + * @example + * new Address6('2001:db8::/64').nextNetwork().networkForm(); // '2001:db8:0:1::/64' + */ + nextNetwork() { + return _Address6.fromBigInt(common.offsetBigInt(this._endAddress(), 1, constants6.BITS, "IPv6")).withSubnetMask(this.subnetMask); + } + withSubnetMask(subnetMask) { + return new _Address6(`${this.correctForm()}/${subnetMask}`); + } /** * The hex form of the subnet mask, e.g. `ffff:ffff:ffff:ffff::` for a * `/64`. Returns an `Address6`; call `.correctForm()` for the string. @@ -50933,7 +51155,10 @@ var require_ipv6 = __commonJS({ return this.addressMinusSuffix === this.canonicalForm(); } /** - * Returns true if the address is a link local address, false otherwise + * Returns true if the address is a link-local unicast address in `fe80::/10` + * ([RFC 4291 ยง2.4](https://datatracker.ietf.org/doc/html/rfc4291#section-2.4)) + * or an IPv4-mapped / NAT64 address whose embedded IPv4 address is link-local + * (`169.254.0.0/16`, e.g. `::ffff:169.254.169.254`), false otherwise. * @returns {boolean} */ isLinkLocal() { @@ -50941,10 +51166,7 @@ var require_ipv6 = __commonJS({ if (embedded) { return embedded.isLinkLocal(); } - if (this.getBitsBase2(0, 64) === "1111111010000000000000000000000000000000000000000000000000000000") { - return true; - } - return false; + return this.isHostInSubnet(LINK_LOCAL_SUBNET); } /** * Returns true if the address is a multicast address, false otherwise @@ -51036,12 +51258,20 @@ var require_ipv6 = __commonJS({ } /** * Returns true if the address is private, i.e. a Unique Local Address in - * `fc00::/7` ([RFC 4193](https://datatracker.ietf.org/doc/html/rfc4193)) or an - * IPv4-mapped / NAT64 address whose embedded IPv4 address is in one of the - * [RFC 1918](https://datatracker.ietf.org/doc/html/rfc1918) private ranges - * (e.g. `::ffff:10.0.0.1`). This is the IPv6 counterpart to + * `fc00::/7` ([RFC 4193](https://datatracker.ietf.org/doc/html/rfc4193)), an + * address in the NAT64 local-use range `64:ff9b:1::/48` + * ([RFC 8215](https://datatracker.ietf.org/doc/html/rfc8215)), or an + * IPv4-mapped / NAT64 well-known address whose embedded IPv4 address is in + * one of the [RFC 1918](https://datatracker.ietf.org/doc/html/rfc1918) + * private ranges (e.g. `::ffff:10.0.0.1`). This is the IPv6 counterpart to * {@link Address4.isPrivate}; use it instead of {@link isULA} when you need to * catch mapped RFC 1918 addresses as well as native ULAs. + * + * The local-use NAT64 range is reported private as a whole rather than by + * its embedded IPv4 address: an operator may carve a prefix of any RFC 6052 + * length out of `64:ff9b:1::/48`, so the same bits decode to different IPv4 + * addresses under different deployments and no single decoding is correct. + * Use {@link toAddress4Nat64} with the deployment's prefix to decode one. * @returns {boolean} */ isPrivate() { @@ -51049,7 +51279,7 @@ var require_ipv6 = __commonJS({ if (embedded) { return embedded.isPrivate(); } - return this.isULA(); + return this.isULA() || this.isHostInSubnet(NAT64_LOCAL_USE_SUBNET); } /** * Returns true if the address is an IPv4-mapped / NAT64 address whose embedded @@ -51097,7 +51327,48 @@ var require_ipv6 = __commonJS({ * @returns {boolean} */ isDocumentation() { - return this.isHostInSubnet(DOCUMENTATION_SUBNET); + return DOCUMENTATION_SUBNETS.some((subnet) => this.isHostInSubnet(subnet)); + } + /** + * Returns true if the address is in the benchmarking range `2001:2::/48` + * ([RFC 5180](https://datatracker.ietf.org/doc/html/rfc5180)) or is an + * IPv4-mapped / NAT64 address whose embedded IPv4 address is in + * `198.18.0.0/15`, false otherwise. + * @returns {boolean} + */ + isBenchmarking() { + const embedded = this.embeddedIPv4(); + if (embedded) { + return embedded.isBenchmarking(); + } + return this.isHostInSubnet(BENCHMARKING_SUBNET); + } + /** + * Returns true if the address is globally reachable: inside the global + * unicast allocation `2000::/3` (the only range the [IANA IPv6 Address Space + * Registry](https://www.iana.org/assignments/ipv6-address-space/) assigns + * for global unicast; everything else is reserved, ULA, link-local, or + * multicast) and not in any block the [IANA IPv6 Special-Purpose Address Registry](https://www.iana.org/assignments/iana-ipv6-special-registry/) + * marks as not globally reachable. An IPv4-mapped or NAT64 well-known + * address answers for its embedded IPv4 address, so `::ffff:10.0.0.1` and + * `64:ff9b::7f00:1` are not global. Teredo (`2001::/32`) and 6to4 + * (`2002::/16`) are not global either: the registry lists them as N/A and a + * packet to one needs a relay. + * + * This covers everything the individual classifiers name and the blocks they + * do not: the discard-only prefix `100::/64`, the IETF protocol assignments + * in `2001::/23`, the deprecated site-local `fec0::/10` and IPv4-compatible + * `::/96` ranges, and unallocated space such as `4000::/3`. It is the single + * predicate to use where a request must not reach an internal or + * special-purpose destination; see SECURITY.md. + * @returns {boolean} + */ + isGlobal() { + const embedded = this.embeddedIPv4(); + if (embedded) { + return embedded.isGlobal(); + } + return this.isHostInSubnet(GLOBAL_UNICAST_SUBNET) && common.isGloballyReachable.call(this, SPECIAL_PURPOSE_V6); } // #endregion // #region HTML @@ -51149,7 +51420,12 @@ var require_ipv6 = __commonJS({ return `${safeForm}`; } /** - * Groups an address + * Groups an address. + * + * Returns an HTML fragment: each group is wrapped in a `` carrying + * the group classes an address-inspector UI hovers on. The address content + * is HTML-escaped; anything you concatenate around it is your + * responsibility. * @returns {String} */ group() { @@ -51240,9 +51516,17 @@ var require_ipv6 = __commonJS({ var TEREDO_SUBNET = new Address6("2001::/32"); var SIX_TO_FOUR_SUBNET = new Address6("2002::/16"); var ULA_SUBNET = new Address6("fc00::/7"); - var DOCUMENTATION_SUBNET = new Address6("2001:db8::/32"); + var LINK_LOCAL_SUBNET = new Address6("fe80::/10"); + var DOCUMENTATION_SUBNETS = [new Address6("2001:db8::/32"), new Address6("3fff::/20")]; + var BENCHMARKING_SUBNET = new Address6("2001:2::/48"); + var GLOBAL_UNICAST_SUBNET = new Address6("2000::/3"); + var SPECIAL_PURPOSE_V6 = constants6.SPECIAL_PURPOSE.map(([cidr, , reachable]) => ({ + subnet: new Address6(cidr), + reachable + })); var IPV4_MAPPED_SUBNET = new Address6("::ffff:0:0/96"); var NAT64_WELL_KNOWN_SUBNET = new Address6("64:ff9b::/96"); + var NAT64_LOCAL_USE_SUBNET = new Address6("64:ff9b:1::/48"); } });