77from plugins .system .abstract import FirewallSystem
88from plugins .system .abstract_rule_match import RuleMatchResult
99from plugins .translate .abstract import Ruleset , Table , Chain , Rule
10- from simulator .packet import PACKET_KINDS , PacketTCPUDP
10+ from simulator .packet import PacketIP , PacketTCPUDP
1111from utils .logger import log_debug , log_info , log_warn
1212
1313
@@ -16,7 +16,7 @@ def __init__(self, fw, run_tables):
1616 self ._fw = fw
1717 self ._run_tables = run_tables
1818
19- def _get_chain_by_name_and_family (self , packet : PACKET_KINDS , table : Table , name : str , family : str ) -> ( Chain , None ) :
19+ def _get_chain_by_name_and_family (self , packet : PacketIP , table : Table , name : str , family : str ) -> Chain | None :
2020 for t in self ._run_tables .get_tables (packet ):
2121 if t .name != table .name or t .family != table .family or t .priority != table .priority :
2222 continue
@@ -41,7 +41,7 @@ def _log_match(self, chain: Chain, rule: Rule, debug: bool = False):
4141 log_info (label = 'Firewall' , v1 = msg , v2 = v2 )
4242
4343 # pylint: disable=R0911,R0912
44- def process (self , chain : Chain , packet : PACKET_KINDS ) -> ( bool , ( Rule , None )) :
44+ def process (self , chain : Chain , packet : PacketIP ) -> tuple [ bool , Rule | None ] :
4545 """
4646 :param chain: Firewall chain to process; if any rule has an action that targets another chain - it will also be processed
4747 :param packet: Packet to match
@@ -52,8 +52,8 @@ def process(self, chain: Chain, packet: PACKET_KINDS) -> (bool, (Rule, None)):
5252
5353 rule_matcher = self ._fw .system .get_rule_matcher ()(chain .run_table )
5454 chain .rules .sort (key = lambda r : r .seq , reverse = False )
55- lazy_action : ( None , RuleAction ) = None
56- lazy_rule : ( None , Rule ) = None
55+ lazy_action : RuleAction | None = None
56+ lazy_rule : Rule | None = None
5757
5858 for rule in chain .rules :
5959 result : RuleMatchResult = rule_matcher .matches (packet = packet , rule = rule )
@@ -162,7 +162,7 @@ def __init__(self, fw):
162162 self ._run_chains = RunFirewallChain (fw = fw , run_tables = self )
163163
164164 @staticmethod
165- def _is_matching_table (packet : PACKET_KINDS , table : Table , ignore_type : list [str ] = None ) -> bool :
165+ def _is_matching_table (packet : PacketIP , table : Table , ignore_type : list [str ] = None ) -> bool :
166166 if ignore_type is not None and table .type in ignore_type :
167167 return False
168168
@@ -177,14 +177,14 @@ def _is_matching_table(packet: PACKET_KINDS, table: Table, ignore_type: list[str
177177
178178 return False
179179
180- def get_tables (self , packet : PACKET_KINDS , ignore_type : list [str ] = None ) -> list [Table ]:
180+ def get_tables (self , packet : PacketIP , ignore_type : list [str ] = None ) -> list [Table ]:
181181 return [
182182 t for t in self ._fw .ruleset .tables
183183 if self ._is_matching_table (packet = packet , table = t , ignore_type = ignore_type )
184184 ]
185185
186186 @staticmethod
187- def _is_matching_chain (packet : PACKET_KINDS , chain : Chain , ignore_type : list [str ] = None ) -> bool :
187+ def _is_matching_chain (packet : PacketIP , chain : Chain , ignore_type : list [str ] = None ) -> bool :
188188 if ignore_type is not None and chain .type in ignore_type :
189189 return False
190190
@@ -200,7 +200,7 @@ def _is_matching_chain(packet: PACKET_KINDS, chain: Chain, ignore_type: list[str
200200
201201 return False
202202
203- def get_chains (self , packet : PACKET_KINDS , table : Table , ignore_type : list [str ] = None ):
203+ def get_chains (self , packet : PacketIP , table : Table , ignore_type : list [str ] = None ):
204204 return [
205205 c for c in table .chains
206206 if self ._is_matching_chain (packet = packet , chain = c , ignore_type = ignore_type )
@@ -283,8 +283,8 @@ def _inherit_table_priority_to_chain(table: Table, chain: Chain):
283283 chain .priority = table .priority
284284
285285 def _process_by_table_prio (
286- self , tables : list [Table ], callback_chain_filter : Callable [[Chain ], bool ], packet : PACKET_KINDS ,
287- ) -> ( bool , ( Rule , None )) :
286+ self , tables : list [Table ], callback_chain_filter : Callable [[Chain ], bool ], packet : PacketIP ,
287+ ) -> tuple [ bool , Rule | None ] :
288288 for table in self ._sort_tables_by_priority (tables ):
289289 chains = [
290290 c for c in self .get_chains (packet = packet , table = table )
@@ -300,8 +300,8 @@ def _process_by_table_prio(
300300 return True , None
301301
302302 def _process_by_chain_prio (
303- self , tables : list [Table ], callback_chain_filter : Callable [[Chain ], bool ], packet : PACKET_KINDS ,
304- ) -> ( bool , ( Rule , None )) :
303+ self , tables : list [Table ], callback_chain_filter : Callable [[Chain ], bool ], packet : PacketIP ,
304+ ) -> tuple [ bool , Rule | None ] :
305305 chains : list [Chain ] = []
306306 for table in tables :
307307 for chain in self .get_chains (packet = packet , table = table ):
@@ -323,7 +323,7 @@ def _process_by_chain_prio(
323323
324324 return True , None
325325
326- def _process_chain (self , chain : Chain , packet : PACKET_KINDS ) -> ( bool , ( Rule , None )) :
326+ def _process_chain (self , chain : Chain , packet : PacketIP ) -> tuple [ bool , Rule | None ] :
327327 """
328328 see: RunFirewallChain.process
329329 """
@@ -343,7 +343,7 @@ def _chain_filter_pre_routing(self, chain: Chain, flow: type[Flow]) -> bool:
343343 before_dnat = self ._is_chain_before_eq (chain = chain , ** self ._fw .system .FIREWALL_NAT [flow ]['dnat' ])
344344 return chain .type != chain .TYPE_NAT and before_dnat
345345
346- def process_pre_routing (self , packet : PACKET_KINDS , flow : type [Flow ]) -> ( bool , ( Rule , None )) :
346+ def process_pre_routing (self , packet : PacketIP , flow : type [Flow ]) -> tuple [ bool , Rule | None ] :
347347 """
348348 :param packet: Packet to process
349349 :param flow: traffic flow-type
@@ -368,7 +368,7 @@ def _chain_filter_dnat(self, chain: Chain, flow: type[Flow]) -> bool:
368368 chain .hook == chain_dnat ['hook' ] and \
369369 chain .priority == chain_dnat ['priority' ]
370370
371- def process_dnat (self , packet : PACKET_KINDS , flow : type [Flow ]) -> ( bool , ( Rule , None )) :
371+ def process_dnat (self , packet : PacketIP , flow : type [Flow ]) -> tuple [ bool , Rule | None ] :
372372 """
373373 :param packet: Packet to process
374374 :param flow: traffic flow-type
@@ -400,7 +400,7 @@ def _chain_filter_main(self, chain: Chain, flow: type[Flow]) -> bool:
400400
401401 return chain .type != chain .TYPE_NAT and after_dnat and before_snat
402402
403- def process_main (self , packet : PACKET_KINDS , flow : type [Flow ]) -> ( bool , ( Rule , None )) :
403+ def process_main (self , packet : PacketIP , flow : type [Flow ]) -> tuple [ bool , Rule | None ] :
404404 """
405405 :param packet: Packet to process
406406 :param flow: traffic flow-type
@@ -425,7 +425,7 @@ def _chain_filter_snat(self, chain: Chain, flow: type[Flow]) -> bool:
425425 chain .hook == chain_snat ['hook' ] and \
426426 chain .priority == chain_snat ['priority' ]
427427
428- def process_snat (self , packet : PACKET_KINDS , flow : type [Flow ]) -> ( bool , ( Rule , None )) :
428+ def process_snat (self , packet : PacketIP , flow : type [Flow ]) -> tuple [ bool , Rule | None ] :
429429 """
430430 :param packet: Packet to process
431431 :param flow: traffic flow-type
@@ -451,7 +451,7 @@ def _chain_filter_egress(self, chain: Chain, flow: type[Flow]) -> bool:
451451 after_snat = self ._is_chain_after (chain = chain , ** self ._fw .system .FIREWALL_NAT [flow ]['snat' ])
452452 return chain .type != chain .TYPE_NAT and after_snat
453453
454- def process_egress (self , packet : PACKET_KINDS , flow : type [Flow ]) -> ( bool , ( Rule , None )) :
454+ def process_egress (self , packet : PacketIP , flow : type [Flow ]) -> tuple [ bool , Rule | None ] :
455455 """
456456 :param packet: Packet to process
457457 :param flow: traffic flow-type
@@ -475,15 +475,15 @@ def __init__(self, system: type[FirewallSystem], ruleset: Ruleset):
475475
476476 self ._run_tables = RunFirewallTables (self )
477477
478- def process_pre_routing (self , packet : PACKET_KINDS , flow : type [Flow ]) -> ( bool , ( Rule , None )) :
478+ def process_pre_routing (self , packet : PacketIP , flow : type [Flow ]) -> tuple [ bool , Rule | None ] :
479479 log_info ('Firewall' , v3 = 'Processing Pre-Routing Filter-Hooks' )
480480 if flow == FlowInputForward :
481481 # before DNAT we cannot know for sure
482482 flow = FlowInput
483483
484484 return self ._run_tables .process_pre_routing (packet = packet , flow = flow )
485485
486- def process_dnat (self , packet : PACKET_KINDS , flow : type [Flow ]) -> ( bool , ( Rule , None )) :
486+ def process_dnat (self , packet : PacketIP , flow : type [Flow ]) -> tuple [ bool , Rule | None ] :
487487 if flow == FlowInputForward :
488488 # before DNAT we cannot know for sure
489489 flow = FlowInput
@@ -496,12 +496,12 @@ def process_dnat(self, packet: PACKET_KINDS, flow: type[Flow]) -> (bool, (Rule,
496496
497497 return self ._run_tables .process_dnat (packet = packet , flow = flow )
498498
499- def process_main (self , packet : PACKET_KINDS , flow : type [Flow ]) -> ( bool , ( Rule , None )) :
499+ def process_main (self , packet : PacketIP , flow : type [Flow ]) -> tuple [ bool , Rule | None ] :
500500 log_info ('Firewall' , v3 = 'Processing Main Filter-Hooks' )
501501
502502 return self ._run_tables .process_main (packet = packet , flow = flow )
503503
504- def process_snat (self , packet : PACKET_KINDS , flow : type [Flow ]) -> ( bool , ( Rule , None )) :
504+ def process_snat (self , packet : PacketIP , flow : type [Flow ]) -> tuple [ bool , Rule | None ] :
505505 if not self .system .FIREWALL_SNAT or 'snat' not in self .system .FIREWALL_NAT [flow ]:
506506 # system or flow has no SNAT capability
507507 return False , None
@@ -510,7 +510,7 @@ def process_snat(self, packet: PACKET_KINDS, flow: type[Flow]) -> (bool, (Rule,
510510
511511 return self ._run_tables .process_snat (packet = packet , flow = flow )
512512
513- def process_egress (self , packet : PACKET_KINDS , flow : type [Flow ]) -> ( bool , ( Rule , None )) :
513+ def process_egress (self , packet : PacketIP , flow : type [Flow ]) -> tuple [ bool , Rule | None ] :
514514 if 'snat' not in self .system .FIREWALL_NAT [flow ]:
515515 # already processed all chains
516516 return True , None
0 commit comments