Skip to content

refactor: one request builder and one request and msg ID generator - #42

Merged
ilyam8 merged 2 commits into
engine-fipsfrom
engine-requests
Oct 11, 2026
Merged

ilyam8 merged 2 commits into
engine-fipsfrom
engine-requests

Conversation

@ilyam8

@ilyam8 ilyam8 commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

Summary

First restructuring step of the request engine: one request builder and one request and msg ID generator. No behavior or exported API change.

  • request.go: Get, GetNext, GetBulk, Set and the packet builders. oidRequest does the MaxOids check and the OID to Null-varbind conversion once instead of three times. GetBulk still checks for SNMPv1 first; Set is unchanged (its first-varbind type check and its Set(nil) panic included).
  • ids.go: the request and msg ID counters as atomic.Uint32, advanced and masked to 31 bits in nextRequestID and nextMsgID (used by sendOneRequest and SnmpEncodePacket, which each had a copy), seeded by Connect, set by SetRequestID and SetMsgID. Connect and the setters no longer write the fields without atomics.

The first commit pins four behaviors no test observed, found by mutation probes, through the public API (SnmpEncodePacket/SnmpDecodePacket read the IDs of the encoded messages): GetBulk checks for SNMPv1 before MaxOids; Connect seeds both IDs from one random value and reseeds them on every Connect (known bug: it discards SetRequestID/SetMsgID); SetMsgID moves the msg ID; the msg ID wraps to 0 after 2147483647. Both pass on the previous code.

Testing

  • go test ./... on darwin/arm64 and GOARCH=386; -race; the FIPS 140-only tests; golangci-lint v2.14.0 (incl. end2end): 0 issues.
  • Every golden (requests, v3, walk, codec) and the API test unchanged.
  • 16 mutation probes on the builder and the generator: 14 caught, 2 equivalent (masking on store: (x & m) + 1 & m == (x + 1) & m).
  • BenchmarkSendOneRequest, interleaved A/B, 6 rounds: time unchanged (p = 0.589), B/op and allocs/op identical.

@ilyam8
ilyam8 added this pull request to stack #38 October 9, 2026 15:18
@ilyam8 ilyam8 changed the title engine requests refactor: one request builder and one request and msg ID generator Oct 9, 2026
@ilyam8
ilyam8 force-pushed the engine-requests branch 2 times, most recently from 1e0f37c to 08ee3ea Compare October 11, 2026 09:46
Mutation probes on the request and ID code found four behaviors no test
observed: GetBulk checks for SNMPv1 before MaxOids; Connect seeds both the
request and the msg ID from one random value and reseeds them from the same
value on every Connect (known bug: it discards SetRequestID and SetMsgID);
SetMsgID moves the msg ID; the msg ID wraps to 0 after 2147483647.

TestGetBulkChecks and TestRequestAndMsgIDs pin them through the public API
(SnmpEncodePacket and SnmpDecodePacket read the IDs of the encoded
messages); both pass on the current code.
The OID operations and the ID handling were copied: Get, GetNext and
GetBulk each checked MaxOids and built their Null varbinds, and
sendOneRequest and SnmpEncodePacket each advanced and masked both IDs, while
Connect and the setters wrote the same fields without atomics.

- request.go: the operations and the packet builders; oidRequest does the
  MaxOids check and the OID to varbind conversion for Get, GetNext and
  GetBulk (GetBulk still checks for SNMPv1 first; Set is unchanged, its
  first-varbind type check and its nil panic included).
- ids.go: the request and msg ID counters as atomic.Uint32, advanced and
  masked to 31 bits in nextRequestID and nextMsgID, seeded by Connect from the
  client's random value, set by SetRequestID and SetMsgID.

No behavior change: every golden and the API test are unchanged.
@ilyam8
ilyam8 merged commit ca4fa2c into master Oct 11, 2026
21 checks passed
@ilyam8
ilyam8 deleted the engine-requests branch October 11, 2026 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants