mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-25 11:50:14 +01:00
l3cfg: set NMIPConfigSource for NML3ConfigData at construct time
Each NML3ConfigData should have a source set, and in fact most callers would call nm_l3_config_data_set_source() right after creating the instance. Move the source parameter to the new() constructor function. Also remove the setter, making the source of an instance immutable. As every l3cfg instance generally has a clear purpose, the source should always be known from the start and doesn't need to change.
This commit is contained in:
parent
7a39f1f7e7
commit
a29d8b712f
8 changed files with 17 additions and 30 deletions
|
|
@ -143,7 +143,7 @@ NMIP6Config *nm_device_ip6_config_new(NMDevice *self);
|
|||
|
||||
NMIPConfig *nm_device_ip_config_new(NMDevice *self, int addr_family);
|
||||
|
||||
NML3ConfigData *nm_device_create_l3_config_data(NMDevice *self);
|
||||
NML3ConfigData *nm_device_create_l3_config_data(NMDevice *self, NMIPConfigSource source);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
|
|
|
|||
|
|
@ -2407,7 +2407,7 @@ nm_device_ip_config_new(NMDevice *self, int addr_family)
|
|||
}
|
||||
|
||||
NML3ConfigData *
|
||||
nm_device_create_l3_config_data(NMDevice *self)
|
||||
nm_device_create_l3_config_data(NMDevice *self, NMIPConfigSource source)
|
||||
{
|
||||
int ifindex;
|
||||
|
||||
|
|
@ -2417,7 +2417,7 @@ nm_device_create_l3_config_data(NMDevice *self)
|
|||
if (ifindex <= 0)
|
||||
g_return_val_if_reached(NULL);
|
||||
|
||||
return nm_l3_config_data_new(nm_device_get_multi_index(self), ifindex);
|
||||
return nm_l3_config_data_new(nm_device_get_multi_index(self), ifindex, source);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
|||
|
|
@ -112,9 +112,7 @@ nm_ndisc_data_to_l3cd(NMDedupMultiIndex * multi_idx,
|
|||
guint i;
|
||||
const gint32 now_sec = nm_utils_get_monotonic_timestamp_sec();
|
||||
|
||||
l3cd = nm_l3_config_data_new(multi_idx, ifindex);
|
||||
|
||||
nm_l3_config_data_set_source(l3cd, NM_IP_CONFIG_SOURCE_NDISC);
|
||||
l3cd = nm_l3_config_data_new(multi_idx, ifindex, NM_IP_CONFIG_SOURCE_NDISC);
|
||||
|
||||
nm_l3_config_data_set_ip6_privacy(l3cd, ip6_privacy);
|
||||
|
||||
|
|
|
|||
|
|
@ -639,12 +639,14 @@ _idx_type_init(DedupMultiIdxType *idx_type, NMPObjectType obj_type)
|
|||
}
|
||||
|
||||
NML3ConfigData *
|
||||
nm_l3_config_data_new(NMDedupMultiIndex *multi_idx, int ifindex)
|
||||
nm_l3_config_data_new(NMDedupMultiIndex *multi_idx, int ifindex, NMIPConfigSource source)
|
||||
{
|
||||
NML3ConfigData *self;
|
||||
|
||||
nm_assert(multi_idx);
|
||||
nm_assert(ifindex > 0);
|
||||
nm_assert(source == NM_IP_CONFIG_SOURCE_UNKNOWN
|
||||
|| (source >= NM_IP_CONFIG_SOURCE_KERNEL && source <= NM_IP_CONFIG_SOURCE_USER));
|
||||
|
||||
self = g_slice_new(NML3ConfigData);
|
||||
*self = (NML3ConfigData){
|
||||
|
|
@ -659,7 +661,7 @@ nm_l3_config_data_new(NMDedupMultiIndex *multi_idx, int ifindex)
|
|||
.proxy_method = NM_PROXY_CONFIG_METHOD_UNKNOWN,
|
||||
.route_table_sync_4 = NM_IP_ROUTE_TABLE_SYNC_MODE_NONE,
|
||||
.route_table_sync_6 = NM_IP_ROUTE_TABLE_SYNC_MODE_NONE,
|
||||
.source = NM_IP_CONFIG_SOURCE_UNKNOWN,
|
||||
.source = source,
|
||||
.ip6_privacy = NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN,
|
||||
.ndisc_hop_limit_set = FALSE,
|
||||
.ndisc_reachable_time_msec_set = FALSE,
|
||||
|
|
@ -1678,18 +1680,6 @@ nm_l3_config_data_set_ip6_mtu(NML3ConfigData *self, guint32 ip6_mtu)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
nm_l3_config_data_set_source(NML3ConfigData *self, NMIPConfigSource source)
|
||||
{
|
||||
nm_assert(_NM_IS_L3_CONFIG_DATA(self, FALSE));
|
||||
|
||||
if (self->source == source)
|
||||
return FALSE;
|
||||
|
||||
self->source = source;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
NMSettingIP6ConfigPrivacy
|
||||
nm_l3_config_data_get_ip6_privacy(const NML3ConfigData *self)
|
||||
{
|
||||
|
|
@ -2570,7 +2560,7 @@ nm_l3_config_data_new_from_connection(NMDedupMultiIndex *multi_idx,
|
|||
NML3ConfigData *self;
|
||||
NMSettingProxy *s_proxy;
|
||||
|
||||
self = nm_l3_config_data_new(multi_idx, ifindex);
|
||||
self = nm_l3_config_data_new(multi_idx, ifindex, NM_IP_CONFIG_SOURCE_USER);
|
||||
|
||||
_init_from_connection_ip(self, AF_INET, connection, route_table_4, route_metric_4);
|
||||
_init_from_connection_ip(self, AF_INET6, connection, route_table_6, route_metric_6);
|
||||
|
|
@ -2689,7 +2679,7 @@ nm_l3_config_data_new_from_platform(NMDedupMultiIndex * multi_idx,
|
|||
if (nm_platform_link_get_master(platform, ifindex) > 0)
|
||||
return NULL;
|
||||
|
||||
self = nm_l3_config_data_new(multi_idx, ifindex);
|
||||
self = nm_l3_config_data_new(multi_idx, ifindex, NM_IP_CONFIG_SOURCE_KERNEL);
|
||||
|
||||
_init_from_platform(self, AF_INET, platform, ipv6_privacy_rfc4941);
|
||||
_init_from_platform(self, AF_INET6, platform, ipv6_privacy_rfc4941);
|
||||
|
|
@ -2929,7 +2919,7 @@ nm_l3_config_data_new_clone(const NML3ConfigData *src, int ifindex)
|
|||
if (ifindex <= 0)
|
||||
ifindex = src->ifindex;
|
||||
|
||||
self = nm_l3_config_data_new(src->multi_idx, ifindex);
|
||||
self = nm_l3_config_data_new(src->multi_idx, ifindex, NM_IP_CONFIG_SOURCE_UNKNOWN);
|
||||
nm_l3_config_data_merge(self,
|
||||
src,
|
||||
NM_L3_CONFIG_MERGE_FLAGS_CLONE,
|
||||
|
|
|
|||
|
|
@ -82,7 +82,8 @@ typedef enum _nm_packed {
|
|||
|
||||
static inline gboolean NM_IS_L3_CONFIG_DATA(const NML3ConfigData *self);
|
||||
|
||||
NML3ConfigData * nm_l3_config_data_new(NMDedupMultiIndex *multi_idx, int ifindex);
|
||||
NML3ConfigData *
|
||||
nm_l3_config_data_new(NMDedupMultiIndex *multi_idx, int ifindex, NMIPConfigSource source);
|
||||
const NML3ConfigData *nm_l3_config_data_ref(const NML3ConfigData *self);
|
||||
const NML3ConfigData *nm_l3_config_data_ref_and_seal(const NML3ConfigData *self);
|
||||
const NML3ConfigData *nm_l3_config_data_seal(const NML3ConfigData *self);
|
||||
|
|
@ -363,8 +364,6 @@ nm_l3_config_data_unset_flags(NML3ConfigData *self, NML3ConfigDatFlags flags)
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
gboolean nm_l3_config_data_set_source(NML3ConfigData *self, NMIPConfigSource source);
|
||||
|
||||
const NMPObject *nm_l3_config_data_get_first_obj(const NML3ConfigData *self,
|
||||
NMPObjectType obj_type,
|
||||
gboolean (*predicate)(const NMPObject *obj));
|
||||
|
|
|
|||
|
|
@ -357,8 +357,7 @@ _l3cd_config_create(int ifindex, in_addr_t addr, NMDedupMultiIndex *multi_idx)
|
|||
nm_assert(ifindex > 0);
|
||||
nm_assert(multi_idx);
|
||||
|
||||
l3cd = nm_l3_config_data_new(multi_idx, ifindex);
|
||||
nm_l3_config_data_set_source(l3cd, NM_IP_CONFIG_SOURCE_IP4LL);
|
||||
l3cd = nm_l3_config_data_new(multi_idx, ifindex, NM_IP_CONFIG_SOURCE_IP4LL);
|
||||
|
||||
nm_l3_config_data_add_address_4(l3cd, _l3cd_config_plat_init_addr(&a, ifindex, addr));
|
||||
nm_l3_config_data_add_route_4(l3cd, _l3cd_config_plat_init_route(&r, ifindex));
|
||||
|
|
|
|||
|
|
@ -3009,7 +3009,8 @@ _l3cfg_update_combined_config(NML3Cfg * self,
|
|||
};
|
||||
|
||||
l3cd = nm_l3_config_data_new(nm_platform_get_multi_idx(self->priv.platform),
|
||||
self->priv.ifindex);
|
||||
self->priv.ifindex,
|
||||
NM_IP_CONFIG_SOURCE_UNKNOWN);
|
||||
|
||||
for (i = 0; i < l3_config_datas_len; i++) {
|
||||
const L3ConfigData *l3cd_data = l3_config_datas_arr[i];
|
||||
|
|
|
|||
|
|
@ -389,7 +389,7 @@ test_l3cfg(gconstpointer test_data)
|
|||
{
|
||||
nm_auto_unref_l3cd_init NML3ConfigData *l3cd = NULL;
|
||||
|
||||
l3cd = nm_l3_config_data_new(f->multiidx, f->ifindex0);
|
||||
l3cd = nm_l3_config_data_new(f->multiidx, f->ifindex0, NM_IP_CONFIG_SOURCE_UNKNOWN);
|
||||
|
||||
nm_l3_config_data_add_address_4(
|
||||
l3cd,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue