summaryrefslogtreecommitdiff
path: root/data/extensions/https-everywhere@eff.org/background-scripts/ip_utils.js
diff options
context:
space:
mode:
authorRuben Rodriguez <ruben@trisquel.info>2022-09-08 20:18:54 -0400
committerRuben Rodriguez <ruben@trisquel.info>2022-09-08 20:18:54 -0400
commit5da28b0f8771834ae208d61431d632875e9f8e7d (patch)
tree688ecaff26197bad8abde617b4947b11d617309e /data/extensions/https-everywhere@eff.org/background-scripts/ip_utils.js
parent4a87716686104266a9cccc2d83cc249e312f3673 (diff)
Updated extensions:
* Upgraded Privacy Redirect to 1.1.49 and configured to use the 10 most reliable invidious instances * Removed ViewTube * Added torproxy@icecat.gnu based on 'Proxy toggle' extension * Added jShelter 0.11.1 * Upgraded LibreJS to 7.21.0 * Upgraded HTTPS Everywhere to 2021.7.13 * Upgraded SubmitMe to 1.9
Diffstat (limited to 'data/extensions/https-everywhere@eff.org/background-scripts/ip_utils.js')
-rw-r--r--data/extensions/https-everywhere@eff.org/background-scripts/ip_utils.js20
1 files changed, 19 insertions, 1 deletions
diff --git a/data/extensions/https-everywhere@eff.org/background-scripts/ip_utils.js b/data/extensions/https-everywhere@eff.org/background-scripts/ip_utils.js
index be7c1c8..90e0b1a 100644
--- a/data/extensions/https-everywhere@eff.org/background-scripts/ip_utils.js
+++ b/data/extensions/https-everywhere@eff.org/background-scripts/ip_utils.js
@@ -2,11 +2,17 @@
(function (exports) {
+/**
+ * Parse and convert literal IP address into numerical IP address.
+ * @param {string} ip
+ * @returns {number}
+ */
const parseIp = ip => {
if (!/^[0-9.]+$/.test(ip)) {
return -1;
}
+ /** @type {string[]} */
const octets = ip.split('.');
if (octets.length !== 4) {
@@ -26,14 +32,21 @@ const parseIp = ip => {
return -1;
}
- ipN = (ipN << 8) | octet;
+ ipN = (ipN << 8) | octetN;
}
return ipN >>> 0;
};
+/**
+ * Check if the numeric IP address is within a certain range.
+ * @param {number} ip
+ * @param {number[]} range
+ * @returns {boolean}
+ */
const isIpInRange = (ip, [rangeIp, mask]) => (ip & mask) >>> 0 === rangeIp;
+// A list of local IP address ranges
const localRanges = [
[/* 0.0.0.0 */ 0x00000000, /* 255.255.255.255 */ 0xffffffff],
[/* 127.0.0.0 */ 0x7f000000, /* 255.0.0.0 */ 0xff000000],
@@ -42,6 +55,11 @@ const localRanges = [
[/* 192.168.0.0 */ 0xc0a80000, /* 255.255.0.0 */ 0xffff0000],
];
+/**
+ * Check if the numeric IP address is inside the local IP address ranges.
+ * @param {number} ip
+ * @returns {boolean}
+ */
const isLocalIp = ip => localRanges.some(range => isIpInRange(ip, range));
Object.assign(exports, {