1 /*
2  * Header file for the ip6mon tool
3  *
4  */
5 
6 #define LUI		long unsigned int
7 
8 #define BUFFER_SIZE	65556
9 #define SNAP_LEN	65535
10 #define ETH_ALEN	6		/* Octets in one ethernet addr	 */
11 #define ETH_HLEN	14		/* Total octets in header.	 */
12 #define ETH_DATA_LEN	1500		/* Max. octets in payload	 */
13 #define	ETHERTYPE_IPV6	0x86dd		/* IP protocol version 6 */
14 #define	ETHER_ADDR_LEN	ETH_ALEN	/* size of ethernet addr */
15 #define	ETHER_HDR_LEN	ETH_HLEN	/* total octets in header */
16 
17 #define ETHER_ADDR_PLEN	18		/* Includes termination byte */
18 
19 #define ETHER_ALLNODES_LINK_ADDR	"33:33:00:00:00:01"
20 #define ETHER_ALLROUTERS_LINK_ADDR	"33:33:00:00:00:02"
21 
22 #define	MIN_IPV6_HLEN		40
23 #define MIN_TCP_HLEN		20
24 #define MIN_UDP_HLEN		20
25 #define MIN_DST_OPT_HLEN	8
26 #define MIN_ICMP6_HLEN		8
27 #define	SLLA_OPT_LEN		1
28 #define	TLLA_OPT_LEN		1
29 #define MAX_TLLA_OPTION		256
30 #define MAX_IFACES		100	/* Max number of configured interfaces to search for */
31 #define IFACE_LENGTH	255
32 
33 #define	PROBE_ICMP6_ECHO	1
34 #define PROBE_UNREC_OPT		2
35 
36 #define IPV6_FILTER "ip6"
37 #define TCPV6_FILTER "ip6 and tcp"
38 #define UDPV6_FILTER "ip6 and udp"
39 #define ICMPV6_FILTER "icmp6"
40 #define ICMPV6_NA_FILTER 		"icmp6 and ip6[7]==255 and ip6[40]==136 and ip6[41]==0"
41 #define ICMPV6_RA_FILTER 		"icmp6 and ip6[7]==255 and ip6[40]==134 and ip6[41]==0"
42 
43 
44 /* multi_scan */
45 #define ICMPV6_ECHO_RESPONSE_FILTER	"icmp6 and ((ip6[40]==129 and ip6[41]==0) or (ip6[40]==135 and ip6[41]==0))"
46 #define ICMPV6_ERROR_FILTER		"icmp6 and ((ip6[40]==4) or (ip6[40]==135 and ip6[41]==0))"	/* ICMPv6 Parameter Problem */
47 #define ICMPV6_ECHO_PAYLOAD_SIZE	56
48 
49 #define MAX_PREFIXES_ONLINK		100
50 #define MAX_PREFIXES_AUTO		100
51 #define	MAX_IPV6_ENTRIES		65000
52 #define MAX_LOCAL_ADDRESSES		256
53 
54 /* Constant for the host-scanning functions */
55 #define	PRINT_ETHER_ADDR		1
56 #define NOT_PRINT_ETHER_ADDR		0
57 
58 
59 #define	VALID_MAPPING			2
60 #define INVALID_MAPPING			3
61 
62 
63 
64 #define ALL_NODES_MULTICAST_ADDR	"FF02::1"
65 #define ALL_ROUTERS_MULTICAST_ADDR	"FF02::2"
66 #define SOLICITED_NODE_MULTICAST_PREFIX "FF02:0:0:0:0:1:FF00::"
67 
68 
69 /* Support for IPv6 extension headers */
70 #define FRAG_HDR_SIZE		8
71 #define	MAX_IPV6_PAYLOAD	65535
72 #define MAX_DST_OPT_HDR		256
73 #define MAX_DST_OPT_U_HDR	MAX_DST_OPT_HDR
74 #define MAX_HBH_OPT_HDR		MAX_DST_OPT_HDR
75 
76 
77 /* Filter Constants */
78 #define MAX_BLOCK_SRC			50
79 #define MAX_BLOCK_DST			50
80 #define MAX_BLOCK_TARGET		50
81 #define MAX_BLOCK_LINK_SRC		50
82 #define MAX_BLOCK_LINK_DST		50
83 
84 #define MAX_ACCEPT_SRC			50
85 #define MAX_ACCEPT_DST			50
86 #define MAX_ACCEPT_TARGET		50
87 #define MAX_ACCEPT_LINK_SRC		50
88 #define MAX_ACCEPT_LINK_DST		50
89 
90 #define ACCEPTED			1
91 #define BLOCKED				0
92 
93 #define	ADD_ENTRY			1
94 #define DEL_ENTRY			2
95 
96 /* Constants used with the libcap functions */
97 #define PCAP_SNAP_LEN			65535
98 
99 /*
100    pcap filter to accept: Neighbor Solicitations, Neighbor Advertisements, Router Advertisements,
101    Echo Reply, and ICMPv6 Error Messages
102  */
103 #define PCAP_IPV6MON_FILTER		"icmp6 and ((((ip6[40]==134 and ip6[41]==0) or (ip6[40]==135 and ip6[41]==0) or (ip6[40]==136 and ip6[41]==0)) and ip6[7]==255) or (ip6[40]==129 and ip6[41]==0) or (ip6[40]==4))"
104 
105 #define	PCAP_TIMEOUT			1
106 #define	PCAP_PROMISC			1
107 #define	PCAP_OPT			1
108 #ifndef PCAP_NETMASK_UNKNOWN
109 	#define PCAP_NETMASK_UNKNOWN	0xffffffff
110 #endif
111 
112 
113 #define MAX_LIST_ENTRIES		8192
114 #define	MIN_ADDR_ENTRIES		100
115 #define	MAX_ADDR_ENTRIES		50000
116 #define MAX_CANDIDATE_ENTRIES		MAX_HOST_ENTRIES/8;
117 #define MAX_FUDGE_FACTOR		15
118 #define MAX_HOST_PROBES			4
119 #define MAX_CANDIDATE_PROBES		4
120 #define	MAX_UNPROBED_INTERVAL		40
121 #define MIN_UNICAST_PROBE_INTERVAL	10
122 #define UNICAST_PROBE_INTERVAL		15
123 #define ADDR_TIMEOUT			90
124 #define MIN_ADDR_TIMEOUT		30
125 #define MIN_CANDIDATE_TIMEOUT		30
126 #define CAND_ADDR_TIMEOUT		((ADDR_TIMEOUT *3) /4)
127 #define MC_ECHO_PROBE_INTERVAL		120
128 #define MIN_MC_ECHO_PROBE_INTERVAL	60
129 #define MC_UNREC_PROBE_INTERVAL		120
130 #define MIN_MC_UNREC_PROBE_INTERVAL	60
131 #define	SELECT_TIMEOUT			4
132 #define RETRY_CONFIG			60
133 #define RS_SEND_INTERVAL		2
134 #define RA_ACCEPT_WINDOW		5
135 #define CHECK_CONFIG_INTERVAL		60
136 #define LOCAL_ADDRESS_TIMEOUT		(CHECK_CONFIG_INTERVAL + RA_ACCEPT_WINDOW)
137 #define MAX_PROC_ENTRIES_INT		1
138 #define MAX_GARB_COLLECT_INT            10
139 
140 /* Internal state of send_multicast */
141 #define	SCAN_LOCAL			1
142 #define SCAN_GLOBAL			2
143 
144 /* Possible values for the TimestampFormat */
145 #define	TIMESTAMP_DATE			1
146 #define	TIMESTAMP_EPOCH			2
147 
148 /* Constants for config file processing */
149 #define MAX_LINE_SIZE			250
150 #define MAX_VAR_NAME_LEN		40
151 
152 
153 struct ether_addr{
154   u_int8_t a[ETHER_ADDR_LEN];
155 } __attribute__ ((__packed__));
156 
157 struct	nd_opt_slla{
158     u_int8_t	type;
159     u_int8_t	length;
160     u_int8_t	address[6];
161 } __attribute__ ((__packed__));
162 
163 struct	nd_opt_tlla{
164     u_int8_t	type;
165     u_int8_t	length;
166     u_int8_t	address[6];
167 } __attribute__ ((__packed__));
168 
169 struct ipv6pseudohdr{
170     struct in6_addr srcaddr;
171     struct in6_addr dstaddr;
172     u_int32_t	len;
173     u_int8_t zero[3];
174     u_int8_t	nh;
175 } __attribute__ ((__packed__));
176 
177 /* 10Mb/s ethernet header */
178 struct ether_header
179 {
180   struct ether_addr dst;	/* destination eth addr	*/
181   struct ether_addr src;	/* source ether addr	*/
182   u_int16_t ether_type;		/* packet type ID field	*/
183 } __attribute__ ((__packed__));
184 
185 
186 struct host_entry{
187 	struct in6_addr		ip6;
188 	struct ether_addr	ether;
189 	unsigned char		flag;
190 	time_t			fseen;
191 	time_t			lseen;
192 	time_t			lprobed;
193 	unsigned int		nprobes;
194 	struct host_entry	*next;
195 	struct host_entry	*prev;
196 	unsigned int		ffactor;
197 };
198 
199 struct host_list{
200 	struct host_entry	**host;			/* Double-linked list of host entries */
201 	unsigned int		nhosts;			/* Current number of host entries */
202 	unsigned int		maxhosts;		/* Maximum number of host entries */
203 	unsigned int		ncandidates;		/* Candidate addresses in list */
204 	unsigned int		maxcandidates;		/* Maximum number of candidate entries */
205 	time_t			lastprocessed;		/* Last time the list was processed entirely */
206 	time_t			lastgcollection;		/* Last time the list was garbage-collected */
207 
208 	u_int16_t		key_l;			/* Low-order word of the hash key */
209 	u_int16_t		key_h;			/* High-order word of the hash key */
210 
211 	unsigned int 		mc_unrec_probe_f;	/* Whether Unrec probes should be sent */
212 	unsigned int		mc_unrec_state;		/* Multicast unrec probe state (local vs. global) */
213 	unsigned int		mc_unrec_naddr;		/* Current src addr for mcast echo probes   */
214 	u_int16_t		mc_unrec_seq;		/* Multicast unrec sequence #	*/
215 	time_t			mc_unrec_last;		/* Last multicast unrec probe	*/
216 
217 	unsigned int		mc_echo_probe_f;	/* Whether Echo probes should be sent */
218 	unsigned int		mc_echo_state;		/* Multicast echo probe state (local vs. global) */
219 	unsigned int		mc_echo_naddr;		/* Current src addr for mcast echo probes   */
220 	unsigned int		mc_echo_seq;		/* Multicast echo sequence #	*/
221 	time_t			mc_echo_last;		/* Last multicast echo probe	*/
222 
223 	unsigned int		np_key;			/* Next list entry to process	*/
224 	struct host_entry	*np_hentry;		/* Next host entry to process	*/
225 };
226 
227 struct prefix_entry{
228 	struct in6_addr		ip6;
229 	unsigned char		len;
230 	time_t			tstamp;
231 };
232 
233 struct prefix_list{
234 	struct prefix_entry	**prefix;
235 	unsigned int		nprefix;
236 	unsigned int		maxprefix;
237 };
238 
239 
240 struct address_list{
241 	struct in6_addr		*addr;
242 	unsigned int		naddr;
243 	unsigned int		maxaddr;
244 };
245 
246 struct iface_data{
247 	char			iface[IFACE_LENGTH];
248 	struct ether_addr	ether;
249 	unsigned int		ether_flag;
250 	struct in6_addr		ip6_local;
251 	unsigned int		ip6_local_flag;
252 	struct prefix_list	ip6_global;
253 	unsigned int		ip6_global_flag;
254 	unsigned int		ip6_global_nconfig;
255 	time_t			ip6_global_conftime;
256 	time_t			ip6_global_lastcheck;
257 	time_t			last_rs;
258 	struct in6_addr		router_ip6;
259 	struct ether_addr	router_ether;
260 	struct prefix_list	prefix_ac;
261 	struct prefix_list	prefix_ol;
262 	unsigned int		local_retrans;
263 	unsigned int		local_timeout;
264 	unsigned int		mtu;
265 	unsigned int		pending_write_f;
266 	void			*pending_write_data;
267 	unsigned int		pending_write_size;
268 	int			fd;
269 	fd_set			*rset;
270 	fd_set			*wset;
271 	fd_set			*eset;
272 	unsigned int		write_errors;
273 };
274 
275 
276 #if defined (__FreeBSD__) || defined(__NetBSD__) || defined (__OpenBSD__) || defined(__APPLE__)
277     #ifndef s6_addr16
278 	    #define s6_addr16	__u6_addr.__u6_addr16
279     #endif
280 
281     #ifndef s6_addr8
282 	    #define s6_addr8	__u6_addr.__u6_addr8
283     #endif
284 
285     #ifndef s6_addr32
286 	    #define s6_addr32	__u6_addr.__u6_addr32
287     #endif
288 #endif
289 
290 
291 /* This causes Linux to use the BSD definition of the TCP and UDP header fields */
292 #ifndef __FAVOR_BSD
293 	#define __FAVOR_BSD
294 #endif
295 
296