Skip to main content

Rip

Struct Rip 

Source
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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn version(self, version: u8) -> Self

Set the version octet (caller-set).

Source

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.

Source

pub fn entry(self, entry: RipEntry) -> Self

Append a single route table entry.

Source

pub fn with_entries(self, entries: impl Into<Vec<RipEntry>>) -> Self

Replace the route table entries with the given list.

Source

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.

Source

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.

Source

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.

Source

pub fn command_value(&self) -> u8

Effective command wire code (caller-set or default).

Source

pub fn command(&self) -> RipCommand

Effective command as a typed RipCommand (caller-set or default).

Source

pub fn version_value(&self) -> u8

Effective version octet (caller-set or default).

Source

pub fn reserved_value(&self) -> u16

Effective reserved header field (caller-set or default).

Source

pub fn entries(&self) -> &[RipEntry]

The route table entries that follow the header.

Source

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 Clone for Rip

Source§

fn clone(&self) -> Rip

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Rip

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Rip

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<R> Div<R> for Rip
where R: IntoPacket,

Source§

type Output = Packet

The resulting type after applying the / operator.
Source§

fn div(self, rhs: R) -> Self::Output

Performs the / operation. Read more
Source§

impl Layer for Rip

Source§

fn name(&self) -> &'static str

Stable layer name used by summaries and generated tools.
Source§

fn encoded_len(&self) -> usize

Encoded length for this layer before dependent auto-fill.
Source§

fn compile(&self, _ctx: &LayerContext<'_>, out: &mut Vec<u8>) -> Result<()>

Encode this layer into out.
Source§

fn summary(&self) -> String

A one-line layer summary.
Source§

fn inspection_fields(&self) -> Vec<(&'static str, String)>

Stable field/value pairs used by packet inspection output.
Source§

fn clone_layer(&self) -> Box<dyn Layer>

Clone this layer behind a trait object.
Source§

fn as_any(&self) -> &dyn Any

Return this layer as Any for typed packet access.
Source§

fn as_any_mut(&mut self) -> &mut dyn Any

Return this layer mutably as Any for typed packet access.
Source§

fn into_any(self: Box<Self>) -> Box<dyn Any>

Convert an owned trait object into Any for downcasting.
Source§

fn encoded_len_with_context(&self, _ctx: &LayerContext<'_>) -> usize

Encoded length for this layer once neighboring-layer context is known. Read more
Source§

fn consumes_following(&self) -> bool

Whether this layer’s compile() emits all following layers itself. Read more
Source§

fn transport_checksum_context( &self, _transport_protocol: u8, ) -> Option<TransportChecksumContext>

Return pseudo-header data for a following transport layer, when present.

Auto Trait Implementations§

§

impl Freeze for Rip

§

impl RefUnwindSafe for Rip

§

impl Send for Rip

§

impl Sync for Rip

§

impl Unpin for Rip

§

impl UnsafeUnpin for Rip

§

impl UnwindSafe for Rip

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoPacket for T
where T: Layer,

Source§

fn into_packet(self) -> Packet

Convert this value into a packet.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.