@@ -568,6 +568,24 @@ where
568
568
& mut self . inner . routes
569
569
}
570
570
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
+
571
589
/// Transmit packets queued in the given sockets, and receive packets queued
572
590
/// in the device.
573
591
///
@@ -2107,7 +2125,9 @@ mod test {
2107
2125
let iface_builder = InterfaceBuilder :: new ( device) . ip_addrs ( ip_addrs) ;
2108
2126
#[ cfg( feature = "proto-igmp" ) ]
2109
2127
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!" ) ;
2111
2131
2112
2132
( iface, SocketSet :: new ( vec ! [ ] ) )
2113
2133
}
@@ -2131,7 +2151,9 @@ mod test {
2131
2151
. ip_addrs ( ip_addrs) ;
2132
2152
#[ cfg( feature = "proto-igmp" ) ]
2133
2153
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!" ) ;
2135
2157
2136
2158
( iface, SocketSet :: new ( vec ! [ ] ) )
2137
2159
}
@@ -2169,6 +2191,34 @@ mod test {
2169
2191
InterfaceBuilder :: new ( Loopback :: new ( Medium :: Ethernet ) ) . finalize ( ) ;
2170
2192
}
2171
2193
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
+
2172
2222
#[ test]
2173
2223
#[ cfg( feature = "proto-ipv4" ) ]
2174
2224
fn test_no_icmp_no_unicast_ipv4 ( ) {
0 commit comments