defs.h revision 18316
118316Swollman/*
218316Swollman * Copyright (c) 1983, 1988, 1993
318316Swollman *	The Regents of the University of California.  All rights reserved.
418316Swollman *
518316Swollman * Redistribution and use in source and binary forms, with or without
618316Swollman * modification, are permitted provided that the following conditions
718316Swollman * are met:
818316Swollman * 1. Redistributions of source code must retain the above copyright
918316Swollman *    notice, this list of conditions and the following disclaimer.
1018316Swollman * 2. Redistributions in binary form must reproduce the above copyright
1118316Swollman *    notice, this list of conditions and the following disclaimer in the
1218316Swollman *    documentation and/or other materials provided with the distribution.
1318316Swollman * 3. All advertising materials mentioning features or use of this software
1418316Swollman *    must display the following acknowledgement:
1518316Swollman *	This product includes software developed by the University of
1618316Swollman *	California, Berkeley and its contributors.
1718316Swollman * 4. Neither the name of the University nor the names of its contributors
1818316Swollman *    may be used to endorse or promote products derived from this software
1918316Swollman *    without specific prior written permission.
2018316Swollman *
2118316Swollman * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2218316Swollman * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2318316Swollman * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2418316Swollman * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2518316Swollman * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2618316Swollman * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2718316Swollman * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2818316Swollman * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2918316Swollman * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3018316Swollman * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3118316Swollman * SUCH DAMAGE.
3218316Swollman *
3318316Swollman *	@(#)defs.h	8.1 (Berkeley) 6/5/93
3418316Swollman *
3518316Swollman *	$NetBSD$
3618316Swollman */
3718316Swollman
3818316Swollman#ifndef  __NetBSD__
3918316Swollman#ident "$Revision: 1.16 $"
4018316Swollman#endif
4118316Swollman
4218316Swollman/* Definitions for RIPv2 routing process.
4318316Swollman *
4418316Swollman * This code is based on the 4.4BSD `routed` daemon, with extensions to
4518316Swollman * support:
4618316Swollman *	RIPv2, including variable length subnet masks.
4718316Swollman *	Router Discovery
4818316Swollman *	aggregate routes in the kernel tables.
4918316Swollman *	aggregate advertised routes.
5018316Swollman *	maintain spare routes for faster selection of another gateway
5118316Swollman *		when the current gateway dies.
5218316Swollman *	timers on routes with second granularity so that selection
5318316Swollman *		of a new route does not wait 30-60 seconds.
5418316Swollman *	tolerance of static routes.
5518316Swollman *	tell the kernel hop counts
5618316Swollman *	do not advertise if ipforwarding=0
5718316Swollman *
5818316Swollman * The vestigual support for other protocols has been removed.  There
5918316Swollman * is no likelihood that IETF RIPv1 or RIPv2 will ever be used with
6018316Swollman * other protocols.  The result is far smaller, faster, cleaner, and
6118316Swollman * perhaps understandable.
6218316Swollman *
6318316Swollman * The accumulation of special flags and kludges added over the many
6418316Swollman * years have been simplified and integrated.
6518316Swollman */
6618316Swollman
6718316Swollman#include <stdio.h>
6818316Swollman#include <netdb.h>
6918316Swollman#include <stdlib.h>
7018316Swollman#include <unistd.h>
7118316Swollman#include <errno.h>
7218316Swollman#include <string.h>
7318316Swollman#ifdef sgi
7418316Swollman#include <strings.h>
7518316Swollman#include <bstring.h>
7618316Swollman#endif
7718316Swollman#include <stdarg.h>
7818316Swollman#include <syslog.h>
7918316Swollman#include <time.h>
8018316Swollman#include <sys/types.h>
8118316Swollman#include <sys/param.h>
8218316Swollman#include <sys/ioctl.h>
8318316Swollman#include <sys/sysctl.h>
8418316Swollman#include <sys/socket.h>
8518316Swollman#ifdef sgi
8618316Swollman#include <net/radix.h>
8718316Swollman#else
8818316Swollman#include "radix.h"
8918316Swollman#endif
9018316Swollman#include <net/if.h>
9118316Swollman#include <net/route.h>
9218316Swollman#include <net/if_dl.h>
9318316Swollman#include <netinet/in.h>
9418316Swollman#include <arpa/inet.h>
9518316Swollman#define RIPVERSION RIPv2
9618316Swollman#include <protocols/routed.h>
9718316Swollman
9818316Swollman
9918316Swollman/* Type of an IP address.
10018316Swollman *	Some systems do not like to pass structures, so do not use in_addr.
10118316Swollman *	Some systems think a long has 64 bits, which would be a gross waste.
10218316Swollman * So define it here so it can be changed for the target system.
10318316Swollman * It should be defined somewhere netinet/in.h, but it is not.
10418316Swollman */
10518316Swollman#ifdef sgi
10618316Swollman#define naddr __uint32_t
10718316Swollman#else
10818316Swollman#ifdef __NetBSD__
10918316Swollman#define naddr u_int32_t
11018316Swollman#else
11118316Swollman#define naddr u_long
11218316Swollman#endif
11318316Swollman#define _HAVE_SA_LEN
11418316Swollman#define _HAVE_SIN_LEN
11518316Swollman#endif
11618316Swollman
11718316Swollman/* Turn on if IP_DROP_MEMBERSHIP and IP_ADD_MEMBERSHIP do not look at
11818316Swollman * the dstaddr of point-to-point interfaces.
11918316Swollman */
12018316Swollman/* #define MCAST_PPP_BUG */
12118316Swollman
12218316Swollman#define NEVER (24*60*60)		/* a long time */
12318316Swollman#define EPOCH NEVER			/* bias time by this to avoid <0 */
12418316Swollman
12518316Swollman/* Scan the kernel regularly to see if any interfaces have appeared or been
12618316Swollman * turned off.  These must be less than STALE_TIME.
12718316Swollman */
12818316Swollman#define	CHECK_BAD_INTERVAL	5	/* when an interface is known bad */
12918316Swollman#define	CHECK_ACT_INTERVAL	30	/* when advertising */
13018316Swollman#define	CHECK_QUIET_INTERVAL	300	/* when not */
13118316Swollman
13218316Swollman#define LIM_SEC(s,l) ((s).tv_sec = MIN((s).tv_sec, (l)))
13318316Swollman
13418316Swollman
13518316Swollman/* Router Discovery parameters */
13618316Swollman#ifndef sgi
13718316Swollman#define INADDR_ALLROUTERS_GROUP		0xe0000002  /* 224.0.0.2 */
13818316Swollman#endif
13918316Swollman#define	MaxMaxAdvertiseInterval		1800
14018316Swollman#define	MinMaxAdvertiseInterval		4
14118316Swollman#define	DefMaxAdvertiseInterval		600
14218316Swollman#define DEF_PreferenceLevel		0
14318316Swollman#define MIN_PreferenceLevel		0x80000000
14418316Swollman
14518316Swollman#define	MAX_INITIAL_ADVERT_INTERVAL	16
14618316Swollman#define	MAX_INITIAL_ADVERTS		3
14718316Swollman#define	MAX_RESPONSE_DELAY		2
14818316Swollman
14918316Swollman#define	MAX_SOLICITATION_DELAY		1
15018316Swollman#define	SOLICITATION_INTERVAL		3
15118316Swollman#define	MAX_SOLICITATIONS		3
15218316Swollman
15318316Swollman
15418316Swollman/* typical packet buffers */
15518316Swollmanunion pkt_buf {
15618316Swollman	char	packet[MAXPACKETSIZE+1];
15718316Swollman	struct	rip rip;
15818316Swollman};
15918316Swollman
16018316Swollman
16118316Swollman/* no more routes than this, to protect ourself in case something goes
16218316Swollman * whacko and starts broadcast zillions of bogus routes.
16318316Swollman */
16418316Swollman#define MAX_ROUTES  (128*1024)
16518316Swollmanextern int total_routes;
16618316Swollman
16718316Swollman/* Main, daemon routing table structure
16818316Swollman */
16918316Swollmanstruct rt_entry {
17018316Swollman	struct	radix_node rt_nodes[2];	/* radix tree glue */
17118316Swollman	u_int	rt_state;
17218316Swollman#	    define RS_IF	0x001	/* for network interface */
17318316Swollman#	    define RS_NET_INT	0x002	/* authority route */
17418316Swollman#	    define RS_NET_SYN	0x004	/* fake net route for subnet */
17518316Swollman#	    define RS_NO_NET_SYN (RS_LOCAL | RS_LOCAL | RS_IF)
17618316Swollman#	    define RS_SUBNET	0x008	/* subnet route from any source */
17718316Swollman#	    define RS_LOCAL	0x010	/* loopback for pt-to-pt */
17818316Swollman#	    define RS_MHOME	0x020	/* from -m */
17918316Swollman#	    define RS_STATIC	0x040	/* from the kernel */
18018316Swollman#	    define RS_RDISC     0x080	/* from router discovery */
18118316Swollman	struct sockaddr_in rt_dst_sock;
18218316Swollman	naddr   rt_mask;
18318316Swollman	struct rt_spare {
18418316Swollman	    struct interface *rts_ifp;
18518316Swollman	    naddr   rts_gate;		/* forward packets here */
18618316Swollman	    naddr   rts_router;		/* on the authority of this router */
18718316Swollman	    char    rts_metric;
18818316Swollman	    u_short rts_tag;
18918316Swollman	    time_t  rts_time;		/* timer to junk stale routes */
19018316Swollman#define NUM_SPARES 4
19118316Swollman	} rt_spares[NUM_SPARES];
19218316Swollman	u_int	rt_seqno;		/* when last changed */
19318316Swollman	char	rt_poison_metric;	/* to notice maximum recently */
19418316Swollman	time_t	rt_poison_time;		/*	advertised metric */
19518316Swollman};
19618316Swollman#define rt_dst	rt_dst_sock.sin_addr.s_addr
19718316Swollman#define rt_ifp	rt_spares[0].rts_ifp
19818316Swollman#define rt_gate	rt_spares[0].rts_gate
19918316Swollman#define rt_router rt_spares[0].rts_router
20018316Swollman#define rt_metric rt_spares[0].rts_metric
20118316Swollman#define rt_tag	rt_spares[0].rts_tag
20218316Swollman#define rt_time	rt_spares[0].rts_time
20318316Swollman
20418316Swollman#define HOST_MASK	0xffffffff
20518316Swollman#define RT_ISHOST(rt)	((rt)->rt_mask == HOST_MASK)
20618316Swollman
20718316Swollman/* age all routes that
20818316Swollman *	are not from -g, -m, or static routes from the kernel
20918316Swollman *	not unbroken interface routes
21018316Swollman *		but not broken interfaces
21118316Swollman *	nor non-passive, remote interfaces that are not aliases
21218316Swollman *		(i.e. remote & metric=0)
21318316Swollman */
21418316Swollman#define AGE_RT(rt_state,ifp) (0 == ((rt_state) & (RS_MHOME | RS_STATIC	    \
21518316Swollman						  | RS_NET_SYN | RS_RDISC)) \
21618316Swollman			      && (!((rt_state) & RS_IF)			    \
21718316Swollman				  || (ifp) == 0				    \
21818316Swollman				  || (((ifp)->int_state & IS_REMOTE)	    \
21918316Swollman				      && !((ifp)->int_state & IS_PASSIVE))))
22018316Swollman
22118316Swollman/* true if A is better than B
22218316Swollman * Better if
22318316Swollman *	- A is not a poisoned route
22418316Swollman *	- and A is not stale
22518316Swollman *	- and A has a shorter path
22618316Swollman *		- or is the router speaking for itself
22718316Swollman *		- or the current route is equal but stale
22818316Swollman *		- or it is a host route advertised by a system for itself
22918316Swollman */
23018316Swollman#define BETTER_LINK(rt,A,B) ((A)->rts_metric < HOPCNT_INFINITY	\
23118316Swollman			     && now_stale <= (A)->rts_time		\
23218316Swollman			     && ((A)->rts_metric < (B)->rts_metric	\
23318316Swollman				 || ((A)->rts_gate == (A)->rts_router	\
23418316Swollman				     && (B)->rts_gate != (B)->rts_router) \
23518316Swollman				 || ((A)->rts_metric == (B)->rts_metric	\
23618316Swollman				     && now_stale > (B)->rts_time)	\
23718316Swollman				 || (RT_ISHOST(rt)			\
23818316Swollman				     && (rt)->rt_dst == (A)->rts_router	\
23918316Swollman				     && (A)->rts_metric == (B)->rts_metric)))
24018316Swollman
24118316Swollman
24218316Swollman/* An "interface" is similar to a kernel ifnet structure, except it also
24318316Swollman * handles "logical" or "IS_REMOTE" interfaces (remote gateways).
24418316Swollman */
24518316Swollmanstruct interface {
24618316Swollman	struct	interface *int_next, *int_prev;
24718316Swollman	char	int_name[IFNAMSIZ+15+1];    /* big enough for IS_REMOTE */
24818316Swollman	u_short	int_index;
24918316Swollman	naddr	int_addr;		/* address on this host (net order) */
25018316Swollman	naddr	int_brdaddr;		/* broadcast address (n) */
25118316Swollman	naddr	int_dstaddr;		/* other end of pt-to-pt link (n) */
25218316Swollman	naddr	int_net;		/* working network # (host order)*/
25318316Swollman	naddr	int_mask;		/* working net mask (host order) */
25418316Swollman	naddr	int_ripv1_mask;		/* for inferring a mask (n) */
25518316Swollman	naddr	int_std_addr;		/* class A/B/C address (n) */
25618316Swollman	naddr	int_std_net;		/* class A/B/C network (h) */
25718316Swollman	naddr	int_std_mask;		/* class A/B/C netmask (h) */
25818316Swollman	int	int_rip_sock;		/* for queries */
25918316Swollman	int	int_if_flags;		/* some bits copied from kernel */
26018316Swollman	u_int	int_state;
26118316Swollman	time_t	int_act_time;		/* last thought healthy */
26218316Swollman	u_short	int_transitions;	/* times gone up-down */
26318316Swollman	char	int_metric;
26418316Swollman	char	int_d_metric;		/* for faked default route */
26518316Swollman	struct int_data {
26618316Swollman		u_int	ipackets;	/* previous network stats */
26718316Swollman		u_int	ierrors;
26818316Swollman		u_int	opackets;
26918316Swollman		u_int	oerrors;
27018316Swollman#ifdef sgi
27118316Swollman		u_int	odrops;
27218316Swollman#endif
27318316Swollman		time_t	ts;		/* timestamp on network stats */
27418316Swollman	} int_data;
27518316Swollman	char	int_passwd[RIP_AUTH_PW_LEN];	/* RIPv2 password */
27618316Swollman	int	int_rdisc_pref;		/* advertised rdisc preference */
27718316Swollman	int	int_rdisc_int;		/* MaxAdvertiseInterval */
27818316Swollman	int	int_rdisc_cnt;
27918316Swollman	struct timeval int_rdisc_timer;
28018316Swollman};
28118316Swollman
28218316Swollman/* bits in int_state */
28318316Swollman#define IS_ALIAS	    0x0000001	/* interface alias */
28418316Swollman#define IS_SUBNET	    0x0000002	/* interface on subnetted network */
28518316Swollman#define	IS_REMOTE	    0x0000004	/* interface is not on this machine */
28618316Swollman#define	IS_PASSIVE	    0x0000008	/* remote and does not do RIP */
28718316Swollman#define IS_EXTERNAL	    0x0000010	/* handled by EGP or something */
28818316Swollman#define IS_CHECKED	    0x0000020	/* still exists */
28918316Swollman#define IS_ALL_HOSTS	    0x0000040	/* in INADDR_ALLHOSTS_GROUP */
29018316Swollman#define IS_ALL_ROUTERS	    0x0000080	/* in INADDR_ALLROUTERS_GROUP */
29118316Swollman#define IS_RIP_QUERIED	    0x0000100	/* query broadcast */
29218316Swollman#define IS_BROKE	    0x0000200	/* seems to be broken */
29318316Swollman#define IS_SICK		    0x0000400	/* seems to be broken */
29418316Swollman#define IS_DUP		    0x0000800	/* has a duplicate address */
29518316Swollman#define IS_ACTIVE	    0x0001000	/* heard from it at least once */
29618316Swollman#define IS_NEED_NET_SYN	    0x0002000	/* need RS_NET_SYN route */
29718316Swollman#define IS_NO_AG	    0x0004000	/* do not aggregate subnets */
29818316Swollman#define IS_NO_SUPER_AG	    0x0008000	/* do not aggregate networks */
29918316Swollman#define IS_NO_RIPV1_IN	    0x0010000	/* no RIPv1 input at all */
30018316Swollman#define IS_NO_RIPV2_IN	    0x0020000	/* no RIPv2 input at all */
30118316Swollman#define IS_NO_RIP_IN	(IS_NO_RIPV1_IN | IS_NO_RIPV2_IN)
30218316Swollman#define IS_RIP_IN_OFF(s) (((s) & IS_NO_RIP_IN) == IS_NO_RIP_IN)
30318316Swollman#define IS_NO_RIPV1_OUT	    0x0040000	/* no RIPv1 output at all */
30418316Swollman#define IS_NO_RIPV2_OUT	    0x0080000	/* no RIPv2 output at all */
30518316Swollman#define IS_NO_RIP_OUT	(IS_NO_RIPV1_OUT | IS_NO_RIPV2_OUT)
30618316Swollman#define IS_NO_RIP	(IS_NO_RIP_OUT | IS_NO_RIP_IN)
30718316Swollman#define IS_RIP_OUT_OFF(s) (((s) & IS_NO_RIP_OUT) == IS_NO_RIP_OUT)
30818316Swollman#define IS_RIP_OFF(s)	(((s) & IS_NO_RIP) == IS_NO_RIP)
30918316Swollman#define IS_NO_ADV_IN	    0x0100000
31018316Swollman#define IS_NO_SOL_OUT	    0x0200000	/* no solicitations */
31118316Swollman#define IS_SOL_OUT	    0x0400000	/* send solicitations */
31218316Swollman#define GROUP_IS_SOL	(IS_NO_ADV_IN|IS_NO_SOL_OUT)
31318316Swollman#define IS_NO_ADV_OUT	    0x0800000	/* do not advertise rdisc */
31418316Swollman#define IS_ADV_OUT	    0x1000000	/* advertise rdisc */
31518316Swollman#define GROUP_IS_ADV	(IS_NO_ADV_OUT|IS_ADV_OUT)
31618316Swollman#define IS_BCAST_RDISC	    0x2000000	/* broadcast instead of multicast */
31718316Swollman#define IS_NO_RDISC	(IS_NO_ADV_IN | IS_NO_SOL_OUT | IS_NO_ADV_OUT)
31818316Swollman#define IS_PM_RDISC	    0x4000000	/* poor-man's router discovery */
31918316Swollman
32018316Swollman#ifdef sgi
32118316Swollman#define IFF_UP_RUNNING (IFF_RUNNING|IFF_UP)
32218316Swollman#else
32318316Swollman#define IFF_UP_RUNNING IFF_UP
32418316Swollman#endif
32518316Swollman#define iff_alive(f) (((f) & IFF_UP_RUNNING) == IFF_UP_RUNNING)
32618316Swollman
32718316Swollman
32818316Swollman/* Information for aggregating routes */
32918316Swollman#define NUM_AG_SLOTS	32
33018316Swollmanstruct ag_info {
33118316Swollman	struct ag_info *ag_fine;	/* slot with finer netmask */
33218316Swollman	struct ag_info *ag_cors;	/* more coarse netmask */
33318316Swollman	naddr	ag_dst_h;		/* destination in host byte order */
33418316Swollman	naddr	ag_mask;
33518316Swollman	naddr	ag_gate;
33618316Swollman	naddr	ag_nhop;
33718316Swollman	char	ag_metric;		/* metric to be advertised */
33818316Swollman	char	ag_pref;		/* aggregate based on this */
33918316Swollman	u_int	ag_seqno;
34018316Swollman	u_short	ag_tag;
34118316Swollman	u_short	ag_state;
34218316Swollman#define	    AGS_SUPPRESS    0x001	/* combine with coaser mask */
34318316Swollman#define	    AGS_PROMOTE	    0x002	/* synthesize combined routes */
34418316Swollman#define	    AGS_REDUN0	    0x004	/* redundant, finer routes output */
34518316Swollman#define	    AGS_REDUN1	    0x008
34618316Swollman#define	    AG_IS_REDUN(state) (((state) & (AGS_REDUN0 | AGS_REDUN1)) \
34718316Swollman				== (AGS_REDUN0 | AGS_REDUN1))
34818316Swollman#define	    AGS_GATEWAY	    0x010	/* tell kernel RTF_GATEWAY */
34918316Swollman#define	    AGS_IF	    0x020	/* for an interface */
35018316Swollman#define	    AGS_RIPV2	    0x040	/* send only as RIPv2 */
35118316Swollman#define	    AGS_FINE_GATE   0x080	/* ignore differing ag_gate when this
35218316Swollman					 * has the finer netmask */
35318316Swollman#define	    AGS_CORS_GATE   0x100	/* ignore differing gate when this
35418316Swollman					 * has the coarser netmaks */
35518316Swollman#define	    AGS_SPLIT_HZ    0x200	/* suppress for split horizon */
35618316Swollman
35718316Swollman	/* some bits are set if they are set on either route */
35818316Swollman#define	    AGS_PROMOTE_EITHER (AGS_RIPV2 | AGS_GATEWAY |   \
35918316Swollman				AGS_SUPPRESS | AGS_CORS_GATE)
36018316Swollman};
36118316Swollman
36218316Swollman
36318316Swollman/* parameters for interfaces */
36418316Swollmanextern struct parm {
36518316Swollman	struct parm *parm_next;
36618316Swollman	char	parm_name[IFNAMSIZ+1];
36718316Swollman	naddr	parm_addr_h;
36818316Swollman	naddr	parm_mask;
36918316Swollman
37018316Swollman	char	parm_d_metric;
37118316Swollman	u_int	parm_int_state;
37218316Swollman	int	parm_rdisc_pref;
37318316Swollman	int	parm_rdisc_int;
37418316Swollman	char	parm_passwd[RIP_AUTH_PW_LEN+1];
37518316Swollman} *parms;
37618316Swollman
37718316Swollman/* authority for internal networks */
37818316Swollmanextern struct intnet {
37918316Swollman	struct intnet *intnet_next;
38018316Swollman	naddr	intnet_addr;
38118316Swollman	naddr	intnet_mask;
38218316Swollman	char	intnet_metric;
38318316Swollman} *intnets;
38418316Swollman
38518316Swollman
38618316Swollman
38718316Swollmanextern pid_t	mypid;
38818316Swollmanextern naddr	myaddr;			/* main address of this system */
38918316Swollman
39018316Swollmanextern int	stopint;		/* !=0 to stop */
39118316Swollman
39218316Swollmanextern int	sock_max;
39318316Swollmanextern int	rip_sock;		/* RIP socket */
39418316Swollmanextern struct interface *rip_sock_mcast;    /* current multicast interface */
39518316Swollmanextern int	rt_sock;		/* routing socket */
39618316Swollmanextern int	rt_sock_seqno;
39718316Swollmanextern int	rdisc_sock;		/* router-discovery raw socket */
39818316Swollman
39918316Swollmanextern int	seqno;			/* sequence number for messages */
40018316Swollmanextern int	supplier;		/* process should supply updates */
40118316Swollmanextern int	lookforinterfaces;	/* 1=probe for new up interfaces */
40218316Swollmanextern int	supplier_set;		/* -s or -q requested */
40318316Swollmanextern int	ridhosts;		/* 1=reduce host routes */
40418316Swollmanextern int	mhome;			/* 1=want multi-homed host route */
40518316Swollmanextern int	advertise_mhome;	/* 1=must continue adverising it */
40618316Swollmanextern int	auth_ok;		/* 1=ignore auth if we do not care */
40718316Swollman
40818316Swollmanextern struct timeval epoch;		/* when started */
40918316Swollmanextern struct timeval now;		/* current idea of time */
41018316Swollmanextern time_t	now_stale;
41118316Swollmanextern time_t	now_expire;
41218316Swollmanextern time_t	now_garbage;
41318316Swollman
41418316Swollmanextern struct timeval next_bcast;	/* next general broadcast */
41518316Swollmanextern struct timeval age_timer;	/* next check of old routes */
41618316Swollmanextern struct timeval no_flash;		/* inhibit flash update until then */
41718316Swollmanextern struct timeval rdisc_timer;	/* next advert. or solicitation */
41818316Swollmanextern int rdisc_ok;			/* using solicited route */
41918316Swollman
42018316Swollmanextern struct timeval ifinit_timer;	/* time to check interfaces */
42118316Swollman
42218316Swollmanextern naddr	loopaddr;		/* our address on loopback */
42318316Swollmanextern int	tot_interfaces;		/* # of remote and local interfaces */
42418316Swollmanextern int	rip_interfaces;		/* # of interfaces doing RIP */
42518316Swollmanextern struct interface *ifnet;		/* all interfaces */
42618316Swollmanextern int	have_ripv1_out;		/* have a RIPv1 interface */
42718316Swollmanextern int	have_ripv1_in;
42818316Swollmanextern int	need_flash;		/* flash update needed */
42918316Swollmanextern struct timeval need_kern;	/* need to update kernel table */
43018316Swollmanextern int	update_seqno;		/* a route has changed */
43118316Swollman
43218316Swollmanextern u_int	tracelevel, new_tracelevel;
43318316Swollman#define MAX_TRACELEVEL 4
43418316Swollman#define TRACEKERNEL (tracelevel >= 4)	/* log kernel changes */
43518316Swollman#define	TRACECONTENTS (tracelevel >= 3)	/* display packet contents */
43618316Swollman#define TRACEPACKETS (tracelevel >= 2)	/* note packets */
43718316Swollman#define	TRACEACTIONS (tracelevel != 0)
43818316Swollmanextern FILE	*ftrace;		/* output trace file */
43918316Swollman
44018316Swollmanextern struct radix_node_head *rhead;
44118316Swollman
44218316Swollman
44318316Swollman#ifdef sgi
44418316Swollman/* Fix conflicts */
44518316Swollman#define	dup2(x,y)		BSDdup2(x,y)
44618316Swollman#endif /* sgi */
44718316Swollman
44818316Swollmanextern void fix_sock(int, char *);
44918316Swollmanextern void fix_select(void);
45018316Swollmanextern void rip_off(void);
45118316Swollmanextern void rip_on(struct interface *);
45218316Swollman
45318316Swollmanenum output_type {OUT_QUERY, OUT_UNICAST, OUT_BROADCAST, OUT_MULTICAST,
45418316Swollman	NO_OUT_MULTICAST, NO_OUT_RIPV2};
45518316Swollmanextern int	output(enum output_type, struct sockaddr_in *,
45618316Swollman		       struct interface *, struct rip *, int);
45718316Swollmanextern void rip_query(void);
45818316Swollmanextern void rip_bcast(int);
45918316Swollmanextern void supply(struct sockaddr_in *, struct interface *,
46018316Swollman		   enum output_type, int, int);
46118316Swollman
46218316Swollmanextern void	msglog(char *, ...);
46318316Swollman#define	LOGERR(msg) msglog(msg ": %s", strerror(errno))
46418316Swollmanextern void	logbad(int, char *, ...);
46518316Swollman#define	BADERR(dump,msg) logbad(dump,msg ": %s", strerror(errno))
46618316Swollman#ifdef DEBUG
46718316Swollman#define	DBGERR(dump,msg) BADERR(dump,msg)
46818316Swollman#else
46918316Swollman#define	DBGERR(dump,msg) LOGERR(msg)
47018316Swollman#endif
47118316Swollmanextern	char	*naddr_ntoa(naddr);
47218316Swollmanextern	char	*saddr_ntoa(struct sockaddr *);
47318316Swollman
47418316Swollmanextern void	*rtmalloc(size_t, char *);
47518316Swollmanextern void	timevaladd(struct timeval *, struct timeval *);
47618316Swollmanextern void	intvl_random(struct timeval *, u_long, u_long);
47718316Swollmanextern int	getnet(char *, naddr *, naddr *);
47818316Swollmanextern int	gethost(char *, naddr *);
47918316Swollmanextern void	gwkludge(void);
48018316Swollmanextern char	*parse_parms(char *);
48118316Swollmanextern char	*check_parms(struct parm *);
48218316Swollmanextern void	get_parms(struct interface *);
48318316Swollman
48418316Swollmanextern void	lastlog(void);
48518316Swollmanextern void	trace_on(char *, int);
48618316Swollmanextern void	trace_off(char*, ...);
48718316Swollmanextern void	trace_flush(void);
48818316Swollmanextern void	set_tracelevel(void);
48918316Swollmanextern void	trace_kernel(char *, ...);
49018316Swollmanextern void	trace_act(char *, ...);
49118316Swollmanextern void	trace_pkt(char *, ...);
49218316Swollmanextern void	trace_add_del(char *, struct rt_entry *);
49318316Swollmanextern void	trace_change(struct rt_entry *, u_int, naddr, naddr, int,
49418316Swollman			     u_short, struct interface *, time_t, char *);
49518316Swollmanextern void	trace_if(char *, struct interface *);
49618316Swollmanextern void	trace_upslot(struct rt_entry *, struct rt_spare *,
49718316Swollman			     naddr, naddr,
49818316Swollman			     struct interface *, int, u_short, time_t);
49918316Swollmanextern void	trace_rip(char*, char*, struct sockaddr_in *,
50018316Swollman			  struct interface *, struct rip *, int);
50118316Swollmanextern char	*addrname(naddr, naddr, int);
50218316Swollman
50318316Swollmanextern void	rdisc_age(naddr);
50418316Swollmanextern void	set_rdisc_mg(struct interface *, int);
50518316Swollmanextern void	set_supplier(void);
50618316Swollmanextern void	if_bad_rdisc(struct interface *);
50718316Swollmanextern void	if_ok_rdisc(struct interface *);
50818316Swollmanextern void	read_rip(int, struct interface *);
50918316Swollmanextern void	read_rt(void);
51018316Swollmanextern void	read_d(void);
51118316Swollmanextern void	rdisc_adv(void);
51218316Swollmanextern void	rdisc_sol(void);
51318316Swollman
51418316Swollmanextern void	sigalrm(int);
51518316Swollmanextern void	sigterm(int);
51618316Swollman
51718316Swollmanextern void	sigtrace_on(int);
51818316Swollmanextern void	sigtrace_off(int);
51918316Swollman
52018316Swollmanextern void	flush_kern(void);
52118316Swollmanextern void	age(naddr);
52218316Swollman
52318316Swollmanextern void	ag_flush(naddr, naddr, void (*)(struct ag_info *));
52418316Swollmanextern void	ag_check(naddr, naddr, naddr, naddr, char, char, u_int,
52518316Swollman			 u_short, u_short, void (*)(struct ag_info *));
52618316Swollmanextern void	del_static(naddr, naddr, int);
52718316Swollmanextern void	del_redirects(naddr, time_t);
52818316Swollmanextern struct rt_entry *rtget(naddr, naddr);
52918316Swollmanextern struct rt_entry *rtfind(naddr);
53018316Swollmanextern void	rtinit(void);
53118316Swollmanextern void	rtadd(naddr, naddr, naddr, naddr,
53218316Swollman		      int, u_short, u_int, struct interface *);
53318316Swollmanextern void	rtchange(struct rt_entry *, u_int, naddr,naddr, int, u_short,
53418316Swollman			 struct interface *ifp, time_t, char *);
53518316Swollmanextern void	rtdelete(struct rt_entry *);
53618316Swollmanextern void	rtbad_sub(struct rt_entry *);
53718316Swollmanextern void	rtswitch(struct rt_entry *, struct rt_spare *);
53818316Swollmanextern void	rtbad(struct rt_entry *);
53918316Swollman
54018316Swollman
54118316Swollman#define S_ADDR(x)	(((struct sockaddr_in *)(x))->sin_addr.s_addr)
54218316Swollman#define INFO_DST(I)	((I)->rti_info[RTAX_DST])
54318316Swollman#define INFO_GATE(I)	((I)->rti_info[RTAX_GATEWAY])
54418316Swollman#define INFO_MASK(I)	((I)->rti_info[RTAX_NETMASK])
54518316Swollman#define INFO_IFA(I)	((I)->rti_info[RTAX_IFA])
54618316Swollman#define INFO_IFP(I)	((I)->rti_info[RTAX_IFP])
54718316Swollman#define INFO_AUTHOR(I)	((I)->rti_info[RTAX_AUTHOR])
54818316Swollman#define INFO_BRD(I)	((I)->rti_info[RTAX_BRD])
54918316Swollmanvoid rt_xaddrs(struct rt_addrinfo *, struct sockaddr *, struct sockaddr *,
55018316Swollman	       int);
55118316Swollman
55218316Swollmanextern naddr	std_mask(naddr);
55318316Swollmanextern naddr	ripv1_mask_net(naddr, struct interface *);
55418316Swollmanextern naddr	ripv1_mask_host(naddr,struct interface *);
55518316Swollman#define		on_net(a,net,mask) (((ntohl(a) ^ (net)) & (mask)) == 0)
55618316Swollmanextern int	check_dst(naddr);
55718316Swollmanextern void	addrouteforif(register struct interface *);
55818316Swollmanextern void	ifinit(void);
55918316Swollmanextern int	walk_bad(struct radix_node *, struct walkarg *);
56018316Swollmanextern int	if_ok(struct interface *, char *);
56118316Swollmanextern void	if_sick(struct interface *);
56218316Swollmanextern void	if_bad(struct interface *);
56318316Swollmanextern struct interface *ifwithaddr(naddr, int, int);
56418316Swollmanextern struct interface *ifwithname(char *, naddr);
56518316Swollmanextern struct interface *ifwithindex(u_short);
56618316Swollmanextern struct interface *iflookup(naddr);
567