pmcf 6.49.17 → 6.50.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.49.17",
3
+ "version": "6.50.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/src/cluster.mjs CHANGED
@@ -183,7 +183,7 @@ export class cluster extends host {
183
183
 
184
184
  default:
185
185
  switch (endpoint.protocol) {
186
- case "tcp":
186
+ case PROTOCOL_TCP:
187
187
  cfg.push(` TCP_CHECK {`);
188
188
  cfg.push(" connect_timeout 10");
189
189
  cfg.push(" }");
@@ -12,6 +12,7 @@ import {
12
12
  boolean_attribute_false,
13
13
  port_attribute_writable
14
14
  } from "pacc";
15
+ import { PROTOCOL_TCP, PROTOCOL_UDP, PROTOCOL_QUIC } from "./constants.mjs";
15
16
 
16
17
  export const networkAddressType = "network|host|network_interface";
17
18
 
@@ -166,7 +167,7 @@ export const endpointAttributes = {
166
167
  protocol: {
167
168
  ...string_attribute_writable,
168
169
  name: "protocol",
169
- values: new Set(["tcp", "udp", "quic"])
170
+ values: new Set([PROTOCOL_TCP, PROTOCOL_UDP, PROTOCOL_QUIC])
170
171
  },
171
172
  type: { ...string_attribute, name: "type" },
172
173
  tls: { ...boolean_attribute_false, name: "tls" },
@@ -0,0 +1,10 @@
1
+ import { FAMILY_IPV4, FAMILY_IPV6 } from "ip-utilties";
2
+
3
+ export const PROTOCOL_TCP = "tcp";
4
+ export const PROTOCOL_UDP = "udp";
5
+ export const PROTOCOL_QUIC = "quic";
6
+
7
+ export const FAMILY_UNIX = "unix";
8
+ export const FAMILY_DNS = "dns";
9
+ export const FAMILY_IPV4_IPV6 = new Set([FAMILY_IPV4, FAMILY_IPV6]);
10
+
@@ -19,10 +19,9 @@ import {
19
19
  DomainNameEndpoint,
20
20
  HTTPEndpoint,
21
21
  unix_endpoint,
22
- addType,
23
- FAMILY_UNIX,
24
- FAMILY_DNS
22
+ addType
25
23
  } from "pmcf";
24
+ import { FAMILY_UNIX, FAMILY_DNS } from "./constants.mjs";
26
25
  import {
27
26
  networkAddressAttributes,
28
27
  extends_attribute,
@@ -77,7 +76,11 @@ export class CoreService extends base {
77
76
  systemdService: { ...string_attribute_writable, name: "systemdService" },
78
77
  systemUserName: { ...string_attribute_writable, name: "systemUserName" },
79
78
  systemGroupName: { ...string_attribute_writable, name: "systemGroupName" },
80
- credentials: { ...default_collection_attribute_writable, type: credential, name: "credentials" }
79
+ credentials: {
80
+ ...default_collection_attribute_writable,
81
+ type: credential,
82
+ name: "credentials"
83
+ }
81
84
  };
82
85
 
83
86
  static {
@@ -155,16 +158,17 @@ export class CoreService extends base {
155
158
  delete options.kind;
156
159
 
157
160
  for (const na of this.host.networkAddresses()) {
158
- if (e.kind && e.kind !== na.networkInterface.kind) {
161
+ if (
162
+ (e.family && e.family !== na.family) ||
163
+ (e.kind && e.kind !== na.networkInterface.kind)
164
+ ) {
159
165
  continue;
160
166
  }
161
-
167
+
162
168
  if (e.pathname) {
163
169
  result.push(new HTTPEndpoint(this, na, options));
164
170
  } else {
165
- if (e.family === na.family) {
166
- result.push(new Endpoint(this, na, options));
167
- }
171
+ result.push(new Endpoint(this, na, options));
168
172
  }
169
173
  }
170
174
 
package/src/endpoint.mjs CHANGED
@@ -1,12 +1,9 @@
1
1
  import { getAttribute, string_attribute, url_attribute } from "pacc";
2
- import { FAMILY_IPV4, FAMILY_IPV6 } from "ip-utilties";
3
- import { addType } from "pmcf";
2
+ import { FAMILY_IPV6 } from "ip-utilties";
3
+ import { addType } from "./type.mjs";
4
4
  import { CoreService } from "./core-service.mjs";
5
5
  import { family_attribute, endpointAttributes } from "./common-attributes.mjs";
6
-
7
- export const FAMILY_UNIX = "unix";
8
- export const FAMILY_DNS = "dns";
9
- export const FAMILY_IPV4_IPV6 = new Set([FAMILY_IPV4, FAMILY_IPV6]);
6
+ import { FAMILY_DNS, FAMILY_UNIX } from "./constants.mjs";
10
7
 
11
8
  class BaseEndpoint {
12
9
  static name = "base_endpoint";
@@ -186,6 +183,7 @@ export class HTTPEndpoint extends BaseEndpoint {
186
183
  * @param {object} data
187
184
  * @param {number} data.port
188
185
  * @param {string} data.pathname
186
+ * @param {string} data.family
189
187
  */
190
188
  constructor(service, address, data) {
191
189
  super(service, data);
@@ -195,15 +193,16 @@ export class HTTPEndpoint extends BaseEndpoint {
195
193
  } else if (address instanceof URL) {
196
194
  this.url = address;
197
195
  } else {
198
- this.family = address.family;
196
+ this.family = data.family ?? address.family;
197
+
199
198
  this.url = new URL(
200
199
  (data.tls ? "https://" : "http://") +
201
- (address.family === FAMILY_IPV6
200
+ (data.family === FAMILY_IPV6
202
201
  ? "[" + address.address + "]"
203
202
  : address.address) +
204
203
  ":" +
205
204
  data.port +
206
- (data.pathname || "/")
205
+ (data.pathname ?? "/")
207
206
  );
208
207
  this.hostname = address.address;
209
208
  }
@@ -229,7 +228,7 @@ export class HTTPEndpoint extends BaseEndpoint {
229
228
  }
230
229
 
231
230
  get protocol() {
232
- return "tcp";
231
+ return PROTOCOL_TCP;
233
232
  }
234
233
 
235
234
  get tls() {
package/src/module.mjs CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from "./type.mjs";
2
+ export * from "./constants.mjs";
2
3
  export * from "./core.mjs";
3
4
  export * from "./content.mjs";
4
5
  export * from "./common-attributes.mjs";
@@ -1,9 +1,11 @@
1
1
  import { asArray } from "pacc";
2
2
  import { FAMILY_IPV6 } from "ip-utilties";
3
- import { FAMILY_UNIX, FAMILY_IPV4_IPV6 } from "./endpoint.mjs";
4
-
5
- const TCP = "tcp";
6
- const UDP = "udp";
3
+ import {
4
+ FAMILY_UNIX,
5
+ FAMILY_IPV4_IPV6,
6
+ PROTOCOL_UDP,
7
+ PROTOCOL_TCP
8
+ } from "./constants.mjs";
7
9
 
8
10
  /**
9
11
  * @typedef {object} ServiceType
@@ -11,7 +13,7 @@ const UDP = "udp";
11
13
  * @property {Array<Object>} services
12
14
  * @property {Array<ServiceType>} extends
13
15
  * @property {Array<object>} endpoints
14
- *
16
+ *
15
17
  */
16
18
  export const ServiceTypes = {
17
19
  "alpm-repo": {
@@ -24,13 +26,13 @@ export const ServiceTypes = {
24
26
  syslog: {
25
27
  endpoints: [
26
28
  {
27
- protocol: UDP,
29
+ protocol: PROTOCOL_UDP,
28
30
  family: FAMILY_IPV4_IPV6,
29
31
  port: 514,
30
32
  tls: false
31
33
  },
32
34
  {
33
- protocol: TCP,
35
+ protocol: PROTOCOL_TCP,
34
36
  family: FAMILY_IPV4_IPV6,
35
37
  port: 514,
36
38
  tls: false
@@ -39,33 +41,63 @@ export const ServiceTypes = {
39
41
  },
40
42
  mqtt: {
41
43
  endpoints: [
42
- { family: FAMILY_IPV4_IPV6, protocol: TCP, port: 1883, tls: false }
44
+ {
45
+ family: FAMILY_IPV4_IPV6,
46
+ protocol: PROTOCOL_TCP,
47
+ port: 1883,
48
+ tls: false
49
+ }
43
50
  ]
44
51
  },
45
52
  "secure-mqtt": {
46
53
  endpoints: [
47
- { family: FAMILY_IPV4_IPV6, protocol: TCP, port: 8883, tls: true }
54
+ {
55
+ family: FAMILY_IPV4_IPV6,
56
+ protocol: PROTOCOL_TCP,
57
+ port: 8883,
58
+ tls: true
59
+ }
48
60
  ]
49
61
  },
50
62
  ntp: {
51
63
  endpoints: [
52
- { family: FAMILY_IPV4_IPV6, protocol: UDP, port: 123, tls: false }
64
+ {
65
+ family: FAMILY_IPV4_IPV6,
66
+ protocol: PROTOCOL_UDP,
67
+ port: 123,
68
+ tls: false
69
+ }
53
70
  ]
54
71
  },
55
72
  dns: {
56
73
  endpoints: [
57
- { family: FAMILY_IPV4_IPV6, protocol: UDP, port: 53, tls: false }
74
+ { family: FAMILY_IPV4_IPV6, protocol: PROTOCOL_UDP, port: 53, tls: false }
58
75
  ]
59
76
  },
60
77
  mdns: {
61
78
  endpoints: [
62
- { family: FAMILY_IPV4_IPV6, protocol: UDP, port: 5353, tls: false }
79
+ {
80
+ family: FAMILY_IPV4_IPV6,
81
+ protocol: PROTOCOL_UDP,
82
+ port: 5353,
83
+ tls: false
84
+ }
63
85
  ]
64
86
  },
65
87
  llmnr: {
66
88
  endpoints: [
67
- { family: FAMILY_IPV4_IPV6, protocol: UDP, port: 5355, tls: false },
68
- { family: FAMILY_IPV4_IPV6, protocol: TCP, port: 5355, tls: false }
89
+ {
90
+ family: FAMILY_IPV4_IPV6,
91
+ protocol: PROTOCOL_UDP,
92
+ port: 5355,
93
+ tls: false
94
+ },
95
+ {
96
+ family: FAMILY_IPV4_IPV6,
97
+ protocol: PROTOCOL_TCP,
98
+ port: 5355,
99
+ tls: false
100
+ }
69
101
  ]
70
102
  },
71
103
  ldap: {
@@ -73,7 +105,7 @@ export const ServiceTypes = {
73
105
  {
74
106
  family: FAMILY_IPV4_IPV6,
75
107
  scheme: "ldap",
76
- protocol: TCP,
108
+ protocol: PROTOCOL_TCP,
77
109
  port: 389,
78
110
  tls: false
79
111
  }
@@ -84,7 +116,7 @@ export const ServiceTypes = {
84
116
  {
85
117
  family: FAMILY_IPV4_IPV6,
86
118
  scheme: "ldaps",
87
- protocol: TCP,
119
+ protocol: PROTOCOL_TCP,
88
120
  port: 636,
89
121
  tls: true
90
122
  }
@@ -98,7 +130,7 @@ export const ServiceTypes = {
98
130
  {
99
131
  family: FAMILY_IPV4_IPV6,
100
132
  scheme: "http",
101
- protocol: TCP,
133
+ protocol: PROTOCOL_TCP,
102
134
  port: 80,
103
135
  tls: false
104
136
  }
@@ -109,7 +141,7 @@ export const ServiceTypes = {
109
141
  {
110
142
  family: FAMILY_IPV4_IPV6,
111
143
  scheme: "https",
112
- protocol: TCP,
144
+ protocol: PROTOCOL_TCP,
113
145
  port: 443,
114
146
  tls: true
115
147
  }
@@ -121,7 +153,7 @@ export const ServiceTypes = {
121
153
  {
122
154
  family: FAMILY_IPV4_IPV6,
123
155
  scheme: "https",
124
- protocol: UDP,
156
+ protocol: PROTOCOL_UDP,
125
157
  port: 443,
126
158
  tls: true
127
159
  }
@@ -133,54 +165,79 @@ export const ServiceTypes = {
133
165
  },
134
166
  rtsp: {
135
167
  endpoints: [
136
- { family: FAMILY_IPV4_IPV6, protocol: TCP, port: 554, tls: false }
168
+ {
169
+ family: FAMILY_IPV4_IPV6,
170
+ protocol: PROTOCOL_TCP,
171
+ port: 554,
172
+ tls: false
173
+ }
137
174
  ]
138
175
  },
139
176
  smtp: {
140
177
  endpoints: [
141
- { family: FAMILY_IPV4_IPV6, protocol: TCP, port: 25, tls: false }
178
+ { family: FAMILY_IPV4_IPV6, protocol: PROTOCOL_TCP, port: 25, tls: false }
142
179
  ],
143
180
  dnsRecord: { type: "MX" }
144
181
  },
145
182
  smtps: {
146
183
  endpoints: [
147
- { family: FAMILY_IPV4_IPV6, protocol: TCP, port: 465, tls: true }
184
+ { family: FAMILY_IPV4_IPV6, protocol: PROTOCOL_TCP, port: 465, tls: true }
148
185
  ],
149
186
  dnsRecord: { type: "MX" }
150
187
  },
151
188
  submission: {
152
189
  endpoints: [
153
- { family: FAMILY_IPV4_IPV6, protocol: TCP, port: 587, tls: false }
190
+ {
191
+ family: FAMILY_IPV4_IPV6,
192
+ protocol: PROTOCOL_TCP,
193
+ port: 587,
194
+ tls: false
195
+ }
154
196
  ]
155
197
  },
156
198
  lmtp: {
157
199
  endpoints: [
158
- { family: FAMILY_IPV4_IPV6, protocol: TCP, port: 24, tls: false }
200
+ { family: FAMILY_IPV4_IPV6, protocol: PROTOCOL_TCP, port: 24, tls: false }
159
201
  ]
160
202
  },
161
203
  ssh: {
162
204
  endpoints: [
163
- { family: FAMILY_IPV4_IPV6, protocol: TCP, port: 22, tls: false }
205
+ { family: FAMILY_IPV4_IPV6, protocol: PROTOCOL_TCP, port: 22, tls: false }
164
206
  ]
165
207
  },
166
208
  imap: {
167
209
  endpoints: [
168
- { family: FAMILY_IPV4_IPV6, protocol: TCP, port: 143, tls: false }
210
+ {
211
+ family: FAMILY_IPV4_IPV6,
212
+ protocol: PROTOCOL_TCP,
213
+ port: 143,
214
+ tls: false
215
+ }
169
216
  ]
170
217
  },
171
218
  imaps: {
172
219
  endpoints: [
173
- { family: FAMILY_IPV4_IPV6, protocol: TCP, port: 993, tls: true }
220
+ { family: FAMILY_IPV4_IPV6, protocol: PROTOCOL_TCP, port: 993, tls: true }
174
221
  ]
175
222
  },
176
223
  dhcp: {
177
224
  endpoints: [
178
- { family: FAMILY_IPV4_IPV6, protocol: UDP, port: 547, tls: false }
225
+ {
226
+ family: FAMILY_IPV4_IPV6,
227
+ protocol: PROTOCOL_UDP,
228
+ port: 547,
229
+ tls: false
230
+ }
179
231
  ]
180
232
  },
181
233
  "dhcpv6-client": {
182
234
  endpoints: [
183
- { family: FAMILY_IPV4_IPV6, protocol: TCP, port: 546, tls: false }
235
+ {
236
+ family: FAMILY_IPV4_IPV6,
237
+ protocol: PROTOCOL_TCP,
238
+ port: 546,
239
+ tls: false
240
+ }
184
241
  ]
185
242
  },
186
243
  "dhcpv6-server": {
@@ -188,7 +245,12 @@ export const ServiceTypes = {
188
245
  },
189
246
  smb: {
190
247
  endpoints: [
191
- { family: FAMILY_IPV4_IPV6, protocol: TCP, port: 445, tls: false }
248
+ {
249
+ family: FAMILY_IPV4_IPV6,
250
+ protocol: PROTOCOL_TCP,
251
+ port: 445,
252
+ tls: false
253
+ }
192
254
  ]
193
255
  },
194
256
  nginx: {
@@ -209,19 +271,34 @@ export const ServiceTypes = {
209
271
  pcp: {
210
272
  // rfc6887
211
273
  endpoints: [
212
- { family: FAMILY_IPV4_IPV6, protocol: UDP, port: 5351, tls: false }
274
+ {
275
+ family: FAMILY_IPV4_IPV6,
276
+ protocol: PROTOCOL_UDP,
277
+ port: 5351,
278
+ tls: false
279
+ }
213
280
  ]
214
281
  },
215
282
  "pcp-multicast": {
216
283
  // rfc6887
217
284
  endpoints: [
218
- { family: FAMILY_IPV4_IPV6, protocol: UDP, port: 5350, tls: false }
285
+ {
286
+ family: FAMILY_IPV4_IPV6,
287
+ protocol: PROTOCOL_UDP,
288
+ port: 5350,
289
+ tls: false
290
+ }
219
291
  ]
220
292
  },
221
- "mbap": {
222
- // Modbus TCP
293
+ mbap: {
294
+ // Modbus PROTOCOL_TCP
223
295
  endpoints: [
224
- { family: FAMILY_IPV4_IPV6, protocol: TCP, port: 502, tls: false }
296
+ {
297
+ family: FAMILY_IPV4_IPV6,
298
+ protocol: PROTOCOL_TCP,
299
+ port: 502,
300
+ tls: false
301
+ }
225
302
  ]
226
303
  }
227
304
  };
@@ -276,9 +353,9 @@ export function serviceTypes(type) {
276
353
  }
277
354
 
278
355
  /**
279
- *
280
- * @param {ServiceType} type
281
- * @param {boolean} bundeledToo
356
+ *
357
+ * @param {ServiceType} type
358
+ * @param {boolean} bundeledToo
282
359
  * @returns {Array<Object>}
283
360
  */
284
361
  export function serviceTypeEndpoints(type, bundeledToo) {
@@ -26,7 +26,8 @@ import {
26
26
  addresses,
27
27
  networkAddressType,
28
28
  addType,
29
- FAMILY_IPV4_IPV6
29
+ FAMILY_IPV4_IPV6,
30
+ PROTOCOL_TCP
30
31
  } from "pmcf";
31
32
  import { yesno, writeLines } from "../utils.mjs";
32
33
  import {
@@ -797,7 +798,7 @@ export class bind extends CoreService {
797
798
  {
798
799
  family: FAMILY_IPV4_IPV6,
799
800
  port: 19521,
800
- protocol: "tcp",
801
+ protocol: PROTOCOL_TCP,
801
802
  pathname: "/",
802
803
  tls: false,
803
804
  kind: "loopback"
@@ -809,7 +810,7 @@ export class bind extends CoreService {
809
810
  {
810
811
  family: FAMILY_IPV4_IPV6,
811
812
  port: 953,
812
- protocol: "tcp",
813
+ protocol: PROTOCOL_TCP,
813
814
  tls: false,
814
815
  kind: "loopback"
815
816
  }
@@ -1,7 +1,8 @@
1
1
  import { join } from "node:path";
2
2
  import { default_collection_attribute_writable, asArray } from "pacc";
3
- import { addType, FAMILY_UNIX, FAMILY_IPV4_IPV6, CoreService } from "pmcf";
3
+ import { addType, CoreService } from "pmcf";
4
4
  import { writeLines } from "../utils.mjs";
5
+ import { FAMILY_UNIX, FAMILY_IPV4_IPV6, PROTOCOL_TCP } from "../constants.mjs";
5
6
 
6
7
  export class chrony extends CoreService {
7
8
  static attributes = {
@@ -22,7 +23,7 @@ export class chrony extends CoreService {
22
23
  {
23
24
  family: FAMILY_IPV4_IPV6,
24
25
  port: 323,
25
- protocol: "tcp",
26
+ protocol: PROTOCOL_TCP,
26
27
  tls: false
27
28
  },
28
29
  {
@@ -1,5 +1,6 @@
1
1
  import { FAMILY_IPV4 } from "ip-utilties";
2
- import { CoreService, addType, FAMILY_UNIX } from "pmcf";
2
+ import { CoreService, addType } from "pmcf";
3
+ import { FAMILY_UNIX, PROTOCOL_TCP } from "../constants.mjs";
3
4
 
4
5
  export class headscale extends CoreService {
5
6
  static service = {
@@ -11,21 +12,21 @@ export class headscale extends CoreService {
11
12
  {
12
13
  family: FAMILY_IPV4,
13
14
  port: 8080,
14
- protocol: "tcp",
15
+ protocol: PROTOCOL_TCP,
15
16
  tls: false
16
17
  },
17
18
  {
18
19
  description: "grpc",
19
20
  family: FAMILY_IPV4,
20
21
  port: 50443,
21
- protocol: "tcp",
22
+ protocol: PROTOCOL_TCP,
22
23
  tls: false
23
24
  },
24
25
  {
25
26
  description: "metrics debug",
26
27
  family: FAMILY_IPV4,
27
28
  port: 9090,
28
- protocol: "tcp",
29
+ protocol: PROTOCOL_TCP,
29
30
  tls: false
30
31
  }
31
32
  ]
@@ -1,8 +1,9 @@
1
1
  import { join } from "node:path";
2
2
  import { stringify } from "yaml";
3
3
  import { boolean_attribute_writable_true } from "pacc";
4
- import { CoreService, addType, FAMILY_IPV4_IPV6 } from "pmcf";
4
+ import { CoreService, addType } from "pmcf";
5
5
  import { writeLines, filterConfigurable } from "../utils.mjs";
6
+ import { FAMILY_IPV4_IPV6, PROTOCOL_TCP } from "../constants.mjs";
6
7
 
7
8
  export class influxdb extends CoreService {
8
9
  static attributes = {
@@ -18,7 +19,7 @@ export class influxdb extends CoreService {
18
19
  {
19
20
  family: FAMILY_IPV4_IPV6,
20
21
  port: 8086,
21
- protocol: "tcp",
22
+ protocol: PROTOCOL_TCP,
22
23
  tls: false,
23
24
  pathname: "/"
24
25
  }
@@ -20,9 +20,9 @@ import {
20
20
  Subnet,
21
21
  CoreService,
22
22
  Endpoint,
23
- sortDescendingByPriority,
24
- FAMILY_UNIX
23
+ sortDescendingByPriority
25
24
  } from "pmcf";
25
+ import { FAMILY_UNIX, PROTOCOL_TCP } from "../constants.mjs";
26
26
  import { writeLines } from "../utils.mjs";
27
27
 
28
28
  class kea_subnet extends Subnet {
@@ -102,7 +102,7 @@ export class kea extends CoreService {
102
102
  family: FAMILY_IPV4,
103
103
  kind: "loopback",
104
104
  port: 53001,
105
- protocol: "tcp",
105
+ protocol: PROTOCOL_TCP,
106
106
  tls: false
107
107
  }
108
108
  ]
@@ -113,7 +113,7 @@ export class kea extends CoreService {
113
113
  family: FAMILY_IPV4,
114
114
  port: 53003,
115
115
  pathname: "/",
116
- protocol: "tcp",
116
+ protocol: PROTOCOL_TCP,
117
117
  tls: false
118
118
  }
119
119
  ]
@@ -124,7 +124,7 @@ export class kea extends CoreService {
124
124
  family: FAMILY_IPV6,
125
125
  port: 53004,
126
126
  pathname: "/",
127
- protocol: "tcp",
127
+ protocol: PROTOCOL_TCP,
128
128
  tls: false
129
129
  }
130
130
  ]
@@ -172,6 +172,122 @@ export class kea extends CoreService {
172
172
 
173
173
  subnets = new Map();
174
174
 
175
+ listenInterfaces(family) {
176
+ return this.endpoints(
177
+ endpoint =>
178
+ endpoint.type === "dhcp" &&
179
+ endpoint.family === family &&
180
+ endpoint.networkInterface.kind !== "loopback" &&
181
+ endpoint.networkInterface.kind !== "tun"
182
+ ).map(endpoint => `${endpoint.networkInterface.name}/${endpoint.address}`);
183
+ }
184
+
185
+ commonConfig(family) {
186
+ const cfg = {
187
+ "interfaces-config": {
188
+ interfaces: this.listenInterfaces(`IPv${family}`)
189
+ },
190
+ "control-sockets": this.endpoints(`kea-control-dhcp${family}`).map(e =>
191
+ toSocket(e)
192
+ ),
193
+ "lease-database": {
194
+ type: "memfile",
195
+ "lfc-interval": 3600
196
+ },
197
+ "multi-threading": {
198
+ "enable-multi-threading": true,
199
+ "thread-pool-size": 2,
200
+ "packet-queue-size": 4
201
+ },
202
+ "expired-leases-processing": {
203
+ "reclaim-timer-wait-time": 10,
204
+ "flush-reclaimed-timer-wait-time": 25,
205
+ "hold-reclaimed-time": 3600,
206
+ "max-reclaim-leases": 100,
207
+ "max-reclaim-time": 250,
208
+ "unwarned-reclaim-cycles": 5
209
+ },
210
+ "hooks-libraries": [
211
+ /*{
212
+ library: "/usr/lib/kea/hooks/libdhcp_ddns_tuning.so"
213
+ },*/
214
+ {
215
+ library: "/usr/lib/kea/hooks/libdhcp_lease_cmds.so"
216
+ },
217
+ {
218
+ library: "/usr/lib/kea/hooks/libdhcp_ha.so",
219
+ parameters: {
220
+ "high-availability": [
221
+ {
222
+ "this-server-name": this.host.name,
223
+ mode: "hot-standby",
224
+ "heartbeat-delay": 60000,
225
+ "max-response-delay": 60000,
226
+ "max-ack-delay": 10000,
227
+ /*
228
+ "multi-threading": {
229
+ "enable-multi-threading": true,
230
+ "http-dedicated-listener": true,
231
+ "http-listener-threads": 2,
232
+ "http-client-threads": 2
233
+ },*/
234
+ peers: asArray(this.peers)
235
+ .sort(sortDescendingByPriority)
236
+ .reduce((a, kea) => {
237
+ if (!kea.host.isCluster) {
238
+ const ctrlAgentEndpoint = kea.endpoint(
239
+ `kea-ha-${family}`
240
+ );
241
+
242
+ if (ctrlAgentEndpoint) {
243
+ const i = a.length;
244
+ a.push({
245
+ name: kea.host.name,
246
+ role:
247
+ i === 0 ? "primary" : i > 1 ? "backup" : "standby",
248
+ url: ctrlAgentEndpoint.url,
249
+ "auto-failover": i <= 1
250
+ });
251
+ }
252
+ }
253
+ return a;
254
+ }, [])
255
+ }
256
+ ]
257
+ }
258
+ }
259
+ ],
260
+ "option-data": [
261
+ {
262
+ name: family == 4 ? "domain-name-servers" : "dns-servers",
263
+ data: asArray(
264
+ this.dnsServerEndpoints
265
+ .filter(
266
+ endpoint =>
267
+ endpoint.family === `IPv${family}` &&
268
+ addressType(endpoint.address) !== ADDRESS_TYPE_LOOPBACK
269
+ )
270
+ .map(endpoint => endpoint.address)
271
+ ).join(",")
272
+ },
273
+ {
274
+ name: "domain-search",
275
+ data: [...this.domains].join(",")
276
+ }
277
+ ]
278
+ };
279
+
280
+ for (const [path, attribute] of extendingAttributeIterator(
281
+ this.constructor,
282
+ attribute => attribute.configurable && this[attribute.name] !== undefined
283
+ )) {
284
+ const name = path.join(".");
285
+ cfg[name] = this[name];
286
+ }
287
+
288
+ return cfg;
289
+ }
290
+
175
291
  async *preparePackages(dir) {
176
292
  const ctrlAgentEndpoint = this.endpoint("kea-ha-4");
177
293
 
@@ -179,13 +295,9 @@ export class kea extends CoreService {
179
295
  return;
180
296
  }
181
297
 
182
- const network = this.network;
183
298
  const host = this.host;
184
299
  const source = host.owner;
185
- const name = host.name;
186
300
  const subnets = [...this.subnets.values()];
187
- const dnsServerEndpoints = this.dnsServerEndpoints;
188
- const packageData = await this.preparePackage(dir);
189
301
 
190
302
  const loggers = [
191
303
  {
@@ -199,150 +311,6 @@ export class kea extends CoreService {
199
311
  }
200
312
  ];
201
313
 
202
- const peers = this.peers;
203
-
204
- const commonConfig = family => {
205
- const cfg = {
206
- "interfaces-config": {
207
- interfaces: listenInterfaces(`IPv${family}`)
208
- },
209
- "control-sockets": this.endpoints(`kea-control-dhcp${family}`).map(e =>
210
- toSocket(e)
211
- ),
212
- "lease-database": {
213
- type: "memfile",
214
- "lfc-interval": 3600
215
- },
216
- "multi-threading": {
217
- "enable-multi-threading": true,
218
- "thread-pool-size": 2,
219
- "packet-queue-size": 4
220
- },
221
- "expired-leases-processing": {
222
- "reclaim-timer-wait-time": 10,
223
- "flush-reclaimed-timer-wait-time": 25,
224
- "hold-reclaimed-time": 3600,
225
- "max-reclaim-leases": 100,
226
- "max-reclaim-time": 250,
227
- "unwarned-reclaim-cycles": 5
228
- },
229
- "hooks-libraries": [
230
- /*{
231
- library: "/usr/lib/kea/hooks/libdhcp_ddns_tuning.so"
232
- },*/
233
- {
234
- library: "/usr/lib/kea/hooks/libdhcp_lease_cmds.so"
235
- },
236
- {
237
- library: "/usr/lib/kea/hooks/libdhcp_ha.so",
238
- parameters: {
239
- "high-availability": [
240
- {
241
- "this-server-name": name,
242
- mode: "hot-standby",
243
- "heartbeat-delay": 60000,
244
- "max-response-delay": 60000,
245
- "max-ack-delay": 10000,
246
- /*
247
- "multi-threading": {
248
- "enable-multi-threading": true,
249
- "http-dedicated-listener": true,
250
- "http-listener-threads": 2,
251
- "http-client-threads": 2
252
- },*/
253
- peers: asArray(peers)
254
- .sort(sortDescendingByPriority)
255
- .reduce((a, kea) => {
256
- if (!kea.host.isCluster) {
257
- const ctrlAgentEndpoint = kea.endpoint(
258
- `kea-ha-${family}`
259
- );
260
- if (ctrlAgentEndpoint) {
261
- const i = a.length;
262
- a.push({
263
- name: kea.host.name,
264
- role:
265
- i === 0
266
- ? "primary"
267
- : i > 1
268
- ? "backup"
269
- : "standby",
270
- url: ctrlAgentEndpoint.url,
271
- "auto-failover": i <= 1
272
- });
273
- }
274
- }
275
- return a;
276
- }, [])
277
- }
278
- ]
279
- }
280
- }
281
- ],
282
- "dhcp-ddns": dhcpServerDdns,
283
-
284
- loggers,
285
- "option-data": [
286
- {
287
- name: family == 4 ? "domain-name-servers" : "dns-servers",
288
- data: asArray(
289
- dnsServerEndpoints
290
- .filter(
291
- endpoint =>
292
- endpoint.family === `IPv${family}` &&
293
- addressType(endpoint.address) !== ADDRESS_TYPE_LOOPBACK
294
- )
295
- .map(endpoint => endpoint.address)
296
- ).join(",")
297
- },
298
- {
299
- name: "domain-search",
300
- data: [...this.domains].join(",")
301
- }
302
- ]
303
- };
304
-
305
- for (const [path, attribute] of extendingAttributeIterator(
306
- this.constructor,
307
- attribute =>
308
- attribute.configurable && this[attribute.name] !== undefined
309
- )) {
310
- const name = path.join(".");
311
-
312
- cfg[name] = this[name];
313
- }
314
-
315
- return cfg;
316
- };
317
-
318
- const toSocket = endpoint => {
319
- switch (endpoint.family) {
320
- case FAMILY_IPV4:
321
- case FAMILY_IPV6:
322
- return {
323
- "socket-type": "http",
324
- "socket-address": endpoint.address.hostname,
325
- "socket-port": endpoint.port,
326
- authentication: {
327
- type: "basic",
328
- realm: "Kea Control Agent",
329
- directory: "/etc/kea",
330
- clients: [
331
- {
332
- "user-file": "kea-api-user",
333
- "password-file": "kea-api-password"
334
- }
335
- ]
336
- }
337
- };
338
- case FAMILY_UNIX:
339
- return {
340
- "socket-type": FAMILY_UNIX,
341
- "socket-name": endpoint?.path
342
- };
343
- }
344
- };
345
-
346
314
  /*const ctrlAgent = {
347
315
  "Control-agent": {
348
316
  "http-host": ctrlAgentEndpoint.hostname,
@@ -360,7 +328,7 @@ export class kea extends CoreService {
360
328
  names.map(name => {
361
329
  return {
362
330
  name,
363
- "dns-servers": dnsServerEndpoints
331
+ "dns-servers": asArray(this.dnsServerEndpoints)
364
332
  .filter(
365
333
  endpoint =>
366
334
  endpoint.family === FAMILY_IPV4 &&
@@ -388,7 +356,6 @@ export class kea extends CoreService {
388
356
  subnets.map(s => s.prefix).map(prefix => reverseArpa(prefix))
389
357
  )
390
358
  },
391
-
392
359
  loggers
393
360
  }
394
361
  };
@@ -436,20 +403,9 @@ export class kea extends CoreService {
436
403
  })
437
404
  .sort((a, b) => a.hostname?.localeCompare(b.hostname));
438
405
 
439
- const listenInterfaces = family =>
440
- this.endpoints(
441
- endpoint =>
442
- endpoint.type === "dhcp" &&
443
- endpoint.family === family &&
444
- endpoint.networkInterface.kind !== "loopback" &&
445
- endpoint.networkInterface.kind !== "tun"
446
- ).map(
447
- endpoint => `${endpoint.networkInterface.name}/${endpoint.address}`
448
- );
449
-
450
406
  const dhcp4 = {
451
407
  Dhcp4: {
452
- ...commonConfig("4"),
408
+ ...this.commonConfig("4"),
453
409
  subnet4: subnets
454
410
  .filter(s => s.family === FAMILY_IPV4)
455
411
  .map((subnet, index) => {
@@ -461,16 +417,18 @@ export class kea extends CoreService {
461
417
  "option-data": [
462
418
  {
463
419
  name: "routers",
464
- data: network.gateway.address
420
+ data: this.network.gateway.address
465
421
  }
466
422
  ]
467
423
  };
468
- })
424
+ }),
425
+ "dhcp-ddns": dhcpServerDdns,
426
+ loggers
469
427
  }
470
428
  };
471
429
  const dhcp6 = {
472
430
  Dhcp6: {
473
- ...commonConfig("6"),
431
+ ...this.commonConfig("6"),
474
432
  subnet6: subnets
475
433
  .filter(s => s.family === FAMILY_IPV6)
476
434
  .map((subnet, index) => {
@@ -480,10 +438,14 @@ export class kea extends CoreService {
480
438
  pools: [{ pool: subnet.pool.join(" - ") }],
481
439
  reservations: reservations(subnet, "6")
482
440
  };
483
- })
441
+ }),
442
+ "dhcp-ddns": dhcpServerDdns,
443
+ loggers
484
444
  }
485
445
  };
486
446
 
447
+ const packageData = await this.preparePackage(dir);
448
+
487
449
  for (const [name, data] of Object.entries({
488
450
  "kea-dhcp-ddns": ddns,
489
451
  "kea-dhcp4": dhcp4,
@@ -500,3 +462,31 @@ export class kea extends CoreService {
500
462
  yield packageData;
501
463
  }
502
464
  }
465
+
466
+ function toSocket(endpoint) {
467
+ switch (endpoint.family) {
468
+ case FAMILY_IPV4:
469
+ case FAMILY_IPV6:
470
+ return {
471
+ "socket-type": "http",
472
+ "socket-address": endpoint.address.hostname,
473
+ "socket-port": endpoint.port,
474
+ authentication: {
475
+ type: "basic",
476
+ realm: "Kea Control Agent",
477
+ directory: "/etc/kea",
478
+ clients: [
479
+ {
480
+ "user-file": "kea-api-user",
481
+ "password-file": "kea-api-password"
482
+ }
483
+ ]
484
+ }
485
+ };
486
+ case FAMILY_UNIX:
487
+ return {
488
+ "socket-type": FAMILY_UNIX,
489
+ "socket-name": endpoint?.path
490
+ };
491
+ }
492
+ }
@@ -4,8 +4,9 @@ import {
4
4
  boolean_attribute_writable,
5
5
  integer_attribute_writable
6
6
  } from "pacc";
7
- import { CoreService, addType, FAMILY_IPV4_IPV6 } from "pmcf";
7
+ import { CoreService, addType } from "pmcf";
8
8
  import { filterConfigurable, sectionLines } from "../utils.mjs";
9
+ import { FAMILY_IPV4_IPV6, PROTOCOL_TCP } from "../constants.mjs";
9
10
 
10
11
  /**
11
12
  * @property {string} ServerCertificateFile
@@ -77,7 +78,7 @@ export class SystemdJournalRemoteService extends CoreService {
77
78
  {
78
79
  family: FAMILY_IPV4_IPV6,
79
80
  port: 19532,
80
- protocol: "tcp",
81
+ protocol: PROTOCOL_TCP,
81
82
  tls: false,
82
83
  pathname: "/"
83
84
  }
@@ -1,5 +1,6 @@
1
1
  import { FAMILY_IPV4 } from "ip-utilties";
2
2
  import { CoreService, addType } from "pmcf";
3
+ import { PROTOCOL_TCP } from "../constants.mjs";
3
4
 
4
5
  export class tailscale extends CoreService {
5
6
  static service = {
@@ -7,7 +8,7 @@ export class tailscale extends CoreService {
7
8
  {
8
9
  family: FAMILY_IPV4,
9
10
  port: 41641,
10
- protocol: "tcp",
11
+ protocol: PROTOCOL_TCP,
11
12
  tls: false
12
13
  }
13
14
  ]