diff options
| author | Kristof Provost <kp@FreeBSD.org> | 2023-07-13 06:34:54 +0000 |
|---|---|---|
| committer | Kristof Provost <kp@FreeBSD.org> | 2023-08-04 13:24:16 +0000 |
| commit | b23dbabb7f3edb3f323a64f03e37be2c9a8b2a45 (patch) | |
| tree | bae26427b03e995d675ad5641e973ab67fe25414 /tests/atf_python/sys | |
| parent | 76afcbb52492f9b3e72ee7d4c4ed0a54c25e1c48 (diff) | |
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)) |
