pmcf 2.10.2 → 2.10.4

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": "2.10.2",
3
+ "version": "2.10.4",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/src/host.mjs CHANGED
@@ -564,6 +564,14 @@ export class NetworkInterface extends Base {
564
564
  return this.rawAddresses[0];
565
565
  }
566
566
 
567
+ get rawIPv4Address() {
568
+ return this.rawAddresses.filter(a=>isIPv4Address(a))[0];
569
+ }
570
+
571
+ get rawIPv6Address() {
572
+ return this.rawAddresses.filter(a=>isIPv6Address(a))[0];
573
+ }
574
+
567
575
  get rawAddresses() {
568
576
  return [...this._ipAddresses].map(([address]) => address);
569
577
  }
@@ -60,11 +60,6 @@ export class DHCPService extends Service {
60
60
  };
61
61
 
62
62
  const commonConfig = {
63
- "interfaces-config": {
64
- interfaces: [...host.networkInterfaces.values()]
65
- .filter(ni => ni.kind !== "loopback")
66
- .map(ni => `${ni.name}/${ni.rawAddress}`)
67
- },
68
63
  "lease-database": {
69
64
  type: "memfile",
70
65
  "lfc-interval": 3600
@@ -179,6 +174,11 @@ export class DHCPService extends Service {
179
174
  const dhcp4 = {
180
175
  Dhcp4: {
181
176
  ...commonConfig,
177
+ "interfaces-config": {
178
+ interfaces: [...host.networkInterfaces.values()]
179
+ .filter(ni => ni.kind !== "loopback")
180
+ .map(ni => `${ni.name}/${ni.rawIPv4Address}`)
181
+ },
182
182
  "multi-threading": {
183
183
  "enable-multi-threading": false
184
184
  },
@@ -218,6 +218,11 @@ export class DHCPService extends Service {
218
218
  const dhcp6 = {
219
219
  Dhcp6: {
220
220
  ...commonConfig,
221
+ "interfaces-config": {
222
+ interfaces: [...host.networkInterfaces.values()]
223
+ .filter(ni => ni.kind !== "loopback")
224
+ .map(ni => `${ni.name}/${ni.rawIPv6Address}`)
225
+ },
221
226
  "control-socket": {
222
227
  "socket-type": "unix",
223
228
  "socket-name": "/run/kea/6-ctrl-socket"
package/src/subnet.mjs CHANGED
@@ -2,7 +2,8 @@ import {
2
2
  normalizeCIDR,
3
3
  isLinkLocal,
4
4
  isIPv4Address,
5
- isIPv6Address
5
+ isIPv6Address,
6
+ addressWithPrefixLength
6
7
  } from "./utils.mjs";
7
8
  import { Base } from "./base.mjs";
8
9
  import { addType } from "./types.mjs";
@@ -62,23 +63,14 @@ export class Subnet extends Base {
62
63
  }
63
64
 
64
65
  get addressRange() {
65
- const l = this.prefixLength;
66
- return l === 24
67
- ? [this.prefix + ".0", this.prefix + ".255"]
68
- : [this.prefix + ".0.0", this.prefix + ".255.255"];
66
+ return [
67
+ addressWithPrefixLength(this.prefix, this.prefixLength),
68
+ this.prefix + ".255".repeat((32 - this.prefixLength) / 8)
69
+ ];
69
70
  }
70
71
 
71
72
  get longPrefix() {
72
- const prefix = this.prefix;
73
-
74
- switch (this.prefixLength) {
75
- case 24:
76
- return prefix + ".0";
77
- case 16:
78
- return prefix + ".0.0";
79
- }
80
-
81
- return prefix;
73
+ return addressWithPrefixLength(this.prefix, this.prefixLength);
82
74
  }
83
75
 
84
76
  get prefix() {
package/src/utils.mjs CHANGED
@@ -143,6 +143,15 @@ const ipv6 = {
143
143
  base: 16
144
144
  };
145
145
 
146
+ export function addressWithPrefixLength(address, prefixLength) {
147
+ const definition = ipv4;
148
+
149
+ return (
150
+ address +
151
+ ".0".repeat((definition.length - prefixLength) / definition.segmentLength)
152
+ );
153
+ }
154
+
146
155
  function _decode(definition, address, length = definition.length) {
147
156
  if (typeof address === "string") {
148
157
  return address;
package/types/host.d.mts CHANGED
@@ -430,6 +430,8 @@ export class NetworkInterface extends Base {
430
430
  set ipAddresses(value: Map<any, any>);
431
431
  get ipAddresses(): Map<any, any>;
432
432
  get rawAddress(): any;
433
+ get rawIPv4Address(): any;
434
+ get rawIPv6Address(): any;
433
435
  get rawAddresses(): any[];
434
436
  get cidrAddress(): any;
435
437
  get cidrAddresses(): any[];
package/types/utils.d.mts CHANGED
@@ -11,6 +11,7 @@ export function isIPv6Address(address: any): boolean;
11
11
  export function isLinkLocal(address: any): boolean;
12
12
  export function isLocalhost(address: any): boolean;
13
13
  export function normalizeIPAddress(address: any): any;
14
+ export function addressWithPrefixLength(address: any, prefixLength: any): string;
14
15
  export function _encode(definition: any, address: any): any;
15
16
  export function decodeIPv6(address: any, length: any): string;
16
17
  export function encodeIPv6(address: any): any;