summaryrefslogtreecommitdiff
path: root/src/network/networkd-address.c
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2015-09-21 15:53:40 +0200
committerTom Gundersen <teg@jklm.no>2015-10-11 14:21:41 +0200
commitf0213e3796b4dd66e546e2de4d677db319f9171b (patch)
treea7c41b70eb2b3e31e760c64afae75702fe1eb00d /src/network/networkd-address.c
parente930d14ac87cbd9280719a30c9ae549821f3adaa (diff)
networkd: route/address - simplify and unify creators
Rename new_dynamic() to simply _new() and reuse that from new_static().
Diffstat (limited to 'src/network/networkd-address.c')
-rw-r--r--src/network/networkd-address.c39
1 files changed, 16 insertions, 23 deletions
diff --git a/src/network/networkd-address.c b/src/network/networkd-address.c
index 388beb5d4c..b2f24ec305 100644
--- a/src/network/networkd-address.c
+++ b/src/network/networkd-address.c
@@ -30,17 +30,27 @@
#include "networkd.h"
#include "networkd-address.h"
-static void address_init(Address *address) {
- assert(address);
+int address_new(Address **ret) {
+ _cleanup_address_free_ Address *address = NULL;
+
+ address = new0(Address, 1);
+ if (!address)
+ return -ENOMEM;
address->family = AF_UNSPEC;
address->scope = RT_SCOPE_UNIVERSE;
address->cinfo.ifa_prefered = CACHE_INFO_INFINITY_LIFE_TIME;
address->cinfo.ifa_valid = CACHE_INFO_INFINITY_LIFE_TIME;
+
+ *ret = address;
+ address = NULL;
+
+ return 0;
}
int address_new_static(Network *network, unsigned section, Address **ret) {
_cleanup_address_free_ Address *address = NULL;
+ int r;
if (section) {
address = hashmap_get(network->addresses_by_section, UINT_TO_PTR(section));
@@ -52,11 +62,9 @@ int address_new_static(Network *network, unsigned section, Address **ret) {
}
}
- address = new0(Address, 1);
- if (!address)
- return -ENOMEM;
-
- address_init(address);
+ r = address_new(&address);
+ if (r < 0)
+ return r;
address->network = network;
@@ -74,21 +82,6 @@ int address_new_static(Network *network, unsigned section, Address **ret) {
return 0;
}
-int address_new_dynamic(Address **ret) {
- _cleanup_address_free_ Address *address = NULL;
-
- address = new0(Address, 1);
- if (!address)
- return -ENOMEM;
-
- address_init(address);
-
- *ret = address;
- address = NULL;
-
- return 0;
-}
-
void address_free(Address *address) {
if (!address)
return;
@@ -292,7 +285,7 @@ static int address_acquire(Link *link, Address *original, Address **ret) {
} else if (original->family == AF_INET6)
in_addr.in6.s6_addr[15] |= 1;
- r = address_new_dynamic(&na);
+ r = address_new(&na);
if (r < 0)
return r;