feat: implement transparent proxy routing

This commit is contained in:
2022-12-21 20:02:45 +01:00
parent a046ec81e8
commit 15eceeb8ac
2 changed files with 39 additions and 0 deletions

27
vm.py
View File

@@ -48,6 +48,33 @@ class VM:
return components
def dumpIptables(self, remove=False):
entries = []
BASE = "iptables -t mangle -{option} "
RULE = "PREROUTING -p {proto} -s {ip} {port} -j MARK --set-xmark 0x1/0xffffffff"
PORT_SIMPLE = "--sport {port}"
PORT_MULTI = "--match multiport --sports {port}"
option = "A"
if remove:
option = "D"
for portStruct in filter(lambda p: p.get("transparent"), self.ports):
# port match #
port = portStruct.get("port")
partport = PORT_SIMPLE.format(port=port)
if type(port) == str and "-" in port:
port = port.replace("-", "")
part_port = PORT_MULTI.format(port=port)
entry = BASE.format(option=option)
entry += RULE.format(ip=self.ip, port=partport, proto=portStruct.get("proto", "tcp"))
entries.append(entry)
return entries
def dumpServerComponents(self):
# https components #