Skip to content

tests/dataset: coverage for the cidr datset type - #3304

Open
jlucovsky wants to merge 5 commits into
OISF:masterfrom
jlucovsky:8124/1
Open

tests/dataset: coverage for the cidr datset type#3304
jlucovsky wants to merge 5 commits into
OISF:masterfrom
jlucovsky:8124/1

Conversation

@jlucovsky

Copy link
Copy Markdown
Contributor

Test coverage for the type cidr dataset

What's covered

27 tests grouped by what they exercise:

  • 01-10 — basic type behavior: isset/isnotset for IPv4, IPv6, mixed dual-stack, /32 host-exact precision, /16 boundary, empty dataset.
  • 11-12set and unset on IPv4.
  • 13-14save and state options rejected at rule load (CIDR is load-only).
  • 15, 17-18 — the mask option in all three notations: decimal prefix (mask 24), hex prefix (mask 0x18), IPv4 bitmask (mask 0xffffff00).
  • 16 — Lua access to a CIDR dataset via dataset:get.
  • 19unset with mask removes the correct /N netblock.
  • 20-21set and unset on IPv6.
  • 22-26 — additional rejection paths: mask on isset, non-contiguous IPv4 netmask, mask on a non-CIDR type, datarep with type cidr, mask 0.
  • 27 — CIDR-dataset equivalent of tests/lua/lua-transform-09, reusing that test's pcap to prove the CIDR type replaces the luaxform IP -> CIDR string workaround with the same alert counts and no per-packet Lua invocation.

Tests 05, 06, 07, 20, 21 ship a per-test suricata.yaml with ipv6-compress: yes so src_ip filters in test.yaml compare
against compressed RFC 5952 IPv6 output. Test 16 uses --set default-rule-path=. so the Lua script is found relative to the test directory rather than the system rules dir.

Rejection tests (13, 14, 22-26) run --engine-analysis with exit-code: 1 and grep suricata.log for the exact error string.

Behavioral tests use small hand-built pcaps generated by writepcap.py scripts kept in each test's directory; tests
downstream reuse pcaps from earlier tests where possible (mapped in tests/datasets-cidr/README.md).

Redmine ticket: https://redmine.openinfosecfoundation.org/issues/8124

Ten suricata-verify tests covering the cidr dataset type:
IPv4 isset/isnotset, dst matching, multi-rule, IPv6 isset/isnotset,
mixed IPv4+IPv6, /32 host-exact precision, boundary conditions, and
empty dataset behavior. All tests require min-version: 9 and verify
per-IP alert counts alongside total alert counts.

Issue: 8124
Nine suricata-verify tests covering additional CIDR behaviors:

- datasets-cidr-11-set: dataset:set fires once per unique source host
- datasets-cidr-12-unset: dataset:unset removes pre-loaded host entries;
  fires once per address then not again
- datasets-cidr-13-save-reject: save option rejected at parse time
- datasets-cidr-14-state-reject: state option rejected at parse time
- datasets-cidr-15-mask: dataset:set with mask 24 fires once per unique
  /24 prefix, not once per host
- datasets-cidr-16-lua: Lua can retrieve a CIDR dataset via dataset.get()
- datasets-cidr-17-mask-hex-prefix: mask 0x18 (hex) behaves like mask 24
- datasets-cidr-18-mask-bitmask: mask 0xffffff00 (IPv4 bitmask) behaves
  like mask 24
- datasets-cidr-19-unset-mask: dataset:unset with mask 24 removes the
  pre-loaded /24 netblock on first match; does not fire on subsequent
  packets from the same /24 after removal

Issue: 8124
- tests 05/06/07: add a per-test suricata.yaml with ipv6-compress: yes
  so eve.json IPv6 addresses appear in RFC5952 compressed form,
  matching the human-readable src_ip filters in test.yaml.
- tests 15/17/18: replace different-source-IP pcap with same-5-tuple
  packets per /24 so intra-/24 ordering is deterministic (same flow ->
  same worker -> serial processing).
- test 16: add --set default-rule-path=. so the Lua script is found
  relative to the test directory rather than the system rules dir.

Issue: 8124
Seven suricata-verify tests:

- datasets-cidr-20-ipv6-set: dataset:set on IPv6 sources, fires once
  per unique host (mirror of test 11 for IPv6).
- datasets-cidr-21-ipv6-unset: dataset:unset on preloaded IPv6 hosts.
- datasets-cidr-22-mask-isset-reject: mask option rejected at rule
  load when combined with isset.
- datasets-cidr-23-mask-out-of-range: non-contiguous bitmask
  (0x00ff00ff) rejected at rule load.
- datasets-cidr-24-mask-non-cidr-reject: mask option rejected when
  used with a non-CIDR dataset type.
- datasets-cidr-25-datarep-cidr-reject: datarep keyword rejected at
  rule load when combined with type cidr.
- datasets-cidr-26-mask-zero-reject: mask 0 rejected at rule load.

Rejection tests use --engine-analysis and grep suricata.log for the
specific error message; they require exit-code 1.

Issue: 8124
Two rules mirror the semantics of tests/lua/lua-transform-09 without
per-packet Lua invocation. That test uses luaxform to mask an IPv4
address to a network and content-matches the resulting CIDR string;
here isset on a type-cidr dataset walks a radix tree that already
contains the target prefix.

Reuses ../../lua/lua-transform-01/test.pcap so the alert counts
(4 for sid:1 on ip.src in 10.20.48.0/24, 4 for sid:2 on ip.dst in
10.50.0.0/16) are directly comparable to lua-transform-09.

Issue: 8124
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

requires suricata pr Depends on a PR in Suricata

Development

Successfully merging this pull request may close these issues.

2 participants