diff options
Diffstat (limited to 'tests/atf_python/sys')
| -rw-r--r-- | tests/atf_python/sys/net/tools.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/atf_python/sys/net/tools.py b/tests/atf_python/sys/net/tools.py index 567d9d4b21ac..44bd74d8578f 100644 --- a/tests/atf_python/sys/net/tools.py +++ b/tests/atf_python/sys/net/tools.py @@ -1,6 +1,7 @@ #!/usr/local/bin/python3 import json import os +import subprocess class ToolsHelper(object): @@ -14,6 +15,26 @@ class ToolsHelper(object): return os.popen(cmd).read() @classmethod + def pf_rules(cls, rules, verbose=True): + pf_conf = "" + for r in rules: + pf_conf = pf_conf + r + "\n" + + if verbose: + print("Set rules:") + print(pf_conf) + + ps = subprocess.Popen("/sbin/pfctl -g -f -", shell=True, + stdin=subprocess.PIPE) + ps.communicate(bytes(pf_conf, 'utf-8')) + ret = ps.wait() + if ret != 0: + raise Exception("Failed to set pf rules %d" % ret) + + if verbose: + cls.print_output("/sbin/pfctl -sr") + + @classmethod def print_output(cls, cmd: str, verbose=True): if verbose: print("======= {} =====".format(cmd)) |
