Created
February 9, 2020 23:03
-
-
Save qdm12/d17e85b2f2615a0381399e98292fe4b5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (c *configurator) runIptablesInstruction(instruction string) error { | |
flags := strings.Fields(instruction) | |
if output, err := c.commander.Run("iptables", flags...); err != nil { | |
return fmt.Errorf("failed executing %q: %s: %w", instruction, output, err) | |
} | |
return nil | |
} | |
func (c *configurator) Clear() error { | |
c.logger.Info("%s: clearing all rules", logPrefix) | |
return c.runIptablesInstructions([]string{ | |
"--flush", | |
"--delete-chain", | |
"-t nat --flush", | |
"-t nat --delete-chain", | |
}) | |
} | |
func (c *configurator) AcceptAll() error { | |
c.logger.Info("%s: accepting all traffic", logPrefix) | |
return c.runIptablesInstructions([]string{ | |
"-P INPUT ACCEPT", | |
"-P OUTPUT ACCEPT", | |
"-P FORWARD ACCEPT", | |
}) | |
} | |
func (c *configurator) BlockAll() error { | |
c.logger.Info("%s: blocking all traffic", logPrefix) | |
return c.runIptablesInstructions([]string{ | |
"-P INPUT DROP", | |
"-F OUTPUT", | |
"-P OUTPUT DROP", | |
"-P FORWARD DROP", | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment