pub struct Rip {
pub command: Field<u8>,
pub version: Field<u8>,
pub reserved: Field<u16>,
pub entries: Vec<RipEntry>,
pub auth: Option<RipAuth>,
pub auth_key: Vec<u8>,
}Expand description
A Routing Information Protocol message over IPv4/UDP 520 (RFC 1058, RFC 2453).
A Rip is the 4-octet RIP header (command, version, 2-octet reserved)
followed by zero or more fixed 20-octet route table entries
(RipEntry). The same layer covers RIP version 1 (RFC 1058) and
version 2 (RFC 2453): both share the header and the 20-octet entry slot
and differ only in how the previously-reserved entry fields are
interpreted, selected by the version field.
Header fields are held in Field wrappers so a later compile() step
can fill defaults (version, reserved) only when the caller left a field
unset and leave caller-set values — including deliberately wrong ones —
untouched. The builders mark touched fields caller-set via set_user.
The command/entries builders use with_-prefixed names so they do not
collide with the same-named Rip::command/Rip::entries accessors
(Rust rejects two inherent methods with the same name).
Fields§
§command: Field<u8>RIP command octet (RFC 1058 §3.1); modeled as a raw code so unknown
commands round-trip. Read it as a typed RipCommand via
Rip::command.
version: Field<u8>RIP version octet (RFC 1058 §3.1 / RFC 2453 §4).
reserved: Field<u16>Reserved 2-octet header field, must be zero (RFC 1058 §3.1).
entries: Vec<RipEntry>Route table entries that follow the header (RFC 2453 §4).
auth: Option<RipAuth>Optional RIPv2 authentication configuration (RFC 2453 §4.1, RFC 4822 §3).
When set, compile() emits the leading AFI-0xFFFF authentication entry
before the route entries and — for the keyed-digest form — appends the
trailing digest block after them, auto-computing the digest from
Self::auth_key unless the caller pinned one.
auth_key: Vec<u8>The authentication key used to compute the keyed digest on compile().
The key is never serialized onto the wire (except where the RFC 2082
Keyed-MD5 construction folds it into the digest region before hashing);
it is held only so compile() can derive the trailing digest.
Implementations§
Source§impl Rip
impl Rip
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a RIP message with library defaults.
The command defaults to RipCommand::Response, the version to
RIP_VERSION_2, the reserved field to 0, and the entry list is
empty. None of these defaults are marked caller-set, so a later
compile() step may overwrite them.
Sourcepub fn request() -> Self
pub fn request() -> Self
Build a RIP version 2 Request message (RFC 2453 §3.9.1).
Sets the command to RipCommand::Request and the version to 2; both
are marked caller-set.
Sourcepub fn response() -> Self
pub fn response() -> Self
Build a RIP version 2 Response message (RFC 2453 §3.9.2).
Sets the command to RipCommand::Response and the version to 2; both
are marked caller-set.
Sourcepub fn update_request() -> Self
pub fn update_request() -> Self
Build a demand-RIP Update Request message (RFC 2091 §2.3).
Sets the command to RipCommand::UpdateRequest (code 9) and the
version to RIP_VERSION_2; both are marked caller-set. Demand RIP
(RFC 2091) layers on the RIPv2 core, so the version is pinned to 2.
Sourcepub fn update_response() -> Self
pub fn update_response() -> Self
Build a demand-RIP Update Response message (RFC 2091 §2.3).
Sets the command to RipCommand::UpdateResponse (code 10) and the
version to RIP_VERSION_2; both are marked caller-set.
Sourcepub fn update_acknowledge() -> Self
pub fn update_acknowledge() -> Self
Build a demand-RIP Update Acknowledge message (RFC 2091 §2.3).
Sets the command to RipCommand::UpdateAcknowledge (code 11) and the
version to RIP_VERSION_2; both are marked caller-set.
Sourcepub fn with_command(self, command: RipCommand) -> Self
pub fn with_command(self, command: RipCommand) -> Self
Set the command from a typed RipCommand (caller-set).
Stores the command’s wire code via RipCommand::code.
Sourcepub fn command_code(self, code: u8) -> Self
pub fn command_code(self, code: u8) -> Self
Set the command from a raw wire code (caller-set).
Use this to emit an unrecognized command octet verbatim.
Sourcepub fn reserved(self, reserved: u16) -> Self
pub fn reserved(self, reserved: u16) -> Self
Set the reserved header field (caller-set).
The reserved field must be zero on the wire (RFC 1058 §3.1); this builder exists so generated tools can emit a deliberately non-zero value.
Sourcepub fn with_entries(self, entries: impl Into<Vec<RipEntry>>) -> Self
pub fn with_entries(self, entries: impl Into<Vec<RipEntry>>) -> Self
Replace the route table entries with the given list.
Sourcepub fn auth(self, auth: RipAuth, key: impl Into<Vec<u8>>) -> Self
pub fn auth(self, auth: RipAuth, key: impl Into<Vec<u8>>) -> Self
Attach RIPv2 authentication to the message (RFC 2453 §4.1, RFC 4822 §3).
Stores the RipAuth configuration and the authentication key. On
compile() the leading AFI-0xFFFF authentication entry
is emitted before the route entries; for the keyed-digest form, the
trailing digest block is appended after them with the digest computed from
key (RFC 2082 Keyed-MD5 / RFC 4822 HMAC-SHA) unless the caller pinned an
explicit digest, in which case the pinned digest survives untouched. The
key is used only for digest computation and is not otherwise serialized.
Sourcepub fn demand_sequence(self, sequence: u16) -> Rip
pub fn demand_sequence(self, sequence: u16) -> Rip
Record a demand-RIP Sequence Number into the header (RFC 2091 §2.3).
On demand circuits (RFC 2091), the Update Request / Update Response /
Update Acknowledge messages carry a Sequence Number used to match
retransmitted updates with their acknowledgements. RFC 2091 §2.3 places
that 2-octet Sequence Number in the header field RIP otherwise reserves
(the 2 octets following the command/version octets), so this builder
records the sequence there via the reserved field’s
set_user. Because the value is caller-set, compile() serializes it
exactly as given and a subsequent decode() reproduces it byte-for-byte.
This view is meaningful only for the demand/triggered Update* commands;
see demand_sequence_value, which returns
None for a plain Request/Response message.
Sourcepub fn demand_sequence_value(&self) -> Option<u16>
pub fn demand_sequence_value(&self) -> Option<u16>
The demand-RIP Sequence Number, if this is a demand message (RFC 2091 §2.3).
Returns Some(sequence) only for the demand/triggered Update* commands
(RipCommand::UpdateRequest, RipCommand::UpdateResponse,
RipCommand::UpdateAcknowledge), reading the value back out of the
header field RFC 2091 §2.3 reuses for the Sequence Number (the 2 octets
RIP otherwise reserves). For a plain RFC 1058 / RFC 2453 Request or
Response — where those octets are simply the reserved field — it returns
None, since the bytes do not carry a demand sequence number there.
Sourcepub fn command_value(&self) -> u8
pub fn command_value(&self) -> u8
Effective command wire code (caller-set or default).
Sourcepub fn command(&self) -> RipCommand
pub fn command(&self) -> RipCommand
Effective command as a typed RipCommand (caller-set or default).
Sourcepub fn version_value(&self) -> u8
pub fn version_value(&self) -> u8
Effective version octet (caller-set or default).
Sourcepub fn reserved_value(&self) -> u16
pub fn reserved_value(&self) -> u16
Effective reserved header field (caller-set or default).
Sourcepub fn auth_config(&self) -> Option<&RipAuth>
pub fn auth_config(&self) -> Option<&RipAuth>
The attached RIPv2 authentication configuration, if any (RFC 2453 §4.1).
Returns Some when the message carries authentication — either set by the
Rip::auth builder or recognized from a leading AFI-0xFFFF entry on
decode. For a decoded keyed-digest message this exposes the parsed
header; verification of the trailing digest is via verify on the raw
message bytes. (Named auth_config so it does not collide with the
same-named Rip::auth builder; Rust rejects two inherent methods with
the same name.)
Trait Implementations§
Source§impl<R> Div<R> for Ripwhere
R: IntoPacket,
impl<R> Div<R> for Ripwhere
R: IntoPacket,
Source§impl Layer for Rip
impl Layer for Rip
Source§fn encoded_len(&self) -> usize
fn encoded_len(&self) -> usize
Source§fn compile(&self, _ctx: &LayerContext<'_>, out: &mut Vec<u8>) -> Result<()>
fn compile(&self, _ctx: &LayerContext<'_>, out: &mut Vec<u8>) -> Result<()>
out.Source§fn inspection_fields(&self) -> Vec<(&'static str, String)>
fn inspection_fields(&self) -> Vec<(&'static str, String)>
Source§fn clone_layer(&self) -> Box<dyn Layer>
fn clone_layer(&self) -> Box<dyn Layer>
Source§fn as_any_mut(&mut self) -> &mut dyn Any
fn as_any_mut(&mut self) -> &mut dyn Any
Any for typed packet access.Source§fn into_any(self: Box<Self>) -> Box<dyn Any>
fn into_any(self: Box<Self>) -> Box<dyn Any>
Any for downcasting.Source§fn encoded_len_with_context(&self, _ctx: &LayerContext<'_>) -> usize
fn encoded_len_with_context(&self, _ctx: &LayerContext<'_>) -> usize
Source§fn consumes_following(&self) -> bool
fn consumes_following(&self) -> bool
compile() emits all following layers itself. Read more