@@ -725,7 +725,8 @@ impl Jail for LinuxJail {
725725 info ! ( "Cleaning up orphaned Linux jail: {}" , jail_id) ;
726726
727727 let namespace_name = format ! ( "httpjail_{}" , jail_id) ;
728- let veth_host = format ! ( "veth_h_{}" , jail_id) ;
728+ let veth_host = format ! ( "vh_{}" , jail_id) ;
729+ let comment = format ! ( "httpjail-{}" , namespace_name) ;
729730
730731 // Clean up namespace-specific config directory
731732 let netns_etc = format ! ( "/etc/netns/{}" , namespace_name) ;
@@ -743,57 +744,56 @@ impl Jail for LinuxJail {
743744 . args ( [ "link" , "del" , & veth_host] )
744745 . output ( ) ;
745746
746- // Clean up iptables rules with matching comment
747- let comment = format ! ( "httpjail-{}" , namespace_name) ;
748-
749- // Remove MASQUERADE rule
750- let _ = Command :: new ( "iptables" )
751- . args ( [
752- "-t" ,
753- "nat" ,
754- "-D" ,
747+ // Create temporary IPTablesRule objects to clean up iptables rules
748+ // Their Drop impl will remove the rules
749+ let _rules = vec ! [
750+ // MASQUERADE rule
751+ IPTablesRule :: new_existing(
752+ Some ( "nat" ) ,
755753 "POSTROUTING" ,
756- "-s" ,
757- LINUX_NS_SUBNET ,
758- "-m" ,
759- "comment" ,
760- "--comment" ,
761- & comment,
762- "-j" ,
763- "MASQUERADE" ,
764- ] )
765- . output ( ) ;
766-
767- // Remove FORWARD rules
768- let _ = Command :: new ( "iptables" )
769- . args ( [
770- "-D" ,
754+ vec![
755+ "-s" ,
756+ LINUX_NS_SUBNET ,
757+ "-m" ,
758+ "comment" ,
759+ "--comment" ,
760+ & comment,
761+ "-j" ,
762+ "MASQUERADE" ,
763+ ] ,
764+ ) ,
765+ // FORWARD source rule
766+ IPTablesRule :: new_existing(
767+ None ,
771768 "FORWARD" ,
772- "-s" ,
773- LINUX_NS_SUBNET ,
774- "-m" ,
775- "comment ",
776- "-- comment",
777- & comment,
778- "-j" ,
779- "ACCEPT ",
780- ] )
781- . output ( ) ;
782-
783- let _ = Command :: new ( "iptables" )
784- . args ( [
785- "-D" ,
769+ vec! [
770+ "-s" ,
771+ LINUX_NS_SUBNET ,
772+ "-m ",
773+ " comment",
774+ "-- comment" ,
775+ & comment ,
776+ "-j ",
777+ "ACCEPT" ,
778+ ] ,
779+ ) ,
780+ // FORWARD destination rule
781+ IPTablesRule :: new_existing (
782+ None ,
786783 "FORWARD" ,
787- "-d" ,
788- LINUX_NS_SUBNET ,
789- "-m" ,
790- "comment" ,
791- "--comment" ,
792- & comment,
793- "-j" ,
794- "ACCEPT" ,
795- ] )
796- . output ( ) ;
784+ vec![
785+ "-d" ,
786+ LINUX_NS_SUBNET ,
787+ "-m" ,
788+ "comment" ,
789+ "--comment" ,
790+ & comment,
791+ "-j" ,
792+ "ACCEPT" ,
793+ ] ,
794+ ) ,
795+ ] ;
796+ // Rules will be cleaned up when _rules goes out of scope
797797
798798 Ok ( ( ) )
799799 }
0 commit comments