Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

SNMP link

The snmp link polls SNMP agents — switches, routers, UPS, PDUs, printers, controllers — like any other device. It speaks SNMPv2c (community) and SNMPv3 (USM: HMAC-SHA-1 or HMAC-192-SHA-256, AES-128 privacy). It runs on the driver framework (ADR 0004): the tree, the add_* / edit / remove / restart / stop / start actions, states, scheduling, read-back writes and the quality ladder are the framework’s, as in every framework link (links.md).

Install it with Install Link ▸ from Driver, driver snmp (embedded or process), or as the package snmp (wyr link pack, binary wyrm-link-snmp).

1. The tree

downstream/<link>/
  <connection>        Add SNMP v2c | Add SNMP v3  (one agent address)
    status, error     the framework's state leaves
    requests, errors, timeouts, exceptions, late_replies, rejected_replies,
    undecodable_replies, last_rtt_ms, avg_rtt_ms
    ▸ Reset Engine Clock  (snmp_v3 only, config; §7)
    <device>          Add Device   (one view of the agent: a v3 context or a v2c community)
      status, error, diagnostics as above
      ▸ Walk
      <point>         Add Point    (one OID)

A connection is one agent (host:port, one UDP socket). A device is one view of it: usually one device per connection with the defaults; add more when the agent shows other data under another v3 context or another v2c community (some switches select a VLAN by community).

2. Parameters

Connection snmp_v2c (Add SNMP v2c)

ParamDefaultBoundsMeaning
host— (required)Agent host name or address. The addresses of a name are tried in turn, IPv4 first, then IPv6, while the bound of opening the connection (the lookup and two addresses) has room; the error lists each address tried.
port1611…65535Agent UDP port.
community— (required, secret)Community string. Entered in add_snmp_v2c/edit, kept sealed; never shown.
timeout_ms1000100…10000Bound on each request.
retries10…5Repeats of a request after a timeout.

Connection snmp_v3 (Add SNMP v3)

ParamDefaultBoundsMeaning
host, port—, 1611…65535As above.
user— (required)1…32 charactersUSM user name.
auth_protocolsha256sha1, sha256usmHMACSHAAuthProtocol (HMAC-SHA-96) or usmHMAC192SHA256AuthProtocol (RFC 7860).
auth_passphrase— (required, secret)≥ 8 charactersAuthentication passphrase.
priv_protocolaes128aes128, noneAES-128-CFB (RFC 3826), or none for authNoPriv.
priv_passphrase"" (secret)≥ 8 characters with aes128Privacy passphrase.
engine_id""5…32 octets in hex (0x8000…, 80:00:… or plain)Optional: the agent’s snmpEngineID, as net-snmp -e. When set, a discovered engine id that is another fails the connection, and a report naming another engine never starts a rediscovery.
timeout_ms, retries1000, 1as above

The engine id is discovered when the connection opens (RFC 3414 §4) and the keys are localized for it. The agent’s boots and time come from authenticated messages only, never from the unauthenticated discovery report. The link keeps them across reconnects (per agent address, engine id and user, for as long as the link runs); the first time, they come from the authenticated answer to the first request, sent at boots/time 0/0: a usmStatsNotInTimeWindows report, or, from an agent that skips that check, a response whose values are not used (the request is sent again). noAuthNoPriv is not offered.

host, port, user, the protocols and context are the destination of the secrets: an edit that changes one of them drops the stored secrets unless it gives them again (the framework’s rule).

Device

ParamDefaultBoundsMeaning
context""SNMPv3 contextName; empty = the default context.
community"" (secret)v2c only: this device’s community instead of the connection’s; empty = the connection’s.
max_varbinds201…100Scalars per GET request.
max_repetitions251…100Rows per GETBULK request (table columns, walk).
max_pages201…200GETBULK requests per table column and poll.
pingtruePing the device.
ping_s100.1…3600Ping period (s).
republish_s00…3600Publish an unchanged value again after this long (0 = on a change only).

Point

ParamDefaultBoundsMeaning
oid— (required)≤ 128 arcsNumeric OID: 1.3.6.1…, .1.3.6.1… or iso.3.6.1… (stored as 1.3.6.1…). For table_column: the column’s OID.
kindscalarscalar, table_columnscalar: GET of oid. table_column: the cell oid.index, read by GETBULK.
index""dotted numbersRow index of a table_column point (3, 1.4.192.0.2.1); refused on a scalar.
convautosee §3Value conversion.
scale, offset1, 0scale ≠ 0value = raw × scale + offset, numeric conversions only.
unit""Shown in ~meta.unit.
poll_s100.01…86400Poll period (s).
writablefalseThe point takes ~set (SET).
set_typeintegerinteger, octet_string, gauge32SMI type of a SET.

Rules checked when a point is added or edited: table_column needs an index; scale/offset only on auto and numeric conversions; a writable integer/gauge32 point uses auto or gauge, a writable octet_string point auto or string.

3. Conversions

convTakesGives
autoanyINTEGER → integer; Counter32/Gauge32/TimeTicks/Counter64 → unsigned; OCTET STRING → text (UTF-8 without trailing NULs, else hex de:ad:be:ef); IpAddress → 192.0.2.1; OBJECT IDENTIFIER → 1.3.6.1…; Opaque → bytes. ~meta.type is dynamic.
counter32Counter32the raw counter
counter64Counter64 or Counter32the raw counter
rate_per_sCounter32 or Counter64(new − old) / seconds between two polls; see below
gaugeGauge32, INTEGER, TimeTicks, countersthe number
timeticks_sTimeTicksseconds (hundredths / 100)
stringany but NULLtext, as auto gives it
ipIpAddress, OCTET STRING of 4 or 16 octetsIPv4 or IPv6 text
macOCTET STRING of 6 octets00:1b:21:0a:0b:0c

Numbers are scaled with scale/offset. With scale = 1 and offset = 0 an integer stays an integer; otherwise the value is a float.

rate_per_s: the first poll gives no value (a rate needs two samples). A Counter32 that goes down wrapped once (new + 2³² − old); a Counter64 that goes down was reset, and that poll gives no value. A plan with rate points also reads sysUpTime.0; when it goes down the agent restarted, and every rate starts again without a value. The time base is the link’s clock: the time each answer came (the answer of the request that carried that varbind, not the end of the poll). scale = 8 turns octets per second into bits per second.

A Counter32 can wrap more than once between two samples, and the link cannot see it: a 1 Gbit/s ifInOctets wraps every 34 s. So a Counter32 sample older than max(2 × poll_s, poll_s + 5 s) (after an outage) gives no rate; the rate starts again from the new sample. Keep poll_s well below the wrap time, and use the 64-bit ifHC* counters for links faster than about 100 Mbit/s. A counter that is cleared without an agent restart (clear counters, an interface reset) looks like one wrap to the link: one rate up to 2³² / seconds. The link does not read ifCounterDiscontinuityTime.

A varbind of the wrong type for its conversion is a point error (conv mac: cannot convert a counter32), never a made-up value. A varbind whose value does not fit its own type (an INTEGER of 5 octets or of none, a Counter32 above 2³², a known agent bug) is a point error too (“malformed INTEGER encoding from the agent”); the other varbinds of that answer keep their values.

4. Reads

  • Scalars of one device and poll period are read with GET, at most max_varbinds per request.
  • Cells of a table column are read with GETBULK, from just below the first wanted row, jumping over the gaps between wanted rows, at most max_pages requests per column and poll. Rows the column does not have are point errors (noSuchInstance).
  • An answer with tooBig splits the request in two; a single varbind that is still too big is a point error. An error status with an index (genErr) fails that point and reads the others again.
  • noSuchObject, noSuchInstance and endOfMibView fail that point only.
  • A request without an answer (after its retries) fails the points it asked for, and the poll goes on with the next request: an agent whose handler for one OID hangs does not stop the other points. Two requests in a row without an answer stop the poll; every point not read yet misses with them.

Every request has a new request id (v3: and msgID). Only an answer with one of the ids of that request is taken; an answer that comes after its timeout is dropped and counted in late_replies. A timeout sends the request again (a new id) up to retries times. Two more counters show datagrams the link drops:

CounterCounts
late_repliesAnswers to an earlier request (their id is not one of this request’s). A late v3 answer is authenticated first, and its boots and time move the link’s notion of the agent’s clock forward.
rejected_repliesv3 messages that are not taken, late ones included (they are authenticated before their id is matched): the MAC does not verify, the authoritative engine id or the user name is another, the security level is lower than the request’s (no MAC, or not encrypted for an authPriv request), it does not decrypt, it is outside the time window (§7).
undecodable_repliesDatagrams that are not an SNMP message the link reads (framing, header or PDU malformed).

5. Writes

A writable point takes ~set: the link sends one SET of set_type and the framework reads the point back; the value is never updated before the read-back. A number is scaled back ((value − offset) / scale, rounded) and must fit the type (INTEGER: 32 bits signed, Gauge32: 0…4294967295). The agent’s refusal (notWritable, wrongType, noAccess, authorizationError, …) is the error of the ~set and changes nothing. A read-only point refuses the write. Only INTEGER, OCTET STRING and Gauge32 are written.

6. Errors and quality

What happensResult
noSuchObject / noSuchInstance / endOfMibView, a conversion that does not fit, a value whose encoding does not fit its type, an error status for one varbindThat point bad; the device stays connected.
No answer within timeout_ms × (1 + retries) to any request of a pollA device miss: points uncertain/stale, after 3 misses bad/comm_fail and the device failed.
No answer to one request while others of the poll are answeredThe points of that request uncertain/stale, after 3 polls in a row bad/comm_fail; the device stays connected.
authorizationError on a poll or pingThe device failed: “authorizationError: the agent’s access control (VACM) refuses this request; check the community, user or context”.
v3 report usmStatsWrongDigests, usmStatsUnknownUserNames, usmStatsUnsupportedSecLevels, usmStatsDecryptionErrorsWhen the connection opens: the connection failed with the reason (e.g. “the agent refused the authentication digest (usmStatsWrongDigests): check auth_protocol and auth_passphrase”); later: the device fails with it.
v3 report snmpUnknownContextsThe device’s context is not one the agent has: the device fails with “the agent does not know this context (snmpUnknownContexts): check the device’s context”. Another report names its OID in the error.
v3 report usmStatsNotInTimeWindows (authenticated)The agent restarted or its clock moved: the link takes the agent’s boots/time (forward only) and sends again once.
v3 answer outside the time window (lower boots, or more than 150 s behind)Dropped (rejected_replies): a replay. When no answer is taken the device misses with “the agent’s answers are outside the time window …”. An agent whose boots counter went down is refused (RFC 3414) until Reset Engine Clock runs on the connection; a connection that opens with only such answers stays connected, says so in attr.warning of its status, and its devices fail.
v3 report usmStatsUnknownEngineIDs with another engine idThe engine id changed (a replaced device): the connection reopens and discovers it again. The report is not authenticated, so this happens at most once per 30 s per agent (the wait doubles up to 15 min while such reports keep coming); within the wait the device fails with “… not discovering it again for N s”.
v3 report usmStatsUnknownEngineIDs with the engine id the link hasNot authenticated and not true (a forged or broken report): the device fails with it; the connection stays.
ICMP port unreachable (nothing listens on the port)The connection drops; it reopens with backoff and stays failed with error while nothing answers; its devices are stopped_by_parent.
No answer when the connection opensThe connection failed (“no answer from the agent …”).

A wrong v2c community gets no answer at all: agents drop such requests without a reply (RFC 3584). It shows as an agent that does not answer, not as an authentication error.

The connection opens with a GET of sysUpTime.0 (v3: after engine discovery) with the connection’s community and the default context: UDP has no connection, so this is how an agent that cannot be reached fails the connection. The device ping is the same GET in the device’s view; any answer, noSuchObject included, means alive.

7. Security

  • The community and both passphrases are secret parameters: entered in add_*/edit, kept sealed in the link’s data_dir, never in ~meta, export, replies or logs. No datagram is ever logged (a v2c datagram holds the community). Bootstrap params in wyrmd.json5 are plain text in that file: prefer the actions.
  • SNMPv2c sends the community and the values in clear text. A v2c connection beyond loopback says so in attr.warning of its status leaf; use snmp_v3 with aes128 beyond a trusted network. A v3 connection with priv_protocol: none beyond loopback says that values travel unencrypted.
  • An answer to a v3 request is taken only when its MAC verifies, its authoritative engine id is the agent’s, its security level is the request’s and it is in the time window (RFC 3414 §3.2 7b): lower boots, or a time more than 150 s behind the link’s notion of the agent’s clock, is a replayed old message and is dropped. The clock moves forward only, and only on authenticated messages, late ones included (RFC 3412 §7.2: authentication and timeliness come before the msgID); the unauthenticated discovery report sets the engine id, never the clock. The values of a response to a request sent before the clock is known are never taken (it may be a replay): only its boots and time, and the request is sent again.
  • Discovery is not authenticated: an on-path attacker can redirect the requests to another agent that has the same user and passphrases (common across a fleet) and relay them; every check then passes, and that device’s values show as this one’s. Set engine_id (the agent’s snmpEngineID, e.g. from snmpget -v3 … 1.3.6.1.6.3.10.2.1.1.0) to refuse any other engine. A replaced device then needs its new id in engine_id.
  • The clock is kept across reconnects, so a forced reconnect (a forged ICMP error or report) does not open a window for replays. Reset Engine Clock (connection action, config, v3) forgets it; run it only when the agent really lost its boots counter (it was reinstalled or reset), or its engine time went back within the same boots (an agent that takes its engine time from the wall clock, after an NTP step): both are refused the same way. RFC 3414 expects the keys to change after the boots go down: change the passphrases then (on the agent and here), because messages recorded in the old boots period stay valid against a link whose clock was just reset. When it succeeds, the connection reconnects once at its next request (its devices show stopped_by_parent for a moment), learns the clock again, and the warning on its status clears. A connection restart does not forget it: to the link a restart is one more open, like any reconnect, and a reconnect can be forced from the network. The kept clock is in the link’s memory: restarting the link process (or wyrmd for an embedded link) forgets it too.
  • Walk is a config action: it reads any subtree of the agent with the link’s credentials (interface, ARP, vendor tables beyond the configured points) and costs the agent up to hundreds of requests, so a read or write caller is refused.

8. Walk

Device action Walk (walk {oid, max = 500}, level config, at most 60 s): GETBULK from oid while the answers stay below it, at most max (1…10000) entries → [{oid, type, value}], type the SMI type (integer, octet_string, counter32, …) and value as auto converts it. Use it to find the OIDs and row indexes for points. The walk holds the connection’s owner while it runs: the connection’s polls wait.

9. Common OIDs

ObjectOIDPoint
sysDescr1.3.6.1.2.1.1.1.0scalar, string
sysUpTime1.3.6.1.2.1.1.3.0scalar, timeticks_s
sysName1.3.6.1.2.1.1.5.0scalar
ifDescr1.3.6.1.2.1.2.2.1.2table_column, index = ifIndex
ifOperStatus1.3.6.1.2.1.2.2.1.8table_column (1 up, 2 down, …)
ifInOctets / ifOutOctets1.3.6.1.2.1.2.2.1.10 / .16table_column, rate_per_s (Counter32)
ifName1.3.6.1.2.1.31.1.1.1.1table_column
ifHCInOctets / ifHCOutOctets1.3.6.1.2.1.31.1.1.1.6 / .10table_column, rate_per_s, scale: 8 for bit/s
hrProcessorLoad (HOST-RESOURCES-MIB)1.3.6.1.2.1.25.3.3.1.2table_column, gauge, unit %
hrStorageUsed / hrStorageSize1.3.6.1.2.1.25.2.3.1.6 / .5table_column, gauge (× hrStorageAllocationUnits .4)
upsBatteryStatus (UPS-MIB)1.3.6.1.2.1.33.1.2.1.0scalar (2 normal, 3 low, 4 depleted)
upsEstimatedChargeRemaining1.3.6.1.2.1.33.1.2.4.0scalar, unit %
upsInputVoltage1.3.6.1.2.1.33.1.3.3.1.3table_column, index 1, unit V
upsOutputPercentLoad1.3.6.1.2.1.33.1.4.4.1.5table_column, index 1, unit %

10. Try it with the simulator

wyrm-snmp-sim is an SNMP agent with community public and the v3 users sha1user (SHA-1, AES), sha256user (SHA-256, AES) and authonly (SHA-256, no privacy), each with the passphrase <user>-pass. Its MIB: the system group (writable sysContact), ifNumber, an ifTable and ifXTable of 4 rows whose octet counters grow every second (row 1’s ifInOctets starts just below the Counter32 wrap), and one object of each SMI type under 1.3.6.1.4.1.64999.1 (.1.0 INTEGER and .2.0 Gauge32 writable, .3.0 IpAddress, .4.0 TimeTicks, .5.0 Opaque, .6.0 Counter64, .7.0 binary OCTET STRING, .8.0 writable text).

cargo run -p wyrm-link-snmp --features bin --bin wyrm-snmp-sim -- --listen 127.0.0.1:1161
snmpwalk -v2c -c public 127.0.0.1:1161 1.3.6.1.2.1.2.2.1.2      # net-snmp, if installed

A link in wyrmd.json5 against it (the community in the file is for the demo only; enter real ones with add_snmp_v2c):

links: {
  net1: {
    driver: "snmp",
    params: {
      connections: {
        sim: {
          kind: "snmp_v2c", host: "127.0.0.1", port: 1161, community: "public",
          devices: {
            agent: {
              points: {
                uptime: { oid: "1.3.6.1.2.1.1.3.0", conv: "timeticks_s", unit: "s" },
                eth0_in: { oid: "1.3.6.1.2.1.31.1.1.1.6", kind: "table_column", index: "1",
                           conv: "rate_per_s", scale: 8, unit: "bit/s", poll_s: 5 },
                contact: { oid: "1.3.6.1.2.1.1.4.0", conv: "string", writable: true,
                           set_type: "octet_string" },
              },
            },
          },
        },
      },
    },
  },
}

Or add the connection at run time: downstream/net1 ▸ Add SNMP v3 with host 127.0.0.1, port 1161, user sha256user, both passphrases sha256user-pass; then Add Device, ▸ Walk 1.3.6.1.2.1.2.2.1, and Add Point for the OIDs found.

The simulator’s failure modes (tests, links/snmp/src/sim.rs): silence, a reply delayed past the timeout, authorizationError, tooBig above a number of varbinds, genErr on one OID, a restart (new boots, sysUpTime from 0), unknown OIDs and communities.

Against a real agent (net-snmp snmpd):

WYRM_SNMP_AGENT=127.0.0.1:16163 WYRM_SNMP_USER=sha1user WYRM_SNMP_PASS=sha1user-pass \
  cargo test -p wyrm-link-snmp --test interop -- --ignored

11. Known limits

  • No trap or inform receiver (follow-up): the link polls only.
  • No MIB files: OIDs are numeric; §9 lists common ones.
  • No SNMPv1, no noAuthNoPriv v3, no MD5 or SHA-224/384/512, no DES, 3DES, AES-192 or AES-256 privacy.
  • No v3 key change (usmUserTable) or user management on the agent.
  • One OID per point; no table point that publishes a whole column as an array.
  • A SET carries one varbind; INTEGER, OCTET STRING and Gauge32 only.
  • rate_per_s uses the link’s clock at each answer, not the agent’s sysUpTime deltas; a counter cleared without a restart gives one spike (§3).
  • SNMP over TCP, TLS (RFC 6353) or DTLS is not supported; UDP only.
  • Interop was checked against net-snmp 5.6 (v2c, v3 SHA-1/AES-128); SHA-256 is checked against the built-in simulator and an independent key derivation.