Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dumpcap): Handle dumpcap invocation for unix transports #489

Merged
merged 1 commit into from
Jan 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 37 additions & 17 deletions src/gallia/dumpcap.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@
from urllib.parse import urlparse

from gallia.log import get_logger
from gallia.transports import ISOTPTransport, RawCANTransport, TargetURI
from gallia.transports import (
ISOTPTransport,
RawCANTransport,
TargetURI,
UnixLinesTransport,
UnixTransport,
)
from gallia.utils import auto_int, split_host_port

logger = get_logger("gallia.dumpcap")
Expand Down Expand Up @@ -48,25 +54,39 @@ async def start(
artifacts_dir: Path,
) -> Dumpcap | None:
ts = int(datetime.now().timestamp())
if target.scheme in [ISOTPTransport.SCHEME, RawCANTransport.SCHEME]:
outfile = artifacts_dir.joinpath(f"candump-{ts}.pcap.gz")
src_addr = (
auto_int(target.qs["src_addr"][0]) if "src_addr" in target.qs else None
)
dst_addr = (
auto_int(target.qs["dst_addr"][0]) if "dst_addr" in target.qs else None
)
cmd = cls._can_cmd(
target.netloc,
src_addr,
dst_addr,
)
else:
outfile = artifacts_dir.joinpath(f"eth-{ts}.pcap.gz")
cmd = await cls._eth_cmd(target.netloc)

match target.scheme:
case ISOTPTransport.SCHEME | RawCANTransport.SCHEME:
outfile = artifacts_dir.joinpath(f"candump-{ts}.pcap.gz")
src_addr = (
auto_int(target.qs["src_addr"][0])
if "src_addr" in target.qs
else None
)
dst_addr = (
auto_int(target.qs["dst_addr"][0])
if "dst_addr" in target.qs
else None
)
cmd = cls._can_cmd(
target.netloc,
src_addr,
dst_addr,
)
# Unix domain sockets are not supported by dumpcap.
case UnixTransport.SCHEME | UnixLinesTransport.SCHEME:
return None
# There is currently no API for transport plugins to
# register a scheme and a corresponding invocation
# for dumpcap. So this match…case is best effort,
# since it defaults to ethernet.
case _:
outfile = artifacts_dir.joinpath(f"eth-{ts}.pcap.gz")
cmd = await cls._eth_cmd(target.netloc)

if cmd is None:
return None

cmd_str = shlex.join(cmd)
try:
proc = await asyncio.create_subprocess_exec(
Expand Down