@@ -163,7 +163,9 @@ _nm_ip_config_add_obj (NMDedupMultiIndex *multi_idx,
163163 NMIPConfigDedupMultiIdxType * idx_type ,
164164 int ifindex ,
165165 const NMPObject * obj_new ,
166- const NMPlatformObject * pl_new )
166+ const NMPlatformObject * pl_new ,
167+ gboolean merge ,
168+ gboolean append_force )
167169{
168170 NMPObject obj_new_stackinit ;
169171 const NMDedupMultiEntry * entry_old ;
@@ -200,58 +202,62 @@ _nm_ip_config_add_obj (NMDedupMultiIndex *multi_idx,
200202 const NMPObject * obj_old = entry_old -> obj ;
201203
202204 if (nmp_object_equal (obj_new , obj_old ))
203- return FALSE;
204-
205- switch (idx_type -> obj_type ) {
206- case NMP_OBJECT_TYPE_IP4_ADDRESS :
207- case NMP_OBJECT_TYPE_IP6_ADDRESS :
208- /* we want to keep the maximum addr_source. But since we expect
209- * that usually we already add the maxiumum right away, we first try to
210- * add the new address (replacing the old one). Only if we later
211- * find out that addr_source is now lower, we fix it.
212- */
213- if (obj_new -> ip_address .addr_source < obj_old -> ip_address .addr_source ) {
214- obj_new = nmp_object_stackinit_obj (& obj_new_stackinit , obj_new );
215- obj_new_stackinit .ip_address .addr_source = obj_old -> ip_address .addr_source ;
216- modified = TRUE;
217- }
205+ goto append_force_and_out ;
206+
207+ /* if @merge, we merge the new object with the existing one.
208+ * Otherwise, we replace it entirely. */
209+ if (merge ) {
210+ switch (idx_type -> obj_type ) {
211+ case NMP_OBJECT_TYPE_IP4_ADDRESS :
212+ case NMP_OBJECT_TYPE_IP6_ADDRESS :
213+ /* we want to keep the maximum addr_source. But since we expect
214+ * that usually we already add the maxiumum right away, we first try to
215+ * add the new address (replacing the old one). Only if we later
216+ * find out that addr_source is now lower, we fix it.
217+ */
218+ if (obj_new -> ip_address .addr_source < obj_old -> ip_address .addr_source ) {
219+ obj_new = nmp_object_stackinit_obj (& obj_new_stackinit , obj_new );
220+ obj_new_stackinit .ip_address .addr_source = obj_old -> ip_address .addr_source ;
221+ modified = TRUE;
222+ }
218223
219- /* for addresses that we read from the kernel, we keep the timestamps as defined
220- * by the previous source (item_old). The reason is, that the other source configured the lifetimes
221- * with "what should be" and the kernel values are "what turned out after configuring it".
222- *
223- * For other sources, the longer lifetime wins. */
224- if ( ( obj_new -> ip_address .addr_source == NM_IP_CONFIG_SOURCE_KERNEL
225- && obj_old -> ip_address .addr_source != NM_IP_CONFIG_SOURCE_KERNEL )
226- || nm_platform_ip_address_cmp_expiry (NMP_OBJECT_CAST_IP_ADDRESS (obj_old ), NMP_OBJECT_CAST_IP_ADDRESS (obj_new )) > 0 ) {
227- obj_new = nmp_object_stackinit_obj (& obj_new_stackinit , obj_new );
228- obj_new_stackinit .ip_address .timestamp = NMP_OBJECT_CAST_IP_ADDRESS (obj_old )-> timestamp ;
229- obj_new_stackinit .ip_address .lifetime = NMP_OBJECT_CAST_IP_ADDRESS (obj_old )-> lifetime ;
230- obj_new_stackinit .ip_address .preferred = NMP_OBJECT_CAST_IP_ADDRESS (obj_old )-> preferred ;
231- modified = TRUE;
232- }
233- break ;
234- case NMP_OBJECT_TYPE_IP4_ROUTE :
235- case NMP_OBJECT_TYPE_IP6_ROUTE :
236- /* we want to keep the maximum rt_source. But since we expect
237- * that usually we already add the maxiumum right away, we first try to
238- * add the new route (replacing the old one). Only if we later
239- * find out that rt_source is now lower, we fix it.
240- */
241- if (obj_new -> ip_route .rt_source < obj_old -> ip_route .rt_source ) {
242- obj_new = nmp_object_stackinit_obj (& obj_new_stackinit , obj_new );
243- obj_new_stackinit .ip_route .rt_source = obj_old -> ip_route .rt_source ;
244- modified = TRUE;
224+ /* for addresses that we read from the kernel, we keep the timestamps as defined
225+ * by the previous source (item_old). The reason is, that the other source configured the lifetimes
226+ * with "what should be" and the kernel values are "what turned out after configuring it".
227+ *
228+ * For other sources, the longer lifetime wins. */
229+ if ( ( obj_new -> ip_address .addr_source == NM_IP_CONFIG_SOURCE_KERNEL
230+ && obj_old -> ip_address .addr_source != NM_IP_CONFIG_SOURCE_KERNEL )
231+ || nm_platform_ip_address_cmp_expiry (NMP_OBJECT_CAST_IP_ADDRESS (obj_old ), NMP_OBJECT_CAST_IP_ADDRESS (obj_new )) > 0 ) {
232+ obj_new = nmp_object_stackinit_obj (& obj_new_stackinit , obj_new );
233+ obj_new_stackinit .ip_address .timestamp = NMP_OBJECT_CAST_IP_ADDRESS (obj_old )-> timestamp ;
234+ obj_new_stackinit .ip_address .lifetime = NMP_OBJECT_CAST_IP_ADDRESS (obj_old )-> lifetime ;
235+ obj_new_stackinit .ip_address .preferred = NMP_OBJECT_CAST_IP_ADDRESS (obj_old )-> preferred ;
236+ modified = TRUE;
237+ }
238+ break ;
239+ case NMP_OBJECT_TYPE_IP4_ROUTE :
240+ case NMP_OBJECT_TYPE_IP6_ROUTE :
241+ /* we want to keep the maximum rt_source. But since we expect
242+ * that usually we already add the maxiumum right away, we first try to
243+ * add the new route (replacing the old one). Only if we later
244+ * find out that rt_source is now lower, we fix it.
245+ */
246+ if (obj_new -> ip_route .rt_source < obj_old -> ip_route .rt_source ) {
247+ obj_new = nmp_object_stackinit_obj (& obj_new_stackinit , obj_new );
248+ obj_new_stackinit .ip_route .rt_source = obj_old -> ip_route .rt_source ;
249+ modified = TRUE;
250+ }
251+ break ;
252+ default :
253+ nm_assert_not_reached ();
254+ break ;
245255 }
246- break ;
247- default :
248- nm_assert_not_reached ();
249- break ;
250- }
251256
252- if ( modified
253- && nmp_object_equal (obj_new , obj_old ))
254- return FALSE;
257+ if ( modified
258+ && nmp_object_equal (obj_new , obj_old ))
259+ goto append_force_and_out ;
260+ }
255261 }
256262
257263 if (!nm_dedup_multi_index_add_full (multi_idx ,
@@ -268,6 +274,13 @@ _nm_ip_config_add_obj (NMDedupMultiIndex *multi_idx,
268274 }
269275
270276 return TRUE;
277+
278+ append_force_and_out :
279+ if (append_force ) {
280+ if (nm_dedup_multi_entry_reorder (entry_old , NULL , TRUE))
281+ return TRUE;
282+ }
283+ return FALSE;
271284}
272285
273286/**
@@ -1955,7 +1968,9 @@ _add_address (NMIP4Config *self, const NMPObject *obj_new, const NMPlatformIP4Ad
19551968 & priv -> idx_ip4_addresses_ ,
19561969 priv -> ifindex ,
19571970 obj_new ,
1958- (const NMPlatformObject * ) new ))
1971+ (const NMPlatformObject * ) new ,
1972+ TRUE,
1973+ FALSE))
19591974 _notify_addresses (self );
19601975}
19611976
@@ -2092,7 +2107,9 @@ _add_route (NMIP4Config *self, const NMPObject *obj_new, const NMPlatformIP4Rout
20922107 & priv -> idx_ip4_routes_ ,
20932108 priv -> ifindex ,
20942109 obj_new ,
2095- (const NMPlatformObject * ) new ))
2110+ (const NMPlatformObject * ) new ,
2111+ TRUE,
2112+ FALSE))
20962113 _notify_routes (self );
20972114}
20982115
0 commit comments