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