Thibaut Vandervelden 3 年 前
コミット
7da0f16f8a
2 ファイル変更60 行追加72 行削除
  1. 30 50
      src/iface/interface.rs
  2. 30 22
      src/iface/neighbor.rs

+ 30 - 50
src/iface/interface.rs

@@ -2296,68 +2296,48 @@ mod test {
             });
         });
 
-        assert!(
-            iface
-                .inner
-                .is_subnet_broadcast(Ipv4Address([192, 168, 1, 255])),
-        );
-        assert!(
-            !iface
-                .inner
-                .is_subnet_broadcast(Ipv4Address([192, 168, 1, 254])),
-        );
+        assert!(iface
+            .inner
+            .is_subnet_broadcast(Ipv4Address([192, 168, 1, 255])),);
+        assert!(!iface
+            .inner
+            .is_subnet_broadcast(Ipv4Address([192, 168, 1, 254])),);
 
         iface.update_ip_addrs(|addrs| {
             addrs.iter_mut().next().map(|addr| {
                 *addr = IpCidr::Ipv4(Ipv4Cidr::new(Ipv4Address([192, 168, 23, 24]), 16));
             });
         });
-        assert!(
-            !iface
-                .inner
-                .is_subnet_broadcast(Ipv4Address([192, 168, 23, 255])),
-        );
-        assert!(
-            !iface
-                .inner
-                .is_subnet_broadcast(Ipv4Address([192, 168, 23, 254])),
-        );
-        assert!(
-            !iface
-                .inner
-                .is_subnet_broadcast(Ipv4Address([192, 168, 255, 254])),
-        );
-        assert!(
-            iface
-                .inner
-                .is_subnet_broadcast(Ipv4Address([192, 168, 255, 255])),
-        );
+        assert!(!iface
+            .inner
+            .is_subnet_broadcast(Ipv4Address([192, 168, 23, 255])),);
+        assert!(!iface
+            .inner
+            .is_subnet_broadcast(Ipv4Address([192, 168, 23, 254])),);
+        assert!(!iface
+            .inner
+            .is_subnet_broadcast(Ipv4Address([192, 168, 255, 254])),);
+        assert!(iface
+            .inner
+            .is_subnet_broadcast(Ipv4Address([192, 168, 255, 255])),);
 
         iface.update_ip_addrs(|addrs| {
             addrs.iter_mut().next().map(|addr| {
                 *addr = IpCidr::Ipv4(Ipv4Cidr::new(Ipv4Address([192, 168, 23, 24]), 8));
             });
         });
-        assert!(
-            !iface
-                .inner
-                .is_subnet_broadcast(Ipv4Address([192, 23, 1, 255])),
-        );
-        assert!(
-            !iface
-                .inner
-                .is_subnet_broadcast(Ipv4Address([192, 23, 1, 254])),
-        );
-        assert!(
-            !iface
-                .inner
-                .is_subnet_broadcast(Ipv4Address([192, 255, 255, 254])),
-        );
-        assert!(
-            iface
-                .inner
-                .is_subnet_broadcast(Ipv4Address([192, 255, 255, 255])),
-        );
+        assert!(!iface
+            .inner
+            .is_subnet_broadcast(Ipv4Address([192, 23, 1, 255])),);
+        assert!(!iface
+            .inner
+            .is_subnet_broadcast(Ipv4Address([192, 23, 1, 254])),);
+        assert!(!iface
+            .inner
+            .is_subnet_broadcast(Ipv4Address([192, 255, 255, 254])),);
+        assert!(iface
+            .inner
+            .is_subnet_broadcast(Ipv4Address([192, 255, 255, 255])),);
     }
 
     #[test]

+ 30 - 22
src/iface/neighbor.rs

@@ -227,26 +227,32 @@ mod test {
         let mut cache_storage = [Default::default(); 3];
         let mut cache = Cache::new(&mut cache_storage[..]);
 
-        assert!(!cache.lookup(&MOCK_IP_ADDR_1, Instant::from_millis(0)).found());
-        assert!(!cache.lookup(&MOCK_IP_ADDR_2, Instant::from_millis(0)).found());
+        assert!(!cache
+            .lookup(&MOCK_IP_ADDR_1, Instant::from_millis(0))
+            .found());
+        assert!(!cache
+            .lookup(&MOCK_IP_ADDR_2, Instant::from_millis(0))
+            .found());
 
         cache.fill(MOCK_IP_ADDR_1, HADDR_A, Instant::from_millis(0));
         assert_eq!(
             cache.lookup(&MOCK_IP_ADDR_1, Instant::from_millis(0)),
             Answer::Found(HADDR_A)
         );
-        assert!(!cache.lookup(&MOCK_IP_ADDR_2, Instant::from_millis(0)).found());
-        assert!(
-            !cache
-                .lookup(
-                    &MOCK_IP_ADDR_1,
-                    Instant::from_millis(0) + Cache::ENTRY_LIFETIME * 2
-                )
-                .found(),
-        );
+        assert!(!cache
+            .lookup(&MOCK_IP_ADDR_2, Instant::from_millis(0))
+            .found());
+        assert!(!cache
+            .lookup(
+                &MOCK_IP_ADDR_1,
+                Instant::from_millis(0) + Cache::ENTRY_LIFETIME * 2
+            )
+            .found(),);
 
         cache.fill(MOCK_IP_ADDR_1, HADDR_A, Instant::from_millis(0));
-        assert!(!cache.lookup(&MOCK_IP_ADDR_2, Instant::from_millis(0)).found());
+        assert!(!cache
+            .lookup(&MOCK_IP_ADDR_2, Instant::from_millis(0))
+            .found());
     }
 
     #[test]
@@ -259,14 +265,12 @@ mod test {
             cache.lookup(&MOCK_IP_ADDR_1, Instant::from_millis(0)),
             Answer::Found(HADDR_A)
         );
-        assert!(
-            !cache
-                .lookup(
-                    &MOCK_IP_ADDR_1,
-                    Instant::from_millis(0) + Cache::ENTRY_LIFETIME * 2
-                )
-                .found(),
-        );
+        assert!(!cache
+            .lookup(
+                &MOCK_IP_ADDR_1,
+                Instant::from_millis(0) + Cache::ENTRY_LIFETIME * 2
+            )
+            .found(),);
     }
 
     #[test]
@@ -321,10 +325,14 @@ mod test {
             cache.lookup(&MOCK_IP_ADDR_2, Instant::from_millis(1000)),
             Answer::Found(HADDR_B)
         );
-        assert!(!cache.lookup(&MOCK_IP_ADDR_4, Instant::from_millis(1000)).found());
+        assert!(!cache
+            .lookup(&MOCK_IP_ADDR_4, Instant::from_millis(1000))
+            .found());
 
         cache.fill(MOCK_IP_ADDR_4, HADDR_D, Instant::from_millis(300));
-        assert!(!cache.lookup(&MOCK_IP_ADDR_2, Instant::from_millis(1000)).found());
+        assert!(!cache
+            .lookup(&MOCK_IP_ADDR_2, Instant::from_millis(1000))
+            .found());
         assert_eq!(
             cache.lookup(&MOCK_IP_ADDR_4, Instant::from_millis(1000)),
             Answer::Found(HADDR_D)