net-snmp 3.11.2 → 3.12.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.
Files changed (3) hide show
  1. package/README.md +23 -13
  2. package/index.js +61 -38
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -67,11 +67,11 @@ for each shown in this table:
67
67
 
68
68
  | Application | Common Use | Documentation |
69
69
  | ----------- | ---------- | ------------- |
70
- | Command Generator | NMS / SNMP tools | [Using This Module: Command & Notification Generator](#using-this-module-command--notification-generator) |
71
- | Command Responder | SNMP agents | [Using This Module: SNMP Agent](#using-this-module-snmp-agent) |
72
- | Notification Originator | SNMP agents / NMS-to-NMS notifications | [Using This Module: Command & Notification Generator](#using-this-module-command--notification-generator) |
73
- | Notification Receiver | NMS | [Using This Module: Notification Receiver](#using-this-module-notification-receiver) |
74
- | Proxy Forwarder | SNMP agents | [Forwarder Module](#forwarder-module) |
70
+ | Command Generator | NMS / SNMP tools | [Application: Command & Notification Generator](#application-command--notification-generator) |
71
+ | Command Responder | SNMP agents | [Application: SNMP Agent](#application-snmp-agent) |
72
+ | Notification Originator | SNMP agents / NMS-to-NMS notifications | [Application: Command & Notification Generator](#application-command--notification-generator) |
73
+ | Notification Receiver | NMS | [Application: Notification Receiver](#application-notification-receiver) |
74
+ | Proxy Forwarder | SNMP agents | [Agent Forwarder Module](#agent-forwarder-module) |
75
75
 
76
76
  # Features
77
77
 
@@ -531,7 +531,7 @@ then it will produce a `ProcessingError` containing:
531
531
  * a `buffer` containing the packet contents, and
532
532
  * an `error` containing the original error encountered during processing.
533
533
 
534
- # Using This Module: Command & Notification Generator
534
+ # Application: Command & Notification Generator
535
535
 
536
536
  This library provides a `Session` class to provide support for building
537
537
  "Command Generator" and "Notification Originator" SNMP applications.
@@ -1448,7 +1448,7 @@ var maxRepetitions = 20;
1448
1448
  session.walk (oid, maxRepetitions, feedCb, doneCb);
1449
1449
  ```
1450
1450
 
1451
- # Using This Module: Notification Receiver
1451
+ # Application: Notification Receiver
1452
1452
 
1453
1453
  RFC 3413 classifies a "Notification Receiver" SNMP application that receives
1454
1454
  "Notification-Class" PDUs. Notifications include both SNMP traps and informs.
@@ -1510,6 +1510,9 @@ an object, possibly empty, and can contain the following fields:
1510
1510
  addresses
1511
1511
  * `includeAuthentication` - adds the community (v1/2c) or user name (v3) information
1512
1512
  to the notification callback - defaults to `false`
1513
+ * `sockets` - an array of objects containing triples of `transport`, `address` and `port` that
1514
+ can be used to specify multiple socket listeners. This option overrides any individual
1515
+ `transport`, `address` and `port` options.
1513
1516
 
1514
1517
  The `callback` parameter is a callback function of the form
1515
1518
  `function (error, notification)`. On an error condition, the `notification`
@@ -1555,7 +1558,7 @@ to the receiver. See the `Authorizer` section for further details.
1555
1558
 
1556
1559
  Closes the receiver's listening socket, ending the operation of the receiver.
1557
1560
 
1558
- # Using This Module: SNMP Agent
1561
+ # Application: SNMP Agent
1559
1562
 
1560
1563
  The SNMP agent responds to all four "request class" PDUs relevant to a Command Responder
1561
1564
  application:
@@ -1565,7 +1568,7 @@ application:
1565
1568
  * **GetBulkRequest** - request a series of "next" OID instances in the MIB tree
1566
1569
  * **SetRequest** - set values for specified OIDs
1567
1570
 
1568
- The agent sends a **GetResponse** PDU to all four request PDU types, in conformance to RFC 3416.
1571
+ The agent sends a **GetResponse** PDU to all four request PDU types, in conformance with RFC 3416.
1569
1572
 
1570
1573
  The agent - like the notification receiver - maintains an `Authorizer` instance
1571
1574
  to control access to the agent, details of which are in the [Authorizer Module](#authorizer-module)
@@ -1625,6 +1628,9 @@ an object, possibly empty, and can contain the following fields:
1625
1628
  * `transport` - the transport family to use - defaults to `udp4`
1626
1629
  * `address` - the IP address to bind to - default to `null`, which means bind to all IP
1627
1630
  addresses
1631
+ * `sockets` - an array of objects containing triples of `transport`, `address` and `port` that
1632
+ can be used to specify multiple socket listeners. This option overrides any individual
1633
+ `transport`, `address` and `port` options.
1628
1634
 
1629
1635
  The `mib` parameter is optional, and sets the agent's singleton `Mib` instance.
1630
1636
  If not supplied, the agent creates itself a new empty `Mib` singleton. If supplied,
@@ -2391,7 +2397,7 @@ methods `Mib.setScalarDefaultValue` and `Mib.setTableRowDefaultValues`
2391
2397
  may be used to conveniently add defaults after the MIB files are
2392
2398
  loaded.
2393
2399
 
2394
- # Using This Module: Module Store
2400
+ # Application: Module Store
2395
2401
 
2396
2402
  The library supports MIB parsing by providing an interface to a `ModuleStore` instance into which
2397
2403
  you can load MIB modules from files, and fetch the resulting JSON MIB module representations.
@@ -2501,7 +2507,7 @@ var namedOid = store.translate ('1.3.6.1.2.1.1.1', snmp.OidFormat.path);
2501
2507
  => 'iso.org.dod.internet.mgmt.mib-2.system.sysDescr'
2502
2508
  ```
2503
2509
 
2504
- # Forwarder Module
2510
+ # Agent Forwarder Module
2505
2511
 
2506
2512
  An `Agent` instance, when created, in turn creates an instance of the `Forwarder` class.
2507
2513
  There is no direct API call to create a `Forwarder` instance; this creation is the
@@ -2523,7 +2529,7 @@ forwarder.addProxy({
2523
2529
  level: snmp.SecurityLevel.authNoPriv,
2524
2530
  authProtocol: snmp.AuthProtocols.sha,
2525
2531
  authKey: "quarryandgravel"
2526
- },
2532
+ }
2527
2533
  });
2528
2534
  ```
2529
2535
 
@@ -2577,7 +2583,7 @@ Returns an object containing a list of all registered proxies, keyed by context
2577
2583
 
2578
2584
  Prints a dump of all proxy definitions to the console.
2579
2585
 
2580
- # Using This Module: AgentX Subagent
2586
+ # Application: AgentX Subagent
2581
2587
 
2582
2588
  The AgentX subagent implements the functionality specified in RFC 2741 to become a "subagent"
2583
2589
  of an AgentX "master agent". The goal of AgentX is to extend the functionality of an existing
@@ -3371,6 +3377,10 @@ Example programs are included under the module's `example` directory.
3371
3377
 
3372
3378
  * Add provider to MIB request
3373
3379
 
3380
+ ## Version 3.12.0 - 28/06/2024
3381
+
3382
+ * Add multiple socket listener support for agent and receiver
3383
+
3374
3384
  # License
3375
3385
 
3376
3386
  Copyright (c) 2020 Mark Abrahams <mark@abrahams.co.nz>
package/index.js CHANGED
@@ -2709,7 +2709,7 @@ Session.prototype.onProxyResponse = function (req, message) {
2709
2709
  message.pdu.contextEngineID = message.msgSecurityParameters.msgAuthoritativeEngineID;
2710
2710
  message.pdu.contextName = this.proxy.context;
2711
2711
  message.pdu.id = req.proxiedPduId;
2712
- this.proxy.listener.send (message, req.proxiedRinfo);
2712
+ this.proxy.listener.send (message, req.proxiedRinfo, req.proxiedSocket);
2713
2713
  };
2714
2714
 
2715
2715
  Session.create = function (target, community, options) {
@@ -2765,27 +2765,50 @@ Engine.prototype.generateEngineID = function() {
2765
2765
  var Listener = function (options, receiver) {
2766
2766
  this.receiver = receiver;
2767
2767
  this.callback = receiver.onMsg;
2768
- this.family = options.transport || 'udp4';
2769
- this.port = options.port || 161;
2770
- this.address = options.address;
2768
+ // this.transport = options.transport || 'udp4';
2769
+ // this.port = options.port || 161;
2770
+ // this.address = options.address;
2771
2771
  this.disableAuthorization = options.disableAuthorization || false;
2772
+ if ( options.sockets ) {
2773
+ this.socketOptions = options.sockets;
2774
+ } else {
2775
+ this.socketOptions = [
2776
+ {
2777
+ transport: options.transport,
2778
+ address: options.address,
2779
+ port: options.port
2780
+ }
2781
+ ];
2782
+ }
2783
+ for ( const socketOption of this.socketOptions ) {
2784
+ socketOption.transport = socketOption.transport || 'udp4';
2785
+ socketOption.address = socketOption.address || null;
2786
+ socketOption.port = socketOption.port || 161;
2787
+ }
2772
2788
  };
2773
2789
 
2774
2790
  Listener.prototype.startListening = function () {
2775
2791
  var me = this;
2776
- this.dgram = dgram.createSocket (this.family);
2777
- this.dgram.on ("error", me.receiver.callback);
2778
- this.dgram.bind (this.port, this.address);
2779
- this.dgram.on ("message", me.callback.bind (me.receiver));
2792
+ this.sockets = {};
2793
+ for ( const socketOptions of this.socketOptions ) {
2794
+ const socket = dgram.createSocket (socketOptions.transport);
2795
+ socket.on ("error", me.receiver.callback);
2796
+ socket.bind (socketOptions.port, socketOptions.address);
2797
+ socket.on ("message", me.callback.bind (me.receiver, socket));
2798
+ const socketKey = socketOptions.transport + ':' + socketOptions.address + ':' + socketOptions.port;
2799
+ if ( this.sockets[socketKey] ) {
2800
+ throw new Error ("Duplicate socket exists for " + socketKey);
2801
+ }
2802
+ this.sockets[socketKey] = socket;
2803
+ }
2780
2804
  };
2781
2805
 
2782
- Listener.prototype.send = function (message, rinfo) {
2806
+ Listener.prototype.send = function (message, rinfo, socket) {
2783
2807
  // var me = this;
2784
2808
 
2785
2809
  var buffer = message.toBuffer ();
2786
2810
 
2787
- this.dgram.send (buffer, 0, buffer.length, rinfo.port, rinfo.address,
2788
- function (error, bytes) {
2811
+ socket.send (buffer, 0, buffer.length, rinfo.port, rinfo.address, function (error, bytes) {
2789
2812
  if (error) {
2790
2813
  // me.callback (error);
2791
2814
  console.error ("Error sending: " + error.message);
@@ -2803,7 +2826,7 @@ Listener.formatCallbackData = function (pdu, rinfo) {
2803
2826
  delete pdu.maxRepetitions;
2804
2827
  return {
2805
2828
  pdu: pdu,
2806
- rinfo: rinfo
2829
+ rinfo: rinfo
2807
2830
  };
2808
2831
  };
2809
2832
 
@@ -2857,8 +2880,8 @@ Listener.processIncoming = function (buffer, authorizer, callback) {
2857
2880
  };
2858
2881
 
2859
2882
  Listener.prototype.close = function () {
2860
- if ( this.dgram ) {
2861
- this.dgram.close ();
2883
+ for ( const socket of Object.values(this.sockets) ) {
2884
+ socket.close ();
2862
2885
  }
2863
2886
  };
2864
2887
 
@@ -3052,7 +3075,6 @@ SimpleAccessControlModel.prototype.isAccessAllowed = function (securityModel, se
3052
3075
 
3053
3076
  var Receiver = function (options, callback) {
3054
3077
  DEBUG = options.debug;
3055
- this.listener = new Listener (options, this);
3056
3078
  this.authorizer = new Authorizer (options);
3057
3079
  this.engine = new Engine (options.engineID);
3058
3080
 
@@ -3074,7 +3096,7 @@ Receiver.prototype.getAuthorizer = function () {
3074
3096
  return this.authorizer;
3075
3097
  };
3076
3098
 
3077
- Receiver.prototype.onMsg = function (buffer, rinfo) {
3099
+ Receiver.prototype.onMsg = function (socket, buffer, rinfo) {
3078
3100
 
3079
3101
  let message;
3080
3102
 
@@ -3102,7 +3124,7 @@ Receiver.prototype.onMsg = function (buffer, rinfo) {
3102
3124
  return;
3103
3125
  }
3104
3126
  let reportMessage = message.createReportResponseMessage (this.engine, this.context);
3105
- this.listener.send (reportMessage, rinfo);
3127
+ this.listener.send (reportMessage, rinfo, socket);
3106
3128
  return;
3107
3129
  }
3108
3130
 
@@ -3114,7 +3136,7 @@ Receiver.prototype.onMsg = function (buffer, rinfo) {
3114
3136
  message.pdu.type = PduType.GetResponse;
3115
3137
  message.buffer = null;
3116
3138
  message.setReportable (false);
3117
- this.listener.send (message, rinfo);
3139
+ this.listener.send (message, rinfo, socket);
3118
3140
  message.pdu.type = PduType.InformRequest;
3119
3141
  this.callback (null, this.formatCallbackData (message, rinfo) );
3120
3142
  } else {
@@ -4646,7 +4668,7 @@ Agent.prototype.tableRowStatusHandlerInternal = function (createRequest) {
4646
4668
  return missingDefVal ? undefined : values;
4647
4669
  };
4648
4670
 
4649
- Agent.prototype.onMsg = function (buffer, rinfo) {
4671
+ Agent.prototype.onMsg = function (socket, buffer, rinfo) {
4650
4672
 
4651
4673
  let message;
4652
4674
 
@@ -4665,22 +4687,22 @@ Agent.prototype.onMsg = function (buffer, rinfo) {
4665
4687
  if ( message.version == Version3 && message.pdu.type == PduType.GetRequest &&
4666
4688
  ! message.hasAuthoritativeEngineID() && message.isReportable () ) {
4667
4689
  let reportMessage = message.createReportResponseMessage (this.engine, this.context);
4668
- this.listener.send (reportMessage, rinfo);
4690
+ this.listener.send (reportMessage, rinfo, socket);
4669
4691
  return;
4670
4692
  }
4671
4693
 
4672
4694
  // Request processing
4673
4695
  // debug (JSON.stringify (message.pdu, null, 2));
4674
4696
  if ( message.pdu.contextName && message.pdu.contextName != "" ) {
4675
- this.onProxyRequest (message, rinfo);
4697
+ this.onProxyRequest (socket, message, rinfo);
4676
4698
  } else if ( message.pdu.type == PduType.GetRequest ) {
4677
- this.getRequest (message, rinfo);
4699
+ this.getRequest (socket, message, rinfo);
4678
4700
  } else if ( message.pdu.type == PduType.SetRequest ) {
4679
- this.setRequest (message, rinfo);
4701
+ this.setRequest (socket, message, rinfo);
4680
4702
  } else if ( message.pdu.type == PduType.GetNextRequest ) {
4681
- this.getNextRequest (message, rinfo);
4703
+ this.getNextRequest (socket, message, rinfo);
4682
4704
  } else if ( message.pdu.type == PduType.GetBulkRequest ) {
4683
- this.getBulkRequest (message, rinfo);
4705
+ this.getBulkRequest (socket, message, rinfo);
4684
4706
  } else {
4685
4707
  this.callback (new RequestInvalidError ("Unexpected PDU type " +
4686
4708
  message.pdu.type + " (" + PduType[message.pdu.type] + ")"));
@@ -4911,7 +4933,7 @@ Agent.prototype.isAllowed = function (pduType, provider, instanceNode) {
4911
4933
  }
4912
4934
  };
4913
4935
 
4914
- Agent.prototype.request = function (requestMessage, rinfo) {
4936
+ Agent.prototype.request = function (socket, requestMessage, rinfo) {
4915
4937
  var me = this;
4916
4938
  var varbindsCompleted = 0;
4917
4939
  var requestPdu = requestMessage.pdu;
@@ -5206,7 +5228,7 @@ Agent.prototype.request = function (requestMessage, rinfo) {
5206
5228
  }
5207
5229
  me.setSingleVarbind (responsePdu, savedIndex, responseVarbind);
5208
5230
  if ( ++varbindsCompleted == varbindsLength) {
5209
- me.sendResponse.call (me, rinfo, requestMessage, responsePdu);
5231
+ me.sendResponse.call (me, socket, rinfo, requestMessage, responsePdu);
5210
5232
  }
5211
5233
  };
5212
5234
  })(i);
@@ -5218,12 +5240,12 @@ Agent.prototype.request = function (requestMessage, rinfo) {
5218
5240
  }
5219
5241
  };
5220
5242
 
5221
- Agent.prototype.getRequest = function (requestMessage, rinfo) {
5222
- this.request (requestMessage, rinfo);
5243
+ Agent.prototype.getRequest = function (socket, requestMessage, rinfo) {
5244
+ this.request (socket, requestMessage, rinfo);
5223
5245
  };
5224
5246
 
5225
- Agent.prototype.setRequest = function (requestMessage, rinfo) {
5226
- this.request (requestMessage, rinfo);
5247
+ Agent.prototype.setRequest = function (socket, requestMessage, rinfo) {
5248
+ this.request (socket, requestMessage, rinfo);
5227
5249
  };
5228
5250
 
5229
5251
  Agent.prototype.addGetNextVarbind = function (targetVarbinds, startOid) {
@@ -5263,7 +5285,7 @@ Agent.prototype.addGetNextVarbind = function (targetVarbinds, startOid) {
5263
5285
  return getNextNode;
5264
5286
  };
5265
5287
 
5266
- Agent.prototype.getNextRequest = function (requestMessage, rinfo) {
5288
+ Agent.prototype.getNextRequest = function (socket, requestMessage, rinfo) {
5267
5289
  var requestPdu = requestMessage.pdu;
5268
5290
  var varbindsLength = requestPdu.varbinds.length;
5269
5291
  var getNextVarbinds = [];
@@ -5273,10 +5295,10 @@ Agent.prototype.getNextRequest = function (requestMessage, rinfo) {
5273
5295
  }
5274
5296
 
5275
5297
  requestMessage.pdu.varbinds = getNextVarbinds;
5276
- this.request (requestMessage, rinfo);
5298
+ this.request (socket, requestMessage, rinfo);
5277
5299
  };
5278
5300
 
5279
- Agent.prototype.getBulkRequest = function (requestMessage, rinfo) {
5301
+ Agent.prototype.getBulkRequest = function (socket, requestMessage, rinfo) {
5280
5302
  var requestPdu = requestMessage.pdu;
5281
5303
  var requestVarbinds = requestPdu.varbinds;
5282
5304
  var getBulkVarbinds = [];
@@ -5310,20 +5332,20 @@ Agent.prototype.getBulkRequest = function (requestMessage, rinfo) {
5310
5332
  }
5311
5333
 
5312
5334
  requestMessage.pdu.varbinds = getBulkVarbinds;
5313
- this.request (requestMessage, rinfo);
5335
+ this.request (socket, requestMessage, rinfo);
5314
5336
  };
5315
5337
 
5316
5338
  Agent.prototype.setSingleVarbind = function (responsePdu, index, responseVarbind) {
5317
5339
  responsePdu.varbinds[index] = responseVarbind;
5318
5340
  };
5319
5341
 
5320
- Agent.prototype.sendResponse = function (rinfo, requestMessage, responsePdu) {
5342
+ Agent.prototype.sendResponse = function (socket, rinfo, requestMessage, responsePdu) {
5321
5343
  var responseMessage = requestMessage.createResponseForRequest (responsePdu);
5322
- this.listener.send (responseMessage, rinfo);
5344
+ this.listener.send (responseMessage, rinfo, socket);
5323
5345
  this.callback (null, Listener.formatCallbackData (responseMessage.pdu, rinfo) );
5324
5346
  };
5325
5347
 
5326
- Agent.prototype.onProxyRequest = function (message, rinfo) {
5348
+ Agent.prototype.onProxyRequest = function (socket, message, rinfo) {
5327
5349
  var contextName = message.pdu.contextName;
5328
5350
  var proxy;
5329
5351
  var proxiedPduId;
@@ -5358,6 +5380,7 @@ Agent.prototype.onProxyRequest = function (message, rinfo) {
5358
5380
  req.proxiedPduId = proxiedPduId;
5359
5381
  req.proxiedUser = proxiedUser;
5360
5382
  req.proxiedEngine = this.engine;
5383
+ req.proxiedSocket = socket;
5361
5384
  proxy.session.send (req);
5362
5385
  }
5363
5386
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "net-snmp",
3
- "version": "3.11.2",
3
+ "version": "3.12.0",
4
4
  "description": "JavaScript implementation of the Simple Network Management Protocol (SNMP)",
5
5
  "main": "index.js",
6
6
  "directories": {