pmcf 6.41.10 → 6.43.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmcf",
3
- "version": "6.41.10",
3
+ "version": "6.43.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -2,12 +2,15 @@ import { join } from "node:path";
2
2
  import { FileContentProvider } from "npm-pkgbuild";
3
3
  import {
4
4
  reverseArpa,
5
- isLinkLocal,
5
+ addressType,
6
6
  FAMILY_IPV4,
7
- FAMILY_IPV6
7
+ FAMILY_IPV6,
8
+ ADDRESS_TYPE_LOOPBACK
8
9
  } from "ip-utilties";
9
10
  import {
11
+ name_attribute,
10
12
  string_attribute_writable,
13
+ string_collection_attribute_writable,
11
14
  number_attribute_writable,
12
15
  boolean_attribute_writable_true,
13
16
  default_collection_attribute_writable,
@@ -15,23 +18,40 @@ import {
15
18
  } from "pacc";
16
19
  import {
17
20
  addType,
21
+ Subnet,
18
22
  CoreService,
19
23
  Endpoint,
20
- endpointAddresses,
21
24
  sortDescendingByPriority,
22
- endpoints,
23
- SUBNET_LOCALHOST_IPV4,
24
- SUBNET_LOCALHOST_IPV6,
25
25
  FAMILY_UNIX
26
26
  } from "pmcf";
27
27
  import { writeLines } from "../utils.mjs";
28
28
 
29
+ class kea_subnet extends Subnet {
30
+ static attributes = {
31
+ pool: {
32
+ ...string_collection_attribute_writable,
33
+ name: "pool"
34
+ }
35
+ };
36
+
37
+ static {
38
+ addType(this);
39
+ }
40
+
41
+ pool = [];
42
+ }
43
+
29
44
  export class kea extends CoreService {
30
45
  static attributes = {
31
- dnsServers: {
46
+ subnets: {
47
+ ...default_collection_attribute_writable,
48
+ type: kea_subnet,
49
+ name: "subnets"
50
+ },
51
+ dnsServerEndpoints: {
32
52
  ...default_collection_attribute_writable,
33
53
  type: Endpoint,
34
- name: "dnsServers",
54
+ name: "dnsServerEndpoints",
35
55
  deferredExpression: true
36
56
  },
37
57
  "ddns-send-updates": {
@@ -135,6 +155,8 @@ export class kea extends CoreService {
135
155
  addType(this);
136
156
  }
137
157
 
158
+ subnets = new Map();
159
+
138
160
  async *preparePackages(dir) {
139
161
  const ctrlAgentEndpoint = this.endpoint("kea-ha-4");
140
162
 
@@ -144,24 +166,10 @@ export class kea extends CoreService {
144
166
 
145
167
  const network = this.network;
146
168
  const host = this.host;
147
-
148
169
  const source = host.owner;
149
170
  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
-
159
- //console.log(source.fullName, [...source.hosts.keys()]);
160
-
161
- const dnsServerEndpoints = endpoints(this.dnsServers).filter(
162
- e => e.networkInterface?.kind !== "loopback"
163
- );
164
-
171
+ const subnets = [...this.subnets.values()];
172
+ const dnsServerEndpoints = this.dnsServerEndpoints;
165
173
  const packageData = await this.packageData;
166
174
 
167
175
  packageData.sources.push(
@@ -270,7 +278,8 @@ export class kea extends CoreService {
270
278
  data: dnsServerEndpoints
271
279
  .filter(
272
280
  endpoint =>
273
- endpoint.family === `IPv${family}` && endpoint.type === "dns"
281
+ endpoint.family === `IPv${family}` &&
282
+ addressType(endpoint.address) !== ADDRESS_TYPE_LOOPBACK
274
283
  )
275
284
  .map(endpoint => endpoint.address)
276
285
  .join(",")
@@ -322,7 +331,8 @@ export class kea extends CoreService {
322
331
  "dns-servers": dnsServerEndpoints
323
332
  .filter(
324
333
  endpoint =>
325
- endpoint.family === FAMILY_IPV4 && endpoint.type === "dns"
334
+ endpoint.family === FAMILY_IPV4 &&
335
+ addressType(endpoint.address) !== ADDRESS_TYPE_LOOPBACK
326
336
  )
327
337
  .map(endpoint => {
328
338
  return { "ip-address": endpoint.address };
@@ -402,29 +412,18 @@ export class kea extends CoreService {
402
412
  endpoint.type === "dhcp" &&
403
413
  endpoint.family === family &&
404
414
  endpoint.networkInterface.kind !== "loopback" &&
405
- endpoint.networkInterface.kind !== "wlan" &&
406
415
  endpoint.networkInterface.kind !== "tun"
407
416
  ).map(
408
417
  endpoint => `${endpoint.networkInterface.name}/${endpoint.address}`
409
418
  );
410
419
 
411
- const pools = subnet => {
412
- return subnet.dhcpPools.map(pool => {
413
- return { pool: Array.isArray(pool) ? pool.join(" - ") : pool };
414
- });
415
- };
420
+ const pools = subnet => [{ pool: subnet.pool.join(" - ") }];
416
421
 
417
422
  const dhcp4 = {
418
423
  Dhcp4: {
419
424
  ...(await commonConfig("4")),
420
425
  subnet4: subnets
421
- .filter(
422
- s =>
423
- s.family === FAMILY_IPV4 &&
424
- // TODO keep out tailscale
425
- s.cidr !== "100.64.0.2/32" &&
426
- s.cidr !== "100.64.0.3/32"
427
- )
426
+ .filter(s => s.family === FAMILY_IPV4)
428
427
  .map((subnet, index) => {
429
428
  return {
430
429
  id: index + 1,
@@ -445,13 +444,7 @@ export class kea extends CoreService {
445
444
  Dhcp6: {
446
445
  ...(await commonConfig("6")),
447
446
  subnet6: subnets
448
- .filter(
449
- s =>
450
- s.family === FAMILY_IPV6 &&
451
- !isLinkLocal(s.address) &&
452
- // TODO keep out tailscale
453
- s.cidr !== "fd7a:115c:a1e0::/64"
454
- )
447
+ .filter(s => s.family === FAMILY_IPV6)
455
448
  .map((subnet, index) => {
456
449
  return {
457
450
  id: index + 1,
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
  }