EDGESEC  0.1.0-alpha.0+sha.ca29a8277b72f80785649ea9ef9cd7edf642d939
Secure router - reference implementation
Macros | Functions
sqlite_header.h File Reference

File containing the definition of the sqlite header utilities. More...

#include <stdint.h>
#include <pcap.h>
#include <sqlite3.h>
#include "../../../utils/allocs.h"
#include "../../../utils/os.h"
#include "../../capture_config.h"
#include "packet_decoder.h"
Include dependency graph for sqlite_header.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define MAX_DB_NAME   100
 
#define ETH_CREATE_TABLE
 
#define ARP_CREATE_TABLE
 
#define IP4_CREATE_TABLE
 
#define IP6_CREATE_TABLE
 
#define TCP_CREATE_TABLE
 
#define UDP_CREATE_TABLE
 
#define ICMP4_CREATE_TABLE
 
#define ICMP6_CREATE_TABLE
 
#define DNS_CREATE_TABLE
 
#define MDNS_CREATE_TABLE
 
#define DHCP_CREATE_TABLE
 
#define ETH_INSERT_INTO
 
#define ARP_INSERT_INTO
 
#define IP4_INSERT_INTO
 
#define IP6_INSERT_INTO
 
#define TCP_INSERT_INTO
 
#define UDP_INSERT_INTO    "INSERT INTO udp VALUES(@id, @source, @dest, @len, @check_p);"
 
#define ICMP4_INSERT_INTO    "INSERT INTO icmp4 VALUES(@id, @type, @code, @checksum, @gateway);"
 
#define ICMP6_INSERT_INTO
 
#define DNS_INSERT_INTO
 
#define MDNS_INSERT_INTO
 
#define DHCP_INSERT_INTO
 

Functions

int save_packet_statement (sqlite3 *db, struct tuple_packet *tp)
 Save packets to sqlite db. More...
 
int init_sqlite_header_db (sqlite3 *db)
 Initialises the sqlite3 header db tables. More...
 

Detailed Description

File containing the definition of the sqlite header utilities.

Author
Alexandru Mereacre
Date
2021

Macro Definition Documentation

◆ ARP_CREATE_TABLE

#define ARP_CREATE_TABLE
Value:
"CREATE TABLE IF NOT EXISTS arp (id TEXT, " \
"ar_hrd INTEGER, ar_pro INTEGER, ar_hln INTEGER, " \
"ar_pln INTEGER, ar_op INTEGER, arp_sha TEXT, arp_spa TEXT, " \
"arp_tha TEXT, arp_tpa TEXT, PRIMARY KEY (id));"

◆ ARP_INSERT_INTO

#define ARP_INSERT_INTO
Value:
"INSERT INTO arp VALUES(@id, " \
"@ar_hrd, @ar_pro, @ar_hln, @ar_pln, @ar_op, @arp_sha, @arp_spa, " \
"@arp_tha, @arp_tpa);"

◆ DHCP_CREATE_TABLE

#define DHCP_CREATE_TABLE
Value:
"CREATE TABLE IF NOT EXISTS dhcp (id TEXT NOT NULL, " \
"op INTEGER, htype INTEGER, hlen INTEGER, hops INTEGER, xid INTEGER, secs " \
"INTEGER, flags INTEGER, " \
"ciaddr TEXT, yiaddr TEXT, siaddr TEXT, giaddr TEXT, chaddr TEXT, " \
"PRIMARY KEY (id));"

◆ DHCP_INSERT_INTO

#define DHCP_INSERT_INTO
Value:
"INSERT INTO dhcp VALUES(@id, " \
"@op, @htype, @hlen, @hops, @xid, @secs, @flags, " \
"@ciaddr, @yiaddr, @siaddr, @giaddr, @chaddr);"

◆ DNS_CREATE_TABLE

#define DNS_CREATE_TABLE
Value:
"CREATE TABLE IF NOT EXISTS dns (id TEXT NOT NULL, " \
"tid INTEGER, flags INTEGER, nqueries INTEGER, nanswers INTEGER, nauth " \
"INTEGER, " \
"nother INTEGER, qname TEXT, PRIMARY KEY (id));"

◆ DNS_INSERT_INTO

#define DNS_INSERT_INTO
Value:
"INSERT INTO dns VALUES(@id, " \
"@tid, @flags, @nqueries, @nanswers, @nauth, @nother, @qname);"

◆ ETH_CREATE_TABLE

#define ETH_CREATE_TABLE
Value:
"CREATE TABLE IF NOT EXISTS eth (timestamp INTEGER NOT NULL, " \
"id TEXT NOT NULL, caplen INTEGER, length INTEGER, ifname TEXT, " \
"ether_dhost TEXT, ether_shost TEXT, ether_type INTEGER, PRIMARY KEY " \
"(timestamp, id));"

◆ ETH_INSERT_INTO

#define ETH_INSERT_INTO
Value:
"INSERT INTO eth VALUES(@timestamp, @id, @caplen, @length, @ifname, " \
"@ether_dhost, @ether_shost, @ether_type);"

◆ ICMP4_CREATE_TABLE

#define ICMP4_CREATE_TABLE
Value:
"CREATE TABLE IF NOT EXISTS icmp4 (id TEXT NOT NULL, " \
"type INTEGER, code INTEGER, checksum INTEGER, gateway INTEGER, PRIMARY " \
"KEY (id));"

◆ ICMP4_INSERT_INTO

#define ICMP4_INSERT_INTO    "INSERT INTO icmp4 VALUES(@id, @type, @code, @checksum, @gateway);"

◆ ICMP6_CREATE_TABLE

#define ICMP6_CREATE_TABLE
Value:
"CREATE TABLE IF NOT EXISTS icmp6 (id TEXT NOT NULL, " \
"icmp6_type INTEGER, icmp6_code INTEGER, icmp6_cksum INTEGER, " \
"icmp6_un_data32 INTEGER, PRIMARY KEY (id));"

◆ ICMP6_INSERT_INTO

#define ICMP6_INSERT_INTO
Value:
"INSERT INTO icmp6 VALUES(@id, " \
"@icmp6_type, @icmp6_code, @icmp6_cksum, @icmp6_un_data32);"

◆ IP4_CREATE_TABLE

#define IP4_CREATE_TABLE
Value:
"CREATE TABLE IF NOT EXISTS ip4 (id TEXT NOT NULL, " \
"ip_hl INTEGER, ip_v INTEGER, ip_tos INTEGER, ip_len INTEGER, ip_id " \
"INTEGER, " \
"ip_off INTEGER, ip_ttl INTEGER, ip_p INTEGER, ip_sum INTEGER, ip_src " \
"TEXT, " \
"ip_dst TEXT, PRIMARY KEY (id));"

◆ IP4_INSERT_INTO

#define IP4_INSERT_INTO
Value:
"INSERT INTO ip4 VALUES(@id, @ip_hl, @ip_v, " \
"@ip_tos, @ip_len, @ip_id, " \
"@ip_off, @ip_ttl, @ip_p, @ip_sum, @ip_src, @ip_dst);"

◆ IP6_CREATE_TABLE

#define IP6_CREATE_TABLE
Value:
"CREATE TABLE IF NOT EXISTS ip6 (id TEXT NOT NULL, " \
"ip6_un1_flow INTEGER, ip6_un1_plen INTEGER, ip6_un1_nxt INTEGER, " \
"ip6_un1_hlim INTEGER, " \
"ip6_un2_vfc INTEGER, ip6_src TEXT, ip6_dst TEXT, PRIMARY KEY (id));"

◆ IP6_INSERT_INTO

#define IP6_INSERT_INTO
Value:
"INSERT INTO ip6 VALUES(@id, " \
"@ip6_un1_flow, @ip6_un1_plen, @ip6_un1_nxt, @ip6_un1_hlim, @ip6_un2_vfc, " \
"@ip6_src, @ip6_dst);"

◆ MAX_DB_NAME

#define MAX_DB_NAME   100

◆ MDNS_CREATE_TABLE

#define MDNS_CREATE_TABLE
Value:
"CREATE TABLE IF NOT EXISTS mdns (id TEXT NOT NULL, " \
"tid INTEGER, flags INTEGER, nqueries INTEGER, nanswers INTEGER, nauth " \
"INTEGER, " \
"nother INTEGER, qname TEXT, PRIMARY KEY (id));"

◆ MDNS_INSERT_INTO

#define MDNS_INSERT_INTO
Value:
"INSERT INTO mdns VALUES(@id, " \
"@tid, @flags, @nqueries, @nanswers, @nauth, @nother, @qname);"

◆ TCP_CREATE_TABLE

#define TCP_CREATE_TABLE
Value:
"CREATE TABLE IF NOT EXISTS tcp (id TEXT NOT NULL, " \
"source INTEGER, dest INTEGER, seq INTEGER, ack_seq INTEGER, res1 INTEGER, " \
"doff INTEGER, fin INTEGER, " \
"syn INTEGER, rst INTEGER, psh INTEGER, ack INTEGER, urg INTEGER, window " \
"INTEGER, check_p INTEGER, " \
"urg_ptr INTEGER, PRIMARY KEY (id));"

◆ TCP_INSERT_INTO

#define TCP_INSERT_INTO
Value:
"INSERT INTO tcp VALUES(@id, " \
"@source, @dest, @seq, @ack_seq, @res1, @doff, @fin, " \
"@syn, @rst, @psh, @ack, @urg, @window, @check_p, @urg_ptr);"

◆ UDP_CREATE_TABLE

#define UDP_CREATE_TABLE
Value:
"CREATE TABLE IF NOT EXISTS udp (id TEXT NOT NULL, " \
"source INTEGER, dest INTEGER, len INTEGER, check_p INTEGER, PRIMARY KEY " \
"(id));"

◆ UDP_INSERT_INTO

#define UDP_INSERT_INTO    "INSERT INTO udp VALUES(@id, @source, @dest, @len, @check_p);"

Function Documentation

◆ init_sqlite_header_db()

int init_sqlite_header_db ( sqlite3 *  db)

Initialises the sqlite3 header db tables.

Parameters
dbThe sqlite3 db
Returns
0 on success, -1 on failure

◆ save_packet_statement()

int save_packet_statement ( sqlite3 *  db,
struct tuple_packet tp 
)

Save packets to sqlite db.

Parameters
dbThe sqlite3 db
tpThe packet tuple structure
Returns
int 0 on success, -1 o failure