summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--interface-definitions/include/vif-s.xml.i19
-rw-r--r--python/vyos/ifconfig/interface.py18
-rwxr-xr-xsrc/migration-scripts/interfaces/12-to-1357
3 files changed, 72 insertions, 22 deletions
diff --git a/interface-definitions/include/vif-s.xml.i b/interface-definitions/include/vif-s.xml.i
index a6d7c81ce..cd0afe742 100644
--- a/interface-definitions/include/vif-s.xml.i
+++ b/interface-definitions/include/vif-s.xml.i
@@ -13,25 +13,26 @@
#include <include/dhcpv6-options.xml.i>
#include <include/interface-disable-link-detect.xml.i>
#include <include/interface-disable.xml.i>
- <leafNode name="ethertype">
+ <leafNode name="protocol">
<properties>
- <help>Set Ethertype</help>
+ <help>Protocol used for service VLAN (default: 802.1ad)</help>
<completionHelp>
- <list>0x88A8 0x8100</list>
+ <list>802.1ad 802.1q</list>
</completionHelp>
<valueHelp>
- <format>0x88A8</format>
- <description>802.1ad</description>
+ <format>802.1ad</format>
+ <description>Provider Bridging (IEEE 802.1ad, Q-inQ), ethertype 0x88a8</description>
</valueHelp>
<valueHelp>
- <format>0x8100</format>
- <description>802.1q</description>
+ <format>802.1q</format>
+ <description>VLAN-tagged frame (IEEE 802.1q), ethertype 0x8100</description>
</valueHelp>
<constraint>
- <regex>(0x88A8|0x8100)</regex>
+ <regex>(802.1q|802.1ad)</regex>
</constraint>
- <constraintErrorMessage>Ethertype must be 0x88A8 or 0x8100</constraintErrorMessage>
+ <constraintErrorMessage>Ethertype must be 802.1ad or 802.1q</constraintErrorMessage>
</properties>
+ <defaultValue>802.1ad</defaultValue>
</leafNode>
<node name="ip">
<children>
diff --git a/python/vyos/ifconfig/interface.py b/python/vyos/ifconfig/interface.py
index be97b411b..4e420dc1d 100644
--- a/python/vyos/ifconfig/interface.py
+++ b/python/vyos/ifconfig/interface.py
@@ -50,14 +50,6 @@ from vyos.ifconfig.vrrp import VRRP
from vyos.ifconfig.operational import Operational
from vyos.ifconfig import Section
-def get_ethertype(ethertype_val):
- if ethertype_val == '0x88A8':
- return '802.1ad'
- elif ethertype_val == '0x8100':
- return '802.1q'
- else:
- raise ConfigError('invalid ethertype "{}"'.format(ethertype_val))
-
class Interface(Control):
# This is the class which will be used to create
# self.operational, it allows subclasses, such as
@@ -1013,7 +1005,7 @@ class Interface(Control):
# create/update 802.1ad (Q-in-Q VLANs)
for vif_s_id, vif_s_config in config.get('vif_s', {}).items():
tmp = deepcopy(VLANIf.get_config())
- tmp['ethertype'] = get_ethertype(vif_s_config.get('ethertype', '0x88A8'))
+ tmp['protocol'] = vif_s_config['protocol']
tmp['source_interface'] = ifname
tmp['vlan_id'] = vif_s_id
@@ -1061,13 +1053,13 @@ class VLANIf(Interface):
'type': 'vlan',
'source_interface': '',
'vlan_id': '',
- 'ethertype': '',
+ 'protocol': '',
'ingress_qos': '',
'egress_qos': '',
}
options = Interface.options + \
- ['source_interface', 'vlan_id', 'ethertype', 'ingress_qos', 'egress_qos']
+ ['source_interface', 'vlan_id', 'protocol', 'ingress_qos', 'egress_qos']
def remove(self):
"""
@@ -1096,8 +1088,8 @@ class VLANIf(Interface):
return
cmd = 'ip link add link {source_interface} name {ifname} type vlan id {vlan_id}'
- if self.config['ethertype']:
- cmd += ' proto {ethertype}'
+ if self.config['protocol']:
+ cmd += ' protocol {protocol}'
if self.config['ingress_qos']:
cmd += ' ingress-qos-map {ingress_qos}'
if self.config['egress_qos']:
diff --git a/src/migration-scripts/interfaces/12-to-13 b/src/migration-scripts/interfaces/12-to-13
new file mode 100755
index 000000000..17d1d0b0a
--- /dev/null
+++ b/src/migration-scripts/interfaces/12-to-13
@@ -0,0 +1,57 @@
+#!/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/>.
+
+# - T2903: Change vif-s ethertype from numeric number to literal
+# - 0x88a8 -> 802.1ad
+# - 0x8100 -> 802.1q
+
+from sys import exit, argv
+from vyos.configtree import ConfigTree
+
+if __name__ == '__main__':
+ if (len(argv) < 1):
+ 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)
+
+ for type in config.list_nodes(['interfaces']):
+ for interface in config.list_nodes(['interfaces', type]):
+ if not config.exists(['interfaces', type, interface, 'vif-s']):
+ continue
+
+ for vif_s in config.list_nodes(['interfaces', type, interface, 'vif-s']):
+ base_path = ['interfaces', type, interface, 'vif-s', vif_s]
+ if config.exists(base_path + ['ethertype']):
+ protocol = '802.1ad'
+ tmp = config.return_value(base_path + ['ethertype'])
+ if tmp == '0x8100':
+ protocol = '802.1q'
+
+ config.set(base_path + ['protocol'], value=protocol)
+ config.delete(base_path + ['ethertype'])
+
+ 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)
+