| 1 | extern crate iptablesrust-analyzer cargo iptables 0.6.0 iptables/; |
| 2 | |
| 3 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std panic/; |
| 4 | |
| 5 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 6 | fn test_newrust-analyzer cargo iptables 0.6.0 test_new().() { |
| 7 | natrust-analyzer cargo iptables 0.6.0 nat().(iptablesrust-analyzer cargo iptables 0.6.0 crate/::newrust-analyzer cargo iptables 0.6.0 new().(false).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), "NATNEW", "NATNEW2"); |
| 8 | filterrust-analyzer cargo iptables 0.6.0 filter().(iptablesrust-analyzer cargo iptables 0.6.0 crate/::newrust-analyzer cargo iptables 0.6.0 new().(false).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), "FILTERNEW"); |
| 9 | } |
| 10 | |
| 11 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 12 | fn test_oldrust-analyzer cargo iptables 0.6.0 test_old().() { |
| 13 | natrust-analyzer cargo iptables 0.6.0 nat().( |
| 14 | iptablesrust-analyzer cargo iptables 0.6.0 crate/::IPTablesrust-analyzer cargo iptables 0.6.0 IPTables# { |
| 15 | cmdrust-analyzer cargo iptables 0.6.0 IPTables#cmd.: "iptables", |
| 16 | has_waitrust-analyzer cargo iptables 0.6.0 IPTables#has_wait.: false, |
| 17 | has_checkrust-analyzer cargo iptables 0.6.0 IPTables#has_check.: false, |
| 18 | is_numericrust-analyzer cargo iptables 0.6.0 IPTables#is_numeric.: false, |
| 19 | }, |
| 20 | "NATOLD", |
| 21 | "NATOLD2", |
| 22 | ); |
| 23 | |
| 24 | filterrust-analyzer cargo iptables 0.6.0 filter().( |
| 25 | iptablesrust-analyzer cargo iptables 0.6.0 crate/::IPTablesrust-analyzer cargo iptables 0.6.0 IPTables# { |
| 26 | cmdrust-analyzer cargo iptables 0.6.0 IPTables#cmd.: "iptables", |
| 27 | has_waitrust-analyzer cargo iptables 0.6.0 IPTables#has_wait.: false, |
| 28 | has_checkrust-analyzer cargo iptables 0.6.0 IPTables#has_check.: false, |
| 29 | is_numericrust-analyzer cargo iptables 0.6.0 IPTables#is_numeric.: false, |
| 30 | }, |
| 31 | "FILTEROLD", |
| 32 | ); |
| 33 | } |
| 34 | |
| 35 | fn natrust-analyzer cargo iptables 0.6.0 nat().(ipt: iptablesrust-analyzer cargo iptables 0.6.0 crate/::IPTablesrust-analyzer cargo iptables 0.6.0 IPTables#, old_name: &str, new_name: &str) { |
| 36 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(ipt.new_chainrust-analyzer cargo iptables 0.6.0 impl#[IPTables]new_chain().("nat", old_name).is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 37 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(ipt.rename_chainrust-analyzer cargo iptables 0.6.0 impl#[IPTables]rename_chain().("nat", old_name, new_name).is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 38 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(ipt.appendrust-analyzer cargo iptables 0.6.0 impl#[IPTables]append().("nat", new_name, "-j ACCEPT").is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 39 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(ipt.existsrust-analyzer cargo iptables 0.6.0 impl#[IPTables]exists().("nat", new_name, "-j ACCEPT").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()); |
| 40 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(ipt.deleterust-analyzer cargo iptables 0.6.0 impl#[IPTables]delete().("nat", new_name, "-j ACCEPT").is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 41 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(ipt.insertrust-analyzer cargo iptables 0.6.0 impl#[IPTables]insert().("nat", new_name, "-j ACCEPT", 1).is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 42 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 43 | ipt.appendrust-analyzer cargo iptables 0.6.0 impl#[IPTables]append().( |
| 44 | "nat", |
| 45 | new_name, |
| 46 | "-m comment --comment \"double-quoted comment\" -j ACCEPT" |
| 47 | ) |
| 48 | .is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().(), |
| 49 | ); |
| 50 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 51 | ipt.existsrust-analyzer cargo iptables 0.6.0 impl#[IPTables]exists().( |
| 52 | "nat", |
| 53 | new_name, |
| 54 | "-m comment --comment \"double-quoted comment\" -j ACCEPT" |
| 55 | ) |
| 56 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 57 | ); |
| 58 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 59 | ipt.appendrust-analyzer cargo iptables 0.6.0 impl#[IPTables]append().( |
| 60 | "nat", |
| 61 | new_name, |
| 62 | "-m comment --comment 'single-quoted comment' -j ACCEPT" |
| 63 | ) |
| 64 | .is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().(), |
| 65 | ); |
| 66 | // The following `exists`-check has to use double-quotes, since the iptables output (if it |
| 67 | // doesn't have the check-functionality) will use double quotes. |
| 68 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 69 | ipt.existsrust-analyzer cargo iptables 0.6.0 impl#[IPTables]exists().( |
| 70 | "nat", |
| 71 | new_name, |
| 72 | "-m comment --comment \"single-quoted comment\" -j ACCEPT" |
| 73 | ) |
| 74 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 75 | ); |
| 76 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(ipt.flush_chainrust-analyzer cargo iptables 0.6.0 impl#[IPTables]flush_chain().("nat", new_name).is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 77 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().ipt.existsrust-analyzer cargo iptables 0.6.0 impl#[IPTables]exists().("nat", new_name, "-j ACCEPT").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()); |
| 78 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 79 | ipt.executerust-analyzer cargo iptables 0.6.0 impl#[IPTables]execute().("nat", &formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("-A {} -j ACCEPT", new_name)) |
| 80 | .is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().() |
| 81 | ); |
| 82 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(ipt.existsrust-analyzer cargo iptables 0.6.0 impl#[IPTables]exists().("nat", new_name, "-j ACCEPT").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()); |
| 83 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(ipt.flush_chainrust-analyzer cargo iptables 0.6.0 impl#[IPTables]flush_chain().("nat", new_name).is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 84 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(ipt.chain_existsrust-analyzer cargo iptables 0.6.0 impl#[IPTables]chain_exists().("nat", new_name).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()); |
| 85 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(ipt.delete_chainrust-analyzer cargo iptables 0.6.0 impl#[IPTables]delete_chain().("nat", new_name).is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 86 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().ipt.chain_existsrust-analyzer cargo iptables 0.6.0 impl#[IPTables]chain_exists().("nat", new_name).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()); |
| 87 | } |
| 88 | |
| 89 | fn filterrust-analyzer cargo iptables 0.6.0 filter().(ipt: iptablesrust-analyzer cargo iptables 0.6.0 crate/::IPTablesrust-analyzer cargo iptables 0.6.0 IPTables#, name: &str) { |
| 90 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(ipt.new_chainrust-analyzer cargo iptables 0.6.0 impl#[IPTables]new_chain().("filter", name).is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 91 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(ipt.insertrust-analyzer cargo iptables 0.6.0 impl#[IPTables]insert().("filter", name, "-j ACCEPT", 1).is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 92 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(ipt.replacerust-analyzer cargo iptables 0.6.0 impl#[IPTables]replace().("filter", name, "-j DROP", 1).is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 93 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(ipt.existsrust-analyzer cargo iptables 0.6.0 impl#[IPTables]exists().("filter", name, "-j DROP").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()); |
| 94 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().ipt.existsrust-analyzer cargo iptables 0.6.0 impl#[IPTables]exists().("filter", name, "-j ACCEPT").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()); |
| 95 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(ipt.deleterust-analyzer cargo iptables 0.6.0 impl#[IPTables]delete().("filter", name, "-j DROP").is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 96 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(ipt.listrust-analyzer cargo iptables 0.6.0 impl#[IPTables]list().("filter", name).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1); |
| 97 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 98 | ipt.executerust-analyzer cargo iptables 0.6.0 impl#[IPTables]execute().("filter", &formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("-A {} -j ACCEPT", name)) |
| 99 | .is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().() |
| 100 | ); |
| 101 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(ipt.existsrust-analyzer cargo iptables 0.6.0 impl#[IPTables]exists().("filter", name, "-j ACCEPT").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()); |
| 102 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 103 | ipt.appendrust-analyzer cargo iptables 0.6.0 impl#[IPTables]append().( |
| 104 | "filter", |
| 105 | name, |
| 106 | "-m comment --comment \"double-quoted comment\" -j ACCEPT" |
| 107 | ) |
| 108 | .is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().(), |
| 109 | ); |
| 110 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 111 | ipt.existsrust-analyzer cargo iptables 0.6.0 impl#[IPTables]exists().( |
| 112 | "filter", |
| 113 | name, |
| 114 | "-m comment --comment \"double-quoted comment\" -j ACCEPT" |
| 115 | ) |
| 116 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().() |
| 117 | ); |
| 118 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 119 | ipt.appendrust-analyzer cargo iptables 0.6.0 impl#[IPTables]append().( |
| 120 | "filter", |
| 121 | name, |
| 122 | "-m comment --comment 'single-quoted comment' -j ACCEPT" |
| 123 | ) |
| 124 | .is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().(), |
| 125 | ); |
| 126 | // The following `exists`-check has to use double-quotes, since the iptables output (if it |
| 127 | // doesn't have the check-functionality) will use double quotes. |
| 128 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 129 | ipt.existsrust-analyzer cargo iptables 0.6.0 impl#[IPTables]exists().( |
| 130 | "filter", |
| 131 | name, |
| 132 | "-m comment --comment \"single-quoted comment\" -j ACCEPT" |
| 133 | ) |
| 134 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 135 | ); |
| 136 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(ipt.flush_chainrust-analyzer cargo iptables 0.6.0 impl#[IPTables]flush_chain().("filter", name).is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 137 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(ipt.chain_existsrust-analyzer cargo iptables 0.6.0 impl#[IPTables]chain_exists().("filter", name).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()); |
| 138 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(ipt.delete_chainrust-analyzer cargo iptables 0.6.0 impl#[IPTables]delete_chain().("filter", name).is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 139 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().ipt.chain_existsrust-analyzer cargo iptables 0.6.0 impl#[IPTables]chain_exists().("filter", name).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()); |
| 140 | } |
| 141 | |
| 142 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 143 | fn test_get_policyrust-analyzer cargo iptables 0.6.0 test_get_policy().() { |
| 144 | let ipt = iptablesrust-analyzer cargo iptables 0.6.0 crate/::newrust-analyzer cargo iptables 0.6.0 new().(false).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 145 | |
| 146 | // filter |
| 147 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(ipt.get_policyrust-analyzer cargo iptables 0.6.0 impl#[IPTables]get_policy().("filter", "INPUT").is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 148 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(ipt.get_policyrust-analyzer cargo iptables 0.6.0 impl#[IPTables]get_policy().("filter", "FORWARD").is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 149 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(ipt.get_policyrust-analyzer cargo iptables 0.6.0 impl#[IPTables]get_policy().("filter", "OUTPUT").is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 150 | // mangle |
| 151 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(ipt.get_policyrust-analyzer cargo iptables 0.6.0 impl#[IPTables]get_policy().("mangle", "PREROUTING").is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 152 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(ipt.get_policyrust-analyzer cargo iptables 0.6.0 impl#[IPTables]get_policy().("mangle", "OUTPUT").is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 153 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(ipt.get_policyrust-analyzer cargo iptables 0.6.0 impl#[IPTables]get_policy().("mangle", "INPUT").is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 154 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(ipt.get_policyrust-analyzer cargo iptables 0.6.0 impl#[IPTables]get_policy().("mangle", "FORWARD").is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 155 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(ipt.get_policyrust-analyzer cargo iptables 0.6.0 impl#[IPTables]get_policy().("mangle", "POSTROUTING").is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 156 | // nat |
| 157 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(ipt.get_policyrust-analyzer cargo iptables 0.6.0 impl#[IPTables]get_policy().("nat", "PREROUTING").is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 158 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(ipt.get_policyrust-analyzer cargo iptables 0.6.0 impl#[IPTables]get_policy().("nat", "POSTROUTING").is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 159 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(ipt.get_policyrust-analyzer cargo iptables 0.6.0 impl#[IPTables]get_policy().("nat", "OUTPUT").is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 160 | // raw |
| 161 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(ipt.get_policyrust-analyzer cargo iptables 0.6.0 impl#[IPTables]get_policy().("raw", "PREROUTING").is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 162 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(ipt.get_policyrust-analyzer cargo iptables 0.6.0 impl#[IPTables]get_policy().("raw", "OUTPUT").is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 163 | // security |
| 164 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(ipt.get_policyrust-analyzer cargo iptables 0.6.0 impl#[IPTables]get_policy().("security", "INPUT").is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 165 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(ipt.get_policyrust-analyzer cargo iptables 0.6.0 impl#[IPTables]get_policy().("security", "OUTPUT").is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 166 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(ipt.get_policyrust-analyzer cargo iptables 0.6.0 impl#[IPTables]get_policy().("security", "FORWARD").is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 167 | |
| 168 | // Wrong table |
| 169 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(ipt.get_policyrust-analyzer cargo iptables 0.6.0 impl#[IPTables]get_policy().("not_existant", "_").is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 170 | // Wrong chain |
| 171 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(ipt.get_policyrust-analyzer cargo iptables 0.6.0 impl#[IPTables]get_policy().("filter", "_").is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 172 | } |
| 173 | |
| 174 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 175 | #[ignore] |
| 176 | fn test_set_policyrust-analyzer cargo iptables 0.6.0 test_set_policy().() { |
| 177 | let ipt = iptablesrust-analyzer cargo iptables 0.6.0 crate/::newrust-analyzer cargo iptables 0.6.0 new().(false).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 178 | |
| 179 | // Since we can only set policies on built-in chains, we have to retain the policy of the chain |
| 180 | // before setting it, to restore it to its original state. |
| 181 | let current_policy = ipt.get_policyrust-analyzer cargo iptables 0.6.0 impl#[IPTables]get_policy().("mangle", "FORWARD").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 182 | |
| 183 | // If the following assertions fail or any other panic occurs, we still have to ensure not to |
| 184 | // change the policy for the user. |
| 185 | let result = panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std panic/::catch_unwindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std panic/catch_unwind().(|| { |
| 186 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(ipt.set_policyrust-analyzer cargo iptables 0.6.0 impl#[IPTables]set_policy().("mangle", "FORWARD", "DROP").is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 187 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(ipt.get_policyrust-analyzer cargo iptables 0.6.0 impl#[IPTables]get_policy().("mangle", "FORWARD").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), "DROP"); |
| 188 | }); |
| 189 | |
| 190 | // Reset the policy to the retained value |
| 191 | ipt.set_policyrust-analyzer cargo iptables 0.6.0 impl#[IPTables]set_policy().("mangle", "FORWARD", ¤t_policy) |
| 192 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 193 | |
| 194 | // "Rethrow" a potential caught panic |
| 195 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(result.is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().()); |
| 196 | } |