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