55use anyhow:: { Context , Result } ;
66use std:: process:: Command ;
77
8- use crate :: firewall:: backend:: { FirewallBackend , FirewallChain , FirewallRule , FirewallTable } ;
8+ use crate :: firewall:: backend:: FirewallBackend ;
99
1010/// nftables table
1111#[ derive( Debug , Clone ) ]
@@ -21,9 +21,11 @@ impl NfTable {
2121 name : name. into ( ) ,
2222 }
2323 }
24+ }
2425
25- fn to_string ( & self ) -> String {
26- format ! ( "{} {}" , self . family, self . name)
26+ impl std:: fmt:: Display for NfTable {
27+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
28+ write ! ( f, "{} {}" , self . family, self . name)
2729 }
2830}
2931
@@ -94,7 +96,7 @@ impl NfTablesBackend {
9496 /// Create a table
9597 pub fn create_table ( & self , table : & NfTable ) -> Result < ( ) > {
9698 let output = Command :: new ( "nft" )
97- . args ( & [ "add" , "table" , & table. to_string ( ) ] )
99+ . args ( [ "add" , "table" , & table. to_string ( ) ] )
98100 . output ( )
99101 . context ( "Failed to create nftables table" ) ?;
100102
@@ -111,7 +113,7 @@ impl NfTablesBackend {
111113 /// Delete a table
112114 pub fn delete_table ( & self , table : & NfTable ) -> Result < ( ) > {
113115 let output = Command :: new ( "nft" )
114- . args ( & [ "delete" , "table" , & table. to_string ( ) ] )
116+ . args ( [ "delete" , "table" , & table. to_string ( ) ] )
115117 . output ( )
116118 . context ( "Failed to delete nftables table" ) ?;
117119
@@ -135,7 +137,7 @@ impl NfTablesBackend {
135137 ) ;
136138
137139 let output = Command :: new ( "nft" )
138- . args ( & [ "-c" , & cmd] )
140+ . args ( [ "-c" , & cmd] )
139141 . output ( )
140142 . context ( "Failed to create nftables chain" ) ?;
141143
@@ -154,7 +156,7 @@ impl NfTablesBackend {
154156 let cmd = format ! ( "delete chain {} {}" , chain. table. to_string( ) , chain. name) ;
155157
156158 let output = Command :: new ( "nft" )
157- . args ( & [ "-c" , & cmd] )
159+ . args ( [ "-c" , & cmd] )
158160 . output ( )
159161 . context ( "Failed to delete nftables chain" ) ?;
160162
@@ -178,7 +180,7 @@ impl NfTablesBackend {
178180 ) ;
179181
180182 let output = Command :: new ( "nft" )
181- . args ( & [ "-c" , & cmd] )
183+ . args ( [ "-c" , & cmd] )
182184 . output ( )
183185 . context ( "Failed to add nftables rule" ) ?;
184186
@@ -202,7 +204,7 @@ impl NfTablesBackend {
202204 ) ;
203205
204206 let output = Command :: new ( "nft" )
205- . args ( & [ "-c" , & cmd] )
207+ . args ( [ "-c" , & cmd] )
206208 . output ( )
207209 . context ( "Failed to delete nftables rule" ) ?;
208210
@@ -229,7 +231,7 @@ impl NfTablesBackend {
229231 let cmd = format ! ( "flush chain {} {}" , chain. table. to_string( ) , chain. name) ;
230232
231233 let output = Command :: new ( "nft" )
232- . args ( & [ "-c" , & cmd] )
234+ . args ( [ "-c" , & cmd] )
233235 . output ( )
234236 . context ( "Failed to flush nftables chain" ) ?;
235237
@@ -248,7 +250,7 @@ impl NfTablesBackend {
248250 let cmd = format ! ( "list chain {} {}" , chain. table. to_string( ) , chain. name) ;
249251
250252 let output = Command :: new ( "nft" )
251- . args ( & [ "-c" , & cmd] )
253+ . args ( [ "-c" , & cmd] )
252254 . output ( )
253255 . context ( "Failed to list nftables rules" ) ?;
254256
0 commit comments