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 subnet queries for some subnets #3060

Merged
merged 3 commits into from Apr 6, 2023
Merged

Conversation

dominiklohmann
Copy link
Member

@dominiklohmann dominiklohmann commented Apr 5, 2023

This fixes an issue reported by @satta, who tried querying for all IPv6 addresses that did not have an equivalent IPv4 address.

VAST incorrectly handled subnets created using IPv6 addresses for which an equivalent IPv4 address existed. This comes with a few changes:

  • Specifying a /0 subnet is now allowed, and comparisons with such subnets now work correctly.
  • The internal representation of subnets always represents the prefix on a scale of 0 to 128 inclusive.
  • The subnet parser now forbids specifying a subnet using an IPv4 address and a prefix above 32, and creates the subnet with the prefix shifted by 96 accordingly.
  • The IP index now optimizes queries that filter IPv4 addresses, e.g., where :ip !in ::ffff:0:0/96 shows all events that contain an IPv6 address that cannot be represented as a valid IPv4 address.
  • Subnets whose network can be represented as an IPv4 address but whose prefix was below 96 now render correctly using an IPv6 address.
  • We now expose IPv4 and IPv6 parsers in addition to the existing IP parser, and also expose an IPv6 printer in addition to the existing IP printer.

@dominiklohmann dominiklohmann added the bug Incorrect behavior label Apr 5, 2023
@dominiklohmann dominiklohmann requested a review from a team April 5, 2023 10:09
libvast/src/index/ip_index.cpp Outdated Show resolved Hide resolved
@dominiklohmann dominiklohmann changed the title Handle queries against /0 subnets correctly Fix subnet queries for some subnets Apr 6, 2023
VAST incorrectly handled subnets created using IPv6 addresses for which
an equivalent IPv4 address existed. This comes with a few changes:
- Specifying a /0 subnet is now allowed, and comparisons with such
  subnets now work correctly.
- The internal representation of subnets always represents the prefix on
  a scale of 0 to 128 inclusive.
- The subnet parser now forbids specifying a subnet using an IPv4
  address and a prefix above 32, and creates the subnet with the prefix
  shifted by 96 accordingly.
- The IP index now optimizes queries that filter IPv4 addresses, e.g.,
  `where :ip !in ::ffff:0:0/96` shows all events that contain an IPv6
  address that cannot be represented as a valid IPv4 address.
- Subnets whose network can be represented as an IPv4 address but whose
  prefix was below 96 now render correctly using an IPv6 address.
- We now expose IPv4 and IPv6 parsers in addition to the existing IP
  parser, and also expose an IPv6 printer in addition to the existing IP
  printer.
Copy link
Member

@tobim tobim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic changes and new tests look right now.

changelog/next/bug-fixes/3060--subnet-queries.md Outdated Show resolved Hide resolved
libvast/src/index/ip_index.cpp Outdated Show resolved Hide resolved
@dominiklohmann dominiklohmann merged commit 893dd16 into main Apr 6, 2023
38 of 39 checks passed
@dominiklohmann dominiklohmann deleted the topic/zero-length-subnet branch April 6, 2023 16:07
@satta
Copy link
Contributor

satta commented Apr 9, 2023

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Incorrect behavior
Projects
None yet
3 participants