add config
All checks were successful
Build and Deploy MITM Webserver / build (push) Successful in 10s
All checks were successful
Build and Deploy MITM Webserver / build (push) Successful in 10s
This commit is contained in:
@@ -31,6 +31,7 @@ from src.utilities.interface_bridge_helpers import (
|
||||
check_interface_up,
|
||||
get_bridge_ports_once,
|
||||
)
|
||||
from src.config import settings
|
||||
from src.utilities.bridge_telemetry import bridge_telemetry_manager
|
||||
from src.utilities.ndpi_classifier import ndpi_classifier
|
||||
from src.utilities.packet_identity import build_packet_uid
|
||||
@@ -100,7 +101,7 @@ class PacketInfo(TypedDict, total=False):
|
||||
|
||||
# small bounded buffer for packets produced before shared_objects is ready
|
||||
_PACKET_BUFFER: List[PacketInfo] = []
|
||||
_BUFFER_CAPACITY = 20000
|
||||
_BUFFER_CAPACITY = settings.sniffer_buffer_capacity
|
||||
|
||||
# Background asyncio loop used for internal tasks in this module (kept but not used for DB pool)
|
||||
async_loop = asyncio.new_event_loop()
|
||||
@@ -396,7 +397,7 @@ def parse_packet(pkt, bridge_label: str) -> None:
|
||||
# -------------------------
|
||||
# AF_PACKET socket utilities
|
||||
# -------------------------
|
||||
def _create_af_packet_socket(ifname: str, rx_buf: int = 4 * 1024 * 1024) -> Optional[socket.socket]:
|
||||
def _create_af_packet_socket(ifname: str, rx_buf: Optional[int] = None) -> Optional[socket.socket]:
|
||||
"""
|
||||
Create and bind an AF_PACKET raw socket to interface.
|
||||
Non-blocking socket returned or None on failure.
|
||||
@@ -411,7 +412,7 @@ def _create_af_packet_socket(ifname: str, rx_buf: int = 4 * 1024 * 1024) -> Opti
|
||||
return None
|
||||
|
||||
try:
|
||||
s.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, rx_buf)
|
||||
s.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, rx_buf or settings.sniffer_socket_rcvbuf_bytes)
|
||||
except Exception:
|
||||
logger.debug("SO_RCVBUF set failed for %s (non-fatal)", ifname)
|
||||
|
||||
@@ -507,7 +508,7 @@ def _session_reader_loop(session_id: str) -> None:
|
||||
pass
|
||||
|
||||
try:
|
||||
events = sel.select(timeout=1.0)
|
||||
events = sel.select(timeout=settings.sniffer_selector_timeout_seconds)
|
||||
except Exception:
|
||||
logger.exception("Selector error in session %s", session_id)
|
||||
time.sleep(0.1)
|
||||
@@ -515,7 +516,7 @@ def _session_reader_loop(session_id: str) -> None:
|
||||
|
||||
if not events:
|
||||
# occasionally attempt to drain buffer if DB becomes available
|
||||
if time.time() - last_drain_ts > 5:
|
||||
if time.time() - last_drain_ts > settings.sniffer_buffer_drain_interval_seconds:
|
||||
try:
|
||||
drain_buffer_to_shared_db()
|
||||
except Exception:
|
||||
@@ -527,7 +528,7 @@ def _session_reader_loop(session_id: str) -> None:
|
||||
sock: socket.socket = key.fileobj
|
||||
iface: str = key.data
|
||||
try:
|
||||
raw = sock.recv(65536)
|
||||
raw = sock.recv(settings.sniffer_recv_bytes)
|
||||
if not raw:
|
||||
continue
|
||||
except BlockingIOError:
|
||||
@@ -639,7 +640,7 @@ def stop_afpacket_sniffer(session_id: Optional[str] = None, target: Optional[str
|
||||
s["stop_event"].set()
|
||||
t = s.get("thread")
|
||||
if t and isinstance(t, threading.Thread):
|
||||
t.join(timeout=2)
|
||||
t.join(timeout=settings.sniffer_thread_join_timeout_seconds)
|
||||
_sync_bridge_telemetry()
|
||||
logger.info("Stopped session %s", session_id)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user