|
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")?; |
22 | | - pf.try_add_anchor(ANCHOR_NAME, pfctl::AnchorKind::Filter) |
23 | | - .chain_err(|| "Unable to add test filter anchor")?; |
24 | | - pf.try_add_anchor(ANCHOR_NAME, pfctl::AnchorKind::Redirect) |
25 | | - .chain_err(|| "Unable to add test redirect anchor")?; |
| 14 | +fn main() -> Result<(), Box<dyn std::error::Error>> { |
| 15 | + let mut pf = PfCtl::new()?; |
| 16 | + pf.try_add_anchor(ANCHOR_NAME, pfctl::AnchorKind::Filter)?; |
| 17 | + pf.try_add_anchor(ANCHOR_NAME, pfctl::AnchorKind::Redirect)?; |
26 | 18 |
|
27 | 19 | // Create the firewall rule instances |
28 | 20 | let pass_all_rule = FilterRuleBuilder::default() |
@@ -94,24 +86,15 @@ fn run() -> Result<()> { |
94 | 86 | .unwrap(); |
95 | 87 |
|
96 | 88 | // Add the rules to the test anchor |
97 | | - pf.add_rule(ANCHOR_NAME, &pass_all_rule) |
98 | | - .chain_err(|| "Unable to add rule")?; |
99 | | - pf.add_rule(ANCHOR_NAME, &pass_all_ipv4_quick_rule) |
100 | | - .chain_err(|| "Unable to add rule")?; |
101 | | - pf.add_rule(ANCHOR_NAME, &pass_all_ipv6_on_utun0_rule) |
102 | | - .chain_err(|| "Unable to add rule")?; |
103 | | - pf.add_rule(ANCHOR_NAME, &block_a_private_net_rule) |
104 | | - .chain_err(|| "Unable to add rule")?; |
105 | | - pf.add_rule(ANCHOR_NAME, &pass_all_icmp_echo_req) |
106 | | - .chain_err(|| "Unable to add rule")?; |
107 | | - pf.add_rule(ANCHOR_NAME, &pass_all_icmp_port_unreach) |
108 | | - .chain_err(|| "Unable to add rule")?; |
109 | | - pf.add_rule(ANCHOR_NAME, &pass_all_icmp_timex_transit) |
110 | | - .chain_err(|| "Unable to add rule")?; |
111 | | - pf.add_rule(ANCHOR_NAME, &pass_all_icmp_timex_reassembly) |
112 | | - .chain_err(|| "Unable to add rule")?; |
113 | | - pf.add_redirect_rule(ANCHOR_NAME, &redirect_incoming_tcp_from_port_3000_to_4000) |
114 | | - .chain_err(|| "Unable to add redirect rule")?; |
| 89 | + pf.add_rule(ANCHOR_NAME, &pass_all_rule)?; |
| 90 | + pf.add_rule(ANCHOR_NAME, &pass_all_ipv4_quick_rule)?; |
| 91 | + pf.add_rule(ANCHOR_NAME, &pass_all_ipv6_on_utun0_rule)?; |
| 92 | + pf.add_rule(ANCHOR_NAME, &block_a_private_net_rule)?; |
| 93 | + pf.add_rule(ANCHOR_NAME, &pass_all_icmp_echo_req)?; |
| 94 | + pf.add_rule(ANCHOR_NAME, &pass_all_icmp_port_unreach)?; |
| 95 | + pf.add_rule(ANCHOR_NAME, &pass_all_icmp_timex_transit)?; |
| 96 | + pf.add_rule(ANCHOR_NAME, &pass_all_icmp_timex_reassembly)?; |
| 97 | + pf.add_redirect_rule(ANCHOR_NAME, &redirect_incoming_tcp_from_port_3000_to_4000)?; |
115 | 98 |
|
116 | 99 | println!("Added a bunch of rules to the {} anchor.", ANCHOR_NAME); |
117 | 100 | println!("Run this command to remove them:"); |
|
0 commit comments