@serve.zone/dcrouter 13.39.0 → 13.40.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.
@@ -91,7 +91,6 @@ export class RadiusServer {
91
91
  private vlanManager: VlanManager;
92
92
  private accountingManager: AccountingManager;
93
93
  private config: IRadiusServerConfig;
94
- private clientSecrets: Map<string, string> = new Map();
95
94
  private running: boolean = false;
96
95
 
97
96
  // Statistics
@@ -138,24 +137,18 @@ export class RadiusServer {
138
137
  await this.vlanManager.importMappings(this.config.vlanAssignment.mappings);
139
138
  }
140
139
 
141
- // Build client secrets map
142
- this.buildClientSecretsMap();
140
+ const cidrSecrets = this.buildClientSecretsMap();
143
141
 
144
142
  // Create the RADIUS server
145
143
  this.radiusServer = new plugins.smartradius.RadiusServer({
146
144
  authPort: this.config.authPort,
147
145
  acctPort: this.config.acctPort,
148
146
  bindAddress: this.config.bindAddress,
149
- secretResolver: this.resolveClientSecret.bind(this),
147
+ cidrSecrets,
150
148
  authenticationHandler: this.handleAuthentication.bind(this),
151
149
  accountingHandler: this.handleAccounting.bind(this),
152
150
  });
153
151
 
154
- // Configure per-client secrets
155
- for (const [ip, secret] of this.clientSecrets) {
156
- this.radiusServer.setClientSecret(ip, secret);
157
- }
158
-
159
152
  // Start the server
160
153
  await this.radiusServer.start();
161
154
 
@@ -204,6 +197,7 @@ export class RadiusServer {
204
197
  calledStationId: request.calledStationId,
205
198
  callingStationId: request.callingStationId,
206
199
  serviceType: request.serviceType !== undefined ? String(request.serviceType) : undefined,
200
+ framedMtu: request.framedMtu,
207
201
  };
208
202
 
209
203
  logger.log('debug', `RADIUS Auth Request: user=${authData.username}, NAS=${authData.nasIpAddress}`);
@@ -288,6 +282,8 @@ export class RadiusServer {
288
282
  outputPackets: request.outputPackets,
289
283
  sessionTime: request.sessionTime,
290
284
  terminateCause: request.terminateCause !== undefined ? String(request.terminateCause) : undefined,
285
+ framedIpAddress: request.framedIpAddress,
286
+ serviceType: request.serviceType !== undefined ? String(request.serviceType) : undefined,
291
287
  };
292
288
 
293
289
  try {
@@ -394,66 +390,18 @@ export class RadiusServer {
394
390
  /**
395
391
  * Build client secrets map from configuration
396
392
  */
397
- private buildClientSecretsMap(): void {
398
- this.clientSecrets.clear();
393
+ private buildClientSecretsMap(): Record<string, string> {
394
+ const cidrSecrets: Record<string, string> = {};
399
395
 
400
396
  for (const client of this.config.clients) {
401
397
  if (!client.enabled) {
402
398
  continue;
403
399
  }
404
400
 
405
- if (!client.ipRange.includes('/')) {
406
- this.clientSecrets.set(client.ipRange, client.secret);
407
- }
408
- }
409
- }
410
-
411
- private resolveClientSecret(clientAddress: string): string | undefined {
412
- const normalizedClientAddress = this.normalizeClientAddress(clientAddress);
413
- if (!normalizedClientAddress) return undefined;
414
-
415
- const exactSecret = this.clientSecrets.get(normalizedClientAddress);
416
- if (exactSecret !== undefined) return exactSecret;
417
-
418
- for (const client of this.config.clients) {
419
- if (!client.enabled || !client.ipRange.includes('/')) continue;
420
- if (this.clientIpMatchesCidr(normalizedClientAddress, client.ipRange)) return client.secret;
401
+ cidrSecrets[client.ipRange] = client.secret;
421
402
  }
422
403
 
423
- return undefined;
424
- }
425
-
426
- private normalizeClientAddress(clientAddress: string): string | undefined {
427
- const trimmedAddress = clientAddress.trim();
428
- const normalizedAddress = trimmedAddress.startsWith('::ffff:')
429
- ? trimmedAddress.slice('::ffff:'.length)
430
- : trimmedAddress;
431
- return plugins.net.isIP(normalizedAddress) ? normalizedAddress : undefined;
432
- }
433
-
434
- private clientIpMatchesCidr(clientAddress: string, cidr: string): boolean {
435
- const [networkAddress, rawPrefix] = cidr.trim().split('/');
436
- const normalizedNetworkAddress = this.normalizeClientAddress(networkAddress || '');
437
- if (!normalizedNetworkAddress || rawPrefix === undefined) return false;
438
-
439
- const clientIp = this.ipv4ToNumber(clientAddress);
440
- const networkIp = this.ipv4ToNumber(normalizedNetworkAddress);
441
- if (clientIp === undefined || networkIp === undefined) return false;
442
-
443
- const prefix = Number(rawPrefix);
444
- if (!Number.isInteger(prefix) || prefix < 0 || prefix > 32) return false;
445
-
446
- const mask = prefix === 0 ? 0 : (0xffffffff << (32 - prefix)) >>> 0;
447
- return ((clientIp & mask) >>> 0) === ((networkIp & mask) >>> 0);
448
- }
449
-
450
- private ipv4ToNumber(ipAddress: string): number | undefined {
451
- if (plugins.net.isIP(ipAddress) !== 4) return undefined;
452
- const parts = ipAddress.split('.').map((part) => Number(part));
453
- if (parts.length !== 4 || parts.some((part) => !Number.isInteger(part) || part < 0 || part > 255)) {
454
- return undefined;
455
- }
456
- return (((parts[0] * 256 + parts[1]) * 256 + parts[2]) * 256 + parts[3]) >>> 0;
404
+ return cidrSecrets;
457
405
  }
458
406
 
459
407
  /**
@@ -462,16 +410,20 @@ export class RadiusServer {
462
410
  async addClient(client: IRadiusClient): Promise<void> {
463
411
  // Check if client already exists
464
412
  const existingIndex = this.config.clients.findIndex(c => c.name === client.name);
413
+ const previousClient = existingIndex >= 0 ? this.config.clients[existingIndex] : undefined;
465
414
  if (existingIndex >= 0) {
466
415
  this.config.clients[existingIndex] = client;
467
416
  } else {
468
417
  this.config.clients.push(client);
469
418
  }
470
419
 
471
- this.buildClientSecretsMap();
472
-
473
- if (this.running && this.radiusServer && client.enabled && !client.ipRange.includes('/')) {
474
- this.radiusServer.setClientSecret(client.ipRange, client.secret);
420
+ if (this.running && this.radiusServer) {
421
+ if (previousClient) {
422
+ this.radiusServer.removeNetworkSecret(previousClient.ipRange);
423
+ }
424
+ if (client.enabled) {
425
+ this.radiusServer.setNetworkSecret(client.ipRange, client.secret);
426
+ }
475
427
  }
476
428
 
477
429
  logger.log('info', `RADIUS client ${client.enabled ? 'added' : 'disabled'}: ${client.name} (${client.ipRange})`);
@@ -486,10 +438,8 @@ export class RadiusServer {
486
438
  const client = this.config.clients[index];
487
439
  this.config.clients.splice(index, 1);
488
440
 
489
- this.buildClientSecretsMap();
490
-
491
- if (this.radiusServer && !client.ipRange.includes('/')) {
492
- this.radiusServer.removeClientSecret(client.ipRange);
441
+ if (this.radiusServer) {
442
+ this.radiusServer.removeNetworkSecret(client.ipRange);
493
443
  }
494
444
 
495
445
  logger.log('info', `RADIUS client removed: ${name}`);
@@ -3,6 +3,6 @@
3
3
  */
4
4
  export const commitinfo = {
5
5
  name: '@serve.zone/dcrouter',
6
- version: '13.39.0',
6
+ version: '13.40.0',
7
7
  description: 'A multifaceted routing service handling mail and SMS delivery functions.'
8
8
  }