xref: /titanic_51/usr/src/cmd/cmd-inet/usr.sbin/in.routed/defs.h (revision e11c3f44f531fdff80941ce57c065d2ae861cefc)
17c478bd9Sstevel@tonic-gate /*
2*e11c3f44Smeem  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
37c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
47c478bd9Sstevel@tonic-gate  *
57c478bd9Sstevel@tonic-gate  * Copyright (c) 1983, 1988, 1993
67c478bd9Sstevel@tonic-gate  *	The Regents of the University of California.  All rights reserved.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * Redistribution and use in source and binary forms, with or without
97c478bd9Sstevel@tonic-gate  * modification, are permitted provided that the following conditions
107c478bd9Sstevel@tonic-gate  * are met:
117c478bd9Sstevel@tonic-gate  * 1. Redistributions of source code must retain the above copyright
127c478bd9Sstevel@tonic-gate  *    notice, this list of conditions and the following disclaimer.
137c478bd9Sstevel@tonic-gate  * 2. Redistributions in binary form must reproduce the above copyright
147c478bd9Sstevel@tonic-gate  *    notice, this list of conditions and the following disclaimer in the
157c478bd9Sstevel@tonic-gate  *    documentation and/or other materials provided with the distribution.
167c478bd9Sstevel@tonic-gate  * 3. All advertising materials mentioning features or use of this software
177c478bd9Sstevel@tonic-gate  *    must display the following acknowledgment:
187c478bd9Sstevel@tonic-gate  *	This product includes software developed by the University of
197c478bd9Sstevel@tonic-gate  *	California, Berkeley and its contributors.
207c478bd9Sstevel@tonic-gate  * 4. Neither the name of the University nor the names of its contributors
217c478bd9Sstevel@tonic-gate  *    may be used to endorse or promote products derived from this software
227c478bd9Sstevel@tonic-gate  *    without specific prior written permission.
237c478bd9Sstevel@tonic-gate  *
247c478bd9Sstevel@tonic-gate  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
257c478bd9Sstevel@tonic-gate  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
267c478bd9Sstevel@tonic-gate  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
277c478bd9Sstevel@tonic-gate  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
287c478bd9Sstevel@tonic-gate  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
297c478bd9Sstevel@tonic-gate  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
307c478bd9Sstevel@tonic-gate  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
317c478bd9Sstevel@tonic-gate  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
327c478bd9Sstevel@tonic-gate  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
337c478bd9Sstevel@tonic-gate  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
347c478bd9Sstevel@tonic-gate  * SUCH DAMAGE.
357c478bd9Sstevel@tonic-gate  *
367c478bd9Sstevel@tonic-gate  *	@(#)defs.h	8.1 (Berkeley) 6/5/93
377c478bd9Sstevel@tonic-gate  *
387c478bd9Sstevel@tonic-gate  * $FreeBSD: src/sbin/routed/defs.h,v 1.14 2000/08/11 08:24:38 sheldonh Exp $
397c478bd9Sstevel@tonic-gate  */
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate #ifndef	_DEFS_H
427c478bd9Sstevel@tonic-gate #define	_DEFS_H
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate /*
457c478bd9Sstevel@tonic-gate  * Definitions for RIPv2 routing process.
467c478bd9Sstevel@tonic-gate  *
477c478bd9Sstevel@tonic-gate  * This code is based on the 4.4BSD `routed` daemon, with extensions to
487c478bd9Sstevel@tonic-gate  * support:
497c478bd9Sstevel@tonic-gate  *	RIPv2, including variable length subnet masks.
507c478bd9Sstevel@tonic-gate  *	Router Discovery
517c478bd9Sstevel@tonic-gate  *	aggregate routes in the kernel tables.
527c478bd9Sstevel@tonic-gate  *	aggregate advertised routes.
537c478bd9Sstevel@tonic-gate  *	maintain spare routes for faster selection of another gateway
547c478bd9Sstevel@tonic-gate  *		when the current gateway dies.
557c478bd9Sstevel@tonic-gate  *	timers on routes with second granularity so that selection
567c478bd9Sstevel@tonic-gate  *		of a new route does not wait 30-60 seconds.
577c478bd9Sstevel@tonic-gate  *	tolerance of static routes.
587c478bd9Sstevel@tonic-gate  *	tell the kernel hop counts.
597c478bd9Sstevel@tonic-gate  *	use of per-interface ip_forwarding state.
607c478bd9Sstevel@tonic-gate  *
617c478bd9Sstevel@tonic-gate  * The vestigial support for other protocols has been removed.  There
627c478bd9Sstevel@tonic-gate  * is no likelihood that IETF RIPv1 or RIPv2 will ever be used with
637c478bd9Sstevel@tonic-gate  * other protocols.  The result is far smaller, faster, cleaner, and
647c478bd9Sstevel@tonic-gate  * perhaps understandable.
657c478bd9Sstevel@tonic-gate  *
667c478bd9Sstevel@tonic-gate  * The accumulation of special flags and kludges added over the many
677c478bd9Sstevel@tonic-gate  * years have been simplified and integrated.
687c478bd9Sstevel@tonic-gate  */
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate #ifdef __cplusplus
717c478bd9Sstevel@tonic-gate extern "C" {
727c478bd9Sstevel@tonic-gate #endif
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate #include <stdio.h>
757c478bd9Sstevel@tonic-gate #include <netdb.h>
767c478bd9Sstevel@tonic-gate #include <stdlib.h>
777c478bd9Sstevel@tonic-gate #include <unistd.h>
787c478bd9Sstevel@tonic-gate #include <errno.h>
797c478bd9Sstevel@tonic-gate #include <string.h>
807c478bd9Sstevel@tonic-gate #include <stdarg.h>
817c478bd9Sstevel@tonic-gate #include <syslog.h>
827c478bd9Sstevel@tonic-gate #include <time.h>
837c478bd9Sstevel@tonic-gate #include <md5.h>
847c478bd9Sstevel@tonic-gate #include <libintl.h>
857c478bd9Sstevel@tonic-gate #include <locale.h>
867c478bd9Sstevel@tonic-gate #include "radix.h"
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate #include <sys/time.h>
897c478bd9Sstevel@tonic-gate #include <sys/types.h>
907c478bd9Sstevel@tonic-gate #include <sys/param.h>
917c478bd9Sstevel@tonic-gate #include <sys/ioctl.h>
927c478bd9Sstevel@tonic-gate #include <sys/socket.h>
937c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate #include <net/if.h>
967c478bd9Sstevel@tonic-gate #include <net/route.h>
977c478bd9Sstevel@tonic-gate #include <net/if_dl.h>
987c478bd9Sstevel@tonic-gate #include <netinet/in.h>
997c478bd9Sstevel@tonic-gate #include <arpa/inet.h>
1007c478bd9Sstevel@tonic-gate #define	RIPVERSION RIPv2
1017c478bd9Sstevel@tonic-gate #include <protocols/routed.h>
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate #define	DAY (24*60*60)
1057c478bd9Sstevel@tonic-gate #define	NEVER DAY			/* a long time */
1067c478bd9Sstevel@tonic-gate #define	EPOCH NEVER			/* bias time by this to avoid <0 */
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate /*
1097c478bd9Sstevel@tonic-gate  * Scan the kernel regularly to see if any interfaces have appeared or been
1107c478bd9Sstevel@tonic-gate  * turned off.
1117c478bd9Sstevel@tonic-gate  */
1127c478bd9Sstevel@tonic-gate #define	CHECK_BAD_INTERVAL	5	/* when an interface is known bad */
1137c478bd9Sstevel@tonic-gate #define	CHECK_ACT_INTERVAL	30	/* when advertising */
1147c478bd9Sstevel@tonic-gate #define	CHECK_QUIET_INTERVAL	300	/* when not */
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate /*
1177c478bd9Sstevel@tonic-gate  * Limit the seconds in the timeval structure "s" to "l" seconds, but only
1187c478bd9Sstevel@tonic-gate  * if l is less than the current seconds in s.  This is used to shorten
1197c478bd9Sstevel@tonic-gate  * certain timers to ensure that scheduled events occur sooner than
1207c478bd9Sstevel@tonic-gate  * originally scheduled.
1217c478bd9Sstevel@tonic-gate  */
1227c478bd9Sstevel@tonic-gate #define	LIM_SEC(s, l) ((s).tv_sec = MIN((s).tv_sec, (l)))
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate /*
1257c478bd9Sstevel@tonic-gate  * Metric used for fake default routes.  It ought to be 15, but when
1267c478bd9Sstevel@tonic-gate  * processing advertised routes, previous versions of `routed` added
1277c478bd9Sstevel@tonic-gate  * to the received metric and discarded the route if the total was 16
1287c478bd9Sstevel@tonic-gate  * or larger.
1297c478bd9Sstevel@tonic-gate  */
1307c478bd9Sstevel@tonic-gate #define	FAKE_METRIC (HOPCNT_INFINITY-2)
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate /* Router Discovery parameters */
1347c478bd9Sstevel@tonic-gate #define	MAX_MAXADVERTISEINTERVAL	1800
1357c478bd9Sstevel@tonic-gate #define	MIN_MAXADVERTISEINTERVAL	4
1367c478bd9Sstevel@tonic-gate #define	DEF_MAXADVERTISEINTERVAL	600
1377c478bd9Sstevel@tonic-gate #define	DEF_PREFERENCELEVEL		0
1387c478bd9Sstevel@tonic-gate #define	MIN_PREFERENCELEVEL		0x80000000
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate #define	MAX_INITIAL_ADVERT_INTERVAL	16
1417c478bd9Sstevel@tonic-gate #define	MAX_INITIAL_ADVERTS		3
1427c478bd9Sstevel@tonic-gate #define	MAX_RESPONSE_DELAY		2
1437c478bd9Sstevel@tonic-gate 
1447c478bd9Sstevel@tonic-gate #define	MAX_SOLICITATION_DELAY		1
1457c478bd9Sstevel@tonic-gate #define	SOLICITATION_INTERVAL		3
1467c478bd9Sstevel@tonic-gate #define	MAX_SOLICITATIONS		3
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate /*
1497c478bd9Sstevel@tonic-gate  * convert between signed, balanced around zero,
1507c478bd9Sstevel@tonic-gate  * and unsigned zero-based preferences
1517c478bd9Sstevel@tonic-gate  */
1527c478bd9Sstevel@tonic-gate #define	SIGN_PREF(p) ((p) ^ MIN_PREFERENCELEVEL)
1537c478bd9Sstevel@tonic-gate #define	UNSIGN_PREF(p) SIGN_PREF(p)
1547c478bd9Sstevel@tonic-gate 
1557c478bd9Sstevel@tonic-gate /*
1567c478bd9Sstevel@tonic-gate  * Bloated packet size for systems that simply add authentication to
1577c478bd9Sstevel@tonic-gate  * full-sized packets
1587c478bd9Sstevel@tonic-gate  */
1597c478bd9Sstevel@tonic-gate #define	OVER_MAXPACKETSIZE (MAXPACKETSIZE+sizeof (struct netinfo)*2)
1607c478bd9Sstevel@tonic-gate /* typical packet buffers */
1617c478bd9Sstevel@tonic-gate union pkt_buf {
1627c478bd9Sstevel@tonic-gate 	uint8_t	packet[OVER_MAXPACKETSIZE*2];
1637c478bd9Sstevel@tonic-gate 	struct	rip rip;
1647c478bd9Sstevel@tonic-gate };
1657c478bd9Sstevel@tonic-gate 
1663173664eSapersson extern struct dr *drs;
1673173664eSapersson 
1687c478bd9Sstevel@tonic-gate /*
1697c478bd9Sstevel@tonic-gate  * IF_NAME_LEN is the maximum size of interface names represented within
1707c478bd9Sstevel@tonic-gate  * in.routed.  Regular Solaris interfaces have names of at most LIFNAMESIZ
1717c478bd9Sstevel@tonic-gate  * characters, but in.routed has remote interfaces represented internally
1727c478bd9Sstevel@tonic-gate  * as "remote(<gatewayname>)", where <gatewayname> is a hostname or IP
1737c478bd9Sstevel@tonic-gate  * address.  IF_NAME_LEN needs to be large enough to also hold such
1747c478bd9Sstevel@tonic-gate  * interface names as well.
1757c478bd9Sstevel@tonic-gate  */
1767c478bd9Sstevel@tonic-gate #define	IF_NAME_LEN	(MAXHOSTNAMELEN + sizeof ("remote()") + 1)
1777c478bd9Sstevel@tonic-gate 
1787c478bd9Sstevel@tonic-gate /*
1797c478bd9Sstevel@tonic-gate  * No more routes than this, to protect ourself in case something goes
1807c478bd9Sstevel@tonic-gate  * whacko and starts broadcasting zillions of bogus routes.
1817c478bd9Sstevel@tonic-gate  */
1827c478bd9Sstevel@tonic-gate #define	MAX_ROUTES  (128*1024)
1837c478bd9Sstevel@tonic-gate 
1847c478bd9Sstevel@tonic-gate enum origin {
1857c478bd9Sstevel@tonic-gate 	RO_NONE,	/* empty slot */
1867c478bd9Sstevel@tonic-gate 	RO_RIP,		/* learnt from RIP */
1877c478bd9Sstevel@tonic-gate 	RO_RDISC,	/* learnt from RDISC */
1887c478bd9Sstevel@tonic-gate 	RO_STATIC,	/* learnt from kernel */
1897c478bd9Sstevel@tonic-gate 	RO_LOOPBCK,	/* loopback route */
1907c478bd9Sstevel@tonic-gate 	RO_PTOPT,	/* point-to-point route */
1917c478bd9Sstevel@tonic-gate 	RO_NET_SYN,	/* fake net route for subnet */
1927c478bd9Sstevel@tonic-gate 	RO_IF,		/* interface route */
1937c478bd9Sstevel@tonic-gate 	RO_FILE		/* from /etc/gateways */
1947c478bd9Sstevel@tonic-gate };
1957c478bd9Sstevel@tonic-gate 
1967c478bd9Sstevel@tonic-gate /*
1977c478bd9Sstevel@tonic-gate  * Main, daemon routing table structure
1987c478bd9Sstevel@tonic-gate  */
1997c478bd9Sstevel@tonic-gate struct rt_spare {
2007c478bd9Sstevel@tonic-gate 	struct interface *rts_ifp;
2017c478bd9Sstevel@tonic-gate 	uint32_t	rts_gate;	/* forward packets here */
2027c478bd9Sstevel@tonic-gate 	uint32_t	rts_router;	/* on this router's authority */
2037c478bd9Sstevel@tonic-gate 	uint8_t		rts_metric;
2047c478bd9Sstevel@tonic-gate 	enum origin	rts_origin;
2057c478bd9Sstevel@tonic-gate 	uint16_t	rts_tag;
2067c478bd9Sstevel@tonic-gate 	time_t		rts_time;	/* timer to junk stale routes */
2077c478bd9Sstevel@tonic-gate 	uint32_t	rts_de_ag;	/* de-aggregation level */
2087c478bd9Sstevel@tonic-gate 	uint16_t	rts_flags;
2097c478bd9Sstevel@tonic-gate };
2107c478bd9Sstevel@tonic-gate 
2117c478bd9Sstevel@tonic-gate #define	RTS_EXTERNAL	0x0001	/* handled by other routing protocol e.g. EGP */
2127c478bd9Sstevel@tonic-gate #define	SPARE_INC	2
2137c478bd9Sstevel@tonic-gate #define	EMPTY_RT_SPARE	{ NULL, 0, 0, HOPCNT_INFINITY, RO_NONE, 0, 0, 0, 0 }
2147c478bd9Sstevel@tonic-gate 
2157c478bd9Sstevel@tonic-gate struct rt_entry {
2167c478bd9Sstevel@tonic-gate 	struct radix_node rt_nodes[2];	/* radix tree glue */
2177c478bd9Sstevel@tonic-gate 	struct sockaddr_in rt_dst_sock;
2187c478bd9Sstevel@tonic-gate 	time_t		rt_poison_time;	/* advertised metric */
2197c478bd9Sstevel@tonic-gate 	in_addr_t	rt_mask;
2207c478bd9Sstevel@tonic-gate 	uint32_t	rt_seqno;	/* when last changed */
2217c478bd9Sstevel@tonic-gate 	uint16_t	rt_state;
2227c478bd9Sstevel@tonic-gate #define	RS_IF		0x0001	/* for network interface */
2237c478bd9Sstevel@tonic-gate #define	RS_NET_INT	0x0002	/* authority route */
2247c478bd9Sstevel@tonic-gate #define	RS_NET_SYN	0x0004	/* fake net route for subnet */
2257c478bd9Sstevel@tonic-gate #define	RS_NO_NET_SYN (RS_LOCAL | RS_IF)
2267c478bd9Sstevel@tonic-gate #define	RS_SUBNET	0x0008	/* subnet route from any source */
2277c478bd9Sstevel@tonic-gate #define	RS_LOCAL	0x0010	/* loopback for pt-to-pt */
2287c478bd9Sstevel@tonic-gate #define	RS_MHOME	0x0020	/* from -m */
2297c478bd9Sstevel@tonic-gate #define	RS_STATIC	0x0040	/* from the kernel */
2307c478bd9Sstevel@tonic-gate #define	RS_NOPROPAGATE	0x0080	/* route which must not be propagated */
2317c478bd9Sstevel@tonic-gate #define	RS_BADIF	0x0100	/* route through dead ifp */
2327c478bd9Sstevel@tonic-gate 
2337c478bd9Sstevel@tonic-gate 	uint8_t		rt_poison_metric;	/* to notice maximum recently */
2347c478bd9Sstevel@tonic-gate 	uint_t		rt_num_spares;
2357c478bd9Sstevel@tonic-gate 	struct rt_spare  *rt_spares;
2367c478bd9Sstevel@tonic-gate };
2377c478bd9Sstevel@tonic-gate #define	rt_dst	    rt_dst_sock.sin_addr.s_addr
2387c478bd9Sstevel@tonic-gate #define	rt_ifp	    rt_spares[0].rts_ifp
2397c478bd9Sstevel@tonic-gate #define	rt_gate	    rt_spares[0].rts_gate
2407c478bd9Sstevel@tonic-gate #define	rt_router   rt_spares[0].rts_router
2417c478bd9Sstevel@tonic-gate #define	rt_metric   rt_spares[0].rts_metric
2427c478bd9Sstevel@tonic-gate #define	rt_tag	    rt_spares[0].rts_tag
2437c478bd9Sstevel@tonic-gate #define	rt_time	    rt_spares[0].rts_time
2447c478bd9Sstevel@tonic-gate #define	rt_de_ag    rt_spares[0].rts_de_ag
2457c478bd9Sstevel@tonic-gate 
2467c478bd9Sstevel@tonic-gate #define	HOST_MASK	0xffffffffU
2477c478bd9Sstevel@tonic-gate #define	RT_ISHOST(rt)	((rt)->rt_mask == HOST_MASK)
2487c478bd9Sstevel@tonic-gate 
2497c478bd9Sstevel@tonic-gate /*
2507c478bd9Sstevel@tonic-gate  * Determine if a route should be aged.  Age all routes that are:
2517c478bd9Sstevel@tonic-gate  * Not from -g, -m, nor static routes from the kernel
2527c478bd9Sstevel@tonic-gate  * not unbroken interface routes but not broken interfaces
2537c478bd9Sstevel@tonic-gate  * not learnt from RDISC or from /etc/gateways
2547c478bd9Sstevel@tonic-gate  * nor non-passive, remote interfaces that are not aliases
2557c478bd9Sstevel@tonic-gate  * (i.e. remote & metric=0)
2567c478bd9Sstevel@tonic-gate  */
2577c478bd9Sstevel@tonic-gate #define	AGE_RT(rt_state, rts_origin, ifp) \
2587c478bd9Sstevel@tonic-gate 	((!((rt_state) & (RS_MHOME | RS_STATIC | RS_NET_SYN)) && \
2597c478bd9Sstevel@tonic-gate 	(rts_origin != RO_RDISC) && \
2607c478bd9Sstevel@tonic-gate 	(rts_origin != RO_FILE)) && \
2617c478bd9Sstevel@tonic-gate 	(!((rt_state) & RS_IF) || \
2627c478bd9Sstevel@tonic-gate 	    (ifp) == NULL || \
2637c478bd9Sstevel@tonic-gate 		(((ifp)->int_state & IS_REMOTE) && \
2647c478bd9Sstevel@tonic-gate 		    !((ifp)->int_state & IS_PASSIVE))))
2657c478bd9Sstevel@tonic-gate 
2667c478bd9Sstevel@tonic-gate /*
2677c478bd9Sstevel@tonic-gate  * true if A is better than B
2687c478bd9Sstevel@tonic-gate  * Better if
2697c478bd9Sstevel@tonic-gate  *	- A is not a poisoned route
2707c478bd9Sstevel@tonic-gate  *	- and A is not stale
2717c478bd9Sstevel@tonic-gate  *	- and either:
2727c478bd9Sstevel@tonic-gate  *		- A has a shorter path
2737c478bd9Sstevel@tonic-gate  *		- or the router is speaking for itself
2747c478bd9Sstevel@tonic-gate  *		- or B has the same metric and isn't stale
2757c478bd9Sstevel@tonic-gate  *		- or A is a host route advertised by a system for itself
2767c478bd9Sstevel@tonic-gate  */
2777c478bd9Sstevel@tonic-gate #define	BETTER_LINK(rt, A, B) ((A)->rts_metric < HOPCNT_INFINITY &&	\
2787c478bd9Sstevel@tonic-gate 			now_stale <= (A)->rts_time &&		\
2797c478bd9Sstevel@tonic-gate 			((A)->rts_metric < (B)->rts_metric ||	\
2807c478bd9Sstevel@tonic-gate 			((A)->rts_gate == (A)->rts_router &&	\
2817c478bd9Sstevel@tonic-gate 			(B)->rts_gate != (B)->rts_router) || \
2827c478bd9Sstevel@tonic-gate 			((A)->rts_metric == (B)->rts_metric &&	\
2837c478bd9Sstevel@tonic-gate 				now_stale > (B)->rts_time) ||	\
2847c478bd9Sstevel@tonic-gate 			(RT_ISHOST(rt) &&			\
2857c478bd9Sstevel@tonic-gate 				(rt)->rt_dst == (A)->rts_router &&	\
2867c478bd9Sstevel@tonic-gate 				(A)->rts_metric == (B)->rts_metric)))
2877c478bd9Sstevel@tonic-gate 
2887c478bd9Sstevel@tonic-gate struct hlinkage {
2897c478bd9Sstevel@tonic-gate 	void *hl_next;
2907c478bd9Sstevel@tonic-gate 	void **hl_prev;
2917c478bd9Sstevel@tonic-gate };
2927c478bd9Sstevel@tonic-gate 
2937c478bd9Sstevel@tonic-gate /*
2947c478bd9Sstevel@tonic-gate  * A "physical_interface" represents the actual hardware.  It is also
2957c478bd9Sstevel@tonic-gate  * a container for a list of the interfaces that have the same ifIndex
2967c478bd9Sstevel@tonic-gate  * number.  This will consist of zero or one "main" interface plus
2977c478bd9Sstevel@tonic-gate  * zero or more IS_ALIAS interfaces.
2987c478bd9Sstevel@tonic-gate  */
2997c478bd9Sstevel@tonic-gate struct physical_interface {
3007c478bd9Sstevel@tonic-gate 	struct hlinkage phyi_link;
3017c478bd9Sstevel@tonic-gate 	uint32_t phyi_index;
3027c478bd9Sstevel@tonic-gate 	struct interface *phyi_interface;
3037c478bd9Sstevel@tonic-gate 	struct phyi_data {
3047c478bd9Sstevel@tonic-gate 		uint32_t	ipackets;	/* previous network stats */
3057c478bd9Sstevel@tonic-gate 		uint32_t	ierrors;
3067c478bd9Sstevel@tonic-gate 		uint32_t	opackets;
3077c478bd9Sstevel@tonic-gate 		uint32_t	oerrors;
3087c478bd9Sstevel@tonic-gate 		time_t	ts;		/* timestamp on network stats */
3097c478bd9Sstevel@tonic-gate 	} phyi_data;
3107c478bd9Sstevel@tonic-gate 	char phyi_name[IF_NAME_LEN+1];
3117c478bd9Sstevel@tonic-gate };
3127c478bd9Sstevel@tonic-gate 
3137c478bd9Sstevel@tonic-gate /*
3147c478bd9Sstevel@tonic-gate  * An "interface" is similar to a kernel ifnet structure, except it also
3157c478bd9Sstevel@tonic-gate  * handles "logical" or "IS_REMOTE" interfaces (remote gateways).
3167c478bd9Sstevel@tonic-gate  */
3177c478bd9Sstevel@tonic-gate struct interface {
3187c478bd9Sstevel@tonic-gate 	/*
3197c478bd9Sstevel@tonic-gate 	 * We keep interfaces in a variety of data structures to
3207c478bd9Sstevel@tonic-gate 	 * optimize for different types of searches.
3217c478bd9Sstevel@tonic-gate 	 */
3227c478bd9Sstevel@tonic-gate 	struct hlinkage int_link;
3237c478bd9Sstevel@tonic-gate #define	int_next	int_link.hl_next
3247c478bd9Sstevel@tonic-gate 	struct hlinkage int_ahash;	/* by address */
3257c478bd9Sstevel@tonic-gate 	struct hlinkage int_bhash;	/* by broadcast address */
3267c478bd9Sstevel@tonic-gate 	struct hlinkage int_nhash;	/* by name */
3277c478bd9Sstevel@tonic-gate 	struct hlinkage int_ilist;	/* ifIndex list */
3287c478bd9Sstevel@tonic-gate 	struct physical_interface *int_phys;	/* backpointer */
3297c478bd9Sstevel@tonic-gate 	char		int_name[IF_NAME_LEN+1];
3307c478bd9Sstevel@tonic-gate 	in_addr_t	int_addr;	/* address on this host (net order) */
3317c478bd9Sstevel@tonic-gate 	in_addr_t	int_brdaddr;	/* broadcast address (n) */
3327c478bd9Sstevel@tonic-gate 	in_addr_t	int_dstaddr;	/* other end of pt-to-pt link (n) */
3337c478bd9Sstevel@tonic-gate 	in_addr_t	int_net;	/* working network # (host order) */
3347c478bd9Sstevel@tonic-gate 	in_addr_t	int_mask;	/* working net mask (host order) */
3357c478bd9Sstevel@tonic-gate 	in_addr_t	int_ripv1_mask;	/* for inferring a mask (n) */
3367c478bd9Sstevel@tonic-gate 	in_addr_t	int_std_addr;	/* class A/B/C address (n) */
3377c478bd9Sstevel@tonic-gate 	in_addr_t	int_std_net;	/* class A/B/C network (h) */
3387c478bd9Sstevel@tonic-gate 	in_addr_t	int_std_mask;	/* class A/B/C netmask (h) */
3397c478bd9Sstevel@tonic-gate 	in_addr_t	int_ripout_addr; /* RIP pkts sent to this addr */
340aee32e3dScarlsonj 	uint64_t	int_if_flags;	/* some bits copied from kernel */
3417c478bd9Sstevel@tonic-gate 	uint32_t	int_state;
3427c478bd9Sstevel@tonic-gate 	time_t		int_act_time;	/* last thought healthy (IS_REMOTE) */
3437c478bd9Sstevel@tonic-gate 	time_t		int_query_time;	/* last query (IS_REMOTE) */
3447c478bd9Sstevel@tonic-gate 	uint32_t	int_transitions; /* times gone up-down */
3457c478bd9Sstevel@tonic-gate 	uint8_t		int_metric;
3467c478bd9Sstevel@tonic-gate 	uint8_t		int_d_metric;	/* for faked default route */
3477c478bd9Sstevel@tonic-gate #define	MAX_AUTH_KEYS 5
3487c478bd9Sstevel@tonic-gate 	struct auth {			/* authentication info */
3497c478bd9Sstevel@tonic-gate 		time_t		start, end;
3507c478bd9Sstevel@tonic-gate 		uint16_t	type;
3517c478bd9Sstevel@tonic-gate 		/*
3527c478bd9Sstevel@tonic-gate 		 * Although the following key is just an array of bytes,
3537c478bd9Sstevel@tonic-gate 		 * in.routed is currently limited to ascii characters
3547c478bd9Sstevel@tonic-gate 		 * because of its configuration syntax and parsing.
3557c478bd9Sstevel@tonic-gate 		 */
3567c478bd9Sstevel@tonic-gate 		uint8_t		key[RIP_AUTH_PW_LEN +1];
3577c478bd9Sstevel@tonic-gate 		uint8_t		keyid;
3587c478bd9Sstevel@tonic-gate 		uint8_t		warnedflag;
3597c478bd9Sstevel@tonic-gate 	} int_auth[MAX_AUTH_KEYS];
3607c478bd9Sstevel@tonic-gate 	/* router discovery parameters */
3617c478bd9Sstevel@tonic-gate 	int		int_rdisc_pref;	/* signed preference to advertise */
3627c478bd9Sstevel@tonic-gate 	uint32_t	int_rdisc_int;	/* MaxAdvertiseInterval */
3637c478bd9Sstevel@tonic-gate 	uint32_t	int_rdisc_cnt;
3647c478bd9Sstevel@tonic-gate 	struct timeval int_rdisc_timer;
3657c478bd9Sstevel@tonic-gate };
3667c478bd9Sstevel@tonic-gate 
3677c478bd9Sstevel@tonic-gate /* bits in int_state */
3687c478bd9Sstevel@tonic-gate #define	IS_ALIAS	    0x00000001	/* interface alias */
3697c478bd9Sstevel@tonic-gate #define	IS_SUBNET	    0x00000002	/* interface on subnetted network */
3707c478bd9Sstevel@tonic-gate #define	IS_REMOTE	    0x00000004	/* interface is not on this machine */
3717c478bd9Sstevel@tonic-gate #define	IS_PASSIVE	    0x00000008	/* remote and does not do RIP */
3727c478bd9Sstevel@tonic-gate #define	IS_EXTERNAL	    0x00000010	/* handled by EGP or something */
3737c478bd9Sstevel@tonic-gate #define	IS_CHECKED	    0x00000020	/* still exists */
3747c478bd9Sstevel@tonic-gate #define	IS_ALL_HOSTS	    0x00000040	/* in INADDR_ALLHOSTS_GROUP */
3757c478bd9Sstevel@tonic-gate #define	IS_ALL_ROUTERS	    0x00000080	/* in INADDR_ALLROUTERS_GROUP */
3767c478bd9Sstevel@tonic-gate #define	IS_DISTRUST	    0x00000100	/* ignore untrusted routers */
3777c478bd9Sstevel@tonic-gate #define	IS_REDIRECT_OK	    0x00000200	/* accept ICMP redirects */
3787c478bd9Sstevel@tonic-gate #define	IS_BROKE	    0x00000400	/* seems to be broken */
3797c478bd9Sstevel@tonic-gate #define	IS_SICK		    0x00000800	/* seems to be broken */
3807c478bd9Sstevel@tonic-gate #define	IS_DUP		    0x00001000	/* duplicates another interface */
3817c478bd9Sstevel@tonic-gate #define	IS_NEED_NET_SYN	    0x00002000	/* need RS_NET_SYN route */
3827c478bd9Sstevel@tonic-gate #define	IS_NO_AG	    0x00004000	/* do not aggregate subnets */
3837c478bd9Sstevel@tonic-gate #define	IS_NO_SUPER_AG	    0x00008000	/* do not aggregate networks */
3847c478bd9Sstevel@tonic-gate #define	IS_NO_RIPV1_IN	    0x00010000	/* no RIPv1 input at all */
3857c478bd9Sstevel@tonic-gate #define	IS_NO_RIPV2_IN	    0x00020000	/* no RIPv2 input at all */
3867c478bd9Sstevel@tonic-gate #define	IS_NO_RIP_IN	(IS_NO_RIPV1_IN | IS_NO_RIPV2_IN)
3877c478bd9Sstevel@tonic-gate #define	IS_RIP_IN_OFF(s) (((s) & IS_NO_RIP_IN) == IS_NO_RIP_IN)
3887c478bd9Sstevel@tonic-gate #define	IS_NO_RIPV1_OUT	    0x00040000	/* no RIPv1 output at all */
3897c478bd9Sstevel@tonic-gate #define	IS_NO_RIPV2_OUT	    0x00080000	/* no RIPv2 output at all */
3907c478bd9Sstevel@tonic-gate #define	IS_NO_RIP_OUT	(IS_NO_RIPV1_OUT | IS_NO_RIPV2_OUT)
3917c478bd9Sstevel@tonic-gate #define	IS_NO_RIP	(IS_NO_RIP_OUT | IS_NO_RIP_IN)
3927c478bd9Sstevel@tonic-gate #define	IS_RIP_OUT_OFF(s) (((s) & IS_NO_RIP_OUT) == IS_NO_RIP_OUT)
3937c478bd9Sstevel@tonic-gate #define	IS_RIP_OFF(s)	(((s) & IS_NO_RIP) == IS_NO_RIP)
3947c478bd9Sstevel@tonic-gate #define	IS_NO_RIP_MCAST	    0x00100000	/* broadcast RIPv2 */
3957c478bd9Sstevel@tonic-gate #define	IS_NO_ADV_IN	    0x00200000	/* do not listen to advertisements */
3967c478bd9Sstevel@tonic-gate #define	IS_NO_SOL_OUT	    0x00400000	/* send no solicitations */
3977c478bd9Sstevel@tonic-gate #define	IS_SOL_OUT	    0x00800000	/* send solicitations */
3987c478bd9Sstevel@tonic-gate #define	GROUP_IS_SOL_OUT (IS_SOL_OUT | IS_NO_SOL_OUT)
3997c478bd9Sstevel@tonic-gate #define	IS_NO_ADV_OUT	    0x01000000	/* do not advertise rdisc */
4007c478bd9Sstevel@tonic-gate #define	IS_ADV_OUT	    0x02000000	/* advertise rdisc */
4017c478bd9Sstevel@tonic-gate #define	GROUP_IS_ADV_OUT (IS_NO_ADV_OUT | IS_ADV_OUT)
4027c478bd9Sstevel@tonic-gate #define	IS_BCAST_RDISC	    0x04000000	/* broadcast instead of multicast */
4037c478bd9Sstevel@tonic-gate #define	IS_NO_RDISC	(IS_NO_ADV_IN | IS_NO_SOL_OUT | IS_NO_ADV_OUT)
4047c478bd9Sstevel@tonic-gate #define	IS_PM_RDISC	    0x08000000	/* poor-man's router discovery */
4057c478bd9Sstevel@tonic-gate #define	IS_NO_HOST	    0x10000000	/* disallow host routes */
4067c478bd9Sstevel@tonic-gate #define	IS_SUPPRESS_RDISC   0x20000000  /* don't send rdisc advs */
4077c478bd9Sstevel@tonic-gate #define	IS_FLUSH_RDISC	    0x40000000	/* flush client rdisc caches */
4087c478bd9Sstevel@tonic-gate 
4097c478bd9Sstevel@tonic-gate /*
4107c478bd9Sstevel@tonic-gate  * passive interfaces are added through gwkludge
4117c478bd9Sstevel@tonic-gate  */
4127c478bd9Sstevel@tonic-gate #define	IS_PASSIVE_IFP(ifp) \
4137c478bd9Sstevel@tonic-gate 	(((ifp)->int_state & (IS_REMOTE|IS_PASSIVE|IS_EXTERNAL|IS_ALIAS)) == \
4147c478bd9Sstevel@tonic-gate 	    (IS_REMOTE|IS_PASSIVE))
4157c478bd9Sstevel@tonic-gate 
4167c478bd9Sstevel@tonic-gate /*
417*e11c3f44Smeem  * Is an IP interface up?
4187c478bd9Sstevel@tonic-gate  */
419*e11c3f44Smeem #define	IS_IFF_UP(f)	(((f) & (IFF_UP|IFF_RUNNING)) == (IFF_UP|IFF_RUNNING))
4207c478bd9Sstevel@tonic-gate 
4217c478bd9Sstevel@tonic-gate /*
4227c478bd9Sstevel@tonic-gate  * This defines interfaces that we should not use for advertising or
4237c478bd9Sstevel@tonic-gate  * soliciting routes by way of RIP and rdisc.  Interfaces marked this
4247c478bd9Sstevel@tonic-gate  * way do not count for purposes of determining how many interfaces
4257c478bd9Sstevel@tonic-gate  * this router has.
4267c478bd9Sstevel@tonic-gate  */
4277c478bd9Sstevel@tonic-gate #define	IS_IFF_QUIET(f)	((f) & (IFF_LOOPBACK|IFF_NORTEXCH|IFF_NOXMIT))
4287c478bd9Sstevel@tonic-gate 
4297c478bd9Sstevel@tonic-gate /*
4307c478bd9Sstevel@tonic-gate  * This defines interfaces that we can use for advertising routes by way of
4317c478bd9Sstevel@tonic-gate  * RIP and rdisc.
4327c478bd9Sstevel@tonic-gate  */
4337c478bd9Sstevel@tonic-gate #define	IS_IFF_ROUTING(f) \
4347c478bd9Sstevel@tonic-gate 	(((f) & IFF_ROUTER) && !((f) & (IFF_NORTEXCH|IFF_NOXMIT)))
4357c478bd9Sstevel@tonic-gate 
4367c478bd9Sstevel@tonic-gate /* Information for aggregating routes */
4377c478bd9Sstevel@tonic-gate #define	NUM_AG_SLOTS	32
4387c478bd9Sstevel@tonic-gate struct ag_info {
4397c478bd9Sstevel@tonic-gate 	struct ag_info *ag_fine;	/* slot with finer netmask */
4407c478bd9Sstevel@tonic-gate 	struct ag_info *ag_cors;	/* more coarse netmask */
4417c478bd9Sstevel@tonic-gate 	in_addr_t	ag_dst_h;	/* destination in host byte order */
4427c478bd9Sstevel@tonic-gate 	in_addr_t	ag_mask;
4437c478bd9Sstevel@tonic-gate 	in_addr_t	ag_gate;
4447c478bd9Sstevel@tonic-gate 	struct interface *ag_ifp;
4457c478bd9Sstevel@tonic-gate 	in_addr_t	ag_nhop;
4467c478bd9Sstevel@tonic-gate 	uint8_t		ag_metric;	/* metric to be advertised */
4477c478bd9Sstevel@tonic-gate 	uint8_t		ag_pref;	/* aggregate based on this */
4487c478bd9Sstevel@tonic-gate 	uint32_t	ag_seqno;
4497c478bd9Sstevel@tonic-gate 	uint16_t	ag_tag;
4507c478bd9Sstevel@tonic-gate 	uint16_t	ag_state;
4517c478bd9Sstevel@tonic-gate #define	    AGS_SUPPRESS    0x001	/* combine with coarser mask */
4527c478bd9Sstevel@tonic-gate #define	    AGS_AGGREGATE   0x002	/* synthesize combined routes */
4537c478bd9Sstevel@tonic-gate #define	    AGS_REDUN0	    0x004	/* redundant, finer routes output */
4547c478bd9Sstevel@tonic-gate #define	    AGS_REDUN1	    0x008
4557c478bd9Sstevel@tonic-gate #define	    AG_IS_REDUN(state) (((state) & (AGS_REDUN0 | AGS_REDUN1)) \
4567c478bd9Sstevel@tonic-gate 				== (AGS_REDUN0 | AGS_REDUN1))
4577c478bd9Sstevel@tonic-gate #define	    AGS_GATEWAY	    0x010	/* tell kernel RTF_GATEWAY */
4587c478bd9Sstevel@tonic-gate #define	    AGS_IF	    0x020	/* for an interface */
4597c478bd9Sstevel@tonic-gate #define	    AGS_RIPV2	    0x040	/* send only as RIPv2 */
4607c478bd9Sstevel@tonic-gate #define	    AGS_FINE_GATE   0x080	/* ignore differing ag_gate when */
4617c478bd9Sstevel@tonic-gate 					/* this has the finer netmask */
4627c478bd9Sstevel@tonic-gate #define	    AGS_CORS_GATE   0x100	/* ignore differing gate when this */
4637c478bd9Sstevel@tonic-gate 					/* has the coarser netmasks */
4647c478bd9Sstevel@tonic-gate #define	    AGS_SPLIT_HZ    0x200	/* suppress for split horizon */
4657c478bd9Sstevel@tonic-gate #define	    AGS_PASSIVE    0x400	/* passive "remote" interface route */
4667c478bd9Sstevel@tonic-gate #define	    AGS_FILE	    0x800	/* from /etc/gateways */
4677c478bd9Sstevel@tonic-gate 
4687c478bd9Sstevel@tonic-gate 	/* some bits are set if they are set on either route */
4697c478bd9Sstevel@tonic-gate #define	    AGS_AGGREGATE_EITHER (AGS_RIPV2 | AGS_GATEWAY | \
4707c478bd9Sstevel@tonic-gate 					AGS_SUPPRESS | AGS_CORS_GATE)
4717c478bd9Sstevel@tonic-gate };
4727c478bd9Sstevel@tonic-gate 
4737c478bd9Sstevel@tonic-gate struct khash {
4747c478bd9Sstevel@tonic-gate 	struct khash *k_next;
4757c478bd9Sstevel@tonic-gate 	in_addr_t	k_dst;
4767c478bd9Sstevel@tonic-gate 	in_addr_t	k_mask;
4777c478bd9Sstevel@tonic-gate 	in_addr_t	k_gate;
4787c478bd9Sstevel@tonic-gate 	struct interface *k_ifp;
4797c478bd9Sstevel@tonic-gate 	short		k_metric;
4807c478bd9Sstevel@tonic-gate 	ushort_t	k_state;	/* KS_* */
4817c478bd9Sstevel@tonic-gate 	time_t	k_keep;
4827c478bd9Sstevel@tonic-gate 	time_t	k_redirect_time;	/* when redirected route 1st seen */
4837c478bd9Sstevel@tonic-gate };
4847c478bd9Sstevel@tonic-gate 
4857c478bd9Sstevel@tonic-gate /* bit flags for k_state; shared between table.c and trace.c */
4867c478bd9Sstevel@tonic-gate #define	    KS_NEW	0x0001
4877c478bd9Sstevel@tonic-gate #define	    KS_DELETE	0x0002		/* need to delete the route */
4887c478bd9Sstevel@tonic-gate #define	    KS_ADD	0x0004		/* add to the kernel */
4897c478bd9Sstevel@tonic-gate #define	    KS_CHANGE	0x0008		/* tell kernel to change the route */
4907c478bd9Sstevel@tonic-gate #define	    KS_DEL_ADD	0x0010		/* delete & add to change the kernel */
4917c478bd9Sstevel@tonic-gate #define	    KS_STATIC	0x0020		/* Static flag in kernel */
4927c478bd9Sstevel@tonic-gate #define	    KS_GATEWAY	0x0040		/* G flag in kernel */
4937c478bd9Sstevel@tonic-gate #define	    KS_DYNAMIC	0x0080		/* result of redirect */
4947c478bd9Sstevel@tonic-gate #define	    KS_DELETED	0x0100		/* already deleted from kernel */
4957c478bd9Sstevel@tonic-gate #define	    KS_PRIVATE	0x0200		/* Private flag in kernel */
4967c478bd9Sstevel@tonic-gate #define	    KS_CHECK	0x0400
4977c478bd9Sstevel@tonic-gate #define	    KS_IF	0x0800		/* interface route */
4987c478bd9Sstevel@tonic-gate #define	    KS_PASSIVE	0x1000		/* passive remote interface route */
4997c478bd9Sstevel@tonic-gate #define	    KS_DEPRE_IF	0x2000		/* IPMP deprecated interface route */
5007c478bd9Sstevel@tonic-gate #define	    KS_FILE	0x4000		/* from /etc/gateways */
5017c478bd9Sstevel@tonic-gate 
5027c478bd9Sstevel@tonic-gate /* default router structure */
5037c478bd9Sstevel@tonic-gate struct dr {			/* accumulated advertisements */
5047c478bd9Sstevel@tonic-gate 	struct interface *dr_ifp;
5057c478bd9Sstevel@tonic-gate 	in_addr_t	dr_gate;	/* gateway */
5067c478bd9Sstevel@tonic-gate 	time_t		dr_ts;		/* when received */
5077c478bd9Sstevel@tonic-gate 	time_t		dr_life;	/* lifetime in host byte order */
5087c478bd9Sstevel@tonic-gate 	uint32_t	dr_recv_pref;	/* received but biased preference */
5097c478bd9Sstevel@tonic-gate 	uint32_t	dr_pref;	/* preference adjusted by metric */
5107c478bd9Sstevel@tonic-gate 	uint32_t	dr_flags;
5117c478bd9Sstevel@tonic-gate #define	DR_CHANGED	1		/* received new info for known dr */
5127c478bd9Sstevel@tonic-gate };
5137c478bd9Sstevel@tonic-gate 
5147c478bd9Sstevel@tonic-gate /* parameters for interfaces */
5157c478bd9Sstevel@tonic-gate struct parm {
5167c478bd9Sstevel@tonic-gate 	struct parm 	*parm_next;
5177c478bd9Sstevel@tonic-gate 	in_addr_t	parm_net;
5187c478bd9Sstevel@tonic-gate 	in_addr_t	parm_mask;
5197c478bd9Sstevel@tonic-gate 	in_addr_t	parm_ripout_addr;
5207c478bd9Sstevel@tonic-gate 	uint32_t	parm_int_state;
5217c478bd9Sstevel@tonic-gate 	int32_t		parm_rdisc_pref;	/* signed IRDP preference */
5227c478bd9Sstevel@tonic-gate 	uint32_t	parm_rdisc_int;		/* IRDP advertising interval */
5237c478bd9Sstevel@tonic-gate 	struct auth 	parm_auth[MAX_AUTH_KEYS];
5247c478bd9Sstevel@tonic-gate 	char		parm_name[IF_NAME_LEN+1];
5257c478bd9Sstevel@tonic-gate 	uint8_t		parm_d_metric;
5267c478bd9Sstevel@tonic-gate };
5277c478bd9Sstevel@tonic-gate 
5287c478bd9Sstevel@tonic-gate /* authority for internal networks */
5297c478bd9Sstevel@tonic-gate extern struct intnet {
5307c478bd9Sstevel@tonic-gate 	struct intnet *intnet_next;
5317c478bd9Sstevel@tonic-gate 	in_addr_t	intnet_addr;	/* network byte order */
5327c478bd9Sstevel@tonic-gate 	in_addr_t	intnet_mask;
5337c478bd9Sstevel@tonic-gate 	int8_t		intnet_metric;
5347c478bd9Sstevel@tonic-gate } *intnets;
5357c478bd9Sstevel@tonic-gate 
5367c478bd9Sstevel@tonic-gate /*
5377c478bd9Sstevel@tonic-gate  * Defined RIPv1 netmasks.  These come from ripv1_mask entries in
5387c478bd9Sstevel@tonic-gate  * /etc/gateways of the form:
5397c478bd9Sstevel@tonic-gate  *
5407c478bd9Sstevel@tonic-gate  * ripv1_mask=<net>/<match>,<mask>
5417c478bd9Sstevel@tonic-gate  *
5427c478bd9Sstevel@tonic-gate  * The intended use of these structures is to give RIPv1 destinations which
5437c478bd9Sstevel@tonic-gate  * are in <net>/<match> a netmask of <mask>, where <mask> > <match>.
5447c478bd9Sstevel@tonic-gate  */
5457c478bd9Sstevel@tonic-gate extern struct r1net {
5467c478bd9Sstevel@tonic-gate 	struct r1net *r1net_next;
5477c478bd9Sstevel@tonic-gate 	in_addr_t	r1net_net;	/* host order */
5487c478bd9Sstevel@tonic-gate 	in_addr_t	r1net_match;
5497c478bd9Sstevel@tonic-gate 	in_addr_t	r1net_mask;
5507c478bd9Sstevel@tonic-gate } *r1nets;
5517c478bd9Sstevel@tonic-gate 
5527c478bd9Sstevel@tonic-gate /* trusted routers */
5537c478bd9Sstevel@tonic-gate extern struct tgate {
5547c478bd9Sstevel@tonic-gate 	struct tgate *tgate_next;
5557c478bd9Sstevel@tonic-gate 	in_addr_t	tgate_addr;
5567c478bd9Sstevel@tonic-gate #define	    MAX_TGATE_NETS 32
5577c478bd9Sstevel@tonic-gate 	struct tgate_net {
5587c478bd9Sstevel@tonic-gate 	    in_addr_t   net;	/* host order */
5597c478bd9Sstevel@tonic-gate 	    in_addr_t   mask;
5607c478bd9Sstevel@tonic-gate 	} tgate_nets[MAX_TGATE_NETS];
5617c478bd9Sstevel@tonic-gate } *tgates;
5627c478bd9Sstevel@tonic-gate 
5637c478bd9Sstevel@tonic-gate enum output_type {OUT_QUERY, OUT_UNICAST, OUT_BROADCAST, OUT_MULTICAST,
5647c478bd9Sstevel@tonic-gate 	NO_OUT_MULTICAST, NO_OUT_RIPV2};
5657c478bd9Sstevel@tonic-gate 
5667c478bd9Sstevel@tonic-gate /* common output buffers */
5677c478bd9Sstevel@tonic-gate extern struct ws_buf {
5687c478bd9Sstevel@tonic-gate 	struct rip	*buf;
5697c478bd9Sstevel@tonic-gate 	struct netinfo	*n;
5707c478bd9Sstevel@tonic-gate 	struct netinfo	*base;
5717c478bd9Sstevel@tonic-gate 	struct netinfo	*lim;
5727c478bd9Sstevel@tonic-gate 	enum output_type type;
5737c478bd9Sstevel@tonic-gate } v12buf;
5747c478bd9Sstevel@tonic-gate 
5757c478bd9Sstevel@tonic-gate extern int	stopint;		/* !=0 to stop in.routed */
5767c478bd9Sstevel@tonic-gate 
5777c478bd9Sstevel@tonic-gate extern int	rip_sock;		/* RIP socket */
5787c478bd9Sstevel@tonic-gate extern struct interface *rip_sock_interface; /* current output interface */
5797c478bd9Sstevel@tonic-gate extern int	rt_sock;		/* routing socket */
5807c478bd9Sstevel@tonic-gate extern int	rdisc_sock;		/* router-discovery raw socket */
5813173664eSapersson extern int	rdisc_mib_sock;		/* AF_UNIX mib info socket */
5827c478bd9Sstevel@tonic-gate 
5837c478bd9Sstevel@tonic-gate extern boolean_t rip_enabled;		/* is rip on? */
5847c478bd9Sstevel@tonic-gate extern boolean_t supplier;		/* process should supply updates */
5857c478bd9Sstevel@tonic-gate extern boolean_t supplier_set;		/* -s or -q requested */
5867c478bd9Sstevel@tonic-gate extern boolean_t save_space;		/* -S option 1=treat all RIP speakers */
5877c478bd9Sstevel@tonic-gate extern boolean_t ridhosts;		/* 1=reduce host routes */
5887c478bd9Sstevel@tonic-gate extern boolean_t mhome;			/* 1=want multi-homed host route */
5897c478bd9Sstevel@tonic-gate extern boolean_t advertise_mhome; 	/* 1=must continue advertising it */
5907c478bd9Sstevel@tonic-gate extern boolean_t auth_ok;		/* 1=ignore auth if we do not care */
5917c478bd9Sstevel@tonic-gate extern boolean_t no_install;		/* 1=don't install in kernel */
5927c478bd9Sstevel@tonic-gate 
5937c478bd9Sstevel@tonic-gate extern struct timeval clk;		/* system clock's idea of time */
5947c478bd9Sstevel@tonic-gate extern struct timeval epoch;		/* system clock when started */
5957c478bd9Sstevel@tonic-gate extern struct timeval now;		/* current idea of time */
5967c478bd9Sstevel@tonic-gate extern time_t	now_stale;
5977c478bd9Sstevel@tonic-gate extern time_t	now_expire;
5987c478bd9Sstevel@tonic-gate extern time_t	now_garbage;
5997c478bd9Sstevel@tonic-gate 
6007c478bd9Sstevel@tonic-gate extern struct timeval age_timer;	/* next check of old routes */
6017c478bd9Sstevel@tonic-gate extern struct timeval no_flash;		/* inhibit flash update until then */
6027c478bd9Sstevel@tonic-gate extern struct timeval rdisc_timer;	/* next advert. or solicitation */
6037c478bd9Sstevel@tonic-gate extern boolean_t rdisc_ok;			/* using solicited route */
6047c478bd9Sstevel@tonic-gate 
6057c478bd9Sstevel@tonic-gate extern struct timeval ifscan_timer;	/* time to check interfaces */
6067c478bd9Sstevel@tonic-gate 
6077c478bd9Sstevel@tonic-gate extern in_addr_t loopaddr;		/* our address on loopback */
6087c478bd9Sstevel@tonic-gate extern uint_t	tot_interfaces;		/* # of remote and local interfaces */
6097c478bd9Sstevel@tonic-gate extern uint_t	rip_interfaces;		/* # of interfaces doing RIP */
6107c478bd9Sstevel@tonic-gate extern uint_t	ripout_interfaces;	/* # of interfaces advertising RIP */
6117c478bd9Sstevel@tonic-gate extern uint_t	fwd_interfaces;		/* # of interfaces ip_forwarding=1 */
6127c478bd9Sstevel@tonic-gate extern struct interface	*ifnet;		/* all interfaces */
6137c478bd9Sstevel@tonic-gate extern size_t hash_table_sizes[];	/* list of primes for hash tables */
6147c478bd9Sstevel@tonic-gate extern boolean_t	have_ripv1_out;	/* have a RIPv1 interface */
6157c478bd9Sstevel@tonic-gate extern boolean_t	need_flash;	/* flash update needed */
6167c478bd9Sstevel@tonic-gate extern struct timeval	need_kern;	/* need to update kernel table */
6177c478bd9Sstevel@tonic-gate extern uint32_t		update_seqno;	/* a route has changed */
6187c478bd9Sstevel@tonic-gate extern struct interface dummy_ifp;	/* wildcard interface */
6197c478bd9Sstevel@tonic-gate 
6207c478bd9Sstevel@tonic-gate extern int	tracelevel, new_tracelevel;
6217c478bd9Sstevel@tonic-gate #define	MAX_TRACELEVEL 5
6227c478bd9Sstevel@tonic-gate #define	TRACERTS (tracelevel >= 5)	/* log routing socket contents */
6237c478bd9Sstevel@tonic-gate #define	TRACEKERNEL (tracelevel >= 4)	/* log kernel changes */
6247c478bd9Sstevel@tonic-gate #define	TRACECONTENTS (tracelevel >= 3)	/* display packet contents */
6257c478bd9Sstevel@tonic-gate #define	TRACEPACKETS (tracelevel >= 2)	/* note packets */
6267c478bd9Sstevel@tonic-gate #define	TRACEACTIONS (tracelevel != 0)
6277c478bd9Sstevel@tonic-gate extern FILE	*ftrace;		/* output trace file */
6287c478bd9Sstevel@tonic-gate extern char inittracename[MAXPATHLEN+1];
6297c478bd9Sstevel@tonic-gate 
6307c478bd9Sstevel@tonic-gate extern struct radix_node_head *rhead;
6317c478bd9Sstevel@tonic-gate 
6327c478bd9Sstevel@tonic-gate extern void fix_sock(int, const char *);
6337c478bd9Sstevel@tonic-gate extern void fix_select(void);
6347c478bd9Sstevel@tonic-gate extern void rip_off(void);
6357c478bd9Sstevel@tonic-gate extern void rip_on(struct interface *);
6367c478bd9Sstevel@tonic-gate 
6377c478bd9Sstevel@tonic-gate extern void bufinit(void);
6387c478bd9Sstevel@tonic-gate extern int  output(enum output_type, struct sockaddr_in *,
6397c478bd9Sstevel@tonic-gate     struct interface *, struct rip *, int);
6407c478bd9Sstevel@tonic-gate extern void clr_ws_buf(struct ws_buf *, struct auth *);
6417c478bd9Sstevel@tonic-gate extern void rip_query(void);
6427c478bd9Sstevel@tonic-gate extern void rip_bcast(int);
6437c478bd9Sstevel@tonic-gate extern void supply(struct sockaddr_in *, struct interface *,
6447c478bd9Sstevel@tonic-gate     enum output_type, int, int, boolean_t);
6457c478bd9Sstevel@tonic-gate 
6467c478bd9Sstevel@tonic-gate extern void	msglog(const char *, ...);
6477c478bd9Sstevel@tonic-gate extern void	writelog(int, const char *, ...);
6487c478bd9Sstevel@tonic-gate struct msg_limit {
6497c478bd9Sstevel@tonic-gate 	time_t	reuse;
6507c478bd9Sstevel@tonic-gate 	struct msg_sub {
6517c478bd9Sstevel@tonic-gate 		in_addr_t addr;
6527c478bd9Sstevel@tonic-gate 		time_t	until;
6537c478bd9Sstevel@tonic-gate #define	MSG_SUBJECT_N 8
6547c478bd9Sstevel@tonic-gate 	} subs[MSG_SUBJECT_N];
6557c478bd9Sstevel@tonic-gate };
6567c478bd9Sstevel@tonic-gate extern void	msglim(struct msg_limit *, in_addr_t, const char *, ...);
6577c478bd9Sstevel@tonic-gate #define	LOGERR(msg) msglog(msg ": %s", rip_strerror(errno))
6587c478bd9Sstevel@tonic-gate extern void	logbad(boolean_t, const char *, ...);
6597c478bd9Sstevel@tonic-gate #define	BADERR(dump, msg) logbad(dump, msg ": %s", rip_strerror(errno))
6607c478bd9Sstevel@tonic-gate #ifdef DEBUG
6617c478bd9Sstevel@tonic-gate #define	DBGERR(dump, msg) BADERR(dump, msg)
6627c478bd9Sstevel@tonic-gate #else
6637c478bd9Sstevel@tonic-gate #define	DBGERR(dump, msg) LOGERR(msg)
6647c478bd9Sstevel@tonic-gate #endif
6657c478bd9Sstevel@tonic-gate extern	char	*naddr_ntoa(in_addr_t);
6667c478bd9Sstevel@tonic-gate extern const char *saddr_ntoa(struct sockaddr_storage *);
6677c478bd9Sstevel@tonic-gate extern const char *rip_strerror(int errnum);
6687c478bd9Sstevel@tonic-gate extern char *if_bit_string(uint_t, boolean_t);
6697c478bd9Sstevel@tonic-gate 
6707c478bd9Sstevel@tonic-gate extern void	*rtmalloc(size_t, const char *);
6717c478bd9Sstevel@tonic-gate extern void	timevaladd(struct timeval *, struct timeval *);
6727c478bd9Sstevel@tonic-gate extern void	intvl_random(struct timeval *, ulong_t, ulong_t);
6737c478bd9Sstevel@tonic-gate extern boolean_t	getnet(const char *, in_addr_t *, in_addr_t *);
6747c478bd9Sstevel@tonic-gate extern int	gethost(char *, in_addr_t *);
6757c478bd9Sstevel@tonic-gate extern void	gwkludge(void);
6767c478bd9Sstevel@tonic-gate extern const char *parse_parms(char *, boolean_t);
6777c478bd9Sstevel@tonic-gate extern const char *insert_parm(struct parm *);
6787c478bd9Sstevel@tonic-gate extern void	get_parms(struct interface *);
6797c478bd9Sstevel@tonic-gate 
6807c478bd9Sstevel@tonic-gate extern void	lastlog(void);
6817c478bd9Sstevel@tonic-gate extern void	trace_close(int);
6827c478bd9Sstevel@tonic-gate extern void	set_tracefile(const char *, const char *, int);
6837c478bd9Sstevel@tonic-gate extern void	tracelevel_msg(const char *, int);
6847c478bd9Sstevel@tonic-gate extern void	trace_off(const char *, ...);
6857c478bd9Sstevel@tonic-gate extern void	set_tracelevel(void);
6867c478bd9Sstevel@tonic-gate extern void	trace_flush(void);
6877c478bd9Sstevel@tonic-gate extern void	trace_misc(const char *, ...);
6887c478bd9Sstevel@tonic-gate extern void	trace_act(const char *, ...);
6897c478bd9Sstevel@tonic-gate extern void	trace_pkt(const char *, ...);
6907c478bd9Sstevel@tonic-gate extern void	trace_add_del(const char *, struct rt_entry *);
6917c478bd9Sstevel@tonic-gate extern void	trace_change(struct rt_entry *, uint16_t, struct rt_spare *,
6927c478bd9Sstevel@tonic-gate     const char *);
6937c478bd9Sstevel@tonic-gate extern void	trace_if(const char *, struct interface *);
6947c478bd9Sstevel@tonic-gate extern void	trace_khash(const struct khash *);
6957c478bd9Sstevel@tonic-gate extern void	trace_dr(const struct dr *);
6967c478bd9Sstevel@tonic-gate extern void	trace_upslot(struct rt_entry *, struct rt_spare *,
6977c478bd9Sstevel@tonic-gate     struct rt_spare *);
6987c478bd9Sstevel@tonic-gate extern void	trace_rip(const char *, const char *, struct sockaddr_in *,
6997c478bd9Sstevel@tonic-gate     struct interface *, struct rip *, int);
7007c478bd9Sstevel@tonic-gate extern char	*addrname(in_addr_t, in_addr_t, int);
7017c478bd9Sstevel@tonic-gate extern char	*rtname(in_addr_t, in_addr_t, in_addr_t);
7027c478bd9Sstevel@tonic-gate 
7037c478bd9Sstevel@tonic-gate extern void	rdisc_age(in_addr_t);
7047c478bd9Sstevel@tonic-gate extern void	set_rdisc_mg(struct interface *, int);
7057c478bd9Sstevel@tonic-gate extern void	set_supplier(void);
7067c478bd9Sstevel@tonic-gate extern void	if_bad_rdisc(struct interface *);
7077c478bd9Sstevel@tonic-gate extern void	if_rewire_rdisc(struct interface *, struct interface *);
7087c478bd9Sstevel@tonic-gate extern void	if_ok_rdisc(struct interface *);
7097c478bd9Sstevel@tonic-gate extern int	read_rip(void);
7107c478bd9Sstevel@tonic-gate extern void	input_route(in_addr_t, in_addr_t, struct rt_spare *,
7117c478bd9Sstevel@tonic-gate     struct netinfo *, uint16_t);
7127c478bd9Sstevel@tonic-gate extern void	read_rt(void);
7137c478bd9Sstevel@tonic-gate extern void	read_d(void);
7143173664eSapersson extern void	process_d_mib_sock(void);
7157c478bd9Sstevel@tonic-gate extern void	rdisc_adv(boolean_t);
7167c478bd9Sstevel@tonic-gate extern void	rdisc_sol(void);
7177c478bd9Sstevel@tonic-gate extern struct interface *receiving_interface(struct msghdr *, boolean_t);
7187c478bd9Sstevel@tonic-gate extern void	*find_ancillary(struct msghdr *, int);
7197c478bd9Sstevel@tonic-gate extern boolean_t	should_supply(struct interface *);
7207c478bd9Sstevel@tonic-gate extern void	rdisc_dump(void);
7217c478bd9Sstevel@tonic-gate extern void	rdisc_suppress(struct interface *);
7227c478bd9Sstevel@tonic-gate extern void	rdisc_restore(struct interface *);
7237c478bd9Sstevel@tonic-gate 
7247c478bd9Sstevel@tonic-gate extern void age_peer_info(void);
7257c478bd9Sstevel@tonic-gate 
7267c478bd9Sstevel@tonic-gate extern void	sigtrace_more(int);
7277c478bd9Sstevel@tonic-gate extern void	sigtrace_less(int);
7287c478bd9Sstevel@tonic-gate extern void	sigtrace_dump(int);
7297c478bd9Sstevel@tonic-gate 
7307c478bd9Sstevel@tonic-gate extern void	sync_kern(void);
7317c478bd9Sstevel@tonic-gate extern void	age(in_addr_t);
7327c478bd9Sstevel@tonic-gate extern void	kern_dump(void);
7337c478bd9Sstevel@tonic-gate extern void	kern_flush_ifp(struct interface *);
7347c478bd9Sstevel@tonic-gate extern void	kern_rewire_ifp(struct interface *, struct interface *);
7357c478bd9Sstevel@tonic-gate 
7367c478bd9Sstevel@tonic-gate extern void	ag_flush(in_addr_t, in_addr_t, void (*)(struct ag_info *));
7377c478bd9Sstevel@tonic-gate extern void	ag_check(in_addr_t, in_addr_t, in_addr_t, struct interface *,
7387c478bd9Sstevel@tonic-gate     in_addr_t, uint8_t, uint8_t, uint32_t, uint16_t, uint16_t,
7397c478bd9Sstevel@tonic-gate     void (*)(struct ag_info *));
7407c478bd9Sstevel@tonic-gate extern void	del_static(in_addr_t, in_addr_t, in_addr_t,
7417c478bd9Sstevel@tonic-gate     struct interface *, int);
7427c478bd9Sstevel@tonic-gate extern void	del_redirects(in_addr_t, time_t);
7437c478bd9Sstevel@tonic-gate extern struct rt_entry *rtget(in_addr_t, in_addr_t);
7447c478bd9Sstevel@tonic-gate extern struct rt_entry *rtfind(in_addr_t);
7457c478bd9Sstevel@tonic-gate extern void	rtinit(void);
7467c478bd9Sstevel@tonic-gate extern void	rtadd(in_addr_t, in_addr_t, uint16_t, struct rt_spare *);
7477c478bd9Sstevel@tonic-gate extern void	rtchange(struct rt_entry *, uint16_t, struct rt_spare *,
7487c478bd9Sstevel@tonic-gate     char *);
7497c478bd9Sstevel@tonic-gate extern void	rtdelete(struct rt_entry *);
7507c478bd9Sstevel@tonic-gate extern void	rts_delete(struct rt_entry *, struct rt_spare *);
7517c478bd9Sstevel@tonic-gate extern void	rtbad_sub(struct rt_entry *, struct interface *);
7527c478bd9Sstevel@tonic-gate extern void	rtswitch(struct rt_entry *, struct rt_spare *);
7537c478bd9Sstevel@tonic-gate 
7547c478bd9Sstevel@tonic-gate #define	S_ADDR(x)	(((struct sockaddr_in *)(x))->sin_addr.s_addr)
7557c478bd9Sstevel@tonic-gate #define	INFO_DST(I)	((I)->rti_info[RTAX_DST])
7567c478bd9Sstevel@tonic-gate #define	INFO_GATE(I)	((I)->rti_info[RTAX_GATEWAY])
7577c478bd9Sstevel@tonic-gate #define	INFO_MASK(I)	((I)->rti_info[RTAX_NETMASK])
7587c478bd9Sstevel@tonic-gate #define	INFO_AUTHOR(I)	((I)->rti_info[RTAX_AUTHOR])
7597c478bd9Sstevel@tonic-gate 
7607c478bd9Sstevel@tonic-gate struct rewire_data {
7617c478bd9Sstevel@tonic-gate 	struct interface *if_old;
7627c478bd9Sstevel@tonic-gate 	struct interface *if_new;
7637c478bd9Sstevel@tonic-gate 	int metric_delta;
7647c478bd9Sstevel@tonic-gate };
7657c478bd9Sstevel@tonic-gate 
7667c478bd9Sstevel@tonic-gate extern char *qstring(const uchar_t *, int);
7677c478bd9Sstevel@tonic-gate extern in_addr_t std_mask(in_addr_t);
7687c478bd9Sstevel@tonic-gate extern int parse_quote(char **, const char *, char *, char *, int);
7697c478bd9Sstevel@tonic-gate extern in_addr_t ripv1_mask_net(in_addr_t, const struct interface *);
7707c478bd9Sstevel@tonic-gate extern in_addr_t ripv1_mask_host(in_addr_t, const struct interface *);
7717c478bd9Sstevel@tonic-gate #define	on_net(a, net, mask)	(((ntohl(a) ^ (net)) & (mask)) == 0)
7727c478bd9Sstevel@tonic-gate extern boolean_t check_dst(in_addr_t);
7737c478bd9Sstevel@tonic-gate extern boolean_t remote_address_ok(struct interface *, in_addr_t);
7747c478bd9Sstevel@tonic-gate extern struct interface *check_dup(const char *, in_addr_t, in_addr_t,
775aee32e3dScarlsonj     in_addr_t, uint64_t, boolean_t);
7767c478bd9Sstevel@tonic-gate extern boolean_t check_remote(struct interface *);
7777c478bd9Sstevel@tonic-gate extern void iftbl_alloc(void);
7787c478bd9Sstevel@tonic-gate extern void ifscan(void);
7797c478bd9Sstevel@tonic-gate extern int walk_bad(struct radix_node *, void *);
7807c478bd9Sstevel@tonic-gate extern int walk_rewire(struct radix_node *, void *);
7817c478bd9Sstevel@tonic-gate extern void if_ok(struct interface *, const char *, boolean_t);
7827c478bd9Sstevel@tonic-gate extern void if_sick(struct interface *, boolean_t);
7837c478bd9Sstevel@tonic-gate extern void if_link(struct interface *, uint32_t);
7847c478bd9Sstevel@tonic-gate extern struct interface *ifwithaddr(in_addr_t, boolean_t, boolean_t);
7857c478bd9Sstevel@tonic-gate extern struct interface *ifwithindex(ulong_t, boolean_t);
7867c478bd9Sstevel@tonic-gate extern struct interface *ifwithname(const char *);
787982ec2c2SRishi Srivatsavai extern struct physical_interface *phys_byname(const char *);
788982ec2c2SRishi Srivatsavai extern boolean_t addr_on_ifp(in_addr_t, struct interface *,
789982ec2c2SRishi Srivatsavai     struct interface **);
7907c478bd9Sstevel@tonic-gate extern struct interface *findremoteif(in_addr_t);
7917c478bd9Sstevel@tonic-gate extern struct interface *findifaddr(in_addr_t);
7927c478bd9Sstevel@tonic-gate extern struct interface *iflookup(in_addr_t);
7937c478bd9Sstevel@tonic-gate extern struct auth *find_auth(struct interface *);
7947c478bd9Sstevel@tonic-gate extern void end_md5_auth(struct ws_buf *, struct auth *);
7957c478bd9Sstevel@tonic-gate extern void rip_mcast_on(struct interface *);
7967c478bd9Sstevel@tonic-gate extern void rip_mcast_off(struct interface *);
7977c478bd9Sstevel@tonic-gate extern void trace_dump();
798e704a8f2Smeem extern int sendtoif(int, const void *, uint_t, uint_t, struct sockaddr_in *,
799e704a8f2Smeem     uint_t);
8007c478bd9Sstevel@tonic-gate 
8017c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
8027c478bd9Sstevel@tonic-gate }
8037c478bd9Sstevel@tonic-gate #endif
8047c478bd9Sstevel@tonic-gate 
8057c478bd9Sstevel@tonic-gate #endif /* _DEFS_H */
806