netpkt/rip.rs#
Source: lib/netpkt/rip.rs
rip -- Routing Information Protocol messages (UDP port 520): version 2 after RFC 2453 and
version 1 after RFC 1058; requests and responses with their route entries, and the
authentication entry of RFC 2453 4.1 (recognised; simple passwords read and written)
RipView::parse(b) command, version, must-be-zero field, the complete 20-byte
entries (entry(i), entries(), routes() without the
authentication entry), auth(), trailing() bytes after them
Rte { afi, tag, addr, mask, next_hop, metric } one entry; Rte::v2 / Rte::v1 build route
entries, prefix() is the destination with a version 2 mask,
mbz_clear() checks the fields version 1 leaves zero
Auth { kind, data } the first entry with AFI 0xFFFF: AUTH_PASSWORD (16 bytes of
plain text: Auth::password, text()), AUTH_MD5 (RFC 4822: kind and
bytes only, not checked)
Rip { command, version, auth, entries } read / to_bytes / response / request_all /
is_request_all (one entry, address family 0, metric 16)
CMD_REQUEST, CMD_RESPONSE, AFI_INET, AFI_AUTH, AUTH_*, INFINITY (16), MAX_ENTRIES (25),
GROUP (224.0.0.9, RIPv2's multicast address), command_name
The view reads whatever is there: more than 25 entries, bytes after the last entry, a version
1 message with a must-be-zero field set or an unknown command are for the receiver to judge
(decode.rs reports them as problems). Version 1 entries carry no mask; the receiver infers it
from the address class and its own interfaces (RFC 1058 3.7).
/// the header: command, version, two bytes that must be zero
RIP_HDR: usize = 4
/// one entry (route or authentication)
RTE_LEN: usize = 20
/// entries a message holds at most (RFC 2453 3.6); 24 routes with an authentication entry
MAX_ENTRIES: usize = 25
CMD_REQUEST: u8 = 1
CMD_RESPONSE: u8 = 2
/// the address family of IPv4 routes
AFI_INET: u16 = 2
/// the address family that marks the authentication entry (RFC 2453 4.1)
AFI_AUTH: u16 = 0xFFFF
/// a plain-text password of 16 bytes (RFC 2453 4.1)
AUTH_PASSWORD: u16 = 2
/// keyed MD5 (RFC 4822)
AUTH_MD5: u16 = 3
/// the metric of an unreachable destination
INFINITY: u32 = 16
/// where version 2 sends its updates (RFC 2453 4.5)
GROUP: Ipv4 = Ipv4([224, 0, 0, 9])
fn command_name(c: u8) -> &'static strthe name of a command as capture tools show itstruct Rteone 20-byte entry; for the authentication entrytagholds the type and the 16 bytes fromaddron hold the authentication data (Auth reads them)afi: u16tag: u16-- the route tag (version 2; zero in version 1)addr: Ipv4mask: Ipv4-- the subnet mask (version 2; zero: not given)next_hop: Ipv4-- where to send packets for the destination (version 2; 0.0.0.0: to the sender)metric: u32
impl Rte
fn read(b: &[u8]) -> Rtean entry from its 20 bytes (the caller has checked the length)fn write(&self, b: &mut [u8])writes the entry into 20 bytesfn v2(prefix: Prefix4, next_hop: Ipv4, metric: u32, tag: u16) -> Rtea version 2 route: the destination with its mask, the next hop (0.0.0.0: the sender itself), the metric and the route tagfn v1(addr: Ipv4, metric: u32) -> Rtea version 1 route: the address alonefn prefix(&self) -> Option<Prefix4>the destination with its version 2 mask (None: no mask, or one with gaps)fn mbz_clear(&self) -> boolthe fields version 1 leaves zero are zero (route tag, mask, next hop)struct Auththe authentication entry of a version 2 messagekind: u16data: [u8; 16]
impl Auth
fn password(pw: &[u8]) -> Autha plain-text password: left-justified, padded with zero bytes, cut at 16 bytesfn text(&self) -> Option<String>the password of a plain-text entry (up to the first zero byte)struct RipView<'a>a received RIP message
impl<'a> RipView<'a>
fn parse(b: &'a [u8]) -> Option<RipView<'a>>at least the headerfn command(&self) -> u8fn version(&self) -> u8fn mbz(&self) -> u16the two header bytes that must be zerofn bytes(&self) -> &'a [u8]fn count(&self) -> usizecomplete entriesfn trailing(&self) -> usizebytes after the last complete entryfn entry(&self, i: usize) -> Option<Rte>entryi(authentication entries included)fn entries(&self) -> impl Iterator<Item = Rte> + '_fn auth(&self) -> Option<Auth>the authentication entry: only the first entry may be one (RFC 2453 4.1)fn routes(&self) -> impl Iterator<Item = Rte> + '_the entries after a leading authentication entrystruct Ripa RIP message to write (or one read)command: u8version: u8auth: Option<Auth>-- written as the first entryentries: Vec<Rte>
impl Rip
fn response(version: u8, entries: Vec<Rte>) -> Ripfn request_all(version: u8) -> Ripthe request for the whole routing table: a single entry with address family 0 and metric 16 (RFC 2453 3.9.1)fn is_request_all(&self) -> boolthis is the request for the whole tablefn read(v: &RipView) -> Ripfn to_bytes(&self) -> Vec<u8>the message as bytes (no limit on the number of entries: the sender splits at 25)