net-snmp 3.13.2 → 3.14.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/README.md CHANGED
@@ -3403,6 +3403,10 @@ Example programs are included under the module's `example` directory.
3403
3403
 
3404
3404
  * Fix AgentX signed integer writing
3405
3405
 
3406
+ ## Version 3.14.0 - 10/09/2024
3407
+
3408
+ * Add support for SMIv1 defined types and TRAP-TYPE SMIv1 macro
3409
+
3406
3410
  # License
3407
3411
 
3408
3412
  Copyright (c) 2020 Mark Abrahams <mark@abrahams.co.nz>
package/index.js CHANGED
@@ -3206,6 +3206,7 @@ ModuleStore.prototype.getSyntaxTypes = function () {
3206
3206
  for ( var mibModule of Object.values (this.parser.Modules) ) {
3207
3207
  entryArray = Object.values (mibModule);
3208
3208
  for ( var mibEntry of entryArray ) {
3209
+ // SMIv2 Textual Conventions
3209
3210
  if ( mibEntry.MACRO == "TEXTUAL-CONVENTION" ) {
3210
3211
  if ( mibEntry.SYNTAX && ! syntaxTypes[mibEntry.ObjectName] ) {
3211
3212
  if ( typeof mibEntry.SYNTAX == "object" ) {
@@ -3214,6 +3215,13 @@ ModuleStore.prototype.getSyntaxTypes = function () {
3214
3215
  syntaxTypes[mibEntry.ObjectName] = syntaxTypes[mibEntry.SYNTAX];
3215
3216
  }
3216
3217
  }
3218
+ // SMIv1 Defined Types
3219
+ } else if ( ! mibEntry.OID && ! syntaxTypes[mibEntry.ObjectName] ) {
3220
+ if ( mibEntry.SYNTAX ) {
3221
+ syntaxTypes[mibEntry.ObjectName] = mibEntry.SYNTAX;
3222
+ } else {
3223
+ syntaxTypes[mibEntry.ObjectName] = syntaxTypes[mibEntry.MACRO];
3224
+ }
3217
3225
  }
3218
3226
  }
3219
3227
  }
package/lib/mib.js CHANGED
@@ -349,21 +349,26 @@ var MIB = function (dir) {
349
349
  let unresolvedObjects = [];
350
350
  for (var i = 0; i < Symbols.length; i++) {
351
351
  switch (Symbols[i]) {
352
- case '::=': //new OBJECT to define
353
- //if OBJECT IDENTIFIER tag IS NEXT, FIND MARCO TO CALL...
354
- if (Symbols[i + 1].indexOf('{') == 0) {
355
- var r = i - 1;
356
- var found = false;
357
- //Go back and find the MACRO to call
358
- while (!found && r > 0) {
359
- r--;
352
+ case '::=': // new OBJECT or SMIv1 TRAP-TYPE to define
353
+ // if an object assignment list is next, the next symbol is a '{' for the integer list
354
+ const isObjectIdentifierAssignment = Symbols[i + 1].indexOf('{') == 0;
355
+ // iff it is a TRAP-TYPE macro (SMIv1), the next symbol is an integer
356
+ const isTrapTypeDefinition = Number.isInteger(Number.parseInt(Symbols[i + 1]));
357
+ // Object assigment or trap type definition
358
+ if ( isObjectIdentifierAssignment || isTrapTypeDefinition ) {
359
+ let macroIndex = i - 1;
360
+ let found = false;
361
+ // Go back and find the index position of the macro
362
+ while ( ! found && macroIndex > 0) {
363
+ macroIndex--;
360
364
  for (var m = 0; m < this.MACROS.length; m++) {
361
- if (Symbols[r] == this.MACROS[m]) {
365
+ if (Symbols[macroIndex] == this.MACROS[m]) {
362
366
  found = true;
363
367
  break;
364
368
  }
365
369
  }
366
370
  }
371
+ // Internal MIB node assignment is marked by an 'OBJECT IDENTIFIER' tag before the ::=
367
372
  if (Symbols[i - 1] == 'OBJECT IDENTIFIER') {
368
373
  Object[Symbols[i - 2]] = {};
369
374
  Object[Symbols[i - 2]]['ObjectName'] = Symbols[i - 2];
@@ -384,44 +389,37 @@ var MIB = function (dir) {
384
389
  // Object[Symbols[i - 2]]['ModuleName'] = ModuleName;
385
390
  // Object[Symbols[i - 2]]['ObjectName'] = Symbols[i - 2];
386
391
  }
387
-
392
+ // Leaf MIB node assignments have a macro, as do TRAP-TYPE definitions
388
393
  } else {
389
- var ObjectName = Symbols[r - 1];
394
+ const ObjectName = Symbols[macroIndex - 1];
390
395
  Object[ObjectName] = {};
391
396
  Object[ObjectName]['ObjectName'] = ObjectName;
392
397
  Object[ObjectName]['ModuleName'] = ModuleName;
393
- Object[ObjectName]['MACRO'] = Symbols[r];
394
- //BUILD OBJECT FROM MACRO TYPE NOTATION
395
- var MARCO = this[Symbols[r]];
396
- if (!MARCO) {
397
- //HACK IF MARCO IS NOT FOUND
398
- //MARCO = {};
399
- //return;
400
- }
401
- var c1 = r;
402
- var keychain = [];
398
+ Object[ObjectName]['MACRO'] = Symbols[macroIndex];
399
+ // Build MACRO object from TYPE NOTATION
400
+ const MACRO = this[Symbols[macroIndex]];
401
+ let c1 = macroIndex;
402
+ const keychain = [];
403
403
  keychain.push('DESCRIPTION');
404
- var key;
405
- for (var notation in MARCO['TYPE NOTATION']) {
404
+ let key;
405
+ for (let notation in MACRO['TYPE NOTATION']) {
406
406
  key = notation;
407
- //if TYPE NOTATION does not have a value
408
- if (MARCO['TYPE NOTATION'][notation] == null) {
409
- //then look up the value from the MACRO Root
410
- key = MARCO[notation]['MACRO'].replace(/"/g, '');
407
+ // If TYPE NOTATION does not have a value
408
+ if (MACRO['TYPE NOTATION'][notation] == null) {
409
+ // Then look up the value from the MACRO Root
410
+ key = MACRO[notation]['MACRO'].replace(/"/g, '');
411
411
  }
412
412
  keychain.push(key);
413
413
  }
414
414
  while (c1 < (i - 1)) {
415
415
  c1++;
416
- key = Symbols[c1]; //Parse TYPE NOTATION. ex: SYNTAX, ACCESS, STATUS, DESCRIPTION.....
417
-
418
- //key == 'DESCRIPTION' ? console.log(keychain.indexOf(key), key, Symbols[c1 + 1]) : false;
416
+ key = Symbols[c1]; // Parse TYPE NOTATION. ex: SYNTAX, ACCESS, STATUS, DESCRIPTION.....
419
417
 
420
- var regExp = /\(([^)]+)\)/; //in parentheses ex: "ethernet-csmacd (6)"
418
+ const regExp = /\(([^)]+)\)/; // in parentheses e.g. "ethernet-csmacd (6)"
421
419
 
422
420
  if (keychain.indexOf(key) > -1 || key == 'REVISION') {
423
- var val = Symbols[c1 + 1].replace(/"/g, "");
424
- //if value array.
421
+ let val = Symbols[c1 + 1].replace(/"/g, "");
422
+ // if value array
425
423
  if (val.indexOf("{") == 0) {
426
424
  c1++;
427
425
  while (Symbols[c1].indexOf("}") == -1) {
@@ -433,7 +431,7 @@ var MIB = function (dir) {
433
431
  val = val.replace(/^{/, '').replace(/}$/, '').trim();
434
432
  } else {
435
433
  // build value array
436
- val = val.replace("{", "").replace("}", "").split(",");
434
+ val = val.replace("{", "").replace("}", "").split(",").map( (v) => v.trim() );
437
435
  }
438
436
  }
439
437
 
@@ -529,32 +527,34 @@ var MIB = function (dir) {
529
527
 
530
528
 
531
529
  }
532
- Object[Symbols[r - 1]]['ObjectName'] = Symbols[r - 1];
533
- Object[Symbols[r - 1]]['ModuleName'] = ModuleName;
534
- Object[Symbols[r - 1]]['OBJECT IDENTIFIER'] = Symbols[i + 1].replace("{", "").replace("}", "").trim().replace(/\s+/, " ");
535
-
536
- if (Object[Symbols[r - 1]]['OBJECT IDENTIFIER'] == '0 0') {
537
- Object[Symbols[r - 1]]['OID'] = '0.0';
538
- Object[Symbols[r - 1]]['NameSpace'] = 'null';
539
- } else {
540
- const { oidString, nameString, unresolvedObject } = this.getOidAndNamePaths(Object[Symbols[r - 1]]['OBJECT IDENTIFIER'], Symbols[r - 1], ModuleName);
541
- Object[Symbols[r - 1]]['OID'] = oidString;
542
- Object[Symbols[r - 1]]['NameSpace'] = nameString;
543
- if (unresolvedObject) {
544
- if ( ! unresolvedObjects.includes(unresolvedObject) ) {
545
- unresolvedObjects.push(unresolvedObject);
530
+ Object[Symbols[macroIndex - 1]]['ObjectName'] = Symbols[macroIndex - 1];
531
+ Object[Symbols[macroIndex - 1]]['ModuleName'] = ModuleName;
532
+ if ( isObjectIdentifierAssignment ) {
533
+ Object[Symbols[macroIndex - 1]]['OBJECT IDENTIFIER'] = Symbols[i + 1].replace("{", "").replace("}", "").trim().replace(/\s+/, " ");
534
+ if (Object[Symbols[macroIndex - 1]]['OBJECT IDENTIFIER'] == '0 0') {
535
+ Object[Symbols[macroIndex - 1]]['OID'] = '0.0';
536
+ Object[Symbols[macroIndex - 1]]['NameSpace'] = 'null';
537
+ } else {
538
+ const { oidString, nameString, unresolvedObject } = this.getOidAndNamePaths(Object[Symbols[macroIndex - 1]]['OBJECT IDENTIFIER'], Symbols[macroIndex - 1], ModuleName);
539
+ Object[Symbols[macroIndex - 1]]['OID'] = oidString;
540
+ Object[Symbols[macroIndex - 1]]['NameSpace'] = nameString;
541
+ if (unresolvedObject) {
542
+ if ( ! unresolvedObjects.includes(unresolvedObject) ) {
543
+ unresolvedObjects.push(unresolvedObject);
544
+ }
546
545
  }
547
546
  }
547
+ } else if ( isTrapTypeDefinition ) {
548
+ Object[Symbols[macroIndex - 1]]['VALUE'] = Number.parseInt(Symbols[i + 1]);
548
549
  }
549
- if ( Object[Symbols[r - 1]]['REVISIONS-DESCRIPTIONS'] &&
550
- Object[Symbols[r - 1]]['REVISIONS-DESCRIPTIONS'].length == 1 &&
551
- Object[Symbols[r - 1]]['REVISIONS-DESCRIPTIONS'][0]['type'] == 'DESCRIPTION' ) {
552
- delete Object[Symbols[r - 1]]['REVISIONS-DESCRIPTIONS'];
550
+ if ( Object[Symbols[macroIndex - 1]]['REVISIONS-DESCRIPTIONS'] &&
551
+ Object[Symbols[macroIndex - 1]]['REVISIONS-DESCRIPTIONS'].length == 1 &&
552
+ Object[Symbols[macroIndex - 1]]['REVISIONS-DESCRIPTIONS'][0]['type'] == 'DESCRIPTION' ) {
553
+ delete Object[Symbols[macroIndex - 1]]['REVISIONS-DESCRIPTIONS'];
553
554
  }
554
-
555
555
  }
556
+ // if object assignment list is not next, check prior symbol for processing instructions / macro creation
556
557
  } else {
557
- //if OBJECT IDENTIFIER tag is NOT NEXT, check prior symbol for processing instructions / MARCO creation.
558
558
  switch (Symbols[i - 1]) {
559
559
  case 'DEFINITIONS':
560
560
  break;
@@ -596,10 +596,10 @@ var MIB = function (dir) {
596
596
  Object["TYPE NOTATION"].INDEX = "Index";
597
597
  Object["TYPE NOTATION"].ACCESS = "Access";
598
598
  }
599
- // End INDEX/AUGMENTS workaround
599
+ // End INDEX/AUGMENTS/ACCESS workaround
600
600
  break;
601
601
  default:
602
- //new object
602
+ // New object
603
603
  Object[Symbols[i - 1]] = {};
604
604
  Object[Symbols[i - 1]]['ObjectName'] = Symbols[i - 1];
605
605
  Object[Symbols[i - 1]]['ModuleName'] = ModuleName;
@@ -611,18 +611,16 @@ var MIB = function (dir) {
611
611
  break;
612
612
  case 'END':
613
613
  if (MACROName != '') {
614
- //ADD macros to root for easier processing
615
- //Still need Import feature
614
+ // Add macros to root for easier processing
615
+ // Still need Import feature
616
616
  this[MACROName] = Object;
617
617
  this.MACROS.push(MACROName);
618
618
  }
619
- //reset Object to Module root;
619
+ // Reset Object to Module root;
620
620
  Object = Module;
621
621
  MACROName = '';
622
622
  break;
623
623
  case 'IMPORTS':
624
- //console.log(ModuleName, 'IMPORTS');
625
- //i++;
626
624
  Module['IMPORTS'] = {};
627
625
  var tmp = i + 1;
628
626
  var IMPORTS = [];
@@ -644,7 +642,9 @@ var MIB = function (dir) {
644
642
  //console.log(ModuleName, 'IMPORTS', Module['IMPORTS']);
645
643
  break;
646
644
  case 'EXPORTS':
647
- //console.log(ModuleName, 'EXPORTS');
645
+ // EXPORTS only appears for SMIv1 once: in RFC1155-SMI - where it exports everything
646
+ // EXPORTS are forbidden for SMIv2 in RFC2578 section 3.3, as all objects are exported by default
647
+ // Therefore, we ignore EXPORTS for both SMIv1 and SMIv2
648
648
  break;
649
649
  default:
650
650
  break;
@@ -652,7 +652,7 @@ var MIB = function (dir) {
652
652
 
653
653
 
654
654
  }
655
- // attempt OID/namespace reconstruction for unresolved objects, as parsing has finished
655
+ // Attempt OID/namespace reconstruction for unresolved objects, as parsing has finished
656
656
  if (unresolvedObjects.length > 0) {
657
657
  for (const unresolved of unresolvedObjects) {
658
658
  const obj = this.Modules[ModuleName][unresolved];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "net-snmp",
3
- "version": "3.13.2",
3
+ "version": "3.14.0",
4
4
  "description": "JavaScript implementation of the Simple Network Management Protocol (SNMP)",
5
5
  "main": "index.js",
6
6
  "directories": {