Commit a99e7c2b authored by Michael Tremer's avatar Michael Tremer

Add flags to network objects

This changes the database format on disk.

Flags can be used to mark networks in order to add more information
later than only ASN and CC.
Signed-off-by: default avatarMichael Tremer <michael.tremer@ipfire.org>
parent 161ac92d
......@@ -63,13 +63,16 @@ global:
# Network
loc_network_get_asn;
loc_network_get_country_code;
loc_network_has_flag;
loc_network_match_asn;
loc_network_match_country_code;
loc_network_match_flag;
loc_network_new;
loc_network_new_from_string;
loc_network_ref;
loc_network_set_asn;
loc_network_set_country_code;
loc_network_set_flag;
loc_network_str;
loc_network_unref;
......
......@@ -79,6 +79,9 @@ struct loc_database_network_v0 {
// ASN
uint32_t asn;
// Flags
uint32_t flags;
};
struct loc_database_as_v0 {
......
......@@ -40,6 +40,10 @@ uint32_t loc_network_get_asn(struct loc_network* network);
int loc_network_set_asn(struct loc_network* network, uint32_t asn);
int loc_network_match_asn(struct loc_network* network, uint32_t asn);
int loc_network_has_flag(struct loc_network* network, uint32_t flag);
int loc_network_set_flag(struct loc_network* network, uint32_t flag);
int loc_network_match_flag(struct loc_network* network, uint32_t flag);
#ifdef LIBLOC_PRIVATE
int loc_network_to_database_v0(struct loc_network* network, struct loc_database_network_v0* dbobj);
......
......@@ -35,6 +35,7 @@ struct loc_network {
char country_code[3];
uint32_t asn;
uint32_t flags;
};
static int valid_prefix(struct in6_addr* address, unsigned int prefix) {
......@@ -328,6 +329,20 @@ LOC_EXPORT int loc_network_match_asn(struct loc_network* network, uint32_t asn)
return network->asn == asn;
}
LOC_EXPORT int loc_network_has_flag(struct loc_network* network, uint32_t flag) {
return network->flags & flag;
}
LOC_EXPORT int loc_network_set_flag(struct loc_network* network, uint32_t flag) {
network->flags |= flag;
return 0;
}
LOC_EXPORT int loc_network_match_flag(struct loc_network* network, uint32_t flag) {
return loc_network_has_flag(network, flag);
}
LOC_EXPORT int loc_network_to_database_v0(struct loc_network* network, struct loc_database_network_v0* dbobj) {
// Add country code
for (unsigned int i = 0; i < 2; i++) {
......@@ -337,6 +352,9 @@ LOC_EXPORT int loc_network_to_database_v0(struct loc_network* network, struct lo
// Add ASN
dbobj->asn = htobe32(network->asn);
// Flags
dbobj->flags = htobe32(network->flags);
return 0;
}
......@@ -362,6 +380,11 @@ LOC_EXPORT int loc_network_new_from_database_v0(struct loc_ctx* ctx, struct loc_
if (r)
return r;
// Import flags
r = loc_network_set_flag(*network, be32toh(dbobj->flags));
if (r)
return r;
return 0;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment