10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 54262Smeem * Common Development and Distribution License (the "License"). 64262Smeem * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*8485SPeter.Memishian@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #ifndef _MPD_DEFS_H 270Sstevel@tonic-gate #define _MPD_DEFS_H 280Sstevel@tonic-gate 290Sstevel@tonic-gate #ifdef __cplusplus 300Sstevel@tonic-gate extern "C" { 310Sstevel@tonic-gate #endif 320Sstevel@tonic-gate 330Sstevel@tonic-gate #include <alloca.h> 340Sstevel@tonic-gate #include <stdio.h> 350Sstevel@tonic-gate #include <stdlib.h> 360Sstevel@tonic-gate #include <strings.h> 370Sstevel@tonic-gate #include <errno.h> 380Sstevel@tonic-gate #include <sys/types.h> 390Sstevel@tonic-gate #include <limits.h> 400Sstevel@tonic-gate #include <fcntl.h> 410Sstevel@tonic-gate #include <signal.h> 420Sstevel@tonic-gate #include <poll.h> 430Sstevel@tonic-gate #include <unistd.h> 440Sstevel@tonic-gate #include <time.h> 450Sstevel@tonic-gate #include <stdarg.h> 466578Smeem #include <syslog.h> 470Sstevel@tonic-gate 480Sstevel@tonic-gate #include <sys/param.h> 490Sstevel@tonic-gate #include <sys/socket.h> 500Sstevel@tonic-gate #include <sys/sysmacros.h> 510Sstevel@tonic-gate #include <arpa/inet.h> 520Sstevel@tonic-gate #include <netdb.h> 530Sstevel@tonic-gate 540Sstevel@tonic-gate #include <sys/ioctl.h> 550Sstevel@tonic-gate #include <sys/sockio.h> 560Sstevel@tonic-gate #include <net/if.h> 570Sstevel@tonic-gate #include <stropts.h> 580Sstevel@tonic-gate #include <sys/tihdr.h> 590Sstevel@tonic-gate #include <inet/mib2.h> 600Sstevel@tonic-gate 610Sstevel@tonic-gate #include <string.h> 620Sstevel@tonic-gate #include <ctype.h> 630Sstevel@tonic-gate 640Sstevel@tonic-gate #include <netinet/in_systm.h> 650Sstevel@tonic-gate #include <netinet/in.h> 660Sstevel@tonic-gate #include <netinet/ip.h> 670Sstevel@tonic-gate #include <netinet/ip_icmp.h> 680Sstevel@tonic-gate #include <netinet/if_ether.h> 690Sstevel@tonic-gate #include <netinet/ip6.h> 700Sstevel@tonic-gate #include <netinet/icmp6.h> 710Sstevel@tonic-gate #include <net/route.h> 720Sstevel@tonic-gate #include <net/if_dl.h> 730Sstevel@tonic-gate 740Sstevel@tonic-gate #include <inet/ip.h> 750Sstevel@tonic-gate #include <libintl.h> 760Sstevel@tonic-gate #include <locale.h> 770Sstevel@tonic-gate #include <deflt.h> 780Sstevel@tonic-gate 79*8485SPeter.Memishian@Sun.COM #include <libdlpi.h> 80*8485SPeter.Memishian@Sun.COM #include <libinetutil.h> 810Sstevel@tonic-gate #include <libnvpair.h> 820Sstevel@tonic-gate #include <libsysevent.h> 830Sstevel@tonic-gate #include <sys/sysevent.h> 840Sstevel@tonic-gate #include <sys/sysevent/eventdefs.h> 850Sstevel@tonic-gate #include <sys/sysevent/ipmp.h> 860Sstevel@tonic-gate 870Sstevel@tonic-gate #include <ipmp_mpathd.h> 880Sstevel@tonic-gate #include <ipmp_query_impl.h> 890Sstevel@tonic-gate #include <assert.h> 900Sstevel@tonic-gate 910Sstevel@tonic-gate /* Debug flags */ 920Sstevel@tonic-gate #define D_ALL 0xffff /* enable all debug */ 930Sstevel@tonic-gate #define D_PROBE 0x0001 /* probe mechanism */ 94*8485SPeter.Memishian@Sun.COM #define D_FAILREP 0x0002 /* failure/repair mechanism */ 950Sstevel@tonic-gate #define D_PHYINT 0x0004 /* phyint table */ 960Sstevel@tonic-gate #define D_LOGINT 0x0008 /* logint table */ 970Sstevel@tonic-gate #define D_TARGET 0x0010 /* target table */ 980Sstevel@tonic-gate #define D_TIMER 0x0020 /* Timer mechanism */ 990Sstevel@tonic-gate #define D_PKTBAD 0x0040 /* Malformed packet */ 1000Sstevel@tonic-gate #define D_LINKNOTE 0x0080 /* Link up/down notifications */ 1010Sstevel@tonic-gate /* 1020Sstevel@tonic-gate * Need a common header file that defines the 2 constants below. 1030Sstevel@tonic-gate * Many applications need them. 1040Sstevel@tonic-gate */ 1050Sstevel@tonic-gate #define IF_SEPARATOR ':' 1060Sstevel@tonic-gate #define IPV6_MAX_HOPS 255 1070Sstevel@tonic-gate 1080Sstevel@tonic-gate /* 1090Sstevel@tonic-gate * General parameters for phyint failure/repair detection 1100Sstevel@tonic-gate */ 1110Sstevel@tonic-gate #define NUM_PROBE_FAILS 5 /* NUM_PROBE_FAILS probe failures */ 1120Sstevel@tonic-gate /* trigger NIC failure detection */ 1130Sstevel@tonic-gate #define NUM_PROBE_REPAIRS 10 /* NUM_PROBE_REPAIRS probe repairs */ 1140Sstevel@tonic-gate /* trigger NIC repair detection */ 1150Sstevel@tonic-gate 1160Sstevel@tonic-gate #define MIN_RANDOM_FACTOR 0.5 /* Randomization factors to */ 1170Sstevel@tonic-gate #define MAX_RANDOM_FACTOR 1.0 /* determine probe send time */ 1180Sstevel@tonic-gate 1190Sstevel@tonic-gate #define MIN_PROBE_TARGETS 3 /* Minimum number of targets */ 1200Sstevel@tonic-gate #define MAX_PROBE_TARGETS 5 /* Maximum number of targets */ 1210Sstevel@tonic-gate 1220Sstevel@tonic-gate /* 1230Sstevel@tonic-gate * A target that is declared slow is usable again after MIN_RECOVERY_TIME ns 1240Sstevel@tonic-gate */ 1250Sstevel@tonic-gate #define MIN_RECOVERY_TIME (60000000000LL) /* (In ns) 60 secs */ 1260Sstevel@tonic-gate 1270Sstevel@tonic-gate /* 1280Sstevel@tonic-gate * If the Failure Detection Time (FDT) is bumped up because the target CRTT 1290Sstevel@tonic-gate * is high, it won't be reduced for the next MIN_SETTLING_TIME ns, to prevent 1300Sstevel@tonic-gate * flapping of FDT 1310Sstevel@tonic-gate */ 1320Sstevel@tonic-gate #define MIN_SETTLING_TIME (60000000000LL) /* (In ns) 60 secs */ 1330Sstevel@tonic-gate 1340Sstevel@tonic-gate /* 1354770Smeem * An admin or script might place a phyint in a group before assigning a test 1364770Smeem * address. To give them time to configure a test address, we delay whining 1374770Smeem * about it being missing for TESTADDR_CONF_TIME seconds. 1384770Smeem */ 1394770Smeem #define TESTADDR_CONF_TIME 20 1404770Smeem 1414770Smeem /* 1420Sstevel@tonic-gate * The circular probe stats array should be able to hold enough 1430Sstevel@tonic-gate * samples to detect phyint failure, target failure, phyint repair 1440Sstevel@tonic-gate * and target repair. 1450Sstevel@tonic-gate */ 1460Sstevel@tonic-gate #define PROBE_STATS_COUNT \ 1470Sstevel@tonic-gate ((uint16_t)(NUM_PROBE_REPAIRS * MAX_PROBE_TARGETS + 2)) 1480Sstevel@tonic-gate 1490Sstevel@tonic-gate #define FAILURE_DETECTION_TIME 10000 /* Default is 10 s */ 1500Sstevel@tonic-gate #define MIN_FAILURE_DETECTION_TIME 100 /* Minimum is 100 ms */ 1510Sstevel@tonic-gate #define FAILURE_DETECTION_QP 40 /* quiet period, in seconds */ 1520Sstevel@tonic-gate 1530Sstevel@tonic-gate #define NEXT_FDT_MULTIPLE 2 /* Raise or lower the FDT by this */ 1540Sstevel@tonic-gate /* factor when required */ 1550Sstevel@tonic-gate #define LOWER_FDT_TRIGGER 4 /* Lower the FDT if crtt is less */ 1560Sstevel@tonic-gate /* than FDT / LOWER_FDT_TRIGGER */ 1570Sstevel@tonic-gate #define EXCEPTION_FACTOR 2 /* The exception target has a crtt */ 1580Sstevel@tonic-gate /* greater by this factor */ 1590Sstevel@tonic-gate 1600Sstevel@tonic-gate #define IF_SCAN_INTERVAL 20000 /* Do initifs() every 20 secs */ 1610Sstevel@tonic-gate 1620Sstevel@tonic-gate /* Return a random number from a range inclusive of the endpoints */ 1630Sstevel@tonic-gate #define GET_RANDOM(LOW, HIGH) (random() % ((HIGH) - (LOW) + 1) + (LOW)) 1640Sstevel@tonic-gate 1650Sstevel@tonic-gate #define TIMER_INFINITY 0x7FFFFFFFU /* Never time out */ 1660Sstevel@tonic-gate 1670Sstevel@tonic-gate /* 1680Sstevel@tonic-gate * Comparing unsigned 32 bit time values in a circular 32-bit sequence space 1690Sstevel@tonic-gate */ 1700Sstevel@tonic-gate #define TIME_GE(a, b) ((int32_t)((a) - (b)) >= 0) 1710Sstevel@tonic-gate #define TIME_GT(a, b) ((int32_t)((a) - (b)) > 0) 1720Sstevel@tonic-gate #define TIME_LT(a, b) ((int32_t)((a) - (b)) < 0) 1730Sstevel@tonic-gate #define TIME_LE(a, b) ((int32_t)((a) - (b)) <= 0) 1740Sstevel@tonic-gate 1750Sstevel@tonic-gate /* 1760Sstevel@tonic-gate * Comparing unsigned 16 bit sequence numbers in a circular 16-bit 1770Sstevel@tonic-gate * sequence space 1780Sstevel@tonic-gate */ 1790Sstevel@tonic-gate #define SEQ_GE(a, b) ((int16_t)((a) - (b)) >= (int16_t)0) 1800Sstevel@tonic-gate #define SEQ_GT(a, b) ((int16_t)((a) - (b)) > (int16_t)0) 1810Sstevel@tonic-gate #define SEQ_LT(a, b) ((int16_t)((a) - (b)) < (int16_t)0) 1820Sstevel@tonic-gate #define SEQ_LE(a, b) ((int16_t)((a) - (b)) <= (int16_t)0) 1830Sstevel@tonic-gate 1840Sstevel@tonic-gate #define AF_OTHER(af) ((af) == AF_INET ? AF_INET6 : AF_INET) 1850Sstevel@tonic-gate #define AF_STR(af) ((af) == AF_INET ? "inet" : "inet6") 1860Sstevel@tonic-gate 1870Sstevel@tonic-gate /* 1880Sstevel@tonic-gate * Globals 1890Sstevel@tonic-gate */ 1900Sstevel@tonic-gate extern boolean_t failback_enabled; /* cmd option to disable failbacks */ 1910Sstevel@tonic-gate extern boolean_t track_all_phyints; /* cmd option to track all phyints */ 1920Sstevel@tonic-gate 1930Sstevel@tonic-gate /* all times below in millisec */ 1940Sstevel@tonic-gate extern int user_probe_interval; /* interval between probes, as */ 1950Sstevel@tonic-gate /* derived from user specified fdt */ 1960Sstevel@tonic-gate extern int user_failure_detection_time; /* User specified fdt */ 1970Sstevel@tonic-gate 1980Sstevel@tonic-gate extern int ifsock_v4; /* IPv4 socket for ioctls */ 1990Sstevel@tonic-gate extern int ifsock_v6; /* IPv6 socket for ioctls */ 2000Sstevel@tonic-gate 2010Sstevel@tonic-gate extern int debug; /* debug option */ 202*8485SPeter.Memishian@Sun.COM extern boolean_t cleanup_started; /* true if we're shutting down */ 2030Sstevel@tonic-gate extern boolean_t handle_link_notifications; 2040Sstevel@tonic-gate 2050Sstevel@tonic-gate /* 2060Sstevel@tonic-gate * Function prototypes 2070Sstevel@tonic-gate */ 2086578Smeem extern void timer_schedule(uint_t delay); 2096578Smeem extern void logmsg(int pri, const char *fmt, ...); 2106578Smeem extern void logperror(const char *str); 2110Sstevel@tonic-gate extern int poll_add(int fd); 212*8485SPeter.Memishian@Sun.COM extern int poll_remove(int fd); 2134770Smeem extern uint64_t getcurrentsec(void); 2140Sstevel@tonic-gate extern uint_t getcurrenttime(void); 2150Sstevel@tonic-gate 2166578Smeem #define logerr(...) logmsg(LOG_ERR, __VA_ARGS__) 2176578Smeem #define logtrace(...) logmsg(LOG_INFO, __VA_ARGS__) 2186578Smeem #define logdebug(...) logmsg(LOG_DEBUG, __VA_ARGS__) 2196578Smeem 2200Sstevel@tonic-gate #ifdef __cplusplus 2210Sstevel@tonic-gate } 2220Sstevel@tonic-gate #endif 2230Sstevel@tonic-gate 2240Sstevel@tonic-gate #endif /* _MPD_DEFS_H */ 225