]> git.ipfire.org Git - people/ms/libloc.git/blobdiff - src/database.c
Implement filtering networks for the ASN they belong to
[people/ms/libloc.git] / src / database.c
index 710fa5641fe37c5708d6bb831111d9354fdb66c6..75fc50a03dc6cb6614c00a98c3c37e3b172d90d8 100644 (file)
@@ -78,6 +78,7 @@ struct loc_database_enumerator {
        // Search string
        char* string;
        char country_code[3];
+       uint32_t asn;
 
        // Index of the AS we are looking at
        unsigned int as_index;
@@ -651,6 +652,13 @@ LOC_EXPORT int loc_database_enumerator_set_country_code(struct loc_database_enum
        return 0;
 }
 
+LOC_EXPORT int loc_database_enumerator_set_asn(
+               struct loc_database_enumerator* enumerator, unsigned int asn) {
+       enumerator->asn = asn;
+
+       return 0;
+}
+
 LOC_EXPORT struct loc_as* loc_database_enumerator_next_as(struct loc_database_enumerator* enumerator) {
        struct loc_database* db = enumerator->db;
        struct loc_as* as;
@@ -771,6 +779,12 @@ static int loc_database_enumerator_network_depth_first_search(
                                continue;
                        }
 
+                       // Skip if the ASN does not match
+                       if (e->asn && !loc_network_match_asn(*network, e->asn)) {
+                               loc_network_unref(*network);
+                               continue;
+                       }
+
                        return 0;
                }
        }