pmcf 2.29.2 → 2.30.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/README.md +0 -1
- package/package.json +1 -1
- package/src/base.mjs +1 -1
- package/src/host-utils.mjs +1 -113
- package/src/host.mjs +13 -9
- package/src/module.mjs +5 -1
- package/src/network-address.mjs +1 -5
- package/src/network-interfaces/ethernet.mjs +37 -0
- package/src/network-interfaces/loopback.mjs +44 -0
- package/src/network-interfaces/network-interface.mjs +245 -0
- package/src/network-interfaces/skeleton.mjs +114 -0
- package/src/network-interfaces/wireguard.mjs +30 -0
- package/src/network-interfaces/wlan.mjs +77 -0
- package/src/service.mjs +1 -1
- package/src/subnet.mjs +1 -0
- package/types/cluster.d.mts +1 -0
- package/types/extra-source-service.d.mts +1 -1
- package/types/host-utils.d.mts +0 -1
- package/types/host.d.mts +1 -0
- package/types/module.d.mts +5 -1
- package/types/network-address.d.mts +1 -5
- package/types/network-interfaces/ethernet.d.mts +338 -0
- package/types/network-interfaces/loopback.d.mts +319 -0
- package/types/network-interfaces/network-interface.d.mts +339 -0
- package/types/network-interfaces/skeleton.d.mts +25 -0
- package/types/network-interfaces/wireguard.d.mts +316 -0
- package/types/network-interfaces/wlan.d.mts +486 -0
- package/types/service.d.mts +2 -2
- package/types/services/dhcp.d.mts +2 -2
- package/types/services/dns.d.mts +2 -2
- package/types/services/ntp.d.mts +2 -2
- package/types/subnet.d.mts +1 -0
- package/src/network-interface.mjs +0 -366
- package/types/network-interface.d.mts +0 -1357
|
@@ -1,366 +0,0 @@
|
|
|
1
|
-
import { hasWellKnownSubnet, normalizeIP } from "ip-utilties";
|
|
2
|
-
import {
|
|
3
|
-
NetworkAddress,
|
|
4
|
-
Base,
|
|
5
|
-
SUBNET_LOCALHOST_IPV4,
|
|
6
|
-
SUBNET_LOCALHOST_IPV6
|
|
7
|
-
} from "pmcf";
|
|
8
|
-
import {
|
|
9
|
-
networkProperties,
|
|
10
|
-
networkAddressProperties
|
|
11
|
-
} from "./network-support.mjs";
|
|
12
|
-
import { asArray } from "./utils.mjs";
|
|
13
|
-
import { addType } from "./types.mjs";
|
|
14
|
-
|
|
15
|
-
class SkeletonNetworkInterface extends Base {
|
|
16
|
-
_extends = [];
|
|
17
|
-
_network;
|
|
18
|
-
|
|
19
|
-
set extends(value) {
|
|
20
|
-
this._extends.push(value);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
get extends() {
|
|
24
|
-
return this._extends;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
get isTemplate() {
|
|
28
|
-
return this.name.indexOf("*") >= 0;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
get host() {
|
|
32
|
-
return this.owner;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
get network_interface() {
|
|
36
|
-
return this;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
get domainNames() {
|
|
40
|
-
return new Set();
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
matches(other) {
|
|
44
|
-
if (this.isTemplate) {
|
|
45
|
-
const name = this.name.replaceAll("*", "");
|
|
46
|
-
return name.length === 0 || other.name.indexOf(name) >= 0;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
get network() {
|
|
53
|
-
return this.extendedProperty("_network") ?? this.host.network;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
set network(network) {
|
|
57
|
-
this._network = network;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
get ipAddresses() {
|
|
61
|
-
return new Map();
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
*
|
|
66
|
-
* @param {object} filter
|
|
67
|
-
* @return {Iterable<NetworkAddress>}
|
|
68
|
-
*/
|
|
69
|
-
*networkAddresses(filter = n => true) {
|
|
70
|
-
for (const [address, subnet] of this.ipAddresses) {
|
|
71
|
-
const networkAddress = new NetworkAddress(this, address, subnet);
|
|
72
|
-
|
|
73
|
-
if (filter(networkAddress)) {
|
|
74
|
-
yield networkAddress;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
networkAddress(filter) {
|
|
80
|
-
for (const a of this.networkAddresses(filter)) {
|
|
81
|
-
return a;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
get address() {
|
|
86
|
-
return this.addresses[0];
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
get addresses() {
|
|
90
|
-
return [...this.ipAddresses].map(([address]) => address);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
async systemdDefinitions(packageData) {}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export const NetworkInterfaceTypeDefinition = {
|
|
97
|
-
name: "network_interface",
|
|
98
|
-
priority: 0.4,
|
|
99
|
-
owners: ["host"],
|
|
100
|
-
extends: Base.typeDefinition,
|
|
101
|
-
specializations: {},
|
|
102
|
-
factoryFor(value) {
|
|
103
|
-
const kind = value.kind;
|
|
104
|
-
const t = NetworkInterfaceTypeDefinition.specializations[kind];
|
|
105
|
-
|
|
106
|
-
if (t) {
|
|
107
|
-
delete value.type;
|
|
108
|
-
return t.clazz;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return NetworkInterface;
|
|
112
|
-
},
|
|
113
|
-
properties: {
|
|
114
|
-
...networkProperties,
|
|
115
|
-
...networkAddressProperties,
|
|
116
|
-
hostName: { type: "string", collection: false, writeable: true },
|
|
117
|
-
ipAddresses: { type: "string", collection: true, writeable: true },
|
|
118
|
-
|
|
119
|
-
hwaddr: { type: "string", collection: false, writeable: true },
|
|
120
|
-
network: { type: "network", collection: false, writeable: true },
|
|
121
|
-
destination: { type: "string", collection: false, writeable: true },
|
|
122
|
-
arpbridge: { type: "network_interface", collection: true, writeable: true }
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
export class NetworkInterface extends SkeletonNetworkInterface {
|
|
127
|
-
static {
|
|
128
|
-
addType(this);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
static get typeDefinition() {
|
|
132
|
-
return NetworkInterfaceTypeDefinition;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
_ipAddresses = new Map();
|
|
136
|
-
_scope;
|
|
137
|
-
_metric;
|
|
138
|
-
_kind;
|
|
139
|
-
_hostName;
|
|
140
|
-
_hwaddr;
|
|
141
|
-
_class;
|
|
142
|
-
arpbridge;
|
|
143
|
-
|
|
144
|
-
constructor(owner, data) {
|
|
145
|
-
super(owner, data);
|
|
146
|
-
this.read(data, NetworkInterfaceTypeDefinition);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
addSubnet(address) {
|
|
150
|
-
if (!this.network) {
|
|
151
|
-
if (!hasWellKnownSubnet(address)) {
|
|
152
|
-
this.error("Missing network", address);
|
|
153
|
-
}
|
|
154
|
-
} else {
|
|
155
|
-
return this.network.addSubnet(address);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
get ipAddresses() {
|
|
160
|
-
return this._ipAddresses;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
set ipAddresses(value) {
|
|
164
|
-
for (const address of asArray(value)) {
|
|
165
|
-
this._ipAddresses.set(normalizeIP(address), this.addSubnet(address));
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
subnetForAddress(address) {
|
|
170
|
-
return (
|
|
171
|
-
this.network?.subnetForAddress(address) ||
|
|
172
|
-
this.host.owner.subnetForAddress(address)
|
|
173
|
-
);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
get gateway() {
|
|
177
|
-
return this.network?.gateway;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
get gatewayAddress() {
|
|
181
|
-
for (const a of this.gateway.networkAddresses()) {
|
|
182
|
-
if (a.networkInterface.network === this.network) {
|
|
183
|
-
return a.address;
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
get hostName() {
|
|
189
|
-
return this.extendedProperty("_hostName") ?? this.host.hostName;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
set hostName(value) {
|
|
193
|
-
this._hostName = value;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
get domainNames() {
|
|
197
|
-
return this.hostName
|
|
198
|
-
? new Set([[this.hostName, this.host.domain].join(".")])
|
|
199
|
-
: this.host.directDomainNames;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
set scope(value) {
|
|
203
|
-
this._scope = value;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
get scope() {
|
|
207
|
-
return (
|
|
208
|
-
this.extendedProperty("_scope") ??
|
|
209
|
-
this.network?.scope ??
|
|
210
|
-
networkProperties.scope.default
|
|
211
|
-
);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
set hwaddr(value) {
|
|
215
|
-
this._hwaddr = value;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
get hwaddr() {
|
|
219
|
-
return this.extendedProperty("_hwaddr");
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
set metric(value) {
|
|
223
|
-
this._metric = value;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
get metric() {
|
|
227
|
-
return (
|
|
228
|
-
this.extendedProperty("_metric") ??
|
|
229
|
-
this.network?.metric ??
|
|
230
|
-
networkProperties.metric.default
|
|
231
|
-
);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
set MTU(value) {
|
|
235
|
-
this._MTU = value;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
get MTU() {
|
|
239
|
-
return this.extendedProperty("_MTU") ?? networkProperties.MTU.default;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
set class(value) {
|
|
243
|
-
this._class = value;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
get class() {
|
|
247
|
-
return this.extendedProperty("_class") ?? this.network?.class;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
set kind(value) {
|
|
251
|
-
this._kind = value;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
get kind() {
|
|
255
|
-
return this.extendedProperty("_kind") ?? this.network?.kind;
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
const WLANNetworkInterfaceTypeDefinition = {
|
|
260
|
-
name: "wlan",
|
|
261
|
-
specializationOf: NetworkInterfaceTypeDefinition,
|
|
262
|
-
owners: NetworkInterfaceTypeDefinition.owners,
|
|
263
|
-
extends: NetworkInterfaceTypeDefinition,
|
|
264
|
-
priority: 0.1,
|
|
265
|
-
properties: {}
|
|
266
|
-
};
|
|
267
|
-
|
|
268
|
-
export class WLANNetworkInterface extends NetworkInterface {
|
|
269
|
-
_ssid;
|
|
270
|
-
_psk;
|
|
271
|
-
|
|
272
|
-
static {
|
|
273
|
-
addType(this);
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
static get typeDefinition() {
|
|
277
|
-
return WLANNetworkInterfaceTypeDefinition;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
/*get kind() {
|
|
281
|
-
return WLANNetworkInterfaceTypeDefinition.name;
|
|
282
|
-
}*/
|
|
283
|
-
|
|
284
|
-
set ssid(value) {
|
|
285
|
-
this._ssid = value;
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
get ssid() {
|
|
289
|
-
return this.extendedProperty("_ssid") ?? this.network?.ssid;
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
set psk(value) {
|
|
293
|
-
this._psk = value;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
get psk() {
|
|
297
|
-
return this.extendedProperty("_psk") ?? this.network?.psk;
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
const LoopbackNetworkInterfaceTypeDefinition = {
|
|
302
|
-
name: "loopback",
|
|
303
|
-
specializationOf: NetworkInterfaceTypeDefinition,
|
|
304
|
-
owners: NetworkInterfaceTypeDefinition.owners,
|
|
305
|
-
extends: NetworkInterfaceTypeDefinition,
|
|
306
|
-
priority: 0.1,
|
|
307
|
-
properties: {}
|
|
308
|
-
};
|
|
309
|
-
|
|
310
|
-
const _localAddresses = new Map([
|
|
311
|
-
["127.0.0.1", SUBNET_LOCALHOST_IPV4],
|
|
312
|
-
["::1", SUBNET_LOCALHOST_IPV6]
|
|
313
|
-
]);
|
|
314
|
-
|
|
315
|
-
export class LoopbackNetworkInterface extends SkeletonNetworkInterface {
|
|
316
|
-
static {
|
|
317
|
-
addType(this);
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
static get typeDefinition() {
|
|
321
|
-
return LoopbackNetworkInterfaceTypeDefinition;
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
get kind() {
|
|
325
|
-
return LoopbackNetworkInterfaceTypeDefinition.name;
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
get scope() {
|
|
329
|
-
return "host";
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
get hostName() {
|
|
333
|
-
return "localhost";
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
get ipAddresses() {
|
|
337
|
-
return _localAddresses;
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
const WireguardNetworkInterfaceTypeDefinition = {
|
|
342
|
-
name: "wireguard",
|
|
343
|
-
specializationOf: NetworkInterfaceTypeDefinition,
|
|
344
|
-
owners: NetworkInterfaceTypeDefinition.owners,
|
|
345
|
-
extends: NetworkInterfaceTypeDefinition,
|
|
346
|
-
priority: 0.1,
|
|
347
|
-
properties: {}
|
|
348
|
-
};
|
|
349
|
-
|
|
350
|
-
export class WireguardNetworkInterface extends SkeletonNetworkInterface {
|
|
351
|
-
static {
|
|
352
|
-
addType(this);
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
static get typeDefinition() {
|
|
356
|
-
return WireguardNetworkInterfaceTypeDefinition;
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
get kind() {
|
|
360
|
-
return WireguardNetworkInterfaceTypeDefinition.name;
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
get ipAddresses() {
|
|
364
|
-
return new Map();
|
|
365
|
-
}
|
|
366
|
-
}
|