Skip to content

Commit 599d40b

Browse files
pandafynemesifier
andauthored
[fix] Fixed bridges renamed on OpenWrt 21 #243
Fixes #243 Co-authored-by: Federico Capoano <f.capoano@openwisp.io>
1 parent 5a26879 commit 599d40b

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

netjsonconfig/backends/openwrt/converters/interfaces.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,21 @@ def __intermediate_device(self, interface):
229229
# A non-bridge interface that contains L2 options.
230230
return device
231231
device['type'] = 'bridge'
232+
if not interface['ifname'].startswith('br-'):
233+
# Add "br-" prefix to the bridge name
234+
# for backward compatibility: OpenWrt <= 19
235+
# automatically added the "br-" prefix to bridges,
236+
# but later in OpenWrt 21 the bridge logic changed
237+
# and that is no longer true, for that reason
238+
# old configurations of OpenWISP made for OpenWrt 19
239+
# which relied on the bridge names to be prefixed
240+
# automatically with "br-" were breaking;
241+
# to resolve this backward compatibility issue
242+
# we now add the "br-" prefix automatically if needed.
243+
interface['ifname'] = f'br-{interface["ifname"]}'
244+
device['name'] = interface['ifname']
245+
interface['device'] = device['name']
246+
232247
# Add STP options only if STP is enabled
233248
self._add_options(
234249
'stp', self._bridge_interface_options['stp'], device, interface
@@ -439,7 +454,7 @@ def __get_device_config_for_interface(self, interface):
439454
del device_config['type']
440455
# ifname has been renamed to device in OpenWrt 21.02
441456
if device_config.get('type') == 'bridge':
442-
interface['ifname'] = 'br-{}'.format(interface.pop('device'))
457+
interface['ifname'] = interface.pop('device')
443458
elif interface.get('proto') not in self._proto_dsa_conflict:
444459
interface['ifname'] = interface.pop('device')
445460
return device_config

tests/openwrt/test_interfaces_dsa.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -874,21 +874,21 @@ def test_parse_simple_bridge(self):
874874
option proto 'none'
875875
876876
config device 'device_lan'
877-
option name 'lan'
877+
option name 'br-lan'
878878
list ports 'eth0'
879879
list ports 'eth1'
880880
option stp '1'
881881
option type 'bridge'
882882
883883
config interface 'lan'
884-
option device 'lan'
884+
option device 'br-lan'
885885
option gateway '10.0.0.10'
886886
list ipaddr '192.168.1.1/24'
887887
list ipaddr '10.0.0.1/24'
888888
option proto 'static'
889889
890890
config interface 'lan_2'
891-
option device 'lan'
891+
option device 'br-lan'
892892
option proto 'dhcp'
893893
"""
894894

0 commit comments

Comments
 (0)