From da101d55e66ebaeeed8b0b16829a2022a1af0678 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Tue, 24 Nov 2020 15:48:55 +0000 Subject: [PATCH] Drop loc_network_eq in favour of loc_network_cmp Signed-off-by: Michael Tremer --- src/libloc.sym | 1 - src/loc/network.h | 1 - src/network.c | 24 ++++-------------------- src/test-network.c | 8 ++++---- 4 files changed, 8 insertions(+), 26 deletions(-) diff --git a/src/libloc.sym b/src/libloc.sym index 4b0ce45..d8e8f14 100644 --- a/src/libloc.sym +++ b/src/libloc.sym @@ -107,7 +107,6 @@ global: # Network loc_network_address_family; loc_network_cmp; - loc_network_eq; loc_network_exclude; loc_network_exclude_list; loc_network_format_first_address; diff --git a/src/loc/network.h b/src/loc/network.h index 8ab1562..d5d0ccd 100644 --- a/src/loc/network.h +++ b/src/loc/network.h @@ -59,7 +59,6 @@ int loc_network_set_flag(struct loc_network* network, uint32_t flag); int loc_network_match_flag(struct loc_network* network, uint32_t flag); int loc_network_cmp(struct loc_network* self, struct loc_network* other); -int loc_network_eq(struct loc_network* self, struct loc_network* other); int loc_network_gt(struct loc_network* self, struct loc_network* other); int loc_network_overlaps(struct loc_network* self, struct loc_network* other); int loc_network_is_subnet(struct loc_network* self, struct loc_network* other); diff --git a/src/network.c b/src/network.c index 7ab22f8..503bf3d 100644 --- a/src/network.c +++ b/src/network.c @@ -463,22 +463,6 @@ LOC_EXPORT int loc_network_cmp(struct loc_network* self, struct loc_network* oth return 0; } -LOC_EXPORT int loc_network_eq(struct loc_network* self, struct loc_network* other) { - // Family must be the same - if (self->family != other->family) - return 0; - - // The start address must be the same - if (in6_addr_cmp(&self->first_address, &other->first_address) != 0) - return 0; - - // The prefix length must be the same - if (self->prefix != other->prefix) - return 0; - - return 1; -} - LOC_EXPORT int loc_network_gt(struct loc_network* self, struct loc_network* other) { // Families must match if (self->family != other->family) @@ -596,12 +580,12 @@ static int __loc_network_exclude(struct loc_network* network, if (r) goto ERROR; - if (loc_network_eq(other, subnet1)) { + if (loc_network_cmp(other, subnet1) == 0) { r = loc_network_list_push(list, subnet2); if (r) goto ERROR; - } else if (loc_network_eq(other, subnet2)) { + } else if (loc_network_cmp(other, subnet2) == 0) { r = loc_network_list_push(list, subnet1); if (r) goto ERROR; @@ -657,7 +641,7 @@ static int __loc_network_exclude_to_list(struct loc_network* self, } // We cannot perform this operation if both networks equal - if (loc_network_eq(self, other)) { + if (loc_network_cmp(self, other) == 0) { DEBUG(self->ctx, "Networks %p and %p are equal\n", self, other); return 1; @@ -745,7 +729,7 @@ LOC_EXPORT struct loc_network_list* loc_network_exclude_list( subnet = loc_network_list_get(list, i); // Drop this subnet if is is already in list - if (loc_network_eq(subnet_to_check, subnet)) { + if (loc_network_cmp(subnet_to_check, subnet) == 0) { passed = 0; loc_network_unref(subnet); break; diff --git a/src/test-network.c b/src/test-network.c index 8a6763c..f4cf97b 100644 --- a/src/test-network.c +++ b/src/test-network.c @@ -125,14 +125,14 @@ int main(int argc, char** argv) { #endif // Check equals function - err = loc_network_eq(network1, network1); - if (!err) { + err = loc_network_cmp(network1, network1); + if (err) { fprintf(stderr, "Network is not equal with itself\n"); exit(EXIT_FAILURE); } - err = loc_network_eq(network1, network2); - if (err) { + err = loc_network_cmp(network1, network2); + if (!err) { fprintf(stderr, "Networks equal unexpectedly\n"); exit(EXIT_FAILURE); } -- 2.39.2