1 #ifndef ADDRWATCH_H
2 #define ADDRWATCH_H
3 
4 #if HAVE_CONFIG_H
5 #include "config.h"
6 #endif
7 #include "common.h"
8 #include "mcache.h"
9 
10 #include <event.h>
11 #include <pcap.h>
12 #if HAVE_LIBSQLITE3
13 #include <sqlite3.h>
14 #endif
15 
16 #include <net/if.h>
17 #include <netinet/in.h>
18 #include <netinet/icmp6.h>
19 #include <netinet/if_ether.h>
20 #include <netinet/ip6.h>
21 #include <sys/socket.h>
22 #include <time.h>
23 
24 #define SNAP_LEN 9000
25 
26 struct iface_config {
27 	char *name;
28 #if HAVE_LIBEVENT2
29 	struct event *event;
30 #else
31 	struct event event;
32 #endif
33 
34 	struct bpf_program pcap_filter;
35 	pcap_t *pcap_handle;
36 
37 	struct mcache_node **cache;
38 
39 	struct iface_config *next;
40 };
41 
42 struct addrwatch_config {
43 	int ratelimit;
44 	int hashsize;
45 	int quiet;
46 
47 	int promisc_flag;
48 	uint8_t v4_flag;
49 	uint8_t v6_flag;
50 	uint8_t daemon_flag;
51 	uint8_t verbose_flag;
52 
53 	char *uname;
54 	long hostname_len;
55 	char *hostname;
56 
57 	struct ip_node *blacklist;
58 
59 	char *pid_file;
60 	char *data_file;
61 	FILE *data_fd;
62 
63 	struct {
64 		struct shm_log *log;
65 		char *name;
66 		uint64_t size;
67 	} shm_data;
68 
69 #if HAVE_LIBSQLITE3
70 	char *sqlite_file;
71 	char *sqlite_table;
72 	sqlite3 *sqlite_conn;
73 	sqlite3_stmt *sqlite_stmt;
74 #endif
75 	struct event_base *eb;
76 #if HAVE_LIBEVENT2
77 	struct event *sigint_ev;
78 	struct event *sigterm_ev;
79 	struct event *sighup_ev;
80 #else
81 	struct event sigint_ev;
82 	struct event sigterm_ev;
83 	struct event sighup_ev;
84 #endif
85 
86 	struct iface_config *interfaces;
87 };
88 
89 struct pkt {
90 	uint8_t *raw_packet;
91 
92 	uint8_t *pos;
93 	unsigned int len;
94 
95 	struct iface_config *ifc;
96 	const struct pcap_pkthdr *pcap_header;
97 
98 	uint16_t vlan_tag;
99 	struct ether_header *ether;
100 	struct ether_arp *arp;
101 	struct ip6_hdr *ip6;
102 	struct icmp6_hdr *icmp6;
103 	struct nd_neighbor_solicit *ns;
104 	struct nd_neighbor_advert *na;
105 	struct nd_opt_hdr *opt_slla;
106 	struct nd_opt_hdr *opt_tlla;
107 
108 	uint8_t *l2_addr;
109 	uint8_t *ip_addr;
110 	uint8_t ip_len;
111 	enum pkt_origin origin;
112 };
113 
114 struct ip_node {
115 	uint8_t ip_addr[16];
116 	uint8_t addr_len;
117 
118 	struct ip_node *next;
119 };
120 
121 extern struct addrwatch_config cfg;
122 extern const char *pkt_origin_str[];
123 
124 #endif
125