summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2015-09-30 15:32:16 +0200
committerTom Gundersen <teg@jklm.no>2015-10-21 03:24:23 +0200
commite7780c8d44ee32ecf6127f45c0188483c041e2e5 (patch)
tree4ad7a73209e65ea76b6655e53639931c504dc4a2
parentbb7ae737a36769553475b1ada882b06869b75b00 (diff)
networkd: link - serialize addresses
-rw-r--r--src/network/networkd-address.c11
-rw-r--r--src/network/networkd-link.c21
2 files changed, 29 insertions, 3 deletions
diff --git a/src/network/networkd-address.c b/src/network/networkd-address.c
index da458dcb64..8b3694d07f 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 c0f27aaca8..1b55f99646 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);