pmcf 2.18.2 → 2.19.0
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 +2 -1
- package/src/dns-utils.mjs +1 -1
- package/src/host.install +0 -2
- package/src/host.mjs +128 -68
- package/src/owner.mjs +1 -1
- package/src/service.mjs +3 -1
- package/src/services/dhcp.mjs +2 -1
- package/src/services/dns.mjs +17 -2
- package/src/subnet.mjs +1 -1
- package/types/host.d.mts +351 -13
- package/types/services/dns.d.mts +8 -0
- package/types/subnet.d.mts +4 -4
- package/src/ip.mjs +0 -323
- package/types/ip.d.mts +0 -37
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pmcf",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.19.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
"lint:typescript": "tsc --allowJs --checkJs --noEmit --resolveJsonModule --target es2024 --lib esnext -m esnext --module nodenext --moduleResolution nodenext ./src**/*.mjs"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
+
"ip-utilties": "^1.0.0",
|
|
41
42
|
"npm-pkgbuild": "^18.0.1",
|
|
42
43
|
"pacc": "^3.3.0",
|
|
43
44
|
"pkg-dir": "^8.0.0"
|
package/src/dns-utils.mjs
CHANGED
package/src/host.install
CHANGED
|
@@ -3,7 +3,6 @@ post_install()
|
|
|
3
3
|
ls -l /etc/resolv.conf | grep -q /run/systemd/resolve/resolv.conf
|
|
4
4
|
if [ $? = 1 ]
|
|
5
5
|
then
|
|
6
|
-
mv /etc/resolv.conf /etc/resolv.conf.pre
|
|
7
6
|
ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf
|
|
8
7
|
fi
|
|
9
8
|
}
|
|
@@ -13,7 +12,6 @@ post_upgrade()
|
|
|
13
12
|
ls -l /etc/resolv.conf | grep -q /run/systemd/resolve/resolv.conf
|
|
14
13
|
if [ $? = 1 ]
|
|
15
14
|
then
|
|
16
|
-
mv /etc/resolv.conf /etc/resolv.conf.pre
|
|
17
15
|
ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf
|
|
18
16
|
fi
|
|
19
17
|
}
|
package/src/host.mjs
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { readFile } from "node:fs/promises";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { FileContentProvider } from "npm-pkgbuild";
|
|
4
|
-
import { Base } from "./base.mjs";
|
|
5
|
-
import {
|
|
6
|
-
networkProperties,
|
|
7
|
-
networkAddressProperties
|
|
8
|
-
} from "./network-support.mjs";
|
|
9
|
-
import { asArray, domainFromDominName, domainName } from "./utils.mjs";
|
|
10
4
|
import {
|
|
11
5
|
isIPv4,
|
|
12
6
|
isIPv6,
|
|
13
7
|
formatCIDR,
|
|
14
8
|
hasWellKnownSubnet,
|
|
15
9
|
normalizeIP
|
|
16
|
-
} from "
|
|
10
|
+
} from "ip-utilties";
|
|
11
|
+
import { Base } from "./base.mjs";
|
|
12
|
+
import {
|
|
13
|
+
networkProperties,
|
|
14
|
+
networkAddressProperties
|
|
15
|
+
} from "./network-support.mjs";
|
|
16
|
+
import { asArray, domainFromDominName, domainName } from "./utils.mjs";
|
|
17
17
|
import { objectFilter } from "./filter.mjs";
|
|
18
18
|
import { addType, types } from "./types.mjs";
|
|
19
19
|
import { loadHooks } from "./hooks.mjs";
|
|
@@ -406,7 +406,7 @@ export class Host extends Base {
|
|
|
406
406
|
filter
|
|
407
407
|
);
|
|
408
408
|
}
|
|
409
|
-
|
|
409
|
+
|
|
410
410
|
findNetworkInterface(filter) {
|
|
411
411
|
for (const ni of objectFilter(
|
|
412
412
|
types.network_interface,
|
|
@@ -505,11 +505,85 @@ export class Host extends Base {
|
|
|
505
505
|
}
|
|
506
506
|
}
|
|
507
507
|
|
|
508
|
+
class SkeletonNetworkInterface extends Base {
|
|
509
|
+
_extends = [];
|
|
510
|
+
_network;
|
|
511
|
+
|
|
512
|
+
set extends(value) {
|
|
513
|
+
this._extends.push(value);
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
get extends() {
|
|
517
|
+
return this._extends;
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
get isTemplate() {
|
|
521
|
+
return this.name.indexOf("*") >= 0;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
get host() {
|
|
525
|
+
return this.owner;
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
get network_interface() {
|
|
529
|
+
return this;
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
get domainNames() {
|
|
533
|
+
return new Set();
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
matches(other) {
|
|
537
|
+
if (this.isTemplate) {
|
|
538
|
+
const name = this.name.replace("*", "");
|
|
539
|
+
return name.length === 0 || other.name.indexOf(name) >= 0;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
return false;
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
get network() {
|
|
546
|
+
return this.extendedProperty("_network") ?? this.host.network;
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
set network(network) {
|
|
550
|
+
this._network = network;
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
get rawAddress() {
|
|
554
|
+
return this.rawAddresses[0];
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
get rawIPv4Address() {
|
|
558
|
+
return this.rawAddresses.filter(a => isIPv4(a))[0];
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
get rawIPv6Address() {
|
|
562
|
+
return this.rawAddresses.filter(a => isIPv6(a))[0];
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
get cidrAddress() {
|
|
566
|
+
return this.cidrAddresses[0];
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
|
|
508
570
|
const NetworkInterfaceTypeDefinition = {
|
|
509
571
|
name: "network_interface",
|
|
510
572
|
priority: 0.4,
|
|
511
573
|
owners: ["host"],
|
|
512
574
|
extends: Base.typeDefinition,
|
|
575
|
+
specializations: {},
|
|
576
|
+
factoryFor(value) {
|
|
577
|
+
const kind = value.kind;
|
|
578
|
+
const t = NetworkInterfaceTypeDefinition.specializations[kind];
|
|
579
|
+
|
|
580
|
+
if (t) {
|
|
581
|
+
delete value.type;
|
|
582
|
+
return t.clazz;
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
return NetworkInterface;
|
|
586
|
+
},
|
|
513
587
|
properties: {
|
|
514
588
|
...networkProperties,
|
|
515
589
|
...networkAddressProperties,
|
|
@@ -523,7 +597,7 @@ const NetworkInterfaceTypeDefinition = {
|
|
|
523
597
|
}
|
|
524
598
|
};
|
|
525
599
|
|
|
526
|
-
export class NetworkInterface extends
|
|
600
|
+
export class NetworkInterface extends SkeletonNetworkInterface {
|
|
527
601
|
static {
|
|
528
602
|
addType(this);
|
|
529
603
|
}
|
|
@@ -537,12 +611,10 @@ export class NetworkInterface extends Base {
|
|
|
537
611
|
_metric;
|
|
538
612
|
_ssid;
|
|
539
613
|
_psk;
|
|
540
|
-
_network;
|
|
541
614
|
_kind;
|
|
542
615
|
_hostName;
|
|
543
616
|
_hwaddr;
|
|
544
617
|
_class;
|
|
545
|
-
_extends = [];
|
|
546
618
|
arpbridge;
|
|
547
619
|
|
|
548
620
|
constructor(owner, data) {
|
|
@@ -550,19 +622,6 @@ export class NetworkInterface extends Base {
|
|
|
550
622
|
this.read(data, NetworkInterfaceTypeDefinition);
|
|
551
623
|
}
|
|
552
624
|
|
|
553
|
-
get isTemplate() {
|
|
554
|
-
return this.name.indexOf("*") >= 0;
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
matches(other) {
|
|
558
|
-
if (this.isTemplate) {
|
|
559
|
-
const name = this.name.replace("*", "");
|
|
560
|
-
return name.length === 0 || other.name.indexOf(name) >= 0;
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
return false;
|
|
564
|
-
}
|
|
565
|
-
|
|
566
625
|
addSubnet(address) {
|
|
567
626
|
if (!this.network) {
|
|
568
627
|
if (!hasWellKnownSubnet(address)) {
|
|
@@ -579,33 +638,14 @@ export class NetworkInterface extends Base {
|
|
|
579
638
|
|
|
580
639
|
set ipAddresses(value) {
|
|
581
640
|
for (const address of asArray(value)) {
|
|
582
|
-
this._ipAddresses.set(
|
|
583
|
-
normalizeIP(address),
|
|
584
|
-
this.addSubnet(address)
|
|
585
|
-
);
|
|
641
|
+
this._ipAddresses.set(normalizeIP(address), this.addSubnet(address));
|
|
586
642
|
}
|
|
587
643
|
}
|
|
588
644
|
|
|
589
|
-
get rawAddress() {
|
|
590
|
-
return this.rawAddresses[0];
|
|
591
|
-
}
|
|
592
|
-
|
|
593
|
-
get rawIPv4Address() {
|
|
594
|
-
return this.rawAddresses.filter(a => isIPv4(a))[0];
|
|
595
|
-
}
|
|
596
|
-
|
|
597
|
-
get rawIPv6Address() {
|
|
598
|
-
return this.rawAddresses.filter(a => isIPv6(a))[0];
|
|
599
|
-
}
|
|
600
|
-
|
|
601
645
|
get rawAddresses() {
|
|
602
646
|
return [...this._ipAddresses].map(([address]) => address);
|
|
603
647
|
}
|
|
604
648
|
|
|
605
|
-
get cidrAddress() {
|
|
606
|
-
return this.cidrAddresses[0];
|
|
607
|
-
}
|
|
608
|
-
|
|
609
649
|
get cidrAddresses() {
|
|
610
650
|
return [...this._ipAddresses].map(([address, subnet]) =>
|
|
611
651
|
formatCIDR(address, subnet)
|
|
@@ -657,30 +697,6 @@ export class NetworkInterface extends Base {
|
|
|
657
697
|
: this.host.directDomainNames;
|
|
658
698
|
}
|
|
659
699
|
|
|
660
|
-
get host() {
|
|
661
|
-
return this.owner;
|
|
662
|
-
}
|
|
663
|
-
|
|
664
|
-
get network_interface() {
|
|
665
|
-
return this;
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
set extends(value) {
|
|
669
|
-
this._extends.push(value);
|
|
670
|
-
}
|
|
671
|
-
|
|
672
|
-
get extends() {
|
|
673
|
-
return this._extends;
|
|
674
|
-
}
|
|
675
|
-
|
|
676
|
-
get network() {
|
|
677
|
-
return this.extendedProperty("_network") ?? this.host.network;
|
|
678
|
-
}
|
|
679
|
-
|
|
680
|
-
set network(network) {
|
|
681
|
-
this._network = network;
|
|
682
|
-
}
|
|
683
|
-
|
|
684
700
|
set scope(value) {
|
|
685
701
|
this._scope = value;
|
|
686
702
|
}
|
|
@@ -753,3 +769,47 @@ export class NetworkInterface extends Base {
|
|
|
753
769
|
return this.extendedProperty("_kind") ?? this.network?.kind;
|
|
754
770
|
}
|
|
755
771
|
}
|
|
772
|
+
|
|
773
|
+
const LoopbackNetworkInterfaceTypeDefinition = {
|
|
774
|
+
name: "loopback",
|
|
775
|
+
specializationOf: NetworkInterfaceTypeDefinition,
|
|
776
|
+
owners: NetworkInterfaceTypeDefinition.owners,
|
|
777
|
+
extends: NetworkInterfaceTypeDefinition,
|
|
778
|
+
priority: 0.1,
|
|
779
|
+
properties: {}
|
|
780
|
+
};
|
|
781
|
+
|
|
782
|
+
const _localAddresses = new Map([
|
|
783
|
+
["127.0.0.1", { prefix: "127.0.0", prefixLength: 8 }], // TODO
|
|
784
|
+
["::1", { prefix: "", prefixLength: 128 }]
|
|
785
|
+
]);
|
|
786
|
+
|
|
787
|
+
export class LoopbackNetworkInterface extends SkeletonNetworkInterface {
|
|
788
|
+
static {
|
|
789
|
+
addType(this);
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
static get typeDefinition() {
|
|
793
|
+
return LoopbackNetworkInterfaceTypeDefinition;
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
get kind() {
|
|
797
|
+
return "loopback";
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
get scope() {
|
|
801
|
+
return "host";
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
get hostName() {
|
|
805
|
+
return "localhost";
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
get ipAddresses() {
|
|
809
|
+
return _localAddresses;
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
get cidrAddresses() {
|
|
813
|
+
return ["127.0.0.1/8", "::1/128"];
|
|
814
|
+
}
|
|
815
|
+
}
|
package/src/owner.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { normalizeCIDR } from "ip-utilties";
|
|
1
2
|
import { asIterator } from "./utils.mjs";
|
|
2
3
|
import { Base } from "./base.mjs";
|
|
3
4
|
import { Subnet } from "./subnet.mjs";
|
|
4
5
|
import { addType, types } from "./types.mjs";
|
|
5
|
-
import { normalizeCIDR } from "./ip.mjs";
|
|
6
6
|
const OwnerTypeDefinition = {
|
|
7
7
|
name: "owner",
|
|
8
8
|
owners: ["location", "owner", "root"],
|
package/src/service.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { isLocalhost } from "ip-utilties";
|
|
1
2
|
import { Base } from "./base.mjs";
|
|
2
3
|
import { addType } from "./types.mjs";
|
|
3
4
|
import { objectFilter } from "./filter.mjs";
|
|
4
5
|
import { asArray } from "./utils.mjs";
|
|
5
6
|
import { networkAddressProperties } from "./network-support.mjs";
|
|
6
|
-
import { isLocalhost } from "./ip.mjs";
|
|
7
7
|
import {
|
|
8
8
|
DNSRecord,
|
|
9
9
|
dnsFullName,
|
|
@@ -22,6 +22,7 @@ const ServiceTypes = {
|
|
|
22
22
|
dnsRecord: { type: "HTTPS", parameters: { alpn: "h2" } }
|
|
23
23
|
},
|
|
24
24
|
http3: {
|
|
25
|
+
extends: ["https"],
|
|
25
26
|
type: "https",
|
|
26
27
|
endpoints: [{ protocol: "tcp", port: 443, tls: true }],
|
|
27
28
|
dnsRecord: {
|
|
@@ -48,6 +49,7 @@ const ServiceTypes = {
|
|
|
48
49
|
smb: { endpoints: [{ protocol: "tcp", port: 445, tls: false }] },
|
|
49
50
|
timemachine: {
|
|
50
51
|
type: "adisk",
|
|
52
|
+
extends: ["smb"],
|
|
51
53
|
endpoints: [{ protocol: "tcp", port: 445, tls: false }],
|
|
52
54
|
dnsRecord: {
|
|
53
55
|
type: "TXT",
|
package/src/services/dhcp.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { join } from "node:path";
|
|
2
2
|
import { FileContentProvider } from "npm-pkgbuild";
|
|
3
|
+
import { isIPv4, isIPv6 } from "ip-utilties";
|
|
3
4
|
import {
|
|
4
5
|
Service,
|
|
5
6
|
ServiceTypeDefinition,
|
|
@@ -8,7 +9,6 @@ import {
|
|
|
8
9
|
} from "../service.mjs";
|
|
9
10
|
import { addType } from "../types.mjs";
|
|
10
11
|
import { writeLines } from "../utils.mjs";
|
|
11
|
-
import { isIPv4, isIPv6 } from "../ip.mjs";
|
|
12
12
|
|
|
13
13
|
const DHCPServiceTypeDefinition = {
|
|
14
14
|
name: "dhcp",
|
|
@@ -20,6 +20,7 @@ const DHCPServiceTypeDefinition = {
|
|
|
20
20
|
};
|
|
21
21
|
|
|
22
22
|
const controlAgentEndpoint = {
|
|
23
|
+
// extends: ["http"],
|
|
23
24
|
type: "kea-control-agent",
|
|
24
25
|
port: 8000,
|
|
25
26
|
protocol: "tcp",
|
package/src/services/dns.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { join } from "node:path";
|
|
2
2
|
import { createHmac } from "node:crypto";
|
|
3
3
|
import { FileContentProvider } from "npm-pkgbuild";
|
|
4
|
+
import { isIPv6, isLinkLocal, isLocalhost, reverseArpa } from "ip-utilties";
|
|
4
5
|
import { writeLines } from "../utils.mjs";
|
|
5
|
-
import { isIPv6, isLinkLocal, isLocalhost, reverseArpa } from "../ip.mjs";
|
|
6
6
|
import { DNSRecord, dnsFullName } from "../dns-utils.mjs";
|
|
7
7
|
import { addType } from "../types.mjs";
|
|
8
8
|
import { ServiceTypeDefinition, serviceAddresses } from "../service.mjs";
|
|
@@ -41,6 +41,12 @@ const DNSServiceTypeDefinition = {
|
|
|
41
41
|
writeable: true,
|
|
42
42
|
default: false
|
|
43
43
|
},
|
|
44
|
+
excludeInterfaceKinds: {
|
|
45
|
+
type: "string",
|
|
46
|
+
collection: true,
|
|
47
|
+
writeable: true
|
|
48
|
+
},
|
|
49
|
+
|
|
44
50
|
exclude: { type: "network", collection: true, writeable: true },
|
|
45
51
|
notify: {
|
|
46
52
|
type: "boolean",
|
|
@@ -87,6 +93,7 @@ export class DNSService extends ExtraSourceService {
|
|
|
87
93
|
_protected = [];
|
|
88
94
|
_open = [];
|
|
89
95
|
_exclude = new Set([]);
|
|
96
|
+
_excludeInterfaceKinds = new Set();
|
|
90
97
|
|
|
91
98
|
serial = Math.ceil(Date.now() / 1000);
|
|
92
99
|
refresh = 36000;
|
|
@@ -147,6 +154,14 @@ export class DNSService extends ExtraSourceService {
|
|
|
147
154
|
return this._exclude;
|
|
148
155
|
}
|
|
149
156
|
|
|
157
|
+
set excludeInterfaceKinds(value) {
|
|
158
|
+
this._excludeInterfaceKinds.add(value);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
get excludeInterfaceKinds() {
|
|
162
|
+
return this._excludeInterfaceKinds;
|
|
163
|
+
}
|
|
164
|
+
|
|
150
165
|
get systemdConfig() {
|
|
151
166
|
return [
|
|
152
167
|
"Resolve",
|
|
@@ -351,7 +366,7 @@ async function generateZoneDefs(dns, location, packageData) {
|
|
|
351
366
|
networkInterface,
|
|
352
367
|
domainNames
|
|
353
368
|
} of location.networkAddresses()) {
|
|
354
|
-
if (!dns.exclude.has(networkInterface.network)) {
|
|
369
|
+
if (!dns.exclude.has(networkInterface.network) && !dns.excludeInterfaceKinds.has(networkInterface.kind)) {
|
|
355
370
|
const host = networkInterface.host;
|
|
356
371
|
if (
|
|
357
372
|
!addresses.has(address) &&
|
package/src/subnet.mjs
CHANGED
package/types/host.d.mts
CHANGED
|
@@ -259,7 +259,7 @@ export class Host extends Base {
|
|
|
259
259
|
};
|
|
260
260
|
}, void, unknown>;
|
|
261
261
|
}
|
|
262
|
-
export class NetworkInterface extends
|
|
262
|
+
export class NetworkInterface extends SkeletonNetworkInterface {
|
|
263
263
|
static get typeDefinition(): {
|
|
264
264
|
name: string;
|
|
265
265
|
priority: number;
|
|
@@ -311,6 +311,8 @@ export class NetworkInterface extends Base {
|
|
|
311
311
|
};
|
|
312
312
|
};
|
|
313
313
|
};
|
|
314
|
+
specializations: {};
|
|
315
|
+
factoryFor(value: any): any;
|
|
314
316
|
properties: {
|
|
315
317
|
hostName: {
|
|
316
318
|
type: string;
|
|
@@ -421,22 +423,15 @@ export class NetworkInterface extends Base {
|
|
|
421
423
|
_metric: any;
|
|
422
424
|
_ssid: any;
|
|
423
425
|
_psk: any;
|
|
424
|
-
_network: any;
|
|
425
426
|
_kind: any;
|
|
426
427
|
_hostName: any;
|
|
427
428
|
_hwaddr: any;
|
|
428
429
|
_class: any;
|
|
429
|
-
_extends: any[];
|
|
430
430
|
arpbridge: any;
|
|
431
|
-
matches(other: any): boolean;
|
|
432
431
|
addSubnet(address: any): any;
|
|
433
432
|
set ipAddresses(value: Map<any, any>);
|
|
434
433
|
get ipAddresses(): Map<any, any>;
|
|
435
|
-
get rawAddress(): any;
|
|
436
|
-
get rawIPv4Address(): any;
|
|
437
|
-
get rawIPv6Address(): any;
|
|
438
434
|
get rawAddresses(): any[];
|
|
439
|
-
get cidrAddress(): any;
|
|
440
435
|
get cidrAddresses(): any[];
|
|
441
436
|
get rawIPv4Addresses(): any[];
|
|
442
437
|
get rawIPv6Addresses(): any[];
|
|
@@ -446,11 +441,6 @@ export class NetworkInterface extends Base {
|
|
|
446
441
|
set hostName(value: any);
|
|
447
442
|
get hostName(): any;
|
|
448
443
|
get domainNames(): any;
|
|
449
|
-
get network_interface(): this;
|
|
450
|
-
set extends(value: any[]);
|
|
451
|
-
get extends(): any[];
|
|
452
|
-
set network(network: any);
|
|
453
|
-
get network(): any;
|
|
454
444
|
set scope(value: any);
|
|
455
445
|
get scope(): any;
|
|
456
446
|
set hwaddr(value: any);
|
|
@@ -469,5 +459,353 @@ export class NetworkInterface extends Base {
|
|
|
469
459
|
set kind(value: any);
|
|
470
460
|
get kind(): any;
|
|
471
461
|
}
|
|
462
|
+
export class LoopbackNetworkInterface extends SkeletonNetworkInterface {
|
|
463
|
+
static get typeDefinition(): {
|
|
464
|
+
name: string;
|
|
465
|
+
specializationOf: {
|
|
466
|
+
name: string;
|
|
467
|
+
priority: number;
|
|
468
|
+
owners: string[];
|
|
469
|
+
extends: {
|
|
470
|
+
name: string;
|
|
471
|
+
owners: any[];
|
|
472
|
+
properties: {
|
|
473
|
+
owner: {
|
|
474
|
+
type: string;
|
|
475
|
+
collection: boolean;
|
|
476
|
+
writeable: boolean;
|
|
477
|
+
};
|
|
478
|
+
type: {
|
|
479
|
+
type: string;
|
|
480
|
+
collection: boolean;
|
|
481
|
+
writeable: boolean;
|
|
482
|
+
};
|
|
483
|
+
name: {
|
|
484
|
+
type: string;
|
|
485
|
+
collection: boolean;
|
|
486
|
+
identifier: boolean;
|
|
487
|
+
writeable: boolean;
|
|
488
|
+
};
|
|
489
|
+
description: {
|
|
490
|
+
type: string;
|
|
491
|
+
collection: boolean;
|
|
492
|
+
writeable: boolean;
|
|
493
|
+
};
|
|
494
|
+
priority: {
|
|
495
|
+
type: string;
|
|
496
|
+
collection: boolean;
|
|
497
|
+
writeable: boolean;
|
|
498
|
+
};
|
|
499
|
+
directory: {
|
|
500
|
+
type: string;
|
|
501
|
+
collection: boolean;
|
|
502
|
+
writeable: boolean;
|
|
503
|
+
};
|
|
504
|
+
packaging: {
|
|
505
|
+
type: string;
|
|
506
|
+
collection: boolean;
|
|
507
|
+
writeable: boolean;
|
|
508
|
+
};
|
|
509
|
+
tags: {
|
|
510
|
+
type: string;
|
|
511
|
+
collection: boolean;
|
|
512
|
+
writeable: boolean;
|
|
513
|
+
};
|
|
514
|
+
};
|
|
515
|
+
};
|
|
516
|
+
specializations: {};
|
|
517
|
+
factoryFor(value: any): any;
|
|
518
|
+
properties: {
|
|
519
|
+
hostName: {
|
|
520
|
+
type: string;
|
|
521
|
+
collection: boolean;
|
|
522
|
+
writeable: boolean;
|
|
523
|
+
};
|
|
524
|
+
ipAddresses: {
|
|
525
|
+
type: string;
|
|
526
|
+
collection: boolean;
|
|
527
|
+
writeable: boolean;
|
|
528
|
+
};
|
|
529
|
+
hwaddr: {
|
|
530
|
+
type: string;
|
|
531
|
+
collection: boolean;
|
|
532
|
+
writeable: boolean;
|
|
533
|
+
};
|
|
534
|
+
network: {
|
|
535
|
+
type: string;
|
|
536
|
+
collection: boolean;
|
|
537
|
+
writeable: boolean;
|
|
538
|
+
};
|
|
539
|
+
destination: {
|
|
540
|
+
type: string;
|
|
541
|
+
collection: boolean;
|
|
542
|
+
writeable: boolean;
|
|
543
|
+
};
|
|
544
|
+
arpbridge: {
|
|
545
|
+
type: string;
|
|
546
|
+
collection: boolean;
|
|
547
|
+
writeable: boolean;
|
|
548
|
+
};
|
|
549
|
+
cidrAddresses: {
|
|
550
|
+
type: string;
|
|
551
|
+
collection: boolean;
|
|
552
|
+
writeable: boolean;
|
|
553
|
+
};
|
|
554
|
+
cidrAddress: {
|
|
555
|
+
type: string;
|
|
556
|
+
collection: boolean;
|
|
557
|
+
writeable: boolean;
|
|
558
|
+
};
|
|
559
|
+
rawAddresses: {
|
|
560
|
+
type: string;
|
|
561
|
+
collection: boolean;
|
|
562
|
+
writeable: boolean;
|
|
563
|
+
};
|
|
564
|
+
rawAddress: {
|
|
565
|
+
type: string;
|
|
566
|
+
collection: boolean;
|
|
567
|
+
writeable: boolean;
|
|
568
|
+
};
|
|
569
|
+
scope: {
|
|
570
|
+
type: string;
|
|
571
|
+
collection: boolean;
|
|
572
|
+
writeable: boolean;
|
|
573
|
+
values: string[];
|
|
574
|
+
default: string;
|
|
575
|
+
};
|
|
576
|
+
class: {
|
|
577
|
+
type: string;
|
|
578
|
+
collection: boolean;
|
|
579
|
+
writeable: boolean;
|
|
580
|
+
values: string[];
|
|
581
|
+
};
|
|
582
|
+
kind: {
|
|
583
|
+
type: string;
|
|
584
|
+
collection: boolean;
|
|
585
|
+
writeable: boolean;
|
|
586
|
+
values: string[];
|
|
587
|
+
};
|
|
588
|
+
ssid: {
|
|
589
|
+
type: string;
|
|
590
|
+
collection: boolean;
|
|
591
|
+
writeable: boolean;
|
|
592
|
+
};
|
|
593
|
+
psk: {
|
|
594
|
+
type: string;
|
|
595
|
+
collection: boolean;
|
|
596
|
+
writeable: boolean;
|
|
597
|
+
};
|
|
598
|
+
metric: {
|
|
599
|
+
type: string;
|
|
600
|
+
collection: boolean;
|
|
601
|
+
writeable: boolean;
|
|
602
|
+
default: number;
|
|
603
|
+
};
|
|
604
|
+
MTU: {
|
|
605
|
+
type: string;
|
|
606
|
+
collection: boolean;
|
|
607
|
+
writeable: boolean;
|
|
608
|
+
default: number;
|
|
609
|
+
};
|
|
610
|
+
gateway: {
|
|
611
|
+
type: string;
|
|
612
|
+
collection: boolean;
|
|
613
|
+
writeable: boolean;
|
|
614
|
+
};
|
|
615
|
+
multicastDNS: {
|
|
616
|
+
type: string;
|
|
617
|
+
collection: boolean;
|
|
618
|
+
writeable: boolean;
|
|
619
|
+
default: boolean;
|
|
620
|
+
};
|
|
621
|
+
};
|
|
622
|
+
};
|
|
623
|
+
owners: string[];
|
|
624
|
+
extends: {
|
|
625
|
+
name: string;
|
|
626
|
+
priority: number;
|
|
627
|
+
owners: string[];
|
|
628
|
+
extends: {
|
|
629
|
+
name: string;
|
|
630
|
+
owners: any[];
|
|
631
|
+
properties: {
|
|
632
|
+
owner: {
|
|
633
|
+
type: string;
|
|
634
|
+
collection: boolean;
|
|
635
|
+
writeable: boolean;
|
|
636
|
+
};
|
|
637
|
+
type: {
|
|
638
|
+
type: string;
|
|
639
|
+
collection: boolean;
|
|
640
|
+
writeable: boolean;
|
|
641
|
+
};
|
|
642
|
+
name: {
|
|
643
|
+
type: string;
|
|
644
|
+
collection: boolean;
|
|
645
|
+
identifier: boolean;
|
|
646
|
+
writeable: boolean;
|
|
647
|
+
};
|
|
648
|
+
description: {
|
|
649
|
+
type: string;
|
|
650
|
+
collection: boolean;
|
|
651
|
+
writeable: boolean;
|
|
652
|
+
};
|
|
653
|
+
priority: {
|
|
654
|
+
type: string;
|
|
655
|
+
collection: boolean;
|
|
656
|
+
writeable: boolean;
|
|
657
|
+
};
|
|
658
|
+
directory: {
|
|
659
|
+
type: string;
|
|
660
|
+
collection: boolean;
|
|
661
|
+
writeable: boolean;
|
|
662
|
+
};
|
|
663
|
+
packaging: {
|
|
664
|
+
type: string;
|
|
665
|
+
collection: boolean;
|
|
666
|
+
writeable: boolean;
|
|
667
|
+
};
|
|
668
|
+
tags: {
|
|
669
|
+
type: string;
|
|
670
|
+
collection: boolean;
|
|
671
|
+
writeable: boolean;
|
|
672
|
+
};
|
|
673
|
+
};
|
|
674
|
+
};
|
|
675
|
+
specializations: {};
|
|
676
|
+
factoryFor(value: any): any;
|
|
677
|
+
properties: {
|
|
678
|
+
hostName: {
|
|
679
|
+
type: string;
|
|
680
|
+
collection: boolean;
|
|
681
|
+
writeable: boolean;
|
|
682
|
+
};
|
|
683
|
+
ipAddresses: {
|
|
684
|
+
type: string;
|
|
685
|
+
collection: boolean;
|
|
686
|
+
writeable: boolean;
|
|
687
|
+
};
|
|
688
|
+
hwaddr: {
|
|
689
|
+
type: string;
|
|
690
|
+
collection: boolean;
|
|
691
|
+
writeable: boolean;
|
|
692
|
+
};
|
|
693
|
+
network: {
|
|
694
|
+
type: string;
|
|
695
|
+
collection: boolean;
|
|
696
|
+
writeable: boolean;
|
|
697
|
+
};
|
|
698
|
+
destination: {
|
|
699
|
+
type: string;
|
|
700
|
+
collection: boolean;
|
|
701
|
+
writeable: boolean;
|
|
702
|
+
};
|
|
703
|
+
arpbridge: {
|
|
704
|
+
type: string;
|
|
705
|
+
collection: boolean;
|
|
706
|
+
writeable: boolean;
|
|
707
|
+
};
|
|
708
|
+
cidrAddresses: {
|
|
709
|
+
type: string;
|
|
710
|
+
collection: boolean;
|
|
711
|
+
writeable: boolean;
|
|
712
|
+
};
|
|
713
|
+
cidrAddress: {
|
|
714
|
+
type: string;
|
|
715
|
+
collection: boolean;
|
|
716
|
+
writeable: boolean;
|
|
717
|
+
};
|
|
718
|
+
rawAddresses: {
|
|
719
|
+
type: string;
|
|
720
|
+
collection: boolean;
|
|
721
|
+
writeable: boolean;
|
|
722
|
+
};
|
|
723
|
+
rawAddress: {
|
|
724
|
+
type: string;
|
|
725
|
+
collection: boolean;
|
|
726
|
+
writeable: boolean;
|
|
727
|
+
};
|
|
728
|
+
scope: {
|
|
729
|
+
type: string;
|
|
730
|
+
collection: boolean;
|
|
731
|
+
writeable: boolean;
|
|
732
|
+
values: string[];
|
|
733
|
+
default: string;
|
|
734
|
+
};
|
|
735
|
+
class: {
|
|
736
|
+
type: string;
|
|
737
|
+
collection: boolean;
|
|
738
|
+
writeable: boolean;
|
|
739
|
+
values: string[];
|
|
740
|
+
};
|
|
741
|
+
kind: {
|
|
742
|
+
type: string;
|
|
743
|
+
collection: boolean;
|
|
744
|
+
writeable: boolean;
|
|
745
|
+
values: string[];
|
|
746
|
+
};
|
|
747
|
+
ssid: {
|
|
748
|
+
type: string;
|
|
749
|
+
collection: boolean;
|
|
750
|
+
writeable: boolean;
|
|
751
|
+
};
|
|
752
|
+
psk: {
|
|
753
|
+
type: string;
|
|
754
|
+
collection: boolean;
|
|
755
|
+
writeable: boolean;
|
|
756
|
+
};
|
|
757
|
+
metric: {
|
|
758
|
+
type: string;
|
|
759
|
+
collection: boolean;
|
|
760
|
+
writeable: boolean;
|
|
761
|
+
default: number;
|
|
762
|
+
};
|
|
763
|
+
MTU: {
|
|
764
|
+
type: string;
|
|
765
|
+
collection: boolean;
|
|
766
|
+
writeable: boolean;
|
|
767
|
+
default: number;
|
|
768
|
+
};
|
|
769
|
+
gateway: {
|
|
770
|
+
type: string;
|
|
771
|
+
collection: boolean;
|
|
772
|
+
writeable: boolean;
|
|
773
|
+
};
|
|
774
|
+
multicastDNS: {
|
|
775
|
+
type: string;
|
|
776
|
+
collection: boolean;
|
|
777
|
+
writeable: boolean;
|
|
778
|
+
default: boolean;
|
|
779
|
+
};
|
|
780
|
+
};
|
|
781
|
+
};
|
|
782
|
+
priority: number;
|
|
783
|
+
properties: {};
|
|
784
|
+
};
|
|
785
|
+
get kind(): string;
|
|
786
|
+
get scope(): string;
|
|
787
|
+
get hostName(): string;
|
|
788
|
+
get ipAddresses(): Map<string, {
|
|
789
|
+
prefix: string;
|
|
790
|
+
prefixLength: number;
|
|
791
|
+
}>;
|
|
792
|
+
get cidrAddresses(): string[];
|
|
793
|
+
}
|
|
472
794
|
import { Base } from "./base.mjs";
|
|
473
795
|
import { FileContentProvider } from "npm-pkgbuild";
|
|
796
|
+
declare class SkeletonNetworkInterface extends Base {
|
|
797
|
+
_extends: any[];
|
|
798
|
+
_network: any;
|
|
799
|
+
set extends(value: any[]);
|
|
800
|
+
get extends(): any[];
|
|
801
|
+
get network_interface(): this;
|
|
802
|
+
get domainNames(): Set<any>;
|
|
803
|
+
matches(other: any): boolean;
|
|
804
|
+
set network(network: any);
|
|
805
|
+
get network(): any;
|
|
806
|
+
get rawAddress(): any;
|
|
807
|
+
get rawIPv4Address(): any;
|
|
808
|
+
get rawIPv6Address(): any;
|
|
809
|
+
get cidrAddress(): any;
|
|
810
|
+
}
|
|
811
|
+
export {};
|
package/types/services/dns.d.mts
CHANGED
|
@@ -297,6 +297,11 @@ export class DNSService extends ExtraSourceService {
|
|
|
297
297
|
writeable: boolean;
|
|
298
298
|
default: boolean;
|
|
299
299
|
};
|
|
300
|
+
excludeInterfaceKinds: {
|
|
301
|
+
type: string;
|
|
302
|
+
collection: boolean;
|
|
303
|
+
writeable: boolean;
|
|
304
|
+
};
|
|
300
305
|
exclude: {
|
|
301
306
|
type: string;
|
|
302
307
|
collection: boolean;
|
|
@@ -355,6 +360,7 @@ export class DNSService extends ExtraSourceService {
|
|
|
355
360
|
_protected: any[];
|
|
356
361
|
_open: any[];
|
|
357
362
|
_exclude: Set<any>;
|
|
363
|
+
_excludeInterfaceKinds: Set<any>;
|
|
358
364
|
serial: number;
|
|
359
365
|
refresh: number;
|
|
360
366
|
retry: number;
|
|
@@ -369,6 +375,8 @@ export class DNSService extends ExtraSourceService {
|
|
|
369
375
|
get open(): any[];
|
|
370
376
|
set exclude(value: Set<any>);
|
|
371
377
|
get exclude(): Set<any>;
|
|
378
|
+
set excludeInterfaceKinds(value: Set<any>);
|
|
379
|
+
get excludeInterfaceKinds(): Set<any>;
|
|
372
380
|
get systemdConfig(): (string | {
|
|
373
381
|
DNS: string;
|
|
374
382
|
FallbackDNS: string;
|
package/types/subnet.d.mts
CHANGED
|
@@ -30,10 +30,10 @@ export class Subnet extends Base {
|
|
|
30
30
|
longPrefix: any;
|
|
31
31
|
get fullName(): string;
|
|
32
32
|
matchesAddress(address: any): any;
|
|
33
|
-
get isLinkLocal():
|
|
34
|
-
get isIPv4():
|
|
35
|
-
get isIPv6():
|
|
36
|
-
get addressRange():
|
|
33
|
+
get isLinkLocal(): any;
|
|
34
|
+
get isIPv4(): any;
|
|
35
|
+
get isIPv6(): any;
|
|
36
|
+
get addressRange(): any;
|
|
37
37
|
get address(): string;
|
|
38
38
|
get longAddress(): string;
|
|
39
39
|
_traverse(...args: any[]): boolean;
|
package/src/ip.mjs
DELETED
|
@@ -1,323 +0,0 @@
|
|
|
1
|
-
const ipv4 = {
|
|
2
|
-
factory: Uint8Array,
|
|
3
|
-
normalize(address) {
|
|
4
|
-
return address;
|
|
5
|
-
},
|
|
6
|
-
separator: ".",
|
|
7
|
-
bitLength: 32,
|
|
8
|
-
byteLength: 4,
|
|
9
|
-
segments: 4,
|
|
10
|
-
segmentLength: 8,
|
|
11
|
-
segmentMask: 0xffn,
|
|
12
|
-
mask: 0xffffffffn,
|
|
13
|
-
base: 10
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const ipv6 = {
|
|
17
|
-
factory: Uint16Array,
|
|
18
|
-
normalize(address) {
|
|
19
|
-
const parts = address.split(":");
|
|
20
|
-
const i = parts.indexOf("");
|
|
21
|
-
if (i >= 0) {
|
|
22
|
-
parts.splice(i, 1, ..."0".repeat(9 - parts.length));
|
|
23
|
-
}
|
|
24
|
-
return parts.join(":");
|
|
25
|
-
},
|
|
26
|
-
separator: ":",
|
|
27
|
-
compressor: "::",
|
|
28
|
-
bitLength: 128,
|
|
29
|
-
byteLength: 8,
|
|
30
|
-
segments: 8,
|
|
31
|
-
segmentLength: 16,
|
|
32
|
-
segmentMask: 0xffffn,
|
|
33
|
-
mask: 0xffffffffffffffffffffffffffffffffn,
|
|
34
|
-
base: 16
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export function IPV4(...args) {
|
|
38
|
-
return _create(ipv4, ...args);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function IPV6(...args) {
|
|
42
|
-
return _create(ipv6, ...args);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function _create(definition, ...args) {
|
|
46
|
-
if (args.length === 1) {
|
|
47
|
-
return _encode(definition, args[0]);
|
|
48
|
-
}
|
|
49
|
-
return new definition.factory(args);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export function encodeIP(address) {
|
|
53
|
-
const d = _definition(address);
|
|
54
|
-
return d && _encode(d, address);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export function encodeIPv6(address) {
|
|
58
|
-
return _encode(ipv6, address);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export function encodeIPv4(address) {
|
|
62
|
-
return _encode(ipv4, address);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export function _encode(definition, address) {
|
|
66
|
-
switch (typeof address) {
|
|
67
|
-
case "string":
|
|
68
|
-
const res = new definition.factory(definition.segments);
|
|
69
|
-
|
|
70
|
-
let i = 0;
|
|
71
|
-
for (const segment of definition
|
|
72
|
-
.normalize(address)
|
|
73
|
-
.split(definition.separator)) {
|
|
74
|
-
res[i++] = parseInt(segment, definition.base);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return res;
|
|
78
|
-
|
|
79
|
-
case "bigint":
|
|
80
|
-
return _encodeBigInt(definition, address);
|
|
81
|
-
|
|
82
|
-
case "object":
|
|
83
|
-
if (
|
|
84
|
-
address instanceof definition.factory &&
|
|
85
|
-
address.length === definition.byteLength
|
|
86
|
-
) {
|
|
87
|
-
return address;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function _decode(definition, address, length) {
|
|
93
|
-
switch (typeof address) {
|
|
94
|
-
case "string":
|
|
95
|
-
if (length === undefined) {
|
|
96
|
-
return address;
|
|
97
|
-
}
|
|
98
|
-
address = _encode(definition, address);
|
|
99
|
-
break;
|
|
100
|
-
case "bigint":
|
|
101
|
-
address = _encodeBigInt(definition, address);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
let result = "";
|
|
105
|
-
let compressed = 0;
|
|
106
|
-
let word;
|
|
107
|
-
let last = address?.length;
|
|
108
|
-
|
|
109
|
-
if (length !== undefined) {
|
|
110
|
-
length /= definition.segmentLength;
|
|
111
|
-
|
|
112
|
-
if (length < last) {
|
|
113
|
-
last = length;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
for (let i = 0, j = 0; i < last; j = j + 1, i = j) {
|
|
117
|
-
for (; j < last; j++) {
|
|
118
|
-
word = address[j];
|
|
119
|
-
|
|
120
|
-
if (word !== 0 || !definition.compressor || compressed > 0) {
|
|
121
|
-
break;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
if (j > i + 1) {
|
|
126
|
-
compressed++;
|
|
127
|
-
result += definition.compressor;
|
|
128
|
-
} else {
|
|
129
|
-
if (result.length > 0) {
|
|
130
|
-
result += definition.separator;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
if (j < last) {
|
|
135
|
-
result += word.toString(definition.base);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
return result;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
export function decodeIPv6(address, length) {
|
|
143
|
-
return _decode(ipv6, address, length);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
export function decodeIPv4(address, length) {
|
|
147
|
-
return _decode(ipv4, address, length);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
export function decodeIP(address, length) {
|
|
151
|
-
return _decode(isIPv4(address) ? ipv4 : ipv6, address, length);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
export function isIPv4(address) {
|
|
155
|
-
return _is(ipv4, address);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
export function isIPv6(address) {
|
|
159
|
-
return _is(ipv6, address);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
function _definition(address) {
|
|
163
|
-
for (const defintion of [ipv4, ipv6]) {
|
|
164
|
-
if (_is(defintion, address)) {
|
|
165
|
-
return defintion;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
export function _is(definition, address) {
|
|
171
|
-
switch (typeof address) {
|
|
172
|
-
case "string":
|
|
173
|
-
return address.indexOf(definition.separator) >= 0;
|
|
174
|
-
|
|
175
|
-
case "object":
|
|
176
|
-
return (
|
|
177
|
-
address instanceof definition.factory &&
|
|
178
|
-
address.length === definition.byteLength
|
|
179
|
-
);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
return false;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
export function asBigInt(address) {
|
|
186
|
-
return _asBigInt(isIPv4(address) ? ipv4 : ipv6, address);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
function _asBigInt(definition, address) {
|
|
190
|
-
if (typeof address === "bigint") {
|
|
191
|
-
return address;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
const ea = _encode(definition, address);
|
|
195
|
-
|
|
196
|
-
let result = 0n;
|
|
197
|
-
|
|
198
|
-
for (let i = 0; i < ea.length; i++) {
|
|
199
|
-
result = result << BigInt(definition.segmentLength);
|
|
200
|
-
result += BigInt(ea[i]);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
return result;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
function _encodeBigInt(definition, address) {
|
|
207
|
-
const segments = [];
|
|
208
|
-
|
|
209
|
-
for (let i = 0; i < definition.segments; i++) {
|
|
210
|
-
segments.push(Number(address & definition.segmentMask));
|
|
211
|
-
address >>= BigInt(definition.segmentLength);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
return new definition.factory(segments.reverse());
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
export function prefixIP(address, length) {
|
|
218
|
-
const definition = isIPv4(address) ? ipv4 : ipv6;
|
|
219
|
-
return _decode(definition, _prefix(definition, address, length));
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
export function _prefix(definition, address, length) {
|
|
223
|
-
return (
|
|
224
|
-
_asBigInt(definition, address) &
|
|
225
|
-
(definition.mask << BigInt(definition.bitLength - length))
|
|
226
|
-
);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
export function rangeIP(address, prefix, lowerAdd = 0, upperReduce = 0) {
|
|
230
|
-
const definition = isIPv4(address) ? ipv4 : ipv6;
|
|
231
|
-
|
|
232
|
-
const from = _prefix(definition, address, prefix);
|
|
233
|
-
const to = from | ((1n << BigInt(definition.bitLength - prefix)) - 1n);
|
|
234
|
-
|
|
235
|
-
return [_encode(definition, from + BigInt(lowerAdd)), _encode(definition, to - BigInt(upperReduce))];
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
export function normalizeCIDR(address) {
|
|
239
|
-
let [prefix, prefixLength] = address.split(/\//);
|
|
240
|
-
let longPrefix;
|
|
241
|
-
|
|
242
|
-
if (!prefixLength && isLinkLocal(address)) {
|
|
243
|
-
prefix = "fe80::";
|
|
244
|
-
longPrefix = prefix;
|
|
245
|
-
prefixLength = 64;
|
|
246
|
-
} else {
|
|
247
|
-
prefixLength = parseInt(prefixLength);
|
|
248
|
-
|
|
249
|
-
const definition = isIPv6(prefix) ? ipv6 : ipv4;
|
|
250
|
-
let n;
|
|
251
|
-
|
|
252
|
-
if (prefixLength) {
|
|
253
|
-
n = _prefix(definition, prefix, prefixLength);
|
|
254
|
-
} else {
|
|
255
|
-
n = _encode(definition, prefix);
|
|
256
|
-
|
|
257
|
-
if (isLocalhost(n)) {
|
|
258
|
-
prefixLength = definition === ipv6 ? 128 : 8;
|
|
259
|
-
} else {
|
|
260
|
-
return {};
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
prefix = _decode(definition, n, prefixLength);
|
|
264
|
-
longPrefix = _decode(definition, n);
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
return {
|
|
268
|
-
longPrefix,
|
|
269
|
-
prefix,
|
|
270
|
-
prefixLength,
|
|
271
|
-
cidr: `${prefix}/${prefixLength}`
|
|
272
|
-
};
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
export function formatCIDR(address, subnet) {
|
|
276
|
-
return subnet ? `${address}/${subnet.prefixLength}` : address;
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
export function normalizeIP(address) {
|
|
280
|
-
return decodeIP(encodeIP(address));
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
export function reverseArpa(address) {
|
|
284
|
-
if (isIPv6(address)) {
|
|
285
|
-
const ea = encodeIPv6(address);
|
|
286
|
-
let result = [];
|
|
287
|
-
for (let i = 0; i < ea.length; i++) {
|
|
288
|
-
const v = ea[i];
|
|
289
|
-
for (let i = 0; i < 4; i++) {
|
|
290
|
-
result.push(((v >> (12 - 4 * i)) & 0x000f).toString(16));
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
return result.reverse().join(".") + ".ip6.arpa";
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
return address.split(".").reverse().join(".") + ".in-addr.arpa";
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
export function isLocalhost(address) {
|
|
300
|
-
const eaddr = encodeIP(address);
|
|
301
|
-
|
|
302
|
-
if (!eaddr) {
|
|
303
|
-
return false;
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
const str = eaddr.toString();
|
|
307
|
-
|
|
308
|
-
return str === IPV4_LOCALHOST.toString() || str === IPV6_LOCALHOST.toString();
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
export function isLinkLocal(address) {
|
|
312
|
-
const eaddr = encodeIP(address);
|
|
313
|
-
return eaddr?.[0] === 0xfe80;
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
export function hasWellKnownSubnet(address) {
|
|
317
|
-
return isLocalhost(address) || isLinkLocal(address);
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
export const IPV6_LINK_LOCAL_BROADCAST = _encode(ipv6, "ff02::1");
|
|
321
|
-
export const IPV6_ROUTER_BROADCAST = _encode(ipv6, "ff02::2");
|
|
322
|
-
export const IPV4_LOCALHOST = _encode(ipv4, "127.0.0.1");
|
|
323
|
-
export const IPV6_LOCALHOST = _encode(ipv6, "::1");
|
package/types/ip.d.mts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
export function IPV4(...args: any[]): any;
|
|
2
|
-
export function IPV6(...args: any[]): any;
|
|
3
|
-
export function encodeIP(address: any): any;
|
|
4
|
-
export function encodeIPv6(address: any): any;
|
|
5
|
-
export function encodeIPv4(address: any): any;
|
|
6
|
-
export function _encode(definition: any, address: any): any;
|
|
7
|
-
export function decodeIPv6(address: any, length: any): string;
|
|
8
|
-
export function decodeIPv4(address: any, length: any): string;
|
|
9
|
-
export function decodeIP(address: any, length: any): string;
|
|
10
|
-
export function isIPv4(address: any): boolean;
|
|
11
|
-
export function isIPv6(address: any): boolean;
|
|
12
|
-
export function _is(definition: any, address: any): boolean;
|
|
13
|
-
export function asBigInt(address: any): bigint;
|
|
14
|
-
export function prefixIP(address: any, length: any): string;
|
|
15
|
-
export function _prefix(definition: any, address: any, length: any): bigint;
|
|
16
|
-
export function rangeIP(address: any, prefix: any, lowerAdd?: number, upperReduce?: number): any[];
|
|
17
|
-
export function normalizeCIDR(address: any): {
|
|
18
|
-
longPrefix?: undefined;
|
|
19
|
-
prefix?: undefined;
|
|
20
|
-
prefixLength?: undefined;
|
|
21
|
-
cidr?: undefined;
|
|
22
|
-
} | {
|
|
23
|
-
longPrefix: any;
|
|
24
|
-
prefix: any;
|
|
25
|
-
prefixLength: any;
|
|
26
|
-
cidr: string;
|
|
27
|
-
};
|
|
28
|
-
export function formatCIDR(address: any, subnet: any): any;
|
|
29
|
-
export function normalizeIP(address: any): string;
|
|
30
|
-
export function reverseArpa(address: any): string;
|
|
31
|
-
export function isLocalhost(address: any): boolean;
|
|
32
|
-
export function isLinkLocal(address: any): boolean;
|
|
33
|
-
export function hasWellKnownSubnet(address: any): boolean;
|
|
34
|
-
export const IPV6_LINK_LOCAL_BROADCAST: any;
|
|
35
|
-
export const IPV6_ROUTER_BROADCAST: any;
|
|
36
|
-
export const IPV4_LOCALHOST: any;
|
|
37
|
-
export const IPV6_LOCALHOST: any;
|