-
Notifications
You must be signed in to change notification settings - Fork 345
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
firewall: T4694: Adding GRE flags & fields matches to firewall rules
Work in progress: * Only matching flags and fields used by modern RFC2890 "extended GRE" * There are no NFT helpers for the GRE key field, which is critical to match individual tunnel sessions * NFT syntax is not flexible enough for multiple field matches in a single rule and the key offset changes depending on flags. * Thus, clumsy compromise in requiring an explicit match on the "checksum" flag if a key is present, so we know where key will be. In most cases, nobody uses the checksum, but assuming it to be off or automatically adding a "not checksum" match unless told otherwise would be confusing * The automatic "flags key" check when specifying a key doesn't have similar validation, I added it first and it makes sense. I would still like to find a workaround to the "checksum" offset problem. * If we could add 2 rules from 1 config definition, we could match both cases with appropriate offsets, but this would break existing FW generation logic, logging, etc. * Added a "gre-protocol" validator for the fields we can pass to nft's gre matches. * The protocol names are out of synch with other parts of the firewall def, but for eg, I can't call a completion+valueHelp "ipv6" without VyOS deciding to show an IPv6 pattern instead of my help text. * I've allowed arbitrary radix numbers for the ethertype, for eg, it's common to use 0x8100 for .1q instead of 33024. nft should accept these as well.
- Loading branch information
Showing
5 changed files
with
240 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
<!-- include start from firewall/gre.xml.i --> | ||
<node name="gre"> | ||
<properties> | ||
<help>GRE fields to match</help> | ||
</properties> | ||
<children> | ||
<node name="flags"> | ||
<properties> | ||
<help>GRE flag bits to match</help> | ||
</properties> | ||
<children> | ||
<leafNode name="key"> | ||
<properties> | ||
<help>Header includes optional key field</help> | ||
<valueless/> | ||
</properties> | ||
</leafNode> | ||
<leafNode name="checksum"> | ||
<properties> | ||
<help>Header includes optional checksum</help> | ||
<valueless/> | ||
</properties> | ||
</leafNode> | ||
<leafNode name="sequence"> | ||
<properties> | ||
<help>Header includes a sequence number field</help> | ||
<valueless/> | ||
</properties> | ||
</leafNode> | ||
<node name="not"> | ||
<properties> | ||
<help>Match flags not set</help> | ||
</properties> | ||
<children> | ||
<leafNode name="key"> | ||
<properties> | ||
<help>Header does not include optional key field</help> | ||
<valueless/> | ||
</properties> | ||
</leafNode> | ||
<leafNode name="checksum"> | ||
<properties> | ||
<help>Header does not include optional checksum</help> | ||
<valueless/> | ||
</properties> | ||
</leafNode> | ||
<leafNode name="sequence"> | ||
<properties> | ||
<help>Header does not include a sequence number field</help> | ||
<valueless/> | ||
</properties> | ||
</leafNode> | ||
</children> | ||
</node> | ||
</children> | ||
</node> | ||
<leafNode name="inner-proto"> | ||
<properties> | ||
<help>EtherType of encapsulated packet</help> | ||
<completionHelp> | ||
<list>ip ip6 arp vlan 8021q 8021ad</list> | ||
</completionHelp> | ||
<valueHelp> | ||
<format>u32:0-65535</format> | ||
<description>Ethernet protocol number</description> | ||
</valueHelp> | ||
<valueHelp> | ||
<format>ip</format> | ||
<description>IPv4</description> | ||
</valueHelp> | ||
<valueHelp> | ||
<format>ip6</format> | ||
<description>IPv6</description> | ||
</valueHelp> | ||
<valueHelp> | ||
<format>arp</format> | ||
<description>Address Resolution Protocol</description> | ||
</valueHelp> | ||
<valueHelp> | ||
<format>vlan</format> | ||
<description>VLAN-tagged Ethernet</description> | ||
</valueHelp> | ||
<valueHelp> | ||
<format>8021q</format> | ||
<description>VLAN-tagged Ethernet</description> | ||
</valueHelp> | ||
<valueHelp> | ||
<format>8021ad</format> | ||
<description>Bridged Ethernet</description> | ||
</valueHelp> | ||
<constraint> | ||
<validator name="gre-protocol"/> | ||
</constraint> | ||
</properties> | ||
</leafNode> | ||
<leafNode name="key"> | ||
<properties> | ||
<help>Tunnel Key</help> | ||
<valueHelp> | ||
<format>u32</format> | ||
<description>Tunnel Key ID</description> | ||
</valueHelp> | ||
<constraint> | ||
<validator name="numeric" /> | ||
</constraint> | ||
</properties> | ||
</leafNode> | ||
<leafNode name="version"> | ||
<properties> | ||
<help>GRE Version</help> | ||
<valueHelp> | ||
<format>gre</format> | ||
<description>Standard GRE</description> | ||
</valueHelp> | ||
<valueHelp> | ||
<format>pptp</format> | ||
<description>Point to Point Protocol</description> | ||
</valueHelp> | ||
<constraint> | ||
<regex>(gre|pptp)</regex> | ||
</constraint> | ||
</properties> | ||
</leafNode> | ||
</children> | ||
</node> | ||
<!-- include end --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/usr/bin/env python3 | ||
# | ||
# Copyright (C) 2024 VyOS maintainers and contributors | ||
# | ||
# This program is free software; you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License version 2 or later as | ||
# published by the Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
import re | ||
from sys import argv,exit | ||
|
||
if __name__ == '__main__': | ||
if len(argv) != 2: | ||
exit(1) | ||
|
||
input = argv[1] | ||
try: | ||
# It's common practice to pass hex for ethtype (eg, 0x8100), so we allow | ||
# other radix prefixes with the int conversion: | ||
if int(input, 0) in range(0, 65535): | ||
exit(0) | ||
except ValueError: | ||
pass | ||
|
||
pattern = "!?\\b(ip|ip6|arp|vlan|8021q|8021ad)\\b" | ||
if re.match(pattern, input): | ||
exit(0) | ||
|
||
print(f'Error: {input} is not a valid GRE inner protocol') | ||
exit(1) |