summaryrefslogtreecommitdiff
path: root/kvmd/apps/otgnet/netctl.py
diff options
context:
space:
mode:
Diffstat (limited to 'kvmd/apps/otgnet/netctl.py')
-rw-r--r--kvmd/apps/otgnet/netctl.py42
1 files changed, 19 insertions, 23 deletions
diff --git a/kvmd/apps/otgnet/netctl.py b/kvmd/apps/otgnet/netctl.py
index f186ea34..15b5ea8c 100644
--- a/kvmd/apps/otgnet/netctl.py
+++ b/kvmd/apps/otgnet/netctl.py
@@ -20,50 +20,46 @@
# ========================================================================== #
-from typing import List
-from typing import Dict
-
-
# =====
class BaseCtl:
- def get_command(self, direct: bool) -> List[str]:
+ def get_command(self, direct: bool) -> list[str]:
raise NotImplementedError
class IfaceUpCtl(BaseCtl):
- def __init__(self, base_cmd: List[str], iface: str) -> None:
+ def __init__(self, base_cmd: list[str], iface: str) -> None:
self.__base_cmd = base_cmd
self.__iface = iface
- def get_command(self, direct: bool) -> List[str]:
+ def get_command(self, direct: bool) -> list[str]:
return [*self.__base_cmd, "link", "set", self.__iface, ("up" if direct else "down")]
class IfaceAddIpCtl(BaseCtl):
- def __init__(self, base_cmd: List[str], iface: str, cidr: str) -> None:
+ def __init__(self, base_cmd: list[str], iface: str, cidr: str) -> None:
self.__base_cmd = base_cmd
self.__iface = iface
self.__cidr = cidr
- def get_command(self, direct: bool) -> List[str]:
+ def get_command(self, direct: bool) -> list[str]:
return [*self.__base_cmd, "address", ("add" if direct else "del"), self.__cidr, "dev", self.__iface]
class IptablesDropAllCtl(BaseCtl):
- def __init__(self, base_cmd: List[str], iface: str) -> None:
+ def __init__(self, base_cmd: list[str], iface: str) -> None:
self.__base_cmd = base_cmd
self.__iface = iface
- def get_command(self, direct: bool) -> List[str]:
+ def get_command(self, direct: bool) -> list[str]:
return [*self.__base_cmd, ("-A" if direct else "-D"), "INPUT", "-i", self.__iface, "-j", "DROP"]
class IptablesAllowIcmpCtl(BaseCtl):
- def __init__(self, base_cmd: List[str], iface: str) -> None:
+ def __init__(self, base_cmd: list[str], iface: str) -> None:
self.__base_cmd = base_cmd
self.__iface = iface
- def get_command(self, direct: bool) -> List[str]:
+ def get_command(self, direct: bool) -> list[str]:
return [
*self.__base_cmd,
("-A" if direct else "-D"), "INPUT", "-i", self.__iface, "-p", "icmp", "-j", "ACCEPT",
@@ -71,13 +67,13 @@ class IptablesAllowIcmpCtl(BaseCtl):
class IptablesAllowPortCtl(BaseCtl):
- def __init__(self, base_cmd: List[str], iface: str, port: int, tcp: bool) -> None:
+ def __init__(self, base_cmd: list[str], iface: str, port: int, tcp: bool) -> None:
self.__base_cmd = base_cmd
self.__iface = iface
self.__port = port
self.__proto = ("tcp" if tcp else "udp")
- def get_command(self, direct: bool) -> List[str]:
+ def get_command(self, direct: bool) -> list[str]:
return [
*self.__base_cmd,
("-A" if direct else "-D"), "INPUT", "-i", self.__iface, "-p", self.__proto,
@@ -86,11 +82,11 @@ class IptablesAllowPortCtl(BaseCtl):
class IptablesForwardOut(BaseCtl):
- def __init__(self, base_cmd: List[str], iface: str) -> None:
+ def __init__(self, base_cmd: list[str], iface: str) -> None:
self.__base_cmd = base_cmd
self.__iface = iface
- def get_command(self, direct: bool) -> List[str]:
+ def get_command(self, direct: bool) -> list[str]:
return [
*self.__base_cmd,
"--table", "nat",
@@ -100,11 +96,11 @@ class IptablesForwardOut(BaseCtl):
class IptablesForwardIn(BaseCtl):
- def __init__(self, base_cmd: List[str], iface: str) -> None:
+ def __init__(self, base_cmd: list[str], iface: str) -> None:
self.__base_cmd = base_cmd
self.__iface = iface
- def get_command(self, direct: bool) -> List[str]:
+ def get_command(self, direct: bool) -> list[str]:
return [
*self.__base_cmd,
("-A" if direct else "-D"), "FORWARD",
@@ -115,16 +111,16 @@ class IptablesForwardIn(BaseCtl):
class CustomCtl(BaseCtl):
def __init__(
self,
- direct_cmd: List[str],
- reverse_cmd: List[str],
- placeholders: Dict[str, str],
+ direct_cmd: list[str],
+ reverse_cmd: list[str],
+ placeholders: dict[str, str],
) -> None:
self.__direct_cmd = direct_cmd
self.__reverse_cmd = reverse_cmd
self.__placeholders = placeholders
- def get_command(self, direct: bool) -> List[str]:
+ def get_command(self, direct: bool) -> list[str]:
return [
part.format(**self.__placeholders)
for part in (self.__direct_cmd if direct else self.__reverse_cmd)