1 #ifndef SRC_SLURM_db_slurm_H_
2 #define SRC_SLURM_db_slurm_H_
3 
4 #include <stdbool.h>
5 #include <sys/queue.h>
6 #include <openssl/evp.h>
7 #include "types/vrp.h"
8 #include "types/router_key.h"
9 
10 /* Flags to get data from structs */
11 #define SLURM_COM_FLAG_NONE		0x00
12 #define SLURM_COM_FLAG_ASN		0x01
13 #define SLURM_COM_FLAG_COMMENT		0x02
14 
15 #define SLURM_PFX_FLAG_PREFIX		0x04
16 #define SLURM_PFX_FLAG_MAX_LENGTH	0x08
17 
18 #define SLURM_BGPS_FLAG_SKI		0x04
19 #define SLURM_BGPS_FLAG_ROUTER_KEY	0x08
20 
21 struct slurm_prefix {
22 	uint8_t		data_flag;
23 	struct vrp	vrp;
24 };
25 
26 struct slurm_bgpsec {
27 	uint8_t		data_flag;
28 	uint32_t	asn;
29 	unsigned char	*ski;
30 	unsigned char	*router_public_key;
31 };
32 
33 
34 struct slurm_file_csum {
35 	unsigned char csum[EVP_MAX_MD_SIZE];
36 	unsigned int csum_len;
37 	SLIST_ENTRY(slurm_file_csum) next;
38 };
39 
40 struct slurm_csum_list {
41 	/* TODO (fine) why tf is this not a SLIST_HEAD */
42 	/* TODO (performance) Actually, why tf is this not an arraylist */
43 	struct slurm_file_csum *slh_first;	/* first element */
44 	unsigned int list_size;
45 };
46 
47 struct db_slurm;
48 
49 typedef int (*prefix_foreach_cb)(struct slurm_prefix *, void *);
50 typedef int (*bgpsec_foreach_cb)(struct slurm_bgpsec *, void *);
51 
52 int db_slurm_create(struct slurm_csum_list *, struct db_slurm **);
53 
54 int db_slurm_add_prefix_filter(struct db_slurm *, struct slurm_prefix *);
55 int db_slurm_add_prefix_assertion(struct db_slurm *, struct slurm_prefix *);
56 int db_slurm_add_bgpsec_filter(struct db_slurm *, struct slurm_bgpsec *);
57 int db_slurm_add_bgpsec_assertion(struct db_slurm *, struct slurm_bgpsec *);
58 
59 bool db_slurm_vrp_is_filtered(struct db_slurm *, struct vrp const *);
60 bool db_slurm_bgpsec_is_filtered(struct db_slurm *, struct router_key const *);
61 
62 int db_slurm_foreach_assertion_prefix(struct db_slurm *, prefix_foreach_cb,
63     void *);
64 int db_slurm_foreach_assertion_bgpsec(struct db_slurm *, bgpsec_foreach_cb,
65     void *);
66 
67 /* Log the DB in human readable form at INFO level */
68 void db_slurm_log(struct db_slurm *);
69 
70 /* Start working on the cache */
71 int db_slurm_start_cache(struct db_slurm *);
72 /* Persist all the data stored at cache and erase cache */
73 int db_slurm_flush_cache(struct db_slurm *);
74 
75 /* Does the SLURM DB has data? */
76 bool db_slurm_has_data(struct db_slurm *);
77 
78 void db_slurm_destroy(struct db_slurm *);
79 
80 void db_slurm_get_csum_list(struct db_slurm *, struct slurm_csum_list *);
81 
82 #endif /* SRC_SLURM_db_slurm_H_ */
83