@@ -568,6 +568,24 @@ where
568568 & mut self . inner . routes
569569 }
570570
571+ /// Trigger the startup sequence for the interface.
572+ ///
573+ /// This method will call [Device::up] on the backing device.
574+ ///
575+ /// [Device::up]: ../phy/trait.Device.html#method.up
576+ pub fn up ( & mut self ) -> Result < ( ) > {
577+ self . device . up ( )
578+ }
579+
580+ /// Trigger the shutdown sequence for the interface.
581+ ///
582+ /// This method will call [Device::down] on the backing device.
583+ ///
584+ /// [Device::down]: ../phy/trait.Device.html#method.down
585+ pub fn down ( & mut self ) -> Result < ( ) > {
586+ self . device . down ( )
587+ }
588+
571589 /// Transmit packets queued in the given sockets, and receive packets queued
572590 /// in the device.
573591 ///
@@ -2107,7 +2125,9 @@ mod test {
21072125 let iface_builder = InterfaceBuilder :: new ( device) . ip_addrs ( ip_addrs) ;
21082126 #[ cfg( feature = "proto-igmp" ) ]
21092127 let iface_builder = iface_builder. ipv4_multicast_groups ( BTreeMap :: new ( ) ) ;
2110- let iface = iface_builder. finalize ( ) ;
2128+ let mut iface = iface_builder. finalize ( ) ;
2129+
2130+ iface. up ( ) . expect ( "Failed to bring device up!" ) ;
21112131
21122132 ( iface, SocketSet :: new ( vec ! [ ] ) )
21132133 }
@@ -2131,7 +2151,9 @@ mod test {
21312151 . ip_addrs ( ip_addrs) ;
21322152 #[ cfg( feature = "proto-igmp" ) ]
21332153 let iface_builder = iface_builder. ipv4_multicast_groups ( BTreeMap :: new ( ) ) ;
2134- let iface = iface_builder. finalize ( ) ;
2154+ let mut iface = iface_builder. finalize ( ) ;
2155+
2156+ iface. up ( ) . expect ( "Failed to bring device up!" ) ;
21352157
21362158 ( iface, SocketSet :: new ( vec ! [ ] ) )
21372159 }
@@ -2169,6 +2191,34 @@ mod test {
21692191 InterfaceBuilder :: new ( Loopback :: new ( Medium :: Ethernet ) ) . finalize ( ) ;
21702192 }
21712193
2194+ #[ test]
2195+ #[ cfg( feature = "medium-ethernet" ) ]
2196+ fn test_iface_updown ( ) {
2197+ let ( mut iface, _) = create_loopback_ethernet ( ) ;
2198+
2199+ iface. down ( ) . unwrap ( ) ;
2200+
2201+ assert ! ( iface. device_mut( ) . transmit( ) . is_none( ) ) ;
2202+
2203+ iface. up ( ) . unwrap ( ) ;
2204+
2205+ let tx_token = match iface. device_mut ( ) . transmit ( ) {
2206+ Some ( token) => token,
2207+ None => panic ! ( "Failed to bring up device!" ) ,
2208+ } ;
2209+
2210+ let buf = [ 0x00 ; 42 ] ;
2211+
2212+ tx_token. consume ( Instant :: from_millis ( 0 ) , buf. len ( ) , |tx_buf| {
2213+ tx_buf. copy_from_slice ( & buf[ ..] ) ;
2214+ Ok ( ( ) )
2215+ } ) . unwrap ( ) ;
2216+
2217+ iface. down ( ) . unwrap ( ) ;
2218+
2219+ assert ! ( iface. device_mut( ) . receive( ) . is_none( ) ) ;
2220+ }
2221+
21722222 #[ test]
21732223 #[ cfg( feature = "proto-ipv4" ) ]
21742224 fn test_no_icmp_no_unicast_ipv4 ( ) {
0 commit comments