fix: update db_insert_packet to include bridge parameter for accurate packet logging
All checks were successful
Build and Deploy MITM Webserver / build (push) Successful in 8s
All checks were successful
Build and Deploy MITM Webserver / build (push) Successful in 8s
This commit is contained in:
@@ -133,7 +133,7 @@ def determine_direction(pkt_iface: str, bridge: str):
|
||||
# -------------------------------------------------------------------
|
||||
# Database insertion
|
||||
# -------------------------------------------------------------------
|
||||
async def db_insert_packet(pkt_info: dict) -> None:
|
||||
async def db_insert_packet(pkt_info: dict, bridge: str) -> None:
|
||||
"""
|
||||
Asynchronously insert parsed packet information into the database.
|
||||
This function is designed to be scheduled on the background asyncio loop
|
||||
@@ -150,7 +150,6 @@ async def db_insert_packet(pkt_info: dict) -> None:
|
||||
"""
|
||||
INSERT INTO packets(
|
||||
iface,
|
||||
direction,
|
||||
src_mac,
|
||||
dst_mac,
|
||||
eth_type,
|
||||
@@ -162,10 +161,9 @@ async def db_insert_packet(pkt_info: dict) -> None:
|
||||
dst_port,
|
||||
length,
|
||||
raw
|
||||
) VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13)
|
||||
) VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12)
|
||||
""",
|
||||
pkt_info["ingress"],
|
||||
"unknown", # direction placeholder; matching/annotation can be done later
|
||||
pkt_info["iface"],
|
||||
pkt_info["src_mac"],
|
||||
pkt_info["dst_mac"],
|
||||
pkt_info["eth_type"],
|
||||
@@ -205,12 +203,9 @@ def parse_packet(pkt, bridge: str) -> None:
|
||||
|
||||
logger.debug("Packet captured on %s, bridge %s", pkt_iface, bridge)
|
||||
|
||||
ingress, egress = determine_direction(pkt_iface, bridge)
|
||||
|
||||
# Basic normalization structure for DB insertion.
|
||||
pkt_info = {
|
||||
"ingress": ingress,
|
||||
"egress": egress,
|
||||
"ingress": pkt_iface,
|
||||
"length": len(pkt),
|
||||
"raw": bytes(pkt),
|
||||
"src_mac": None,
|
||||
@@ -284,7 +279,7 @@ def parse_packet(pkt, bridge: str) -> None:
|
||||
pkt_info["protocol_name"] = "RAW"
|
||||
|
||||
# Submit DB insert to background asyncio loop from this thread.
|
||||
asyncio.run_coroutine_threadsafe(db_insert_packet(pkt_info), async_loop)
|
||||
asyncio.run_coroutine_threadsafe(db_insert_packet(pkt_info, bridge), async_loop)
|
||||
|
||||
|
||||
# -------------------------
|
||||
|
||||
Reference in New Issue
Block a user