time_t created_at;
off_t vendor;
off_t description;
+ off_t license;
// ASes in the database
struct loc_database_as_v0* as_v0;
db->created_at = be64toh(header.created_at);
db->vendor = be32toh(header.vendor);
db->description = be32toh(header.description);
+ db->license = be32toh(header.license);
// Open pool
off_t pool_offset = be32toh(header.pool_offset);
}
static void loc_database_free(struct loc_database* db) {
+ int r;
+
DEBUG(db->ctx, "Releasing database %p\n", db);
// Removing all ASes
if (db->as_v0) {
- int r = munmap(db->as_v0, db->as_count * sizeof(*db->as_v0));
+ r = munmap(db->as_v0, db->as_count * sizeof(*db->as_v0));
if (r)
ERROR(db->ctx, "Could not unmap AS section: %s\n", strerror(errno));
}
+ // Remove mapped network sections
+ if (db->networks_v0) {
+ r = munmap(db->networks_v0, db->networks_count * sizeof(*db->networks_v0));
+ if (r)
+ ERROR(db->ctx, "Could not unmap networks section: %s\n", strerror(errno));
+ }
+
+ // Remove mapped network nodes section
+ if (db->network_nodes_v0) {
+ r = munmap(db->network_nodes_v0, db->network_nodes_count * sizeof(*db->network_nodes_v0));
+ if (r)
+ ERROR(db->ctx, "Could not unmap network nodes section: %s\n", strerror(errno));
+ }
+
loc_stringpool_unref(db->pool);
loc_unref(db->ctx);
return loc_stringpool_get(db->pool, db->description);
}
+LOC_EXPORT const char* loc_database_get_license(struct loc_database* db) {
+ return loc_stringpool_get(db->pool, db->license);
+}
+
LOC_EXPORT size_t loc_database_count_as(struct loc_database* db) {
return db->as_count;
}
return r;
}
-static int __loc_database_lookup_leaf_node(struct loc_database* db, const struct in6_addr* address,
+static int __loc_database_node_is_leaf(const struct loc_database_network_node_v0* node) {
+ return (node->zero == htobe32(0xffffffff));
+}
+
+static int __loc_database_lookup_handle_leaf(struct loc_database* db, const struct in6_addr* address,
struct loc_network** network, struct in6_addr* network_address,
const struct loc_database_network_node_v0* node) {
- // Check if this node is a leaf node
- if (node->zero != htobe32(0xffffffff))
- return 1;
-
- DEBUG(db->ctx, "Node is a leaf: %jd\n", node - db->network_nodes_v0);
+ DEBUG(db->ctx, "Handling leaf node at %jd\n", node - db->network_nodes_v0);
// Fetch the network
int r = loc_database_fetch_network(db, network,
// Returns the highest result available
static int __loc_database_lookup_max(struct loc_database* db, const struct in6_addr* address,
struct loc_network** network, struct in6_addr* network_address,
- const struct loc_database_network_node_v0* node, int level) {
-
+ const struct loc_database_network_node_v0* node, unsigned int level) {
// If the node is a leaf node, we end here
- int r = __loc_database_lookup_leaf_node(db, address, network, network_address, node);
- if (r <= 0)
- return r;
+ if (__loc_database_node_is_leaf(node))
+ return __loc_database_lookup_handle_leaf(db, address, network, network_address, node);
+ int r;
off_t node_index;
// Try to go down the ones path first
// Searches for an exact match along the path
static int __loc_database_lookup(struct loc_database* db, const struct in6_addr* address,
struct loc_network** network, struct in6_addr* network_address,
- const struct loc_database_network_node_v0* node, int level) {
+ const struct loc_database_network_node_v0* node, unsigned int level) {
// If the node is a leaf node, we end here
- int r = __loc_database_lookup_leaf_node(db, address, network, network_address, node);
- if (r <= 0)
- return r;
+ if (__loc_database_node_is_leaf(node))
+ return __loc_database_lookup_handle_leaf(db, address, network, network_address, node);
+ int r;
off_t node_index;
// Follow the path