pmcf 2.19.3 → 2.19.5
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 -2
- package/src/host.mjs +5 -322
- package/src/module.mjs +1 -0
- package/src/network-interface.mjs +323 -0
- package/types/host.d.mts +0 -548
- package/types/module.d.mts +1 -0
- package/types/network-interface.d.mts +709 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pmcf",
|
|
3
|
-
"version": "2.19.
|
|
3
|
+
"version": "2.19.5",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -38,7 +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
|
|
41
|
+
"ip-utilties": "^1.1.0",
|
|
42
42
|
"npm-pkgbuild": "^18.0.1",
|
|
43
43
|
"pacc": "^3.3.0",
|
|
44
44
|
"pkg-dir": "^8.0.0"
|
package/src/host.mjs
CHANGED
|
@@ -1,19 +1,10 @@
|
|
|
1
1
|
import { readFile } from "node:fs/promises";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { FileContentProvider } from "npm-pkgbuild";
|
|
4
|
-
import {
|
|
5
|
-
isIPv4,
|
|
6
|
-
isIPv6,
|
|
7
|
-
formatCIDR,
|
|
8
|
-
hasWellKnownSubnet,
|
|
9
|
-
normalizeIP
|
|
10
|
-
} from "ip-utilties";
|
|
4
|
+
import { formatCIDR } from "ip-utilties";
|
|
11
5
|
import { Base } from "./base.mjs";
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
networkAddressProperties
|
|
15
|
-
} from "./network-support.mjs";
|
|
16
|
-
import { asArray, domainFromDominName, domainName } from "./utils.mjs";
|
|
6
|
+
import { networkAddressProperties } from "./network-support.mjs";
|
|
7
|
+
import { domainFromDominName, domainName } from "./utils.mjs";
|
|
17
8
|
import { objectFilter } from "./filter.mjs";
|
|
18
9
|
import { addType, types } from "./types.mjs";
|
|
19
10
|
import { loadHooks } from "./hooks.mjs";
|
|
@@ -22,6 +13,7 @@ import {
|
|
|
22
13
|
generateMachineInfo,
|
|
23
14
|
generateKnownHosts
|
|
24
15
|
} from "./host-utils.mjs";
|
|
16
|
+
import { NetworkInterfaceTypeDefinition } from "./network-interface.mjs";
|
|
25
17
|
|
|
26
18
|
const HostTypeDefinition = {
|
|
27
19
|
name: "host",
|
|
@@ -456,7 +448,7 @@ export class Host extends Base {
|
|
|
456
448
|
|
|
457
449
|
get cidrAddresses() {
|
|
458
450
|
return [...this.networkAddresses()].map(({ address, subnet }) =>
|
|
459
|
-
formatCIDR(address, subnet)
|
|
451
|
+
formatCIDR(address, subnet.prefixLength)
|
|
460
452
|
);
|
|
461
453
|
}
|
|
462
454
|
|
|
@@ -504,312 +496,3 @@ export class Host extends Base {
|
|
|
504
496
|
yield packageData;
|
|
505
497
|
}
|
|
506
498
|
}
|
|
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
|
-
|
|
570
|
-
const NetworkInterfaceTypeDefinition = {
|
|
571
|
-
name: "network_interface",
|
|
572
|
-
priority: 0.4,
|
|
573
|
-
owners: ["host"],
|
|
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
|
-
},
|
|
587
|
-
properties: {
|
|
588
|
-
...networkProperties,
|
|
589
|
-
...networkAddressProperties,
|
|
590
|
-
hostName: { type: "string", collection: false, writeable: true },
|
|
591
|
-
ipAddresses: { type: "string", collection: true, writeable: true },
|
|
592
|
-
|
|
593
|
-
hwaddr: { type: "string", collection: false, writeable: true },
|
|
594
|
-
network: { type: "network", collection: false, writeable: true },
|
|
595
|
-
destination: { type: "string", collection: false, writeable: true },
|
|
596
|
-
arpbridge: { type: "network_interface", collection: true, writeable: true }
|
|
597
|
-
}
|
|
598
|
-
};
|
|
599
|
-
|
|
600
|
-
export class NetworkInterface extends SkeletonNetworkInterface {
|
|
601
|
-
static {
|
|
602
|
-
addType(this);
|
|
603
|
-
}
|
|
604
|
-
|
|
605
|
-
static get typeDefinition() {
|
|
606
|
-
return NetworkInterfaceTypeDefinition;
|
|
607
|
-
}
|
|
608
|
-
|
|
609
|
-
_ipAddresses = new Map();
|
|
610
|
-
_scope;
|
|
611
|
-
_metric;
|
|
612
|
-
_ssid;
|
|
613
|
-
_psk;
|
|
614
|
-
_kind;
|
|
615
|
-
_hostName;
|
|
616
|
-
_hwaddr;
|
|
617
|
-
_class;
|
|
618
|
-
arpbridge;
|
|
619
|
-
|
|
620
|
-
constructor(owner, data) {
|
|
621
|
-
super(owner, data);
|
|
622
|
-
this.read(data, NetworkInterfaceTypeDefinition);
|
|
623
|
-
}
|
|
624
|
-
|
|
625
|
-
addSubnet(address) {
|
|
626
|
-
if (!this.network) {
|
|
627
|
-
if (!hasWellKnownSubnet(address)) {
|
|
628
|
-
this.error("Missing network", address);
|
|
629
|
-
}
|
|
630
|
-
} else {
|
|
631
|
-
return this.network.addSubnet(address);
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
|
|
635
|
-
get ipAddresses() {
|
|
636
|
-
return this._ipAddresses;
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
set ipAddresses(value) {
|
|
640
|
-
for (const address of asArray(value)) {
|
|
641
|
-
this._ipAddresses.set(normalizeIP(address), this.addSubnet(address));
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
|
|
645
|
-
get rawAddresses() {
|
|
646
|
-
return [...this._ipAddresses].map(([address]) => address);
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
get cidrAddresses() {
|
|
650
|
-
return [...this._ipAddresses].map(([address, subnet]) =>
|
|
651
|
-
formatCIDR(address, subnet)
|
|
652
|
-
);
|
|
653
|
-
}
|
|
654
|
-
|
|
655
|
-
get rawIPv4Addresses() {
|
|
656
|
-
return [...this.ipAddresses]
|
|
657
|
-
.filter(([address]) => isIPv4(address))
|
|
658
|
-
.map(([address]) => address);
|
|
659
|
-
}
|
|
660
|
-
|
|
661
|
-
get rawIPv6Addresses() {
|
|
662
|
-
return [...this.ipAddresses]
|
|
663
|
-
.filter(([address]) => isIPv6(address))
|
|
664
|
-
.map(([address]) => address);
|
|
665
|
-
}
|
|
666
|
-
|
|
667
|
-
subnetForAddress(address) {
|
|
668
|
-
return (
|
|
669
|
-
this.network?.subnetForAddress(address) ||
|
|
670
|
-
this.host.owner.subnetForAddress(address)
|
|
671
|
-
);
|
|
672
|
-
}
|
|
673
|
-
|
|
674
|
-
get gateway() {
|
|
675
|
-
return this.network?.gateway;
|
|
676
|
-
}
|
|
677
|
-
|
|
678
|
-
get gatewayAddress() {
|
|
679
|
-
for (const a of this.gateway.networkAddresses()) {
|
|
680
|
-
if (a.networkInterface.network === this.network) {
|
|
681
|
-
return a.address;
|
|
682
|
-
}
|
|
683
|
-
}
|
|
684
|
-
}
|
|
685
|
-
|
|
686
|
-
get hostName() {
|
|
687
|
-
return this.extendedProperty("_hostName") ?? this.host.hostName;
|
|
688
|
-
}
|
|
689
|
-
|
|
690
|
-
set hostName(value) {
|
|
691
|
-
this._hostName = value;
|
|
692
|
-
}
|
|
693
|
-
|
|
694
|
-
get domainNames() {
|
|
695
|
-
return this.hostName
|
|
696
|
-
? new Set([[this.hostName, this.host.domain].join(".")])
|
|
697
|
-
: this.host.directDomainNames;
|
|
698
|
-
}
|
|
699
|
-
|
|
700
|
-
set scope(value) {
|
|
701
|
-
this._scope = value;
|
|
702
|
-
}
|
|
703
|
-
|
|
704
|
-
get scope() {
|
|
705
|
-
return (
|
|
706
|
-
this.extendedProperty("_scope") ??
|
|
707
|
-
this.network?.scope ??
|
|
708
|
-
networkProperties.scope.default
|
|
709
|
-
);
|
|
710
|
-
}
|
|
711
|
-
|
|
712
|
-
set hwaddr(value) {
|
|
713
|
-
this._hwaddr = value;
|
|
714
|
-
}
|
|
715
|
-
|
|
716
|
-
get hwaddr() {
|
|
717
|
-
return this.extendedProperty("_hwaddr");
|
|
718
|
-
}
|
|
719
|
-
|
|
720
|
-
set metric(value) {
|
|
721
|
-
this._metric = value;
|
|
722
|
-
}
|
|
723
|
-
|
|
724
|
-
get metric() {
|
|
725
|
-
return (
|
|
726
|
-
this.extendedProperty("_metric") ??
|
|
727
|
-
this.network?.metric ??
|
|
728
|
-
networkProperties.metric.default
|
|
729
|
-
);
|
|
730
|
-
}
|
|
731
|
-
|
|
732
|
-
set MTU(value) {
|
|
733
|
-
this._MTU = value;
|
|
734
|
-
}
|
|
735
|
-
|
|
736
|
-
get MTU() {
|
|
737
|
-
return this.extendedProperty("_MTU") ?? networkProperties.MTU.default;
|
|
738
|
-
}
|
|
739
|
-
|
|
740
|
-
set class(value) {
|
|
741
|
-
this._class = value;
|
|
742
|
-
}
|
|
743
|
-
|
|
744
|
-
get class() {
|
|
745
|
-
return this.extendedProperty("_class") ?? this.network?.class;
|
|
746
|
-
}
|
|
747
|
-
|
|
748
|
-
set ssid(value) {
|
|
749
|
-
this._ssid = value;
|
|
750
|
-
}
|
|
751
|
-
|
|
752
|
-
get ssid() {
|
|
753
|
-
return this.extendedProperty("_ssid") ?? this.network?.ssid;
|
|
754
|
-
}
|
|
755
|
-
|
|
756
|
-
set psk(value) {
|
|
757
|
-
this._psk = value;
|
|
758
|
-
}
|
|
759
|
-
|
|
760
|
-
get psk() {
|
|
761
|
-
return this.extendedProperty("_psk") ?? this.network?.psk;
|
|
762
|
-
}
|
|
763
|
-
|
|
764
|
-
set kind(value) {
|
|
765
|
-
this._kind = value;
|
|
766
|
-
}
|
|
767
|
-
|
|
768
|
-
get kind() {
|
|
769
|
-
return this.extendedProperty("_kind") ?? this.network?.kind;
|
|
770
|
-
}
|
|
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/module.mjs
CHANGED
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isIPv4,
|
|
3
|
+
isIPv6,
|
|
4
|
+
formatCIDR,
|
|
5
|
+
hasWellKnownSubnet,
|
|
6
|
+
normalizeIP
|
|
7
|
+
} from "ip-utilties";
|
|
8
|
+
import { Base } from "./base.mjs";
|
|
9
|
+
import {
|
|
10
|
+
networkProperties,
|
|
11
|
+
networkAddressProperties
|
|
12
|
+
} from "./network-support.mjs";
|
|
13
|
+
import { asArray } from "./utils.mjs";
|
|
14
|
+
import { addType } from "./types.mjs";
|
|
15
|
+
|
|
16
|
+
class SkeletonNetworkInterface extends Base {
|
|
17
|
+
_extends = [];
|
|
18
|
+
_network;
|
|
19
|
+
|
|
20
|
+
set extends(value) {
|
|
21
|
+
this._extends.push(value);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
get extends() {
|
|
25
|
+
return this._extends;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
get isTemplate() {
|
|
29
|
+
return this.name.indexOf("*") >= 0;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
get host() {
|
|
33
|
+
return this.owner;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
get network_interface() {
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
get domainNames() {
|
|
41
|
+
return new Set();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
matches(other) {
|
|
45
|
+
if (this.isTemplate) {
|
|
46
|
+
const name = this.name.replace("*", "");
|
|
47
|
+
return name.length === 0 || other.name.indexOf(name) >= 0;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
get network() {
|
|
54
|
+
return this.extendedProperty("_network") ?? this.host.network;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
set network(network) {
|
|
58
|
+
this._network = network;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
get rawAddress() {
|
|
62
|
+
return this.rawAddresses[0];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
get rawIPv4Address() {
|
|
66
|
+
return this.rawAddresses.filter(a => isIPv4(a))[0];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
get rawIPv6Address() {
|
|
70
|
+
return this.rawAddresses.filter(a => isIPv6(a))[0];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
get cidrAddress() {
|
|
74
|
+
return this.cidrAddresses[0];
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
get ipAddresses() {
|
|
78
|
+
return new Map();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
get rawAddresses() {
|
|
82
|
+
return [...this.ipAddresses].map(([address]) => address);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
get rawIPv4Addresses() {
|
|
86
|
+
return [...this.ipAddresses]
|
|
87
|
+
.filter(([address]) => isIPv4(address))
|
|
88
|
+
.map(([address]) => address);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
get rawIPv6Addresses() {
|
|
92
|
+
return [...this.ipAddresses]
|
|
93
|
+
.filter(([address]) => isIPv6(address))
|
|
94
|
+
.map(([address]) => address);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
get cidrAddresses() {
|
|
98
|
+
return [...this.ipAddresses].map(([address, subnet]) =>
|
|
99
|
+
formatCIDR(address, subnet.prefixLength)
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export const NetworkInterfaceTypeDefinition = {
|
|
105
|
+
name: "network_interface",
|
|
106
|
+
priority: 0.4,
|
|
107
|
+
owners: ["host"],
|
|
108
|
+
extends: Base.typeDefinition,
|
|
109
|
+
specializations: {},
|
|
110
|
+
factoryFor(value) {
|
|
111
|
+
const kind = value.kind;
|
|
112
|
+
const t = NetworkInterfaceTypeDefinition.specializations[kind];
|
|
113
|
+
|
|
114
|
+
if (t) {
|
|
115
|
+
delete value.type;
|
|
116
|
+
return t.clazz;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return NetworkInterface;
|
|
120
|
+
},
|
|
121
|
+
properties: {
|
|
122
|
+
...networkProperties,
|
|
123
|
+
...networkAddressProperties,
|
|
124
|
+
hostName: { type: "string", collection: false, writeable: true },
|
|
125
|
+
ipAddresses: { type: "string", collection: true, writeable: true },
|
|
126
|
+
|
|
127
|
+
hwaddr: { type: "string", collection: false, writeable: true },
|
|
128
|
+
network: { type: "network", collection: false, writeable: true },
|
|
129
|
+
destination: { type: "string", collection: false, writeable: true },
|
|
130
|
+
arpbridge: { type: "network_interface", collection: true, writeable: true }
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
export class NetworkInterface extends SkeletonNetworkInterface {
|
|
135
|
+
static {
|
|
136
|
+
addType(this);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
static get typeDefinition() {
|
|
140
|
+
return NetworkInterfaceTypeDefinition;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
_ipAddresses = new Map();
|
|
144
|
+
_scope;
|
|
145
|
+
_metric;
|
|
146
|
+
_ssid;
|
|
147
|
+
_psk;
|
|
148
|
+
_kind;
|
|
149
|
+
_hostName;
|
|
150
|
+
_hwaddr;
|
|
151
|
+
_class;
|
|
152
|
+
arpbridge;
|
|
153
|
+
|
|
154
|
+
constructor(owner, data) {
|
|
155
|
+
super(owner, data);
|
|
156
|
+
this.read(data, NetworkInterfaceTypeDefinition);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
addSubnet(address) {
|
|
160
|
+
if (!this.network) {
|
|
161
|
+
if (!hasWellKnownSubnet(address)) {
|
|
162
|
+
this.error("Missing network", address);
|
|
163
|
+
}
|
|
164
|
+
} else {
|
|
165
|
+
return this.network.addSubnet(address);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
get ipAddresses() {
|
|
170
|
+
return this._ipAddresses;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
set ipAddresses(value) {
|
|
174
|
+
for (const address of asArray(value)) {
|
|
175
|
+
this._ipAddresses.set(normalizeIP(address), this.addSubnet(address));
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
subnetForAddress(address) {
|
|
180
|
+
return (
|
|
181
|
+
this.network?.subnetForAddress(address) ||
|
|
182
|
+
this.host.owner.subnetForAddress(address)
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
get gateway() {
|
|
187
|
+
return this.network?.gateway;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
get gatewayAddress() {
|
|
191
|
+
for (const a of this.gateway.networkAddresses()) {
|
|
192
|
+
if (a.networkInterface.network === this.network) {
|
|
193
|
+
return a.address;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
get hostName() {
|
|
199
|
+
return this.extendedProperty("_hostName") ?? this.host.hostName;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
set hostName(value) {
|
|
203
|
+
this._hostName = value;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
get domainNames() {
|
|
207
|
+
return this.hostName
|
|
208
|
+
? new Set([[this.hostName, this.host.domain].join(".")])
|
|
209
|
+
: this.host.directDomainNames;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
set scope(value) {
|
|
213
|
+
this._scope = value;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
get scope() {
|
|
217
|
+
return (
|
|
218
|
+
this.extendedProperty("_scope") ??
|
|
219
|
+
this.network?.scope ??
|
|
220
|
+
networkProperties.scope.default
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
set hwaddr(value) {
|
|
225
|
+
this._hwaddr = value;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
get hwaddr() {
|
|
229
|
+
return this.extendedProperty("_hwaddr");
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
set metric(value) {
|
|
233
|
+
this._metric = value;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
get metric() {
|
|
237
|
+
return (
|
|
238
|
+
this.extendedProperty("_metric") ??
|
|
239
|
+
this.network?.metric ??
|
|
240
|
+
networkProperties.metric.default
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
set MTU(value) {
|
|
245
|
+
this._MTU = value;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
get MTU() {
|
|
249
|
+
return this.extendedProperty("_MTU") ?? networkProperties.MTU.default;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
set class(value) {
|
|
253
|
+
this._class = value;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
get class() {
|
|
257
|
+
return this.extendedProperty("_class") ?? this.network?.class;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
set ssid(value) {
|
|
261
|
+
this._ssid = value;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
get ssid() {
|
|
265
|
+
return this.extendedProperty("_ssid") ?? this.network?.ssid;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
set psk(value) {
|
|
269
|
+
this._psk = value;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
get psk() {
|
|
273
|
+
return this.extendedProperty("_psk") ?? this.network?.psk;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
set kind(value) {
|
|
277
|
+
this._kind = value;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
get kind() {
|
|
281
|
+
return this.extendedProperty("_kind") ?? this.network?.kind;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
const LoopbackNetworkInterfaceTypeDefinition = {
|
|
286
|
+
name: "loopback",
|
|
287
|
+
specializationOf: NetworkInterfaceTypeDefinition,
|
|
288
|
+
owners: NetworkInterfaceTypeDefinition.owners,
|
|
289
|
+
extends: NetworkInterfaceTypeDefinition,
|
|
290
|
+
priority: 0.1,
|
|
291
|
+
properties: {}
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
const _localAddresses = new Map([
|
|
295
|
+
["127.0.0.1", { address: "127.0.0/8", prefix: "127.0.0", prefixLength: 8 }], // TODO
|
|
296
|
+
["::1", { address: "::1/128", prefix: "::1", prefixLength: 128 }]
|
|
297
|
+
]);
|
|
298
|
+
|
|
299
|
+
export class LoopbackNetworkInterface extends SkeletonNetworkInterface {
|
|
300
|
+
static {
|
|
301
|
+
addType(this);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
static get typeDefinition() {
|
|
305
|
+
return LoopbackNetworkInterfaceTypeDefinition;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
get kind() {
|
|
309
|
+
return "loopback";
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
get scope() {
|
|
313
|
+
return "host";
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
get hostName() {
|
|
317
|
+
return "localhost";
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
get ipAddresses() {
|
|
321
|
+
return _localAddresses;
|
|
322
|
+
}
|
|
323
|
+
}
|