1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #ifndef	_MPD_DEFS_H
28*7c478bd9Sstevel@tonic-gate #define	_MPD_DEFS_H
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*7c478bd9Sstevel@tonic-gate 
32*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
33*7c478bd9Sstevel@tonic-gate extern "C" {
34*7c478bd9Sstevel@tonic-gate #endif
35*7c478bd9Sstevel@tonic-gate 
36*7c478bd9Sstevel@tonic-gate #include <alloca.h>
37*7c478bd9Sstevel@tonic-gate #include <stdio.h>
38*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
39*7c478bd9Sstevel@tonic-gate #include <strings.h>
40*7c478bd9Sstevel@tonic-gate #include <errno.h>
41*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
42*7c478bd9Sstevel@tonic-gate #include <limits.h>
43*7c478bd9Sstevel@tonic-gate #include <fcntl.h>
44*7c478bd9Sstevel@tonic-gate #include <signal.h>
45*7c478bd9Sstevel@tonic-gate #include <poll.h>
46*7c478bd9Sstevel@tonic-gate #include <unistd.h>
47*7c478bd9Sstevel@tonic-gate #include <time.h>
48*7c478bd9Sstevel@tonic-gate #include <stdarg.h>
49*7c478bd9Sstevel@tonic-gate 
50*7c478bd9Sstevel@tonic-gate #include <sys/param.h>
51*7c478bd9Sstevel@tonic-gate #include <sys/socket.h>
52*7c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
53*7c478bd9Sstevel@tonic-gate #include <arpa/inet.h>
54*7c478bd9Sstevel@tonic-gate #include <netdb.h>
55*7c478bd9Sstevel@tonic-gate 
56*7c478bd9Sstevel@tonic-gate #include <sys/ioctl.h>
57*7c478bd9Sstevel@tonic-gate #include <sys/sockio.h>
58*7c478bd9Sstevel@tonic-gate #include <net/if.h>
59*7c478bd9Sstevel@tonic-gate #include <stropts.h>
60*7c478bd9Sstevel@tonic-gate #include <sys/tihdr.h>
61*7c478bd9Sstevel@tonic-gate #include <inet/mib2.h>
62*7c478bd9Sstevel@tonic-gate 
63*7c478bd9Sstevel@tonic-gate #include <string.h>
64*7c478bd9Sstevel@tonic-gate #include <ctype.h>
65*7c478bd9Sstevel@tonic-gate 
66*7c478bd9Sstevel@tonic-gate #include <netinet/in_systm.h>
67*7c478bd9Sstevel@tonic-gate #include <netinet/in.h>
68*7c478bd9Sstevel@tonic-gate #include <netinet/ip.h>
69*7c478bd9Sstevel@tonic-gate #include <netinet/ip_icmp.h>
70*7c478bd9Sstevel@tonic-gate #include <netinet/if_ether.h>
71*7c478bd9Sstevel@tonic-gate #include <netinet/ip6.h>
72*7c478bd9Sstevel@tonic-gate #include <netinet/icmp6.h>
73*7c478bd9Sstevel@tonic-gate #include <net/route.h>
74*7c478bd9Sstevel@tonic-gate #include <net/if_dl.h>
75*7c478bd9Sstevel@tonic-gate 
76*7c478bd9Sstevel@tonic-gate #include <inet/ip.h>
77*7c478bd9Sstevel@tonic-gate #include <libintl.h>
78*7c478bd9Sstevel@tonic-gate #include <locale.h>
79*7c478bd9Sstevel@tonic-gate #include <deflt.h>
80*7c478bd9Sstevel@tonic-gate 
81*7c478bd9Sstevel@tonic-gate #include <libnvpair.h>
82*7c478bd9Sstevel@tonic-gate #include <libsysevent.h>
83*7c478bd9Sstevel@tonic-gate #include <sys/sysevent.h>
84*7c478bd9Sstevel@tonic-gate #include <sys/sysevent/eventdefs.h>
85*7c478bd9Sstevel@tonic-gate #include <sys/sysevent/ipmp.h>
86*7c478bd9Sstevel@tonic-gate 
87*7c478bd9Sstevel@tonic-gate #include <ipmp_mpathd.h>
88*7c478bd9Sstevel@tonic-gate #include <ipmp_query_impl.h>
89*7c478bd9Sstevel@tonic-gate #include <assert.h>
90*7c478bd9Sstevel@tonic-gate 
91*7c478bd9Sstevel@tonic-gate /* Debug flags */
92*7c478bd9Sstevel@tonic-gate #define	D_ALL		0xffff		/* enable all debug */
93*7c478bd9Sstevel@tonic-gate #define	D_PROBE		0x0001		/* probe mechanism */
94*7c478bd9Sstevel@tonic-gate #define	D_FAILOVER	0x0002		/* failover mechanism */
95*7c478bd9Sstevel@tonic-gate #define	D_PHYINT	0x0004		/* phyint table */
96*7c478bd9Sstevel@tonic-gate #define	D_LOGINT	0x0008		/* logint table */
97*7c478bd9Sstevel@tonic-gate #define	D_TARGET	0x0010		/* target table */
98*7c478bd9Sstevel@tonic-gate #define	D_TIMER		0x0020		/* Timer mechanism */
99*7c478bd9Sstevel@tonic-gate #define	D_PKTBAD	0x0040		/* Malformed packet */
100*7c478bd9Sstevel@tonic-gate #define	D_LINKNOTE	0x0080		/* Link up/down notifications */
101*7c478bd9Sstevel@tonic-gate /*
102*7c478bd9Sstevel@tonic-gate  * Need a common header file that defines the 2 constants below.
103*7c478bd9Sstevel@tonic-gate  * Many applications need them.
104*7c478bd9Sstevel@tonic-gate  */
105*7c478bd9Sstevel@tonic-gate #define	IF_SEPARATOR		':'
106*7c478bd9Sstevel@tonic-gate #define	IPV6_MAX_HOPS		255
107*7c478bd9Sstevel@tonic-gate 
108*7c478bd9Sstevel@tonic-gate /*
109*7c478bd9Sstevel@tonic-gate  * General parameters for phyint failure/repair detection
110*7c478bd9Sstevel@tonic-gate  */
111*7c478bd9Sstevel@tonic-gate #define	NUM_PROBE_FAILS		5	/* NUM_PROBE_FAILS probe failures */
112*7c478bd9Sstevel@tonic-gate 					/* trigger NIC failure detection */
113*7c478bd9Sstevel@tonic-gate #define	NUM_PROBE_REPAIRS	10	/* NUM_PROBE_REPAIRS probe repairs */
114*7c478bd9Sstevel@tonic-gate 					/* trigger NIC repair detection */
115*7c478bd9Sstevel@tonic-gate 
116*7c478bd9Sstevel@tonic-gate #define	MIN_RANDOM_FACTOR	0.5	/* Randomization factors to */
117*7c478bd9Sstevel@tonic-gate #define	MAX_RANDOM_FACTOR	1.0	/* determine probe send time */
118*7c478bd9Sstevel@tonic-gate 
119*7c478bd9Sstevel@tonic-gate #define	MIN_PROBE_TARGETS	3	/* Minimum number of targets */
120*7c478bd9Sstevel@tonic-gate #define	MAX_PROBE_TARGETS	5	/* Maximum number of targets */
121*7c478bd9Sstevel@tonic-gate 
122*7c478bd9Sstevel@tonic-gate /*
123*7c478bd9Sstevel@tonic-gate  * A target that is declared slow is usable again after MIN_RECOVERY_TIME ns
124*7c478bd9Sstevel@tonic-gate  */
125*7c478bd9Sstevel@tonic-gate #define	MIN_RECOVERY_TIME	(60000000000LL) /* (In ns) 60 secs */
126*7c478bd9Sstevel@tonic-gate 
127*7c478bd9Sstevel@tonic-gate /*
128*7c478bd9Sstevel@tonic-gate  * If the Failure Detection Time (FDT) is bumped up because the target CRTT
129*7c478bd9Sstevel@tonic-gate  * is high, it won't be reduced for the next MIN_SETTLING_TIME ns, to prevent
130*7c478bd9Sstevel@tonic-gate  * flapping of FDT
131*7c478bd9Sstevel@tonic-gate  */
132*7c478bd9Sstevel@tonic-gate #define	MIN_SETTLING_TIME	(60000000000LL) /* (In ns) 60 secs */
133*7c478bd9Sstevel@tonic-gate 
134*7c478bd9Sstevel@tonic-gate /*
135*7c478bd9Sstevel@tonic-gate  * The circular probe stats array should be able to hold enough
136*7c478bd9Sstevel@tonic-gate  * samples to detect phyint failure, target failure, phyint repair
137*7c478bd9Sstevel@tonic-gate  * and target repair.
138*7c478bd9Sstevel@tonic-gate  */
139*7c478bd9Sstevel@tonic-gate #define	PROBE_STATS_COUNT	\
140*7c478bd9Sstevel@tonic-gate 	((uint16_t)(NUM_PROBE_REPAIRS * MAX_PROBE_TARGETS + 2))
141*7c478bd9Sstevel@tonic-gate 
142*7c478bd9Sstevel@tonic-gate #define	FAILURE_DETECTION_TIME	10000	/* Default is 10 s */
143*7c478bd9Sstevel@tonic-gate #define	MIN_FAILURE_DETECTION_TIME	100	/* Minimum is 100 ms */
144*7c478bd9Sstevel@tonic-gate #define	FAILURE_DETECTION_QP	40	/* quiet period, in seconds */
145*7c478bd9Sstevel@tonic-gate 
146*7c478bd9Sstevel@tonic-gate #define	NEXT_FDT_MULTIPLE	2	/* Raise or lower the FDT by this */
147*7c478bd9Sstevel@tonic-gate 					/* factor when required */
148*7c478bd9Sstevel@tonic-gate #define	LOWER_FDT_TRIGGER	4	/* Lower the FDT if crtt is less */
149*7c478bd9Sstevel@tonic-gate 					/* than FDT / LOWER_FDT_TRIGGER  */
150*7c478bd9Sstevel@tonic-gate #define	EXCEPTION_FACTOR	2	/* The exception target has a crtt */
151*7c478bd9Sstevel@tonic-gate 					/* greater by this factor */
152*7c478bd9Sstevel@tonic-gate 
153*7c478bd9Sstevel@tonic-gate #define	IF_SCAN_INTERVAL	20000	/* Do initifs() every 20 secs */
154*7c478bd9Sstevel@tonic-gate 
155*7c478bd9Sstevel@tonic-gate /* Return a random number from a range inclusive of the endpoints */
156*7c478bd9Sstevel@tonic-gate #define	GET_RANDOM(LOW, HIGH) (random() % ((HIGH) - (LOW) + 1) + (LOW))
157*7c478bd9Sstevel@tonic-gate 
158*7c478bd9Sstevel@tonic-gate #define	TIMER_INFINITY	0x7FFFFFFFU	/* Never time out */
159*7c478bd9Sstevel@tonic-gate 
160*7c478bd9Sstevel@tonic-gate /*
161*7c478bd9Sstevel@tonic-gate  * Comparing unsigned 32 bit time values in a circular 32-bit sequence space
162*7c478bd9Sstevel@tonic-gate  */
163*7c478bd9Sstevel@tonic-gate #define	TIME_GE(a, b)	((int32_t)((a) - (b)) >= 0)
164*7c478bd9Sstevel@tonic-gate #define	TIME_GT(a, b)	((int32_t)((a) - (b)) >  0)
165*7c478bd9Sstevel@tonic-gate #define	TIME_LT(a, b)	((int32_t)((a) - (b)) <  0)
166*7c478bd9Sstevel@tonic-gate #define	TIME_LE(a, b)	((int32_t)((a) - (b)) <= 0)
167*7c478bd9Sstevel@tonic-gate 
168*7c478bd9Sstevel@tonic-gate /*
169*7c478bd9Sstevel@tonic-gate  * Comparing unsigned 16 bit sequence numbers in a circular 16-bit
170*7c478bd9Sstevel@tonic-gate  * sequence space
171*7c478bd9Sstevel@tonic-gate  */
172*7c478bd9Sstevel@tonic-gate #define	SEQ_GE(a, b)	((int16_t)((a) - (b)) >= (int16_t)0)
173*7c478bd9Sstevel@tonic-gate #define	SEQ_GT(a, b)	((int16_t)((a) - (b)) >  (int16_t)0)
174*7c478bd9Sstevel@tonic-gate #define	SEQ_LT(a, b)	((int16_t)((a) - (b)) <  (int16_t)0)
175*7c478bd9Sstevel@tonic-gate #define	SEQ_LE(a, b)	((int16_t)((a) - (b)) <= (int16_t)0)
176*7c478bd9Sstevel@tonic-gate 
177*7c478bd9Sstevel@tonic-gate #define	AF_OTHER(af)	((af) == AF_INET ? AF_INET6 : AF_INET)
178*7c478bd9Sstevel@tonic-gate #define	AF_STR(af)	((af) == AF_INET ? "inet" : "inet6")
179*7c478bd9Sstevel@tonic-gate 
180*7c478bd9Sstevel@tonic-gate /*
181*7c478bd9Sstevel@tonic-gate  * Globals
182*7c478bd9Sstevel@tonic-gate  */
183*7c478bd9Sstevel@tonic-gate extern boolean_t failback_enabled;	/* cmd option to disable failbacks */
184*7c478bd9Sstevel@tonic-gate extern boolean_t track_all_phyints;	/* cmd option to track all phyints */
185*7c478bd9Sstevel@tonic-gate 
186*7c478bd9Sstevel@tonic-gate 					/* all times below in millisec */
187*7c478bd9Sstevel@tonic-gate extern	int	user_probe_interval;	/* interval between probes, as */
188*7c478bd9Sstevel@tonic-gate 					/* derived from user specified fdt */
189*7c478bd9Sstevel@tonic-gate extern	int	user_failure_detection_time; /* User specified fdt */
190*7c478bd9Sstevel@tonic-gate 
191*7c478bd9Sstevel@tonic-gate extern	int	ifsock_v4;		/* IPv4 socket for ioctls */
192*7c478bd9Sstevel@tonic-gate extern	int	ifsock_v6;		/* IPv6 socket for ioctls */
193*7c478bd9Sstevel@tonic-gate 
194*7c478bd9Sstevel@tonic-gate extern boolean_t full_scan_required;	/* Do full scans */
195*7c478bd9Sstevel@tonic-gate 
196*7c478bd9Sstevel@tonic-gate extern int debug;			/* debug option */
197*7c478bd9Sstevel@tonic-gate 
198*7c478bd9Sstevel@tonic-gate extern boolean_t handle_link_notifications;
199*7c478bd9Sstevel@tonic-gate 
200*7c478bd9Sstevel@tonic-gate /*
201*7c478bd9Sstevel@tonic-gate  * Function prototypes
202*7c478bd9Sstevel@tonic-gate  */
203*7c478bd9Sstevel@tonic-gate void		timer_schedule(uint_t delay);
204*7c478bd9Sstevel@tonic-gate extern void	logerr(char *fmt, ...);
205*7c478bd9Sstevel@tonic-gate extern void	logtrace(char *fmt, ...);
206*7c478bd9Sstevel@tonic-gate extern void	logdebug(char *fmt, ...);
207*7c478bd9Sstevel@tonic-gate extern void	logperror(char *str);
208*7c478bd9Sstevel@tonic-gate 
209*7c478bd9Sstevel@tonic-gate extern int	poll_add(int fd);
210*7c478bd9Sstevel@tonic-gate extern uint_t	getcurrenttime(void);
211*7c478bd9Sstevel@tonic-gate 
212*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
213*7c478bd9Sstevel@tonic-gate }
214*7c478bd9Sstevel@tonic-gate #endif
215*7c478bd9Sstevel@tonic-gate 
216*7c478bd9Sstevel@tonic-gate #endif	/* _MPD_DEFS_H */
217