Browse Source

Address code review

- Split mldv2_router_alert() in two, adding a new function named
  push_padn_option(u8) to emit a PadN hop-by-hop option after any
  other options have been pushed already
- When emiting ReportRecordReprs, remove the conditional block
  that attempted to copy payload data over the destination record
Lucas Villa Real 10 months ago
parent
commit
4d25db83c8
3 changed files with 11 additions and 8 deletions
  1. 3 1
      src/iface/interface/ipv6.rs
  2. 8 3
      src/wire/ipv6hbh.rs
  3. 0 4
      src/wire/mld.rs

+ 3 - 1
src/iface/interface/ipv6.rs

@@ -514,7 +514,9 @@ impl InterfaceInner {
             data: &[],
         };
 
-        let hbh_repr = Ipv6HopByHopRepr::mldv2_router_alert(0);
+        let mut hbh_repr = Ipv6HopByHopRepr::mldv2_router_alert();
+        hbh_repr.push_padn_option(0);
+
         let mld_repr = MldRepr::ReportRecordReprs(records);
         let records_len = records
             .iter()

+ 8 - 3
src/wire/ipv6hbh.rs

@@ -107,10 +107,9 @@ impl<'a> Repr<'a> {
         }
     }
 
-    /// The hop-by-hop header containing a PadN and a MLDv2 router alert option.
-    pub fn mldv2_router_alert(n: u8) -> Self {
+    /// The hop-by-hop header containing a MLDv2 router alert option
+    pub fn mldv2_router_alert() -> Self {
         let mut options = Vec::new();
-        options.push(Ipv6OptionRepr::PadN(n)).unwrap();
         options
             .push(Ipv6OptionRepr::RouterAlert(
                 RouterAlert::MulticastListenerDiscovery,
@@ -118,6 +117,12 @@ impl<'a> Repr<'a> {
             .unwrap();
         Self { options }
     }
+
+    /// Append a PadN option to the vector of hop-by-hop options
+    pub fn push_padn_option(&mut self, n: u8) {
+        self.options.push(Ipv6OptionRepr::PadN(n)).unwrap();
+    }
+
 }
 
 #[cfg(test)]

+ 0 - 4
src/wire/mld.rs

@@ -447,10 +447,6 @@ impl<'a> Repr<'a> {
                 packet.set_nr_mcast_addr_rcrds(records.len() as u16);
                 let mut payload = packet.payload_mut();
                 for record in *records {
-                    if record.payload.len() == payload.len() {
-                        // TODO: handle the case where the payload sizes are different
-                        payload.copy_from_slice(record.payload);
-                    }
                     record.emit(&mut AddressRecord::new_unchecked(&mut *payload));
                     payload = &mut payload[record.buffer_len()..];
                 }