mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-25 13:00:16 +01:00
ndisc: minor refactoring loop in nm_ndisc_add_address()
No change in behavior. Just don't do so much work inside
the deeper nesting of the loop.
(cherry picked from commit 9d0a138ef0)
This commit is contained in:
parent
ac5669633c
commit
3cecb4d018
1 changed files with 18 additions and 11 deletions
|
|
@ -411,6 +411,7 @@ nm_ndisc_add_address (NMNDisc *ndisc, const NMNDiscAddress *new, gboolean from_r
|
|||
NMNDiscPrivate *priv = NM_NDISC_GET_PRIVATE (ndisc);
|
||||
NMNDiscDataInternal *rdata = &priv->rdata;
|
||||
NMNDiscAddress new2;
|
||||
NMNDiscAddress *existing = NULL;
|
||||
guint i;
|
||||
|
||||
nm_assert (new);
|
||||
|
|
@ -425,29 +426,35 @@ nm_ndisc_add_address (NMNDisc *ndisc, const NMNDiscAddress *new, gboolean from_r
|
|||
if (from_ra) {
|
||||
/* RFC4862 5.5.3.d, we find an existing address with the same prefix.
|
||||
* (note that all prefixes at this point have implicity length /64). */
|
||||
if (memcmp (&item->address, &new->address, 8) != 0)
|
||||
continue;
|
||||
if (memcmp (&item->address, &new->address, 8) == 0) {
|
||||
existing = item;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (!IN6_ARE_ADDR_EQUAL (&item->address, &new->address))
|
||||
continue;
|
||||
if (IN6_ARE_ADDR_EQUAL (&item->address, &new->address)) {
|
||||
existing = item;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (existing) {
|
||||
if (new->lifetime == 0) {
|
||||
g_array_remove_index (rdata->addresses, i);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if ( get_expiry (item) == get_expiry (new)
|
||||
&& get_expiry_preferred (item) == get_expiry_preferred (new)
|
||||
if ( get_expiry (existing) == get_expiry (new)
|
||||
&& get_expiry_preferred (existing) == get_expiry_preferred (new)
|
||||
&& ( from_ra
|
||||
|| item->dad_counter == new->dad_counter))
|
||||
|| existing->dad_counter == new->dad_counter))
|
||||
return FALSE;
|
||||
|
||||
if (!from_ra)
|
||||
item->dad_counter = new->dad_counter;
|
||||
item->timestamp = new->timestamp;
|
||||
item->lifetime = new->lifetime;
|
||||
item->preferred = new->preferred;
|
||||
existing->dad_counter = new->dad_counter;
|
||||
existing->timestamp = new->timestamp;
|
||||
existing->lifetime = new->lifetime;
|
||||
existing->preferred = new->preferred;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue