Skip to content

Commit

Permalink
[fix] Fixed bridges renamed on OpenWrt 21 #243
Browse files Browse the repository at this point in the history
Fixes #243

Co-authored-by: Federico Capoano <[email protected]>
(cherry picked from commit 599d40b)
  • Loading branch information
pandafy authored and nemesifier committed Nov 29, 2022
1 parent f240a4f commit ccfb1c5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
17 changes: 16 additions & 1 deletion netjsonconfig/backends/openwrt/converters/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,21 @@ def __intermediate_device(self, interface):
# A non-bridge interface that contains L2 options.
return device
device['type'] = 'bridge'
if not interface['ifname'].startswith('br-'):
# Add "br-" prefix to the bridge name
# for backward compatibility: OpenWrt <= 19
# automatically added the "br-" prefix to bridges,
# but later in OpenWrt 21 the bridge logic changed
# and that is no longer true, for that reason
# old configurations of OpenWISP made for OpenWrt 19
# which relied on the bridge names to be prefixed
# automatically with "br-" were breaking;
# to resolve this backward compatibility issue
# we now add the "br-" prefix automatically if needed.
interface['ifname'] = f'br-{interface["ifname"]}'
device['name'] = interface['ifname']
interface['device'] = device['name']

# Add STP options only if STP is enabled
self._add_options(
'stp', self._bridge_interface_options['stp'], device, interface
Expand Down Expand Up @@ -439,7 +454,7 @@ def __get_device_config_for_interface(self, interface):
del device_config['type']
# ifname has been renamed to device in OpenWrt 21.02
if device_config.get('type') == 'bridge':
interface['ifname'] = 'br-{}'.format(interface.pop('device'))
interface['ifname'] = interface.pop('device')
elif interface.get('proto') not in self._proto_dsa_conflict:
interface['ifname'] = interface.pop('device')
return device_config
Expand Down
6 changes: 3 additions & 3 deletions tests/openwrt/test_interfaces_dsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -874,21 +874,21 @@ def test_parse_simple_bridge(self):
option proto 'none'
config device 'device_lan'
option name 'lan'
option name 'br-lan'
list ports 'eth0'
list ports 'eth1'
option stp '1'
option type 'bridge'
config interface 'lan'
option device 'lan'
option device 'br-lan'
option gateway '10.0.0.10'
list ipaddr '192.168.1.1/24'
list ipaddr '10.0.0.1/24'
option proto 'static'
config interface 'lan_2'
option device 'lan'
option device 'br-lan'
option proto 'dhcp'
"""

Expand Down

0 comments on commit ccfb1c5

Please sign in to comment.