summaryrefslogtreecommitdiff
path: root/src/network/test-network.c
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2015-09-22 17:54:27 +0200
committerTom Gundersen <teg@jklm.no>2015-10-11 15:03:04 +0200
commit3ac8e5433f20bfb5e12b918252643106a2de52af (patch)
tree1114150ee49b728395a2669e79db5ef0e6335d64 /src/network/test-network.c
parent7d20d3759e375367c36471906ba898c6909d5132 (diff)
networkd: address - add hash helpers for Address objects
Add compare_func and hash_func for the Address object. The notion of address equality is the same as in the kernel, and hashing preserves preserves equality. Two addresses are considered equal if: - they have the same address family, and - they are neither IPv4 nor IPv6 addresses, or - the local addresses are identical, and - they are IPv6 addresses, or - they have the same prefixlength, and - their peer prefixes are identical This fixes a bug in the old equality check, which got the local address and the peer prefix mixed up.
Diffstat (limited to 'src/network/test-network.c')
-rw-r--r--src/network/test-network.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/network/test-network.c b/src/network/test-network.c
index 80676651a9..bac1d6781d 100644
--- a/src/network/test-network.c
+++ b/src/network/test-network.c
@@ -158,17 +158,18 @@ static void test_address_equality(void) {
assert_se(address_equal(a1, a2));
assert_se(inet_pton(AF_INET, "192.168.3.9", &a1->in_addr.in));
- assert_se(address_equal(a1, a2));
+ assert_se(!address_equal(a1, a2));
assert_se(inet_pton(AF_INET, "192.168.3.9", &a2->in_addr.in));
assert_se(address_equal(a1, a2));
+ assert_se(inet_pton(AF_INET, "192.168.3.10", &a1->in_addr_peer.in));
+ assert_se(address_equal(a1, a2));
+ assert_se(inet_pton(AF_INET, "192.168.3.11", &a2->in_addr_peer.in));
+ assert_se(address_equal(a1, a2));
a1->prefixlen = 10;
assert_se(!address_equal(a1, a2));
a2->prefixlen = 10;
assert_se(address_equal(a1, a2));
- assert_se(inet_pton(AF_INET, "192.168.3.10", &a2->in_addr.in));
- assert_se(address_equal(a1, a2));
-
a1->family = AF_INET6;
assert_se(!address_equal(a1, a2));