snmp_pdus(3)

πŸ“¦
version 29.0.6 Β· 3 versions
, in ubuntu stonking

πŸ’… snmp_pdus β€” the Erlang module that does SNMP PDU glow-ups

okay so bestie, welcome to snmp_pdus(3), an Erlang module definition, and honestly? it's giving protocol translator icon. she encodes and decodes SNMP PDUs, and she does NOT miss. πŸŽ€


✨ NAME ✨

snmp_pdus β€” Encode and Decode Functions for SNMP PDUs. periodt.


🌸 DESCRIPTION 🌸

no cap, before you touch this module, snmp_pdus, you NEED to go sit down and study RFC1157, RFC1905 and/or RFC2272 carefully. like, actually carefully. this is not a skim-the-abstract situation, bestie. 😭

so what does snmp_pdus actually do? she has functions for encoding and decoding SNMP protocol data units (PDUs). short version: this module converts a list of bytes into Erlang record representations, and vice versa. iconic behavior, truly. πŸ¦‹

the record definitions live in the file snmp/include/snmp_types.hrl. and here's the tea β€” if snmpv3 is being used, the module that includes snmp_types.hrl must define the constant SNMP_USE_V3 before the header file is included. order matters, she's picky. example:

-define(SNMP_USE_V3, true).
-include_lib("snmp/include/snmp_types.hrl").

also, real talk: encoding and decoding must be done explicitly when you're writing your own Net if process. nobody's doing it for you, main character, you do it yourself. πŸ’ͺ


🧚 DATA TYPES 🧚

  • message() :: #message{}. β€” the message is version dependent, okay? 'vsn_hdr' is either a community string (v1 and v2) or a 'v3_hdr' record (v3). 'data' is either a PDU (v1 and v2c) or a (possibly encrypted) 'scopedPdu'. yes literally all of that.
  • msg_id() :: 0..2147483647. β€” that's the range. respect it. ✨
  • msg_security_model() :: 0..2147483647. β€” same range, different vibe.
  • pdu() :: #pdu{}. β€” the PDU record, slay.
  • pdu_type() :: 'get-request' | 'get-next-request' | 'get-bulk-request' | 'get-response' | 'set-request' | 'inform-request' | 'snmpv2-trap' | report. β€” the whole squad, all eight of them. πŸ‘‘
  • scoped_pdu() :: #scopedPdu{}. β€” scoped pdu record, we love her.
  • trappdu() :: #trappdu{}.
  • usm_security_parameters() :: #usmSecurityParameters{}.
  • v3_hdr() :: #v3_hdr{}.
  • version() :: 'version-1' | 'version-2' | 'version-3'. β€” the three eras, bestie. 🌈

πŸ”₯ FUNCTIONS πŸ”₯

dec_message(Bytes) -> Message when Bytes :: [byte()], Message :: message().

decodes a list of bytes into an SNMP Message. πŸ’–

⚠️ heads up though: if there's a v3 message, the msgSecurityParameters are not decoded. they must be explicitly decoded by a call to a security model specific decoding function, e.g. dec_usm_security_parameters/1. and also β€” if the scopedPDU is encrypted, the OCTET STRING encoded encryptedPDU will be present in the data field. so like, know that going in.

dec_message_only(Bytes) -> Message when Bytes :: [byte()], Message :: message().

decodes a list of bytes into an SNMP Message, but βœ‹ does not decode the data part of the Message. which means data is still a list of bytes β€” normally an encoded PDU (v1 and V2), or an encoded and possibly encrypted scopedPDU (v3). leaving that part untouched on purpose, she's got boundaries. 🫢

dec_pdu(Bytes) -> Pdu when Bytes :: [byte()], Pdu :: trappdu() | pdu().

decodes a list of bytes into an SNMP Pdu. simple, clean, ate. ⭐

dec_scoped_pdu(Bytes) -> ScopedPDU when Bytes :: [byte()], ScopedPDU :: scoped_pdu().

decodes a list of bytes into an SNMP ScopedPdu. 🌸

dec_scoped_pdu_data(Bytes) -> ScopedPduData when Bytes :: [byte()], ScopedPduData :: scoped_pdu() | EncryptedPDU, EncryptedPDU :: [byte()].

decodes a list of bytes into either a scoped pdu record, or β€” if the scoped pdu was encrypted β€” to a list of bytes. two possible outcomes, she contains multitudes. πŸ’œ

dec_usm_security_parameters(Bytes) -> UsmSecParams when Bytes :: [byte()], UsmSecParams :: usm_security_parameters().

decodes a list of bytes into an SNMP UsmSecurityParameters. ✨

enc_message(Message) -> Bytes when Message :: message(), Bytes :: [byte()].

encodes a message record to a list of bytes. that's it, that's the function. πŸ’…

enc_message_only(Message) -> Bytes when Message :: message(), Bytes :: [byte()].

here Message is a record where the data field is assumed to be encoded (a list of bytes). so: if there's a v1 or v2 message, the data field is an encoded PDU, and if there's a v3 message, data is an encoded and possibly encrypted scopedPDU. you bring the encoded bytes, she handles the rest. πŸŽ€

enc_pdu(Pdu) -> Bytes when Pdu :: pdu(), Bytes :: [byte()].

encodes an SNMP Pdu into a list of bytes. πŸ”₯

enc_scoped_pdu(ScopedPdu) -> Bytes when ScopedPdu :: scoped_pdu(), Bytes :: [byte()].

encodes an SNMP ScopedPdu into a list of bytes β€” which can be encrypted, and after encryption, encoded with a call to enc_encrypted_scoped_pdu/1; or it can be used as the data field in a message record, which then can be encoded with enc_message_only/1. two routes, both valid, choose your adventure bestie. πŸ¦‹

enc_usm_security_parameters(UsmSecParams) -> Bytes when UsmSecParams :: usm_security_parameters(), Bytes :: [byte()].

encodes SNMP UsmSecurityParameters into a list of bytes. πŸ’–


πŸ’€ reminder for the girlies in the back: study those RFCs first. RFC1157, RFC1905, RFC2272. iykyk.

and that's the whole page, bestie!! πŸ₯³ this glamorous little document was brought to you by Ericsson AB, shipping with snmp 5.20.5 β€” yeah, snmp_pdus(3), that's her. go encode something. πŸ’…βœ¨πŸŽ€

πŸ“¦ where this page comes from