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 /* 228485SPeter.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> 73*8865SJonathan.Anderson@Sun.COM #include <tiuser.h> 740Sstevel@tonic-gate 750Sstevel@tonic-gate #include <inet/ip.h> 760Sstevel@tonic-gate #include <libintl.h> 770Sstevel@tonic-gate #include <locale.h> 780Sstevel@tonic-gate #include <deflt.h> 790Sstevel@tonic-gate 808485SPeter.Memishian@Sun.COM #include <libdlpi.h> 818485SPeter.Memishian@Sun.COM #include <libinetutil.h> 820Sstevel@tonic-gate #include <libnvpair.h> 830Sstevel@tonic-gate #include <libsysevent.h> 840Sstevel@tonic-gate #include <sys/sysevent.h> 850Sstevel@tonic-gate #include <sys/sysevent/eventdefs.h> 860Sstevel@tonic-gate #include <sys/sysevent/ipmp.h> 870Sstevel@tonic-gate 880Sstevel@tonic-gate #include <ipmp_mpathd.h> 890Sstevel@tonic-gate #include <ipmp_query_impl.h> 900Sstevel@tonic-gate #include <assert.h> 910Sstevel@tonic-gate 920Sstevel@tonic-gate /* Debug flags */ 930Sstevel@tonic-gate #define D_ALL 0xffff /* enable all debug */ 940Sstevel@tonic-gate #define D_PROBE 0x0001 /* probe mechanism */ 958485SPeter.Memishian@Sun.COM #define D_FAILREP 0x0002 /* failure/repair mechanism */ 960Sstevel@tonic-gate #define D_PHYINT 0x0004 /* phyint table */ 970Sstevel@tonic-gate #define D_LOGINT 0x0008 /* logint table */ 980Sstevel@tonic-gate #define D_TARGET 0x0010 /* target table */ 990Sstevel@tonic-gate #define D_TIMER 0x0020 /* Timer mechanism */ 1000Sstevel@tonic-gate #define D_PKTBAD 0x0040 /* Malformed packet */ 1010Sstevel@tonic-gate #define D_LINKNOTE 0x0080 /* Link up/down notifications */ 1020Sstevel@tonic-gate /* 1030Sstevel@tonic-gate * Need a common header file that defines the 2 constants below. 1040Sstevel@tonic-gate * Many applications need them. 1050Sstevel@tonic-gate */ 1060Sstevel@tonic-gate #define IF_SEPARATOR ':' 1070Sstevel@tonic-gate #define IPV6_MAX_HOPS 255 1080Sstevel@tonic-gate 1090Sstevel@tonic-gate /* 1100Sstevel@tonic-gate * General parameters for phyint failure/repair detection 1110Sstevel@tonic-gate */ 1120Sstevel@tonic-gate #define NUM_PROBE_FAILS 5 /* NUM_PROBE_FAILS probe failures */ 1130Sstevel@tonic-gate /* trigger NIC failure detection */ 1140Sstevel@tonic-gate #define NUM_PROBE_REPAIRS 10 /* NUM_PROBE_REPAIRS probe repairs */ 1150Sstevel@tonic-gate /* trigger NIC repair detection */ 1160Sstevel@tonic-gate 1170Sstevel@tonic-gate #define MIN_RANDOM_FACTOR 0.5 /* Randomization factors to */ 1180Sstevel@tonic-gate #define MAX_RANDOM_FACTOR 1.0 /* determine probe send time */ 1190Sstevel@tonic-gate 1200Sstevel@tonic-gate #define MIN_PROBE_TARGETS 3 /* Minimum number of targets */ 1210Sstevel@tonic-gate #define MAX_PROBE_TARGETS 5 /* Maximum number of targets */ 1220Sstevel@tonic-gate 1230Sstevel@tonic-gate /* 1240Sstevel@tonic-gate * A target that is declared slow is usable again after MIN_RECOVERY_TIME ns 1250Sstevel@tonic-gate */ 1260Sstevel@tonic-gate #define MIN_RECOVERY_TIME (60000000000LL) /* (In ns) 60 secs */ 1270Sstevel@tonic-gate 1280Sstevel@tonic-gate /* 1290Sstevel@tonic-gate * If the Failure Detection Time (FDT) is bumped up because the target CRTT 1300Sstevel@tonic-gate * is high, it won't be reduced for the next MIN_SETTLING_TIME ns, to prevent 1310Sstevel@tonic-gate * flapping of FDT 1320Sstevel@tonic-gate */ 1330Sstevel@tonic-gate #define MIN_SETTLING_TIME (60000000000LL) /* (In ns) 60 secs */ 1340Sstevel@tonic-gate 1350Sstevel@tonic-gate /* 1364770Smeem * An admin or script might place a phyint in a group before assigning a test 1374770Smeem * address. To give them time to configure a test address, we delay whining 1384770Smeem * about it being missing for TESTADDR_CONF_TIME seconds. 1394770Smeem */ 1404770Smeem #define TESTADDR_CONF_TIME 20 1414770Smeem 1424770Smeem /* 1430Sstevel@tonic-gate * The circular probe stats array should be able to hold enough 1440Sstevel@tonic-gate * samples to detect phyint failure, target failure, phyint repair 1450Sstevel@tonic-gate * and target repair. 1460Sstevel@tonic-gate */ 1470Sstevel@tonic-gate #define PROBE_STATS_COUNT \ 1480Sstevel@tonic-gate ((uint16_t)(NUM_PROBE_REPAIRS * MAX_PROBE_TARGETS + 2)) 1490Sstevel@tonic-gate 1500Sstevel@tonic-gate #define FAILURE_DETECTION_TIME 10000 /* Default is 10 s */ 1510Sstevel@tonic-gate #define MIN_FAILURE_DETECTION_TIME 100 /* Minimum is 100 ms */ 1520Sstevel@tonic-gate #define FAILURE_DETECTION_QP 40 /* quiet period, in seconds */ 1530Sstevel@tonic-gate 1540Sstevel@tonic-gate #define NEXT_FDT_MULTIPLE 2 /* Raise or lower the FDT by this */ 1550Sstevel@tonic-gate /* factor when required */ 1560Sstevel@tonic-gate #define LOWER_FDT_TRIGGER 4 /* Lower the FDT if crtt is less */ 1570Sstevel@tonic-gate /* than FDT / LOWER_FDT_TRIGGER */ 1580Sstevel@tonic-gate #define EXCEPTION_FACTOR 2 /* The exception target has a crtt */ 1590Sstevel@tonic-gate /* greater by this factor */ 1600Sstevel@tonic-gate 1610Sstevel@tonic-gate #define IF_SCAN_INTERVAL 20000 /* Do initifs() every 20 secs */ 1620Sstevel@tonic-gate 1630Sstevel@tonic-gate /* Return a random number from a range inclusive of the endpoints */ 1640Sstevel@tonic-gate #define GET_RANDOM(LOW, HIGH) (random() % ((HIGH) - (LOW) + 1) + (LOW)) 1650Sstevel@tonic-gate 1660Sstevel@tonic-gate #define TIMER_INFINITY 0x7FFFFFFFU /* Never time out */ 1670Sstevel@tonic-gate 1680Sstevel@tonic-gate /* 1690Sstevel@tonic-gate * Comparing unsigned 32 bit time values in a circular 32-bit sequence space 1700Sstevel@tonic-gate */ 1710Sstevel@tonic-gate #define TIME_GE(a, b) ((int32_t)((a) - (b)) >= 0) 1720Sstevel@tonic-gate #define TIME_GT(a, b) ((int32_t)((a) - (b)) > 0) 1730Sstevel@tonic-gate #define TIME_LT(a, b) ((int32_t)((a) - (b)) < 0) 1740Sstevel@tonic-gate #define TIME_LE(a, b) ((int32_t)((a) - (b)) <= 0) 1750Sstevel@tonic-gate 1760Sstevel@tonic-gate /* 1770Sstevel@tonic-gate * Comparing unsigned 16 bit sequence numbers in a circular 16-bit 1780Sstevel@tonic-gate * sequence space 1790Sstevel@tonic-gate */ 1800Sstevel@tonic-gate #define SEQ_GE(a, b) ((int16_t)((a) - (b)) >= (int16_t)0) 1810Sstevel@tonic-gate #define SEQ_GT(a, b) ((int16_t)((a) - (b)) > (int16_t)0) 1820Sstevel@tonic-gate #define SEQ_LT(a, b) ((int16_t)((a) - (b)) < (int16_t)0) 1830Sstevel@tonic-gate #define SEQ_LE(a, b) ((int16_t)((a) - (b)) <= (int16_t)0) 1840Sstevel@tonic-gate 1850Sstevel@tonic-gate #define AF_OTHER(af) ((af) == AF_INET ? AF_INET6 : AF_INET) 1860Sstevel@tonic-gate #define AF_STR(af) ((af) == AF_INET ? "inet" : "inet6") 1870Sstevel@tonic-gate 1880Sstevel@tonic-gate /* 1890Sstevel@tonic-gate * Globals 1900Sstevel@tonic-gate */ 1910Sstevel@tonic-gate extern boolean_t failback_enabled; /* cmd option to disable failbacks */ 1920Sstevel@tonic-gate extern boolean_t track_all_phyints; /* cmd option to track all phyints */ 1930Sstevel@tonic-gate 1940Sstevel@tonic-gate /* all times below in millisec */ 1950Sstevel@tonic-gate extern int user_probe_interval; /* interval between probes, as */ 1960Sstevel@tonic-gate /* derived from user specified fdt */ 1970Sstevel@tonic-gate extern int user_failure_detection_time; /* User specified fdt */ 1980Sstevel@tonic-gate 1990Sstevel@tonic-gate extern int ifsock_v4; /* IPv4 socket for ioctls */ 2000Sstevel@tonic-gate extern int ifsock_v6; /* IPv6 socket for ioctls */ 2010Sstevel@tonic-gate 2020Sstevel@tonic-gate extern int debug; /* debug option */ 2038485SPeter.Memishian@Sun.COM extern boolean_t cleanup_started; /* true if we're shutting down */ 2040Sstevel@tonic-gate extern boolean_t handle_link_notifications; 2050Sstevel@tonic-gate 2060Sstevel@tonic-gate /* 2070Sstevel@tonic-gate * Function prototypes 2080Sstevel@tonic-gate */ 2096578Smeem extern void timer_schedule(uint_t delay); 2106578Smeem extern void logmsg(int pri, const char *fmt, ...); 2116578Smeem extern void logperror(const char *str); 2120Sstevel@tonic-gate extern int poll_add(int fd); 2138485SPeter.Memishian@Sun.COM extern int poll_remove(int fd); 2144770Smeem extern uint64_t getcurrentsec(void); 2150Sstevel@tonic-gate extern uint_t getcurrenttime(void); 2160Sstevel@tonic-gate 2176578Smeem #define logerr(...) logmsg(LOG_ERR, __VA_ARGS__) 2186578Smeem #define logtrace(...) logmsg(LOG_INFO, __VA_ARGS__) 2196578Smeem #define logdebug(...) logmsg(LOG_DEBUG, __VA_ARGS__) 2206578Smeem 2210Sstevel@tonic-gate #ifdef __cplusplus 2220Sstevel@tonic-gate } 2230Sstevel@tonic-gate #endif 2240Sstevel@tonic-gate 2250Sstevel@tonic-gate #endif /* _MPD_DEFS_H */ 226