-
Notifications
You must be signed in to change notification settings - Fork 179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add free bsd firewall #2606
base: main
Are you sure you want to change the base?
Add free bsd firewall #2606
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT license. | ||
import re | ||
|
||
from lisa.base_tools import Service | ||
from lisa.executable import Tool | ||
from lisa.tools import Cat, Sed | ||
|
||
|
||
class Firewall(Tool): | ||
|
@@ -35,6 +37,11 @@ def stop(self) -> None: | |
iptables = self.node.tools[Iptables] | ||
iptables.stop() | ||
return | ||
cmd_result = self.node.execute("command -v ipf", shell=True) | ||
if 0 == cmd_result.exit_code: | ||
ipf = self.node.tools[Ipf] | ||
ipf.stop() | ||
return | ||
|
||
|
||
class Ufw(Tool): | ||
|
@@ -149,3 +156,56 @@ def can_install(self) -> bool: | |
def stop(self) -> None: | ||
service = self.node.tools[Service] | ||
service.stop_service("firewalld") | ||
|
||
|
||
class Ipf(Tool): | ||
_ipf_enable_pattern = re.compile( | ||
r"(?P<param>ipfilter_enable=):*(?P<value>.*)$", re.MULTILINE | ||
) | ||
|
||
@property | ||
def command(self) -> str: | ||
return "ipf" | ||
|
||
@property | ||
def can_install(self) -> bool: | ||
return False | ||
|
||
def stop(self) -> None: | ||
cmd_result = self.node.tools[Cat].read( | ||
file="/etc/rc.conf", | ||
sudo=True, | ||
force_run=True, | ||
) | ||
ipf_enable_found = re.search(self._ipf_enable_pattern, cmd_result) | ||
if ipf_enable_found: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to reload the service using this file rc.conf file? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Hmm think we can do "service ipfilter start" to start IPF. |
||
self.node.tools[Sed].substitute( | ||
regexp="YES", | ||
replacement="NO", | ||
file="/etc/rc.conf", | ||
match_lines="ipfilter_enable", | ||
sudo=True, | ||
) | ||
|
||
def start(self) -> None: | ||
cmd_result = self.node.tools[Cat].read( | ||
file="/etc/rc.conf", | ||
sudo=True, | ||
force_run=True, | ||
) | ||
ipf_enable_found = re.search(self._ipf_enable_pattern, cmd_result) | ||
if ipf_enable_found: | ||
self.node.tools[Sed].substitute( | ||
regexp="NO", | ||
replacement="YES", | ||
file="/etc/rc.conf", | ||
match_lines="ipfilter_enable", | ||
sudo=True, | ||
) | ||
else: | ||
self.run( | ||
'echo "ipf_enable="YES"" | sudo tee -a /etc/rc.conf >/dev/null', | ||
sharsonia marked this conversation as resolved.
Show resolved
Hide resolved
|
||
shell=True, | ||
sudo=True, | ||
force_run=True, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please add few example patterns here?