From e7780c8d44ee32ecf6127f45c0188483c041e2e5 Mon Sep 17 00:00:00 2001 From: Tom Gundersen Date: Wed, 30 Sep 2015 15:32:16 +0200 Subject: [PATCH] networkd: link - serialize addresses --- src/network/networkd-address.c | 11 ++++++++++- src/network/networkd-link.c | 21 +++++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/network/networkd-address.c b/src/network/networkd-address.c index da458dcb640..8b3694d07fe 100644 --- a/src/network/networkd-address.c +++ b/src/network/networkd-address.c @@ -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) { diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c index c0f27aaca8f..1b55f99646a 100644 --- a/src/network/networkd-link.c +++ b/src/network/networkd-link.c @@ -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);