# zig-smi
A reader for SNMP MIB modules: SMIv1 and SMIv2, in Zig.
The API documentation is generated from the doc comments, which carry most of
the explanation, and is published at ****.
```console
$ git clone https://git.jcollie.dev/jeff/zig-smi.git
$ cd zig-smi
$ nix develop -c zig build test
```
It is written for Zig 0.17. The last release for Zig 0.16 is `v0.1.0`, and the
`zig-0.16` branch holds it.
## Where this lives
Three homes, with the same history in all of them.
* Forgejo, at , which is where the
workflow runs and where the documentation is published from.
* [Tangled](https://tangled.org/), at .
* The [Radicle](https://radicle.xyz/) network, where the repository's
identifier is
```
rad:z2yVrgep2QYVHEopX1SZARvBAeL7f
```
and
```console
$ rad clone rad:z2yVrgep2QYVHEopX1SZARvBAeL7f
```
fetches it from any node that seeds it, needing no account and no forge. A
Radicle repository is findable by its identifier and by nothing else, so
that string is the whole of the address.
## What this is for
[`zig-snmp`](https://git.jcollie.dev/jeff/zig-snmp) speaks the protocol and
knows nothing about what any OID *means*: it can fetch `1.3.6.1.2.1.1.1.0` but
not `sysDescr.0`, and it renders that object's value as an octet string
because it has no way to learn it is a `DisplayString`. All of that meaning
lives in MIB modules, which are written in a language of their own — ASN.1
with a set of macros bolted on — and reading them is a compiler rather than a
protocol feature. Hence a separate repository.
## State
**The lexer, the module parser, the name resolver and the clause reader.**
What is left is the integration into `zig-snmp` itself, so that its tools take
`-m` and `-M` and a symbolic name.
Measured against **2,852 published MIB files** — net-snmp's 65 base modules,
and Cisco's 1,648 SMIv2 and 1,139 SMIv1 modules at a pinned revision:
| | |
| --- | --- |
| lex cleanly | 2,849 of 2,852 |
| parse into a module | **2,847**, yielding **280,240 assignments** |
| contain no module at all | 2 — one of them is nine lines of comment reading "please ignore this mib" |
| fail | 3, **all of which net-snmp also rejects**, naming the identical line on two |
The three failures are genuinely broken files: a stray full stop after a
closing quote, a `VARIATION` clause left outside the macro it belonged to, and
two `DESCRIPTION`s whose quote was closed early so that prose spills into the
grammar.
## The three rules that cost the time
**A comment ends at `--` or at the end of the line, whichever comes first.**
X.208 §8.6 says so, and it matters: in
```
SYNTAX INTEGER -- a comment -- (0..255)
```
the constraint is real, and treating `--` as "rest of line" drops it silently
— producing a wrong SYNTAX rather than an error, so nothing notices. But real
MIBs are full of banner lines made of dashes, where the pairs close and reopen
the comment and the author plainly meant the whole line. net-snmp ships `-Pc`
to switch the rule off for exactly this reason. Neither reading is right for
every real file, so it is an option.
**Underscores appear in identifiers, and ASN.1 says they may not.**
`CISCO-LWAPP-TC-MIB` has `dot11_6ghz(6)`; `CISCO-SWITCH-QOS-MIB` has
`inputStats_ingressStraight(1)`. net-snmp rejects both with `Expected "(" (_)`
until `-Pu` is passed. **The default here is the opposite of net-snmp's**, on
the grounds that the job is to read the MIBs that exist; anything comparing
the two passes `-Pu` on the other side.
**A module ends at `END`, and files have things after it.**
`CISCO-OSPF-CAPABILITY.my` ends with `