EDGESEC  0.1.0-alpha.0+sha.ca29a8277b72f80785649ea9ef9cd7edf642d939
Secure router - reference implementation
sqlite_header.h
Go to the documentation of this file.
1 
11 #ifndef SQLITE_HEADER_H
12 #define SQLITE_HEADER_H
13 
14 #include <stdint.h>
15 #include <pcap.h>
16 #include <sqlite3.h>
17 
18 #include "../../../utils/allocs.h"
19 #include "../../../utils/os.h"
20 
21 #include "../../capture_config.h"
22 
23 #include "packet_decoder.h"
24 
25 #define MAX_DB_NAME 100
26 
27 #define ETH_CREATE_TABLE \
28  "CREATE TABLE IF NOT EXISTS eth (timestamp INTEGER NOT NULL, " \
29  "id TEXT NOT NULL, caplen INTEGER, length INTEGER, ifname TEXT, " \
30  "ether_dhost TEXT, ether_shost TEXT, ether_type INTEGER, PRIMARY KEY " \
31  "(timestamp, id));"
32 
33 #define ARP_CREATE_TABLE \
34  "CREATE TABLE IF NOT EXISTS arp (id TEXT, " \
35  "ar_hrd INTEGER, ar_pro INTEGER, ar_hln INTEGER, " \
36  "ar_pln INTEGER, ar_op INTEGER, arp_sha TEXT, arp_spa TEXT, " \
37  "arp_tha TEXT, arp_tpa TEXT, PRIMARY KEY (id));"
38 
39 #define IP4_CREATE_TABLE \
40  "CREATE TABLE IF NOT EXISTS ip4 (id TEXT NOT NULL, " \
41  "ip_hl INTEGER, ip_v INTEGER, ip_tos INTEGER, ip_len INTEGER, ip_id " \
42  "INTEGER, " \
43  "ip_off INTEGER, ip_ttl INTEGER, ip_p INTEGER, ip_sum INTEGER, ip_src " \
44  "TEXT, " \
45  "ip_dst TEXT, PRIMARY KEY (id));"
46 
47 #define IP6_CREATE_TABLE \
48  "CREATE TABLE IF NOT EXISTS ip6 (id TEXT NOT NULL, " \
49  "ip6_un1_flow INTEGER, ip6_un1_plen INTEGER, ip6_un1_nxt INTEGER, " \
50  "ip6_un1_hlim INTEGER, " \
51  "ip6_un2_vfc INTEGER, ip6_src TEXT, ip6_dst TEXT, PRIMARY KEY (id));"
52 
53 #define TCP_CREATE_TABLE \
54  "CREATE TABLE IF NOT EXISTS tcp (id TEXT NOT NULL, " \
55  "source INTEGER, dest INTEGER, seq INTEGER, ack_seq INTEGER, res1 INTEGER, " \
56  "doff INTEGER, fin INTEGER, " \
57  "syn INTEGER, rst INTEGER, psh INTEGER, ack INTEGER, urg INTEGER, window " \
58  "INTEGER, check_p INTEGER, " \
59  "urg_ptr INTEGER, PRIMARY KEY (id));"
60 
61 #define UDP_CREATE_TABLE \
62  "CREATE TABLE IF NOT EXISTS udp (id TEXT NOT NULL, " \
63  "source INTEGER, dest INTEGER, len INTEGER, check_p INTEGER, PRIMARY KEY " \
64  "(id));"
65 
66 #define ICMP4_CREATE_TABLE \
67  "CREATE TABLE IF NOT EXISTS icmp4 (id TEXT NOT NULL, " \
68  "type INTEGER, code INTEGER, checksum INTEGER, gateway INTEGER, PRIMARY " \
69  "KEY (id));"
70 
71 #define ICMP6_CREATE_TABLE \
72  "CREATE TABLE IF NOT EXISTS icmp6 (id TEXT NOT NULL, " \
73  "icmp6_type INTEGER, icmp6_code INTEGER, icmp6_cksum INTEGER, " \
74  "icmp6_un_data32 INTEGER, PRIMARY KEY (id));"
75 
76 #define DNS_CREATE_TABLE \
77  "CREATE TABLE IF NOT EXISTS dns (id TEXT NOT NULL, " \
78  "tid INTEGER, flags INTEGER, nqueries INTEGER, nanswers INTEGER, nauth " \
79  "INTEGER, " \
80  "nother INTEGER, qname TEXT, PRIMARY KEY (id));"
81 
82 #define MDNS_CREATE_TABLE \
83  "CREATE TABLE IF NOT EXISTS mdns (id TEXT NOT NULL, " \
84  "tid INTEGER, flags INTEGER, nqueries INTEGER, nanswers INTEGER, nauth " \
85  "INTEGER, " \
86  "nother INTEGER, qname TEXT, PRIMARY KEY (id));"
87 
88 #define DHCP_CREATE_TABLE \
89  "CREATE TABLE IF NOT EXISTS dhcp (id TEXT NOT NULL, " \
90  "op INTEGER, htype INTEGER, hlen INTEGER, hops INTEGER, xid INTEGER, secs " \
91  "INTEGER, flags INTEGER, " \
92  "ciaddr TEXT, yiaddr TEXT, siaddr TEXT, giaddr TEXT, chaddr TEXT, " \
93  "PRIMARY KEY (id));"
94 
95 #define ETH_INSERT_INTO \
96  "INSERT INTO eth VALUES(@timestamp, @id, @caplen, @length, @ifname, " \
97  "@ether_dhost, @ether_shost, @ether_type);"
98 #define ARP_INSERT_INTO \
99  "INSERT INTO arp VALUES(@id, " \
100  "@ar_hrd, @ar_pro, @ar_hln, @ar_pln, @ar_op, @arp_sha, @arp_spa, " \
101  "@arp_tha, @arp_tpa);"
102 #define IP4_INSERT_INTO \
103  "INSERT INTO ip4 VALUES(@id, @ip_hl, @ip_v, " \
104  "@ip_tos, @ip_len, @ip_id, " \
105  "@ip_off, @ip_ttl, @ip_p, @ip_sum, @ip_src, @ip_dst);"
106 #define IP6_INSERT_INTO \
107  "INSERT INTO ip6 VALUES(@id, " \
108  "@ip6_un1_flow, @ip6_un1_plen, @ip6_un1_nxt, @ip6_un1_hlim, @ip6_un2_vfc, " \
109  "@ip6_src, @ip6_dst);"
110 #define TCP_INSERT_INTO \
111  "INSERT INTO tcp VALUES(@id, " \
112  "@source, @dest, @seq, @ack_seq, @res1, @doff, @fin, " \
113  "@syn, @rst, @psh, @ack, @urg, @window, @check_p, @urg_ptr);"
114 #define UDP_INSERT_INTO \
115  "INSERT INTO udp VALUES(@id, @source, @dest, @len, @check_p);"
116 #define ICMP4_INSERT_INTO \
117  "INSERT INTO icmp4 VALUES(@id, @type, @code, @checksum, @gateway);"
118 #define ICMP6_INSERT_INTO \
119  "INSERT INTO icmp6 VALUES(@id, " \
120  "@icmp6_type, @icmp6_code, @icmp6_cksum, @icmp6_un_data32);"
121 #define DNS_INSERT_INTO \
122  "INSERT INTO dns VALUES(@id, " \
123  "@tid, @flags, @nqueries, @nanswers, @nauth, @nother, @qname);"
124 #define MDNS_INSERT_INTO \
125  "INSERT INTO mdns VALUES(@id, " \
126  "@tid, @flags, @nqueries, @nanswers, @nauth, @nother, @qname);"
127 #define DHCP_INSERT_INTO \
128  "INSERT INTO dhcp VALUES(@id, " \
129  "@op, @htype, @hlen, @hops, @xid, @secs, @flags, " \
130  "@ciaddr, @yiaddr, @siaddr, @giaddr, @chaddr);"
131 
139 int save_packet_statement(sqlite3 *db, struct tuple_packet *tp);
140 
147 int init_sqlite_header_db(sqlite3 *db);
148 #endif
File containing the definition of the packet decoder utilities.
int save_packet_statement(sqlite3 *db, struct tuple_packet *tp)
Save packets to sqlite db.
Definition: sqlite_header.c:551
int init_sqlite_header_db(sqlite3 *db)
Initialises the sqlite3 header db tables.
Definition: sqlite_header.c:597
Definition: packet_decoder.h:40