1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-07 18:27:04 +03:00

networkd: link - serialize addresses

This commit is contained in:
Tom Gundersen 2015-09-30 15:32:16 +02:00
parent bb7ae737a3
commit e7780c8d44
2 changed files with 29 additions and 3 deletions

View File

@ -98,6 +98,7 @@ void address_free(Address *address) {
if (address->link) {
set_remove(address->link->addresses, address);
set_remove(address->link->addresses_foreign, address);
link_save(address->link);
}
free(address);
@ -270,7 +271,15 @@ 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) {
return address_add_internal(link, &link->addresses, family, in_addr, prefixlen, ret);
int r;
r = address_add_internal(link, &link->addresses, family, in_addr, prefixlen, ret);
if (r < 0)
return r;
link_save(link);
return 0;
}
static int address_release(Address *address) {

View File

@ -2364,6 +2364,8 @@ int link_save(Link *link) {
_cleanup_free_ char *temp_path = NULL;
_cleanup_fclose_ FILE *f = NULL;
const char *admin_state, *oper_state;
Address *a;
Iterator i;
int r;
assert(link);
@ -2541,11 +2543,27 @@ int link_save(Link *link) {
fprintf(f, "LLMNR=%s\n",
resolve_support_to_string(link->network->llmnr));
fprintf(f, "ADDRESSES=");
space = false;
SET_FOREACH(a, link->addresses, i) {
_cleanup_free_ char *address_str = NULL;
r = in_addr_to_string(a->family, &a->in_addr, &address_str);
if (r < 0)
goto fail;
if (space)
fputc(' ', f);
fprintf(f, "%s%s/%u", space ? " " : "", address_str, a->prefixlen);
space = true;
}
fputs("\n", f);
}
if (!hashmap_isempty(link->bound_to_links)) {
Link *carrier;
Iterator i;
bool space = false;
fputs("CARRIER_BOUND_TO=", f);
@ -2561,7 +2579,6 @@ int link_save(Link *link) {
if (!hashmap_isempty(link->bound_by_links)) {
Link *carrier;
Iterator i;
bool space = false;
fputs("CARRIER_BOUND_BY=", f);