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