|
|
89e515 |
From 5f41f061390876f4c43c2306911d9b3482aed396 Mon Sep 17 00:00:00 2001
|
|
|
89e515 |
From: Lubomir Rintel <lkundrak@v3.sk>
|
|
|
89e515 |
Date: Mon, 16 Jul 2018 17:42:34 +0200
|
|
|
89e515 |
Subject: [PATCH 1/3] firewall.core.fw_nm: avoid iterating NM devices,
|
|
|
89e515 |
connections
|
|
|
89e515 |
|
|
|
89e515 |
NetworkManager has an API to do the lookups.
|
|
|
89e515 |
|
|
|
89e515 |
(cherry picked from commit 65f92930a5d049404dac780c15eebe2d788e6285)
|
|
|
89e515 |
---
|
|
|
89e515 |
src/firewall/core/fw_nm.py | 70 ++++++++++++++++++----------------------------
|
|
|
89e515 |
1 file changed, 27 insertions(+), 43 deletions(-)
|
|
|
89e515 |
|
|
|
89e515 |
diff --git a/src/firewall/core/fw_nm.py b/src/firewall/core/fw_nm.py
|
|
|
89e515 |
index f75733fe65f6..76901cee2adf 100644
|
|
|
89e515 |
--- a/src/firewall/core/fw_nm.py
|
|
|
89e515 |
+++ b/src/firewall/core/fw_nm.py
|
|
|
89e515 |
@@ -73,22 +73,18 @@ def nm_get_zone_of_connection(connection):
|
|
|
89e515 |
"""
|
|
|
89e515 |
check_nm_imported()
|
|
|
89e515 |
|
|
|
89e515 |
- active_connections = nm_get_client().get_active_connections()
|
|
|
89e515 |
+ con = nm_get_client().get_connection_by_id(connection)
|
|
|
89e515 |
+ if con is None:
|
|
|
89e515 |
+ return False
|
|
|
89e515 |
|
|
|
89e515 |
- for active_con in active_connections:
|
|
|
89e515 |
- if active_con.get_id() == connection:
|
|
|
89e515 |
- con = active_con.get_connection()
|
|
|
89e515 |
- if con is None:
|
|
|
89e515 |
- continue
|
|
|
89e515 |
- setting_con = con.get_setting_connection()
|
|
|
89e515 |
- if setting_con is None:
|
|
|
89e515 |
- continue
|
|
|
89e515 |
- zone = setting_con.get_zone()
|
|
|
89e515 |
- if zone is None:
|
|
|
89e515 |
- zone = ""
|
|
|
89e515 |
- return zone
|
|
|
89e515 |
+ setting_con = con.get_setting_connection()
|
|
|
89e515 |
+ if setting_con is None:
|
|
|
89e515 |
+ return False
|
|
|
89e515 |
|
|
|
89e515 |
- return None
|
|
|
89e515 |
+ zone = setting_con.get_zone()
|
|
|
89e515 |
+ if zone is None:
|
|
|
89e515 |
+ zone = ""
|
|
|
89e515 |
+ return zone
|
|
|
89e515 |
|
|
|
89e515 |
def nm_set_zone_of_connection(zone, connection):
|
|
|
89e515 |
"""Set the zone for a connection
|
|
|
89e515 |
@@ -98,24 +94,18 @@ def nm_set_zone_of_connection(zone, connection):
|
|
|
89e515 |
"""
|
|
|
89e515 |
check_nm_imported()
|
|
|
89e515 |
|
|
|
89e515 |
- active_connections = nm_get_client().get_active_connections()
|
|
|
89e515 |
-
|
|
|
89e515 |
- for active_con in active_connections:
|
|
|
89e515 |
- con = active_con.get_connection()
|
|
|
89e515 |
- if con is None:
|
|
|
89e515 |
- continue
|
|
|
89e515 |
+ con = nm_get_client().get_connection_by_id(connection)
|
|
|
89e515 |
+ if con is None:
|
|
|
89e515 |
+ return False
|
|
|
89e515 |
|
|
|
89e515 |
- if active_con.get_id() == connection:
|
|
|
89e515 |
- setting_con = con.get_setting_connection()
|
|
|
89e515 |
- if setting_con is None:
|
|
|
89e515 |
- continue
|
|
|
89e515 |
- if zone == "":
|
|
|
89e515 |
- zone = None
|
|
|
89e515 |
- setting_con.set_property("zone", zone)
|
|
|
89e515 |
- con.commit_changes(True, None)
|
|
|
89e515 |
- return True
|
|
|
89e515 |
+ setting_con = con.get_setting_connection()
|
|
|
89e515 |
+ if setting_con is None:
|
|
|
89e515 |
+ return False
|
|
|
89e515 |
|
|
|
89e515 |
- return False
|
|
|
89e515 |
+ if zone == "":
|
|
|
89e515 |
+ zone = None
|
|
|
89e515 |
+ setting_con.set_property("zone", zone)
|
|
|
89e515 |
+ return con.commit_changes(True, None)
|
|
|
89e515 |
|
|
|
89e515 |
def nm_get_connections(connections, connections_uuid):
|
|
|
89e515 |
"""Get active connections from NM
|
|
|
89e515 |
@@ -150,21 +140,15 @@ def nm_get_connection_of_interface(interface):
|
|
|
89e515 |
"""
|
|
|
89e515 |
check_nm_imported()
|
|
|
89e515 |
|
|
|
89e515 |
- active_connections = nm_get_client().get_active_connections()
|
|
|
89e515 |
-
|
|
|
89e515 |
- for active_con in active_connections:
|
|
|
89e515 |
- # ignore vpn devices for now
|
|
|
89e515 |
- if active_con.get_vpn():
|
|
|
89e515 |
- continue
|
|
|
89e515 |
-
|
|
|
89e515 |
- devices = active_con.get_devices()
|
|
|
89e515 |
-
|
|
|
89e515 |
- for dev in devices:
|
|
|
89e515 |
- if dev.get_iface() == interface:
|
|
|
89e515 |
- return active_con.get_id()
|
|
|
89e515 |
+ device = nm_get_client().get_device_by_iface(interface)
|
|
|
89e515 |
+ if device is None:
|
|
|
89e515 |
+ return None
|
|
|
89e515 |
|
|
|
89e515 |
+ active_con = device.get_active_connection()
|
|
|
89e515 |
+ if active_con is None:
|
|
|
89e515 |
+ return None
|
|
|
89e515 |
|
|
|
89e515 |
- return None
|
|
|
89e515 |
+ return active_con.get_id()
|
|
|
89e515 |
|
|
|
89e515 |
def nm_get_bus_name():
|
|
|
89e515 |
if not _nm_imported:
|
|
|
89e515 |
--
|
|
|
89e515 |
2.16.3
|
|
|
89e515 |
|