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 /*
22e11c3f44Smeem  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate #ifndef	_MPD_TABLES_H
277c478bd9Sstevel@tonic-gate #define	_MPD_TABLES_H
297c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
307c478bd9Sstevel@tonic-gate extern "C" {
317c478bd9Sstevel@tonic-gate #endif
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.
48e11c3f44Smeem  * 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  */
537c478bd9Sstevel@tonic-gate #define	MAXDEFERREDRTT		1	/* Maximum number of deferred rtts */
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 */
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. */
717c478bd9Sstevel@tonic-gate #define	PHYINT_FLAGS(flags)	\
72e11c3f44Smeem 	(((flags) & (IFF_STANDBY | IFF_INACTIVE | IFF_FAILED | IFF_OFFLINE | \
73e11c3f44Smeem 	IFF_RUNNING)) | (handle_link_notifications ? 0 : IFF_RUNNING))
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)
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)))
907c478bd9Sstevel@tonic-gate #define	PROBE_CAPABLE(pii) \
917c478bd9Sstevel@tonic-gate 	(PROBE_ENABLED(pii) && ((pii)->pii_ntargets != 0))
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))
977c478bd9Sstevel@tonic-gate /* Increment modulo n */
987c478bd9Sstevel@tonic-gate #define	MOD_INCR(a, n)		\
997c478bd9Sstevel@tonic-gate 	(((a) + 1) % (n))
1017c478bd9Sstevel@tonic-gate /* Decrement modulo n */
1027c478bd9Sstevel@tonic-gate #define	MOD_DCR(a, n)		\
1037c478bd9Sstevel@tonic-gate 	MOD_SUB(a, 1, n)
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)
1147c478bd9Sstevel@tonic-gate #define	PROBE_INDEX_NEXT(index)	\
1157c478bd9Sstevel@tonic-gate 	MOD_INCR(index, PROBE_STATS_COUNT)
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
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)
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 {
138e11c3f44Smeem 	PG_OK = 1,	/* all interfaces in the group are working */
139e11c3f44Smeem 	PG_DEGRADED,	/* some interfaces in the group are unusable */
140e11c3f44Smeem 	PG_FAILED	/* all interfaces in the group are unusable */
1417c478bd9Sstevel@tonic-gate };
1437c478bd9Sstevel@tonic-gate /*
1447c478bd9Sstevel@tonic-gate  * Convenience macro to check if the whole group has failed.
1457c478bd9Sstevel@tonic-gate  */
146e11c3f44Smeem #define	GROUP_FAILED(pg)	((pg)->pg_state == PG_FAILED)
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 {
153e11c3f44Smeem 	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 */
157e11c3f44Smeem 	uint64_t 	pg_sig;		/* Current signature of this group */
158e11c3f44Smeem 	int		pg_probeint;	/* Interval between probes */
159e11c3f44Smeem 	int		pg_fdt;		/* Time needed to detect failure */
160e11c3f44Smeem 	enum pg_state	pg_state;	/* Current group state */
161e11c3f44Smeem 	boolean_t	pg_in_use;	/* To detect removed groups */
162e11c3f44Smeem 	struct addrlist	*pg_addrs;	/* Data addresses in this group */
163e11c3f44Smeem 	boolean_t pg_failmsg_printed;	/* Group failure msg printed */
1647c478bd9Sstevel@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 {
170fcdc8680Smeem 	PI_INIT		= 0,	/* Phyint is being initialized */
1717c478bd9Sstevel@tonic-gate 	PI_NOTARGETS	= 1,	/* Phyint has no targets */
1727c478bd9Sstevel@tonic-gate 	PI_RUNNING	= 2,	/* Phyint is functioning */
1737c478bd9Sstevel@tonic-gate 	PI_FAILED	= 3,	/* Phyint is failed */
1747c478bd9Sstevel@tonic-gate 	PI_OFFLINE	= 4	/* Phyint is offline */
1757c478bd9Sstevel@tonic-gate };
1777c478bd9Sstevel@tonic-gate /*
1787c478bd9Sstevel@tonic-gate  * Representation of a NIC or a phyint. There is a list of all known phyints.
1797c478bd9Sstevel@tonic-gate  * There is also a list of phyints belonging to a phyint group, one list
1807c478bd9Sstevel@tonic-gate  * per phyint group.
1817c478bd9Sstevel@tonic-gate  */
1827c478bd9Sstevel@tonic-gate struct phyint {
1837c478bd9Sstevel@tonic-gate 	char	pi_name[LIFNAMSIZ + 1]; /* Phyint name eg. le0 */
1847c478bd9Sstevel@tonic-gate 	struct phyint_instance *pi_v4;	/* The IPv4 instance */
1857c478bd9Sstevel@tonic-gate 	struct phyint_instance *pi_v6;	/* The IPv6 instance */
1867c478bd9Sstevel@tonic-gate 	struct phyint_group *pi_group;	/* Pointer to the group */
1877c478bd9Sstevel@tonic-gate 	struct phyint	*pi_next;	/* List of all phyints */
1887c478bd9Sstevel@tonic-gate 	struct phyint	*pi_prev;	/* List of all phyints */
1897c478bd9Sstevel@tonic-gate 	struct phyint	*pi_pgnext;	/* List of phyints in this group */
1907c478bd9Sstevel@tonic-gate 	struct phyint	*pi_pgprev;	/* List of phyints in this group */
1917c478bd9Sstevel@tonic-gate 	uint_t		pi_ifindex;	/* interface index */
1927c478bd9Sstevel@tonic-gate 	enum pi_state	pi_state;	/* State of the phyint */
1937c478bd9Sstevel@tonic-gate 	uint64_t	pi_flags;	/* Phyint flags from kernel */
1947c478bd9Sstevel@tonic-gate 	uint16_t	pi_icmpid;	/* icmp id in icmp echo request */
195e6ed03fcSmeem 	uint64_t	pi_taddrthresh;	/* time (in secs) to delay logging */
196e6ed03fcSmeem 					/* about missing test addresses */
197e11c3f44Smeem 	dlpi_handle_t	pi_dh;		/* DLPI handle to underlying link */
198e11c3f44Smeem 	uint_t		pi_notes; 	/* enabled DLPI notifications */
199e11c3f44Smeem 	uchar_t		pi_hwaddr[DLPI_PHYSADDR_MAX]; /* phyint's hw address */
200e11c3f44Smeem 	size_t		pi_hwaddrlen;	/* phyint's hw address length */
2027c478bd9Sstevel@tonic-gate 	/*
2037c478bd9Sstevel@tonic-gate 	 * The pi_whenup array is a circular buffer of the most recent
2047c478bd9Sstevel@tonic-gate 	 * times (in milliseconds since some arbitrary point of time in
2057c478bd9Sstevel@tonic-gate 	 * the past) that the interface was brought up; pi_whendx identifies
2067c478bd9Sstevel@tonic-gate 	 * the oldest element of the array.
2077c478bd9Sstevel@tonic-gate 	 */
2087c478bd9Sstevel@tonic-gate 	uint_t		pi_whenup[LINK_UP_PERMIN];
2097c478bd9Sstevel@tonic-gate 	unsigned int	pi_whendx;
2117c478bd9Sstevel@tonic-gate 	uint_t
2127c478bd9Sstevel@tonic-gate 		pi_taddrmsg_printed : 1,	/* testaddr msg printed */
213e6ed03fcSmeem 		pi_duptaddrmsg_printed : 1,	/* dup testaddr msg printed */
2147c478bd9Sstevel@tonic-gate 		pi_cfgmsg_printed : 1,	/* bad config msg printed */
2157c478bd9Sstevel@tonic-gate 		pi_lfmsg_printed : 1,   /* link-flapping msg printed */
216e11c3f44Smeem 		pi_link_state : 1,	/* interface link state */
217e11c3f44Smeem 		pi_hwaddrdup : 1; 	/* disabled due to dup hw address */
2187c478bd9Sstevel@tonic-gate };
2207c478bd9Sstevel@tonic-gate /*
2217c478bd9Sstevel@tonic-gate  * A doubly linked list of all phyint_instances each of which contains a
2227c478bd9Sstevel@tonic-gate  * doubly linked list of logical interfaces and targets. For eg. if both
2237c478bd9Sstevel@tonic-gate  * IPv4 and IPv6 are used over hme0, we have 2 phyint instances, 1 for each
2247c478bd9Sstevel@tonic-gate  * protocol.
2257c478bd9Sstevel@tonic-gate  */
2267c478bd9Sstevel@tonic-gate struct phyint_instance {
2277c478bd9Sstevel@tonic-gate 	struct phyint_instance	*pii_next;	/* List of all phyint insts */
2287c478bd9Sstevel@tonic-gate 	struct phyint_instance	*pii_prev;	/* List of all phyint insts */
2307c478bd9Sstevel@tonic-gate 	struct phyint	*pii_phyint;	/* Back pointer to the phyint */
2317c478bd9Sstevel@tonic-gate 	struct target	*pii_targets;	/* List of targets on this link */
2327c478bd9Sstevel@tonic-gate 	struct logint	*pii_probe_logint; /* IFF_NOFAILOVER addr for probing */
2337c478bd9Sstevel@tonic-gate 	struct logint	*pii_logint;	/* Doubly linked list of logical ifs */
2357c478bd9Sstevel@tonic-gate 	int	pii_probe_sock;		/* Socket for ICMP Probe packets */
2367c478bd9Sstevel@tonic-gate 	int	pii_af;			/* Address family */
2377c478bd9Sstevel@tonic-gate 	uint16_t pii_rack;		/* highest acknowledged seq number */
2387c478bd9Sstevel@tonic-gate 	uint16_t pii_snxt;		/* sequence number of next probe */
2397c478bd9Sstevel@tonic-gate 	uint_t	pii_snxt_time;		/* actual next probe time that */
2407c478bd9Sstevel@tonic-gate 					/* includes some randomness */
2427c478bd9Sstevel@tonic-gate 	uint_t	pii_snxt_basetime; 	/* strictly periodic base probe time */
2437c478bd9Sstevel@tonic-gate 					/* for all periodic probes */
2447c478bd9Sstevel@tonic-gate 	uint_t	pii_fd_snxt_basetime; 	/* strictly periodic base probe time */
2457c478bd9Sstevel@tonic-gate 					/* for failure detection probes */
2477c478bd9Sstevel@tonic-gate 	hrtime_t 	pii_fd_hrtime;	/* hrtime_t before which we should */
2487c478bd9Sstevel@tonic-gate 					/* not send probes out this pii */
2507c478bd9Sstevel@tonic-gate 	uint64_t	pii_flags;	/* Phyint flags from kernel */
2527c478bd9Sstevel@tonic-gate 	struct probe_stats {
253e11c3f44Smeem 		uint_t		pr_id;		/* Full ID of probe */
254e11c3f44Smeem 		struct target	*pr_target;	/* Probe Target */
255e11c3f44Smeem 		uint_t		pr_time_lost; 	/* Time probe declared lost */
256e11c3f44Smeem 		struct timeval	pr_tv_sent;	/* Wall time probe was sent */
257e11c3f44Smeem 		hrtime_t pr_hrtime_start;	/* hrtime probe op started */
258e11c3f44Smeem 		hrtime_t pr_hrtime_sent;	/* hrtime probe was sent */
259e11c3f44Smeem 		hrtime_t pr_hrtime_ackrecv; 	/* hrtime probe ack received */
260e11c3f44Smeem 		hrtime_t pr_hrtime_ackproc;	/* hrtime probe ack processed */
2617c478bd9Sstevel@tonic-gate 		uint_t	pr_status;	/* probe status as below */
2627c478bd9Sstevel@tonic-gate #define	PR_UNUSED	0		/* Probe slot unused */
2637c478bd9Sstevel@tonic-gate #define	PR_UNACKED	1		/* Probe is unacknowledged */
2647c478bd9Sstevel@tonic-gate #define	PR_ACKED	2		/* Probe has been acknowledged */
2657c478bd9Sstevel@tonic-gate #define	PR_LOST		3		/* Probe is declared lost */
2667c478bd9Sstevel@tonic-gate 	} pii_probes[PROBE_STATS_COUNT];
2687c478bd9Sstevel@tonic-gate 	uint_t
2697c478bd9Sstevel@tonic-gate 		pii_in_use : 1,			/* To detect removed phyints */
2707c478bd9Sstevel@tonic-gate 		pii_basetime_inited : 1,	/* probe time initialized */
2717c478bd9Sstevel@tonic-gate 		pii_targets_are_routers : 1;	/* routers or hosts ? */
2737c478bd9Sstevel@tonic-gate 	uint_t	pii_probe_next;		/* next index to use in pii_probes[] */
2747c478bd9Sstevel@tonic-gate 	struct target *pii_target_next;	/* next target for probing */
2757c478bd9Sstevel@tonic-gate 	struct target *pii_rtt_target_next;
2767c478bd9Sstevel@tonic-gate 					/* next target for rtt probes */
2787c478bd9Sstevel@tonic-gate 	int	pii_ntargets;		/* Number of active targets */
2797c478bd9Sstevel@tonic-gate 	struct stats {			/* Cumulative statistics */
2807c478bd9Sstevel@tonic-gate 		uint64_t	lost;		/* Number of probes lost */
2817c478bd9Sstevel@tonic-gate 		uint64_t	acked;		/* Number of probes acked */
2827c478bd9Sstevel@tonic-gate 		uint64_t	sent;		/* Number of probes sent */
2837c478bd9Sstevel@tonic-gate 		uint64_t	unknown;	/* Number of ambiguous */
2847c478bd9Sstevel@tonic-gate 						/* probe acks */
2857c478bd9Sstevel@tonic-gate 	} pii_cum_stats;
2867c478bd9Sstevel@tonic-gate };
2887c478bd9Sstevel@tonic-gate #define	pii_name	pii_phyint->pi_name
2897c478bd9Sstevel@tonic-gate #define	pii_ifindex	pii_phyint->pi_ifindex
2907c478bd9Sstevel@tonic-gate #define	pii_state	pii_phyint->pi_state
2917c478bd9Sstevel@tonic-gate #define	pii_icmpid	pii_phyint->pi_icmpid
2937c478bd9Sstevel@tonic-gate #define	PR_STATUS_VALID(status)		((status) <= PR_LOST)
2967c478bd9Sstevel@tonic-gate /*
2977c478bd9Sstevel@tonic-gate  * A doubly linked list of prefixes or logicals, hanging off the
2987c478bd9Sstevel@tonic-gate  * phyint instance.
2997c478bd9Sstevel@tonic-gate  */
3007c478bd9Sstevel@tonic-gate struct logint {
3017c478bd9Sstevel@tonic-gate 	struct logint	*li_next;	/* Next logint of this phyint inst. */
3027c478bd9Sstevel@tonic-gate 	struct logint	*li_prev;	/* Prev logint of this phyint inst. */
3037c478bd9Sstevel@tonic-gate 	struct phyint_instance	*li_phyint_inst;
3047c478bd9Sstevel@tonic-gate 					/* Back pointer to phyint inst. */
3067c478bd9Sstevel@tonic-gate 	char		li_name[LIFNAMSIZ + 1];	/* name Eg. hme0:1 */
3077c478bd9Sstevel@tonic-gate 	struct in6_addr	li_addr;	/* IP address */
3087c478bd9Sstevel@tonic-gate 	struct in6_addr	li_dstaddr;	/* Dst IP address for pointopoint */
3097c478bd9Sstevel@tonic-gate 	struct in6_addr	li_subnet;	/* prefix / subnet */
3107c478bd9Sstevel@tonic-gate 	uint_t		li_subnet_len;	/* prefix / subnet length */
3117c478bd9Sstevel@tonic-gate 	uint64_t	li_flags;	/* IFF_* flags */
3127c478bd9Sstevel@tonic-gate 	uint_t
3137c478bd9Sstevel@tonic-gate 			li_in_use : 1,	/* flag to detect deleted logints */
314e6ed03fcSmeem 			li_dupaddr : 1;	/* test address is not unique */
3157c478bd9Sstevel@tonic-gate };
3187c478bd9Sstevel@tonic-gate /*
3197c478bd9Sstevel@tonic-gate  * Doubly-linked list of probe targets on a phyint instance. Probe targets are
3207c478bd9Sstevel@tonic-gate  * usually onlink routers. If no onlink routers can be found, onlink hosts
3217c478bd9Sstevel@tonic-gate  * are used.
3227c478bd9Sstevel@tonic-gate  */
3237c478bd9Sstevel@tonic-gate struct target {
3247c478bd9Sstevel@tonic-gate 	struct target	*tg_next;	/* Next target for this phyint inst. */
3257c478bd9Sstevel@tonic-gate 	struct target	*tg_prev;	/* Prev target for this phyint inst. */
3267c478bd9Sstevel@tonic-gate 	struct phyint_instance	*tg_phyint_inst;
3277c478bd9Sstevel@tonic-gate 					/* Back pointer to phyint instance */
3297c478bd9Sstevel@tonic-gate 	struct in6_addr	tg_address;	/* Target IP address */
3307c478bd9Sstevel@tonic-gate 	int		tg_status;	/* Status of the target below */
3317c478bd9Sstevel@tonic-gate #define	TG_ACTIVE	1		/* active probe target */
3327c478bd9Sstevel@tonic-gate #define	TG_UNUSED	2		/* target not in use now */
3337c478bd9Sstevel@tonic-gate #define	TG_SLOW		3		/* rtt is high - Not in use now */
3347c478bd9Sstevel@tonic-gate #define	TG_DEAD		4		/* Target is not responding */
3367c478bd9Sstevel@tonic-gate 	hrtime_t	tg_latime;	/* Target's last active time */
337e11c3f44Smeem 	int64_t		tg_rtt_sa;	/* Scaled RTT average (in ns) */
338e11c3f44Smeem 	int64_t		tg_rtt_sd;	/* Scaled RTT deviation (in ns) */
339e11c3f44Smeem 	int		tg_crtt;	/* Conservative RTT = A + 4D (in ms) */
3407c478bd9Sstevel@tonic-gate 	uint32_t
3417c478bd9Sstevel@tonic-gate 			tg_in_use : 1;	/* In use flag */
342e11c3f44Smeem 	int64_t		tg_deferred[MAXDEFERREDRTT + 1];
3437c478bd9Sstevel@tonic-gate 					/* Deferred rtt data points */
3447c478bd9Sstevel@tonic-gate 	int		tg_num_deferred;
3457c478bd9Sstevel@tonic-gate 					/* Number of deferred rtt data points */
3467c478bd9Sstevel@tonic-gate };
3487c478bd9Sstevel@tonic-gate #define	TG_STATUS_VALID(status) \
3497c478bd9Sstevel@tonic-gate 	(((status) >= TG_ACTIVE) && ((status) <= TG_DEAD))
3517c478bd9Sstevel@tonic-gate /*
3527c478bd9Sstevel@tonic-gate  * Statistics about consecutive probe failures are passed around between
3537c478bd9Sstevel@tonic-gate  * functions in this structure.
3547c478bd9Sstevel@tonic-gate  */
3557c478bd9Sstevel@tonic-gate struct probe_fail_count
3567c478bd9Sstevel@tonic-gate {
3577c478bd9Sstevel@tonic-gate 	uint_t	pf_tff;		/* Earliest time of failure in a series */
3587c478bd9Sstevel@tonic-gate 	int	pf_nfail;	/* Number of consecutive probe failures */
3597c478bd9Sstevel@tonic-gate 	int	pf_nfail_tg;	/* Number of consecutive probe fails for */
3607c478bd9Sstevel@tonic-gate 				/* some given target 'tg' */
3617c478bd9Sstevel@tonic-gate };
3637c478bd9Sstevel@tonic-gate /*
3647c478bd9Sstevel@tonic-gate  * Statistics about consecutive probe successes is passed around between
3657c478bd9Sstevel@tonic-gate  * functions in this structure.
3667c478bd9Sstevel@tonic-gate  */
3677c478bd9Sstevel@tonic-gate struct probe_success_count
3687c478bd9Sstevel@tonic-gate {
3697c478bd9Sstevel@tonic-gate 	uint_t ps_tls;		/* Most recent time of probe success */
3707c478bd9Sstevel@tonic-gate 	boolean_t ps_tls_valid;	/* is ps_tls valid */
3717c478bd9Sstevel@tonic-gate 	int	ps_nsucc;	/* Number of consecutive probe successes */
3727c478bd9Sstevel@tonic-gate 				/* starting from the most recent */
3737c478bd9Sstevel@tonic-gate 	int	ps_nsucc_tg;	/* Number of consecutive probe successes */
3747c478bd9Sstevel@tonic-gate 				/* for some given target 'tg' */
3757c478bd9Sstevel@tonic-gate };
3777c478bd9Sstevel@tonic-gate /*
3787c478bd9Sstevel@tonic-gate  * Statistics about missed probes that were never sent.
3797c478bd9Sstevel@tonic-gate  * Happens due to scheduling delay.
3807c478bd9Sstevel@tonic-gate  */
3827c478bd9Sstevel@tonic-gate struct probes_missed
3837c478bd9Sstevel@tonic-gate {
3847c478bd9Sstevel@tonic-gate 	uint_t	pm_nprobes;	/* Cumulative number of missed probes */
385e11c3f44Smeem 	uint_t	pm_ntimes;	/* Total number of occasions */
3867c478bd9Sstevel@tonic-gate };
388e11c3f44Smeem typedef struct addrlist {
389e11c3f44Smeem 	struct addrlist		*al_next; 		/* next address */
390e11c3f44Smeem 	char			al_name[LIFNAMSIZ];	/* address lif name */
391e11c3f44Smeem 	uint64_t		al_flags;		/* address flags */
392e11c3f44Smeem 	struct sockaddr_storage	al_addr; 		/* address */
393e11c3f44Smeem } addrlist_t;
3957c478bd9Sstevel@tonic-gate /*
3967c478bd9Sstevel@tonic-gate  * Globals
3977c478bd9Sstevel@tonic-gate  */
398e11c3f44Smeem extern addrlist_t *localaddrs;
39987e66ffcSrk 			/* List of all local addresses, including local zones */
4007c478bd9Sstevel@tonic-gate extern struct phyint *phyints;		/* List of all phyints */
4017c478bd9Sstevel@tonic-gate extern struct phyint_group *phyint_groups; /* List of all phyint groups */
4027c478bd9Sstevel@tonic-gate extern struct phyint_group *phyint_anongroup; /* Pointer to the anon group */
4037c478bd9Sstevel@tonic-gate extern struct phyint_instance *phyint_instances;
4047c478bd9Sstevel@tonic-gate 					/* List of all phyint instances */
4057c478bd9Sstevel@tonic-gate extern struct probes_missed probes_missed;
4067c478bd9Sstevel@tonic-gate 					/* statistics about missed probes */
4087c478bd9Sstevel@tonic-gate /*
4097c478bd9Sstevel@tonic-gate  * Function prototypes
4107c478bd9Sstevel@tonic-gate  */
4117c478bd9Sstevel@tonic-gate extern int phyint_init(void);
4127c478bd9Sstevel@tonic-gate extern struct phyint *phyint_lookup(const char *name);
4137c478bd9Sstevel@tonic-gate extern struct phyint_instance *phyint_inst_lookup(int af, char *name);
4147c478bd9Sstevel@tonic-gate extern struct phyint_instance *phyint_inst_init_from_k(int af, char *name);
4157c478bd9Sstevel@tonic-gate extern struct phyint_instance *phyint_inst_other(struct phyint_instance *pii);
4167c478bd9Sstevel@tonic-gate extern int phyint_inst_update_from_k(struct phyint_instance *pii);
4177c478bd9Sstevel@tonic-gate extern void phyint_inst_delete(struct phyint_instance *pii);
4187c478bd9Sstevel@tonic-gate extern uint_t phyint_inst_timer(struct phyint_instance *pii);
4197c478bd9Sstevel@tonic-gate extern boolean_t phyint_inst_sockinit(struct phyint_instance *pii);
421e11c3f44Smeem extern void phyint_changed(struct phyint *pi);
4227c478bd9Sstevel@tonic-gate extern void phyint_chstate(struct phyint *pi, enum pi_state state);
4237c478bd9Sstevel@tonic-gate extern void phyint_group_chstate(struct phyint_group *pg, enum pg_state state);
424e11c3f44Smeem extern struct phyint_group *phyint_group_create(const char *pg_name);
425e11c3f44Smeem extern struct phyint_group *phyint_group_lookup(const char *pg_name);
426e11c3f44Smeem extern void phyint_group_insert(struct phyint_group *pg);
427e11c3f44Smeem extern void phyint_group_delete(struct phyint_group *pg);
428e11c3f44Smeem extern void phyint_group_refresh_state(struct phyint_group *pg);
429*9bea6098Smeem extern void phyint_standby_refresh_inactive(struct phyint *pi);
4307c478bd9Sstevel@tonic-gate extern void phyint_check_for_repair(struct phyint *pi);
431e11c3f44Smeem extern void phyint_transition_to_running(struct phyint *pi);
432e11c3f44Smeem extern void phyint_activate_another(struct phyint *pi);
433e11c3f44Smeem extern int phyint_offline(struct phyint *pi, unsigned int);
434e11c3f44Smeem extern int phyint_undo_offline(struct phyint *pi);
435*9bea6098Smeem extern boolean_t phyint_is_functioning(struct phyint *pi);
4377c478bd9Sstevel@tonic-gate extern void logint_init_from_k(struct phyint_instance *pii, char *li_name);
4387c478bd9Sstevel@tonic-gate extern void logint_delete(struct logint *li);
4407c478bd9Sstevel@tonic-gate extern struct target *target_lookup(struct phyint_instance *pii,
4417c478bd9Sstevel@tonic-gate     struct in6_addr addr);
4427c478bd9Sstevel@tonic-gate extern void target_create(struct phyint_instance *pii,
4437c478bd9Sstevel@tonic-gate     struct in6_addr addr, boolean_t is_router);
4447c478bd9Sstevel@tonic-gate extern void target_delete(struct target *tg);
4457c478bd9Sstevel@tonic-gate extern struct target *target_next(struct target *tg);
4467c478bd9Sstevel@tonic-gate extern void target_add(struct phyint_instance *pii, struct in6_addr addr,
4477c478bd9Sstevel@tonic-gate     boolean_t is_router);
4497c478bd9Sstevel@tonic-gate extern void in_data(struct phyint_instance *pii);
4507c478bd9Sstevel@tonic-gate extern void in6_data(struct phyint_instance *pii);
452e3e7cd29Smeem extern void logperror_pii(struct phyint_instance *pii, const char *str);
453e3e7cd29Smeem extern void logperror_li(struct logint *li, const char *str);
4547c478bd9Sstevel@tonic-gate extern char *pr_addr(int af, struct in6_addr addr, char *abuf, int len);
455e11c3f44Smeem extern void addr2storage(int af, const struct in6_addr *addr,
456e11c3f44Smeem     struct sockaddr_storage *ssp);
4577c478bd9Sstevel@tonic-gate extern void phyint_inst_print_all(void);
458e11c3f44Smeem extern boolean_t prefix_equal(struct in6_addr, struct in6_addr, uint_t);
4607c478bd9Sstevel@tonic-gate extern void reset_crtt_all(struct phyint *pi);
4617c478bd9Sstevel@tonic-gate extern int failure_state(struct phyint_instance *pii);
4627c478bd9Sstevel@tonic-gate extern void process_link_state_changes(void);
4637c478bd9Sstevel@tonic-gate extern void clear_pii_probe_stats(struct phyint_instance *pii);
4647c478bd9Sstevel@tonic-gate extern void start_timer(struct phyint_instance *pii);
465e11c3f44Smeem extern void stop_probing(struct phyint *pi);
46787e66ffcSrk extern boolean_t own_address(struct in6_addr addr);
468e11c3f44Smeem extern boolean_t change_pif_flags(struct phyint *pi, uint64_t set,
469e11c3f44Smeem     uint64_t clear);
4717c478bd9Sstevel@tonic-gate extern void close_probe_socket(struct phyint_instance *pii, boolean_t flag);
472e11c3f44Smeem extern int probe_state_event(struct probe_stats *, struct phyint_instance *);
473e11c3f44Smeem extern void probe_chstate(struct probe_stats *, struct phyint_instance *, int);
475e11c3f44Smeem extern unsigned int getgraddrinfo(const char *, struct sockaddr_storage *,
476e11c3f44Smeem     ipmp_addrinfo_t **);
4777c478bd9Sstevel@tonic-gate extern unsigned int getifinfo(const char *, ipmp_ifinfo_t **);
4787c478bd9Sstevel@tonic-gate extern unsigned int getgroupinfo(const char *, ipmp_groupinfo_t **);
4797c478bd9Sstevel@tonic-gate extern unsigned int getgrouplist(ipmp_grouplist_t **);
4807c478bd9Sstevel@tonic-gate extern unsigned int getsnap(ipmp_snap_t **);
482e11c3f44Smeem extern boolean_t addrlist_add(addrlist_t **, const char *, uint64_t,
483e11c3f44Smeem     struct sockaddr_storage *);
484e11c3f44Smeem extern void addrlist_free(addrlist_t **);
4867c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
4877c478bd9Sstevel@tonic-gate }
4887c478bd9Sstevel@tonic-gate #endif
4907c478bd9Sstevel@tonic-gate #endif	/* _MPD_TABLES_H */