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

Firewall rules: add support for IPv4 and IPv6 packet fragments #2089

Merged
merged 3 commits into from
Feb 3, 2025

Conversation

francescolavra
Copy link
Member

This change set adds support for a new "fragment" attribute that can be specified in the "ip" and "ip6" objects in firewall rules; this new attribute, whose behavior mimics the --fragment iptables option, can have a "y" or "n" value: "y" makes the rule match the second and subsequent fragments of fragmented IP packets, while "n" makes the rule match non-fragmented packets and the first fragment of fragmented packets.
Example snippet of Ops configuration that makes the firewall drop all fragmented IPv4 packets:

  "ManifestPassthrough": {
    "firewall": {
      "rules": [
        {"ip": {"fragment": "y"}, "action": "drop"}
      ]
    }
  }

In addition, handling of fragmented packets in the firewall klib is being fixed in order for the second and subsequent fragments of a fragmented packet to not match any rule that contains transport layer constraints (because the transport layer protocol header is only present in the first fragment, and not in subsequent fragments).

This helper function walks through the list of headers of an IPv6
packet until a given header type is found; it will be reused when
adding support for identifying packet fragments.
Make firewall_ip6_get_hdr() call this helper function (no
functional change).
Wen incoming IP packets are fragmented, the transport layer
protocol header is ony present in the first fragment, and not in
subsequent fragments; therefore, the firewall code cannot check
subsequent fragments against any transport layer constraints in a
firewall rule.
Amend the firewall_ip*_match() functions so that the second and
subsequent framgments of a fragmented packet do not match any rule
that contains transport layer constraints.
Add support for a new "fragment" tuple attribute that can be
specified in "ip" and "ip6" tuples in firewall rules; this new
attribute can have a "y" or "n" value: "y" makes the rule match the
second and subsequent fragments of fragmented IP packets, while
"n" makes the rule match non-fragmented packets and the first
fragment of fragmented packets.
Example snippet of Ops configuration that makes the firewall drop
all fragmented IPv4 packets:
```
  "ManifestPassthrough": {
    "firewall": {
      "rules": [
        {"ip": {"fragment": "y"}, "action": "drop"}
      ]
    }
  }
```
@francescolavra francescolavra merged commit 26ee8dc into master Feb 3, 2025
7 checks passed
@francescolavra francescolavra deleted the feature/firewall-fragment branch February 3, 2025 07:27
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.

1 participant