]> git.ipfire.org Git - people/ms/libloc.git/blobdiff - src/network.c
network: Speed up subnet check
[people/ms/libloc.git] / src / network.c
index 4720503cef893e26a2edd1a827e0f3105cad36e9..e52b58c63af2ec4ef69cfa31a94956980c170c99 100644 (file)
@@ -501,6 +501,14 @@ LOC_EXPORT int loc_network_overlaps(struct loc_network* self, struct loc_network
 }
 
 LOC_EXPORT int loc_network_is_subnet(struct loc_network* self, struct loc_network* other) {
+       // Check family
+       if (self->family != other->family)
+               return 0;
+
+       // The prefix must be smaller (this avoids the more complex comparisons later)
+       if (self->prefix > other->prefix)
+               return 0;
+
        // If the start address of the other network is smaller than this network,
        // it cannot be a subnet.
        if (in6_addr_cmp(&self->first_address, &other->first_address) > 0)