Skip to content

test: add Scapy-backed advanced packet regression tests#48

Merged
leodido merged 4 commits intomainfrom
test/scapy-regression
May 4, 2026
Merged

test: add Scapy-backed advanced packet regression tests#48
leodido merged 4 commits intomainfrom
test/scapy-regression

Conversation

@leodido
Copy link
Copy Markdown
Owner

@leodido leodido commented May 3, 2026

Add 13 test cases covering IP options (IHL > 5), first/subsequent
fragment handling, ICMP subnet filtering, TCP-only SSH exemption,
UDP/GRE blocking, and fail-open behavior for block_* programs.

Architecture

  • test/scapy_packets.py: Python helper with send/sniff subcommands
  • test/scapy.bats: Bats test file using existing veth+namespace topology
  • test/helpers.bash: sniffer lifecycle wrappers and packet assertions

Tests judge allow/block by wire visibility on the host-side veth,
not application-level behavior. Each packet uses a unique IP ID for
deterministic sniffing. Sniff timeout defaults to 2s, configurable
via SCAPY_SNIFF_TIMEOUT env var.

Test cases

block_ipv4

  • Drops packet with IP options (IHL > 5)
  • Drops first and subsequent fragments to blocked IP

block_port

  • Drops TCP with IP options when port matches
  • Allows TCP with IP options when port does not match
  • Drops first fragment with blocked port
  • Allows subsequent fragment (fail-open)

block_private_ipv4

  • Allows ICMP to non-private destination
  • Drops ICMP to private destination
  • Allows TCP source port 22 to private (SSH exemption)
  • Allows TCP source port 22 with IP options (SSH + IHL > 5)
  • Drops UDP source port 22 to private (SSH exemption is TCP-only)
  • Drops GRE to private destination
  • Drops first fragment to private, allows subsequent (fail-open)

Infrastructure changes

  • Scapy added to .devcontainer/Dockerfile and both CI jobs (Ubuntu + Arch)
  • Tests skip gracefully if scapy is not installed
  • README updated to note scapy dependency for full test suite

@leodido leodido self-assigned this May 3, 2026
Comment thread test/scapy_packets.py Outdated
Comment thread test/scapy.bats Outdated
Comment thread test/scapy.bats Outdated
Comment thread test/scapy.bats Outdated
leodido and others added 4 commits May 3, 2026 22:23
Required for advanced packet tests that craft IP options,
fragments, and protocol-specific packets via Scapy.

Co-authored-by: Ona <no-reply@ona.com>
test/scapy_packets.py: Python CLI with send/sniff subcommands.
Uses L3 send (kernel handles Ethernet/routing). Supports packet
types: tcp, udp, icmp, gre, fragment-first, fragment-subsequent.
IP options (IHL > 5) via --ip-options flag. Unique IP ID per packet
for deterministic sniffing.

test/helpers.bash: start_sniffer, wait_sniffer, scapy_send,
arp_prewarm, assert_packet_seen, assert_packet_blocked. Sniff
timeout defaults to 2s, configurable via SCAPY_SNIFF_TIMEOUT.

Co-authored-by: Ona <no-reply@ona.com>
…ivate_ipv4

13 test cases covering:
- block_ipv4: IP options, first/subsequent fragments
- block_port: IP options with matching/non-matching port, first
  fragment drop, subsequent fragment pass (fail-open)
- block_private_ipv4: ICMP to private vs non-private, TCP-only SSH
  exemption (port 22), UDP port 22 drop, GRE drop, fragment handling

Co-authored-by: Ona <no-reply@ona.com>
Co-authored-by: Ona <no-reply@ona.com>
@leodido leodido force-pushed the test/scapy-regression branch from f8c5a01 to b684cd2 Compare May 3, 2026 22:24
@leodido leodido requested a review from fntlnz May 3, 2026 23:12
@leodido leodido merged commit 9e9c14f into main May 4, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants