From 3ac8e5433f20bfb5e12b918252643106a2de52af Mon Sep 17 00:00:00 2001 From: Tom Gundersen Date: Tue, 22 Sep 2015 17:54:27 +0200 Subject: 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. --- src/network/test-network.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/network/test-network.c') 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)); -- cgit v1.2.3-54-g00ecf