core: rename l3cd's "dhcp_enabled" to "allow_routes_without_address"

The name "dhcp_enabled" is misleading because the flag is set for
method=auto, which doesn't necessarily imply DHCP. Also, it doesn't
convey what the flag is used for. Rename it to
"allow_routes_without_address".

(cherry picked from commit b31febea22)
This commit is contained in:
Beniamino Galvani 2024-05-08 10:49:27 +02:00
parent 518b7c5bd5
commit 6897b6ecfd
3 changed files with 41 additions and 39 deletions

View file

@ -157,8 +157,8 @@ struct _NML3ConfigData {
bool has_routes_with_type_local_6_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_4_val : 1;
bool has_routes_with_type_local_6_val : 1; bool has_routes_with_type_local_6_val : 1;
bool dhcp_enabled_4 : 1; bool allow_routes_without_address_4 : 1;
bool dhcp_enabled_6 : 1; bool allow_routes_without_address_6 : 1;
bool ndisc_hop_limit_set : 1; bool ndisc_hop_limit_set : 1;
bool ndisc_reachable_time_msec_set : 1; bool ndisc_reachable_time_msec_set : 1;
@ -678,26 +678,28 @@ nm_l3_config_data_new(NMDedupMultiIndex *multi_idx, int ifindex, NMIPConfigSourc
self = g_slice_new(NML3ConfigData); self = g_slice_new(NML3ConfigData);
*self = (NML3ConfigData){ *self = (NML3ConfigData){
.ref_count = 1, .ref_count = 1,
.ifindex = ifindex, .ifindex = ifindex,
.multi_idx = nm_dedup_multi_index_ref(multi_idx), .multi_idx = nm_dedup_multi_index_ref(multi_idx),
.mdns = NM_SETTING_CONNECTION_MDNS_DEFAULT, .mdns = NM_SETTING_CONNECTION_MDNS_DEFAULT,
.llmnr = NM_SETTING_CONNECTION_LLMNR_DEFAULT, .llmnr = NM_SETTING_CONNECTION_LLMNR_DEFAULT,
.dns_over_tls = NM_SETTING_CONNECTION_DNS_OVER_TLS_DEFAULT, .dns_over_tls = NM_SETTING_CONNECTION_DNS_OVER_TLS_DEFAULT,
.flags = NM_L3_CONFIG_DAT_FLAGS_NONE, .flags = NM_L3_CONFIG_DAT_FLAGS_NONE,
.metered = NM_TERNARY_DEFAULT, .metered = NM_TERNARY_DEFAULT,
.proxy_browser_only = NM_TERNARY_DEFAULT, .proxy_browser_only = NM_TERNARY_DEFAULT,
.proxy_method = NM_PROXY_CONFIG_METHOD_UNKNOWN, .proxy_method = NM_PROXY_CONFIG_METHOD_UNKNOWN,
.route_table_sync_4 = NM_IP_ROUTE_TABLE_SYNC_MODE_NONE, .route_table_sync_4 = NM_IP_ROUTE_TABLE_SYNC_MODE_NONE,
.route_table_sync_6 = NM_IP_ROUTE_TABLE_SYNC_MODE_NONE, .route_table_sync_6 = NM_IP_ROUTE_TABLE_SYNC_MODE_NONE,
.never_default_6 = NM_OPTION_BOOL_DEFAULT, .never_default_6 = NM_OPTION_BOOL_DEFAULT,
.never_default_4 = NM_OPTION_BOOL_DEFAULT, .never_default_4 = NM_OPTION_BOOL_DEFAULT,
.source = source, .source = source,
.ip6_privacy = NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN, .ip6_privacy = NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN,
.mptcp_flags = NM_MPTCP_FLAGS_NONE, .mptcp_flags = NM_MPTCP_FLAGS_NONE,
.ndisc_hop_limit_set = FALSE, .ndisc_hop_limit_set = FALSE,
.ndisc_reachable_time_msec_set = FALSE, .ndisc_reachable_time_msec_set = FALSE,
.ndisc_retrans_timer_msec_set = FALSE, .ndisc_retrans_timer_msec_set = FALSE,
.allow_routes_without_address_4 = TRUE,
.allow_routes_without_address_6 = TRUE,
}; };
_idx_type_init(&self->idx_addresses_4, NMP_OBJECT_TYPE_IP4_ADDRESS); _idx_type_init(&self->idx_addresses_4, NMP_OBJECT_TYPE_IP4_ADDRESS);
@ -1936,15 +1938,15 @@ nm_l3_config_data_set_mptcp_flags(NML3ConfigData *self, NMMptcpFlags mptcp_flags
} }
gboolean gboolean
nm_l3_config_data_get_dhcp_enabled(const NML3ConfigData *self, int addr_family) nm_l3_config_data_get_allow_routes_without_address(const NML3ConfigData *self, int addr_family)
{ {
const int IS_IPv4 = NM_IS_IPv4(addr_family); const int IS_IPv4 = NM_IS_IPv4(addr_family);
nm_assert(_NM_IS_L3_CONFIG_DATA(self, TRUE)); nm_assert(_NM_IS_L3_CONFIG_DATA(self, TRUE));
if (IS_IPv4) { if (IS_IPv4) {
return self->dhcp_enabled_4; return self->allow_routes_without_address_4;
} else { } else {
return self->dhcp_enabled_6; return self->allow_routes_without_address_6;
} }
} }
@ -2758,18 +2760,18 @@ _init_from_connection_ip(NML3ConfigData *self, int addr_family, NMConnection *co
method = nm_setting_ip_config_get_method(s_ip); method = nm_setting_ip_config_get_method(s_ip);
if (IS_IPv4) { if (IS_IPv4) {
if (nm_streq(method, NM_SETTING_IP4_CONFIG_METHOD_AUTO)) { if (nm_streq(method, NM_SETTING_IP4_CONFIG_METHOD_AUTO)) {
self->dhcp_enabled_4 = TRUE; self->allow_routes_without_address_4 = FALSE;
} else { } else {
self->dhcp_enabled_4 = FALSE; self->allow_routes_without_address_4 = TRUE;
} }
} else { } else {
method = nm_setting_ip_config_get_method(s_ip); method = nm_setting_ip_config_get_method(s_ip);
if (NM_IN_STRSET(method, if (NM_IN_STRSET(method,
NM_SETTING_IP6_CONFIG_METHOD_AUTO, NM_SETTING_IP6_CONFIG_METHOD_AUTO,
NM_SETTING_IP6_CONFIG_METHOD_DHCP)) { NM_SETTING_IP6_CONFIG_METHOD_DHCP)) {
self->dhcp_enabled_6 = TRUE; self->allow_routes_without_address_6 = FALSE;
} else { } else {
self->dhcp_enabled_6 = FALSE; self->allow_routes_without_address_6 = TRUE;
} }
} }
@ -3456,11 +3458,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[0] = nm_dhcp_lease_ref(self->dhcp_lease_x[0]);
self->dhcp_lease_x[1] = nm_dhcp_lease_ref(self->dhcp_lease_x[1]); self->dhcp_lease_x[1] = nm_dhcp_lease_ref(self->dhcp_lease_x[1]);
} }
if (src->dhcp_enabled_4) if (!src->allow_routes_without_address_4)
self->dhcp_enabled_4 = TRUE; self->allow_routes_without_address_4 = FALSE;
if (src->dhcp_enabled_6) if (!src->allow_routes_without_address_6)
self->dhcp_enabled_6 = TRUE; self->allow_routes_without_address_6 = FALSE;
} }
NML3ConfigData * NML3ConfigData *

View file

@ -554,7 +554,8 @@ NMSettingIP6ConfigPrivacy nm_l3_config_data_get_ip6_privacy(const NML3ConfigData
gboolean nm_l3_config_data_set_ip6_privacy(NML3ConfigData *self, gboolean nm_l3_config_data_set_ip6_privacy(NML3ConfigData *self,
NMSettingIP6ConfigPrivacy ip6_privacy); NMSettingIP6ConfigPrivacy ip6_privacy);
gboolean nm_l3_config_data_get_dhcp_enabled(const NML3ConfigData *self, int addr_family); gboolean nm_l3_config_data_get_allow_routes_without_address(const NML3ConfigData *self,
int addr_family);
NMProxyConfigMethod nm_l3_config_data_get_proxy_method(const NML3ConfigData *self); NMProxyConfigMethod nm_l3_config_data_get_proxy_method(const NML3ConfigData *self);

View file

@ -1301,7 +1301,6 @@ _commit_collect_routes(NML3Cfg *self,
const int IS_IPv4 = NM_IS_IPv4(addr_family); const int IS_IPv4 = NM_IS_IPv4(addr_family);
const NMDedupMultiHeadEntry *head_entry; const NMDedupMultiHeadEntry *head_entry;
const NMDedupMultiEntry *entry; const NMDedupMultiEntry *entry;
gboolean is_dhcp_enabled;
nm_assert(routes && !*routes); nm_assert(routes && !*routes);
nm_assert(routes_nodev && !*routes_nodev); nm_assert(routes_nodev && !*routes_nodev);
@ -1321,10 +1320,10 @@ _commit_collect_routes(NML3Cfg *self,
else { else {
nm_assert(NMP_OBJECT_CAST_IP_ROUTE(obj)->ifindex == self->priv.ifindex); nm_assert(NMP_OBJECT_CAST_IP_ROUTE(obj)->ifindex == self->priv.ifindex);
is_dhcp_enabled = if (!any_addrs
nm_l3_config_data_get_dhcp_enabled(self->priv.p->combined_l3cd_commited, && !nm_l3_config_data_get_allow_routes_without_address(
addr_family); self->priv.p->combined_l3cd_commited,
if (!any_addrs && is_dhcp_enabled) { addr_family)) {
/* This is a unicast route (or a similar route, which has an /* This is a unicast route (or a similar route, which has an
* ifindex). * ifindex).
* *