Skip to main content

Module codec

Module codec 

Source
Expand description

HSRP wire formats, both of them.

HSRPv1 and HSRPv2 are not the same protocol in a different dress — they are two unrelated encodings that happen to share a name, a port and an election idea. v1 is a flat 20-byte struct (RFC 2281 §5); v2 is a sequence of TLVs. Nothing about one parses as the other, and the state numbers differ in a way that silently mis-decodes rather than failing: code 4 is Speak in v1 and Standby in v2. That collision is the single most dangerous thing in this file, which is why the enums below never carry a bare integer across a version boundary — HsrpState is converted through from_v1_code/from_v2_code and v1_code/v2_code, and there is no as u8 shortcut anywhere.

This module is pure: no sockets, no LLM, no state. mod.rs owns all of that.

Structs§

HsrpMessage
One HSRP advertisement, version-independent.
Md5Auth
What an HSRPv2 MD5 Authentication TLV said, minus the digest.

Enums§

HsrpState
Where the speaker says it is in the election.
HsrpVersion
Which of the two incompatible encodings a message uses.
Opcode
What the message asserts. All three are elections moves, not queries.

Constants§

AUTH_FIELD_LEN
Width of the authentication field in both versions.
DEFAULT_AUTH_DATA
The notorious Cisco default. See CLAUDE.md: this is plaintext on the wire and provides no security whatsoever — it is a misconfiguration guard, not authentication.
V1_LEN
Exact size of an HSRPv1 datagram (RFC 2281 §5): eight one-byte fields, eight bytes of authentication data, four bytes of virtual IP.
V1_VERSION_BYTE
The value HSRPv1 puts in its Version byte. It is 0, not 1 (RFC 2281 §5: “Currently, this is version 0”). Reading this as “v1 means byte 1” produces a packet no Cisco device accepts, and is the first thing to check if interop ever fails.
V2_GROUP_STATE_LEN
Payload length of the Group State TLV, i.e. the byte after the type. Always 40.
V2_GROUP_STATE_TOTAL
Total size of a Group State TLV including its two-byte type/length header.
V2_MD5_AUTH_LEN
Payload length of the MD5 Authentication TLV in the form this parser accepts.
V2_TEXT_AUTH_LEN
Payload length of the Text Authentication TLV. Always 8, like v1’s inline field.
V2_TLV_GROUP_STATE
HSRPv2 Group State TLV type.
V2_TLV_INTERFACE_STATE
HSRPv2 Interface State TLV type. Parsed past, never generated.
V2_TLV_MD5_AUTH
HSRPv2 MD5 Authentication TLV type. Parsed structurally; see Md5Auth.
V2_TLV_TEXT_AUTH
HSRPv2 Text Authentication TLV type — the v2 home of the same 8-byte plaintext field v1 carries inline.

Functions§

decode
Parse a datagram as whichever of the two formats it is.
encode
Serialize a message in whichever format its version names.