From 3cb7a104621bf6ba1acbbcc221e5738b89f289dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20=22=27=20OR=201=3D=3D1=3B=20--=20=23=20Ib=C3=A1?= =?UTF-8?q?=C3=B1ez?= Date: Thu, 11 Jul 2024 10:00:16 +0400 Subject: [PATCH] MDM Agent: Handle NetlinkDumpInterrupted except in ip.get_links() --- .../src/nats/src/cbma_adaptation.py | 12 +++++++++++- .../src/nats/src/comms_if_monitor.py | 12 +++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/modules/sc-mesh-secure-deployment/src/nats/src/cbma_adaptation.py b/modules/sc-mesh-secure-deployment/src/nats/src/cbma_adaptation.py index 7dcb4fb2..6f5d6b85 100644 --- a/modules/sc-mesh-secure-deployment/src/nats/src/cbma_adaptation.py +++ b/modules/sc-mesh-secure-deployment/src/nats/src/cbma_adaptation.py @@ -15,6 +15,7 @@ import ipaddress import errno from pyroute2 import IPRoute, NetlinkError, arp # type: ignore[import-not-found, import-untyped] +from pyroute2.netlink.exceptions import NetlinkDumpInterrupted from src import cbma_paths from src.comms_controller import CommsController @@ -280,7 +281,16 @@ def __delete_vlan_interfaces(self) -> bool: def __get_interfaces(self) -> None: interfaces = [] ip = IPRoute() - for link in ip.get_links(): + + ip_links = [] + while True: + try: + ip_links = ip.get_links() + break + except NetlinkDumpInterrupted: + time.sleep(1) + + for link in ip_links: ifname = link.get_attr("IFLA_IFNAME") ifstate = link.get_attr("IFLA_OPERSTATE") mac_address = link.get_attr("IFLA_ADDRESS") diff --git a/modules/sc-mesh-secure-deployment/src/nats/src/comms_if_monitor.py b/modules/sc-mesh-secure-deployment/src/nats/src/comms_if_monitor.py index e26be6b6..39151ab9 100644 --- a/modules/sc-mesh-secure-deployment/src/nats/src/comms_if_monitor.py +++ b/modules/sc-mesh-secure-deployment/src/nats/src/comms_if_monitor.py @@ -6,8 +6,10 @@ # pylint: disable=too-few-public-methods, too-many-nested-blocks from typing import Callable, List, Dict import subprocess +import time from copy import deepcopy from pyroute2 import IPRoute +from pyroute2.netlink.exceptions import NetlinkDumpInterrupted DUMMY_INTERFACE_NAME = 'ifdummy0' @@ -24,7 +26,15 @@ def __init__(self, callback: Callable[[List[Dict]], None]) -> None: self.__ipr = IPRoute() def __get_initial_interfaces(self): - for link in self.__ipr.get_links(): + ip_links = [] + while True: + try: + ip_links = self.__ipr.get_links() + break + except NetlinkDumpInterrupted: + time.sleep(1) + + for link in ip_links: interface_info = self.__get_interface_info(link) if interface_info: self.__interfaces.append(interface_info)