Skip to content

Commit c78c5bd

Browse files
authored
Merge pull request #4018 from nicolas-fort/T6647
T6647: firewall. Introduce patch for accepting invalid ARP and DHCP
2 parents 497863b + 8e0e1a9 commit c78c5bd

File tree

6 files changed

+68
-2
lines changed

6 files changed

+68
-2
lines changed

data/templates/firewall/nftables.j2

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,8 +376,14 @@ table bridge vyos_filter {
376376

377377
{% if bridge.output is vyos_defined %}
378378
{% for prior, conf in bridge.output.items() %}
379-
chain VYOS_OUTUT_{{ prior }} {
379+
chain VYOS_OUTPUT_{{ prior }} {
380380
type filter hook output priority {{ prior }}; policy accept;
381+
{% if global_options.apply_to_bridged_traffic is vyos_defined %}
382+
{% if 'invalid_connections' in global_options.apply_to_bridged_traffic %}
383+
ct state invalid udp sport 67 udp dport 68 counter accept
384+
ct state invalid ether type arp counter accept
385+
{% endif %}
386+
{% endif %}
381387
{% if global_options.state_policy is vyos_defined %}
382388
jump VYOS_STATE_POLICY
383389
{% endif %}

interface-definitions/include/firewall/common-rule-bridge.xml.i

100644100755
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <include/firewall/limit.xml.i>
1111
#include <include/firewall/log.xml.i>
1212
#include <include/firewall/log-options.xml.i>
13+
#include <include/firewall/match-ether-type.xml.i>
1314
#include <include/firewall/match-ipsec.xml.i>
1415
#include <include/firewall/match-vlan.xml.i>
1516
#include <include/firewall/nft-queue.xml.i>

interface-definitions/include/firewall/global-options.xml.i

100644100755
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@
4949
<help>Apply configured firewall rules to traffic switched by bridges</help>
5050
</properties>
5151
<children>
52+
<leafNode name="invalid-connections">
53+
<properties>
54+
<help>Accept ARP and DHCP despite they are marked as invalid connection</help>
55+
<valueless/>
56+
</properties>
57+
</leafNode>
5258
<leafNode name="ipv4">
5359
<properties>
5460
<help>Apply configured IPv4 firewall rules</help>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<!-- include start from firewall/match-ether-type.xml.i -->
2+
<leafNode name="ethernet-type">
3+
<properties>
4+
<help>Ethernet type</help>
5+
<completionHelp>
6+
<list>802.1q 802.1ad arp ipv4 ipv6</list>
7+
</completionHelp>
8+
<valueHelp>
9+
<format>802.1q</format>
10+
<description>Customer VLAN tag type</description>
11+
</valueHelp>
12+
<valueHelp>
13+
<format>802.1ad</format>
14+
<description>Service VLAN tag type</description>
15+
</valueHelp>
16+
<valueHelp>
17+
<format>arp</format>
18+
<description>Adress Resolution Protocol</description>
19+
</valueHelp>
20+
<valueHelp>
21+
<format>_ipv4</format>
22+
<description>Internet Protocol version 4</description>
23+
</valueHelp>
24+
<valueHelp>
25+
<format>_ipv6</format>
26+
<description>Internet Protocol version 6</description>
27+
</valueHelp>
28+
</properties>
29+
</leafNode>
30+
<!-- include end -->

python/vyos/firewall.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,20 @@ def parse_rule(rule_conf, hook, fw_name, rule_id, ip_name):
151151
proto = '{tcp, udp}'
152152
output.append(f'meta l4proto {operator} {proto}')
153153

154+
if 'ethernet_type' in rule_conf:
155+
ether_type_mapping = {
156+
'802.1q': '8021q',
157+
'802.1ad': '8021ad',
158+
'ipv6': 'ip6',
159+
'ipv4': 'ip',
160+
'arp': 'arp'
161+
}
162+
ether_type = rule_conf['ethernet_type']
163+
operator = '!=' if ether_type.startswith('!') else ''
164+
ether_type = ether_type.lstrip('!')
165+
ether_type = ether_type_mapping.get(ether_type, ether_type)
166+
output.append(f'ether type {operator} {ether_type}')
167+
154168
for side in ['destination', 'source']:
155169
if side in rule_conf:
156170
prefix = side[0]

smoketest/scripts/cli/test_firewall.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,7 @@ def test_bridge_firewall(self):
707707
self.cli_set(['firewall', 'group', 'ipv6-address-group', 'AGV6', 'address', '2001:db1::1'])
708708
self.cli_set(['firewall', 'global-options', 'state-policy', 'established', 'action', 'accept'])
709709
self.cli_set(['firewall', 'global-options', 'apply-to-bridged-traffic', 'ipv4'])
710+
self.cli_set(['firewall', 'global-options', 'apply-to-bridged-traffic', 'invalid-connections'])
710711

711712
self.cli_set(['firewall', 'bridge', 'name', name, 'default-action', 'accept'])
712713
self.cli_set(['firewall', 'bridge', 'name', name, 'default-log'])
@@ -731,6 +732,9 @@ def test_bridge_firewall(self):
731732

732733
self.cli_set(['firewall', 'bridge', 'prerouting', 'filter', 'rule', '1', 'action', 'notrack'])
733734
self.cli_set(['firewall', 'bridge', 'prerouting', 'filter', 'rule', '1', 'destination', 'group', 'ipv6-address-group', 'AGV6'])
735+
self.cli_set(['firewall', 'bridge', 'prerouting', 'filter', 'rule', '2', 'ethernet-type', 'arp'])
736+
self.cli_set(['firewall', 'bridge', 'prerouting', 'filter', 'rule', '2', 'action', 'accept'])
737+
734738

735739
self.cli_commit()
736740

@@ -750,9 +754,14 @@ def test_bridge_firewall(self):
750754
['chain VYOS_INPUT_filter'],
751755
['type filter hook input priority filter; policy accept;'],
752756
['ct state new', 'ip saddr 192.0.2.2', f'iifname "{interface_in}"', 'accept'],
757+
['chain VYOS_OUTPUT_filter'],
758+
['type filter hook output priority filter; policy accept;'],
759+
['ct state invalid', 'udp sport 67', 'udp dport 68', 'accept'],
760+
['ct state invalid', 'ether type arp', 'accept'],
753761
['chain VYOS_PREROUTING_filter'],
754762
['type filter hook prerouting priority filter; policy accept;'],
755-
['ip6 daddr @A6_AGV6', 'notrack']
763+
['ip6 daddr @A6_AGV6', 'notrack'],
764+
['ether type arp', 'accept']
756765
]
757766

758767
self.verify_nftables(nftables_search, 'bridge vyos_filter')

0 commit comments

Comments
 (0)