Files
firegex-traffic-viewer/fgex-lib/firegex/nfproxy/internals/models.py

50 lines
1.2 KiB
Python
Raw Normal View History

2025-03-03 20:25:36 +01:00
from dataclasses import dataclass, field
from enum import Enum
class Action(Enum):
2025-03-07 23:13:36 +01:00
"""Action to be taken by the filter"""
2025-03-03 20:25:36 +01:00
ACCEPT = 0
DROP = 1
REJECT = 2
MANGLE = 3
class ExceptionAction(Enum):
"""Action to be taken by the filter when an exception occurs (used in some cases)"""
ACCEPT = 0
DROP = 1
REJECT = 2
NOACTION = 3
2025-03-03 20:25:36 +01:00
class FullStreamAction(Enum):
2025-03-07 23:13:36 +01:00
"""Action to be taken by the filter when the stream is full"""
2025-03-03 20:25:36 +01:00
FLUSH = 0
ACCEPT = 1
REJECT = 2
DROP = 3
@dataclass
class FilterHandler:
2025-03-07 23:13:36 +01:00
"""Filter handler"""
2025-03-03 20:25:36 +01:00
func: callable
name: str
params: dict[type, callable]
proto: str
@dataclass
class PacketHandlerResult:
2025-03-07 23:13:36 +01:00
"""Packet handler result"""
2025-03-03 20:25:36 +01:00
glob: dict = field(repr=False)
action: Action = Action.ACCEPT
matched_by: str = None
mangled_packet: bytes = None
def set_result(self) -> None:
self.glob["__firegex_pyfilter_result"] = {
"action": self.action.value,
"matched_by": self.matched_by,
"mangled_packet": self.mangled_packet
}
def reset_result(self) -> None:
self.glob["__firegex_pyfilter_result"] = None