defs.h revision 19885
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
3419885Swollman *	$Id: defs.h,v 1.2 1996/09/16 17:03:29 wollman Exp $
3518316Swollman */
3618316Swollman
3718316Swollman/* Definitions for RIPv2 routing process.
3818316Swollman *
3918316Swollman * This code is based on the 4.4BSD `routed` daemon, with extensions to
4018316Swollman * support:
4118316Swollman *	RIPv2, including variable length subnet masks.
4218316Swollman *	Router Discovery
4318316Swollman *	aggregate routes in the kernel tables.
4418316Swollman *	aggregate advertised routes.
4518316Swollman *	maintain spare routes for faster selection of another gateway
4618316Swollman *		when the current gateway dies.
4718316Swollman *	timers on routes with second granularity so that selection
4818316Swollman *		of a new route does not wait 30-60 seconds.
4918316Swollman *	tolerance of static routes.
5018316Swollman *	tell the kernel hop counts
5118316Swollman *	do not advertise if ipforwarding=0
5218316Swollman *
5318316Swollman * The vestigual support for other protocols has been removed.  There
5418316Swollman * is no likelihood that IETF RIPv1 or RIPv2 will ever be used with
5518316Swollman * other protocols.  The result is far smaller, faster, cleaner, and
5618316Swollman * perhaps understandable.
5718316Swollman *
5818316Swollman * The accumulation of special flags and kludges added over the many
5918316Swollman * years have been simplified and integrated.
6018316Swollman */
6118316Swollman
6218316Swollman#include <stdio.h>
6318316Swollman#include <netdb.h>
6418316Swollman#include <stdlib.h>
6518316Swollman#include <unistd.h>
6618316Swollman#include <errno.h>
6718316Swollman#include <string.h>
6818316Swollman#ifdef sgi
6918316Swollman#include <strings.h>
7018316Swollman#include <bstring.h>
7118316Swollman#endif
7218316Swollman#include <stdarg.h>
7318316Swollman#include <syslog.h>
7418316Swollman#include <time.h>
7518316Swollman#include <sys/types.h>
7618316Swollman#include <sys/param.h>
7718316Swollman#include <sys/ioctl.h>
7818316Swollman#include <sys/sysctl.h>
7918316Swollman#include <sys/socket.h>
8018316Swollman#ifdef sgi
8118316Swollman#include <net/radix.h>
8218316Swollman#else
8318316Swollman#include "radix.h"
8418316Swollman#endif
8518316Swollman#include <net/if.h>
8618316Swollman#include <net/route.h>
8718316Swollman#include <net/if_dl.h>
8818316Swollman#include <netinet/in.h>
8918316Swollman#include <arpa/inet.h>
9018316Swollman#define RIPVERSION RIPv2
9118316Swollman#include <protocols/routed.h>
9218316Swollman
9319885Swollman#ifdef sgi
9419885Swollman#define USE_PASSIFNAME
9519885Swollman#endif
9618316Swollman
9719885Swollman
9818316Swollman/* Type of an IP address.
9918316Swollman *	Some systems do not like to pass structures, so do not use in_addr.
10018316Swollman *	Some systems think a long has 64 bits, which would be a gross waste.
10118316Swollman * So define it here so it can be changed for the target system.
10218316Swollman * It should be defined somewhere netinet/in.h, but it is not.
10318316Swollman */
10418316Swollman#ifdef sgi
10518316Swollman#define naddr __uint32_t
10618316Swollman#else
10718316Swollman#ifdef __NetBSD__
10818316Swollman#define naddr u_int32_t
10918316Swollman#else
11018316Swollman#define naddr u_long
11118316Swollman#endif
11218316Swollman#define _HAVE_SA_LEN
11318316Swollman#define _HAVE_SIN_LEN
11418316Swollman#endif
11518316Swollman
11618316Swollman/* Turn on if IP_DROP_MEMBERSHIP and IP_ADD_MEMBERSHIP do not look at
11718316Swollman * the dstaddr of point-to-point interfaces.
11818316Swollman */
11918316Swollman/* #define MCAST_PPP_BUG */
12018316Swollman
12118316Swollman#define NEVER (24*60*60)		/* a long time */
12218316Swollman#define EPOCH NEVER			/* bias time by this to avoid <0 */
12318316Swollman
12418316Swollman/* Scan the kernel regularly to see if any interfaces have appeared or been
12518316Swollman * turned off.  These must be less than STALE_TIME.
12618316Swollman */
12718316Swollman#define	CHECK_BAD_INTERVAL	5	/* when an interface is known bad */
12818316Swollman#define	CHECK_ACT_INTERVAL	30	/* when advertising */
12918316Swollman#define	CHECK_QUIET_INTERVAL	300	/* when not */
13018316Swollman
13118316Swollman#define LIM_SEC(s,l) ((s).tv_sec = MIN((s).tv_sec, (l)))
13218316Swollman
13319885Swollman/* Metric used for fake default routes.  It ought to be 15, but when
13419885Swollman * processing advertised routes, previous versions of `routed` added
13519885Swollman * to the received metric and discarded the route if the total was 16
13619885Swollman * or larger.
13719885Swollman */
13819885Swollman#define FAKE_METRIC (HOPCNT_INFINITY-2)
13918316Swollman
14019885Swollman
14118316Swollman/* Router Discovery parameters */
14218316Swollman#ifndef sgi
14318316Swollman#define INADDR_ALLROUTERS_GROUP		0xe0000002  /* 224.0.0.2 */
14418316Swollman#endif
14518316Swollman#define	MaxMaxAdvertiseInterval		1800
14618316Swollman#define	MinMaxAdvertiseInterval		4
14718316Swollman#define	DefMaxAdvertiseInterval		600
14818316Swollman#define DEF_PreferenceLevel		0
14918316Swollman#define MIN_PreferenceLevel		0x80000000
15018316Swollman
15118316Swollman#define	MAX_INITIAL_ADVERT_INTERVAL	16
15218316Swollman#define	MAX_INITIAL_ADVERTS		3
15318316Swollman#define	MAX_RESPONSE_DELAY		2
15418316Swollman
15518316Swollman#define	MAX_SOLICITATION_DELAY		1
15618316Swollman#define	SOLICITATION_INTERVAL		3
15718316Swollman#define	MAX_SOLICITATIONS		3
15818316Swollman
15918316Swollman
16019885Swollman/* Bloated packet size for systems that simply add authentication to
16119885Swollman * full-sized packets
16219885Swollman */
16319885Swollman#define OVER_MAXPACKETSIZE (MAXPACKETSIZE+sizeof(struct netinfo)*2)
16418316Swollman/* typical packet buffers */
16518316Swollmanunion pkt_buf {
16619885Swollman	char	packet[OVER_MAXPACKETSIZE*2];
16718316Swollman	struct	rip rip;
16818316Swollman};
16918316Swollman
17018316Swollman
17119885Swollman/* No more routes than this, to protect ourself in case something goes
17219885Swollman * whacko and starts broadcasting zillions of bogus routes.
17318316Swollman */
17418316Swollman#define MAX_ROUTES  (128*1024)
17518316Swollmanextern int total_routes;
17618316Swollman
17718316Swollman/* Main, daemon routing table structure
17818316Swollman */
17918316Swollmanstruct rt_entry {
18018316Swollman	struct	radix_node rt_nodes[2];	/* radix tree glue */
18118316Swollman	u_int	rt_state;
18218316Swollman#	    define RS_IF	0x001	/* for network interface */
18318316Swollman#	    define RS_NET_INT	0x002	/* authority route */
18418316Swollman#	    define RS_NET_SYN	0x004	/* fake net route for subnet */
18518316Swollman#	    define RS_NO_NET_SYN (RS_LOCAL | RS_LOCAL | RS_IF)
18618316Swollman#	    define RS_SUBNET	0x008	/* subnet route from any source */
18718316Swollman#	    define RS_LOCAL	0x010	/* loopback for pt-to-pt */
18818316Swollman#	    define RS_MHOME	0x020	/* from -m */
18918316Swollman#	    define RS_STATIC	0x040	/* from the kernel */
19018316Swollman#	    define RS_RDISC     0x080	/* from router discovery */
19118316Swollman	struct sockaddr_in rt_dst_sock;
19218316Swollman	naddr   rt_mask;
19318316Swollman	struct rt_spare {
19418316Swollman	    struct interface *rts_ifp;
19518316Swollman	    naddr   rts_gate;		/* forward packets here */
19618316Swollman	    naddr   rts_router;		/* on the authority of this router */
19718316Swollman	    char    rts_metric;
19818316Swollman	    u_short rts_tag;
19918316Swollman	    time_t  rts_time;		/* timer to junk stale routes */
20018316Swollman#define NUM_SPARES 4
20118316Swollman	} rt_spares[NUM_SPARES];
20218316Swollman	u_int	rt_seqno;		/* when last changed */
20318316Swollman	char	rt_poison_metric;	/* to notice maximum recently */
20418316Swollman	time_t	rt_poison_time;		/*	advertised metric */
20518316Swollman};
20618316Swollman#define rt_dst	rt_dst_sock.sin_addr.s_addr
20718316Swollman#define rt_ifp	rt_spares[0].rts_ifp
20818316Swollman#define rt_gate	rt_spares[0].rts_gate
20918316Swollman#define rt_router rt_spares[0].rts_router
21018316Swollman#define rt_metric rt_spares[0].rts_metric
21118316Swollman#define rt_tag	rt_spares[0].rts_tag
21218316Swollman#define rt_time	rt_spares[0].rts_time
21318316Swollman
21418316Swollman#define HOST_MASK	0xffffffff
21518316Swollman#define RT_ISHOST(rt)	((rt)->rt_mask == HOST_MASK)
21618316Swollman
21718316Swollman/* age all routes that
21818316Swollman *	are not from -g, -m, or static routes from the kernel
21918316Swollman *	not unbroken interface routes
22018316Swollman *		but not broken interfaces
22118316Swollman *	nor non-passive, remote interfaces that are not aliases
22218316Swollman *		(i.e. remote & metric=0)
22318316Swollman */
22418316Swollman#define AGE_RT(rt_state,ifp) (0 == ((rt_state) & (RS_MHOME | RS_STATIC	    \
22518316Swollman						  | RS_NET_SYN | RS_RDISC)) \
22618316Swollman			      && (!((rt_state) & RS_IF)			    \
22718316Swollman				  || (ifp) == 0				    \
22818316Swollman				  || (((ifp)->int_state & IS_REMOTE)	    \
22918316Swollman				      && !((ifp)->int_state & IS_PASSIVE))))
23018316Swollman
23118316Swollman/* true if A is better than B
23218316Swollman * Better if
23318316Swollman *	- A is not a poisoned route
23418316Swollman *	- and A is not stale
23518316Swollman *	- and A has a shorter path
23618316Swollman *		- or is the router speaking for itself
23718316Swollman *		- or the current route is equal but stale
23818316Swollman *		- or it is a host route advertised by a system for itself
23918316Swollman */
24018316Swollman#define BETTER_LINK(rt,A,B) ((A)->rts_metric < HOPCNT_INFINITY	\
24118316Swollman			     && now_stale <= (A)->rts_time		\
24218316Swollman			     && ((A)->rts_metric < (B)->rts_metric	\
24318316Swollman				 || ((A)->rts_gate == (A)->rts_router	\
24418316Swollman				     && (B)->rts_gate != (B)->rts_router) \
24518316Swollman				 || ((A)->rts_metric == (B)->rts_metric	\
24618316Swollman				     && now_stale > (B)->rts_time)	\
24718316Swollman				 || (RT_ISHOST(rt)			\
24818316Swollman				     && (rt)->rt_dst == (A)->rts_router	\
24918316Swollman				     && (A)->rts_metric == (B)->rts_metric)))
25018316Swollman
25118316Swollman
25218316Swollman/* An "interface" is similar to a kernel ifnet structure, except it also
25318316Swollman * handles "logical" or "IS_REMOTE" interfaces (remote gateways).
25418316Swollman */
25518316Swollmanstruct interface {
25619885Swollman	struct interface *int_next, **int_prev;
25719885Swollman	struct interface *int_ahash, **int_ahash_prev;
25819885Swollman	struct interface *int_bhash, **int_bhash_prev;
25919885Swollman	struct interface *int_rlink, **int_rlink_prev;
26019885Swollman	struct interface *int_nhash, **int_nhash_prev;
26118316Swollman	char	int_name[IFNAMSIZ+15+1];    /* big enough for IS_REMOTE */
26218316Swollman	u_short	int_index;
26318316Swollman	naddr	int_addr;		/* address on this host (net order) */
26418316Swollman	naddr	int_brdaddr;		/* broadcast address (n) */
26518316Swollman	naddr	int_dstaddr;		/* other end of pt-to-pt link (n) */
26618316Swollman	naddr	int_net;		/* working network # (host order)*/
26718316Swollman	naddr	int_mask;		/* working net mask (host order) */
26818316Swollman	naddr	int_ripv1_mask;		/* for inferring a mask (n) */
26918316Swollman	naddr	int_std_addr;		/* class A/B/C address (n) */
27018316Swollman	naddr	int_std_net;		/* class A/B/C network (h) */
27118316Swollman	naddr	int_std_mask;		/* class A/B/C netmask (h) */
27218316Swollman	int	int_rip_sock;		/* for queries */
27318316Swollman	int	int_if_flags;		/* some bits copied from kernel */
27418316Swollman	u_int	int_state;
27518316Swollman	time_t	int_act_time;		/* last thought healthy */
27619885Swollman	time_t	int_query_time;
27718316Swollman	u_short	int_transitions;	/* times gone up-down */
27818316Swollman	char	int_metric;
27918316Swollman	char	int_d_metric;		/* for faked default route */
28018316Swollman	struct int_data {
28118316Swollman		u_int	ipackets;	/* previous network stats */
28218316Swollman		u_int	ierrors;
28318316Swollman		u_int	opackets;
28418316Swollman		u_int	oerrors;
28518316Swollman#ifdef sgi
28618316Swollman		u_int	odrops;
28718316Swollman#endif
28818316Swollman		time_t	ts;		/* timestamp on network stats */
28918316Swollman	} int_data;
29019885Swollman	struct auth {			/* authentication info */
29119885Swollman	    u_char  type;
29219885Swollman#	    define MAX_AUTH_KEYS 3
29319885Swollman	    struct auth_key {
29419885Swollman		u_char	key[RIP_AUTH_PW_LEN];
29519885Swollman		u_char  keyid;
29619885Swollman		time_t  start, end;
29719885Swollman	    } keys[MAX_AUTH_KEYS];
29819885Swollman	} int_auth;
29918316Swollman	int	int_rdisc_pref;		/* advertised rdisc preference */
30018316Swollman	int	int_rdisc_int;		/* MaxAdvertiseInterval */
30118316Swollman	int	int_rdisc_cnt;
30218316Swollman	struct timeval int_rdisc_timer;
30318316Swollman};
30418316Swollman
30518316Swollman/* bits in int_state */
30618316Swollman#define IS_ALIAS	    0x0000001	/* interface alias */
30718316Swollman#define IS_SUBNET	    0x0000002	/* interface on subnetted network */
30818316Swollman#define	IS_REMOTE	    0x0000004	/* interface is not on this machine */
30918316Swollman#define	IS_PASSIVE	    0x0000008	/* remote and does not do RIP */
31018316Swollman#define IS_EXTERNAL	    0x0000010	/* handled by EGP or something */
31118316Swollman#define IS_CHECKED	    0x0000020	/* still exists */
31218316Swollman#define IS_ALL_HOSTS	    0x0000040	/* in INADDR_ALLHOSTS_GROUP */
31318316Swollman#define IS_ALL_ROUTERS	    0x0000080	/* in INADDR_ALLROUTERS_GROUP */
31419885Swollman#define IS_DISTRUST	    0x0000100	/* ignore untrusted routers */
31518316Swollman#define IS_BROKE	    0x0000200	/* seems to be broken */
31618316Swollman#define IS_SICK		    0x0000400	/* seems to be broken */
31718316Swollman#define IS_DUP		    0x0000800	/* has a duplicate address */
31819885Swollman/*			    0x0001000      spare */
31918316Swollman#define IS_NEED_NET_SYN	    0x0002000	/* need RS_NET_SYN route */
32018316Swollman#define IS_NO_AG	    0x0004000	/* do not aggregate subnets */
32118316Swollman#define IS_NO_SUPER_AG	    0x0008000	/* do not aggregate networks */
32218316Swollman#define IS_NO_RIPV1_IN	    0x0010000	/* no RIPv1 input at all */
32318316Swollman#define IS_NO_RIPV2_IN	    0x0020000	/* no RIPv2 input at all */
32418316Swollman#define IS_NO_RIP_IN	(IS_NO_RIPV1_IN | IS_NO_RIPV2_IN)
32518316Swollman#define IS_RIP_IN_OFF(s) (((s) & IS_NO_RIP_IN) == IS_NO_RIP_IN)
32618316Swollman#define IS_NO_RIPV1_OUT	    0x0040000	/* no RIPv1 output at all */
32718316Swollman#define IS_NO_RIPV2_OUT	    0x0080000	/* no RIPv2 output at all */
32818316Swollman#define IS_NO_RIP_OUT	(IS_NO_RIPV1_OUT | IS_NO_RIPV2_OUT)
32918316Swollman#define IS_NO_RIP	(IS_NO_RIP_OUT | IS_NO_RIP_IN)
33018316Swollman#define IS_RIP_OUT_OFF(s) (((s) & IS_NO_RIP_OUT) == IS_NO_RIP_OUT)
33118316Swollman#define IS_RIP_OFF(s)	(((s) & IS_NO_RIP) == IS_NO_RIP)
33218316Swollman#define IS_NO_ADV_IN	    0x0100000
33318316Swollman#define IS_NO_SOL_OUT	    0x0200000	/* no solicitations */
33418316Swollman#define IS_SOL_OUT	    0x0400000	/* send solicitations */
33518316Swollman#define GROUP_IS_SOL	(IS_NO_ADV_IN|IS_NO_SOL_OUT)
33618316Swollman#define IS_NO_ADV_OUT	    0x0800000	/* do not advertise rdisc */
33718316Swollman#define IS_ADV_OUT	    0x1000000	/* advertise rdisc */
33818316Swollman#define GROUP_IS_ADV	(IS_NO_ADV_OUT|IS_ADV_OUT)
33918316Swollman#define IS_BCAST_RDISC	    0x2000000	/* broadcast instead of multicast */
34018316Swollman#define IS_NO_RDISC	(IS_NO_ADV_IN | IS_NO_SOL_OUT | IS_NO_ADV_OUT)
34118316Swollman#define IS_PM_RDISC	    0x4000000	/* poor-man's router discovery */
34218316Swollman
34318316Swollman#ifdef sgi
34418316Swollman#define IFF_UP_RUNNING (IFF_RUNNING|IFF_UP)
34518316Swollman#else
34618316Swollman#define IFF_UP_RUNNING IFF_UP
34718316Swollman#endif
34818316Swollman#define iff_alive(f) (((f) & IFF_UP_RUNNING) == IFF_UP_RUNNING)
34918316Swollman
35018316Swollman
35118316Swollman/* Information for aggregating routes */
35218316Swollman#define NUM_AG_SLOTS	32
35318316Swollmanstruct ag_info {
35418316Swollman	struct ag_info *ag_fine;	/* slot with finer netmask */
35518316Swollman	struct ag_info *ag_cors;	/* more coarse netmask */
35618316Swollman	naddr	ag_dst_h;		/* destination in host byte order */
35718316Swollman	naddr	ag_mask;
35818316Swollman	naddr	ag_gate;
35918316Swollman	naddr	ag_nhop;
36018316Swollman	char	ag_metric;		/* metric to be advertised */
36118316Swollman	char	ag_pref;		/* aggregate based on this */
36218316Swollman	u_int	ag_seqno;
36318316Swollman	u_short	ag_tag;
36418316Swollman	u_short	ag_state;
36518316Swollman#define	    AGS_SUPPRESS    0x001	/* combine with coaser mask */
36618316Swollman#define	    AGS_PROMOTE	    0x002	/* synthesize combined routes */
36718316Swollman#define	    AGS_REDUN0	    0x004	/* redundant, finer routes output */
36818316Swollman#define	    AGS_REDUN1	    0x008
36918316Swollman#define	    AG_IS_REDUN(state) (((state) & (AGS_REDUN0 | AGS_REDUN1)) \
37018316Swollman				== (AGS_REDUN0 | AGS_REDUN1))
37118316Swollman#define	    AGS_GATEWAY	    0x010	/* tell kernel RTF_GATEWAY */
37218316Swollman#define	    AGS_IF	    0x020	/* for an interface */
37318316Swollman#define	    AGS_RIPV2	    0x040	/* send only as RIPv2 */
37418316Swollman#define	    AGS_FINE_GATE   0x080	/* ignore differing ag_gate when this
37518316Swollman					 * has the finer netmask */
37618316Swollman#define	    AGS_CORS_GATE   0x100	/* ignore differing gate when this
37718316Swollman					 * has the coarser netmaks */
37818316Swollman#define	    AGS_SPLIT_HZ    0x200	/* suppress for split horizon */
37918316Swollman
38018316Swollman	/* some bits are set if they are set on either route */
38118316Swollman#define	    AGS_PROMOTE_EITHER (AGS_RIPV2 | AGS_GATEWAY |   \
38218316Swollman				AGS_SUPPRESS | AGS_CORS_GATE)
38318316Swollman};
38418316Swollman
38518316Swollman
38618316Swollman/* parameters for interfaces */
38718316Swollmanextern struct parm {
38818316Swollman	struct parm *parm_next;
38918316Swollman	char	parm_name[IFNAMSIZ+1];
39019885Swollman	naddr	parm_net;
39118316Swollman	naddr	parm_mask;
39218316Swollman
39318316Swollman	char	parm_d_metric;
39418316Swollman	u_int	parm_int_state;
39518316Swollman	int	parm_rdisc_pref;
39618316Swollman	int	parm_rdisc_int;
39719885Swollman	struct auth parm_auth;
39818316Swollman} *parms;
39918316Swollman
40018316Swollman/* authority for internal networks */
40118316Swollmanextern struct intnet {
40218316Swollman	struct intnet *intnet_next;
40318316Swollman	naddr	intnet_addr;
40418316Swollman	naddr	intnet_mask;
40518316Swollman	char	intnet_metric;
40618316Swollman} *intnets;
40718316Swollman
40819885Swollman/* trusted routers */
40919885Swollmanextern struct tgate {
41019885Swollman	struct tgate *tgate_next;
41119885Swollman	naddr	tgate_addr;
41219885Swollman} *tgates;
41318316Swollman
41419885Swollmanenum output_type {OUT_QUERY, OUT_UNICAST, OUT_BROADCAST, OUT_MULTICAST,
41519885Swollman	NO_OUT_MULTICAST, NO_OUT_RIPV2};
41618316Swollman
41719885Swollman/* common output buffers */
41819885Swollmanextern struct ws_buf {
41919885Swollman	struct rip	*buf;
42019885Swollman	struct netinfo	*n;
42119885Swollman	struct netinfo	*base;
42219885Swollman	struct netinfo	*lim;
42319885Swollman	enum output_type type;
42419885Swollman} v12buf, v2buf;
42519885Swollman
42618316Swollmanextern pid_t	mypid;
42718316Swollmanextern naddr	myaddr;			/* main address of this system */
42818316Swollman
42918316Swollmanextern int	stopint;		/* !=0 to stop */
43018316Swollman
43118316Swollmanextern int	sock_max;
43218316Swollmanextern int	rip_sock;		/* RIP socket */
43318316Swollmanextern struct interface *rip_sock_mcast;    /* current multicast interface */
43418316Swollmanextern int	rt_sock;		/* routing socket */
43518316Swollmanextern int	rt_sock_seqno;
43618316Swollmanextern int	rdisc_sock;		/* router-discovery raw socket */
43718316Swollman
43818316Swollmanextern int	seqno;			/* sequence number for messages */
43918316Swollmanextern int	supplier;		/* process should supply updates */
44018316Swollmanextern int	lookforinterfaces;	/* 1=probe for new up interfaces */
44118316Swollmanextern int	supplier_set;		/* -s or -q requested */
44218316Swollmanextern int	ridhosts;		/* 1=reduce host routes */
44318316Swollmanextern int	mhome;			/* 1=want multi-homed host route */
44418316Swollmanextern int	advertise_mhome;	/* 1=must continue adverising it */
44518316Swollmanextern int	auth_ok;		/* 1=ignore auth if we do not care */
44618316Swollman
44719885Swollmanextern struct timeval clk;		/* system clock's idea of time */
44819885Swollmanextern struct timeval epoch;		/* system clock when started */
44918316Swollmanextern struct timeval now;		/* current idea of time */
45018316Swollmanextern time_t	now_stale;
45118316Swollmanextern time_t	now_expire;
45218316Swollmanextern time_t	now_garbage;
45318316Swollman
45418316Swollmanextern struct timeval next_bcast;	/* next general broadcast */
45518316Swollmanextern struct timeval age_timer;	/* next check of old routes */
45618316Swollmanextern struct timeval no_flash;		/* inhibit flash update until then */
45718316Swollmanextern struct timeval rdisc_timer;	/* next advert. or solicitation */
45818316Swollmanextern int rdisc_ok;			/* using solicited route */
45918316Swollman
46018316Swollmanextern struct timeval ifinit_timer;	/* time to check interfaces */
46118316Swollman
46218316Swollmanextern naddr	loopaddr;		/* our address on loopback */
46318316Swollmanextern int	tot_interfaces;		/* # of remote and local interfaces */
46418316Swollmanextern int	rip_interfaces;		/* # of interfaces doing RIP */
46518316Swollmanextern struct interface *ifnet;		/* all interfaces */
46619885Swollmanextern struct interface *remote_if;	/* remote interfaces */
46718316Swollmanextern int	have_ripv1_out;		/* have a RIPv1 interface */
46818316Swollmanextern int	have_ripv1_in;
46918316Swollmanextern int	need_flash;		/* flash update needed */
47018316Swollmanextern struct timeval need_kern;	/* need to update kernel table */
47118316Swollmanextern int	update_seqno;		/* a route has changed */
47218316Swollman
47318316Swollmanextern u_int	tracelevel, new_tracelevel;
47418316Swollman#define MAX_TRACELEVEL 4
47518316Swollman#define TRACEKERNEL (tracelevel >= 4)	/* log kernel changes */
47618316Swollman#define	TRACECONTENTS (tracelevel >= 3)	/* display packet contents */
47718316Swollman#define TRACEPACKETS (tracelevel >= 2)	/* note packets */
47818316Swollman#define	TRACEACTIONS (tracelevel != 0)
47918316Swollmanextern FILE	*ftrace;		/* output trace file */
48018316Swollman
48118316Swollmanextern struct radix_node_head *rhead;
48218316Swollman
48318316Swollman
48418316Swollman#ifdef sgi
48518316Swollman/* Fix conflicts */
48618316Swollman#define	dup2(x,y)		BSDdup2(x,y)
48718316Swollman#endif /* sgi */
48818316Swollman
48918316Swollmanextern void fix_sock(int, char *);
49018316Swollmanextern void fix_select(void);
49118316Swollmanextern void rip_off(void);
49218316Swollmanextern void rip_on(struct interface *);
49318316Swollman
49419885Swollmanextern void bufinit(void);
49519885Swollmanextern int  output(enum output_type, struct sockaddr_in *,
49619885Swollman		   struct interface *, struct rip *, int);
49719885Swollmanextern void clr_ws_buf(struct ws_buf *, struct auth_key *, struct interface *);
49818316Swollmanextern void rip_query(void);
49918316Swollmanextern void rip_bcast(int);
50018316Swollmanextern void supply(struct sockaddr_in *, struct interface *,
50119885Swollman		   enum output_type, int, int, int);
50218316Swollman
50318316Swollmanextern void	msglog(char *, ...);
50419885Swollmanstruct msg_limit {
50519885Swollman	naddr	addr;
50619885Swollman	time_t	until;
50719885Swollman};
50819885Swollmanextern void	msglim(struct msg_limit *, naddr, char *, ...);
50918316Swollman#define	LOGERR(msg) msglog(msg ": %s", strerror(errno))
51018316Swollmanextern void	logbad(int, char *, ...);
51118316Swollman#define	BADERR(dump,msg) logbad(dump,msg ": %s", strerror(errno))
51218316Swollman#ifdef DEBUG
51318316Swollman#define	DBGERR(dump,msg) BADERR(dump,msg)
51418316Swollman#else
51518316Swollman#define	DBGERR(dump,msg) LOGERR(msg)
51618316Swollman#endif
51718316Swollmanextern	char	*naddr_ntoa(naddr);
51818316Swollmanextern	char	*saddr_ntoa(struct sockaddr *);
51918316Swollman
52018316Swollmanextern void	*rtmalloc(size_t, char *);
52118316Swollmanextern void	timevaladd(struct timeval *, struct timeval *);
52218316Swollmanextern void	intvl_random(struct timeval *, u_long, u_long);
52318316Swollmanextern int	getnet(char *, naddr *, naddr *);
52418316Swollmanextern int	gethost(char *, naddr *);
52518316Swollmanextern void	gwkludge(void);
52618316Swollmanextern char	*parse_parms(char *);
52718316Swollmanextern char	*check_parms(struct parm *);
52818316Swollmanextern void	get_parms(struct interface *);
52918316Swollman
53018316Swollmanextern void	lastlog(void);
53118316Swollmanextern void	trace_on(char *, int);
53218316Swollmanextern void	trace_off(char*, ...);
53318316Swollmanextern void	trace_flush(void);
53419885Swollmanextern void	set_tracelevel(int);
53518316Swollmanextern void	trace_kernel(char *, ...);
53618316Swollmanextern void	trace_act(char *, ...);
53718316Swollmanextern void	trace_pkt(char *, ...);
53818316Swollmanextern void	trace_add_del(char *, struct rt_entry *);
53918316Swollmanextern void	trace_change(struct rt_entry *, u_int, naddr, naddr, int,
54018316Swollman			     u_short, struct interface *, time_t, char *);
54118316Swollmanextern void	trace_if(char *, struct interface *);
54218316Swollmanextern void	trace_upslot(struct rt_entry *, struct rt_spare *,
54318316Swollman			     naddr, naddr,
54418316Swollman			     struct interface *, int, u_short, time_t);
54518316Swollmanextern void	trace_rip(char*, char*, struct sockaddr_in *,
54618316Swollman			  struct interface *, struct rip *, int);
54718316Swollmanextern char	*addrname(naddr, naddr, int);
54818316Swollman
54918316Swollmanextern void	rdisc_age(naddr);
55018316Swollmanextern void	set_rdisc_mg(struct interface *, int);
55118316Swollmanextern void	set_supplier(void);
55218316Swollmanextern void	if_bad_rdisc(struct interface *);
55318316Swollmanextern void	if_ok_rdisc(struct interface *);
55418316Swollmanextern void	read_rip(int, struct interface *);
55518316Swollmanextern void	read_rt(void);
55618316Swollmanextern void	read_d(void);
55718316Swollmanextern void	rdisc_adv(void);
55818316Swollmanextern void	rdisc_sol(void);
55918316Swollman
56018316Swollmanextern void	sigalrm(int);
56118316Swollmanextern void	sigterm(int);
56218316Swollman
56318316Swollmanextern void	sigtrace_on(int);
56418316Swollmanextern void	sigtrace_off(int);
56518316Swollman
56618316Swollmanextern void	flush_kern(void);
56718316Swollmanextern void	age(naddr);
56818316Swollman
56918316Swollmanextern void	ag_flush(naddr, naddr, void (*)(struct ag_info *));
57018316Swollmanextern void	ag_check(naddr, naddr, naddr, naddr, char, char, u_int,
57118316Swollman			 u_short, u_short, void (*)(struct ag_info *));
57218316Swollmanextern void	del_static(naddr, naddr, int);
57318316Swollmanextern void	del_redirects(naddr, time_t);
57418316Swollmanextern struct rt_entry *rtget(naddr, naddr);
57518316Swollmanextern struct rt_entry *rtfind(naddr);
57618316Swollmanextern void	rtinit(void);
57718316Swollmanextern void	rtadd(naddr, naddr, naddr, naddr,
57818316Swollman		      int, u_short, u_int, struct interface *);
57918316Swollmanextern void	rtchange(struct rt_entry *, u_int, naddr,naddr, int, u_short,
58018316Swollman			 struct interface *ifp, time_t, char *);
58118316Swollmanextern void	rtdelete(struct rt_entry *);
58218316Swollmanextern void	rtbad_sub(struct rt_entry *);
58318316Swollmanextern void	rtswitch(struct rt_entry *, struct rt_spare *);
58418316Swollmanextern void	rtbad(struct rt_entry *);
58518316Swollman
58618316Swollman
58718316Swollman#define S_ADDR(x)	(((struct sockaddr_in *)(x))->sin_addr.s_addr)
58818316Swollman#define INFO_DST(I)	((I)->rti_info[RTAX_DST])
58918316Swollman#define INFO_GATE(I)	((I)->rti_info[RTAX_GATEWAY])
59018316Swollman#define INFO_MASK(I)	((I)->rti_info[RTAX_NETMASK])
59118316Swollman#define INFO_IFA(I)	((I)->rti_info[RTAX_IFA])
59218316Swollman#define INFO_IFP(I)	((I)->rti_info[RTAX_IFP])
59318316Swollman#define INFO_AUTHOR(I)	((I)->rti_info[RTAX_AUTHOR])
59418316Swollman#define INFO_BRD(I)	((I)->rti_info[RTAX_BRD])
59518316Swollmanvoid rt_xaddrs(struct rt_addrinfo *, struct sockaddr *, struct sockaddr *,
59618316Swollman	       int);
59718316Swollman
59818316Swollmanextern naddr	std_mask(naddr);
59918316Swollmanextern naddr	ripv1_mask_net(naddr, struct interface *);
60018316Swollmanextern naddr	ripv1_mask_host(naddr,struct interface *);
60118316Swollman#define		on_net(a,net,mask) (((ntohl(a) ^ (net)) & (mask)) == 0)
60218316Swollmanextern int	check_dst(naddr);
60319885Swollmanextern struct interface *check_dup(naddr, naddr, naddr, int);
60419885Swollmanextern int	check_remote(struct interface *);
60519885Swollmanextern int	addrouteforif(register struct interface *);
60618316Swollmanextern void	ifinit(void);
60718316Swollmanextern int	walk_bad(struct radix_node *, struct walkarg *);
60818316Swollmanextern int	if_ok(struct interface *, char *);
60918316Swollmanextern void	if_sick(struct interface *);
61018316Swollmanextern void	if_bad(struct interface *);
61119885Swollmanextern void	if_link(struct interface *);
61218316Swollmanextern struct interface *ifwithaddr(naddr, int, int);
61318316Swollmanextern struct interface *ifwithname(char *, naddr);
61418316Swollmanextern struct interface *ifwithindex(u_short);
61518316Swollmanextern struct interface *iflookup(naddr);
61619885Swollman
61719885Swollmanextern struct auth_key *find_auth(struct interface *);
61819885Swollmanextern void end_md5_auth(struct ws_buf *, struct auth_key *);
61919885Swollman
62019885Swollman#include <md5.h>
621