Isolate talks to the WFP (Windows Filtering Platform) engine to set up firewall rules that result in complete host isolation. The traffic is allowed for the IP addresses specified in the permitted parameter. If the firewall rules already exist and the whitelist IP addresses are given, the rules are
(whitelist []net.IP)
| 227 | // are given, the rules are first removed and then recreated with the new |
| 228 | // allowed IP set. |
| 229 | func Isolate(whitelist []net.IP) error { |
| 230 | if fw == nil { |
| 231 | var err error |
| 232 | fw, err = newFirewall() |
| 233 | if err != nil { |
| 234 | return err |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | if err := fw.findAllowRules(); err != nil { |
| 239 | return err |
| 240 | } |
| 241 | |
| 242 | switch { |
| 243 | case fw.hasAllowRules(): |
| 244 | // rules were added and no new permitted |
| 245 | // addresses are supplied in the action |
| 246 | return nil |
| 247 | default: |
| 248 | // rules were not added, so we set up |
| 249 | // the rule to allow localhost in/out |
| 250 | // traffic in addition to permitted |
| 251 | // IP address. |
| 252 | // Block the remaining in/out traffic |
| 253 | if err := fw.allow(whitelist); err != nil { |
| 254 | return err |
| 255 | } |
| 256 | return fw.deny() |
| 257 | } |
| 258 | } |
no test coverage detected