mirror of
https://github.com/FAUSheppy/athq-vm-management
synced 2025-12-06 05:41:35 +01:00
feat: implement transparent proxy routing
This commit is contained in:
27
vm.py
27
vm.py
@@ -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 #
|
||||
|
||||
Reference in New Issue
Block a user