summaryrefslogtreecommitdiff
path: root/src/network/networkd-address.c
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2015-09-23 01:53:29 +0200
committerTom Gundersen <teg@jklm.no>2015-10-11 15:04:16 +0200
commitcf1d700da3fe04cd4c27980a292301694be3b05f (patch)
tree1637158da3463b4f94a6522818fd941c95e6cfc4 /src/network/networkd-address.c
parent200a0868fcdf7b95f3d8d1fda3aa2aef48d84fdd (diff)
networkd: address - store active addresses in a Set rather than a List
We need to be able to look these things up quickly as we will be updating them continuously and there can in principle be many of them.
Diffstat (limited to 'src/network/networkd-address.c')
-rw-r--r--src/network/networkd-address.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/network/networkd-address.c b/src/network/networkd-address.c
index efbdda5939..9600b957fe 100644
--- a/src/network/networkd-address.c
+++ b/src/network/networkd-address.c
@@ -95,6 +95,9 @@ void address_free(Address *address) {
UINT_TO_PTR(address->section));
}
+ if (address->link)
+ set_remove(address->link->addresses, address);
+
free(address);
}
@@ -195,6 +198,45 @@ bool address_equal(Address *a1, Address *a2) {
return address_compare_func(a1, a2) == 0;
}
+int address_add(Link *link, Address *address) {
+ int r;
+
+ assert(link);
+ assert(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;
+
+ address->link = link;
+
+ return 0;
+}
+
+int address_get(Link *link, int family, const union in_addr_union *in_addr, unsigned char prefixlen, Address **ret) {
+ Address address = {}, *existing;
+
+ assert(link);
+ assert(in_addr);
+ assert(ret);
+
+ address.family = family;
+ address.in_addr = *in_addr;
+ address.prefixlen = prefixlen;
+
+ existing = set_get(link->addresses, &address);
+ if (!existing)
+ return -ENOENT;
+
+ *ret = existing;
+
+ return 0;
+}
+
int address_establish(Address *address, Link *link) {
bool masq;
int r;