summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2018-10-11 13:52:03 +0200
committerThomas Haller <thaller@redhat.com>2018-10-13 17:11:52 +0200
commit9d0a138ef05544954de49a8056f47e34c6bf3c5a (patch)
tree1735ad933a1c1ef712fd63481b3b5d3d4e5e3cc0
parent23c417854a943eb796a8c06e7d94b02d18f19691 (diff)
downloadNetworkManager-9d0a138ef05544954de49a8056f47e34c6bf3c5a.tar.gz
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.
-rw-r--r--src/ndisc/nm-ndisc.c29
1 files changed, 18 insertions, 11 deletions
diff --git a/src/ndisc/nm-ndisc.c b/src/ndisc/nm-ndisc.c
index db70bd8347..0c2dbf8cdd 100644
--- a/src/ndisc/nm-ndisc.c
+++ b/src/ndisc/nm-ndisc.c
@@ -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;
}