diff options
Diffstat (limited to 'src/core/nm-l3-config-data.c')
| -rw-r--r-- | src/core/nm-l3-config-data.c | 62 |
1 files changed, 55 insertions, 7 deletions
diff --git a/src/core/nm-l3-config-data.c b/src/core/nm-l3-config-data.c index 96274ba9..a4647116 100644 --- a/src/core/nm-l3-config-data.c +++ b/src/core/nm-l3-config-data.c @@ -157,6 +157,8 @@ struct _NML3ConfigData { 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; + bool dhcp_enabled_4 : 1; + bool dhcp_enabled_6 : 1; bool ndisc_hop_limit_set : 1; bool ndisc_reachable_time_msec_set : 1; @@ -324,7 +326,7 @@ _strv_ptrarray_merge(GPtrArray **p_dst, const GPtrArray *src) const char *s = src->pdata[i]; if (dst_initial_len > 0 - && nm_strv_find_first((const char *const *) ((*p_dst)->pdata), dst_initial_len, s) >= 0) + && nm_strv_contains((const char *const *) ((*p_dst)->pdata), dst_initial_len, s)) continue; g_ptr_array_add(*p_dst, g_strdup(s)); @@ -1642,7 +1644,7 @@ nm_l3_config_data_get_dns_priority(const NML3ConfigData *self, int addr_family, case AF_UNSPEC: if (NM_FLAGS_ANY(self->flags, NM_L3_CONFIG_DAT_FLAGS_HAS_DNS_PRIORITY_4)) { if (NM_FLAGS_ANY(self->flags, NM_L3_CONFIG_DAT_FLAGS_HAS_DNS_PRIORITY_6)) { - NM_SET_OUT(out_prio, MIN(self->dns_priority_4, self->dns_priority_6)); + NM_SET_OUT(out_prio, NM_MIN(self->dns_priority_4, self->dns_priority_6)); return TRUE; } NM_SET_OUT(out_prio, self->dns_priority_4); @@ -1933,6 +1935,19 @@ nm_l3_config_data_set_mptcp_flags(NML3ConfigData *self, NMMptcpFlags mptcp_flags return TRUE; } +gboolean +nm_l3_config_data_get_dhcp_enabled(const NML3ConfigData *self, int addr_family) +{ + const int IS_IPv4 = NM_IS_IPv4(addr_family); + + nm_assert(_NM_IS_L3_CONFIG_DATA(self, TRUE)); + if (IS_IPv4) { + return self->dhcp_enabled_4; + } else { + return self->dhcp_enabled_6; + } +} + NMProxyConfigMethod nm_l3_config_data_get_proxy_method(const NML3ConfigData *self) { @@ -2231,14 +2246,23 @@ static const NML3ConfigData * get_empty_l3cd(void) { static NML3ConfigData *empty_l3cd; + NML3ConfigData *l3cd; + +again: + l3cd = g_atomic_pointer_get(&empty_l3cd); + if (G_UNLIKELY(!l3cd)) { + l3cd = nm_l3_config_data_new(nm_dedup_multi_index_new(), 1, NM_IP_CONFIG_SOURCE_UNKNOWN); + l3cd->ifindex = 0; - if (!empty_l3cd) { - empty_l3cd = - nm_l3_config_data_new(nm_dedup_multi_index_new(), 1, NM_IP_CONFIG_SOURCE_UNKNOWN); - empty_l3cd->ifindex = 0; + nm_l3_config_data_seal(l3cd); + + if (!g_atomic_pointer_compare_and_exchange(&empty_l3cd, NULL, l3cd)) { + nm_l3_config_data_unref(l3cd); + goto again; + } } - return empty_l3cd; + return l3cd; } int @@ -2713,6 +2737,7 @@ _init_from_connection_ip(NML3ConfigData *self, int addr_family, NMConnection *co guint nnameservers; guint nsearches; const char *gateway_str; + const char *method; NMIPAddr gateway_bin; guint i; int idx; @@ -2730,6 +2755,24 @@ _init_from_connection_ip(NML3ConfigData *self, int addr_family, NMConnection *co never_default = nm_setting_ip_config_get_never_default(s_ip); + method = nm_setting_ip_config_get_method(s_ip); + if (IS_IPv4) { + if (nm_streq(method, NM_SETTING_IP4_CONFIG_METHOD_AUTO)) { + self->dhcp_enabled_4 = TRUE; + } else { + self->dhcp_enabled_4 = FALSE; + } + } else { + method = nm_setting_ip_config_get_method(s_ip); + if (NM_IN_STRSET(method, + NM_SETTING_IP6_CONFIG_METHOD_AUTO, + NM_SETTING_IP6_CONFIG_METHOD_DHCP)) { + self->dhcp_enabled_6 = TRUE; + } else { + self->dhcp_enabled_6 = FALSE; + } + } + nm_l3_config_data_set_never_default(self, addr_family, !!never_default); if (!never_default && (gateway_str = nm_setting_ip_config_get_gateway(s_ip)) @@ -3413,6 +3456,11 @@ nm_l3_config_data_merge(NML3ConfigData *self, self->dhcp_lease_x[0] = nm_dhcp_lease_ref(self->dhcp_lease_x[0]); self->dhcp_lease_x[1] = nm_dhcp_lease_ref(self->dhcp_lease_x[1]); } + if (src->dhcp_enabled_4) + self->dhcp_enabled_4 = TRUE; + + if (src->dhcp_enabled_6) + self->dhcp_enabled_6 = TRUE; } NML3ConfigData * |