From 07decd8707905817b675fad8bf0621860540b7f6 Mon Sep 17 00:00:00 2001 From: Darryl Nixon Date: Sun, 2 Jul 2023 14:30:36 -0700 Subject: [PATCH] Swap back to MANGLE table, and remove extraneous packet payload check since .mangle() accepts unchanged packets --- drawbridge/drawbridge.py | 17 +++++++++-------- drawbridge/net_queue.py | 4 ++-- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/drawbridge/drawbridge.py b/drawbridge/drawbridge.py index cedb66c..c75d8a1 100644 --- a/drawbridge/drawbridge.py +++ b/drawbridge/drawbridge.py @@ -36,15 +36,16 @@ class DrawBridge: def run(self): asyncio.run(self.raise_bridges()) - async def _listen(self, listener, callback: Callable) -> None: - for packet in listener: - original = packet.payload - if asyncio.iscoroutinefunction(callback): - packet.payload = await callback(packet.payload) - else: - packet.payload = callback(packet.payload) - if packet.payload != original: + async def _listen(self, connection, callback: Callable) -> None: + try: + for packet in connection: + if asyncio.iscoroutinefunction(callback): + packet.payload = await callback(packet.payload) + else: + packet.payload = callback(packet.payload) packet.mangle() + except fnfqueue.BufferOverflowException: + logger.warning("Packets arriving too quickly") def _delete_rules(self): for queue in self.net_queues: diff --git a/drawbridge/net_queue.py b/drawbridge/net_queue.py index 91cc90f..4fa85fa 100644 --- a/drawbridge/net_queue.py +++ b/drawbridge/net_queue.py @@ -44,12 +44,12 @@ class NetQueue: return rule def write_rule(self): - table = iptc.Table(iptc.Table.NAT) + table = iptc.Table(iptc.Table.MANGLE) chain = iptc.Chain(table, "PREROUTING") chain.insert_rule(self.rule) def delete_rule(self): - table = iptc.Table(iptc.Table.NAT) + table = iptc.Table(iptc.Table.MANGLE) chain = iptc.Chain(table, "PREROUTING") try: chain.delete_rule(self.rule)