From ab2432ae31593c3045afbc25a112037ea40122a1 Mon Sep 17 00:00:00 2001 From: BPplays Date: Mon, 30 Sep 2024 11:47:20 -0700 Subject: [PATCH 001/115] started adding nat64 prefix --- Makefile | 6 ++++++ src/background.js | 1 + src/common.js | 1 + src/options.html | 17 +++++++++++++++-- src/options.js | 9 ++++++++- 5 files changed, 31 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 9d57ac5..a89e500 100644 --- a/Makefile +++ b/Makefile @@ -28,5 +28,11 @@ chrome: prepare cp -f ${MANIFEST_C} ${MANIFEST} zip -9j ${BUILDDIR}${NAME}-${VERSION_C}.zip -j src/* + rm -rf ${BUILDDIR}${NAME}-${VERSION_C} + cp -f ${MANIFEST_C} ${MANIFEST} + # zip -9j ${BUILDDIR}${NAME}-${VERSION_C}.zip -j src/* + mkdir -p ${BUILDDIR}${NAME}-${VERSION_C} + cp -r src/* ${BUILDDIR}${NAME}-${VERSION_C}/ + clean: rm -rf ${BUILDDIR} diff --git a/src/background.js b/src/background.js index 56ac370..2b8226f 100644 --- a/src/background.js +++ b/src/background.js @@ -483,6 +483,7 @@ class DomainInfo { addrVersion() { if (this.addr) { if (/^64:ff9b::/.test(this.addr)) return "4"; // RFC6052 + // if Option. if (this.addr.indexOf(".") >= 0) return "4"; if (this.addr.indexOf(":") >= 0) return "6"; } diff --git a/src/common.js b/src/common.js index a4e6393..0f2e988 100644 --- a/src/common.js +++ b/src/common.js @@ -150,6 +150,7 @@ function drawSprite(ctx, size, targets, sources) { const DEFAULT_OPTIONS = { regularColorScheme: "darkfg", incognitoColorScheme: "lightfg", + // nat64Prefix: "64:ff9b::", }; let _watchOptionsFunc = null; diff --git a/src/options.html b/src/options.html index 4722893..d5644ba 100644 --- a/src/options.html +++ b/src/options.html @@ -66,6 +66,15 @@ background-color: #222; color: #eee; } + + input[type="text"] { + background-color: #333; + color: #eee; + border-color: #333; + border-style: "solid"; + border-width: 0px; + border-radius: 5px; + } } @@ -115,10 +124,14 @@

Icon color scheme

+
+ Note that popups use the system light/dark theme. +
+ +

NAT64 Prefix

+ -
- Note that popups use the system light/dark theme.
diff --git a/src/options.js b/src/options.js index cc384fd..6f2bf25 100644 --- a/src/options.js +++ b/src/options.js @@ -23,6 +23,12 @@ window.onload = async () => { await spriteImgReady; for (const option of Object.keys(DEFAULT_OPTIONS)) { + if (option === "nat64Prefix") { + const canvas = document.getElementById(`${option}:${color}`); + const ctx = canvas.getContext("2d"); + const imageData = buildIcon("646", 16, color); + ctx.putImageData(imageData, 0, 0); + } if (!option.endsWith("ColorScheme")) continue; for (const color of ["darkfg", "lightfg"]) { const canvas = document.getElementById(`${option}:${color}`); @@ -33,8 +39,9 @@ window.onload = async () => { } watchOptions(function(optionsChanged) { + for (const option of optionsChanged) { - if (!option.endsWith("ColorScheme")) continue; + // if (!option.endsWith("ColorScheme")) continue; const radio = document.optionsForm[option]; radio.value = options[option]; } From e2206562f30141f5ef47d4c8d9ce06e7e43ce916 Mon Sep 17 00:00:00 2001 From: BPplays Date: Mon, 30 Sep 2024 11:48:17 -0700 Subject: [PATCH 002/115] started adding nat64 prefix --- src/options.html | 2 +- src/options.js | 12 +++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/options.html b/src/options.html index d5644ba..194906d 100644 --- a/src/options.html +++ b/src/options.html @@ -70,7 +70,7 @@ input[type="text"] { background-color: #333; color: #eee; - border-color: #333; + border-color: #444; border-style: "solid"; border-width: 0px; border-radius: 5px; diff --git a/src/options.js b/src/options.js index 6f2bf25..cbe8d22 100644 --- a/src/options.js +++ b/src/options.js @@ -23,12 +23,6 @@ window.onload = async () => { await spriteImgReady; for (const option of Object.keys(DEFAULT_OPTIONS)) { - if (option === "nat64Prefix") { - const canvas = document.getElementById(`${option}:${color}`); - const ctx = canvas.getContext("2d"); - const imageData = buildIcon("646", 16, color); - ctx.putImageData(imageData, 0, 0); - } if (!option.endsWith("ColorScheme")) continue; for (const color of ["darkfg", "lightfg"]) { const canvas = document.getElementById(`${option}:${color}`); @@ -41,7 +35,11 @@ window.onload = async () => { watchOptions(function(optionsChanged) { for (const option of optionsChanged) { - // if (!option.endsWith("ColorScheme")) continue; + + if (option === "nat64Prefix") { + + } + if (!option.endsWith("ColorScheme")) continue; const radio = document.optionsForm[option]; radio.value = options[option]; } From 5fd62646a3bc921708f909dbca199998e79d4733 Mon Sep 17 00:00:00 2001 From: BPplays Date: Mon, 30 Sep 2024 14:26:14 -0700 Subject: [PATCH 003/115] changed html --- src/options.html | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/options.html b/src/options.html index 194906d..cc1acfb 100644 --- a/src/options.html +++ b/src/options.html @@ -60,6 +60,12 @@ font-weight: bold; } + .nat64PrefixGroup { + display: flex; + align-items: center; + gap: 0px; + } + /* dark mode */ @media (prefers-color-scheme: dark) { body { @@ -128,8 +134,11 @@

Icon color scheme

Note that popups use the system light/dark theme.
-

NAT64 Prefix

- +

NAT64 Options

+
+ + +
From b7c239cef1f8607c9f625ba1517d671e40ff6b4a Mon Sep 17 00:00:00 2001 From: BPplays Date: Tue, 1 Oct 2024 21:55:32 -0700 Subject: [PATCH 004/115] testing ipv6 parse --- src/background.js | 72 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/src/background.js b/src/background.js index 2b8226f..0b4865f 100644 --- a/src/background.js +++ b/src/background.js @@ -478,10 +478,82 @@ class DomainInfo { return new DomainInfo(tabInfo, domain, addr, flags); } + setBitAtPosition(int, bitPosition, value) { + if (value === 1) { + // Set bit n to 1 (use OR) + int = int | (BigInt(1) << BigInt(bitPosition)); + } else { + // Set bit n to 0 (use AND with a mask that has bit n cleared) + let mask = ~(BigInt(1) << BigInt(bitPosition)); + int = int & mask; + } + return int; + } + + setNibbleAtPosition(int128, nibble, bitPosition) { + // Convert the nibble (hex string) to a number + let nibbleValue = BigInt(parseInt(nibble, 16)); + + // Clear the existing bits at the position + let mask = ~(BigInt(0xF) << BigInt(bitPosition)); // Mask for 4 bits (nibble) + int128 = int128 & mask; + + // Set the new nibble at the bitPosition + int128 = int128 | (nibbleValue << BigInt(bitPosition)); + + return int128; + } + + parseIPv6WithCIDR(addressWithCIDR) { + let [address, cidr] = addressWithCIDR.split('/'); + let int128 = BigInt(0); // Start with all bits set to 0 + let bitPos = 124; // Start at bit 124 for the most significant nibble + + // Parse the address part, ignoring colons + for (let i = 0; i < address.length; i++) { + if (address[i] !== ':') { + int128 = setNibbleAtPosition(int128, address[i], bitPos); + bitPos -= 4; // Move 4 bits to the right for each nibble + } + } + + // If CIDR is present, parse and return it, otherwise assume /128 (full address) + let cidrValue = cidr ? parseInt(cidr, 10) : 128; + + console.log(int128) + + return { int128, cidr: cidrValue }; + } + + // parse_ipv6(address) { + // let int = BigInt(0); + // let colon_hex_left = 4; + // + // for (let i = address.length - 1; i >= 0; i--) { + // console.log(address[i]); + // if (address[i] === ':') { + // i += colon_hex_left; + // colon_hex_left = 4; + // continue; + // } + // for (let i = 0; i < address.length; i++) { + // if (address[i] !== ':') { + // int128 = setNibbleAtPosition(int128, address[i], bitPos); + // bitPos -= 4; // Move 4 bits to the right for each nibble + // } + // } + // } + // + // console.log(int); + // } + // In theory, we should be using a full-blown subnet parser/matcher here, // but let's keep it simple and stick with text for now. addrVersion() { if (this.addr) { + // this.parse_ipv6(this.addr) + this.parseIPv6WithCIDR("2001:db8::1") + // if (/^64:ff9b::/.test(this.addr)) return "4"; // RFC6052 if (/^64:ff9b::/.test(this.addr)) return "4"; // RFC6052 // if Option. if (this.addr.indexOf(".") >= 0) return "4"; From 639f13489906ad4a009e50c5b1c67695e27a5331 Mon Sep 17 00:00:00 2001 From: BPplays Date: Tue, 1 Oct 2024 22:22:20 -0700 Subject: [PATCH 005/115] fixed v6 addr parsing --- src/background.js | 58 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 44 insertions(+), 14 deletions(-) diff --git a/src/background.js b/src/background.js index 0b4865f..d19af8b 100644 --- a/src/background.js +++ b/src/background.js @@ -505,24 +505,54 @@ class DomainInfo { } parseIPv6WithCIDR(addressWithCIDR) { - let [address, cidr] = addressWithCIDR.split('/'); - let int128 = BigInt(0); // Start with all bits set to 0 - let bitPos = 124; // Start at bit 124 for the most significant nibble - - // Parse the address part, ignoring colons - for (let i = 0; i < address.length; i++) { - if (address[i] !== ':') { - int128 = setNibbleAtPosition(int128, address[i], bitPos); - bitPos -= 4; // Move 4 bits to the right for each nibble - } + let [address, cidr] = addressWithCIDR.split('/'); + let int128 = BigInt(0); // Start with all bits set to 0 + let bitPos = 0; // Start at bit 124 for the most significant nibble + let colon_hex_left = 4; + let colonseen = 0; + + // Parse the address part, ignoring colons + for (let i = address.length - 1; i >= 0; i--) { + if (colonseen >= 2) { + break; + } + if (address[i] !== ':') { + colonseen = 0 + int128 = this.setNibbleAtPosition(int128, address[i], bitPos); + bitPos += 4; // Move 4 bits to the right for each nibble + } else { + colonseen += 1; + bitPos += colon_hex_left; + colon_hex_left = 4; + } + } + + + + bitPos = 124; // Start at bit 124 for the most significant nibble + colon_hex_left = 4; + colonseen = 0; + for (let i = 0; i < address.length; i++) { + if (colonseen >= 2) { + break; } + if (address[i] !== ':') { + colonseen = 0 + int128 = this.setNibbleAtPosition(int128, address[i], bitPos); + bitPos -= 4; // Move 4 bits to the right for each nibble + } else { + colonseen += 1; + bitPos -= colon_hex_left; + colon_hex_left = 4; + } + } - // If CIDR is present, parse and return it, otherwise assume /128 (full address) - let cidrValue = cidr ? parseInt(cidr, 10) : 128; + // If CIDR is present, parse and return it, otherwise assume /128 (full address) + let cidrValue = cidr ? parseInt(cidr, 10) : 96; - console.log(int128) + console.log(int128.toString(2)) - return { int128, cidr: cidrValue }; + return { int128, cidr: cidrValue }; } // parse_ipv6(address) { From 89f75b9a160273641b61361a008939552befc87e Mon Sep 17 00:00:00 2001 From: BPplays Date: Tue, 1 Oct 2024 23:39:44 -0700 Subject: [PATCH 006/115] fixed v6 addr parsing --- src/background.js | 54 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 16 deletions(-) diff --git a/src/background.js b/src/background.js index d19af8b..6aa096a 100644 --- a/src/background.js +++ b/src/background.js @@ -491,22 +491,43 @@ class DomainInfo { } setNibbleAtPosition(int128, nibble, bitPosition) { - // Convert the nibble (hex string) to a number - let nibbleValue = BigInt(parseInt(nibble, 16)); + // Convert the nibble (hex string) to a number + let nibbleValue = BigInt(parseInt(nibble, 16)); - // Clear the existing bits at the position - let mask = ~(BigInt(0xF) << BigInt(bitPosition)); // Mask for 4 bits (nibble) - int128 = int128 & mask; + // Clear the existing bits at the position + let mask = ~(BigInt(0xF) << BigInt(bitPosition)); // Mask for 4 bits (nibble) + int128 = int128 & mask; - // Set the new nibble at the bitPosition - int128 = int128 | (nibbleValue << BigInt(bitPosition)); + // Set the new nibble at the bitPosition + int128 = int128 | (nibbleValue << BigInt(bitPosition)); - return int128; + return int128; } + + inAddrRange(addr_str, nat64AddrStr) { + + let addr = this.parseIPv6WithCIDR(addr_str) + let nat64Addr = this.parseIPv6WithCIDR(nat64AddrStr) + + // let addrMask = (BigInt(1) << BigInt(128 - nat64Addr.cidr)) - BigInt(1); + // addr.addr = addr.addr & ~addrMask; + + + + let nat64AddrMask = (BigInt(1) << BigInt(128 - nat64Addr.cidr)) - BigInt(1); + // nat64Addr.addr = nat64Addr.addr & ~nat64AddrMask; + + // console.log(addr.toString(2)) + + console.log("addrstr: ", addr_str, "\nnat64str: ", nat64AddrStr,"\naddr: ", addr.addr.toString(2), "\n", "nat64addr: ", nat64Addr.addr.toString(2), "\n bitmask: ", nat64AddrMask.toString(2)) + return addr.addr === nat64Addr.addr; + } + + parseIPv6WithCIDR(addressWithCIDR) { let [address, cidr] = addressWithCIDR.split('/'); - let int128 = BigInt(0); // Start with all bits set to 0 + let addr = BigInt(0); // Start with all bits set to 0 let bitPos = 0; // Start at bit 124 for the most significant nibble let colon_hex_left = 4; let colonseen = 0; @@ -518,7 +539,7 @@ class DomainInfo { } if (address[i] !== ':') { colonseen = 0 - int128 = this.setNibbleAtPosition(int128, address[i], bitPos); + addr = this.setNibbleAtPosition(addr, address[i], bitPos); bitPos += 4; // Move 4 bits to the right for each nibble } else { colonseen += 1; @@ -538,7 +559,7 @@ class DomainInfo { } if (address[i] !== ':') { colonseen = 0 - int128 = this.setNibbleAtPosition(int128, address[i], bitPos); + addr = this.setNibbleAtPosition(addr, address[i], bitPos); bitPos -= 4; // Move 4 bits to the right for each nibble } else { colonseen += 1; @@ -547,12 +568,11 @@ class DomainInfo { } } - // If CIDR is present, parse and return it, otherwise assume /128 (full address) let cidrValue = cidr ? parseInt(cidr, 10) : 96; - console.log(int128.toString(2)) + // console.log(int128.toString(2), cidrValue) - return { int128, cidr: cidrValue }; + return { addr: addr, cidr: cidrValue }; } // parse_ipv6(address) { @@ -582,9 +602,11 @@ class DomainInfo { addrVersion() { if (this.addr) { // this.parse_ipv6(this.addr) - this.parseIPv6WithCIDR("2001:db8::1") + // let ipv6 = this.parseIPv6WithCIDR("2001:db8::1") // if (/^64:ff9b::/.test(this.addr)) return "4"; // RFC6052 - if (/^64:ff9b::/.test(this.addr)) return "4"; // RFC6052 + // if (this.inAddrRange(this.addr, "64:ff9b::/96")) return "4"; // RFC6052 + this.inAddrRange("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", "f:f:f:f::f:f") + if (this.inAddrRange(this.addr, "6464:6464::/96")) return "4"; // RFC6052 // if Option. if (this.addr.indexOf(".") >= 0) return "4"; if (this.addr.indexOf(":") >= 0) return "6"; From 9e44eaf4b4b39069206e671cd27853eeed39ce8b Mon Sep 17 00:00:00 2001 From: BPplays Date: Tue, 1 Oct 2024 23:57:40 -0700 Subject: [PATCH 007/115] test split --- src/background.js | 65 +++++++++++++++++++---------------------------- 1 file changed, 26 insertions(+), 39 deletions(-) diff --git a/src/background.js b/src/background.js index 6aa096a..0afaa63 100644 --- a/src/background.js +++ b/src/background.js @@ -527,51 +527,38 @@ class DomainInfo { parseIPv6WithCIDR(addressWithCIDR) { let [address, cidr] = addressWithCIDR.split('/'); - let addr = BigInt(0); // Start with all bits set to 0 - let bitPos = 0; // Start at bit 124 for the most significant nibble - let colon_hex_left = 4; - let colonseen = 0; - - // Parse the address part, ignoring colons - for (let i = address.length - 1; i >= 0; i--) { - if (colonseen >= 2) { - break; - } - if (address[i] !== ':') { - colonseen = 0 - addr = this.setNibbleAtPosition(addr, address[i], bitPos); - bitPos += 4; // Move 4 bits to the right for each nibble - } else { - colonseen += 1; - bitPos += colon_hex_left; - colon_hex_left = 4; + let addr = BigInt(0); + let bitPos = 124; + let colonSeen = 0; + let segments = address.split(':'); + + // Determine how many segments are omitted + const omittedCount = 8 - segments.filter(seg => seg.length > 0).length + (address.includes('::') ? 0 : 0); + + console.log("omit: ", omittedCount) + for (let i = 0; i < segments.length; i++) { + if (segments[i] === '') { + // Handle double colon case + for (let j = 0; j < omittedCount; j++) { + // addr = this.setNibbleAtPosition(addr, '0', bitPos); // Fill in with zeros + bitPos -= 16; // Each omitted segment contributes 16 bits (4 nibbles) + } + continue; // Skip the empty segment } - } - - - bitPos = 124; // Start at bit 124 for the most significant nibble - colon_hex_left = 4; - colonseen = 0; - for (let i = 0; i < address.length; i++) { - if (colonseen >= 2) { - break; - } - if (address[i] !== ':') { - colonseen = 0 - addr = this.setNibbleAtPosition(addr, address[i], bitPos); - bitPos -= 4; // Move 4 bits to the right for each nibble - } else { - colonseen += 1; - bitPos -= colon_hex_left; - colon_hex_left = 4; + // Process the segment + for (let j = 0; j < segments[i].length; j++) { + addr = this.setNibbleAtPosition(addr, segments[i][j], bitPos); + bitPos -= 4; } + + // Adjust bit position for the next segment + // bitPos -= 4; } + // Handle CIDR value let cidrValue = cidr ? parseInt(cidr, 10) : 96; - // console.log(int128.toString(2), cidrValue) - return { addr: addr, cidr: cidrValue }; } @@ -605,7 +592,7 @@ class DomainInfo { // let ipv6 = this.parseIPv6WithCIDR("2001:db8::1") // if (/^64:ff9b::/.test(this.addr)) return "4"; // RFC6052 // if (this.inAddrRange(this.addr, "64:ff9b::/96")) return "4"; // RFC6052 - this.inAddrRange("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", "f:f:f:f::f:f") + this.inAddrRange("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", "f:f:f:f:f:f:f:f") if (this.inAddrRange(this.addr, "6464:6464::/96")) return "4"; // RFC6052 // if Option. if (this.addr.indexOf(".") >= 0) return "4"; From 563affb5f22b5f6cbe7e41884d1b1cd47539ced4 Mon Sep 17 00:00:00 2001 From: BPplays Date: Wed, 2 Oct 2024 00:08:28 -0700 Subject: [PATCH 008/115] fixed v6 addr parsing --- src/background.js | 70 +++++++++++++++++++++++++++++------------------ 1 file changed, 44 insertions(+), 26 deletions(-) diff --git a/src/background.js b/src/background.js index 0afaa63..db43921 100644 --- a/src/background.js +++ b/src/background.js @@ -524,41 +524,58 @@ class DomainInfo { return addr.addr === nat64Addr.addr; } - parseIPv6WithCIDR(addressWithCIDR) { let [address, cidr] = addressWithCIDR.split('/'); - let addr = BigInt(0); - let bitPos = 124; - let colonSeen = 0; - let segments = address.split(':'); - - // Determine how many segments are omitted - const omittedCount = 8 - segments.filter(seg => seg.length > 0).length + (address.includes('::') ? 0 : 0); - - console.log("omit: ", omittedCount) - for (let i = 0; i < segments.length; i++) { - if (segments[i] === '') { - // Handle double colon case - for (let j = 0; j < omittedCount; j++) { - // addr = this.setNibbleAtPosition(addr, '0', bitPos); // Fill in with zeros - bitPos -= 16; // Each omitted segment contributes 16 bits (4 nibbles) - } - continue; // Skip the empty segment + let addr = BigInt(0); // Start with all bits set to 0 + let bitPos = 0; // Start at bit 124 for the most significant nibble + let colon_hex_left = 16; + let colonseen = 0; + let sec_loop = false; + + // Parse the address part, ignoring colons + for (let i = address.length - 1; i >= 0; i--) { + if (colonseen >= 2) { + sec_loop = true; + break; } - - // Process the segment - for (let j = 0; j < segments[i].length; j++) { - addr = this.setNibbleAtPosition(addr, segments[i][j], bitPos); - bitPos -= 4; + if (address[i] !== ':') { + colonseen = 0 + addr = this.setNibbleAtPosition(addr, address[i], bitPos); + bitPos += 4; // Move 4 bits to the right for each nibble + colon_hex_left -= 4; + } else { + colonseen += 1; + bitPos += colon_hex_left; + colon_hex_left = 16; } + } - // Adjust bit position for the next segment - // bitPos -= 4; + + if (sec_loop) { + bitPos = 124; // Start at bit 124 for the most significant nibble + colon_hex_left = 4; + colonseen = 0; + for (let i = 0; i < address.length; i++) { + if (colonseen >= 2) { + break; + } + if (address[i] !== ':') { + colonseen = 0 + addr = this.setNibbleAtPosition(addr, address[i], bitPos); + bitPos -= 4; // Move 4 bits to the right for each nibble + colon_hex_left -= 4; + } else { + colonseen += 1; + bitPos -= colon_hex_left; + colon_hex_left = 16; + } + } } - // Handle CIDR value let cidrValue = cidr ? parseInt(cidr, 10) : 96; + // console.log(int128.toString(2), cidrValue) + return { addr: addr, cidr: cidrValue }; } @@ -593,6 +610,7 @@ class DomainInfo { // if (/^64:ff9b::/.test(this.addr)) return "4"; // RFC6052 // if (this.inAddrRange(this.addr, "64:ff9b::/96")) return "4"; // RFC6052 this.inAddrRange("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", "f:f:f:f:f:f:f:f") + this.inAddrRange("ffff:ffff:ffff::ffff:ffff:ffff", "f:f:f:f::f:f") if (this.inAddrRange(this.addr, "6464:6464::/96")) return "4"; // RFC6052 // if Option. if (this.addr.indexOf(".") >= 0) return "4"; From 3cb31c5ef83a6bb14e3263a5ba50c9922946c42b Mon Sep 17 00:00:00 2001 From: BPplays Date: Wed, 2 Oct 2024 00:10:34 -0700 Subject: [PATCH 009/115] fixed v6 addr parsing --- src/background.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/background.js b/src/background.js index db43921..617af5b 100644 --- a/src/background.js +++ b/src/background.js @@ -510,13 +510,13 @@ class DomainInfo { let addr = this.parseIPv6WithCIDR(addr_str) let nat64Addr = this.parseIPv6WithCIDR(nat64AddrStr) - // let addrMask = (BigInt(1) << BigInt(128 - nat64Addr.cidr)) - BigInt(1); - // addr.addr = addr.addr & ~addrMask; + let addrMask = (BigInt(1) << BigInt(128 - nat64Addr.cidr)) - BigInt(1); + addr.addr = addr.addr & ~addrMask; let nat64AddrMask = (BigInt(1) << BigInt(128 - nat64Addr.cidr)) - BigInt(1); - // nat64Addr.addr = nat64Addr.addr & ~nat64AddrMask; + nat64Addr.addr = nat64Addr.addr & ~nat64AddrMask; // console.log(addr.toString(2)) From 18e26e64aef1c66cf05578c59e0b656b5ff210f4 Mon Sep 17 00:00:00 2001 From: BPplays Date: Wed, 2 Oct 2024 18:15:28 -0700 Subject: [PATCH 010/115] fixed v6 addr parsing --- src/background.js | 82 +++++++++++++++++++++++++++++++---------------- 1 file changed, 55 insertions(+), 27 deletions(-) diff --git a/src/background.js b/src/background.js index 617af5b..5497ec5 100644 --- a/src/background.js +++ b/src/background.js @@ -510,13 +510,13 @@ class DomainInfo { let addr = this.parseIPv6WithCIDR(addr_str) let nat64Addr = this.parseIPv6WithCIDR(nat64AddrStr) - let addrMask = (BigInt(1) << BigInt(128 - nat64Addr.cidr)) - BigInt(1); - addr.addr = addr.addr & ~addrMask; + // let addrMask = (BigInt(1) << BigInt(128 - nat64Addr.cidr)) - BigInt(1); + // addr.addr = addr.addr & ~addrMask; let nat64AddrMask = (BigInt(1) << BigInt(128 - nat64Addr.cidr)) - BigInt(1); - nat64Addr.addr = nat64Addr.addr & ~nat64AddrMask; + // nat64Addr.addr = nat64Addr.addr & ~nat64AddrMask; // console.log(addr.toString(2)) @@ -524,23 +524,32 @@ class DomainInfo { return addr.addr === nat64Addr.addr; } + countOccurrences(string, substring) { + return string.split(substring).length - 1; + } + parseIPv6WithCIDR(addressWithCIDR) { - let [address, cidr] = addressWithCIDR.split('/'); + let [addressSTR, cidr] = addressWithCIDR.split('/'); let addr = BigInt(0); // Start with all bits set to 0 let bitPos = 0; // Start at bit 124 for the most significant nibble let colon_hex_left = 16; let colonseen = 0; let sec_loop = false; + let cols = this.countOccurrences(addressSTR) + let double_skip = 16 * (8 - cols) + + + // Parse the address part, ignoring colons - for (let i = address.length - 1; i >= 0; i--) { + for (let i = addressSTR.length - 1; i >= 0; i--) { if (colonseen >= 2) { sec_loop = true; break; } - if (address[i] !== ':') { + if (addressSTR[i] !== ':') { colonseen = 0 - addr = this.setNibbleAtPosition(addr, address[i], bitPos); + addr = this.setNibbleAtPosition(addr, addressSTR[i], bitPos); bitPos += 4; // Move 4 bits to the right for each nibble colon_hex_left -= 4; } else { @@ -551,26 +560,45 @@ class DomainInfo { } - if (sec_loop) { - bitPos = 124; // Start at bit 124 for the most significant nibble - colon_hex_left = 4; - colonseen = 0; - for (let i = 0; i < address.length; i++) { - if (colonseen >= 2) { - break; - } - if (address[i] !== ':') { - colonseen = 0 - addr = this.setNibbleAtPosition(addr, address[i], bitPos); - bitPos -= 4; // Move 4 bits to the right for each nibble - colon_hex_left -= 4; - } else { - colonseen += 1; - bitPos -= colon_hex_left; - colon_hex_left = 16; - } - } - } + // if (sec_loop) { + // bitPos = 124; // Start at bit 124 for the most significant nibble + // colon_hex_left = 16; + // colonseen = 0; + // for (let i = 0; i < addressSTR.length; i++) { + // if (colonseen >= 2) { + // break; + // } + // + // if (addressSTR[i] === ':') { + // for (let j = i - 1; i >= 0; i--) { + // if (colonseen >= 2) { + // sec_loop = true; + // break; + // } + // if (addressSTR[j] !== ':') { + // colonseen = 0 + // addr = this.setNibbleAtPosition(addr, addressSTR[i], bitPos); + // bitPos += 4; // Move 4 bits to the right for each nibble + // colon_hex_left -= 4; + // } else { + // colonseen += 1; + // bitPos += colon_hex_left; + // colon_hex_left = 16; + // } + // } + // } + // if (addressSTR[i] !== ':') { + // colonseen = 0 + // addr = this.setNibbleAtPosition(addr, addressSTR[i], bitPos); + // bitPos -= 4; // Move 4 bits to the right for each nibble + // colon_hex_left -= 4; + // } else { + // colonseen += 1; + // bitPos -= colon_hex_left; + // colon_hex_left = 16; + // } + // } + // } let cidrValue = cidr ? parseInt(cidr, 10) : 96; From 417345bc49e8536e0d13247e0e330d959e593bc9 Mon Sep 17 00:00:00 2001 From: BPplays Date: Wed, 2 Oct 2024 18:24:36 -0700 Subject: [PATCH 011/115] fixed v6 addr parsing, and removed old code --- src/background.js | 50 +++++++---------------------------------------- 1 file changed, 7 insertions(+), 43 deletions(-) diff --git a/src/background.js b/src/background.js index 5497ec5..a39c6d6 100644 --- a/src/background.js +++ b/src/background.js @@ -536,8 +536,9 @@ class DomainInfo { let colonseen = 0; let sec_loop = false; - let cols = this.countOccurrences(addressSTR) + let cols = this.countOccurrences(addressSTR, ":") let double_skip = 16 * (8 - cols) + // console.log("dskip: ", double_skip, "cols: ", cols) @@ -545,7 +546,11 @@ class DomainInfo { for (let i = addressSTR.length - 1; i >= 0; i--) { if (colonseen >= 2) { sec_loop = true; - break; + // break; + bitPos += double_skip + } else if (colonseen === 1) { + bitPos += colon_hex_left; + colon_hex_left = 16; } if (addressSTR[i] !== ':') { colonseen = 0 @@ -554,51 +559,10 @@ class DomainInfo { colon_hex_left -= 4; } else { colonseen += 1; - bitPos += colon_hex_left; - colon_hex_left = 16; } } - // if (sec_loop) { - // bitPos = 124; // Start at bit 124 for the most significant nibble - // colon_hex_left = 16; - // colonseen = 0; - // for (let i = 0; i < addressSTR.length; i++) { - // if (colonseen >= 2) { - // break; - // } - // - // if (addressSTR[i] === ':') { - // for (let j = i - 1; i >= 0; i--) { - // if (colonseen >= 2) { - // sec_loop = true; - // break; - // } - // if (addressSTR[j] !== ':') { - // colonseen = 0 - // addr = this.setNibbleAtPosition(addr, addressSTR[i], bitPos); - // bitPos += 4; // Move 4 bits to the right for each nibble - // colon_hex_left -= 4; - // } else { - // colonseen += 1; - // bitPos += colon_hex_left; - // colon_hex_left = 16; - // } - // } - // } - // if (addressSTR[i] !== ':') { - // colonseen = 0 - // addr = this.setNibbleAtPosition(addr, addressSTR[i], bitPos); - // bitPos -= 4; // Move 4 bits to the right for each nibble - // colon_hex_left -= 4; - // } else { - // colonseen += 1; - // bitPos -= colon_hex_left; - // colon_hex_left = 16; - // } - // } - // } let cidrValue = cidr ? parseInt(cidr, 10) : 96; From c3eee912d20abec90cb0fa7e8244b87ffb98c6ee Mon Sep 17 00:00:00 2001 From: BPplays Date: Wed, 2 Oct 2024 18:31:09 -0700 Subject: [PATCH 012/115] added error handling --- src/background.js | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/background.js b/src/background.js index a39c6d6..4a2ffc9 100644 --- a/src/background.js +++ b/src/background.js @@ -506,22 +506,25 @@ class DomainInfo { inAddrRange(addr_str, nat64AddrStr) { + try { + let addr = this.parseIPv6WithCIDR(addr_str) + let nat64Addr = this.parseIPv6WithCIDR(nat64AddrStr) - let addr = this.parseIPv6WithCIDR(addr_str) - let nat64Addr = this.parseIPv6WithCIDR(nat64AddrStr) - - // let addrMask = (BigInt(1) << BigInt(128 - nat64Addr.cidr)) - BigInt(1); - // addr.addr = addr.addr & ~addrMask; + let addrMask = (BigInt(1) << BigInt(128 - nat64Addr.cidr)) - BigInt(1); + addr.addr = addr.addr & ~addrMask; - let nat64AddrMask = (BigInt(1) << BigInt(128 - nat64Addr.cidr)) - BigInt(1); - // nat64Addr.addr = nat64Addr.addr & ~nat64AddrMask; + let nat64AddrMask = (BigInt(1) << BigInt(128 - nat64Addr.cidr)) - BigInt(1); + nat64Addr.addr = nat64Addr.addr & ~nat64AddrMask; - // console.log(addr.toString(2)) + // console.log(addr.toString(2)) - console.log("addrstr: ", addr_str, "\nnat64str: ", nat64AddrStr,"\naddr: ", addr.addr.toString(2), "\n", "nat64addr: ", nat64Addr.addr.toString(2), "\n bitmask: ", nat64AddrMask.toString(2)) - return addr.addr === nat64Addr.addr; + console.log("addrstr: ", addr_str, "\nnat64str: ", nat64AddrStr,"\naddr: ", addr.addr.toString(2), "\n", "nat64addr: ", nat64Addr.addr.toString(2), "\n bitmask: ", nat64AddrMask.toString(2)) + return addr.addr === nat64Addr.addr; + } catch (error) { + return false; + } } countOccurrences(string, substring) { @@ -601,8 +604,8 @@ class DomainInfo { // let ipv6 = this.parseIPv6WithCIDR("2001:db8::1") // if (/^64:ff9b::/.test(this.addr)) return "4"; // RFC6052 // if (this.inAddrRange(this.addr, "64:ff9b::/96")) return "4"; // RFC6052 - this.inAddrRange("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", "f:f:f:f:f:f:f:f") - this.inAddrRange("ffff:ffff:ffff::ffff:ffff:ffff", "f:f:f:f::f:f") + // this.inAddrRange("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", "f:f:f:f:f:f:f:f") + // this.inAddrRange("ffff:ffff:ffff::ffff:ffff:ffff", "f:f:f:f::f:f") if (this.inAddrRange(this.addr, "6464:6464::/96")) return "4"; // RFC6052 // if Option. if (this.addr.indexOf(".") >= 0) return "4"; From 91017d6ec291531de5e360085dbb332d8815848d Mon Sep 17 00:00:00 2001 From: BPplays Date: Wed, 2 Oct 2024 18:36:47 -0700 Subject: [PATCH 013/115] added error handling --- src/background.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/background.js b/src/background.js index 4a2ffc9..90608f3 100644 --- a/src/background.js +++ b/src/background.js @@ -540,6 +540,9 @@ class DomainInfo { let sec_loop = false; let cols = this.countOccurrences(addressSTR, ":") + if (cols <= 0) { + throw new Error('not_ipv6') + } let double_skip = 16 * (8 - cols) // console.log("dskip: ", double_skip, "cols: ", cols) From 1dcab119743a3762b9a3c7adb169d4049a933122 Mon Sep 17 00:00:00 2001 From: BPplays Date: Wed, 2 Oct 2024 18:37:57 -0700 Subject: [PATCH 014/115] removed old code --- src/background.js | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/src/background.js b/src/background.js index 90608f3..b3ea54a 100644 --- a/src/background.js +++ b/src/background.js @@ -577,27 +577,6 @@ class DomainInfo { return { addr: addr, cidr: cidrValue }; } - // parse_ipv6(address) { - // let int = BigInt(0); - // let colon_hex_left = 4; - // - // for (let i = address.length - 1; i >= 0; i--) { - // console.log(address[i]); - // if (address[i] === ':') { - // i += colon_hex_left; - // colon_hex_left = 4; - // continue; - // } - // for (let i = 0; i < address.length; i++) { - // if (address[i] !== ':') { - // int128 = setNibbleAtPosition(int128, address[i], bitPos); - // bitPos -= 4; // Move 4 bits to the right for each nibble - // } - // } - // } - // - // console.log(int); - // } // In theory, we should be using a full-blown subnet parser/matcher here, // but let's keep it simple and stick with text for now. From e0ec07be425851d82adcdb3932203e21cdb5483d Mon Sep 17 00:00:00 2001 From: BPplays Date: Thu, 3 Oct 2024 01:04:40 -0700 Subject: [PATCH 015/115] started adding nat64 foramtting --- src/background.js | 32 ++++++++++++++++++++++---------- src/common.js | 4 ++++ 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/background.js b/src/background.js index b3ea54a..bb2cdf5 100644 --- a/src/background.js +++ b/src/background.js @@ -358,17 +358,26 @@ class TabInfo extends SaveableEntry { let has4 = false; let has6 = false; let tooltip = ""; - for (const [domain, d] of Object.entries(this.domains)) { + for (let [domain, d] of Object.entries(this.domains)) { if (domain == this.mainDomain) { - pattern = d.addrVersion(); + let [addrVer, _] = d.addrVersion(); + pattern = addrVer; if (IS_MOBILE) { tooltip = d.addr; // Limited tooltip space on Android. } else { tooltip = `${d.addr}\n${NAME_VERSION}`; } } else { - switch (d.addrVersion()) { - case "4": has4 = true; break; + let [addrVer, nat64] = d.addrVersion(); + console.log(addrVer) + switch (addrVer) { + // case "nat64": d.addr = "2606:50c0:8000::"; console.log(d.addr); has4 = true; break; + case "4": ; + if (nat64) { + d.addr = "6464:6464::10.0.40.1"; + } + has4 = true + break case "6": has6 = true; break; } } @@ -430,12 +439,13 @@ class TabInfo extends SaveableEntry { const tuples = [mainTuple]; for (const domain of domains) { const d = this.domains[domain]; + let [addrVer, _] = d.addrVersion(); if (domain == mainTuple[0]) { mainTuple[1] = d.addr; - mainTuple[2] = d.addrVersion(); + mainTuple[2] = addrVer; mainTuple[3] = d.flags; } else { - tuples.push([domain, d.addr, d.addrVersion(), d.flags]); + tuples.push([domain, d.addr, addrVer, d.flags]); } } return tuples; @@ -448,7 +458,9 @@ class TabInfo extends SaveableEntry { // Perhaps this.domains was cleared during the request's lifetime. return null; } - return [domain, d.addr, d.addrVersion(), d.flags]; + + let [addrVer, _] = d.addrVersion(); + return [domain, d.addr, addrVer, d.flags]; } } @@ -588,10 +600,10 @@ class DomainInfo { // if (this.inAddrRange(this.addr, "64:ff9b::/96")) return "4"; // RFC6052 // this.inAddrRange("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", "f:f:f:f:f:f:f:f") // this.inAddrRange("ffff:ffff:ffff::ffff:ffff:ffff", "f:f:f:f::f:f") - if (this.inAddrRange(this.addr, "6464:6464::/96")) return "4"; // RFC6052 + if (this.inAddrRange(this.addr, "6464:6464::/96")) return ["4", true]; // RFC6052 // if Option. - if (this.addr.indexOf(".") >= 0) return "4"; - if (this.addr.indexOf(":") >= 0) return "6"; + if (this.addr.indexOf(".") >= 0) return ["4", false]; + if (this.addr.indexOf(":") >= 0) return ["6", false]; } return "?"; } diff --git a/src/common.js b/src/common.js index 0f2e988..9e0e762 100644 --- a/src/common.js +++ b/src/common.js @@ -80,6 +80,8 @@ function _getCanvasContext(size) { // Images from spritesXX.png: [x, y, w, h] const spriteBig = { + "7": {16: [1, 1, 9, 14], + 32: [1, 1, 21, 28]}, "4": {16: [1, 1, 9, 14], 32: [1, 1, 21, 28]}, "6": {16: [11, 1, 9, 14], @@ -88,6 +90,8 @@ const spriteBig = { 32: [45, 1, 21, 28]}, }; const spriteSmall = { + "7": {16: [31, 1, 6, 6], + 32: [67, 1, 10, 10]}, "4": {16: [31, 1, 6, 6], 32: [67, 1, 10, 10]}, "6": {16: [31, 8, 6, 6], From d4e7fe963a5575f72266b5e93c60a2b83cf407a2 Mon Sep 17 00:00:00 2001 From: BPplays Date: Thu, 3 Oct 2024 01:37:59 -0700 Subject: [PATCH 016/115] started adding nat64 foramtting --- src/background.js | 83 ++++++++++++++++++++++++++++++++++++++++++++--- src/common.js | 4 --- 2 files changed, 78 insertions(+), 9 deletions(-) diff --git a/src/background.js b/src/background.js index bb2cdf5..7150071 100644 --- a/src/background.js +++ b/src/background.js @@ -369,13 +369,14 @@ class TabInfo extends SaveableEntry { } } else { let [addrVer, nat64] = d.addrVersion(); + console.log(addrVer) switch (addrVer) { // case "nat64": d.addr = "2606:50c0:8000::"; console.log(d.addr); has4 = true; break; case "4": ; - if (nat64) { - d.addr = "6464:6464::10.0.40.1"; - } + // if (nat64) { + // d.addr = "6464:6464::10.0.40.1"; + // } has4 = true break case "6": has6 = true; break; @@ -521,6 +522,9 @@ class DomainInfo { try { let addr = this.parseIPv6WithCIDR(addr_str) let nat64Addr = this.parseIPv6WithCIDR(nat64AddrStr) + let ren = this.bigintToIPv6(addr.addr) + + console.log("addrstr: ", addr_str, "\nreren: ", ren) let addrMask = (BigInt(1) << BigInt(128 - nat64Addr.cidr)) - BigInt(1); addr.addr = addr.addr & ~addrMask; @@ -532,7 +536,7 @@ class DomainInfo { // console.log(addr.toString(2)) - console.log("addrstr: ", addr_str, "\nnat64str: ", nat64AddrStr,"\naddr: ", addr.addr.toString(2), "\n", "nat64addr: ", nat64Addr.addr.toString(2), "\n bitmask: ", nat64AddrMask.toString(2)) + // console.log("addrstr: ", addr_str, "\nnat64str: ", nat64AddrStr,"\naddr: ", addr.addr.toString(2), "\n", "nat64addr: ", nat64Addr.addr.toString(2), "\n bitmask: ", nat64AddrMask.toString(2)) return addr.addr === nat64Addr.addr; } catch (error) { return false; @@ -590,6 +594,72 @@ class DomainInfo { } + bigintToIPv6(bigInt) { + // Ensure the input is a BigInt + if (typeof bigInt !== 'bigint') { + throw new TypeError('Input must be a BigInt'); + } + + // Convert the BigInt to a hexadecimal string + let hex = bigInt.toString(16).padStart(32, '0'); // Pad with zeros to ensure 32 hex digits + + // Split the hex string into 8 groups of 4 hex digits (16 bits per group) + let ipv6 = []; + for (let i = 0; i < 8; i++) { + ipv6.push(hex.substr(i * 4, 4)); + } + + // Manually remove leading zeros from each block + ipv6 = ipv6.map(group => group.replace(/^0+/, '') || '0'); + + // Find the longest sequence of zero blocks to shorten + let zeroStart = -1; + let zeroLength = 0; + let bestZeroStart = -1; + let bestZeroLength = 0; + + for (let i = 0; i < ipv6.length; i++) { + if (ipv6[i] === '0') { + if (zeroStart === -1) { + zeroStart = i; + } + zeroLength++; + } else { + if (zeroLength > bestZeroLength) { + bestZeroStart = zeroStart; + bestZeroLength = zeroLength; + } + zeroStart = -1; + zeroLength = 0; + } + } + + // Handle the case where the longest sequence of zero blocks is at the end + if (zeroLength > bestZeroLength) { + bestZeroStart = zeroStart; + bestZeroLength = zeroLength; + } + + // If we found a sequence of two or more consecutive zero blocks, shorten it + if (bestZeroLength > 1) { + ipv6.splice(bestZeroStart, bestZeroLength, ''); // Replace the longest zero sequence with an empty string + } + + // Join the groups with ':' to form the IPv6 address + let ipv6Address = ipv6.join(':'); + + // Handle special case where address starts or ends with :: + if (ipv6Address.startsWith(':')) { + ipv6Address = ':' + ipv6Address; + } + if (ipv6Address.endsWith(':')) { + ipv6Address = ipv6Address + ':'; + } + + return ipv6Address; + } + + // In theory, we should be using a full-blown subnet parser/matcher here, // but let's keep it simple and stick with text for now. addrVersion() { @@ -599,7 +669,10 @@ class DomainInfo { // if (/^64:ff9b::/.test(this.addr)) return "4"; // RFC6052 // if (this.inAddrRange(this.addr, "64:ff9b::/96")) return "4"; // RFC6052 // this.inAddrRange("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", "f:f:f:f:f:f:f:f") - // this.inAddrRange("ffff:ffff:ffff::ffff:ffff:ffff", "f:f:f:f::f:f") + this.inAddrRange("ffff:ffff:ffff::ffff:ffff:ffff", "f:f:f:f::f:f") + this.inAddrRange("f:f:f:f::f:f", "f:f:f:f::f:f") + this.inAddrRange("f:f:f:f::", "f:f:f:f::f:f") + if (this.inAddrRange(this.addr, "6464:6464::/96")) return ["4", true]; // RFC6052 // if Option. if (this.addr.indexOf(".") >= 0) return ["4", false]; diff --git a/src/common.js b/src/common.js index 9e0e762..0f2e988 100644 --- a/src/common.js +++ b/src/common.js @@ -80,8 +80,6 @@ function _getCanvasContext(size) { // Images from spritesXX.png: [x, y, w, h] const spriteBig = { - "7": {16: [1, 1, 9, 14], - 32: [1, 1, 21, 28]}, "4": {16: [1, 1, 9, 14], 32: [1, 1, 21, 28]}, "6": {16: [11, 1, 9, 14], @@ -90,8 +88,6 @@ const spriteBig = { 32: [45, 1, 21, 28]}, }; const spriteSmall = { - "7": {16: [31, 1, 6, 6], - 32: [67, 1, 10, 10]}, "4": {16: [31, 1, 6, 6], 32: [67, 1, 10, 10]}, "6": {16: [31, 8, 6, 6], From 8472c01a09220281bdab696b9f7e97ed720ffe91 Mon Sep 17 00:00:00 2001 From: BPplays Date: Thu, 3 Oct 2024 01:50:49 -0700 Subject: [PATCH 017/115] started adding nat64 foramtting --- src/background.js | 48 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/src/background.js b/src/background.js index 7150071..7558e0e 100644 --- a/src/background.js +++ b/src/background.js @@ -522,7 +522,7 @@ class DomainInfo { try { let addr = this.parseIPv6WithCIDR(addr_str) let nat64Addr = this.parseIPv6WithCIDR(nat64AddrStr) - let ren = this.bigintToIPv6(addr.addr) + let ren = this.bigintToMixedIPv6(addr.addr, nat64Addr.cidr) console.log("addrstr: ", addr_str, "\nreren: ", ren) @@ -594,25 +594,52 @@ class DomainInfo { } - bigintToIPv6(bigInt) { + bigintToMixedIPv6(bigInt, v6_stop) { // Ensure the input is a BigInt if (typeof bigInt !== 'bigint') { throw new TypeError('Input must be a BigInt'); } // Convert the BigInt to a hexadecimal string - let hex = bigInt.toString(16).padStart(32, '0'); // Pad with zeros to ensure 32 hex digits + let hex = bigInt.toString(16).padStart(32, '0'); // Pad with zeros to ensure 32 hex digits (128 bits) - // Split the hex string into 8 groups of 4 hex digits (16 bits per group) + // Determine the number of 16-bit groups needed for IPv6 before switching to IPv4 + const ipv6Groups = Math.floor(v6_stop / 16); // Number of 16-bit blocks to be rendered as IPv6 + const v4StartBit = v6_stop % 16; // Remainder bits that need to be handled for transition + + // Prepare IPv6 part let ipv6 = []; - for (let i = 0; i < 8; i++) { + for (let i = 0; i < ipv6Groups; i++) { ipv6.push(hex.substr(i * 4, 4)); } - // Manually remove leading zeros from each block + // Handle any remaining bits from the transition point (v4StartBit) + let remainingHex = hex.substr(ipv6Groups * 4); + + // Convert any remaining bits to an IPv4 address + let v4Part = ''; + if (remainingHex.length > 0) { + let remainingBigInt = BigInt('0x' + remainingHex); + + // Shift bits so that any leftover bits before the IPv4 section are discarded + if (v4StartBit > 0) { + remainingBigInt = remainingBigInt >> BigInt(16 - v4StartBit); + } + + // Convert the final 32 bits to IPv4 address (dot-decimal) + let v4Number = Number(remainingBigInt & BigInt(0xFFFFFFFF)); // Mask to 32 bits + v4Part = [ + (v4Number >> 24) & 0xFF, + (v4Number >> 16) & 0xFF, + (v4Number >> 8) & 0xFF, + v4Number & 0xFF + ].join('.'); + } + + // Manually remove leading zeros from each block in the IPv6 part ipv6 = ipv6.map(group => group.replace(/^0+/, '') || '0'); - // Find the longest sequence of zero blocks to shorten + // Find the longest sequence of zero blocks for shortening (same as previous method) let zeroStart = -1; let zeroLength = 0; let bestZeroStart = -1; @@ -645,7 +672,7 @@ class DomainInfo { ipv6.splice(bestZeroStart, bestZeroLength, ''); // Replace the longest zero sequence with an empty string } - // Join the groups with ':' to form the IPv6 address + // Join the groups with ':' to form the IPv6 part of the address let ipv6Address = ipv6.join(':'); // Handle special case where address starts or ends with :: @@ -656,10 +683,10 @@ class DomainInfo { ipv6Address = ipv6Address + ':'; } - return ipv6Address; + // Return the combined IPv6 and IPv4 address + return ipv6Address + (v4Part ? ':' + v4Part : ''); } - // In theory, we should be using a full-blown subnet parser/matcher here, // but let's keep it simple and stick with text for now. addrVersion() { @@ -672,6 +699,7 @@ class DomainInfo { this.inAddrRange("ffff:ffff:ffff::ffff:ffff:ffff", "f:f:f:f::f:f") this.inAddrRange("f:f:f:f::f:f", "f:f:f:f::f:f") this.inAddrRange("f:f:f:f::", "f:f:f:f::f:f") + this.inAddrRange("6464:6464::a00:1", "6464:6464::/96") if (this.inAddrRange(this.addr, "6464:6464::/96")) return ["4", true]; // RFC6052 // if Option. From b0b65c3e8376173970a44c193534fb8bc6c48884 Mon Sep 17 00:00:00 2001 From: BPplays Date: Thu, 3 Oct 2024 02:25:31 -0700 Subject: [PATCH 018/115] started adding nat64 foramtting --- src/background.js | 43 ++++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/src/background.js b/src/background.js index 7558e0e..63c9b5e 100644 --- a/src/background.js +++ b/src/background.js @@ -374,9 +374,10 @@ class TabInfo extends SaveableEntry { switch (addrVer) { // case "nat64": d.addr = "2606:50c0:8000::"; console.log(d.addr); has4 = true; break; case "4": ; - // if (nat64) { - // d.addr = "6464:6464::10.0.40.1"; - // } + if (nat64) { + console.log(d.bigintToMixedIPv6(d.addrBitsCIDR.addr, 128)); + // d.addr = d.bigintToMixedIPv6(d.addrBitsCIDR.addr, d.nat64AddrBitsCIDR.cidr); + } has4 = true break case "6": has6 = true; break; @@ -469,6 +470,9 @@ class DomainInfo { tabInfo; domain; addr; + addrBitsCIDR; + nat64Addr; + nat64AddrBitsCIDR; flags; count = 0; // count of active requests @@ -478,6 +482,10 @@ class DomainInfo { this.tabInfo = tabInfo; this.domain = domain; this.addr = addr; + this.addrBitsCIDR = this.parseIPv6WithCIDR(addr); + + this.nat64Addr = "6464:6464::/96"; + this.nat64AddrBitsCIDR = this.parseIPv6WithCIDR(this.nat64Addr); this.flags = flags; } @@ -518,13 +526,13 @@ class DomainInfo { } - inAddrRange(addr_str, nat64AddrStr) { + inAddrRange(addr, nat64Addr) { try { - let addr = this.parseIPv6WithCIDR(addr_str) - let nat64Addr = this.parseIPv6WithCIDR(nat64AddrStr) - let ren = this.bigintToMixedIPv6(addr.addr, nat64Addr.cidr) + // let addr = this.parseIPv6WithCIDR(addr_str) + // let nat64Addr = this.parseIPv6WithCIDR(nat64AddrStr) + // let ren = this.bigintToMixedIPv6(addr.addr, nat64Addr.cidr) - console.log("addrstr: ", addr_str, "\nreren: ", ren) + console.log("addrstr: ", this.addr, "\nreren: ", ren) let addrMask = (BigInt(1) << BigInt(128 - nat64Addr.cidr)) - BigInt(1); addr.addr = addr.addr & ~addrMask; @@ -536,9 +544,10 @@ class DomainInfo { // console.log(addr.toString(2)) - // console.log("addrstr: ", addr_str, "\nnat64str: ", nat64AddrStr,"\naddr: ", addr.addr.toString(2), "\n", "nat64addr: ", nat64Addr.addr.toString(2), "\n bitmask: ", nat64AddrMask.toString(2)) + // console.log("\naddr: ", addr.addr.toString(2), "\n", "nat64addr: ", nat64Addr.addr.toString(2), "\n bitmask: ", nat64AddrMask.toString(2)) return addr.addr === nat64Addr.addr; } catch (error) { + console.log(error) return false; } } @@ -675,16 +684,19 @@ class DomainInfo { // Join the groups with ':' to form the IPv6 part of the address let ipv6Address = ipv6.join(':'); + let ipv4_col = ':'; + // Handle special case where address starts or ends with :: if (ipv6Address.startsWith(':')) { ipv6Address = ':' + ipv6Address; } if (ipv6Address.endsWith(':')) { ipv6Address = ipv6Address + ':'; + ipv4_col = ''; } // Return the combined IPv6 and IPv4 address - return ipv6Address + (v4Part ? ':' + v4Part : ''); + return ipv6Address + (v4Part ? ipv4_col + v4Part : ''); } // In theory, we should be using a full-blown subnet parser/matcher here, @@ -696,12 +708,13 @@ class DomainInfo { // if (/^64:ff9b::/.test(this.addr)) return "4"; // RFC6052 // if (this.inAddrRange(this.addr, "64:ff9b::/96")) return "4"; // RFC6052 // this.inAddrRange("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", "f:f:f:f:f:f:f:f") - this.inAddrRange("ffff:ffff:ffff::ffff:ffff:ffff", "f:f:f:f::f:f") - this.inAddrRange("f:f:f:f::f:f", "f:f:f:f::f:f") - this.inAddrRange("f:f:f:f::", "f:f:f:f::f:f") - this.inAddrRange("6464:6464::a00:1", "6464:6464::/96") + // this.inAddrRange("ffff:ffff:ffff::ffff:ffff:ffff", "f:f:f:f::f:f") + // this.inAddrRange("f:f:f:f::f:f", "f:f:f:f::f:f") + // this.inAddrRange("f:f:f:f::", "f:f:f:f::f:f") + // this.inAddrRange("6464:6464::a00:1", "6464:6464::/96") + // this.inAddrRange("6464:6464:1:1:1:1:a00:1", "6464:6464::/96") - if (this.inAddrRange(this.addr, "6464:6464::/96")) return ["4", true]; // RFC6052 + if (this.inAddrRange(this.addrBitsCIDR, this.nat64AddrBitsCIDR)) return ["4", true]; // RFC6052 // if Option. if (this.addr.indexOf(".") >= 0) return ["4", false]; if (this.addr.indexOf(":") >= 0) return ["6", false]; From dae435acba4a01333404105de2454b627dba2dae Mon Sep 17 00:00:00 2001 From: BPplays Date: Thu, 3 Oct 2024 16:59:10 -0700 Subject: [PATCH 019/115] started adding nat64 foramtting --- src/background.js | 74 +++++++++++++++++++---------------------------- 1 file changed, 29 insertions(+), 45 deletions(-) diff --git a/src/background.js b/src/background.js index 63c9b5e..41eab68 100644 --- a/src/background.js +++ b/src/background.js @@ -375,7 +375,8 @@ class TabInfo extends SaveableEntry { // case "nat64": d.addr = "2606:50c0:8000::"; console.log(d.addr); has4 = true; break; case "4": ; if (nat64) { - console.log(d.bigintToMixedIPv6(d.addrBitsCIDR.addr, 128)); + // console.log(d.bigintToIPv6(d.addrBitsCIDR.addr, false)); + // console.log(d.bigintToIPv6(d.addrBitsCIDR.addr, 96)); // d.addr = d.bigintToMixedIPv6(d.addrBitsCIDR.addr, d.nat64AddrBitsCIDR.cidr); } has4 = true @@ -470,7 +471,6 @@ class DomainInfo { tabInfo; domain; addr; - addrBitsCIDR; nat64Addr; nat64AddrBitsCIDR; flags; @@ -482,8 +482,6 @@ class DomainInfo { this.tabInfo = tabInfo; this.domain = domain; this.addr = addr; - this.addrBitsCIDR = this.parseIPv6WithCIDR(addr); - this.nat64Addr = "6464:6464::/96"; this.nat64AddrBitsCIDR = this.parseIPv6WithCIDR(this.nat64Addr); this.flags = flags; @@ -530,7 +528,8 @@ class DomainInfo { try { // let addr = this.parseIPv6WithCIDR(addr_str) // let nat64Addr = this.parseIPv6WithCIDR(nat64AddrStr) - // let ren = this.bigintToMixedIPv6(addr.addr, nat64Addr.cidr) + console.log("raadd: ", addr.addr.toString(16)) + let ren = this.bigintToIPv6(addr.addr, false) console.log("addrstr: ", this.addr, "\nreren: ", ren) @@ -603,52 +602,37 @@ class DomainInfo { } - bigintToMixedIPv6(bigInt, v6_stop) { + bigintToIPv6(bigInt, nat64 = false) { // Ensure the input is a BigInt if (typeof bigInt !== 'bigint') { throw new TypeError('Input must be a BigInt'); } - // Convert the BigInt to a hexadecimal string - let hex = bigInt.toString(16).padStart(32, '0'); // Pad with zeros to ensure 32 hex digits (128 bits) + let ipv6Bits = BigInt(bigInt) + let ipv4Bits = BigInt(bigInt) - // Determine the number of 16-bit groups needed for IPv6 before switching to IPv4 - const ipv6Groups = Math.floor(v6_stop / 16); // Number of 16-bit blocks to be rendered as IPv6 - const v4StartBit = v6_stop % 16; // Remainder bits that need to be handled for transition + let addrMask = (BigInt(1) << BigInt(32)) - BigInt(1); - // Prepare IPv6 part - let ipv6 = []; - for (let i = 0; i < ipv6Groups; i++) { - ipv6.push(hex.substr(i * 4, 4)); + if (nat64) { + // ipv6Bits = ipv6Bits & ~addrMask + ipv4Bits = ipv4Bits & addrMask } - // Handle any remaining bits from the transition point (v4StartBit) - let remainingHex = hex.substr(ipv6Groups * 4); - - // Convert any remaining bits to an IPv4 address - let v4Part = ''; - if (remainingHex.length > 0) { - let remainingBigInt = BigInt('0x' + remainingHex); - - // Shift bits so that any leftover bits before the IPv4 section are discarded - if (v4StartBit > 0) { - remainingBigInt = remainingBigInt >> BigInt(16 - v4StartBit); - } + // Convert the BigInt to a hexadecimal string + let hex = ipv6Bits.toString(16).padStart(32, '0'); // Pad with zeros to ensure 32 hex digits + console.log(hex, bigInt.toString(16)) - // Convert the final 32 bits to IPv4 address (dot-decimal) - let v4Number = Number(remainingBigInt & BigInt(0xFFFFFFFF)); // Mask to 32 bits - v4Part = [ - (v4Number >> 24) & 0xFF, - (v4Number >> 16) & 0xFF, - (v4Number >> 8) & 0xFF, - v4Number & 0xFF - ].join('.'); + // Split the hex string into 8 groups of 4 hex digits (16 bits per group) + let ipv6 = []; + for (let i = 0; i < 8; i++) { + ipv6.push(hex.substr(i * 4, 4)); } - // Manually remove leading zeros from each block in the IPv6 part + console.log(ipv6) + // Manually remove leading zeros from each block ipv6 = ipv6.map(group => group.replace(/^0+/, '') || '0'); - // Find the longest sequence of zero blocks for shortening (same as previous method) + // Find the longest sequence of zero blocks to shorten let zeroStart = -1; let zeroLength = 0; let bestZeroStart = -1; @@ -681,24 +665,22 @@ class DomainInfo { ipv6.splice(bestZeroStart, bestZeroLength, ''); // Replace the longest zero sequence with an empty string } - // Join the groups with ':' to form the IPv6 part of the address + // Join the groups with ':' to form the IPv6 address let ipv6Address = ipv6.join(':'); - let ipv4_col = ':'; - // Handle special case where address starts or ends with :: if (ipv6Address.startsWith(':')) { ipv6Address = ':' + ipv6Address; } if (ipv6Address.endsWith(':')) { ipv6Address = ipv6Address + ':'; - ipv4_col = ''; } - // Return the combined IPv6 and IPv4 address - return ipv6Address + (v4Part ? ipv4_col + v4Part : ''); + return ipv6Address; } + + // In theory, we should be using a full-blown subnet parser/matcher here, // but let's keep it simple and stick with text for now. addrVersion() { @@ -714,8 +696,10 @@ class DomainInfo { // this.inAddrRange("6464:6464::a00:1", "6464:6464::/96") // this.inAddrRange("6464:6464:1:1:1:1:a00:1", "6464:6464::/96") - if (this.inAddrRange(this.addrBitsCIDR, this.nat64AddrBitsCIDR)) return ["4", true]; // RFC6052 - // if Option. + // console.log(this.addrBitsCIDR.addr.toString(2).padStart(128, "0")) + // console.log("thadder: ", this.addrBitsCIDR.addr.toString(16), "\nthisaddrSTR: ", this.addr) + if (this.inAddrRange(this.parseIPv6WithCIDR(this.addr), this.nat64AddrBitsCIDR)) return ["4", true]; // RFC6052 + // if Option. if (this.addr.indexOf(".") >= 0) return ["4", false]; if (this.addr.indexOf(":") >= 0) return ["6", false]; } From 1238a26cdb5960089a50a9b4e6cc329ef1261999 Mon Sep 17 00:00:00 2001 From: BPplays Date: Thu, 3 Oct 2024 17:39:30 -0700 Subject: [PATCH 020/115] added v4 rendering --- src/background.js | 51 +++++++++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/src/background.js b/src/background.js index 41eab68..8e5f1e0 100644 --- a/src/background.js +++ b/src/background.js @@ -360,7 +360,7 @@ class TabInfo extends SaveableEntry { let tooltip = ""; for (let [domain, d] of Object.entries(this.domains)) { if (domain == this.mainDomain) { - let [addrVer, _] = d.addrVersion(); + let [addrVer, nat64] = d.addrVersion(); pattern = addrVer; if (IS_MOBILE) { tooltip = d.addr; // Limited tooltip space on Android. @@ -370,14 +370,14 @@ class TabInfo extends SaveableEntry { } else { let [addrVer, nat64] = d.addrVersion(); - console.log(addrVer) + console.log(addrVer, nat64) switch (addrVer) { // case "nat64": d.addr = "2606:50c0:8000::"; console.log(d.addr); has4 = true; break; case "4": ; if (nat64) { // console.log(d.bigintToIPv6(d.addrBitsCIDR.addr, false)); // console.log(d.bigintToIPv6(d.addrBitsCIDR.addr, 96)); - // d.addr = d.bigintToMixedIPv6(d.addrBitsCIDR.addr, d.nat64AddrBitsCIDR.cidr); + d.addr = d.renderIPv6(d.parseIPv6WithCIDR(d.addr), true); } has4 = true break @@ -529,9 +529,10 @@ class DomainInfo { // let addr = this.parseIPv6WithCIDR(addr_str) // let nat64Addr = this.parseIPv6WithCIDR(nat64AddrStr) console.log("raadd: ", addr.addr.toString(16)) - let ren = this.bigintToIPv6(addr.addr, false) + let ren = this.renderIPv6(addr.addr, false) + let renv4 = this.renderIPv6(addr.addr, true) - console.log("addrstr: ", this.addr, "\nreren: ", ren) + console.log("addrstr: ", this.addr, "\nreren: ", ren, "\nrenv4: ", renv4) let addrMask = (BigInt(1) << BigInt(128 - nat64Addr.cidr)) - BigInt(1); addr.addr = addr.addr & ~addrMask; @@ -601,8 +602,27 @@ class DomainInfo { return { addr: addr, cidr: cidrValue }; } + renderIPv4(addr) { + let ipv4 = [] + + for (let i = 3; i >= 0; i--) { + + let mask = (BigInt(1) << BigInt(8)) - BigInt(1); + + console.log("v4 render test oct: ", addr.toString(2)) + let oct = addr >> BigInt(i * 8); + console.log("v4 render test oct: ", oct) + oct = oct & mask + console.log("v4 render test oct: ", oct) + ipv4.push(oct) + } + // console.log("v4 render test: ", ipv4) + + return ipv4.join(".") + + } - bigintToIPv6(bigInt, nat64 = false) { + renderIPv6(bigInt, nat64 = false) { // Ensure the input is a BigInt if (typeof bigInt !== 'bigint') { throw new TypeError('Input must be a BigInt'); @@ -614,25 +634,21 @@ class DomainInfo { let addrMask = (BigInt(1) << BigInt(32)) - BigInt(1); if (nat64) { - // ipv6Bits = ipv6Bits & ~addrMask + ipv6Bits = ipv6Bits & ~addrMask ipv4Bits = ipv4Bits & addrMask } - // Convert the BigInt to a hexadecimal string - let hex = ipv6Bits.toString(16).padStart(32, '0'); // Pad with zeros to ensure 32 hex digits + let hex = ipv6Bits.toString(16).padStart(32, '0'); console.log(hex, bigInt.toString(16)) - // Split the hex string into 8 groups of 4 hex digits (16 bits per group) let ipv6 = []; for (let i = 0; i < 8; i++) { ipv6.push(hex.substr(i * 4, 4)); } console.log(ipv6) - // Manually remove leading zeros from each block ipv6 = ipv6.map(group => group.replace(/^0+/, '') || '0'); - // Find the longest sequence of zero blocks to shorten let zeroStart = -1; let zeroLength = 0; let bestZeroStart = -1; @@ -654,27 +670,27 @@ class DomainInfo { } } - // Handle the case where the longest sequence of zero blocks is at the end if (zeroLength > bestZeroLength) { bestZeroStart = zeroStart; bestZeroLength = zeroLength; } - // If we found a sequence of two or more consecutive zero blocks, shorten it if (bestZeroLength > 1) { - ipv6.splice(bestZeroStart, bestZeroLength, ''); // Replace the longest zero sequence with an empty string + ipv6.splice(bestZeroStart, bestZeroLength, ''); } - // Join the groups with ':' to form the IPv6 address let ipv6Address = ipv6.join(':'); - // Handle special case where address starts or ends with :: if (ipv6Address.startsWith(':')) { ipv6Address = ':' + ipv6Address; } if (ipv6Address.endsWith(':')) { ipv6Address = ipv6Address + ':'; } + let ipv4 = this.renderIPv4(ipv4Bits); + if (nat64) { + ipv6Address += ipv4 + } return ipv6Address; } @@ -694,6 +710,7 @@ class DomainInfo { // this.inAddrRange("f:f:f:f::f:f", "f:f:f:f::f:f") // this.inAddrRange("f:f:f:f::", "f:f:f:f::f:f") // this.inAddrRange("6464:6464::a00:1", "6464:6464::/96") + if (this.inAddrRange(this.parseIPv6WithCIDR("6464:6464::a01:203"), this.nat64AddrBitsCIDR)) return ["4", true]; // RFC6052 // this.inAddrRange("6464:6464:1:1:1:1:a00:1", "6464:6464::/96") // console.log(this.addrBitsCIDR.addr.toString(2).padStart(128, "0")) From 7d8c1b9eb0e7b91a4643db98907e277dbf2fbeee Mon Sep 17 00:00:00 2001 From: BPplays Date: Thu, 3 Oct 2024 18:07:23 -0700 Subject: [PATCH 021/115] made popup render nat64 style --- src/background.js | 40 +++++++++++++++++++++++++++++++++------- src/popup.js | 3 ++- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/src/background.js b/src/background.js index 8e5f1e0..4654350 100644 --- a/src/background.js +++ b/src/background.js @@ -362,9 +362,18 @@ class TabInfo extends SaveableEntry { if (domain == this.mainDomain) { let [addrVer, nat64] = d.addrVersion(); pattern = addrVer; + + // if (nat64) { + // // console.log(d.bigintToIPv6(d.addrBitsCIDR.addr, false)); + // // console.log(d.bigintToIPv6(d.addrBitsCIDR.addr, 96)); + // let bitAddr = d.parseIPv6WithCIDR(d.addr); + // d.addr = d.renderIPv6(bitAddr.addr, true); + // } + if (IS_MOBILE) { tooltip = d.addr; // Limited tooltip space on Android. } else { + tooltip = `${d.addr}\n${NAME_VERSION}`; } } else { @@ -374,11 +383,12 @@ class TabInfo extends SaveableEntry { switch (addrVer) { // case "nat64": d.addr = "2606:50c0:8000::"; console.log(d.addr); has4 = true; break; case "4": ; - if (nat64) { - // console.log(d.bigintToIPv6(d.addrBitsCIDR.addr, false)); - // console.log(d.bigintToIPv6(d.addrBitsCIDR.addr, 96)); - d.addr = d.renderIPv6(d.parseIPv6WithCIDR(d.addr), true); - } + // if (nat64) { + // // console.log(d.bigintToIPv6(d.addrBitsCIDR.addr, false)); + // // console.log(d.bigintToIPv6(d.addrBitsCIDR.addr, 96)); + // let bitAddr = d.parseIPv6WithCIDR(d.addr); + // d.addr = d.renderIPv6(bitAddr.addr, true); + // } has4 = true break case "6": has6 = true; break; @@ -447,8 +457,9 @@ class TabInfo extends SaveableEntry { mainTuple[1] = d.addr; mainTuple[2] = addrVer; mainTuple[3] = d.flags; + mainTuple[4] = d.renderAddr(); } else { - tuples.push([domain, d.addr, addrVer, d.flags]); + tuples.push([domain, d.addr, addrVer, d.flags, d.renderAddr()]); } } return tuples; @@ -463,7 +474,7 @@ class TabInfo extends SaveableEntry { } let [addrVer, _] = d.addrVersion(); - return [domain, d.addr, addrVer, d.flags]; + return [domain, d.addr, addrVer, d.flags, d.renderAddr()]; } } @@ -473,6 +484,7 @@ class DomainInfo { addr; nat64Addr; nat64AddrBitsCIDR; + isNat64; flags; count = 0; // count of active requests @@ -484,6 +496,8 @@ class DomainInfo { this.addr = addr; this.nat64Addr = "6464:6464::/96"; this.nat64AddrBitsCIDR = this.parseIPv6WithCIDR(this.nat64Addr); + let [_, nat64] = this.addrVersion(addr) + this.isNat64 = nat64 this.flags = flags; } @@ -497,6 +511,18 @@ class DomainInfo { return new DomainInfo(tabInfo, domain, addr, flags); } + renderAddr() { + let [_, nat64] = this.addrVersion(this.addr) + this.isNat64 = nat64 + + if (this.isNat64) { + let bits = this.parseIPv6WithCIDR(this.addr) + return this.renderIPv6(bits.addr, true) + } + return this.addr + + } + setBitAtPosition(int, bitPosition, value) { if (value === 1) { // Set bit n to 1 (use OR) diff --git a/src/popup.js b/src/popup.js index 40eaade..f85336e 100644 --- a/src/popup.js +++ b/src/popup.js @@ -234,8 +234,9 @@ function makeSslImg(flags) { } function makeRow(isFirst, tuple) { + console.log(tuple) const domain = tuple[0]; - const addr = tuple[1]; + const addr = tuple[4]; const version = tuple[2]; const flags = tuple[3]; From 1d592cbf5a719e2b153c00abf2a3964b2266eff6 Mon Sep 17 00:00:00 2001 From: BPplays Date: Thu, 3 Oct 2024 22:53:25 -0700 Subject: [PATCH 022/115] changed dismiss to onmousedown instead of onclick --- src/background.js | 17 +++++++++-------- src/options.js | 2 +- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/background.js b/src/background.js index 4654350..472f231 100644 --- a/src/background.js +++ b/src/background.js @@ -556,9 +556,10 @@ class DomainInfo { // let nat64Addr = this.parseIPv6WithCIDR(nat64AddrStr) console.log("raadd: ", addr.addr.toString(16)) let ren = this.renderIPv6(addr.addr, false) + let rennat = this.renderIPv6(nat64Addr.addr, false) let renv4 = this.renderIPv6(addr.addr, true) - console.log("addrstr: ", this.addr, "\nreren: ", ren, "\nrenv4: ", renv4) + // console.log("addrstr: ", this.addr, "\nreren: ", ren, "\nrenv4: ", renv4) let addrMask = (BigInt(1) << BigInt(128 - nat64Addr.cidr)) - BigInt(1); addr.addr = addr.addr & ~addrMask; @@ -570,7 +571,7 @@ class DomainInfo { // console.log(addr.toString(2)) - // console.log("\naddr: ", addr.addr.toString(2), "\n", "nat64addr: ", nat64Addr.addr.toString(2), "\n bitmask: ", nat64AddrMask.toString(2)) + console.log("rended: ", ren, "\nrennat: ", rennat,"\naddr: ", addr.addr.toString(2), "\n", "nat64addr: ", nat64Addr.addr.toString(2), "\n bitmask: ", nat64AddrMask.toString(2)) return addr.addr === nat64Addr.addr; } catch (error) { console.log(error) @@ -635,11 +636,11 @@ class DomainInfo { let mask = (BigInt(1) << BigInt(8)) - BigInt(1); - console.log("v4 render test oct: ", addr.toString(2)) + // console.log("v4 render test oct: ", addr.toString(2)) let oct = addr >> BigInt(i * 8); - console.log("v4 render test oct: ", oct) + // console.log("v4 render test oct: ", oct) oct = oct & mask - console.log("v4 render test oct: ", oct) + // console.log("v4 render test oct: ", oct) ipv4.push(oct) } // console.log("v4 render test: ", ipv4) @@ -665,14 +666,14 @@ class DomainInfo { } let hex = ipv6Bits.toString(16).padStart(32, '0'); - console.log(hex, bigInt.toString(16)) + // console.log(hex, bigInt.toString(16)) let ipv6 = []; for (let i = 0; i < 8; i++) { ipv6.push(hex.substr(i * 4, 4)); } - console.log(ipv6) + // console.log(ipv6) ipv6 = ipv6.map(group => group.replace(/^0+/, '') || '0'); let zeroStart = -1; @@ -736,7 +737,7 @@ class DomainInfo { // this.inAddrRange("f:f:f:f::f:f", "f:f:f:f::f:f") // this.inAddrRange("f:f:f:f::", "f:f:f:f::f:f") // this.inAddrRange("6464:6464::a00:1", "6464:6464::/96") - if (this.inAddrRange(this.parseIPv6WithCIDR("6464:6464::a01:203"), this.nat64AddrBitsCIDR)) return ["4", true]; // RFC6052 + // if (this.inAddrRange(this.parseIPv6WithCIDR("6464:6464::a00:1"), this.nat64AddrBitsCIDR)) return ["4", true]; // RFC6052 // this.inAddrRange("6464:6464:1:1:1:1:a00:1", "6464:6464::/96") // console.log(this.addrBitsCIDR.addr.toString(2).padStart(128, "0")) diff --git a/src/options.js b/src/options.js index cbe8d22..b488f9a 100644 --- a/src/options.js +++ b/src/options.js @@ -63,7 +63,7 @@ window.onload = async () => { } }; - document.getElementById("dismiss_btn").onclick = function() { + document.getElementById("dismiss_btn").onmousedown = function() { if (window.history.length > 1) { window.history.back(); } else { From 2f23b20df3f5d6e8d9dea2dbaf80869b2f1cad34 Mon Sep 17 00:00:00 2001 From: BPplays Date: Thu, 3 Oct 2024 23:32:49 -0700 Subject: [PATCH 023/115] changed html input sytle --- src/options.html | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/options.html b/src/options.html index cc1acfb..11d2415 100644 --- a/src/options.html +++ b/src/options.html @@ -74,15 +74,24 @@ } input[type="text"] { - background-color: #333; + background-color: #303030; color: #eee; border-color: #444; border-style: "solid"; border-width: 0px; border-radius: 5px; + + outline-color: #666; + } + input[type="text"]:focus { + background-color: #333; + outline: 2px solid #333; + outline-offset: -2px; } } + + @@ -146,5 +155,7 @@

NAT64 Options

+ + From 9cea0a50c66c8ac2a1a26f65258eda2fbeba54c5 Mon Sep 17 00:00:00 2001 From: BPplays Date: Fri, 4 Oct 2024 01:59:40 -0700 Subject: [PATCH 024/115] added proper option for nat64 --- src/background.js | 2 +- src/common.js | 2 +- src/options.html | 1 - src/options.js | 8 ++++++-- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/background.js b/src/background.js index 472f231..1e9188c 100644 --- a/src/background.js +++ b/src/background.js @@ -494,7 +494,7 @@ class DomainInfo { this.tabInfo = tabInfo; this.domain = domain; this.addr = addr; - this.nat64Addr = "6464:6464::/96"; + this.nat64Addr = options['nat64Prefix']; this.nat64AddrBitsCIDR = this.parseIPv6WithCIDR(this.nat64Addr); let [_, nat64] = this.addrVersion(addr) this.isNat64 = nat64 diff --git a/src/common.js b/src/common.js index 0f2e988..390f8de 100644 --- a/src/common.js +++ b/src/common.js @@ -150,7 +150,7 @@ function drawSprite(ctx, size, targets, sources) { const DEFAULT_OPTIONS = { regularColorScheme: "darkfg", incognitoColorScheme: "lightfg", - // nat64Prefix: "64:ff9b::", + nat64Prefix: "64:ff9b::", }; let _watchOptionsFunc = null; diff --git a/src/options.html b/src/options.html index 11d2415..942545f 100644 --- a/src/options.html +++ b/src/options.html @@ -76,7 +76,6 @@ input[type="text"] { background-color: #303030; color: #eee; - border-color: #444; border-style: "solid"; border-width: 0px; border-radius: 5px; diff --git a/src/options.js b/src/options.js index b488f9a..b1ad571 100644 --- a/src/options.js +++ b/src/options.js @@ -35,10 +35,10 @@ window.onload = async () => { watchOptions(function(optionsChanged) { for (const option of optionsChanged) { - if (option === "nat64Prefix") { - + document.getElementById('nat64Prefix').value = options["nat64Prefix"]; } + if (!option.endsWith("ColorScheme")) continue; const radio = document.optionsForm[option]; radio.value = options[option]; @@ -48,6 +48,10 @@ window.onload = async () => { document.optionsForm.onchange = function(evt) { const newOptions = {}; + + const nat64Prefix = document.getElementById('nat64Prefix').value; + newOptions["nat64Prefix"] = nat64Prefix; + for (const option of Object.keys(DEFAULT_OPTIONS)) { if (!option.endsWith("ColorScheme")) continue; newOptions[option] = document.optionsForm[option].value; From 925e2ce29c751616b6ffe4d00497fe18944ae82f Mon Sep 17 00:00:00 2001 From: BPplays Date: Fri, 4 Oct 2024 02:03:12 -0700 Subject: [PATCH 025/115] added proper option for nat64 --- src/common.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common.js b/src/common.js index 390f8de..7da33bd 100644 --- a/src/common.js +++ b/src/common.js @@ -150,7 +150,7 @@ function drawSprite(ctx, size, targets, sources) { const DEFAULT_OPTIONS = { regularColorScheme: "darkfg", incognitoColorScheme: "lightfg", - nat64Prefix: "64:ff9b::", + nat64Prefix: "64:ff9b::/96", }; let _watchOptionsFunc = null; From 3c615f5b0deff441584e39111647475488d7972e Mon Sep 17 00:00:00 2001 From: BPplays Date: Fri, 4 Oct 2024 19:14:56 -0700 Subject: [PATCH 026/115] started adding nat64hex option --- src/background.js | 14 ++++++++++++++ src/common.js | 1 + src/options.html | 4 ++++ src/options.js | 10 ++++++++++ 4 files changed, 29 insertions(+) diff --git a/src/background.js b/src/background.js index 1e9188c..6bda163 100644 --- a/src/background.js +++ b/src/background.js @@ -523,6 +523,20 @@ class DomainInfo { } + getNat64Addr() { + if (options['nat64Prefix'] === "") { + // this.nat64AddrBitsCIDR = this.parseIPv6WithCIDR(); + // this.nat64Addr = options['nat64Prefix']; + } else { + this.nat64Addr = options['nat64Prefix']; + this.nat64AddrBitsCIDR = this.parseIPv6WithCIDR(this.nat64Addr); + } + + this.nat64AddrBitsCIDR = this.parseIPv6WithCIDR(this.nat64Addr); + let [_, nat64] = this.addrVersion(this.addr) + this.isNat64 = nat64 + } + setBitAtPosition(int, bitPosition, value) { if (value === 1) { // Set bit n to 1 (use OR) diff --git a/src/common.js b/src/common.js index 7da33bd..b0791fd 100644 --- a/src/common.js +++ b/src/common.js @@ -151,6 +151,7 @@ const DEFAULT_OPTIONS = { regularColorScheme: "darkfg", incognitoColorScheme: "lightfg", nat64Prefix: "64:ff9b::/96", + nat64V4PartHex: false, }; let _watchOptionsFunc = null; diff --git a/src/options.html b/src/options.html index 942545f..129d8f8 100644 --- a/src/options.html +++ b/src/options.html @@ -147,6 +147,10 @@

NAT64 Options

+ + diff --git a/src/options.js b/src/options.js index b1ad571..21e32a1 100644 --- a/src/options.js +++ b/src/options.js @@ -74,6 +74,16 @@ window.onload = async () => { window.close(); } }; + + + document.getElementById("nat64hex").onclick = function(event) { + event.preventDefault(); + // this.checked = !this.checked; + }; + + document.getElementById("nat64hex").onmousedown = function() { + this.checked = !this.checked; + }; } function disableAll(disabled) { From 8aaa352cb173a378159d4f10d9f5844d7befaff0 Mon Sep 17 00:00:00 2001 From: BPplays Date: Fri, 4 Oct 2024 19:55:56 -0700 Subject: [PATCH 027/115] started adding nat64hex option --- src/background.js | 2 ++ src/common.js | 2 +- src/options.html | 2 +- src/options.js | 20 ++++++++++++++++---- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/background.js b/src/background.js index 6bda163..098bc69 100644 --- a/src/background.js +++ b/src/background.js @@ -515,6 +515,8 @@ class DomainInfo { let [_, nat64] = this.addrVersion(this.addr) this.isNat64 = nat64 + // if (this.isNat64 && options("nex64Hex")) { + console.log("nat64 hex: ", options["nat64Hex"]) if (this.isNat64) { let bits = this.parseIPv6WithCIDR(this.addr) return this.renderIPv6(bits.addr, true) diff --git a/src/common.js b/src/common.js index b0791fd..0256337 100644 --- a/src/common.js +++ b/src/common.js @@ -151,7 +151,7 @@ const DEFAULT_OPTIONS = { regularColorScheme: "darkfg", incognitoColorScheme: "lightfg", nat64Prefix: "64:ff9b::/96", - nat64V4PartHex: false, + nat64Hex: false, }; let _watchOptionsFunc = null; diff --git a/src/options.html b/src/options.html index 129d8f8..abc0b08 100644 --- a/src/options.html +++ b/src/options.html @@ -149,7 +149,7 @@

NAT64 Options

diff --git a/src/options.js b/src/options.js index 21e32a1..68b506d 100644 --- a/src/options.js +++ b/src/options.js @@ -39,6 +39,10 @@ window.onload = async () => { document.getElementById('nat64Prefix').value = options["nat64Prefix"]; } + if (option === "nat64Hex") { + document.getElementById('nat64Hex').checked = options["nat64Hex"]; + } + if (!option.endsWith("ColorScheme")) continue; const radio = document.optionsForm[option]; radio.value = options[option]; @@ -52,6 +56,9 @@ window.onload = async () => { const nat64Prefix = document.getElementById('nat64Prefix').value; newOptions["nat64Prefix"] = nat64Prefix; + const nat64Hex = document.getElementById('nat64Hex').checked; + newOptions["nat64Hex"] = nat64Hex; + for (const option of Object.keys(DEFAULT_OPTIONS)) { if (!option.endsWith("ColorScheme")) continue; newOptions[option] = document.optionsForm[option].value; @@ -76,12 +83,17 @@ window.onload = async () => { }; - document.getElementById("nat64hex").onclick = function(event) { - event.preventDefault(); - // this.checked = !this.checked; + + // document.getElementById("nat64Hex").onclick = function(event) { + // event.preventDefault(); + // }; + + document.getElementById("nat64Hex").onmousedown = function() { + this.checked = !this.checked; }; - document.getElementById("nat64hex").onmousedown = function() { + + document.getElementById("nat64Hex").onmouseup = function() { this.checked = !this.checked; }; } From eb57d6baf1daa2b0184090570a64e0c5fd3dc717 Mon Sep 17 00:00:00 2001 From: BPplays Date: Sat, 5 Oct 2024 02:53:05 -0700 Subject: [PATCH 028/115] started adding nat64hex option --- src/background.js | 4 +--- src/options.js | 2 ++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/background.js b/src/background.js index 098bc69..480dc06 100644 --- a/src/background.js +++ b/src/background.js @@ -515,9 +515,7 @@ class DomainInfo { let [_, nat64] = this.addrVersion(this.addr) this.isNat64 = nat64 - // if (this.isNat64 && options("nex64Hex")) { - console.log("nat64 hex: ", options["nat64Hex"]) - if (this.isNat64) { + if (this.isNat64 && !options["nat64Hex"]) { let bits = this.parseIPv6WithCIDR(this.addr) return this.renderIPv6(bits.addr, true) } diff --git a/src/options.js b/src/options.js index 68b506d..7bf1b67 100644 --- a/src/options.js +++ b/src/options.js @@ -84,12 +84,14 @@ window.onload = async () => { + // document.getElementById("nat64Hex").onclick = function(event) { // event.preventDefault(); // }; document.getElementById("nat64Hex").onmousedown = function() { this.checked = !this.checked; + // this.click() }; From a38562137b126c6e6895e5cd2829c8e889c5b4be Mon Sep 17 00:00:00 2001 From: BPplays Date: Sat, 5 Oct 2024 13:11:33 -0700 Subject: [PATCH 029/115] changed onmousedown for hex opt --- src/options.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/options.js b/src/options.js index 7bf1b67..dbf4cb7 100644 --- a/src/options.js +++ b/src/options.js @@ -84,19 +84,25 @@ window.onload = async () => { + let nat64hex_click_on = false; - // document.getElementById("nat64Hex").onclick = function(event) { - // event.preventDefault(); - // }; + document.getElementById("nat64Hex").onclick = function(event) { + if (!nat64hex_click_on) { + event.preventDefault(); + } + }; document.getElementById("nat64Hex").onmousedown = function() { - this.checked = !this.checked; - // this.click() + // this.checked = !this.checked; + nat64hex_click_on = true; + this.click() + nat64hex_click_on = false; + // this.value = this.checked }; document.getElementById("nat64Hex").onmouseup = function() { - this.checked = !this.checked; + // this.checked = !this.checked; }; } From a6b8097e4ee6ca82e7112d71358d8b91aa30d74e Mon Sep 17 00:00:00 2001 From: BPplays Date: Sat, 5 Oct 2024 13:17:08 -0700 Subject: [PATCH 030/115] changed onmousedown for hex opt --- src/options.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/options.js b/src/options.js index dbf4cb7..894bd6f 100644 --- a/src/options.js +++ b/src/options.js @@ -93,11 +93,13 @@ window.onload = async () => { }; document.getElementById("nat64Hex").onmousedown = function() { - // this.checked = !this.checked; nat64hex_click_on = true; this.click() nat64hex_click_on = false; + + // this.checked = !this.checked; // this.value = this.checked + // this.onchange() }; From 7feb17cfef922534e5b2e0fb65a7d1b45afc95b5 Mon Sep 17 00:00:00 2001 From: BPplays Date: Sat, 5 Oct 2024 23:19:30 -0700 Subject: [PATCH 031/115] changed onmousedown for hex opt --- src/options.html | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/options.html b/src/options.html index abc0b08..71691e1 100644 --- a/src/options.html +++ b/src/options.html @@ -143,10 +143,13 @@

Icon color scheme


NAT64 Options

-
- - -
+ + + + +