summaryrefslogtreecommitdiff
path: root/src/migration-scripts
diff options
context:
space:
mode:
authorjack9603301 <jack9603301@163.com>2021-01-09 21:32:19 +0800
committerjack9603301 <jack9603301@163.com>2021-01-15 16:26:33 +0800
commit38566b8fbdec60b1601ed127fd759c85802909e9 (patch)
tree00a658fbeb2d2b27fe3d7def53b9bbdb681de0c3 /src/migration-scripts
parent931692c5e4b15eb5ab62cd537ffd915365429e1c (diff)
downloadvyos-1x-38566b8fbdec60b1601ed127fd759c85802909e9.tar.gz
vyos-1x-38566b8fbdec60b1601ed127fd759c85802909e9.zip
bridge: T3137: Let VLAN aware bridge approach the behavior of professional equipment
According to the consensus, the specific behavior of a VLAN aware bridge should conform to the behavior of professional equipment. This commit makes a significant change to the behavior of VLAN aware bridge, and has the following behaviors: 1. Disable `vif 1` configuration 2. When the VLAN aware bridge is enabled, the parent interface is always VLAN 1 3. When `native-vlan` is not configured, the default behavior of the device is `native-vlan 1` 4. The VLAN ids forwarded by the bridge are determined by `vif` 5. It has an `enable-vlan` node to enable VLAN awareness 6. VLAN configuration is allowed only when VLAN aware bridge is activated
Diffstat (limited to 'src/migration-scripts')
-rwxr-xr-xsrc/migration-scripts/interfaces/18-to-1984
1 files changed, 84 insertions, 0 deletions
diff --git a/src/migration-scripts/interfaces/18-to-19 b/src/migration-scripts/interfaces/18-to-19
new file mode 100755
index 000000000..86b2343b9
--- /dev/null
+++ b/src/migration-scripts/interfaces/18-to-19
@@ -0,0 +1,84 @@
+#!/usr/bin/env python3
+#
+# Copyright (C) 2020 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/>.
+
+# VLAN 1 command line migration for bridge aware
+# https://phabricator.vyos.net/T3137
+
+import sys
+from vyos.configtree import ConfigTree
+
+if __name__ == '__main__':
+ if (len(sys.argv) < 1):
+ print("Must specify file name!")
+ sys.exit(1)
+
+ file_name = sys.argv[1]
+
+ with open(file_name, 'r') as f:
+ config_file = f.read()
+
+ config = ConfigTree(config_file)
+ base = ['interfaces', 'bridge']
+ if not config.exists(base):
+ # Nothing to do
+ sys.exit(0)
+
+ vlan_add = set()
+
+ for interface in config.list_nodes(base):
+ vif_1_old_base = base + [interface, 'vif', '1']
+ if config.exists(vif_1_old_base):
+ address_base = vif_1_old_base + ['address']
+ if config.exists(address_base):
+ address = config.return_values(address_base)
+ for addr in address:
+ config.set(base + [interface, 'address'],addr,False)
+ config.delete(vif_1_old_base)
+
+ # Get all VLANs
+ member_base = base + [interface, 'member', 'interface']
+ if config.exists(member_base):
+ for mem_intf in config.list_nodes(member_base):
+ native_vlan_base = member_base + [mem_intf,'native-vlan']
+ allowed_vlan_base = member_base + [mem_intf,'allowed-vlan']
+ if config.exists(native_vlan_base):
+ vlan = config.return_values(native_vlan_base)[0]
+ vlan_add.add(vlan)
+
+ if config.exists(allowed_vlan_base):
+ vlan_ranges = config.return_values(allowed_vlan_base)
+ for vlan_range in vlan_ranges:
+ vlan_data = vlan_range.split('-')
+ for vlan in range(int(vlan_data[0]),int(vlan_data[1])+1):
+ vlan_add.add(vlan)
+
+ # Start configuration
+ if len(vlan_add):
+ for vlan in vlan_add:
+ if int(vlan) != 1:
+ config.set(base + [interface, 'vif', vlan])
+ config.set(base + [interface, 'enable-vlan'])
+
+
+ config.set_tag(base + [interface])
+
+
+ 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))
+ sys.exit(1)