pmcf 1.43.0 → 1.43.1
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/package.json +1 -1
- package/src/host.mjs +3 -7
- package/src/owner.mjs +10 -0
- package/src/subnet.mjs +5 -1
- package/src/utils.mjs +11 -3
- package/types/host.d.mts +0 -1
package/package.json
CHANGED
package/src/host.mjs
CHANGED
|
@@ -402,7 +402,7 @@ export class NetworkInterface extends Base {
|
|
|
402
402
|
subnetForAddress(address) {
|
|
403
403
|
return (
|
|
404
404
|
this.network?.subnetForAddress(address) ||
|
|
405
|
-
this.
|
|
405
|
+
this.host.owner.subnetForAddress(address)
|
|
406
406
|
);
|
|
407
407
|
}
|
|
408
408
|
|
|
@@ -427,8 +427,8 @@ export class NetworkInterface extends Base {
|
|
|
427
427
|
}
|
|
428
428
|
|
|
429
429
|
get ipAddressesWithPrefixLength() {
|
|
430
|
-
return [...this
|
|
431
|
-
|
|
430
|
+
return [...this.#ipAddresses].map(
|
|
431
|
+
([address, subnet]) => `${address}/${subnet?.prefixLength}`
|
|
432
432
|
);
|
|
433
433
|
}
|
|
434
434
|
|
|
@@ -440,10 +440,6 @@ export class NetworkInterface extends Base {
|
|
|
440
440
|
return [...this.ipAddresses].filter(a => isIPv6Address(a));
|
|
441
441
|
}
|
|
442
442
|
|
|
443
|
-
get prefixLength() {
|
|
444
|
-
return this.network?.prefixLength;
|
|
445
|
-
}
|
|
446
|
-
|
|
447
443
|
get host() {
|
|
448
444
|
return this.owner;
|
|
449
445
|
}
|
package/src/owner.mjs
CHANGED
|
@@ -165,6 +165,16 @@ export class Owner extends Base {
|
|
|
165
165
|
if (cidr) {
|
|
166
166
|
return this.subnetNamed(cidr) || new Subnet(this, cidr);
|
|
167
167
|
}
|
|
168
|
+
|
|
169
|
+
const subnets = [...this.subnets()];
|
|
170
|
+
if (subnets.length === 1) {
|
|
171
|
+
return subnets[0];
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
this.error(
|
|
175
|
+
`Address without subnet ${address}`,
|
|
176
|
+
[...this.subnets()].map(s => s.address)
|
|
177
|
+
);
|
|
168
178
|
}
|
|
169
179
|
|
|
170
180
|
subnetForAddress(address) {
|
package/src/subnet.mjs
CHANGED
|
@@ -14,7 +14,11 @@ export class Subnet extends Base {
|
|
|
14
14
|
name: "subnet",
|
|
15
15
|
extends: "base",
|
|
16
16
|
properties: {
|
|
17
|
-
|
|
17
|
+
/*
|
|
18
|
+
address: {},
|
|
19
|
+
networks: { type: "network", collection true },
|
|
20
|
+
prefixLength: { type: "number", writeable: false }
|
|
21
|
+
*/
|
|
18
22
|
}
|
|
19
23
|
};
|
|
20
24
|
}
|
package/src/utils.mjs
CHANGED
|
@@ -137,15 +137,23 @@ export function normalizeCIDR(address) {
|
|
|
137
137
|
prefix = "fe80::";
|
|
138
138
|
prefixLength = 64;
|
|
139
139
|
} else {
|
|
140
|
+
const definition = isIPv4Address(prefix) ? ipv4 : ipv6;
|
|
141
|
+
let n = _encode(definition, prefix);
|
|
142
|
+
|
|
140
143
|
if (prefixLength) {
|
|
141
|
-
const definition = isIPv4Address(prefix) ? ipv4 : ipv6;
|
|
142
|
-
let n = _encode(definition, prefix);
|
|
143
144
|
n = n & (definition.mask << BigInt(definition.length - prefixLength));
|
|
144
145
|
prefix = _decode(definition, n, prefixLength);
|
|
145
146
|
} else {
|
|
146
|
-
|
|
147
|
+
if (n === IPV4_LOCALHOST) {
|
|
148
|
+
prefixLength = 8;
|
|
149
|
+
prefix = _decode(definition, n, prefixLength);
|
|
150
|
+
} else {
|
|
151
|
+
return {};
|
|
152
|
+
}
|
|
147
153
|
}
|
|
148
154
|
}
|
|
149
155
|
|
|
150
156
|
return { prefix, prefixLength, cidr: `${prefix}/${prefixLength}` };
|
|
151
157
|
}
|
|
158
|
+
|
|
159
|
+
const IPV4_LOCALHOST = _encode(ipv4,'127.0.0.1')
|
package/types/host.d.mts
CHANGED