summaryrefslogtreecommitdiff
path: root/src/nm-pacrunner-manager.c
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2017-07-07 23:34:41 +0200
committerThomas Haller <thaller@redhat.com>2017-07-25 06:44:12 +0200
commit22edeb5b691befd796c534cf71901b32f0b7945b (patch)
tree98cdbd184ae8d73242d267d27f4882094ecbf236 /src/nm-pacrunner-manager.c
parent74816a22374091f1cde34372387f8c6bfcd688dc (diff)
downloadNetworkManager-22edeb5b691befd796c534cf71901b32f0b7945b.tar.gz
core: track addresses for NMIP4Config/NMIP6Config via NMDedupMultiIndex
Reasons: - it adds an O(1) lookup index for accessing NMIPxConfig's addresses. Hence, operations like merge/intersect have now runtime O(n) instead of O(n^2). Arguably, we expect low numbers of addresses in general. For low numbers, the O(n^2) doesn't matter and quite likely in those cases the previous implementation was just fine -- maybe even faster. But the simple case works fine either way. It's important to scale well in the exceptional case. - the tracked objects can be shared between the various NMPI4Config, NMIP6Config instances with NMPlatform and everybody else. - the NMPObject can be treated generically, meaning it enables code to handle both IPv4 and IPv6, or addresses and routes. See for example _nm_ip_config_add_obj(). - I want core to evolve to somewhere where we don't keep copies of NMPlatformIP4Address, et al. instances. Instead they shall all be shared. I hope this will reduce memory consumption (although tracking a reference consumes some memory too). Also, it shortcuts nmp_object_equal() when comparing the same object. Calling nmp_object_equal() on the identical objects would be a common case after the hash function pre-evaluates equality.
Diffstat (limited to 'src/nm-pacrunner-manager.c')
-rw-r--r--src/nm-pacrunner-manager.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/src/nm-pacrunner-manager.c b/src/nm-pacrunner-manager.c
index d9095cce5b..2558ca0f30 100644
--- a/src/nm-pacrunner-manager.c
+++ b/src/nm-pacrunner-manager.c
@@ -170,6 +170,7 @@ get_ip4_domains (GPtrArray *domains, NMIP4Config *ip4)
{
NMDedupMultiIter ipconf_iter;
char *cidr;
+ const NMPlatformIP4Address *address;
const NMPlatformIP4Route *routes;
guint i;
@@ -182,16 +183,15 @@ get_ip4_domains (GPtrArray *domains, NMIP4Config *ip4)
g_ptr_array_add (domains, g_strdup (nm_ip4_config_get_domain (ip4, i)));
/* Add addresses and routes in CIDR form */
- for (i = 0; i < nm_ip4_config_get_num_addresses (ip4); i++) {
- const NMPlatformIP4Address *address = nm_ip4_config_get_address (ip4, i);
+ nm_ip_config_iter_ip4_address_for_each (&ipconf_iter, ip4, &address) {
cidr = g_strdup_printf ("%s/%u",
nm_utils_inet4_ntop (address->address, NULL),
address->plen);
g_ptr_array_add (domains, cidr);
}
- nm_ip4_config_iter_ip4_route_for_each (&ipconf_iter, ip4, &routes) {
+ nm_ip_config_iter_ip4_route_for_each (&ipconf_iter, ip4, &routes) {
cidr = g_strdup_printf ("%s/%u",
nm_utils_inet4_ntop (routes->network, NULL),
routes->plen);
@@ -204,6 +204,7 @@ get_ip6_domains (GPtrArray *domains, NMIP6Config *ip6)
{
NMDedupMultiIter ipconf_iter;
char *cidr;
+ const NMPlatformIP6Address *address;
const NMPlatformIP6Route *routes;
guint i;
@@ -216,16 +217,14 @@ get_ip6_domains (GPtrArray *domains, NMIP6Config *ip6)
g_ptr_array_add (domains, g_strdup (nm_ip6_config_get_domain (ip6, i)));
/* Add addresses and routes in CIDR form */
- for (i = 0; i < nm_ip6_config_get_num_addresses (ip6); i++) {
- const NMPlatformIP6Address *address = nm_ip6_config_get_address (ip6, i);
-
+ nm_ip_config_iter_ip6_address_for_each (&ipconf_iter, ip6, &address) {
cidr = g_strdup_printf ("%s/%u",
nm_utils_inet6_ntop (&address->address, NULL),
address->plen);
g_ptr_array_add (domains, cidr);
}
- nm_ip6_config_iter_ip6_route_for_each (&ipconf_iter, ip6, &routes) {
+ nm_ip_config_iter_ip6_route_for_each (&ipconf_iter, ip6, &routes) {
cidr = g_strdup_printf ("%s/%u",
nm_utils_inet6_ntop (&routes->network, NULL),
routes->plen);