Skip to content

Commit

Permalink
Merge pull request #3310 from vyos/mergify/bp/sagitta/pr-3309
Browse files Browse the repository at this point in the history
T5535: firewall: migrate command <set system ip disable-directed-broadcast> to firewall global-optinos (backport #3309)
  • Loading branch information
c-po authored Apr 15, 2024
2 parents 131bb13 + 67bc108 commit d8bca08
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 23 deletions.
20 changes: 20 additions & 0 deletions interface-definitions/include/firewall/global-options.xml.i
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,26 @@
</properties>
<defaultValue>disable</defaultValue>
</leafNode>
<leafNode name="directed-broadcast">
<properties>
<help>Policy for handling IPv4 directed broadcast forwarding on all interfaces</help>
<completionHelp>
<list>enable disable</list>
</completionHelp>
<valueHelp>
<format>enable</format>
<description>Enable IPv4 directed broadcast forwarding on all interfaces</description>
</valueHelp>
<valueHelp>
<format>disable</format>
<description>Disable IPv4 directed broadcast forwarding on all interfaces</description>
</valueHelp>
<constraint>
<regex>(enable|disable)</regex>
</constraint>
</properties>
<defaultValue>enable</defaultValue>
</leafNode>
<leafNode name="ip-src-route">
<properties>
<help>Policy for handling IPv4 packets with source route option</help>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<!-- include start from include/version/firewall-version.xml.i -->
<syntaxVersion component='firewall' version='14'></syntaxVersion>
<syntaxVersion component='firewall' version='15'></syntaxVersion>
<!-- include end -->
6 changes: 0 additions & 6 deletions interface-definitions/system_ip.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@
<valueless/>
</properties>
</leafNode>
<leafNode name="disable-directed-broadcast">
<properties>
<help>Disable IPv4 directed broadcast forwarding on all interfaces</help>
<valueless/>
</properties>
</leafNode>
<node name="multipath">
<properties>
<help>IPv4 multipath settings</help>
Expand Down
1 change: 1 addition & 0 deletions smoketest/scripts/cli/test_firewall.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
sysfs_config = {
'all_ping': {'sysfs': '/proc/sys/net/ipv4/icmp_echo_ignore_all', 'default': '0', 'test_value': 'disable'},
'broadcast_ping': {'sysfs': '/proc/sys/net/ipv4/icmp_echo_ignore_broadcasts', 'default': '1', 'test_value': 'enable'},
'directed_broadcast': {'sysfs': '/proc/sys/net/ipv4/conf/all/bc_forwarding', 'default': '1', 'test_value': 'disable'},
'ip_src_route': {'sysfs': '/proc/sys/net/ipv4/conf/*/accept_source_route', 'default': '0', 'test_value': 'enable'},
'ipv6_receive_redirects': {'sysfs': '/proc/sys/net/ipv6/conf/*/accept_redirects', 'default': '0', 'test_value': 'enable'},
'ipv6_src_route': {'sysfs': '/proc/sys/net/ipv6/conf/*/accept_source_route', 'default': '-1', 'test_value': 'enable'},
Expand Down
11 changes: 0 additions & 11 deletions smoketest/scripts/cli/test_system_ip.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,6 @@ def test_system_ip_forwarding(self):

self.assertEqual(read_file(all_forwarding), '0')

def test_system_ip_directed_broadcast_forwarding(self):
# Test if IPv4 directed broadcast forwarding can be disabled globally,
# default is '1' which means forwarding enabled
bc_forwarding = '/proc/sys/net/ipv4/conf/all/bc_forwarding'
self.assertEqual(read_file(bc_forwarding), '1')

self.cli_set(base_path + ['disable-directed-broadcast'])
self.cli_commit()

self.assertEqual(read_file(bc_forwarding), '0')

def test_system_ip_multipath(self):
# Test IPv4 multipathing options, options default to off -> '0'
use_neigh = '/proc/sys/net/ipv4/fib_multipath_use_neigh'
Expand Down
1 change: 1 addition & 0 deletions src/conf_mode/firewall.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
sysfs_config = {
'all_ping': {'sysfs': '/proc/sys/net/ipv4/icmp_echo_ignore_all', 'enable': '0', 'disable': '1'},
'broadcast_ping': {'sysfs': '/proc/sys/net/ipv4/icmp_echo_ignore_broadcasts', 'enable': '0', 'disable': '1'},
'directed_broadcast' : {'sysfs': '/proc/sys/net/ipv4/conf/all/bc_forwarding', 'enable': '1', 'disable': '0'},
'ip_src_route': {'sysfs': '/proc/sys/net/ipv4/conf/*/accept_source_route'},
'ipv6_receive_redirects': {'sysfs': '/proc/sys/net/ipv6/conf/*/accept_redirects'},
'ipv6_src_route': {'sysfs': '/proc/sys/net/ipv6/conf/*/accept_source_route', 'enable': '0', 'disable': '-1'},
Expand Down
5 changes: 0 additions & 5 deletions src/conf_mode/system_ip.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,6 @@ def apply(opt):
value = '0' if (tmp != None) else '1'
write_file('/proc/sys/net/ipv4/conf/all/forwarding', value)

# enable/disable IPv4 directed broadcast forwarding
tmp = dict_search('disable_directed_broadcast', opt)
value = '0' if (tmp != None) else '1'
write_file('/proc/sys/net/ipv4/conf/all/bc_forwarding', value)

# configure multipath
tmp = dict_search('multipath.ignore_unreachable_nexthops', opt)
value = '1' if (tmp != None) else '0'
Expand Down
46 changes: 46 additions & 0 deletions src/migration-scripts/firewall/14-to-15
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env python3
#
# Copyright (C) 2022-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/>.

# T5535: Migrate <set system ip disable-directed-broadcast> to <set firewall global-options directed-broadcas [enable|disable]

from sys import argv
from sys import exit

from vyos.configtree import ConfigTree

if len(argv) < 2:
print("Must specify file name!")
exit(1)

file_name = argv[1]

with open(file_name, 'r') as f:
config_file = f.read()

config = ConfigTree(config_file)

base = ['firewall']

if config.exists(['system', 'ip', 'disable-directed-broadcast']):
config.set(['firewall', 'global-options', 'directed-broadcast'], value='disable')
config.delete(['system', 'ip', 'disable-directed-broadcast'])

try:
with open(file_name, 'w') as f:
f.write(config.to_string())
except OSError as e:
print("Failed to save the modified config: {}".format(e))
exit(1)

0 comments on commit d8bca08

Please sign in to comment.