Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 3.9.0 #318

Open
wants to merge 132 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
132 commits
Select commit Hold shift + click to select a range
e15ced6
addons: address: get default mac address from policy
julienfortin Oct 30, 2024
c8fb057
SONAR: addons: address: Merge if statement with the enclosing one.
julienfortin May 30, 2022
f0639a9
addons: address: special diff mode handling for stale fdb entries
julienfortin Oct 30, 2024
d3d6e32
addons: address: dont reset swp's mac if part of a bond
julienfortin Jul 12, 2024
05461a0
addons: address: reset mac address on switch port
Jul 30, 2024
0599c25
addons: address: Changing bond member port mac addr should not get ap…
Jul 22, 2024
245fe81
addons: addressvirtual: vrr macvlan is created even if address-virtua…
Jun 18, 2024
1337235
addons: addressvirtual: fix regex to allow single digit segments
julienfortin Sep 19, 2024
cd28db9
addressvirtual: set accept_dad=0 before link up
aroulin Apr 17, 2024
c1ae42c
addons: bond: don't speed check downed slave
julienfortin Apr 26, 2024
621f539
addons: bond: removing bond-slave speed check
julienfortin Sep 19, 2024
2980792
addons: bond: change bond mac inheritance code (any slave mac is fine)
julienfortin Nov 28, 2023
97fb31c
addons: bond: fix 'list index out of range' error when removing first…
julienfortin Jan 5, 2024
aae38cd
SONAR: bridge: Rename class "bridgeFlags" to match the regular expres…
julienfortin May 30, 2022
67944c5
addons: bridge: remove deprecated bridge-hashel default value
julienfortin Jan 23, 2024
d0ca062
SONAR: bridge: Merge if statements with the enclosing ones
julienfortin May 30, 2022
353dcfb
SONAR: dhcp: rename DHCLIENT_RETRY_ON_FAILURE constant to avoid namin…
julienfortin May 30, 2022
08650b1
addons: dhcp: new policy: dhclient_no_wait_on_reload
julienfortin Jun 16, 2022
b174e20
SONAR: dhcp: Rename this parameter "dhclientX_running" to match the r…
julienfortin May 30, 2022
d8b9c2f
sonarlink: use the opposite operation 'not in'
julienfortin Feb 15, 2023
a518621
addons: dhcp: bring dhcp config down if link-down yes is set
julienfortin Sep 18, 2024
49945ff
SONAR: Remove redundant Exception class; it derives from another whic…
julienfortin May 30, 2022
a71a614
SONAR: dhcp: remove uneeded pass statement
julienfortin May 30, 2022
ae4f53a
SONAR: addons: address: Remove redundant return and pass statement
julienfortin May 30, 2022
2230ff1
SONAR: addons: bond: removed uneeded "pass" statement
julienfortin May 30, 2022
b6f91cb
SONAR: addressvirtual: Remove unneeded "pass".
julienfortin May 30, 2022
5db0421
SONAR: bridge: remove uneeded pass stateme
julienfortin May 30, 2022
387d447
SONAR: mstpctl: remove uneeded pass statement
julienfortin May 31, 2022
59d76d9
SONAR: usercmds: remove unneeded pass statement
julienfortin May 31, 2022
ba18a63
SONAR: vrf: remove unneeded pass statement and fix exception handler …
julienfortin May 31, 2022
ee6e5c5
SONAR: vrrpd: remove unneeded pass statement
julienfortin May 31, 2022
687a35b
SONAR: link: Merge this if statement with the enclosing one
julienfortin May 30, 2022
e5ae0fc
SONAR: vrf: Merge if statement with the enclosing one
julienfortin May 31, 2022
b6721ea
SONAR: vrf: Remove commented out code
julienfortin May 31, 2022
af52e66
SONAR: vrf: Rename class "vrfPrivFlags" to match the regular expressi…
julienfortin May 31, 2022
8c82fe2
SONAR: vrf: remove unneeded return statement
julienfortin May 31, 2022
375a838
SONAR: vrf: remove unneeded try/except
julienfortin May 31, 2022
fe73211
addons: vrf: unslave macvlans if vrf is removed from lower interface
julienfortin Apr 18, 2024
d46afbb
SONAR: bridgevlan: remove this redundant return statement
julienfortin May 30, 2022
e4f18c2
addons: vxlan: vxlan_tos_str will never be None/Null
julienfortin Nov 30, 2022
4b286f8
SONAR: vxlan: Rename map variable; it shadows a builtin
julienfortin May 31, 2022
59da367
addons: vxlan: svd: reset local and group ip when removed from user c…
julienfortin Aug 10, 2023
43dd5a3
addons: vxlan: set remoteip as an empty list if removed
julienfortin Apr 12, 2024
d565ead
SONAR: vxlan: Merge if statements with the enclosing ones
julienfortin May 31, 2022
1ff0d8f
addons: vxlan: cleaning up duplicated fdb vnifilter code
julienfortin Apr 17, 2024
5eff9ba
addons: vxlan: fix: name 'json' is not defined
julienfortin Jun 16, 2022
340edab
SONAR: argv: Remove the unused local variable "e"
julienfortin May 31, 2022
a574d8c
sonarlink: remove unused function parameter
julienfortin Feb 15, 2023
879e284
ifupdown: main: fix code indentation
julienfortin Oct 31, 2024
ebe5076
ifupdown: main: remove unnecessary try/except
julienfortin Oct 31, 2024
0d25d6a
sonarlink: merge if statements with enclosing ones
julienfortin Feb 15, 2023
c6160b1
ifupdownmain: rename variable to not shadow python built-in
julienfortin Feb 15, 2023
29e7843
ifupdownmain: remove unnecessary try/except
julienfortin Oct 31, 2024
c416953
Bad use of null-like value (FORWARD_NULL) 6. invalid_operation: Inval…
julienfortin Nov 30, 2022
209899c
nlmanager: Bad use of null-like value (FORWARD_NULL) 4. invalid_opera…
julienfortin Nov 30, 2022
c8e19a1
lib: log: disable persistent debug log for ifquery
julienfortin Apr 15, 2024
e9cebfd
ifupdownmain: remove unnecessary try/except
julienfortin Oct 31, 2024
956bf60
json not imported in networkinterfaces.py
slaffer-au Jul 25, 2022
fae326c
policymanager: ignore "README" elements
julienfortin Jul 25, 2024
e8c2bd1
statemanager: remove uncessary try/except
julienfortin Oct 31, 2024
8402991
log: dump sys.argv when log.debug is used
julienfortin Dec 21, 2022
7688f24
iproute2: bridge vni only accepts "delete" not "del"
aroulin Apr 12, 2024
fff2ef5
addons: address: fix traceback bridge: 'NoneType' object has no attri…
Aug 6, 2024
93aebdf
sonarlink: replace generic exception with a more specific one
julienfortin Feb 15, 2023
c6b9376
SONAR: addons: address: remove unused local variables
julienfortin May 30, 2022
82432a4
addons: bridge: fix TypeError & AttributeError when no bridge-ports i…
julienfortin Jun 19, 2023
3887109
addons: ethtool: re-applying link-speed to reset link-lanes to defaul…
julienfortin Oct 30, 2023
f928878
nlcache: fix dry-run function prototype (missing arguments)
julienfortin May 30, 2023
775d918
lib: nlcache: remove unnecessary try/except
julienfortin Nov 6, 2024
7f9791d
vlan: add vxlan hopping filter
julienfortin Nov 6, 2024
6e9c989
lib: addon: removing duplicated get_bridge_port_list method
julienfortin Jan 25, 2024
281a4b1
addons: vxlan: bridge port cycling on VNI-VLAN mapping changes
julienfortin Oct 10, 2024
128939c
addons: bridge: avoid checking reserved vlan range on l3vni bridge
julienfortin Dec 11, 2023
2d3f57e
ifreload: new --diff cli argument: only reload delta between /e/n/i
julienfortin Jan 11, 2024
b5dda06
ifreload-diff: propagate mtu from physical interface to upper devs
julienfortin Apr 23, 2024
c82c84c
lib: addon: removing duplicated get_bridge_port_list method
julienfortin Jan 25, 2024
9dee032
addons: bridge: add missing statemanager import
julienfortin Nov 28, 2024
6ea3050
vlan: add ifaceobj_getfunc to vlan
julienfortin Nov 28, 2024
7a929a4
sonarlink: various fixes
julienfortin Feb 15, 2023
7b06712
addons: vxlan: remove ifupdownaddons.cache import
julienfortin Nov 28, 2024
1db40e0
utilsbase: remove ifupdownaddons.cache import
julienfortin Nov 28, 2024
773be90
scheduler: run_queue: process child interface first
julienfortin Mar 26, 2024
c5c623e
ifreload-diff: process interface if not present on the system
julienfortin Apr 4, 2024
d473aec
diff: add lower dev of removed interfaces to the run queue
julienfortin Apr 15, 2024
849f6ec
diff-mode: reload all clagd interface if clagd change is detected
julienfortin Apr 30, 2024
218df68
diff-mode: check interface admin state during diff-check
julienfortin May 7, 2024
8ee517d
ifupdownmain: update log level for clagd change detected log
julienfortin Jul 24, 2024
a7fcaaa
ifupdownmain: diff-mode: save state even if there's no diff
julienfortin Apr 16, 2024
cc14664
sonarlink: remove uneeded 'pass'
julienfortin Feb 15, 2023
3c3910f
ifupdownmain: cleanups
julienfortin Nov 28, 2024
b4c3ea6
sonarlink: eliminate except clauses that are not required
julienfortin Feb 15, 2023
8ef3bab
scheduler: diff-mode: filter out interface based on the initial filte…
julienfortin Apr 5, 2024
9709d27
addons: mstpctl: add diff-mode check before brport configuration
julienfortin Jul 31, 2024
5796ff9
scheduler: diff-mode: set run queue as diff-list
julienfortin Apr 8, 2024
ea5d2f9
scheduler: use SchedulerException instead of broad Exception
julienfortin Nov 28, 2024
d771a54
enable per vlan snooping when config mcqv4src
Sep 3, 2024
8aab90e
use exist_ok=True when trying to create /run/network/ directory
julienfortin Aug 14, 2023
7a3766d
networkinterfaces.py: fix missing return statement
aroulin Mar 8, 2023
8185847
fix: unsupported operand type(s) for +=: 'int' and 'NoneType'
julienfortin Feb 20, 2023
57b16e6
sonarlink: remove uneeded 'continue' and 'return' statement
julienfortin Feb 15, 2023
b2476ce
statemanager: cleanups: remove empty lines
julienfortin Nov 28, 2024
eb2be19
__main__: use ModuleNotFounderror instead of Exception
julienfortin Nov 28, 2024
11226cf
Flush DHCP client lease files on boot up
slaffer-au Jul 25, 2024
7bc0519
nlpacket: AttributeIFLA_PROTINFO: loop over range to add padding
julienfortin Nov 29, 2024
d63cfc3
SONAR: ethtool: Merge this if statement with the enclosing one
julienfortin May 30, 2022
d5b8fe2
dead_error_line: Execution cannot reach the expression configured ins…
julienfortin Nov 30, 2022
44eb525
addons: ethtool: update check for back and forward compatibility
Apr 15, 2024
8a7fcdc
addons: ethtool: cleanups & sync with internal repo
julienfortin Nov 29, 2024
7d527e1
start-networking: add callable hooks
Sep 15, 2021
d432a2e
Pytest: add initial support for pytest with code coverage
julienfortin Feb 6, 2024
ed81155
pytest: conftest: use pprint to display json deepdiff
julienfortin Sep 19, 2024
57edafb
pytest: add ifreload-diff support - enabled by default
julienfortin Apr 9, 2024
4ce87bd
pytest: conftest: fix python code loading swp names
julienfortin Apr 9, 2024
20cfb8e
pytest: bridge vlan show: drop compressed vlan option
julienfortin Apr 9, 2024
aa1e229
pytest: test_l3: fix hardcoded swp name to swp_XX_ format
julienfortin Apr 9, 2024
82ca8bb
pytest: use assert_identical_json when checking json output
julienfortin Apr 17, 2024
cfde50b
tests: fix bridge_attr_back_to_default
julienfortin Sep 19, 2024
87ebc11
pytest: fix test_cm_11485_vlan_device_name_vlan
julienfortin Sep 19, 2024
5c9c88c
mstpctl: PVRST support
julienfortin Jul 25, 2023
19e2dc9
SONAR: mstpctl: Rename class "mstpctlFlags" to match the regular expr…
julienfortin May 31, 2022
638f26b
addons: mstpctl: set mstpctl-port-vlan-priority default to 128
julienfortin Jul 27, 2023
272e3f8
addons: mstpctl: remove pvrst-clag check
julienfortin Oct 10, 2023
2139f4b
addons: mstpctl: fix KeyError in query-running path
julienfortin Jul 27, 2023
610a621
addons: mstpctl: cache brport before applying user config
julienfortin Aug 4, 2023
8825c56
mstpctl: fix KeyError when fetching treeportprio
julienfortin Aug 12, 2023
bce1e1f
addons: mstpctl: handle mstpctl empty output
julienfortin Aug 16, 2023
81e349f
SONAR: mstpctl: Remove unused local variable "jsonAttr"
julienfortin May 31, 2022
636fa07
SONAR: mstpctl: Remove unused local variable "mstpctlcmdattrname"
julienfortin May 31, 2022
cf8c7f2
addons: mstpctl: SONAR cleanups
julienfortin Dec 2, 2024
b627f32
utils: catch mstpctl setmodepvrst exception and log debug
julienfortin Jul 31, 2023
9efd8a2
sync with downstream repo
julienfortin Dec 2, 2024
834bd6d
debian: changelog: new entry for version 3.9.0
julienfortin Dec 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,5 @@ ifupdown2/ifdown
ifupdown2/ifquery
ifupdown2/ifreload
ifupdown2/ifup

tests/results
32 changes: 32 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
ifupdown2 (3.9.0) unstable; urgency=medium

* New: ifreload: new --diff cli argument: only reload delta between /e/n/i
* New: Support for Per-VLAN Rapid Spanning Tree attributes:
mstpctl-pvrst-mode (on/off): Enable/disable PVRST mode
mstpctl-vlan-priority (range 4096-32768)
mstpctl-vlan-hello (range 1-10)
mstpctl-vlan-fdelay (range 4-30)
mstpctl-vlan-maxage (range 6-40)
mstpctl-port-vlan-path-cost (range 1-200000000)
mstpctl-port-vlan-priority (range 0-240)
* New: Get default mac address from policy file as 'address' iface_default
* New: Enable per vlan snooping when config mcqv4src
* New: Add vxlan hopping filter
* New: Add support for setting mac addresses via iface_defaults policy
* New: Reset mac address on switch port when 'hwaddress' is removed from eni
* New: Policy "dhclient_no_wait_on_reload": dhclient won't wait (default off)
* Fix: Bring DHCP config down if link-down yes is set
* Fix: Various code cleanups (SonarQube)
* Fix: Macvlan/VRR: set accept_dad=0 before link up
* Fix: Flush DHCP lease on boot up
* Fix: Disable persistent debug log for ifquery
* Fix:
* Fix: Vxlan clear last fdb entry when remoteip is removed from user config
* Fix: Vxlan reset local and group ip when removed from user config
* Fix: Re-applying link-speed to reset link-lanes to default when removed
* Fix: Missing json import in networkinterfaces.py and vxlan.py
* Fix: Nlmanager Invalid operation on null-like value range_flag
* Deprecated: remove bridge-hashel default value

-- Julien Fortin <[email protected]> Wed, 04 Dec 2024 23:42:00 -0800

ifupdown2 (3.3.0) unstable; urgency=medium

* New: performance improvement: replace glob.glob with os.listdir
Expand Down
2 changes: 1 addition & 1 deletion ifupdown2/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

__version__ = '3.0.0'
__version__ = '3.9.0'

# Copyright (C) 2014,2015,2016,2017,2018,2019,2020 Cumulus Networks, Inc. All rights reserved
#
Expand Down
7 changes: 5 additions & 2 deletions ifupdown2/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@
import os
import sys

sys.path.insert(0, "/root/ifupdown2/ifupdown2")
#sys.path.append("/usr/share/ifupdown2/")

try:
from ifupdown2.lib.log import LogManager, root_logger
from ifupdown2.lib.status import Status
except Exception:
except ModuleNotFoundError:
from lib.log import LogManager, root_logger
from lib.status import Status

Expand All @@ -47,7 +50,7 @@

from ifupdown2.ifupdown.client import Client
from ifupdown2.ifupdown.exceptions import ArgvParseHelp, ArgvParseError
except Exception:
except ModuleNotFoundError:
import ifupdown.config as config

config.__version__ = __import__("__init__").__version__
Expand Down
140 changes: 103 additions & 37 deletions ifupdown2/addons/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Author: Roopa Prabhu, [email protected]
#

import re
import socket
import json
import time
Expand All @@ -12,7 +13,7 @@
from setuptools.dist import strtobool

try:
from ifupdown2.lib.addon import AddonWithIpBlackList
from ifupdown2.lib.addon import AddonWithIpBlackList, AddonException
from ifupdown2.nlmanager.nlmanager import Link

from ifupdown2.ifupdown.iface import ifaceType, ifaceLinkKind, ifaceLinkPrivFlags, ifaceStatus, iface
Expand All @@ -27,8 +28,8 @@
import ifupdown2.ifupdown.policymanager as policymanager
import ifupdown2.ifupdown.ifupdownflags as ifupdownflags
import ifupdown2.ifupdown.ifupdownconfig as ifupdownconfig
except (ImportError, ModuleNotFoundError):
from lib.addon import AddonWithIpBlackList
except ImportError:
from lib.addon import AddonWithIpBlackList, AddonException
from nlmanager.nlmanager import Link

from ifupdown.iface import ifaceType, ifaceLinkKind, ifaceLinkPrivFlags, ifaceStatus, iface
Expand Down Expand Up @@ -269,6 +270,9 @@ def __init__(self, *args, **kargs):
self.logger.debug(f"policy: default_loopback_scope set to {self.default_loopback_scope}")
self.valid_scopes = self.get_mod_subattr("scope", "validvals")

self.mac_regex = re.compile(r"^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$")


def __policy_get_default_mtu(self):
default_mtu = policymanager.policymanager_api.get_attr_default(
module_name=self.__class__.__name__,
Expand Down Expand Up @@ -373,12 +377,12 @@ def syntax_check_enable_l3_iface_forwardings(self, ifaceobj, ifaceobj_getfunc, s

if vlan_addr and vlan_ipforward_off:
if syntax_check:
raise Exception(
raise AddonException(
'configuring ip-forward off and ip address(es) (%s) is not compatible'
% (', '.join(vlan_addr))
)
else:
raise Exception(
raise AddonException(
'%s: configuring ip-forward off and ip address(es) (%s) is not compatible'
% (ifname, ', '.join(vlan_addr))
)
Expand Down Expand Up @@ -419,7 +423,7 @@ def syntax_check_addr_allowed_on(self, ifaceobj, syntax_check=False):
def _syntax_check_multiple_gateway(self, family, found, addr, version):
if ipnetwork.IPNetwork(addr).version == version:
if found:
raise Exception('%s: multiple gateways for %s family'
raise AddonException('%s: multiple gateways for %s family'
% (addr, family))
return True
return False
Expand Down Expand Up @@ -457,11 +461,10 @@ def _process_bridge(self, ifaceobj, up, hwaddress, old_mac_addr=None):
arp_accept = utils.boolean_support_binary(arp_accept)
is_vlan_dev_on_vlan_aware_bridge = False
is_bridge = self.cache.get_link_kind(ifaceobj.name) == 'bridge'
if not is_bridge:
if ifaceobj.link_kind & ifaceLinkKind.VLAN:
bridgename = ifaceobj.lowerifaces[0]
vlan = self._get_vlan_id(ifaceobj)
is_vlan_dev_on_vlan_aware_bridge = self.cache.bridge_is_vlan_aware(bridgename)
if not is_bridge and ifaceobj.link_kind & ifaceLinkKind.VLAN:
bridgename = ifaceobj.lowerifaces[0]
vlan = self._get_vlan_id(ifaceobj)
is_vlan_dev_on_vlan_aware_bridge = self.cache.bridge_is_vlan_aware(bridgename)
if ((is_bridge and not self.cache.bridge_is_vlan_aware(ifaceobj.name))
or is_vlan_dev_on_vlan_aware_bridge):
if self._address_valid(addrs):
Expand Down Expand Up @@ -499,6 +502,33 @@ def _process_bridge(self, ifaceobj, up, hwaddress, old_mac_addr=None):
else:
self.iproute2.bridge_fdb_del(bridgename, hwaddress, vlan)

if is_bridge:
# Get the link hwaddress of bridge if we cannot find it in defaults
if not hwaddress:
hwaddress = self.cache.get_link_address(ifaceobj.name)

# we need to do an fdb check during bridge processing and purge stale macs
fdbs = self._get_bridge_fdbs(ifaceobj.name)

# Save the permanent MACs for comparison too, as this can be used to preserve
# perm entries for VRR interfaces.
valid_macs = set([utils.mac_str_to_int(i) for i in fdbs.get('permanent', [])])
# Add the actual bridge MAC to this set too.
valid_macs.add(utils.mac_str_to_int(hwaddress))

# Now iterate and purge if it's not a valid mac.
for vlan, macs in fdbs.items():
for mac in macs:
if utils.mac_str_to_int(mac) not in valid_macs:
self.logger.info(f"{ifaceobj.name}: stale fdb entry ({mac}) detected on vlan {vlan}")
try:
if vlan == 'permanent':
self.iproute2.bridge_fdb_del(ifaceobj.name, mac)
else:
self.iproute2.bridge_fdb_del(ifaceobj.name, mac, vlan)
except Exception as e:
self.logger.debug(f"{ifaceobj.name}: bridge_fdb_del failed: {str(e)}")

def __get_ip_addr_with_attributes(self, ifaceobj_list, ifname):
user_config_ip_addrs_list = []

Expand Down Expand Up @@ -809,6 +839,16 @@ def _check_mtu_config(self, ifaceobj, mtu_str, mtu_int, ifaceobj_getfunc, syntax
return retval

def _propagate_mtu_to_upper_devs(self, ifaceobj, mtu_str, mtu_int, ifaceobj_getfunc):
if not (
(not ifupdownflags.flags.ALL or ifupdownconfig.diff_mode) and
not ifaceobj.link_kind and
ifupdownconfig.config.get('adjust_logical_dev_mtu', '1') != '0'
):
# This is additional cost to us, so do it only when
# ifupdown2 is called on a particular interface and
# it is a physical interface (or diff mode)
return

if (not ifaceobj.upperifaces or
(ifaceobj.link_privflags & ifaceLinkPrivFlags.BOND_SLAVE) or
(ifaceobj.link_privflags & ifaceLinkPrivFlags.VRF_SLAVE) or
Expand All @@ -832,18 +872,9 @@ def _process_mtu_config_mtu_valid(self, ifaceobj, ifaceobj_getfunc, mtu_str, mtu

if mtu_int != self.cache.get_link_mtu(ifaceobj.name):
self.sysfs.link_set_mtu(ifaceobj.name, mtu_str=mtu_str, mtu_int=mtu_int)
self._propagate_mtu_to_upper_devs(ifaceobj, mtu_str, mtu_int, ifaceobj_getfunc)

if (not ifupdownflags.flags.ALL and
not ifaceobj.link_kind and
ifupdownconfig.config.get('adjust_logical_dev_mtu', '1') != '0'):
# This is additional cost to us, so do it only when
# ifupdown2 is called on a particular interface and
# it is a physical interface
self._propagate_mtu_to_upper_devs(ifaceobj, mtu_str, mtu_int, ifaceobj_getfunc)
return

def _process_mtu_config_mtu_none(self, ifaceobj):

def _process_mtu_config_mtu_none(self, ifaceobj, ifaceobj_getfunc):
if (ifaceobj.link_privflags & ifaceLinkPrivFlags.MGMT_INTF):
return

Expand Down Expand Up @@ -888,6 +919,8 @@ def _process_mtu_config_mtu_none(self, ifaceobj):
# on which devices we want to reset mtu to default.
# essentially only physical interfaces which are not bond slaves
self.sysfs.link_set_mtu(ifaceobj.name, mtu_str=self.default_mtu, mtu_int=self.default_mtu_int)
if ifupdownconfig.diff_mode:
self._propagate_mtu_to_upper_devs(ifaceobj, self.default_mtu, self.default_mtu_int, ifaceobj_getfunc)

def _set_bridge_forwarding(self, ifaceobj):
""" set ip forwarding to 0 if bridge interface does not have a
Expand Down Expand Up @@ -1032,7 +1065,7 @@ def process_mtu(self, ifaceobj, ifaceobj_getfunc):

self._process_mtu_config_mtu_valid(ifaceobj, ifaceobj_getfunc, mtu_str, mtu_int)
else:
self._process_mtu_config_mtu_none(ifaceobj)
self._process_mtu_config_mtu_none(ifaceobj, ifaceobj_getfunc)

def up_ipv6_addrgen(self, ifaceobj):
user_configured_ipv6_addrgen = ifaceobj.get_attr_value_first('ipv6-addrgen')
Expand Down Expand Up @@ -1216,6 +1249,28 @@ def _up(self, ifaceobj, ifaceobj_getfunc=None):
return
self._settle_dad(ifaceobj, [ip for ip, _ in user_addrs_list if ip.version == 6])

def validate_mac(self, mac):
if not mac:
return False
if not bool(self.mac_regex.match(mac)):
raise Exception("Invalid MAC address from policy: %s" % mac)
return True

def process_hwaddress_reset_to_default(self, ifaceobj):
if not ifaceobj.link_kind and ifaceobj.link_privflags & ifaceLinkPrivFlags.BOND_SLAVE:
# if the switch port is part of a bond we shouldn't revert the mac address
return None

iface_defaults = policymanager.policymanager_api.get_iface_defaults("address")

if iface_defaults:
interface_mac_default = iface_defaults.get(ifaceobj.name, {}).get("hwaddress")

if self.validate_mac(interface_mac_default):
return interface_mac_default

return None

def process_hwaddress(self, ifaceobj):
hwaddress = self._get_hwaddress(ifaceobj)

Expand All @@ -1230,7 +1285,9 @@ def process_hwaddress(self, ifaceobj):
if not hwaddress:
return None, None
else:
return None, None
hwaddress = self.process_hwaddress_reset_to_default(ifaceobj)
if not hwaddress:
return None, None

if not ifupdownflags.flags.PERFMODE: # system is clean
running_hwaddress = self.cache.get_link_address(ifaceobj.name)
Expand All @@ -1249,6 +1306,11 @@ def process_hwaddress(self, ifaceobj):
self.netlink.link_down(l)
slave_down = True
try:
if ifaceobj.link_privflags & ifaceLinkPrivFlags.BOND_SLAVE and ifaceobj.get_attr_value("hwaddress"):
master_ifname = self.cache.get_master(ifaceobj.name)
if master_ifname:
self.log_error("%s: setting hwaddress is not permitted on an existing bond slave" % ifaceobj.name, ifaceobj=ifaceobj)

self.netlink.link_set_address(
ifaceobj.name,
hwaddress,
Expand Down Expand Up @@ -1306,26 +1368,33 @@ def _down(self, ifaceobj, ifaceobj_getfunc=None):
if alias:
self.sysfs.link_set_alias(ifaceobj.name, None) # None to reset alias.

# XXX hwaddress reset cannot happen because we dont know last
# address.
hwaddress = self.process_hwaddress_reset_to_default(ifaceobj)
if hwaddress != None and not ifaceobj.link_kind:
hwaddress_int = utils.mac_str_to_int(hwaddress)
self.netlink.link_set_address(
ifaceobj.name,
hwaddress,
hwaddress_int,
keep_link_down=ifaceobj.link_privflags & ifaceLinkPrivFlags.KEEP_LINK_DOWN
)
else:
# Handle special things on a bridge
hwaddress = self._get_hwaddress(ifaceobj)
if not hwaddress:
hwaddress = self.cache.get_link_address(ifaceobj.name)

# Handle special things on a bridge
hwaddress = self._get_hwaddress(ifaceobj)
if not hwaddress:
hwaddress = self.cache.get_link_address(ifaceobj.name)
self._process_bridge(ifaceobj, False, hwaddress, None)
except Exception as e:
self.logger.debug('%s : %s' %(ifaceobj.name, str(e)))
pass

def _get_bridge_fdbs(self, bridgename, vlan):
def _get_bridge_fdbs(self, bridgename, vlan=None):
fdbs = self._bridge_fdb_query_cache.get(bridgename)
if not fdbs:
fdbs = self.iproute2.bridge_fdb_show_dev(bridgename)
if not fdbs:
return
return {}
self._bridge_fdb_query_cache[bridgename] = fdbs
return fdbs.get(vlan)
return fdbs.get(vlan) if vlan else fdbs

def _check_addresses_in_bridge(self, ifaceobj, hwaddress):
""" If the device is a bridge, make sure the addresses
Expand Down Expand Up @@ -1381,7 +1450,6 @@ def _query_sysctl(self, ifaceobj, ifaceobjcurr):
ifaceobjcurr.update_config_with_status('mpls-enable',
running_mpls_enable,
mpls_enable != running_mpls_enable)
return

def query_check_ipv6_addrgen(self, ifaceobj, ifaceobjcurr):
ipv6_addrgen = ifaceobj.get_attr_value_first('ipv6-addrgen')
Expand Down Expand Up @@ -1417,15 +1485,13 @@ def _query_check(self, ifaceobj, ifaceobjcurr, ifaceobj_getfunc=None):
"""
TODO: Check broadcast address, scope, etc
"""
runningaddrsdict = None
if not self.cache.link_exists(ifaceobj.name):
self.logger.debug('iface %s not found' %ifaceobj.name)
return

self.query_check_disable_ipv6(ifaceobj, ifaceobjcurr)
self.query_check_ipv6_addrgen(ifaceobj, ifaceobjcurr)

addr_method = ifaceobj.addr_method
self.query_n_update_ifaceobjcurr_attr(ifaceobj, ifaceobjcurr,
'mtu', self.cache.get_link_mtu_str)
hwaddress = self._get_hwaddress(ifaceobj)
Expand Down
Loading