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
5921e7e07Smeem  * Common Development and Distribution License (the "License").
6921e7e07Smeem  * 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 /*
22*e11c3f44Smeem  * 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_TABLES_H
277c478bd9Sstevel@tonic-gate #define	_MPD_TABLES_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
307c478bd9Sstevel@tonic-gate extern "C" {
317c478bd9Sstevel@tonic-gate #endif
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate /*
347c478bd9Sstevel@tonic-gate  * Terminology:
357c478bd9Sstevel@tonic-gate  *
367c478bd9Sstevel@tonic-gate  * phyint: A NIC eg. hme0. This is represented as 'struct phyint'
377c478bd9Sstevel@tonic-gate  *
387c478bd9Sstevel@tonic-gate  * phyint instance: A protocol instance of a phyint. Eg. the IPv4 instance of
397c478bd9Sstevel@tonic-gate  * 	hme0 or the IPv6 instance of hme0. (struct phyint_instance)
407c478bd9Sstevel@tonic-gate  *
417c478bd9Sstevel@tonic-gate  * logint: A logical interface eg. hme0:1 (struct logint)
427c478bd9Sstevel@tonic-gate  *
437c478bd9Sstevel@tonic-gate  * phyint_group: A group of phyints i.e. physical interfaces that are
447c478bd9Sstevel@tonic-gate  *	(i) connected to the same level 2 topology e.g. the same ethernet
457c478bd9Sstevel@tonic-gate  *	    switch AND
467c478bd9Sstevel@tonic-gate  *	(ii) share the same phyint group name.
477c478bd9Sstevel@tonic-gate  * Load spreading and failover occur across members of the same phyint group.
48*e11c3f44Smeem  * phyint group members must be homogeneous. i.e. if a phyint belonging to a
497c478bd9Sstevel@tonic-gate  * phyint group has a IPv6 protocol instance, then all members of the phyint
507c478bd9Sstevel@tonic-gate  * group, must have IPv6 protocol instances. (struct phyint_group)
517c478bd9Sstevel@tonic-gate  */
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate #define	MAXDEFERREDRTT		1	/* Maximum number of deferred rtts */
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate /*
567c478bd9Sstevel@tonic-gate  * Status of the phyint, expressed by the return code of failure_state()
577c478bd9Sstevel@tonic-gate  */
587c478bd9Sstevel@tonic-gate #define	PHYINT_OK	0		/* No failure detected */
597c478bd9Sstevel@tonic-gate #define	PHYINT_FAILURE	1		/* NIC failure detected */
607c478bd9Sstevel@tonic-gate #define	GROUP_FAILURE	2		/* All NICs have failed */
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate /*
637c478bd9Sstevel@tonic-gate  * Return values of phyint_inst_update_from_k()
647c478bd9Sstevel@tonic-gate  */
657c478bd9Sstevel@tonic-gate #define	PI_OK			1	/* Phyint matches in the kernel */
667c478bd9Sstevel@tonic-gate #define	PI_DELETED		2	/* Phyint has vanished in the kernel */
677c478bd9Sstevel@tonic-gate #define	PI_IFINDEX_CHANGED	3	/* Phyint's ifindex has changed */
687c478bd9Sstevel@tonic-gate #define	PI_IOCTL_ERROR		4	/* Some ioctl error */
697c478bd9Sstevel@tonic-gate #define	PI_GROUP_CHANGED	5	/* The phyint has changed group. */
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate #define	PHYINT_FLAGS(flags)	\
72*e11c3f44Smeem 	(((flags) & (IFF_STANDBY | IFF_INACTIVE | IFF_FAILED | IFF_OFFLINE | \
73*e11c3f44Smeem 	IFF_RUNNING)) | (handle_link_notifications ? 0 : IFF_RUNNING))
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate /* A Phyint can have up to 2 instances, the IPv4 and the IPv6 instance */
767c478bd9Sstevel@tonic-gate #define	PHYINT_INSTANCE(pi, af)	\
777c478bd9Sstevel@tonic-gate 	((af) == AF_INET ? (pi)->pi_v4 : (pi)->pi_v6)
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate /*
8006cdd167Smeem  * A phyint instance is probe *enabled* if it has been configured with a
8106cdd167Smeem  * unique probe address (i.e., an IFF_NOFAILOVER address).  It is probe
8206cdd167Smeem  * *capable* if it is also able to send probes (i.e., has one or more
8306cdd167Smeem  * targets available).
847c478bd9Sstevel@tonic-gate  */
857c478bd9Sstevel@tonic-gate #define	PROBE_ENABLED(pii) \
8606cdd167Smeem 	(((pii) != NULL) && ((pii)->pii_probe_sock != -1) &&	\
8706cdd167Smeem 	((pii)->pii_probe_logint != NULL) &&			\
8806cdd167Smeem 	(((pii)->pii_probe_logint->li_dupaddr == 0)))
897c478bd9Sstevel@tonic-gate 
907c478bd9Sstevel@tonic-gate #define	PROBE_CAPABLE(pii) \
917c478bd9Sstevel@tonic-gate 	(PROBE_ENABLED(pii) && ((pii)->pii_ntargets != 0))
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate /* Subtract b from a modulo n. i.e. (a - b) mod n  */
947c478bd9Sstevel@tonic-gate #define	MOD_SUB(a, b, n)	\
957c478bd9Sstevel@tonic-gate 	((((a) + (n)) - (b)) % (n))
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate /* Increment modulo n */
987c478bd9Sstevel@tonic-gate #define	MOD_INCR(a, n)		\
997c478bd9Sstevel@tonic-gate 	(((a) + 1) % (n))
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate /* Decrement modulo n */
1027c478bd9Sstevel@tonic-gate #define	MOD_DCR(a, n)		\
1037c478bd9Sstevel@tonic-gate 	MOD_SUB(a, 1, n)
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate /*
1067c478bd9Sstevel@tonic-gate  * 'index' represents an index into the circular probe stats array of
1077c478bd9Sstevel@tonic-gate  * size PROBE_STATS_COUNT.  0 <= index < PROBE_STATS_COUNT. This is used
1087c478bd9Sstevel@tonic-gate  * to access members of the pii_probes[] array defined in the phyint_instance
1097c478bd9Sstevel@tonic-gate  * structure.
1107c478bd9Sstevel@tonic-gate  */
1117c478bd9Sstevel@tonic-gate #define	PROBE_INDEX_PREV(index)	\
1127c478bd9Sstevel@tonic-gate 	MOD_DCR(index, PROBE_STATS_COUNT)
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate #define	PROBE_INDEX_NEXT(index)	\
1157c478bd9Sstevel@tonic-gate 	MOD_INCR(index, PROBE_STATS_COUNT)
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate /*
1197c478bd9Sstevel@tonic-gate  * If we receive more than LINK_UP_PERMIN "link up" notifications in a minute,
1207c478bd9Sstevel@tonic-gate  * then don't actually perform the repair operation until we've dropped back
1217c478bd9Sstevel@tonic-gate  * below the threshold (or we have a probe address and our probes indicate
1227c478bd9Sstevel@tonic-gate  * that the link is functioning again).  This is to prevent link flapping in
1237c478bd9Sstevel@tonic-gate  * the case where we don't have a probe address.
1247c478bd9Sstevel@tonic-gate  */
1257c478bd9Sstevel@tonic-gate #define	LINK_UP_PERMIN	2
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate #define	LINK_DOWN(pi) ((pi)->pi_link_state == 0)
1287c478bd9Sstevel@tonic-gate #define	LINK_UP(pi) (!LINK_DOWN(pi))
1297c478bd9Sstevel@tonic-gate #define	FLAGS_TO_LINK_STATE(pi) (((pi)->pi_flags & IFF_RUNNING) != 0)
1307c478bd9Sstevel@tonic-gate #define	UPDATE_LINK_STATE(pi) ((pi)->pi_link_state = \
1317c478bd9Sstevel@tonic-gate 	FLAGS_TO_LINK_STATE(pi) ? 1 : 0)
1327c478bd9Sstevel@tonic-gate #define	INIT_LINK_STATE(pi) ((pi)->pi_link_state = 1)
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate /*
1357c478bd9Sstevel@tonic-gate  * Phyint group states; see below for the phyint group definition.
1367c478bd9Sstevel@tonic-gate  */
1377c478bd9Sstevel@tonic-gate enum pg_state {
138*e11c3f44Smeem 	PG_OK = 1,	/* all interfaces in the group are working */
139*e11c3f44Smeem 	PG_DEGRADED,	/* some interfaces in the group are unusable */
140*e11c3f44Smeem 	PG_FAILED	/* all interfaces in the group are unusable */
1417c478bd9Sstevel@tonic-gate };
1427c478bd9Sstevel@tonic-gate 
1437c478bd9Sstevel@tonic-gate /*
1447c478bd9Sstevel@tonic-gate  * Convenience macro to check if the whole group has failed.
1457c478bd9Sstevel@tonic-gate  */
146*e11c3f44Smeem #define	GROUP_FAILED(pg)	((pg)->pg_state == PG_FAILED)
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate /*
1497c478bd9Sstevel@tonic-gate  * A doubly linked list of all phyint groups in the system.
1507c478bd9Sstevel@tonic-gate  * A phyint group is identified by its group name.
1517c478bd9Sstevel@tonic-gate  */
1527c478bd9Sstevel@tonic-gate struct phyint_group {
153*e11c3f44Smeem 	char pg_name[LIFGRNAMSIZ];	/* Phyint group name */
1547c478bd9Sstevel@tonic-gate 	struct phyint *pg_phyint;	/* List of phyints in this group */
1557c478bd9Sstevel@tonic-gate 	struct phyint_group *pg_next;	/* Next phyint group */
1567c478bd9Sstevel@tonic-gate 	struct phyint_group *pg_prev;	/* Prev phyint group */
157*e11c3f44Smeem 	uint64_t 	pg_sig;		/* Current signature of this group */
158*e11c3f44Smeem 	int		pg_probeint;	/* Interval between probes */
159*e11c3f44Smeem 	int		pg_fdt;		/* Time needed to detect failure */
160*e11c3f44Smeem 	enum pg_state	pg_state;	/* Current group state */
161*e11c3f44Smeem 	boolean_t	pg_in_use;	/* To detect removed groups */
162*e11c3f44Smeem 	struct addrlist	*pg_addrs;	/* Data addresses in this group */
163*e11c3f44Smeem 	boolean_t pg_failmsg_printed;	/* Group failure msg printed */
1647c478bd9Sstevel@tonic-gate };
1657c478bd9Sstevel@tonic-gate 
1667c478bd9Sstevel@tonic-gate /*
1677c478bd9Sstevel@tonic-gate  * Phyint states; see below for the phyint definition.
1687c478bd9Sstevel@tonic-gate  */
1697c478bd9Sstevel@tonic-gate enum pi_state {
1707c478bd9Sstevel@tonic-gate 	PI_NOTARGETS	= 1,	/* Phyint has no targets */
1717c478bd9Sstevel@tonic-gate 	PI_RUNNING	= 2,	/* Phyint is functioning */
1727c478bd9Sstevel@tonic-gate 	PI_FAILED	= 3,	/* Phyint is failed */
1737c478bd9Sstevel@tonic-gate 	PI_OFFLINE	= 4	/* Phyint is offline */
1747c478bd9Sstevel@tonic-gate };
1757c478bd9Sstevel@tonic-gate 
1767c478bd9Sstevel@tonic-gate /*
1777c478bd9Sstevel@tonic-gate  * Representation of a NIC or a phyint. There is a list of all known phyints.
1787c478bd9Sstevel@tonic-gate  * There is also a list of phyints belonging to a phyint group, one list
1797c478bd9Sstevel@tonic-gate  * per phyint group.
1807c478bd9Sstevel@tonic-gate  */
1817c478bd9Sstevel@tonic-gate struct phyint {
1827c478bd9Sstevel@tonic-gate 	char	pi_name[LIFNAMSIZ + 1]; /* Phyint name eg. le0 */
1837c478bd9Sstevel@tonic-gate 	struct phyint_instance *pi_v4;	/* The IPv4 instance */
1847c478bd9Sstevel@tonic-gate 	struct phyint_instance *pi_v6;	/* The IPv6 instance */
1857c478bd9Sstevel@tonic-gate 	struct phyint_group *pi_group;	/* Pointer to the group */
1867c478bd9Sstevel@tonic-gate 	struct phyint	*pi_next;	/* List of all phyints */
1877c478bd9Sstevel@tonic-gate 	struct phyint	*pi_prev;	/* List of all phyints */
1887c478bd9Sstevel@tonic-gate 	struct phyint	*pi_pgnext;	/* List of phyints in this group */
1897c478bd9Sstevel@tonic-gate 	struct phyint	*pi_pgprev;	/* List of phyints in this group */
1907c478bd9Sstevel@tonic-gate 	uint_t		pi_ifindex;	/* interface index */
1917c478bd9Sstevel@tonic-gate 	enum pi_state	pi_state;	/* State of the phyint */
1927c478bd9Sstevel@tonic-gate 	uint64_t	pi_flags;	/* Phyint flags from kernel */
1937c478bd9Sstevel@tonic-gate 	uint16_t	pi_icmpid;	/* icmp id in icmp echo request */
194e6ed03fcSmeem 	uint64_t	pi_taddrthresh;	/* time (in secs) to delay logging */
195e6ed03fcSmeem 					/* about missing test addresses */
196*e11c3f44Smeem 	dlpi_handle_t	pi_dh;		/* DLPI handle to underlying link */
197*e11c3f44Smeem 	uint_t		pi_notes; 	/* enabled DLPI notifications */
198*e11c3f44Smeem 	uchar_t		pi_hwaddr[DLPI_PHYSADDR_MAX]; /* phyint's hw address */
199*e11c3f44Smeem 	size_t		pi_hwaddrlen;	/* phyint's hw address length */
200*e11c3f44Smeem 
2017c478bd9Sstevel@tonic-gate 	/*
2027c478bd9Sstevel@tonic-gate 	 * The pi_whenup array is a circular buffer of the most recent
2037c478bd9Sstevel@tonic-gate 	 * times (in milliseconds since some arbitrary point of time in
2047c478bd9Sstevel@tonic-gate 	 * the past) that the interface was brought up; pi_whendx identifies
2057c478bd9Sstevel@tonic-gate 	 * the oldest element of the array.
2067c478bd9Sstevel@tonic-gate 	 */
2077c478bd9Sstevel@tonic-gate 	uint_t		pi_whenup[LINK_UP_PERMIN];
2087c478bd9Sstevel@tonic-gate 	unsigned int	pi_whendx;
2097c478bd9Sstevel@tonic-gate 
2107c478bd9Sstevel@tonic-gate 	uint_t
2117c478bd9Sstevel@tonic-gate 		pi_taddrmsg_printed : 1,	/* testaddr msg printed */
212e6ed03fcSmeem 		pi_duptaddrmsg_printed : 1,	/* dup testaddr msg printed */
2137c478bd9Sstevel@tonic-gate 		pi_cfgmsg_printed : 1,	/* bad config msg printed */
2147c478bd9Sstevel@tonic-gate 		pi_lfmsg_printed : 1,   /* link-flapping msg printed */
215*e11c3f44Smeem 		pi_link_state : 1,	/* interface link state */
216*e11c3f44Smeem 		pi_hwaddrdup : 1; 	/* disabled due to dup hw address */
2177c478bd9Sstevel@tonic-gate };
2187c478bd9Sstevel@tonic-gate 
2197c478bd9Sstevel@tonic-gate /*
2207c478bd9Sstevel@tonic-gate  * A doubly linked list of all phyint_instances each of which contains a
2217c478bd9Sstevel@tonic-gate  * doubly linked list of logical interfaces and targets. For eg. if both
2227c478bd9Sstevel@tonic-gate  * IPv4 and IPv6 are used over hme0, we have 2 phyint instances, 1 for each
2237c478bd9Sstevel@tonic-gate  * protocol.
2247c478bd9Sstevel@tonic-gate  */
2257c478bd9Sstevel@tonic-gate struct phyint_instance {
2267c478bd9Sstevel@tonic-gate 	struct phyint_instance	*pii_next;	/* List of all phyint insts */
2277c478bd9Sstevel@tonic-gate 	struct phyint_instance	*pii_prev;	/* List of all phyint insts */
2287c478bd9Sstevel@tonic-gate 
2297c478bd9Sstevel@tonic-gate 	struct phyint	*pii_phyint;	/* Back pointer to the phyint */
2307c478bd9Sstevel@tonic-gate 	struct target	*pii_targets;	/* List of targets on this link */
2317c478bd9Sstevel@tonic-gate 	struct logint	*pii_probe_logint; /* IFF_NOFAILOVER addr for probing */
2327c478bd9Sstevel@tonic-gate 	struct logint	*pii_logint;	/* Doubly linked list of logical ifs */
2337c478bd9Sstevel@tonic-gate 
2347c478bd9Sstevel@tonic-gate 	int	pii_probe_sock;		/* Socket for ICMP Probe packets */
2357c478bd9Sstevel@tonic-gate 	int	pii_af;			/* Address family */
2367c478bd9Sstevel@tonic-gate 	uint16_t pii_rack;		/* highest acknowledged seq number */
2377c478bd9Sstevel@tonic-gate 	uint16_t pii_snxt;		/* sequence number of next probe */
2387c478bd9Sstevel@tonic-gate 	uint_t	pii_snxt_time;		/* actual next probe time that */
2397c478bd9Sstevel@tonic-gate 					/* includes some randomness */
2407c478bd9Sstevel@tonic-gate 
2417c478bd9Sstevel@tonic-gate 	uint_t	pii_snxt_basetime; 	/* strictly periodic base probe time */
2427c478bd9Sstevel@tonic-gate 					/* for all periodic probes */
2437c478bd9Sstevel@tonic-gate 	uint_t	pii_fd_snxt_basetime; 	/* strictly periodic base probe time */
2447c478bd9Sstevel@tonic-gate 					/* for failure detection probes */
2457c478bd9Sstevel@tonic-gate 
2467c478bd9Sstevel@tonic-gate 	hrtime_t 	pii_fd_hrtime;	/* hrtime_t before which we should */
2477c478bd9Sstevel@tonic-gate 					/* not send probes out this pii */
2487c478bd9Sstevel@tonic-gate 
2497c478bd9Sstevel@tonic-gate 	uint64_t	pii_flags;	/* Phyint flags from kernel */
2507c478bd9Sstevel@tonic-gate 
2517c478bd9Sstevel@tonic-gate 	struct probe_stats {
252*e11c3f44Smeem 		uint_t		pr_id;		/* Full ID of probe */
253*e11c3f44Smeem 		struct target	*pr_target;	/* Probe Target */
254*e11c3f44Smeem 		uint_t		pr_time_lost; 	/* Time probe declared lost */
255*e11c3f44Smeem 		struct timeval	pr_tv_sent;	/* Wall time probe was sent */
256*e11c3f44Smeem 		hrtime_t pr_hrtime_start;	/* hrtime probe op started */
257*e11c3f44Smeem 		hrtime_t pr_hrtime_sent;	/* hrtime probe was sent */
258*e11c3f44Smeem 		hrtime_t pr_hrtime_ackrecv; 	/* hrtime probe ack received */
259*e11c3f44Smeem 		hrtime_t pr_hrtime_ackproc;	/* hrtime probe ack processed */
2607c478bd9Sstevel@tonic-gate 		uint_t	pr_status;	/* probe status as below */
2617c478bd9Sstevel@tonic-gate #define	PR_UNUSED	0		/* Probe slot unused */
2627c478bd9Sstevel@tonic-gate #define	PR_UNACKED	1		/* Probe is unacknowledged */
2637c478bd9Sstevel@tonic-gate #define	PR_ACKED	2		/* Probe has been acknowledged */
2647c478bd9Sstevel@tonic-gate #define	PR_LOST		3		/* Probe is declared lost */
2657c478bd9Sstevel@tonic-gate 	} pii_probes[PROBE_STATS_COUNT];
2667c478bd9Sstevel@tonic-gate 
2677c478bd9Sstevel@tonic-gate 	uint_t
2687c478bd9Sstevel@tonic-gate 		pii_in_use : 1,			/* To detect removed phyints */
2697c478bd9Sstevel@tonic-gate 		pii_basetime_inited : 1,	/* probe time initialized */
2707c478bd9Sstevel@tonic-gate 		pii_targets_are_routers : 1;	/* routers or hosts ? */
2717c478bd9Sstevel@tonic-gate 
2727c478bd9Sstevel@tonic-gate 	uint_t	pii_probe_next;		/* next index to use in pii_probes[] */
2737c478bd9Sstevel@tonic-gate 	struct target *pii_target_next;	/* next target for probing */
2747c478bd9Sstevel@tonic-gate 	struct target *pii_rtt_target_next;
2757c478bd9Sstevel@tonic-gate 					/* next target for rtt probes */
2767c478bd9Sstevel@tonic-gate 
2777c478bd9Sstevel@tonic-gate 	int	pii_ntargets;		/* Number of active targets */
2787c478bd9Sstevel@tonic-gate 	struct stats {			/* Cumulative statistics */
2797c478bd9Sstevel@tonic-gate 		uint64_t	lost;		/* Number of probes lost */
2807c478bd9Sstevel@tonic-gate 		uint64_t	acked;		/* Number of probes acked */
2817c478bd9Sstevel@tonic-gate 		uint64_t	sent;		/* Number of probes sent */
2827c478bd9Sstevel@tonic-gate 		uint64_t	unknown;	/* Number of ambiguous */
2837c478bd9Sstevel@tonic-gate 						/* probe acks */
2847c478bd9Sstevel@tonic-gate 	} pii_cum_stats;
2857c478bd9Sstevel@tonic-gate };
2867c478bd9Sstevel@tonic-gate 
2877c478bd9Sstevel@tonic-gate #define	pii_name	pii_phyint->pi_name
2887c478bd9Sstevel@tonic-gate #define	pii_ifindex	pii_phyint->pi_ifindex
2897c478bd9Sstevel@tonic-gate #define	pii_state	pii_phyint->pi_state
2907c478bd9Sstevel@tonic-gate #define	pii_icmpid	pii_phyint->pi_icmpid
2917c478bd9Sstevel@tonic-gate 
2927c478bd9Sstevel@tonic-gate #define	PR_STATUS_VALID(status)		((status) <= PR_LOST)
2937c478bd9Sstevel@tonic-gate 
2947c478bd9Sstevel@tonic-gate 
2957c478bd9Sstevel@tonic-gate /*
2967c478bd9Sstevel@tonic-gate  * A doubly linked list of prefixes or logicals, hanging off the
2977c478bd9Sstevel@tonic-gate  * phyint instance.
2987c478bd9Sstevel@tonic-gate  */
2997c478bd9Sstevel@tonic-gate struct logint {
3007c478bd9Sstevel@tonic-gate 	struct logint	*li_next;	/* Next logint of this phyint inst. */
3017c478bd9Sstevel@tonic-gate 	struct logint	*li_prev;	/* Prev logint of this phyint inst. */
3027c478bd9Sstevel@tonic-gate 	struct phyint_instance	*li_phyint_inst;
3037c478bd9Sstevel@tonic-gate 					/* Back pointer to phyint inst. */
3047c478bd9Sstevel@tonic-gate 
3057c478bd9Sstevel@tonic-gate 	char		li_name[LIFNAMSIZ + 1];	/* name Eg. hme0:1 */
3067c478bd9Sstevel@tonic-gate 	struct in6_addr	li_addr;	/* IP address */
3077c478bd9Sstevel@tonic-gate 	struct in6_addr	li_dstaddr;	/* Dst IP address for pointopoint */
3087c478bd9Sstevel@tonic-gate 	struct in6_addr	li_subnet;	/* prefix / subnet */
3097c478bd9Sstevel@tonic-gate 	uint_t		li_subnet_len;	/* prefix / subnet length */
3107c478bd9Sstevel@tonic-gate 	uint64_t	li_flags;	/* IFF_* flags */
3117c478bd9Sstevel@tonic-gate 	uint_t
3127c478bd9Sstevel@tonic-gate 			li_in_use : 1,	/* flag to detect deleted logints */
313e6ed03fcSmeem 			li_dupaddr : 1;	/* test address is not unique */
3147c478bd9Sstevel@tonic-gate };
3157c478bd9Sstevel@tonic-gate 
3167c478bd9Sstevel@tonic-gate 
3177c478bd9Sstevel@tonic-gate /*
3187c478bd9Sstevel@tonic-gate  * Doubly-linked list of probe targets on a phyint instance. Probe targets are
3197c478bd9Sstevel@tonic-gate  * usually onlink routers. If no onlink routers can be found, onlink hosts
3207c478bd9Sstevel@tonic-gate  * are used.
3217c478bd9Sstevel@tonic-gate  */
3227c478bd9Sstevel@tonic-gate struct target {
3237c478bd9Sstevel@tonic-gate 	struct target	*tg_next;	/* Next target for this phyint inst. */
3247c478bd9Sstevel@tonic-gate 	struct target	*tg_prev;	/* Prev target for this phyint inst. */
3257c478bd9Sstevel@tonic-gate 	struct phyint_instance	*tg_phyint_inst;
3267c478bd9Sstevel@tonic-gate 					/* Back pointer to phyint instance */
3277c478bd9Sstevel@tonic-gate 
3287c478bd9Sstevel@tonic-gate 	struct in6_addr	tg_address;	/* Target IP address */
3297c478bd9Sstevel@tonic-gate 	int		tg_status;	/* Status of the target below */
3307c478bd9Sstevel@tonic-gate #define	TG_ACTIVE	1		/* active probe target */
3317c478bd9Sstevel@tonic-gate #define	TG_UNUSED	2		/* target not in use now */
3327c478bd9Sstevel@tonic-gate #define	TG_SLOW		3		/* rtt is high - Not in use now */
3337c478bd9Sstevel@tonic-gate #define	TG_DEAD		4		/* Target is not responding */
3347c478bd9Sstevel@tonic-gate 
3357c478bd9Sstevel@tonic-gate 	hrtime_t	tg_latime;	/* Target's last active time */
336*e11c3f44Smeem 	int64_t		tg_rtt_sa;	/* Scaled RTT average (in ns) */
337*e11c3f44Smeem 	int64_t		tg_rtt_sd;	/* Scaled RTT deviation (in ns) */
338*e11c3f44Smeem 	int		tg_crtt;	/* Conservative RTT = A + 4D (in ms) */
3397c478bd9Sstevel@tonic-gate 	uint32_t
3407c478bd9Sstevel@tonic-gate 			tg_in_use : 1;	/* In use flag */
341*e11c3f44Smeem 	int64_t		tg_deferred[MAXDEFERREDRTT + 1];
3427c478bd9Sstevel@tonic-gate 					/* Deferred rtt data points */
3437c478bd9Sstevel@tonic-gate 	int		tg_num_deferred;
3447c478bd9Sstevel@tonic-gate 					/* Number of deferred rtt data points */
3457c478bd9Sstevel@tonic-gate };
3467c478bd9Sstevel@tonic-gate 
3477c478bd9Sstevel@tonic-gate #define	TG_STATUS_VALID(status) \
3487c478bd9Sstevel@tonic-gate 	(((status) >= TG_ACTIVE) && ((status) <= TG_DEAD))
3497c478bd9Sstevel@tonic-gate 
3507c478bd9Sstevel@tonic-gate /*
3517c478bd9Sstevel@tonic-gate  * Statistics about consecutive probe failures are passed around between
3527c478bd9Sstevel@tonic-gate  * functions in this structure.
3537c478bd9Sstevel@tonic-gate  */
3547c478bd9Sstevel@tonic-gate struct probe_fail_count
3557c478bd9Sstevel@tonic-gate {
3567c478bd9Sstevel@tonic-gate 	uint_t	pf_tff;		/* Earliest time of failure in a series */
3577c478bd9Sstevel@tonic-gate 	int	pf_nfail;	/* Number of consecutive probe failures */
3587c478bd9Sstevel@tonic-gate 	int	pf_nfail_tg;	/* Number of consecutive probe fails for */
3597c478bd9Sstevel@tonic-gate 				/* some given target 'tg' */
3607c478bd9Sstevel@tonic-gate };
3617c478bd9Sstevel@tonic-gate 
3627c478bd9Sstevel@tonic-gate /*
3637c478bd9Sstevel@tonic-gate  * Statistics about consecutive probe successes is passed around between
3647c478bd9Sstevel@tonic-gate  * functions in this structure.
3657c478bd9Sstevel@tonic-gate  */
3667c478bd9Sstevel@tonic-gate struct probe_success_count
3677c478bd9Sstevel@tonic-gate {
3687c478bd9Sstevel@tonic-gate 	uint_t ps_tls;		/* Most recent time of probe success */
3697c478bd9Sstevel@tonic-gate 	boolean_t ps_tls_valid;	/* is ps_tls valid */
3707c478bd9Sstevel@tonic-gate 	int	ps_nsucc;	/* Number of consecutive probe successes */
3717c478bd9Sstevel@tonic-gate 				/* starting from the most recent */
3727c478bd9Sstevel@tonic-gate 	int	ps_nsucc_tg;	/* Number of consecutive probe successes */
3737c478bd9Sstevel@tonic-gate 				/* for some given target 'tg' */
3747c478bd9Sstevel@tonic-gate };
3757c478bd9Sstevel@tonic-gate 
3767c478bd9Sstevel@tonic-gate /*
3777c478bd9Sstevel@tonic-gate  * Statistics about missed probes that were never sent.
3787c478bd9Sstevel@tonic-gate  * Happens due to scheduling delay.
3797c478bd9Sstevel@tonic-gate  */
3807c478bd9Sstevel@tonic-gate 
3817c478bd9Sstevel@tonic-gate struct probes_missed
3827c478bd9Sstevel@tonic-gate {
3837c478bd9Sstevel@tonic-gate 	uint_t	pm_nprobes;	/* Cumulative number of missed probes */
384*e11c3f44Smeem 	uint_t	pm_ntimes;	/* Total number of occasions */
3857c478bd9Sstevel@tonic-gate };
3867c478bd9Sstevel@tonic-gate 
387*e11c3f44Smeem typedef struct addrlist {
388*e11c3f44Smeem 	struct addrlist		*al_next; 		/* next address */
389*e11c3f44Smeem 	char			al_name[LIFNAMSIZ];	/* address lif name */
390*e11c3f44Smeem 	uint64_t		al_flags;		/* address flags */
391*e11c3f44Smeem 	struct sockaddr_storage	al_addr; 		/* address */
392*e11c3f44Smeem } addrlist_t;
39387e66ffcSrk 
3947c478bd9Sstevel@tonic-gate /*
3957c478bd9Sstevel@tonic-gate  * Globals
3967c478bd9Sstevel@tonic-gate  */
397*e11c3f44Smeem extern addrlist_t *localaddrs;
39887e66ffcSrk 			/* List of all local addresses, including local zones */
3997c478bd9Sstevel@tonic-gate extern struct phyint *phyints;		/* List of all phyints */
4007c478bd9Sstevel@tonic-gate extern struct phyint_group *phyint_groups; /* List of all phyint groups */
4017c478bd9Sstevel@tonic-gate extern struct phyint_group *phyint_anongroup; /* Pointer to the anon group */
4027c478bd9Sstevel@tonic-gate extern struct phyint_instance *phyint_instances;
4037c478bd9Sstevel@tonic-gate 					/* List of all phyint instances */
4047c478bd9Sstevel@tonic-gate extern struct probes_missed probes_missed;
4057c478bd9Sstevel@tonic-gate 					/* statistics about missed probes */
4067c478bd9Sstevel@tonic-gate 
4077c478bd9Sstevel@tonic-gate /*
4087c478bd9Sstevel@tonic-gate  * Function prototypes
4097c478bd9Sstevel@tonic-gate  */
4107c478bd9Sstevel@tonic-gate extern int phyint_init(void);
4117c478bd9Sstevel@tonic-gate extern struct phyint *phyint_lookup(const char *name);
4127c478bd9Sstevel@tonic-gate extern struct phyint_instance *phyint_inst_lookup(int af, char *name);
4137c478bd9Sstevel@tonic-gate extern struct phyint_instance *phyint_inst_init_from_k(int af, char *name);
4147c478bd9Sstevel@tonic-gate extern struct phyint_instance *phyint_inst_other(struct phyint_instance *pii);
4157c478bd9Sstevel@tonic-gate extern int phyint_inst_update_from_k(struct phyint_instance *pii);
4167c478bd9Sstevel@tonic-gate extern void phyint_inst_delete(struct phyint_instance *pii);
4177c478bd9Sstevel@tonic-gate extern uint_t phyint_inst_timer(struct phyint_instance *pii);
4187c478bd9Sstevel@tonic-gate extern boolean_t phyint_inst_sockinit(struct phyint_instance *pii);
4197c478bd9Sstevel@tonic-gate 
420*e11c3f44Smeem extern void phyint_changed(struct phyint *pi);
4217c478bd9Sstevel@tonic-gate extern void phyint_chstate(struct phyint *pi, enum pi_state state);
4227c478bd9Sstevel@tonic-gate extern void phyint_group_chstate(struct phyint_group *pg, enum pg_state state);
423*e11c3f44Smeem extern struct phyint_group *phyint_group_create(const char *pg_name);
424*e11c3f44Smeem extern struct phyint_group *phyint_group_lookup(const char *pg_name);
425*e11c3f44Smeem extern void phyint_group_insert(struct phyint_group *pg);
426*e11c3f44Smeem extern void phyint_group_delete(struct phyint_group *pg);
427*e11c3f44Smeem extern void phyint_group_refresh_state(struct phyint_group *pg);
4287c478bd9Sstevel@tonic-gate extern void phyint_check_for_repair(struct phyint *pi);
429*e11c3f44Smeem extern void phyint_transition_to_running(struct phyint *pi);
430*e11c3f44Smeem extern void phyint_activate_another(struct phyint *pi);
431*e11c3f44Smeem extern int phyint_offline(struct phyint *pi, unsigned int);
432*e11c3f44Smeem extern int phyint_undo_offline(struct phyint *pi);
4337c478bd9Sstevel@tonic-gate 
4347c478bd9Sstevel@tonic-gate extern void logint_init_from_k(struct phyint_instance *pii, char *li_name);
4357c478bd9Sstevel@tonic-gate extern void logint_delete(struct logint *li);
4367c478bd9Sstevel@tonic-gate 
4377c478bd9Sstevel@tonic-gate extern struct target *target_lookup(struct phyint_instance *pii,
4387c478bd9Sstevel@tonic-gate     struct in6_addr addr);
4397c478bd9Sstevel@tonic-gate extern void target_create(struct phyint_instance *pii,
4407c478bd9Sstevel@tonic-gate     struct in6_addr addr, boolean_t is_router);
4417c478bd9Sstevel@tonic-gate extern void target_delete(struct target *tg);
4427c478bd9Sstevel@tonic-gate extern struct target *target_next(struct target *tg);
4437c478bd9Sstevel@tonic-gate extern void target_add(struct phyint_instance *pii, struct in6_addr addr,
4447c478bd9Sstevel@tonic-gate     boolean_t is_router);
4457c478bd9Sstevel@tonic-gate 
4467c478bd9Sstevel@tonic-gate extern void in_data(struct phyint_instance *pii);
4477c478bd9Sstevel@tonic-gate extern void in6_data(struct phyint_instance *pii);
4487c478bd9Sstevel@tonic-gate 
449e3e7cd29Smeem extern void logperror_pii(struct phyint_instance *pii, const char *str);
450e3e7cd29Smeem extern void logperror_li(struct logint *li, const char *str);
4517c478bd9Sstevel@tonic-gate extern char *pr_addr(int af, struct in6_addr addr, char *abuf, int len);
452*e11c3f44Smeem extern void addr2storage(int af, const struct in6_addr *addr,
453*e11c3f44Smeem     struct sockaddr_storage *ssp);
4547c478bd9Sstevel@tonic-gate extern void phyint_inst_print_all(void);
455*e11c3f44Smeem extern boolean_t prefix_equal(struct in6_addr, struct in6_addr, uint_t);
4567c478bd9Sstevel@tonic-gate 
4577c478bd9Sstevel@tonic-gate extern void reset_crtt_all(struct phyint *pi);
4587c478bd9Sstevel@tonic-gate extern int failure_state(struct phyint_instance *pii);
4597c478bd9Sstevel@tonic-gate extern void process_link_state_changes(void);
4607c478bd9Sstevel@tonic-gate extern void clear_pii_probe_stats(struct phyint_instance *pii);
4617c478bd9Sstevel@tonic-gate extern void start_timer(struct phyint_instance *pii);
462*e11c3f44Smeem extern void stop_probing(struct phyint *pi);
4637c478bd9Sstevel@tonic-gate 
46487e66ffcSrk extern boolean_t own_address(struct in6_addr addr);
465*e11c3f44Smeem extern boolean_t change_pif_flags(struct phyint *pi, uint64_t set,
466*e11c3f44Smeem     uint64_t clear);
4677c478bd9Sstevel@tonic-gate 
4687c478bd9Sstevel@tonic-gate extern void close_probe_socket(struct phyint_instance *pii, boolean_t flag);
469*e11c3f44Smeem extern int probe_state_event(struct probe_stats *, struct phyint_instance *);
470*e11c3f44Smeem extern void probe_chstate(struct probe_stats *, struct phyint_instance *, int);
4717c478bd9Sstevel@tonic-gate 
472*e11c3f44Smeem extern unsigned int getgraddrinfo(const char *, struct sockaddr_storage *,
473*e11c3f44Smeem     ipmp_addrinfo_t **);
4747c478bd9Sstevel@tonic-gate extern unsigned int getifinfo(const char *, ipmp_ifinfo_t **);
4757c478bd9Sstevel@tonic-gate extern unsigned int getgroupinfo(const char *, ipmp_groupinfo_t **);
4767c478bd9Sstevel@tonic-gate extern unsigned int getgrouplist(ipmp_grouplist_t **);
4777c478bd9Sstevel@tonic-gate extern unsigned int getsnap(ipmp_snap_t **);
4787c478bd9Sstevel@tonic-gate 
479*e11c3f44Smeem extern boolean_t addrlist_add(addrlist_t **, const char *, uint64_t,
480*e11c3f44Smeem     struct sockaddr_storage *);
481*e11c3f44Smeem extern void addrlist_free(addrlist_t **);
482*e11c3f44Smeem 
4837c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
4847c478bd9Sstevel@tonic-gate }
4857c478bd9Sstevel@tonic-gate #endif
4867c478bd9Sstevel@tonic-gate 
4877c478bd9Sstevel@tonic-gate #endif	/* _MPD_TABLES_H */
488