|
6 | 6 | // option. This file may not be copied, modified, or distributed
|
7 | 7 | // except according to those terms.
|
8 | 8 |
|
9 |
| -#[macro_use] |
10 |
| -extern crate error_chain; |
11 |
| - |
12 | 9 | use pfctl::{ipnetwork, FilterRuleBuilder, PfCtl, RedirectRuleBuilder};
|
13 | 10 | use std::net::Ipv4Addr;
|
14 | 11 |
|
15 |
| -error_chain! {} |
16 |
| -quick_main!(run); |
17 |
| - |
18 | 12 | static ANCHOR_NAME: &str = "test.anchor";
|
19 | 13 |
|
20 |
| -fn run() -> Result<()> { |
21 |
| - let mut pf = PfCtl::new().chain_err(|| "Unable to connect to PF")?; |
| 14 | +fn main() { |
| 15 | + let mut pf = PfCtl::new().expect("Unable to connect to PF"); |
22 | 16 | pf.try_add_anchor(ANCHOR_NAME, pfctl::AnchorKind::Filter)
|
23 |
| - .chain_err(|| "Unable to add test filter anchor")?; |
| 17 | + .expect("Unable to add test filter anchor"); |
24 | 18 | pf.try_add_anchor(ANCHOR_NAME, pfctl::AnchorKind::Redirect)
|
25 |
| - .chain_err(|| "Unable to add test redirect anchor")?; |
| 19 | + .expect("Unable to add test redirect anchor"); |
26 | 20 |
|
27 | 21 | // Create the firewall rule instances
|
28 | 22 | let pass_all_rule = FilterRuleBuilder::default()
|
@@ -95,26 +89,25 @@ fn run() -> Result<()> {
|
95 | 89 |
|
96 | 90 | // Add the rules to the test anchor
|
97 | 91 | pf.add_rule(ANCHOR_NAME, &pass_all_rule)
|
98 |
| - .chain_err(|| "Unable to add rule")?; |
| 92 | + .expect("Unable to add rule"); |
99 | 93 | pf.add_rule(ANCHOR_NAME, &pass_all_ipv4_quick_rule)
|
100 |
| - .chain_err(|| "Unable to add rule")?; |
| 94 | + .expect("Unable to add rule"); |
101 | 95 | pf.add_rule(ANCHOR_NAME, &pass_all_ipv6_on_utun0_rule)
|
102 |
| - .chain_err(|| "Unable to add rule")?; |
| 96 | + .expect("Unable to add rule"); |
103 | 97 | pf.add_rule(ANCHOR_NAME, &block_a_private_net_rule)
|
104 |
| - .chain_err(|| "Unable to add rule")?; |
| 98 | + .expect("Unable to add rule"); |
105 | 99 | pf.add_rule(ANCHOR_NAME, &pass_all_icmp_echo_req)
|
106 |
| - .chain_err(|| "Unable to add rule")?; |
| 100 | + .expect("Unable to add rule"); |
107 | 101 | pf.add_rule(ANCHOR_NAME, &pass_all_icmp_port_unreach)
|
108 |
| - .chain_err(|| "Unable to add rule")?; |
| 102 | + .expect("Unable to add rule"); |
109 | 103 | pf.add_rule(ANCHOR_NAME, &pass_all_icmp_timex_transit)
|
110 |
| - .chain_err(|| "Unable to add rule")?; |
| 104 | + .expect("Unable to add rule"); |
111 | 105 | pf.add_rule(ANCHOR_NAME, &pass_all_icmp_timex_reassembly)
|
112 |
| - .chain_err(|| "Unable to add rule")?; |
| 106 | + .expect("Unable to add rule"); |
113 | 107 | pf.add_redirect_rule(ANCHOR_NAME, &redirect_incoming_tcp_from_port_3000_to_4000)
|
114 |
| - .chain_err(|| "Unable to add redirect rule")?; |
| 108 | + .expect("Unable to add redirect rule"); |
115 | 109 |
|
116 | 110 | println!("Added a bunch of rules to the {} anchor.", ANCHOR_NAME);
|
117 | 111 | println!("Run this command to remove them:");
|
118 | 112 | println!("sudo pfctl -a {} -F all", ANCHOR_NAME);
|
119 |
| - Ok(()) |
120 | 113 | }
|
0 commit comments