pmcf 6.42.0 → 6.44.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 +1 -1
- package/src/content.mjs +6 -3
- package/src/core.mjs +1 -1
- package/src/services/kea.mjs +58 -61
- package/src/subnet.mjs +6 -11
package/package.json
CHANGED
package/src/content.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { join } from "node:path";
|
|
2
2
|
import {
|
|
3
3
|
name_attribute_writable,
|
|
4
4
|
string_attribute_writable,
|
|
@@ -8,7 +8,8 @@ import {
|
|
|
8
8
|
extendingAttributeIterator
|
|
9
9
|
} from "pacc";
|
|
10
10
|
import { allOutputs } from "npm-pkgbuild";
|
|
11
|
-
import { core
|
|
11
|
+
import { core } from "./core.mjs";
|
|
12
|
+
import { addType } from "./type.mjs";
|
|
12
13
|
import { union } from "./utils.mjs";
|
|
13
14
|
import { loadHooks } from "./hooks.mjs";
|
|
14
15
|
|
|
@@ -236,7 +237,9 @@ export class content extends core {
|
|
|
236
237
|
}
|
|
237
238
|
|
|
238
239
|
get permissions() {
|
|
239
|
-
return this.expand(
|
|
240
|
+
return this.expand(
|
|
241
|
+
this.mapFromDirections(["this", "extends"], "_permissions")
|
|
242
|
+
);
|
|
240
243
|
}
|
|
241
244
|
|
|
242
245
|
/**
|
package/src/core.mjs
CHANGED
package/src/services/kea.mjs
CHANGED
|
@@ -2,7 +2,6 @@ import { join } from "node:path";
|
|
|
2
2
|
import { FileContentProvider } from "npm-pkgbuild";
|
|
3
3
|
import {
|
|
4
4
|
reverseArpa,
|
|
5
|
-
isLinkLocal,
|
|
6
5
|
addressType,
|
|
7
6
|
FAMILY_IPV4,
|
|
8
7
|
FAMILY_IPV6,
|
|
@@ -10,6 +9,7 @@ import {
|
|
|
10
9
|
} from "ip-utilties";
|
|
11
10
|
import {
|
|
12
11
|
string_attribute_writable,
|
|
12
|
+
string_collection_attribute_writable,
|
|
13
13
|
number_attribute_writable,
|
|
14
14
|
boolean_attribute_writable_true,
|
|
15
15
|
default_collection_attribute_writable,
|
|
@@ -17,17 +17,42 @@ import {
|
|
|
17
17
|
} from "pacc";
|
|
18
18
|
import {
|
|
19
19
|
addType,
|
|
20
|
+
Subnet,
|
|
20
21
|
CoreService,
|
|
21
22
|
Endpoint,
|
|
22
23
|
sortDescendingByPriority,
|
|
23
|
-
SUBNET_LOCALHOST_IPV4,
|
|
24
|
-
SUBNET_LOCALHOST_IPV6,
|
|
25
24
|
FAMILY_UNIX
|
|
26
25
|
} from "pmcf";
|
|
27
26
|
import { writeLines } from "../utils.mjs";
|
|
28
27
|
|
|
28
|
+
class kea_subnet extends Subnet {
|
|
29
|
+
static attributes = {
|
|
30
|
+
pool: {
|
|
31
|
+
...string_collection_attribute_writable,
|
|
32
|
+
name: "pool"
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
static {
|
|
37
|
+
addType(this);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
pool = [];
|
|
41
|
+
}
|
|
42
|
+
|
|
29
43
|
export class kea extends CoreService {
|
|
30
44
|
static attributes = {
|
|
45
|
+
subnets: {
|
|
46
|
+
...default_collection_attribute_writable,
|
|
47
|
+
type: kea_subnet,
|
|
48
|
+
name: "subnets"
|
|
49
|
+
},
|
|
50
|
+
peers: {
|
|
51
|
+
...default_collection_attribute_writable,
|
|
52
|
+
type: CoreService,
|
|
53
|
+
name: "peers",
|
|
54
|
+
deferredExpression: true
|
|
55
|
+
},
|
|
31
56
|
dnsServerEndpoints: {
|
|
32
57
|
...default_collection_attribute_writable,
|
|
33
58
|
type: Endpoint,
|
|
@@ -135,6 +160,8 @@ export class kea extends CoreService {
|
|
|
135
160
|
addType(this);
|
|
136
161
|
}
|
|
137
162
|
|
|
163
|
+
subnets = new Map();
|
|
164
|
+
|
|
138
165
|
async *preparePackages(dir) {
|
|
139
166
|
const ctrlAgentEndpoint = this.endpoint("kea-ha-4");
|
|
140
167
|
|
|
@@ -144,18 +171,9 @@ export class kea extends CoreService {
|
|
|
144
171
|
|
|
145
172
|
const network = this.network;
|
|
146
173
|
const host = this.host;
|
|
147
|
-
|
|
148
174
|
const source = host.owner;
|
|
149
175
|
const name = host.name;
|
|
150
|
-
|
|
151
|
-
const subnets = [...new Map(this.subnets).values()].filter(
|
|
152
|
-
s => s !== SUBNET_LOCALHOST_IPV4 && s !== SUBNET_LOCALHOST_IPV6
|
|
153
|
-
); // TODO should be normal
|
|
154
|
-
/*console.log(
|
|
155
|
-
"SUBNETS",
|
|
156
|
-
subnets.map(s => s.fullName)
|
|
157
|
-
);*/
|
|
158
|
-
|
|
176
|
+
const subnets = [...this.subnets.values()];
|
|
159
177
|
const dnsServerEndpoints = this.dnsServerEndpoints;
|
|
160
178
|
const packageData = await this.packageData;
|
|
161
179
|
|
|
@@ -170,27 +188,6 @@ export class kea extends CoreService {
|
|
|
170
188
|
})
|
|
171
189
|
);
|
|
172
190
|
|
|
173
|
-
const peers = async family =>
|
|
174
|
-
Array.from(
|
|
175
|
-
source.expression(
|
|
176
|
-
`services[types[kea] && priority>=${Math.min(this.priority, 100)}]`
|
|
177
|
-
)
|
|
178
|
-
)
|
|
179
|
-
.sort(sortDescendingByPriority)
|
|
180
|
-
.map((dhcp, i) => {
|
|
181
|
-
const ctrlAgentEndpoint = dhcp.endpoint(`kea-ha-${family}`);
|
|
182
|
-
|
|
183
|
-
if (ctrlAgentEndpoint) {
|
|
184
|
-
return {
|
|
185
|
-
name: dhcp.host.name,
|
|
186
|
-
role: i === 0 ? "primary" : i > 1 ? "backup" : "standby",
|
|
187
|
-
url: ctrlAgentEndpoint.url,
|
|
188
|
-
"auto-failover": i <= 1
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
})
|
|
192
|
-
.filter(p => p != null);
|
|
193
|
-
|
|
194
191
|
const loggers = [
|
|
195
192
|
{
|
|
196
193
|
"output-options": [
|
|
@@ -203,7 +200,9 @@ export class kea extends CoreService {
|
|
|
203
200
|
}
|
|
204
201
|
];
|
|
205
202
|
|
|
206
|
-
const
|
|
203
|
+
const peers = this.peers;
|
|
204
|
+
|
|
205
|
+
const commonConfig = family => {
|
|
207
206
|
const cfg = {
|
|
208
207
|
"interfaces-config": {
|
|
209
208
|
interfaces: listenInterfaces(`IPv${family}`)
|
|
@@ -250,7 +249,24 @@ export class kea extends CoreService {
|
|
|
250
249
|
"http-listener-threads": 2,
|
|
251
250
|
"http-client-threads": 2
|
|
252
251
|
},*/
|
|
253
|
-
peers:
|
|
252
|
+
peers: peers
|
|
253
|
+
.sort(sortDescendingByPriority)
|
|
254
|
+
.reduce((a, kea) => {
|
|
255
|
+
const ctrlAgentEndpoint = kea.endpoint(
|
|
256
|
+
`kea-ha-${family}`
|
|
257
|
+
);
|
|
258
|
+
if (ctrlAgentEndpoint) {
|
|
259
|
+
const i = a.length;
|
|
260
|
+
a.push({
|
|
261
|
+
name: kea.host.name,
|
|
262
|
+
role:
|
|
263
|
+
i === 0 ? "primary" : i > 1 ? "backup" : "standby",
|
|
264
|
+
url: ctrlAgentEndpoint.url,
|
|
265
|
+
"auto-failover": i <= 1
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
return a;
|
|
269
|
+
}, [])
|
|
254
270
|
}
|
|
255
271
|
]
|
|
256
272
|
}
|
|
@@ -399,34 +415,21 @@ export class kea extends CoreService {
|
|
|
399
415
|
endpoint.type === "dhcp" &&
|
|
400
416
|
endpoint.family === family &&
|
|
401
417
|
endpoint.networkInterface.kind !== "loopback" &&
|
|
402
|
-
endpoint.networkInterface.kind !== "wlan" &&
|
|
403
418
|
endpoint.networkInterface.kind !== "tun"
|
|
404
419
|
).map(
|
|
405
420
|
endpoint => `${endpoint.networkInterface.name}/${endpoint.address}`
|
|
406
421
|
);
|
|
407
422
|
|
|
408
|
-
const pools = subnet => {
|
|
409
|
-
return subnet.dhcpPools.map(pool => {
|
|
410
|
-
return { pool: Array.isArray(pool) ? pool.join(" - ") : pool };
|
|
411
|
-
});
|
|
412
|
-
};
|
|
413
|
-
|
|
414
423
|
const dhcp4 = {
|
|
415
424
|
Dhcp4: {
|
|
416
|
-
...
|
|
425
|
+
...commonConfig("4"),
|
|
417
426
|
subnet4: subnets
|
|
418
|
-
.filter(
|
|
419
|
-
s =>
|
|
420
|
-
s.family === FAMILY_IPV4 &&
|
|
421
|
-
// TODO keep out tailscale
|
|
422
|
-
s.cidr !== "100.64.0.2/32" &&
|
|
423
|
-
s.cidr !== "100.64.0.3/32"
|
|
424
|
-
)
|
|
427
|
+
.filter(s => s.family === FAMILY_IPV4)
|
|
425
428
|
.map((subnet, index) => {
|
|
426
429
|
return {
|
|
427
430
|
id: index + 1,
|
|
428
431
|
subnet: subnet.longAddress,
|
|
429
|
-
pools:
|
|
432
|
+
pools: [{ pool: subnet.pool.join(" - ") }],
|
|
430
433
|
reservations: reservations(subnet, "4"),
|
|
431
434
|
"option-data": [
|
|
432
435
|
{
|
|
@@ -440,20 +443,14 @@ export class kea extends CoreService {
|
|
|
440
443
|
};
|
|
441
444
|
const dhcp6 = {
|
|
442
445
|
Dhcp6: {
|
|
443
|
-
...
|
|
446
|
+
...commonConfig("6"),
|
|
444
447
|
subnet6: subnets
|
|
445
|
-
.filter(
|
|
446
|
-
s =>
|
|
447
|
-
s.family === FAMILY_IPV6 &&
|
|
448
|
-
!isLinkLocal(s.address) &&
|
|
449
|
-
// TODO keep out tailscale
|
|
450
|
-
s.cidr !== "fd7a:115c:a1e0::/64"
|
|
451
|
-
)
|
|
448
|
+
.filter(s => s.family === FAMILY_IPV6)
|
|
452
449
|
.map((subnet, index) => {
|
|
453
450
|
return {
|
|
454
451
|
id: index + 1,
|
|
455
452
|
subnet: subnet.longAddress,
|
|
456
|
-
pools:
|
|
453
|
+
pools: [{ pool: subnet.pool.join(" - ") }],
|
|
457
454
|
reservations: reservations(subnet, "6")
|
|
458
455
|
};
|
|
459
456
|
})
|
package/src/subnet.mjs
CHANGED
|
@@ -3,7 +3,6 @@ import {
|
|
|
3
3
|
rangeIP,
|
|
4
4
|
decodeIP,
|
|
5
5
|
matchPrefixIP,
|
|
6
|
-
FAMILY_IPV6
|
|
7
6
|
} from "ip-utilties";
|
|
8
7
|
import { string_attribute, name_attribute, integer_attribute } from "pacc";
|
|
9
8
|
import { networks_attribute } from "./common-attributes.mjs";
|
|
@@ -30,6 +29,12 @@ export class Subnet extends core {
|
|
|
30
29
|
|
|
31
30
|
constructor(owner, address) {
|
|
32
31
|
super();
|
|
32
|
+
|
|
33
|
+
switch(typeof address) {
|
|
34
|
+
case "object":
|
|
35
|
+
address = address.address;
|
|
36
|
+
}
|
|
37
|
+
|
|
33
38
|
const { longPrefix, prefix, prefixLength, cidr, family } =
|
|
34
39
|
normalizeCIDR(address);
|
|
35
40
|
|
|
@@ -71,16 +76,6 @@ export class Subnet extends core {
|
|
|
71
76
|
return rangeIP(this.prefix, this.prefixLength, 1, 1).map(a => decodeIP(a));
|
|
72
77
|
}
|
|
73
78
|
|
|
74
|
-
get dhcpPools() {
|
|
75
|
-
/* TODO where to take values from ? */
|
|
76
|
-
|
|
77
|
-
return [
|
|
78
|
-
this.family === FAMILY_IPV6
|
|
79
|
-
? this.cidr
|
|
80
|
-
: rangeIP(this.prefix, this.prefixLength, 51, 20).map(a => decodeIP(a))
|
|
81
|
-
];
|
|
82
|
-
}
|
|
83
|
-
|
|
84
79
|
get longAddress() {
|
|
85
80
|
return `${this.longPrefix}/${this.prefixLength}`;
|
|
86
81
|
}
|