diff options
author | Thomas Haller <thaller@redhat.com> | 2020-09-03 12:24:08 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2020-09-07 16:11:51 +0200 |
commit | 4c07d345057c84a5005dea0385c8b3e9d1c6138d (patch) | |
tree | b9dcb8ad5e0e1a7cef8726cc06fbd7b3983542f0 | |
parent | c328c10227bbffea0e29b3c80ba26611124bbe75 (diff) | |
download | NetworkManager-4c07d345057c84a5005dea0385c8b3e9d1c6138d.tar.gz |
l3cfg: add nm_l3_config_data_has_routes_with_type_local() helper
-rw-r--r-- | src/nm-l3-config-data.c | 57 | ||||
-rw-r--r-- | src/nm-l3-config-data.h | 3 |
2 files changed, 60 insertions, 0 deletions
diff --git a/src/nm-l3-config-data.c b/src/nm-l3-config-data.c index e2bc28265a..d547b5bd60 100644 --- a/src/nm-l3-config-data.c +++ b/src/nm-l3-config-data.c @@ -116,6 +116,11 @@ struct _NML3ConfigData { NMTernary metered:3; bool is_sealed:1; + + bool has_routes_with_type_local_4_set:1; + bool has_routes_with_type_local_6_set:1; + bool has_routes_with_type_local_4_val:1; + bool has_routes_with_type_local_6_val:1; }; /*****************************************************************************/ @@ -614,6 +619,50 @@ nmtst_l3_config_data_get_obj_at (const NML3ConfigData *self, /*****************************************************************************/ +gboolean +nm_l3_config_data_has_routes_with_type_local (const NML3ConfigData *self, int addr_family) +{ + const gboolean IS_IPv4 = NM_IS_IPv4 (addr_family); + NML3ConfigData *self_mutable; + NMDedupMultiIter iter; + const NMPObject *obj; + gboolean val; + + nm_assert (_NM_IS_L3_CONFIG_DATA (self, TRUE)); + nm_assert_addr_family (addr_family); + + if (IS_IPv4) { + if (G_LIKELY (self->has_routes_with_type_local_4_set)) + return self->has_routes_with_type_local_4_val; + } else { + if (G_LIKELY (self->has_routes_with_type_local_6_set)) + return self->has_routes_with_type_local_6_val; + } + + val = FALSE; + nm_l3_config_data_iter_obj_for_each (&iter, self, &obj, NMP_OBJECT_TYPE_IP_ROUTE (IS_IPv4)) { + if (NMP_OBJECT_CAST_IP_ROUTE (obj)->type_coerced == nm_platform_route_type_coerce (RTN_LOCAL)) { + val = TRUE; + break; + } + } + + /* the value gets accumulated and cached. Doing that is also permissible to a + * const/sealed instance. Hence, we cast the const-ness away. */ + self_mutable = (NML3ConfigData *) self; + if (IS_IPv4) { + self_mutable->has_routes_with_type_local_4_set = TRUE; + self_mutable->has_routes_with_type_local_4_val = val; + } else { + self_mutable->has_routes_with_type_local_6_set = TRUE; + self_mutable->has_routes_with_type_local_6_val = val; + } + + return val; +} + +/*****************************************************************************/ + NMDedupMultiIndex * nm_l3_config_data_get_multi_idx (const NML3ConfigData *self) { @@ -920,6 +969,10 @@ nm_l3_config_data_add_route_full (NML3ConfigData *self, || ( NMP_OBJECT_GET_ADDR_FAMILY (obj_new) == addr_family && _route_valid (addr_family, NMP_OBJECT_CAST_IP_ROUTE (obj_new)))); + if (IS_IPv4) + self->has_routes_with_type_local_4_set = FALSE; + else + self->has_routes_with_type_local_6_set = FALSE; if (_l3_config_data_add_obj (self->multi_idx, addr_family == AF_INET ? &self->idx_routes_4 @@ -1945,6 +1998,10 @@ _init_from_platform (NML3ConfigData *self, : NMP_OBJECT_TYPE_IP6_ADDRESS, self->ifindex); if (head_entry) { + if (IS_IPv4) + self->has_routes_with_type_local_4_set = FALSE; + else + self->has_routes_with_type_local_6_set = FALSE; nmp_cache_iter_for_each (&iter, head_entry, &plobj) { if (!_l3_config_data_add_obj (self->multi_idx, &self->idx_addresses_x[IS_IPv4], diff --git a/src/nm-l3-config-data.h b/src/nm-l3-config-data.h index 964e4698a9..429325626c 100644 --- a/src/nm-l3-config-data.h +++ b/src/nm-l3-config-data.h @@ -271,6 +271,9 @@ nm_l3_config_data_get_num_routes (const NML3ConfigData *self, int addr_family) : NMP_OBJECT_TYPE_IP6_ROUTE); } +gboolean nm_l3_config_data_has_routes_with_type_local (const NML3ConfigData *self, + int addr_family); + const NMPObject *nmtst_l3_config_data_get_obj_at (const NML3ConfigData *self, NMPObjectType obj_type, guint i); |