File tree Expand file tree Collapse file tree 4 files changed +43
-1
lines changed Expand file tree Collapse file tree 4 files changed +43
-1
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ license = "Apache-2.0"
77
88[dependencies ]
99# internal
10+ args = { workspace = true }
1011interface-manager = { workspace = true }
1112net = { workspace = true }
1213pipeline = { workspace = true }
Original file line number Diff line number Diff line change 88
99mod ctl;
1010mod io;
11-
1211mod nf;
12+ mod tapinit;
1313mod tests;
1414
1515// re-exports
1616pub use ctl:: IoManagerCtl ;
1717pub use io:: { IoManagerError , start_io} ;
1818pub use nf:: PktIo ;
1919pub use nf:: PktQueue ;
20+ pub use tapinit:: { tap_init, tap_init_async} ;
Original file line number Diff line number Diff line change 1+ // SPDX-License-Identifier: Apache-2.0
2+ // Copyright Open Network Fabric Authors
3+
4+ //! Tap initialization
5+
6+ use args:: InterfaceArg ;
7+ use interface_manager:: interface:: TapDevice ;
8+ use tokio:: runtime:: Runtime ;
9+ use tracing:: { error, info} ;
10+
11+ /// Creates a tap device for each of the [`InterfaceArg`]s provided.
12+ ///
13+ /// # Errors
14+ ///
15+ /// This function fails if any of the taps cannot be created.
16+ pub async fn tap_init_async ( ifargs : & [ InterfaceArg ] ) -> std:: io:: Result < ( ) > {
17+ info ! ( "Creating tap devices" ) ;
18+ for ifarg in ifargs. iter ( ) {
19+ if let Err ( e) = TapDevice :: open ( & ifarg. interface ) . await {
20+ error ! ( "Failed to create tap '{}':{e}" , ifarg. interface) ;
21+ return Err ( e) ;
22+ } else {
23+ info ! ( "Created tap device '{}'" , ifarg. interface) ;
24+ }
25+ }
26+ Ok ( ( ) )
27+ }
28+
29+ /// Creates a tap device for each of the [`InterfaceArg`]s provided.
30+ /// This is a sync wrapper to `tap_init_async`.
31+ ///
32+ /// # Errors
33+ ///
34+ /// This function fails if any of the taps cannot be created.
35+ pub fn tap_init ( port_specs : & [ InterfaceArg ] ) -> std:: io:: Result < ( ) > {
36+ Runtime :: new ( )
37+ . expect ( "Tokio runtime creation failed!" )
38+ . block_on ( tap_init_async ( port_specs) )
39+ }
You can’t perform that action at this time.
0 commit comments