summaryrefslogtreecommitdiff
path: root/python/vyos/ifconfig
diff options
context:
space:
mode:
Diffstat (limited to 'python/vyos/ifconfig')
-rw-r--r--python/vyos/ifconfig/bridge.py6
-rw-r--r--python/vyos/ifconfig/geneve.py13
-rw-r--r--python/vyos/ifconfig/interface.py75
-rw-r--r--python/vyos/ifconfig/l2tpv3.py34
-rw-r--r--python/vyos/ifconfig/macsec.py16
-rw-r--r--python/vyos/ifconfig/macvlan.py15
-rw-r--r--python/vyos/ifconfig/vxlan.py14
-rw-r--r--python/vyos/ifconfig/wireless.py43
8 files changed, 75 insertions, 141 deletions
diff --git a/python/vyos/ifconfig/bridge.py b/python/vyos/ifconfig/bridge.py
index 4c76fe996..c133a56fc 100644
--- a/python/vyos/ifconfig/bridge.py
+++ b/python/vyos/ifconfig/bridge.py
@@ -13,6 +13,8 @@
# You should have received a copy of the GNU Lesser General Public
# License along with this library. If not, see <http://www.gnu.org/licenses/>.
+from netifaces import interfaces
+
from vyos.ifconfig.interface import Interface
from vyos.ifconfig.stp import STP
from vyos.validate import assert_boolean
@@ -228,8 +230,8 @@ class BridgeIf(Interface):
# remove interface from bridge
tmp = vyos_dict_search('member.interface_remove', config)
- if tmp:
- for member in tmp:
+ for member in (tmp or []):
+ if member in interfaces():
self.del_port(member)
STPBridgeIf = STP.enable(BridgeIf)
diff --git a/python/vyos/ifconfig/geneve.py b/python/vyos/ifconfig/geneve.py
index 0a13043cc..5c4597be8 100644
--- a/python/vyos/ifconfig/geneve.py
+++ b/python/vyos/ifconfig/geneve.py
@@ -13,7 +13,6 @@
# You should have received a copy of the GNU Lesser General Public
# License along with this library. If not, see <http://www.gnu.org/licenses/>.
-from copy import deepcopy
from vyos.ifconfig.interface import Interface
@Interface.register
@@ -51,18 +50,6 @@ class GeneveIf(Interface):
# interface is always A/D down. It needs to be enabled explicitly
self.set_admin_state('down')
- @classmethod
- def get_config(cls):
- """
- GENEVE interfaces require a configuration when they are added using
- iproute2. This static method will provide the configuration dictionary
- used by this class.
-
- Example:
- >> dict = GeneveIf().get_config()
- """
- return deepcopy(cls.default)
-
def update(self, config):
""" General helper function which works on a dictionary retrived by
get_config_dict(). It's main intention is to consolidate the scattered
diff --git a/python/vyos/ifconfig/interface.py b/python/vyos/ifconfig/interface.py
index be97b411b..d200fc7a8 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
@@ -86,6 +78,14 @@ class Interface(Control):
'shellcmd': 'ip -json link show dev {ifname}',
'format': lambda j: 'up' if 'UP' in jmespath.search('[*].flags | [0]', json.loads(j)) else 'down',
},
+ 'min_mtu': {
+ 'shellcmd': 'ip -json -detail link list dev {ifname}',
+ 'format': lambda j: jmespath.search('[*].min_mtu | [0]', json.loads(j)),
+ },
+ 'max_mtu': {
+ 'shellcmd': 'ip -json -detail link list dev {ifname}',
+ 'format': lambda j: jmespath.search('[*].max_mtu | [0]', json.loads(j)),
+ },
}
_command_set = {
@@ -182,6 +182,15 @@ class Interface(Control):
def exists(cls, ifname):
return os.path.exists(f'/sys/class/net/{ifname}')
+ @classmethod
+ def get_config(cls):
+ """
+ Some but not all interfaces require a configuration when they are added
+ using iproute2. This method will provide the configuration dictionary
+ used by this class.
+ """
+ return deepcopy(cls.default)
+
def __init__(self, ifname, **kargs):
"""
This is the base interface class which supports basic IP/MAC address
@@ -281,6 +290,28 @@ class Interface(Control):
cmd = 'ip link del dev {ifname}'.format(**self.config)
return self._cmd(cmd)
+ def get_min_mtu(self):
+ """
+ Get hardware minimum supported MTU
+
+ Example:
+ >>> from vyos.ifconfig import Interface
+ >>> Interface('eth0').get_min_mtu()
+ '60'
+ """
+ return int(self.get_interface('min_mtu'))
+
+ def get_max_mtu(self):
+ """
+ Get hardware maximum supported MTU
+
+ Example:
+ >>> from vyos.ifconfig import Interface
+ >>> Interface('eth0').get_max_mtu()
+ '9000'
+ """
+ return int(self.get_interface('max_mtu'))
+
def get_mtu(self):
"""
Get/set interface mtu in bytes.
@@ -290,7 +321,7 @@ class Interface(Control):
>>> Interface('eth0').get_mtu()
'1500'
"""
- return self.get_interface('mtu')
+ return int(self.get_interface('mtu'))
def set_mtu(self, mtu):
"""
@@ -1013,7 +1044,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 +1092,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):
"""
@@ -1092,12 +1123,12 @@ class VLANIf(Interface):
def _create(self):
# bail out early if interface already exists
- if os.path.exists(f'/sys/class/net/{self.ifname}'):
+ if self.exists(f'{self.ifname}'):
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']:
@@ -1108,20 +1139,6 @@ class VLANIf(Interface):
# interface is always A/D down. It needs to be enabled explicitly
self.set_admin_state('down')
- @staticmethod
- def get_config():
- """
- MACsec interfaces require a configuration when they are added using
- iproute2. This static method will provide the configuration dictionary
- used by this class.
-
- Example:
- >> dict = VLANIf().get_config()
- """
- config = deepcopy(__class__.default)
- del config['type']
- return config
-
def set_admin_state(self, state):
"""
Set interface administrative state to be 'up' or 'down'
diff --git a/python/vyos/ifconfig/l2tpv3.py b/python/vyos/ifconfig/l2tpv3.py
index 33740921e..5fd90f9cf 100644
--- a/python/vyos/ifconfig/l2tpv3.py
+++ b/python/vyos/ifconfig/l2tpv3.py
@@ -13,7 +13,6 @@
# You should have received a copy of the GNU Lesser General Public
# License along with this library. If not, see <http://www.gnu.org/licenses/>.
-import os
from vyos.ifconfig.interface import Interface
@Interface.register
@@ -28,6 +27,15 @@ class L2TPv3If(Interface):
default = {
'type': 'l2tp',
+ 'peer_tunnel_id': '',
+ 'local_port': 0,
+ 'remote_port': 0,
+ 'encapsulation': 'udp',
+ 'local_address': '',
+ 'remote_address': '',
+ 'session_id': '',
+ 'tunnel_id': '',
+ 'peer_session_id': ''
}
definition = {
**Interface.definition,
@@ -73,7 +81,7 @@ class L2TPv3If(Interface):
>>> i.remove()
"""
- if os.path.exists('/sys/class/net/{}'.format(self.config['ifname'])):
+ if self.exists(self.config['ifname']):
# interface is always A/D down. It needs to be enabled explicitly
self.set_admin_state('down')
@@ -86,25 +94,3 @@ class L2TPv3If(Interface):
cmd = 'ip l2tp del tunnel tunnel_id {tunnel_id}'
self._cmd(cmd.format(**self.config))
- @staticmethod
- def get_config():
- """
- L2TPv3 interfaces require a configuration when they are added using
- iproute2. This static method will provide the configuration dictionary
- used by this class.
-
- Example:
- >> dict = L2TPv3If().get_config()
- """
- config = {
- 'peer_tunnel_id': '',
- 'local_port': 0,
- 'remote_port': 0,
- 'encapsulation': 'udp',
- 'local_address': '',
- 'remote_address': '',
- 'session_id': '',
- 'tunnel_id': '',
- 'peer_session_id': ''
- }
- return config
diff --git a/python/vyos/ifconfig/macsec.py b/python/vyos/ifconfig/macsec.py
index 6f570d162..456686ea6 100644
--- a/python/vyos/ifconfig/macsec.py
+++ b/python/vyos/ifconfig/macsec.py
@@ -56,22 +56,6 @@ class MACsecIf(Interface):
# interface is always A/D down. It needs to be enabled explicitly
self.set_admin_state('down')
- @staticmethod
- def get_config():
- """
- MACsec interfaces require a configuration when they are added using
- iproute2. This static method will provide the configuration dictionary
- used by this class.
-
- Example:
- >> dict = MACsecIf().get_config()
- """
- config = {
- 'security_cipher': '',
- 'source_interface': '',
- }
- return config
-
def update(self, config):
""" General helper function which works on a dictionary retrived by
get_config_dict(). It's main intention is to consolidate the scattered
diff --git a/python/vyos/ifconfig/macvlan.py b/python/vyos/ifconfig/macvlan.py
index 9c1d09c1c..2447fec77 100644
--- a/python/vyos/ifconfig/macvlan.py
+++ b/python/vyos/ifconfig/macvlan.py
@@ -1,4 +1,4 @@
-# Copyright 2019 VyOS maintainers and contributors <maintainers@vyos.io>
+# Copyright 2019-2020 VyOS maintainers and contributors <maintainers@vyos.io>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
@@ -13,7 +13,6 @@
# You should have received a copy of the GNU Lesser General Public
# License along with this library. If not, see <http://www.gnu.org/licenses/>.
-from copy import deepcopy
from vyos.ifconfig.interface import Interface
@Interface.register
@@ -53,18 +52,6 @@ class MACVLANIf(Interface):
cmd = f'ip link set dev {ifname} type macvlan mode {mode}'
return self._cmd(cmd)
- @classmethod
- def get_config(cls):
- """
- MACVLAN interfaces require a configuration when they are added using
- iproute2. This method will provide the configuration dictionary used
- by this class.
-
- Example:
- >> dict = MACVLANIf().get_config()
- """
- return deepcopy(cls.default)
-
def update(self, config):
""" General helper function which works on a dictionary retrived by
get_config_dict(). It's main intention is to consolidate the scattered
diff --git a/python/vyos/ifconfig/vxlan.py b/python/vyos/ifconfig/vxlan.py
index dba62b61a..ad1f605ed 100644
--- a/python/vyos/ifconfig/vxlan.py
+++ b/python/vyos/ifconfig/vxlan.py
@@ -13,8 +13,6 @@
# You should have received a copy of the GNU Lesser General Public
# License along with this library. If not, see <http://www.gnu.org/licenses/>.
-from copy import deepcopy
-
from vyos import ConfigError
from vyos.ifconfig.interface import Interface
@@ -97,18 +95,6 @@ class VXLANIf(Interface):
self._cmd(cmd)
- @classmethod
- def get_config(cls):
- """
- VXLAN interfaces require a configuration when they are added using
- iproute2. This static method will provide the configuration dictionary
- used by this class.
-
- Example:
- >> dict = VXLANIf().get_config()
- """
- return deepcopy(cls.default)
-
def update(self, config):
""" General helper function which works on a dictionary retrived by
get_config_dict(). It's main intention is to consolidate the scattered
diff --git a/python/vyos/ifconfig/wireless.py b/python/vyos/ifconfig/wireless.py
index 346577119..deca68bf0 100644
--- a/python/vyos/ifconfig/wireless.py
+++ b/python/vyos/ifconfig/wireless.py
@@ -23,8 +23,10 @@ class WiFiIf(Interface):
default = {
'type': 'wifi',
- 'phy': 'phy0'
+ 'phy': '',
+ 'wds': 'off',
}
+
definition = {
**Interface.definition,
**{
@@ -33,12 +35,19 @@ class WiFiIf(Interface):
'bridgeable': True,
}
}
+
options = Interface.options + \
['phy', 'op_mode']
+ _command_set = {**Interface._command_set, **{
+ '4addr': {
+ 'shellcmd': 'iw dev {ifname} set 4addr {value}',
+ },
+ }}
+
def _create(self):
# all interfaces will be added in monitor mode
- cmd = 'iw phy {phy} interface add {ifname} type monitor' \
+ cmd = 'iw phy {phy} interface add {ifname} type monitor 4addr {wds}' \
.format(**self.config)
self._cmd(cmd)
@@ -50,21 +59,8 @@ class WiFiIf(Interface):
.format(**self.config)
self._cmd(cmd)
- @staticmethod
- def get_config():
- """
- WiFi interfaces require a configuration when they are added using
- iw (type/phy). This static method will provide the configuration
- ictionary used by this class.
-
- Example:
- >> conf = WiFiIf().get_config()
- """
- config = {
- 'phy': 'phy0'
- }
- return config
-
+ def set_4aadr_mode(self, state):
+ return self.set_interface('4addr', state)
def update(self, config):
""" General helper function which works on a dictionary retrived by
@@ -72,22 +68,11 @@ class WiFiIf(Interface):
interface setup code and provide a single point of entry when workin
on any interface. """
- # We can not call add_to_bridge() until wpa_supplicant is running, thus
- # we will remove the key from the config dict and react to this specal
- # case in thie derived class.
- # re-add ourselves to any bridge we might have fallen out of
- bridge_member = ''
- if 'is_bridge_member' in config:
- bridge_member = config['is_bridge_member']
- del config['is_bridge_member']
+ self.set_4aadr_mode('on' if 'wds' in config else 'off')
# call base class first
super().update(config)
- # re-add ourselves to any bridge we might have fallen out of
- if bridge_member:
- self.add_to_bridge(bridge_member)
-
# Enable/Disable of an interface must always be done at the end of the
# derived class to make use of the ref-counting set_admin_state()
# function. We will only enable the interface if 'up' was called as