diff options
author | Tom Gundersen <teg@jklm.no> | 2015-10-26 11:40:02 +0100 |
---|---|---|
committer | Tom Gundersen <teg@jklm.no> | 2015-10-30 12:32:48 +0100 |
commit | cab974b035c24a87f9a8cf152ea415b0c14404b7 (patch) | |
tree | 25f16fc81257e28208791ae23945ee855025f9ce | |
parent | a3a019e125ff2ab38505579eaddce08874e270aa (diff) |
networkd: address - properly take over a foreign address
-rw-r--r-- | src/network/networkd-address.c | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/src/network/networkd-address.c b/src/network/networkd-address.c index 0338fe9393..5b5492e02e 100644 --- a/src/network/networkd-address.c +++ b/src/network/networkd-address.c @@ -272,14 +272,34 @@ int address_add_foreign(Link *link, int family, const union in_addr_union *in_ad } static int address_add(Link *link, int family, const union in_addr_union *in_addr, unsigned char prefixlen, Address **ret) { + Address *address; int r; - r = address_add_internal(link, &link->addresses, family, in_addr, prefixlen, ret); - if (r < 0) + r = address_get(link, family, in_addr, prefixlen, &address); + if (r == -ENOENT) { + /* Address does not exist, create a new one */ + r = address_add_internal(link, &link->addresses, family, in_addr, prefixlen, &address); + if (r < 0) + return r; + } else if (r == 0) { + /* Take over a foreign address */ + r = set_ensure_allocated(&link->addresses, &address_hash_ops); + if (r < 0) + return r; + + r = set_put(link->addresses, address); + if (r < 0) + return r; + + set_remove(link->addresses_foreign, address); + } else if (r == 1) { + /* Already exists, do nothing */ + ; + } else return r; - link_update_operstate(link); - link_dirty(link); + if (ret) + *ret = address; return 0; } @@ -360,7 +380,11 @@ int address_get(Link *link, int family, const union in_addr_union *in_addr, unsi address.prefixlen = prefixlen; existing = set_get(link->addresses, &address); - if (!existing) { + if (existing) { + *ret = existing; + + return 1; + } else { existing = set_get(link->addresses_foreign, &address); if (!existing) return -ENOENT; |