Skip to content

Commit 070107f

Browse files
committed
ripv2: adjust maximum number of RTEs when authentication is enabled
According to RFC 2453, a Response packet in RIPv2 can contain up to 25 RTEs. However, when cryptographic authentication is used, the authentication trailer is encoded as a regular RTE. In that case, the effective maximum number of RTEs should be 23, not 24, to accommodate both the authentication header and trailer. It's worth noting that the authentication trailer may exceed 20 bytes when using algorithms other than Keyed-MD5. That fact should be taken into consideration when implementing those algorithms (e.g. HMAC-SHA1). Signed-off-by: Renato Westphal <[email protected]>
1 parent dead2e7 commit 070107f

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

holo-rip/src/output.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,10 @@ pub(crate) fn send_response<V>(
129129
}
130130

131131
// Send as many PDUs as necessary.
132-
let mut max_entries = V::Pdu::max_entries(iface.core.system.mtu.unwrap());
133-
if iface.core.config.auth_key.is_some() {
134-
// Reserve space for the authentication header.
135-
max_entries -= 1;
136-
}
132+
let max_entries = V::Pdu::max_entries(
133+
iface.core.system.mtu.unwrap(),
134+
iface.core.config.auth_algo,
135+
);
137136
for rtes in rtes
138137
.into_iter()
139138
.chunks(max_entries)

holo-rip/src/packet.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub trait PduVersion<
6262
fn set_command(&mut self, command: Command);
6363

6464
// Return maximum number of RTEs that can fit in the specified MTU size.
65-
fn max_entries(mtu: u32) -> usize;
65+
fn max_entries(mtu: u32, auth_algo: Option<CryptoAlgo>) -> usize;
6666

6767
// Return a reference to the PDU's RTEs.
6868
fn rtes(&self) -> &Vec<Self::Rte>;

holo-rip/src/ripng/packet.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use std::net::Ipv6Addr;
99
use bytes::{Buf, BufMut, Bytes, BytesMut};
1010
use derive_new::new;
1111
use holo_utils::bytes::{BytesExt, BytesMutExt, TLS_BUF};
12+
use holo_utils::crypto::CryptoAlgo;
1213
use holo_utils::ip::Ipv6NetworkExt;
1314
use ipnetwork::Ipv6Network;
1415
use num_traits::FromPrimitive;
@@ -196,7 +197,7 @@ impl PduVersion<Ipv6Addr, Ipv6Network, DecodeError> for Pdu {
196197
// #RTEs = INT | --------------------------------------------------- |
197198
// | RTE_size |
198199
// +- -+"
199-
fn max_entries(mtu: u32) -> usize {
200+
fn max_entries(mtu: u32, _auth_algo: Option<CryptoAlgo>) -> usize {
200201
const IPV6_HDR_LENGTH: usize = 40;
201202
const UDP_HDR_LENGTH: usize = 8;
202203

holo-rip/src/ripv2/packet.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,13 @@ impl PduVersion<Ipv4Addr, Ipv4Network, DecodeError> for Pdu {
360360
self.command = command;
361361
}
362362

363-
fn max_entries(_mtu: u32) -> usize {
364-
Self::MAX_ENTRIES
363+
fn max_entries(_mtu: u32, auth_algo: Option<CryptoAlgo>) -> usize {
364+
let mut max_entries = Self::MAX_ENTRIES;
365+
if auth_algo.is_some() {
366+
// Reserve space for the authentication header and trailer.
367+
max_entries -= 2;
368+
}
369+
max_entries
365370
}
366371

367372
fn rtes(&self) -> &Vec<Self::Rte> {

0 commit comments

Comments
 (0)