17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5d8233146Smeem  * Common Development and Distribution License (the "License").
6d8233146Smeem  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22e11c3f44Smeem  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef	_MPD_DEFS_H
277c478bd9Sstevel@tonic-gate #define	_MPD_DEFS_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
307c478bd9Sstevel@tonic-gate extern "C" {
317c478bd9Sstevel@tonic-gate #endif
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #include <alloca.h>
347c478bd9Sstevel@tonic-gate #include <stdio.h>
357c478bd9Sstevel@tonic-gate #include <stdlib.h>
367c478bd9Sstevel@tonic-gate #include <strings.h>
377c478bd9Sstevel@tonic-gate #include <errno.h>
387c478bd9Sstevel@tonic-gate #include <sys/types.h>
397c478bd9Sstevel@tonic-gate #include <limits.h>
407c478bd9Sstevel@tonic-gate #include <fcntl.h>
417c478bd9Sstevel@tonic-gate #include <signal.h>
427c478bd9Sstevel@tonic-gate #include <poll.h>
437c478bd9Sstevel@tonic-gate #include <unistd.h>
447c478bd9Sstevel@tonic-gate #include <time.h>
457c478bd9Sstevel@tonic-gate #include <stdarg.h>
46e3e7cd29Smeem #include <syslog.h>
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate #include <sys/param.h>
497c478bd9Sstevel@tonic-gate #include <sys/socket.h>
507c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
517c478bd9Sstevel@tonic-gate #include <arpa/inet.h>
527c478bd9Sstevel@tonic-gate #include <netdb.h>
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate #include <sys/ioctl.h>
557c478bd9Sstevel@tonic-gate #include <sys/sockio.h>
567c478bd9Sstevel@tonic-gate #include <net/if.h>
577c478bd9Sstevel@tonic-gate #include <stropts.h>
587c478bd9Sstevel@tonic-gate #include <sys/tihdr.h>
597c478bd9Sstevel@tonic-gate #include <inet/mib2.h>
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate #include <string.h>
627c478bd9Sstevel@tonic-gate #include <ctype.h>
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate #include <netinet/in_systm.h>
657c478bd9Sstevel@tonic-gate #include <netinet/in.h>
667c478bd9Sstevel@tonic-gate #include <netinet/ip.h>
677c478bd9Sstevel@tonic-gate #include <netinet/ip_icmp.h>
687c478bd9Sstevel@tonic-gate #include <netinet/if_ether.h>
697c478bd9Sstevel@tonic-gate #include <netinet/ip6.h>
707c478bd9Sstevel@tonic-gate #include <netinet/icmp6.h>
717c478bd9Sstevel@tonic-gate #include <net/route.h>
727c478bd9Sstevel@tonic-gate #include <net/if_dl.h>
73*27438c18SJon Anderson #include <tiuser.h>
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate #include <inet/ip.h>
767c478bd9Sstevel@tonic-gate #include <libintl.h>
777c478bd9Sstevel@tonic-gate #include <locale.h>
787c478bd9Sstevel@tonic-gate #include <deflt.h>
797c478bd9Sstevel@tonic-gate 
80e11c3f44Smeem #include <libdlpi.h>
81e11c3f44Smeem #include <libinetutil.h>
827c478bd9Sstevel@tonic-gate #include <libnvpair.h>
837c478bd9Sstevel@tonic-gate #include <libsysevent.h>
847c478bd9Sstevel@tonic-gate #include <sys/sysevent.h>
857c478bd9Sstevel@tonic-gate #include <sys/sysevent/eventdefs.h>
867c478bd9Sstevel@tonic-gate #include <sys/sysevent/ipmp.h>
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate #include <ipmp_mpathd.h>
897c478bd9Sstevel@tonic-gate #include <ipmp_query_impl.h>
907c478bd9Sstevel@tonic-gate #include <assert.h>
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate /* Debug flags */
937c478bd9Sstevel@tonic-gate #define	D_ALL		0xffff		/* enable all debug */
947c478bd9Sstevel@tonic-gate #define	D_PROBE		0x0001		/* probe mechanism */
95e11c3f44Smeem #define	D_FAILREP	0x0002		/* failure/repair mechanism */
967c478bd9Sstevel@tonic-gate #define	D_PHYINT	0x0004		/* phyint table */
977c478bd9Sstevel@tonic-gate #define	D_LOGINT	0x0008		/* logint table */
987c478bd9Sstevel@tonic-gate #define	D_TARGET	0x0010		/* target table */
997c478bd9Sstevel@tonic-gate #define	D_TIMER		0x0020		/* Timer mechanism */
1007c478bd9Sstevel@tonic-gate #define	D_PKTBAD	0x0040		/* Malformed packet */
1017c478bd9Sstevel@tonic-gate #define	D_LINKNOTE	0x0080		/* Link up/down notifications */
1027c478bd9Sstevel@tonic-gate /*
1037c478bd9Sstevel@tonic-gate  * Need a common header file that defines the 2 constants below.
1047c478bd9Sstevel@tonic-gate  * Many applications need them.
1057c478bd9Sstevel@tonic-gate  */
1067c478bd9Sstevel@tonic-gate #define	IF_SEPARATOR		':'
1077c478bd9Sstevel@tonic-gate #define	IPV6_MAX_HOPS		255
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate /*
1107c478bd9Sstevel@tonic-gate  * General parameters for phyint failure/repair detection
1117c478bd9Sstevel@tonic-gate  */
1127c478bd9Sstevel@tonic-gate #define	NUM_PROBE_FAILS		5	/* NUM_PROBE_FAILS probe failures */
1137c478bd9Sstevel@tonic-gate 					/* trigger NIC failure detection */
1147c478bd9Sstevel@tonic-gate #define	NUM_PROBE_REPAIRS	10	/* NUM_PROBE_REPAIRS probe repairs */
1157c478bd9Sstevel@tonic-gate 					/* trigger NIC repair detection */
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate #define	MIN_RANDOM_FACTOR	0.5	/* Randomization factors to */
1187c478bd9Sstevel@tonic-gate #define	MAX_RANDOM_FACTOR	1.0	/* determine probe send time */
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate #define	MIN_PROBE_TARGETS	3	/* Minimum number of targets */
1217c478bd9Sstevel@tonic-gate #define	MAX_PROBE_TARGETS	5	/* Maximum number of targets */
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate /*
1247c478bd9Sstevel@tonic-gate  * A target that is declared slow is usable again after MIN_RECOVERY_TIME ns
1257c478bd9Sstevel@tonic-gate  */
1267c478bd9Sstevel@tonic-gate #define	MIN_RECOVERY_TIME	(60000000000LL) /* (In ns) 60 secs */
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate /*
1297c478bd9Sstevel@tonic-gate  * If the Failure Detection Time (FDT) is bumped up because the target CRTT
1307c478bd9Sstevel@tonic-gate  * is high, it won't be reduced for the next MIN_SETTLING_TIME ns, to prevent
1317c478bd9Sstevel@tonic-gate  * flapping of FDT
1327c478bd9Sstevel@tonic-gate  */
1337c478bd9Sstevel@tonic-gate #define	MIN_SETTLING_TIME	(60000000000LL) /* (In ns) 60 secs */
1347c478bd9Sstevel@tonic-gate 
135e6ed03fcSmeem /*
136e6ed03fcSmeem  * An admin or script might place a phyint in a group before assigning a test
137e6ed03fcSmeem  * address.  To give them time to configure a test address, we delay whining
138e6ed03fcSmeem  * about it being missing for TESTADDR_CONF_TIME seconds.
139e6ed03fcSmeem  */
140e6ed03fcSmeem #define	TESTADDR_CONF_TIME	20
141e6ed03fcSmeem 
1427c478bd9Sstevel@tonic-gate /*
1437c478bd9Sstevel@tonic-gate  * The circular probe stats array should be able to hold enough
1447c478bd9Sstevel@tonic-gate  * samples to detect phyint failure, target failure, phyint repair
1457c478bd9Sstevel@tonic-gate  * and target repair.
1467c478bd9Sstevel@tonic-gate  */
1477c478bd9Sstevel@tonic-gate #define	PROBE_STATS_COUNT	\
1487c478bd9Sstevel@tonic-gate 	((uint16_t)(NUM_PROBE_REPAIRS * MAX_PROBE_TARGETS + 2))
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate #define	FAILURE_DETECTION_TIME	10000	/* Default is 10 s */
1517c478bd9Sstevel@tonic-gate #define	MIN_FAILURE_DETECTION_TIME	100	/* Minimum is 100 ms */
1527c478bd9Sstevel@tonic-gate #define	FAILURE_DETECTION_QP	40	/* quiet period, in seconds */
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate #define	NEXT_FDT_MULTIPLE	2	/* Raise or lower the FDT by this */
1557c478bd9Sstevel@tonic-gate 					/* factor when required */
1567c478bd9Sstevel@tonic-gate #define	LOWER_FDT_TRIGGER	4	/* Lower the FDT if crtt is less */
1577c478bd9Sstevel@tonic-gate 					/* than FDT / LOWER_FDT_TRIGGER  */
1587c478bd9Sstevel@tonic-gate #define	EXCEPTION_FACTOR	2	/* The exception target has a crtt */
1597c478bd9Sstevel@tonic-gate 					/* greater by this factor */
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate #define	IF_SCAN_INTERVAL	20000	/* Do initifs() every 20 secs */
1627c478bd9Sstevel@tonic-gate 
1637c478bd9Sstevel@tonic-gate /* Return a random number from a range inclusive of the endpoints */
1647c478bd9Sstevel@tonic-gate #define	GET_RANDOM(LOW, HIGH) (random() % ((HIGH) - (LOW) + 1) + (LOW))
1657c478bd9Sstevel@tonic-gate 
1667c478bd9Sstevel@tonic-gate #define	TIMER_INFINITY	0x7FFFFFFFU	/* Never time out */
1677c478bd9Sstevel@tonic-gate 
1687c478bd9Sstevel@tonic-gate /*
1697c478bd9Sstevel@tonic-gate  * Comparing unsigned 32 bit time values in a circular 32-bit sequence space
1707c478bd9Sstevel@tonic-gate  */
1717c478bd9Sstevel@tonic-gate #define	TIME_GE(a, b)	((int32_t)((a) - (b)) >= 0)
1727c478bd9Sstevel@tonic-gate #define	TIME_GT(a, b)	((int32_t)((a) - (b)) >  0)
1737c478bd9Sstevel@tonic-gate #define	TIME_LT(a, b)	((int32_t)((a) - (b)) <  0)
1747c478bd9Sstevel@tonic-gate #define	TIME_LE(a, b)	((int32_t)((a) - (b)) <= 0)
1757c478bd9Sstevel@tonic-gate 
1767c478bd9Sstevel@tonic-gate /*
1777c478bd9Sstevel@tonic-gate  * Comparing unsigned 16 bit sequence numbers in a circular 16-bit
1787c478bd9Sstevel@tonic-gate  * sequence space
1797c478bd9Sstevel@tonic-gate  */
1807c478bd9Sstevel@tonic-gate #define	SEQ_GE(a, b)	((int16_t)((a) - (b)) >= (int16_t)0)
1817c478bd9Sstevel@tonic-gate #define	SEQ_GT(a, b)	((int16_t)((a) - (b)) >  (int16_t)0)
1827c478bd9Sstevel@tonic-gate #define	SEQ_LT(a, b)	((int16_t)((a) - (b)) <  (int16_t)0)
1837c478bd9Sstevel@tonic-gate #define	SEQ_LE(a, b)	((int16_t)((a) - (b)) <= (int16_t)0)
1847c478bd9Sstevel@tonic-gate 
1857c478bd9Sstevel@tonic-gate #define	AF_OTHER(af)	((af) == AF_INET ? AF_INET6 : AF_INET)
1867c478bd9Sstevel@tonic-gate #define	AF_STR(af)	((af) == AF_INET ? "inet" : "inet6")
1877c478bd9Sstevel@tonic-gate 
1887c478bd9Sstevel@tonic-gate /*
1897c478bd9Sstevel@tonic-gate  * Globals
1907c478bd9Sstevel@tonic-gate  */
1917c478bd9Sstevel@tonic-gate extern boolean_t failback_enabled;	/* cmd option to disable failbacks */
1927c478bd9Sstevel@tonic-gate extern boolean_t track_all_phyints;	/* cmd option to track all phyints */
1937c478bd9Sstevel@tonic-gate 
1947c478bd9Sstevel@tonic-gate 					/* all times below in millisec */
1957c478bd9Sstevel@tonic-gate extern	int	user_probe_interval;	/* interval between probes, as */
1967c478bd9Sstevel@tonic-gate 					/* derived from user specified fdt */
1977c478bd9Sstevel@tonic-gate extern	int	user_failure_detection_time; /* User specified fdt */
1987c478bd9Sstevel@tonic-gate 
1997c478bd9Sstevel@tonic-gate extern	int	ifsock_v4;		/* IPv4 socket for ioctls */
2007c478bd9Sstevel@tonic-gate extern	int	ifsock_v6;		/* IPv6 socket for ioctls */
2017c478bd9Sstevel@tonic-gate 
2027c478bd9Sstevel@tonic-gate extern int debug;			/* debug option */
203e11c3f44Smeem extern boolean_t cleanup_started;	/* true if we're shutting down */
2047c478bd9Sstevel@tonic-gate extern boolean_t handle_link_notifications;
2057c478bd9Sstevel@tonic-gate 
2067c478bd9Sstevel@tonic-gate /*
2077c478bd9Sstevel@tonic-gate  * Function prototypes
2087c478bd9Sstevel@tonic-gate  */
209e3e7cd29Smeem extern void	timer_schedule(uint_t delay);
210e3e7cd29Smeem extern void	logmsg(int pri, const char *fmt, ...);
211e3e7cd29Smeem extern void	logperror(const char *str);
2127c478bd9Sstevel@tonic-gate extern int	poll_add(int fd);
213e11c3f44Smeem extern int	poll_remove(int fd);
214e6ed03fcSmeem extern uint64_t	getcurrentsec(void);
2157c478bd9Sstevel@tonic-gate extern uint_t	getcurrenttime(void);
2167c478bd9Sstevel@tonic-gate 
217e3e7cd29Smeem #define	logerr(...)	logmsg(LOG_ERR, __VA_ARGS__)
218e3e7cd29Smeem #define	logtrace(...)	logmsg(LOG_INFO, __VA_ARGS__)
219e3e7cd29Smeem #define	logdebug(...)	logmsg(LOG_DEBUG, __VA_ARGS__)
220e3e7cd29Smeem 
2217c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
2227c478bd9Sstevel@tonic-gate }
2237c478bd9Sstevel@tonic-gate #endif
2247c478bd9Sstevel@tonic-gate 
2257c478bd9Sstevel@tonic-gate #endif	/* _MPD_DEFS_H */
226