pmcf 1.35.0 → 1.35.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/pmcf-named-defs +3 -3
- package/package.json +1 -1
- package/src/utils.mjs +43 -8
- package/types/utils.d.mts +1 -0
package/bin/pmcf-named-defs
CHANGED
|
@@ -80,13 +80,13 @@ async function generateNamedDefs(owner, targetDir) {
|
|
|
80
80
|
for (const subnet of owner.subnets()) {
|
|
81
81
|
if (subnet.prefix) {
|
|
82
82
|
const reverseArpa = reverseArpaAddress(subnet.prefix);
|
|
83
|
-
const
|
|
83
|
+
const reverseZone = {
|
|
84
84
|
id: reverseArpa,
|
|
85
85
|
file: `${reverseArpa}.zone`,
|
|
86
86
|
records: new Set([SOARecord, NSRecord])
|
|
87
87
|
};
|
|
88
|
-
zones.push(
|
|
89
|
-
subnet.reverseZone =
|
|
88
|
+
zones.push(reverseZone);
|
|
89
|
+
subnet.reverseZone = reverseZone;
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
|
package/package.json
CHANGED
package/src/utils.mjs
CHANGED
|
@@ -40,6 +40,10 @@ export function isIPv6Address(address) {
|
|
|
40
40
|
return address.indexOf(":") >= 0;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
export function isLinkLocal(address) {
|
|
44
|
+
return address.startsWith("fe80");
|
|
45
|
+
}
|
|
46
|
+
|
|
43
47
|
export function normalizeIPAddress(address) {
|
|
44
48
|
address = address.replace(/\/\d+$/, "");
|
|
45
49
|
if (isIPv4Address(address)) {
|
|
@@ -53,20 +57,51 @@ export function normalizeIPAddress(address) {
|
|
|
53
57
|
return parts.map(s => s.padStart(4, "0")).join(":");
|
|
54
58
|
}
|
|
55
59
|
|
|
60
|
+
function encodeIPv4(address) {
|
|
61
|
+
const octets = [0, 0, 0, 0];
|
|
62
|
+
|
|
63
|
+
let i = 0;
|
|
64
|
+
for (const a of address.split(/\./)) {
|
|
65
|
+
octets[i++] = parseInt(a);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return (octets[0] << 24) + (octets[1] << 16) + (octets[2] << 8) + octets[3];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function decodeIPv4(address, length = 32) {
|
|
72
|
+
const octets = [
|
|
73
|
+
(address >> 24) & 0xff,
|
|
74
|
+
(address >> 16) & 0xff,
|
|
75
|
+
(address >> 8) & 0xff,
|
|
76
|
+
address & 0xff
|
|
77
|
+
];
|
|
78
|
+
|
|
79
|
+
octets.length = Math.ceil(length / 8);
|
|
80
|
+
|
|
81
|
+
return octets.join(".");
|
|
82
|
+
}
|
|
83
|
+
|
|
56
84
|
export function normalizeCIDR(address) {
|
|
57
85
|
let [prefix, prefixLength] = address.split(/\//);
|
|
58
86
|
|
|
59
|
-
if (prefixLength) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
87
|
+
if (!prefixLength && isLinkLocal(address)) {
|
|
88
|
+
prefix = "fe80::";
|
|
89
|
+
prefixLength = 64;
|
|
90
|
+
} else {
|
|
91
|
+
if (prefixLength) {
|
|
92
|
+
if (isIPv4Address(prefix)) {
|
|
93
|
+
let n = encodeIPv4(prefix);
|
|
94
|
+
n = n & (0xffffffff << (32 - prefixLength));
|
|
95
|
+
prefix = decodeIPv4(n, prefixLength);
|
|
96
|
+
} else {
|
|
97
|
+
prefix = normalizeIPAddress(prefix);
|
|
98
|
+
const parts = prefix.split(/\:/);
|
|
99
|
+
prefix = parts.slice(0, prefixLength / 16).join(":");
|
|
100
|
+
}
|
|
63
101
|
} else {
|
|
64
|
-
|
|
102
|
+
return {};
|
|
65
103
|
}
|
|
66
104
|
}
|
|
67
|
-
else {
|
|
68
|
-
return {};
|
|
69
|
-
}
|
|
70
105
|
|
|
71
106
|
return { prefix, prefixLength, cidr: `${prefix}/${prefixLength}` };
|
|
72
107
|
}
|
package/types/utils.d.mts
CHANGED
|
@@ -4,6 +4,7 @@ export function bridgeToJSON(bridge: any): any[];
|
|
|
4
4
|
export function asArray(value: any): any[];
|
|
5
5
|
export function isIPv4Address(address: any): boolean;
|
|
6
6
|
export function isIPv6Address(address: any): boolean;
|
|
7
|
+
export function isLinkLocal(address: any): any;
|
|
7
8
|
export function normalizeIPAddress(address: any): any;
|
|
8
9
|
export function normalizeCIDR(address: any): {
|
|
9
10
|
prefix?: undefined;
|