diff --git a/src/middlewared/debian/control b/src/middlewared/debian/control index f1da12930b53b..df8fc0d1ed180 100644 --- a/src/middlewared/debian/control +++ b/src/middlewared/debian/control @@ -13,7 +13,6 @@ Build-Depends: alembic, python3-apps-validation, python3-asyncssh, python3-aws-requests-auth, - python3-bidict, python3-boto3, python3-certbot-dns-cloudflare, python3-certbot-dns-digitalocean, @@ -108,7 +107,6 @@ Depends: alembic, python3-apps-validation, python3-asyncssh, python3-aws-requests-auth, - python3-bidict, python3-boto3, python3-certbot-dns-cloudflare, python3-certbot-dns-digitalocean, diff --git a/src/middlewared/middlewared/plugins/interface/netif_linux/routing.py b/src/middlewared/middlewared/plugins/interface/netif_linux/routing.py index 2186b94ace9df..94f32a0ca1ae6 100644 --- a/src/middlewared/middlewared/plugins/interface/netif_linux/routing.py +++ b/src/middlewared/middlewared/plugins/interface/netif_linux/routing.py @@ -1,12 +1,10 @@ # -*- coding=utf-8 -*- -import collections import enum import ipaddress import logging import os import socket -import bidict from pyroute2 import IPRoute from pyroute2.netlink.exceptions import NetlinkDumpInterrupted @@ -209,7 +207,7 @@ def delete(self, route): self._op("delete", route) def _interfaces(self): - return bidict.bidict({i["index"]: dict(i["attrs"]).get("IFLA_IFNAME") for i in self._ip_links()}) + return {i["index"]: dict(i["attrs"]).get("IFLA_IFNAME") for i in self._ip_links()} def _ip_links(self): retries = 5 @@ -229,19 +227,20 @@ def _op(self, op, route): else: raise RuntimeError() - kwargs = dict(dst=f"{route.network}/{prefixlen}", gateway=str(route.gateway) if route.gateway else None) - for key, value in map( - lambda v: [v[0], v[1]() if isinstance(v[1], collections.abc.Callable) else v[1]], - filter( - lambda v: v[2] if len(v) == 3 else v[1], ( - ("oif", lambda: self._interfaces().inv[route.interface], route.interface is not None), - ("table", route.table_id), - ("scope", route.scope), - ("prefsrc", route.preferred_source), - ) - ) - ): - kwargs[key] = value + kwargs = { + "dst": f"{route.network}/{prefixlen}", + "gateway": str(route.gateway) if route.gateway else None, + "oif": None, + "table": route.table_id, + "scope": route.scope, + "prefsrc": route.preferred_source, + } + if route.interface is not None: + for i in self._ip_links(): + ifname = dict(i["attrs"]).get("IFLA_IFNAME") + if ifname is not None and ifname == route.interface: + kwargs["oif"] = i["index"] + break ip.route(op, **kwargs)