Skip to Content
[CAIDA - Center for Applied Internet Data Analysis logo]
The Center for Applied Internet Data Analysis
corsaro_geo.h
Go to the documentation of this file.
1 /*
2  * corsaro
3  *
4  * Alistair King, CAIDA, UC San Diego
5  * corsaro-info@caida.org
6  *
7  * Copyright (C) 2012 The Regents of the University of California.
8  *
9  * This file is part of corsaro.
10  *
11  * corsaro is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * corsaro is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with corsaro. If not, see <http://www.gnu.org/licenses/>.
23  *
24  */
25 
26 
27 #ifndef __CORSARO_GEO_H
28 #define __CORSARO_GEO_H
29 
30 #include "khash.h"
31 
32 #include "corsaro_int.h"
33 
34 KHASH_MAP_INIT_INT(corsaro_geo_rechash, struct corsaro_geo_record *)
35 
36 
45 typedef struct corsaro_geo_record
46 {
52  uint32_t id;
53 
55  char country_code[3];
56 
59 
61  char region[3];
62 
64  char *city;
65 
70  char *post_code;
71 
73  double latitude;
74 
76  double longitude;
77 
79  uint32_t metro_code;
80 
82  uint32_t area_code;
83 
85  char *conn_speed;
86 
88  uint32_t *asn;
89 
91  int asn_cnt;
92 
94  uint32_t asn_ip_cnt;
95 
96  /* -- ADD NEW FIELDS ABOVE HERE -- */
97 
99  struct corsaro_geo_record *next;
100 
102 
105  {
108 
111 
113 
121  {
124 
127 
130 
133 
135 
137 typedef struct corsaro_geo_provider
138 {
141 
143  const char *name;
144 
146  khash_t(corsaro_geo_rechash) *all_records;
147 
150 
154 
156 
160  {
163 
168 
171 
173 
176 {
179 
181  char *name;
182 
185 
187  void (*free)(struct corsaro_geo_datastructure *ds);
188 
191  struct corsaro_geo_datastructure *ds,
192  uint32_t addr, uint8_t mask,
194 
197  struct corsaro_geo_datastructure *ds,
198  uint32_t addr);
199 
201  void *state;
202 
204 
211 
219 const char **corsaro_geo_get_provider_names();
220 
239  corsaro_geo_provider_id_t provider_id,
241  corsaro_geo_provider_default_t set_default);
242 
252  corsaro_geo_provider_t *provider);
253 
268  uint32_t id);
269 
277  uint32_t id);
278 
291  corsaro_geo_record_t ***records);
292 
293 
305  corsaro_geo_provider_t *provider,
306  uint32_t addr,
307  uint8_t mask,
309 
319  corsaro_geo_provider_t *provider,
320  uint32_t addr);
321 
332 
347 
348 
356 
365 
373  const char *name);
374 
385 
391 
405 const char *corsaro_geo_get_maxmind_iso2(int country_id);
406 
413 int corsaro_geo_get_maxmind_iso2_list(const char ***countries);
414 
420 const char *corsaro_geo_get_maxmind_iso3(int country_id);
421 
428 int corsaro_geo_get_maxmind_iso3_list(const char ***countries);
429 
435 const char *corsaro_geo_get_maxmind_country_name(int country_id);
436 
442 int corsaro_geo_get_maxmind_country_name_list(const char ***countries);
443 
449 const char *corsaro_geo_get_maxmind_continent(int country_id);
450 
459 int corsaro_geo_get_maxmind_country_continent_list(const char ***continents);
460 
465 #endif /* __CORSARO_GEO_H */
uint32_t id
A unique ID for this record (used to join the Blocks and Locations Files)
Definition: corsaro_geo.h:52
void * state
Pointer to a instance-specific state object.
Definition: corsaro_geo.h:201
struct corsaro_geo_record corsaro_geo_record_t
Structure which contains a geolocation record.
Structure which represents a geolocation datastructure.
Definition: corsaro_geo.h:175
char * conn_speed
Connection Speed/Type.
Definition: corsaro_geo.h:85
Default Geolocation data-structure.
Definition: corsaro_geo.h:170
const char * corsaro_geo_get_maxmind_iso2(int country_id)
Get the ISO-3166-1 2 character country code for the given maxmind country id.
Definition: corsaro_geo.c:728
int corsaro_geo_get_maxmind_iso3_list(const char ***countries)
Get a list of all possible ISO-3166-1 3 character country codes that maxmind uses.
Definition: corsaro_geo.c:746
corsaro_geo_provider_default
Should this provider be set to be the default geolocation result provider.
Definition: corsaro_geo.h:104
void corsaro_geo_free_provider(corsaro_t *corsaro, corsaro_geo_provider_t *provider)
Free the given geolocation provider object.
Definition: corsaro_geo.c:299
int corsaro_geo_get_maxmind_country_name_list(const char ***countries)
Get a list of all possible country names that maxmind uses.
Definition: corsaro_geo.c:758
int corsaro_geo_get_maxmind_iso2_list(const char ***countries)
Get a list of all possible ISO-3166-1 2 character country codes that maxmind uses.
Definition: corsaro_geo.c:734
corsaro_geo_provider_t * corsaro_geo_get_by_id(corsaro_t *corsaro, corsaro_geo_provider_id_t id)
Retrieve the provider object for the given provider ID.
Definition: corsaro_geo.c:495
Geolocation data from Net Acuity Edge.
Definition: corsaro_geo.h:126
const char * corsaro_geo_get_provider_name(corsaro_geo_provider_id_t id)
Get the provider name for the given ID.
Definition: corsaro_geo.c:203
struct corsaro_geo_provider corsaro_geo_provider_t
Structure which represents a geolocation provider.
This provider should be the default geolocation result.
Definition: corsaro_geo.h:110
void corsaro_geo_provider_add_record(corsaro_geo_provider_t *provider, corsaro_geo_record_t *record)
Add the given geolocation record to the head of the given geolocation provider object.
Definition: corsaro_geo.c:465
const char * corsaro_geo_get_maxmind_continent(int country_id)
Get the continent code for the given maxmind country id.
Definition: corsaro_geo.c:764
struct corsaro_geo_datastructure corsaro_geo_datastructure_t
Structure which represents a geolocation datastructure.
Structure which represents a geolocation provider.
Definition: corsaro_geo.h:137
corsaro_geo_record_t * corsaro_geo_provider_lookup_record(corsaro_t *corsaro, corsaro_geo_provider_t *provider, uint32_t addr)
Look up the given address in the provider's datastructure.
Definition: corsaro_geo.c:437
Highest numbered geolocation provider ID.
Definition: corsaro_geo.h:132
void corsaro_geo_dump_record(corsaro_geo_record_t *record)
Dump the given geolocation record to stdout (for debugging)
Definition: corsaro_geo.c:536
corsaro_geo_record_t * records
The list of records which contain the results of geolocation using this provider. ...
Definition: corsaro_geo.h:153
khash_t(corsaro_geo_rechash)*all_records
A hash of id => record for all allocated records of this provider.
const char * name
The name of the provider.
Definition: corsaro_geo.h:143
struct corsaro_geo_datastructure * ds
The datastructure that will be used to perform pfx => record lookups.
Definition: corsaro_geo.h:149
int corsaro_geo_get_maxmind_country_continent_list(const char ***continents)
Get a mapping of continent codes that maxmind uses.
Definition: corsaro_geo.c:770
int asn_cnt
Number of ASNs in the asn array.
Definition: corsaro_geo.h:91
int corsaro_geo_provider_clear(corsaro_geo_provider_t *provider)
Remove all the existing records from the given geolocation provider.
Definition: corsaro_geo.c:447
corsaro_geo_record_t * corsaro_geo_next_record(corsaro_geo_provider_t *provider, corsaro_geo_record_t *record)
Retrieve the next geolocation provider record in the list.
Definition: corsaro_geo.c:521
enum corsaro_geo_provider_default corsaro_geo_provider_default_t
Should this provider be set to be the default geolocation result provider.
corsaro_geo_provider_id
A unique identifier for each geolocation provider that corsaro supports.
Definition: corsaro_geo.h:120
static corsaro_in_record_t * record
A pointer to a corsaro record.
Definition: corsaro_main.c:76
uint32_t asn_ip_cnt
Number of IP addresses that this ASN (or ASN group) 'owns'.
Definition: corsaro_geo.h:94
double latitude
Latitude of the city.
Definition: corsaro_geo.h:73
double longitude
Longitude of the city.
Definition: corsaro_geo.h:76
Geolocation data from Maxmind (Geo or GeoLite)
Definition: corsaro_geo.h:123
static corsaro_t * corsaro
A pointer to the instance of corsaro that we will drive.
Definition: corsaro_main.c:80
corsaro_geo_record_t * corsaro_geo_get_record(corsaro_geo_provider_t *provider, uint32_t id)
Get the geolocation record for the given id.
Definition: corsaro_geo.c:372
corsaro_geo_provider_t * corsaro_geo_get_default(corsaro_t *corsaro)
Retrieve the provider object for the default geolocation provider.
Definition: corsaro_geo.c:489
corsaro_geo_provider_t * corsaro_geo_init_provider(corsaro_t *corsaro, corsaro_geo_provider_id_t provider_id, corsaro_geo_datastructure_id_t ds_id, corsaro_geo_provider_default_t set_default)
Allocate a geolocation provider object in the packet state.
Definition: corsaro_geo.c:222
char * name
The name of this datastructure.
Definition: corsaro_geo.h:181
Highest numbered datastructure ID.
Definition: corsaro_geo.h:167
corsaro_geo_datastructure_id_t id
The ID of this datastructure.
Definition: corsaro_geo.h:178
void(* free)(struct corsaro_geo_datastructure *ds)
Pointer to free function.
Definition: corsaro_geo.h:187
uint32_t area_code
Area code.
Definition: corsaro_geo.h:82
corsaro_geo_provider_id_t id
The ID of the provider.
Definition: corsaro_geo.h:140
char * post_code
String which contains the postal code.
Definition: corsaro_geo.h:70
int corsaro_geo_provider_associate_record(corsaro_t *corsaro, corsaro_geo_provider_t *provider, uint32_t addr, uint8_t mask, corsaro_geo_record_t *record)
Register a new prefix to record mapping for the given provider.
Definition: corsaro_geo.c:425
Structure which contains a geolocation record.
Definition: corsaro_geo.h:45
corsaro_geo_datastructure_id
A unique identifier for each geolocation datastructure that corsaro supports.
Definition: corsaro_geo.h:159
uint32_t * asn
Array of Autonomous System Numbers.
Definition: corsaro_geo.h:88
struct corsaro_geo_record * next
The next record in the list.
Definition: corsaro_geo.h:99
uint32_t metro_code
Metro code.
Definition: corsaro_geo.h:79
int continent_code
Continent Code.
Definition: corsaro_geo.h:58
const char * corsaro_geo_get_maxmind_country_name(int country_id)
Get the country name for the given maxmind country id.
Definition: corsaro_geo.c:752
corsaro_geo_provider_t * corsaro_geo_get_by_name(corsaro_t *corsaro, const char *name)
Retrieve the provider object for the given provider name.
Definition: corsaro_geo.c:503
int corsaro_geo_get_all_records(corsaro_geo_provider_t *provider, corsaro_geo_record_t ***records)
Get an array of all the geolocation records registered with the given provider.
Definition: corsaro_geo.c:386
Corsaro output state.
Definition: corsaro_int.h:230
enum corsaro_geo_datastructure_id corsaro_geo_datastructure_id_t
A unique identifier for each geolocation datastructure that corsaro supports.
This provider should not be the default geolocation result.
Definition: corsaro_geo.h:107
int(* add_prefix)(corsaro_t *corsaro, struct corsaro_geo_datastructure *ds, uint32_t addr, uint8_t mask, corsaro_geo_record_t *record)
Pointer to add prefix function.
Definition: corsaro_geo.h:190
char * city
String which contains the city name.
Definition: corsaro_geo.h:64
enum corsaro_geo_provider_id corsaro_geo_provider_id_t
A unique identifier for each geolocation provider that corsaro supports.
int(* init)(corsaro_t *corsaro, struct corsaro_geo_datastructure *ds)
Pointer to init function.
Definition: corsaro_geo.h:184
const char * corsaro_geo_get_maxmind_iso3(int country_id)
Get the ISO-3166-1 3 character country code for the given maxmind country id.
Definition: corsaro_geo.c:740
corsaro_geo_record_t * corsaro_geo_init_record(corsaro_geo_provider_t *provider, uint32_t id)
Allocate an empty geolocation record for the given id.
Definition: corsaro_geo.c:346
const char ** corsaro_geo_get_provider_names()
Get an array of provider names.
Definition: corsaro_geo.c:215
'Geolocation' data from CAIDA pfx2as
Definition: corsaro_geo.h:129
Header file dealing with the internal corsaro functions.