defs.h revision 22990
1139778Simp/*
212115Sdyson * Copyright (c) 1983, 1988, 1993
312115Sdyson *	The Regents of the University of California.  All rights reserved.
412115Sdyson *
512115Sdyson * Redistribution and use in source and binary forms, with or without
612115Sdyson * modification, are permitted provided that the following conditions
7139778Simp * are met:
812115Sdyson * 1. Redistributions of source code must retain the above copyright
912115Sdyson *    notice, this list of conditions and the following disclaimer.
1012115Sdyson * 2. Redistributions in binary form must reproduce the above copyright
1112115Sdyson *    notice, this list of conditions and the following disclaimer in the
1212115Sdyson *    documentation and/or other materials provided with the distribution.
1312115Sdyson * 3. All advertising materials mentioning features or use of this software
1412115Sdyson *    must display the following acknowledgement:
1512115Sdyson *	This product includes software developed by the University of
1612115Sdyson *	California, Berkeley and its contributors.
1712115Sdyson * 4. Neither the name of the University nor the names of its contributors
1812115Sdyson *    may be used to endorse or promote products derived from this software
1912115Sdyson *    without specific prior written permission.
2012115Sdyson *
2112115Sdyson * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2212115Sdyson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2312115Sdyson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2412115Sdyson * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2512115Sdyson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2612115Sdyson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2712115Sdyson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2812115Sdyson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2912115Sdyson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3012115Sdyson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3112115Sdyson * SUCH DAMAGE.
3212115Sdyson *
3312115Sdyson *	@(#)defs.h	8.1 (Berkeley) 6/5/93
3412115Sdyson *	$Id$
3512115Sdyson */
3612115Sdyson
3712115Sdyson/* Definitions for RIPv2 routing process.
3812115Sdyson *
3912115Sdyson * This code is based on the 4.4BSD `routed` daemon, with extensions to
4012115Sdyson * support:
4193016Sbde *	RIPv2, including variable length subnet masks.
4212115Sdyson *	Router Discovery
4312115Sdyson *	aggregate routes in the kernel tables.
4412115Sdyson *	aggregate advertised routes.
4512159Sbde *	maintain spare routes for faster selection of another gateway
4612115Sdyson *		when the current gateway dies.
4760041Sphk *	timers on routes with second granularity so that selection
4812115Sdyson *		of a new route does not wait 30-60 seconds.
49193377Sstas *	tolerance of static routes.
5012115Sdyson *	tell the kernel hop counts
5112115Sdyson *	do not advertise if ipforwarding=0
5212115Sdyson *
5312115Sdyson * The vestigual support for other protocols has been removed.  There
5496753Siedowse * is no likelihood that IETF RIPv1 or RIPv2 will ever be used with
5512115Sdyson * other protocols.  The result is far smaller, faster, cleaner, and
5612115Sdyson * perhaps understandable.
5712115Sdyson *
58202283Slulf * The accumulation of special flags and kludges added over the many
59202283Slulf * years have been simplified and integrated.
60202283Slulf */
61221128Sjhb
62202283Slulf#include <stdio.h>
63221128Sjhb#include <netdb.h>
6412115Sdyson#include <stdlib.h>
65252008Spfg#include <unistd.h>
6696753Siedowse#include <errno.h>
6796753Siedowse#include <string.h>
6896753Siedowse#ifdef sgi
6996753Siedowse#include <strings.h>
7096753Siedowse#include <bstring.h>
71141633Sphk#endif
7296753Siedowse#include <stdarg.h>
7396753Siedowse#include <syslog.h>
74111742Sdes#include <time.h>
7512115Sdyson#include <sys/types.h>
7612115Sdyson#include <sys/param.h>
7712115Sdyson#include <sys/ioctl.h>
7812115Sdyson#include <sys/sysctl.h>
7912115Sdyson#include <sys/socket.h>
8012115Sdyson#include <sys/time.h>
8155477Sbde#ifdef sgi
8255477Sbde#include <net/radix.h>
8355477Sbde#else
8455477Sbde#include "radix.h"
8555477Sbde#endif
8655477Sbde#include <net/if.h>
8755477Sbde#include <net/route.h>
8855477Sbde#include <net/if_dl.h>
8955477Sbde#include <netinet/in.h>
9055477Sbde#include <arpa/inet.h>
91247055Spfg#define RIPVERSION RIPv2
92247055Spfg#include <protocols/routed.h>
9355477Sbde
9455477Sbde
9555477Sbde/* Type of an IP address.
9655477Sbde *	Some systems do not like to pass structures, so do not use in_addr.
9755477Sbde *	Some systems think a long has 64 bits, which would be a gross waste.
9855477Sbde * So define it here so it can be changed for the target system.
9955477Sbde * It should be defined somewhere netinet/in.h, but it is not.
10055477Sbde */
10155477Sbde#ifdef sgi
10255477Sbde#define naddr __uint32_t
10355477Sbde#else
10455477Sbde#ifdef __NetBSD__
10555477Sbde#define naddr u_int32_t
10655477Sbde#else
10755477Sbde#define naddr u_long
10855477Sbde#endif
10955477Sbde#define _HAVE_SA_LEN
11055477Sbde#define _HAVE_SIN_LEN
111247055Spfg#endif
112247055Spfg
11355477Sbde/* Turn on if IP_DROP_MEMBERSHIP and IP_ADD_MEMBERSHIP do not look at
114202283Slulf * the dstaddr of point-to-point interfaces.
11593014Sbde */
116235820Spfg/* #define MCAST_PPP_BUG */
117235820Spfg
11812159Sbde#define DAY (24*60*60)
11912115Sdyson#define NEVER DAY			/* a long time */
12012115Sdyson#define EPOCH NEVER			/* bias time by this to avoid <0 */
12112115Sdyson
122221867Sjhb/* Scan the kernel regularly to see if any interfaces have appeared or been
123221867Sjhb * turned off.  These must be less than STALE_TIME.
124221867Sjhb */
125221867Sjhb#define	CHECK_BAD_INTERVAL	5	/* when an interface is known bad */
126221867Sjhb#define	CHECK_ACT_INTERVAL	30	/* when advertising */
12712115Sdyson#define	CHECK_QUIET_INTERVAL	300	/* when not */
12812115Sdyson
12912115Sdyson#define LIM_SEC(s,l) ((s).tv_sec = MIN((s).tv_sec, (l)))
13012115Sdyson
13112115Sdyson/* Metric used for fake default routes.  It ought to be 15, but when
132247209Spfg * processing advertised routes, previous versions of `routed` added
13312115Sdyson * to the received metric and discarded the route if the total was 16
134111742Sdes * or larger.
135111742Sdes */
13612115Sdyson#define FAKE_METRIC (HOPCNT_INFINITY-2)
137202283Slulf
13824649Sdfr
13912115Sdyson/* Router Discovery parameters */
14012115Sdyson#ifndef sgi
14112115Sdyson#define INADDR_ALLROUTERS_GROUP		0xe0000002  /* 224.0.0.2 */
14212115Sdyson#endif
143202283Slulf#define	MaxMaxAdvertiseInterval		1800
14412115Sdyson#define	MinMaxAdvertiseInterval		4
14565780Sbde#define	DefMaxAdvertiseInterval		600
14612115Sdyson#define DEF_PreferenceLevel		0
14765780Sbde#define MIN_PreferenceLevel		0x80000000
14865780Sbde
14965780Sbde#define	MAX_INITIAL_ADVERT_INTERVAL	16
15065780Sbde#define	MAX_INITIAL_ADVERTS		3
15165780Sbde#define	MAX_RESPONSE_DELAY		2
15265780Sbde
15365780Sbde#define	MAX_SOLICITATION_DELAY		1
15465780Sbde#define	SOLICITATION_INTERVAL		3
15565780Sbde#define	MAX_SOLICITATIONS		3
15665780Sbde
15765780Sbde
15865780Sbde/* Bloated packet size for systems that simply add authentication to
15912115Sdyson * full-sized packets
16012115Sdyson */
16112115Sdyson#define OVER_MAXPACKETSIZE (MAXPACKETSIZE+sizeof(struct netinfo)*2)
16265780Sbde/* typical packet buffers */
16312115Sdysonunion pkt_buf {
16412115Sdyson	char	packet[OVER_MAXPACKETSIZE*2];
165184205Sdes	struct	rip rip;
16612115Sdyson};
16712115Sdyson
16812115Sdyson
16912115Sdyson/* No more routes than this, to protect ourself in case something goes
170202283Slulf * whacko and starts broadcasting zillions of bogus routes.
17124649Sdfr */
17255477Sbde#define MAX_ROUTES  (128*1024)
173202283Slulfextern int total_routes;
17455477Sbde
17555477Sbde/* Main, daemon routing table structure
17655477Sbde */
17755477Sbdestruct rt_entry {
17855477Sbde	struct	radix_node rt_nodes[2];	/* radix tree glue */
17955477Sbde	u_int	rt_state;
180125843Sbde#	    define RS_IF	0x001	/* for network interface */
18155477Sbde#	    define RS_NET_INT	0x002	/* authority route */
18255477Sbde#	    define RS_NET_SYN	0x004	/* fake net route for subnet */
18355477Sbde#	    define RS_NO_NET_SYN (RS_LOCAL | RS_LOCAL | RS_IF)
184125843Sbde#	    define RS_SUBNET	0x008	/* subnet route from any source */
185125843Sbde#	    define RS_LOCAL	0x010	/* loopback for pt-to-pt */
18655477Sbde#	    define RS_MHOME	0x020	/* from -m */
18755477Sbde#	    define RS_STATIC	0x040	/* from the kernel */
188125843Sbde#	    define RS_RDISC     0x080	/* from router discovery */
18955477Sbde	struct sockaddr_in rt_dst_sock;
19055477Sbde	naddr   rt_mask;
191202283Slulf	struct rt_spare {
192202283Slulf	    struct interface *rts_ifp;
193202283Slulf	    naddr   rts_gate;		/* forward packets here */
19455477Sbde	    naddr   rts_router;		/* on the authority of this router */
195202283Slulf	    char    rts_metric;
19655477Sbde	    u_short rts_tag;
19755477Sbde	    time_t  rts_time;		/* timer to junk stale routes */
19855477Sbde#define NUM_SPARES 4
19955477Sbde	} rt_spares[NUM_SPARES];
200202283Slulf	u_int	rt_seqno;		/* when last changed */
20112115Sdyson	char	rt_poison_metric;	/* to notice maximum recently */
20212115Sdyson	time_t	rt_poison_time;		/*	advertised metric */
203202283Slulf};
204202283Slulf#define rt_dst	rt_dst_sock.sin_addr.s_addr
205111742Sdes#define rt_ifp	rt_spares[0].rts_ifp
206111741Sdes#define rt_gate	rt_spares[0].rts_gate
20724649Sdfr#define rt_router rt_spares[0].rts_router
20824649Sdfr#define rt_metric rt_spares[0].rts_metric
20912115Sdyson#define rt_tag	rt_spares[0].rts_tag
21012115Sdyson#define rt_time	rt_spares[0].rts_time
21112115Sdyson
21212115Sdyson#define HOST_MASK	0xffffffff
21312115Sdyson#define RT_ISHOST(rt)	((rt)->rt_mask == HOST_MASK)
21412115Sdyson
21512115Sdyson/* age all routes that
21612115Sdyson *	are not from -g, -m, or static routes from the kernel
21712115Sdyson *	not unbroken interface routes
21824649Sdfr *		but not broken interfaces
21924649Sdfr *	nor non-passive, remote interfaces that are not aliases
22065780Sbde *		(i.e. remote & metric=0)
22124649Sdfr */
22224649Sdfr#define AGE_RT(rt_state,ifp) (0 == ((rt_state) & (RS_MHOME | RS_STATIC	    \
22324649Sdfr						  | RS_NET_SYN | RS_RDISC)) \
224125843Sbde			      && (!((rt_state) & RS_IF)			    \
225184205Sdes				  || (ifp) == 0				    \
226111119Simp				  || (((ifp)->int_state & IS_REMOTE)	    \
22724649Sdfr				      && !((ifp)->int_state & IS_PASSIVE))))
228202283Slulf
22965780Sbde/* true if A is better than B
23065780Sbde * Better if
231202283Slulf *	- A is not a poisoned route
232202283Slulf *	- and A is not stale
23324649Sdfr *	- and A has a shorter path
23424649Sdfr *		- or is the router speaking for itself
23524649Sdfr *		- or the current route is equal but stale
23624649Sdfr *		- or it is a host route advertised by a system for itself
23724649Sdfr */
23812115Sdyson#define BETTER_LINK(rt,A,B) ((A)->rts_metric < HOPCNT_INFINITY	\
239184205Sdes			     && now_stale <= (A)->rts_time		\
24024649Sdfr			     && ((A)->rts_metric < (B)->rts_metric	\
24124649Sdfr				 || ((A)->rts_gate == (A)->rts_router	\
242111742Sdes				     && (B)->rts_gate != (B)->rts_router) \
24312115Sdyson				 || ((A)->rts_metric == (B)->rts_metric	\
24412115Sdyson				     && now_stale > (B)->rts_time)	\
24512115Sdyson				 || (RT_ISHOST(rt)			\
24612115Sdyson				     && (rt)->rt_dst == (A)->rts_router	\
24712115Sdyson				     && (A)->rts_metric == (B)->rts_metric)))
24812115Sdyson
24912115Sdyson
25012115Sdyson/* An "interface" is similar to a kernel ifnet structure, except it also
25112115Sdyson * handles "logical" or "IS_REMOTE" interfaces (remote gateways).
25212115Sdyson */
25312115Sdysonstruct interface {
25412115Sdyson	struct interface *int_next, **int_prev;
25512115Sdyson	struct interface *int_ahash, **int_ahash_prev;
25612115Sdyson	struct interface *int_bhash, **int_bhash_prev;
25712115Sdyson	struct interface *int_rlink, **int_rlink_prev;
25812115Sdyson	struct interface *int_nhash, **int_nhash_prev;
25912115Sdyson	char	int_name[IFNAMSIZ+15+1];    /* big enough for IS_REMOTE */
26012115Sdyson	u_short	int_index;
26112115Sdyson	naddr	int_addr;		/* address on this host (net order) */
262125843Sbde	naddr	int_brdaddr;		/* broadcast address (n) */
26312115Sdyson	naddr	int_dstaddr;		/* other end of pt-to-pt link (n) */
26412115Sdyson	naddr	int_net;		/* working network # (host order)*/
26512115Sdyson	naddr	int_mask;		/* working net mask (host order) */
26612115Sdyson	naddr	int_ripv1_mask;		/* for inferring a mask (n) */
26712115Sdyson	naddr	int_std_addr;		/* class A/B/C address (n) */
26812115Sdyson	naddr	int_std_net;		/* class A/B/C network (h) */
26912115Sdyson	naddr	int_std_mask;		/* class A/B/C netmask (h) */
27012115Sdyson	int	int_rip_sock;		/* for queries */
27112115Sdyson	int	int_if_flags;		/* some bits copied from kernel */
27212115Sdyson	u_int	int_state;
27312115Sdyson	time_t	int_act_time;		/* last thought healthy */
27412115Sdyson	time_t	int_query_time;
27512115Sdyson	u_short	int_transitions;	/* times gone up-down */
276247209Spfg	char	int_metric;
27712115Sdyson	char	int_d_metric;		/* for faked default route */
278235820Spfg	struct int_data {
279235820Spfg		u_int	ipackets;	/* previous network stats */
280235820Spfg		u_int	ierrors;
281235820Spfg		u_int	opackets;
282235820Spfg		u_int	oerrors;
283235820Spfg#ifdef sgi
284235820Spfg		u_int	odrops;
285235820Spfg#endif
28696752Siedowse		time_t	ts;		/* timestamp on network stats */
28712115Sdyson	} int_data;
288202283Slulf#	define MAX_AUTH_KEYS 5
28912115Sdyson	struct auth {			/* authentication info */
29012115Sdyson	    u_char  type;
29112115Sdyson	    u_char	key[RIP_AUTH_PW_LEN];
292202283Slulf	    u_char  keyid;
293202283Slulf	    time_t  start, end;
294252677Spfg	} int_auth[MAX_AUTH_KEYS];
29512115Sdyson	int	int_rdisc_pref;		/* advertised rdisc preference */
29612115Sdyson	int	int_rdisc_int;		/* MaxAdvertiseInterval */
29712115Sdyson	int	int_rdisc_cnt;
29812115Sdyson	struct timeval int_rdisc_timer;
29912115Sdyson};
30012115Sdyson
30112115Sdyson/* bits in int_state */
30212115Sdyson#define IS_ALIAS	    0x0000001	/* interface alias */
30312115Sdyson#define IS_SUBNET	    0x0000002	/* interface on subnetted network */
30412115Sdyson#define	IS_REMOTE	    0x0000004	/* interface is not on this machine */
30512115Sdyson#define	IS_PASSIVE	    0x0000008	/* remote and does not do RIP */
30612115Sdyson#define IS_EXTERNAL	    0x0000010	/* handled by EGP or something */
30712115Sdyson#define IS_CHECKED	    0x0000020	/* still exists */
308235820Spfg#define IS_ALL_HOSTS	    0x0000040	/* in INADDR_ALLHOSTS_GROUP */
309202283Slulf#define IS_ALL_ROUTERS	    0x0000080	/* in INADDR_ALLROUTERS_GROUP */
31012115Sdyson#define IS_DISTRUST	    0x0000100	/* ignore untrusted routers */
311235820Spfg#define IS_REDIRECT_OK	    0x0000200	/* accept ICMP redirects */
31212115Sdyson#define IS_BROKE	    0x0000400	/* seems to be broken */
313235820Spfg#define IS_SICK		    0x0000800	/* seems to be broken */
314235820Spfg#define IS_DUP		    0x0001000	/* has a duplicate address */
315235820Spfg#define IS_NEED_NET_SYN	    0x0002000	/* need RS_NET_SYN route */
316235820Spfg#define IS_NO_AG	    0x0004000	/* do not aggregate subnets */
317235820Spfg#define IS_NO_SUPER_AG	    0x0008000	/* do not aggregate networks */
318235820Spfg#define IS_NO_RIPV1_IN	    0x0010000	/* no RIPv1 input at all */
31912115Sdyson#define IS_NO_RIPV2_IN	    0x0020000	/* no RIPv2 input at all */
32012115Sdyson#define IS_NO_RIP_IN	(IS_NO_RIPV1_IN | IS_NO_RIPV2_IN)
321217584Sjhb#define IS_RIP_IN_OFF(s) (((s) & IS_NO_RIP_IN) == IS_NO_RIP_IN)
32212115Sdyson#define IS_NO_RIPV1_OUT	    0x0040000	/* no RIPv1 output at all */
32312115Sdyson#define IS_NO_RIPV2_OUT	    0x0080000	/* no RIPv2 output at all */
32412115Sdyson#define IS_NO_RIP_OUT	(IS_NO_RIPV1_OUT | IS_NO_RIPV2_OUT)
32512115Sdyson#define IS_NO_RIP	(IS_NO_RIP_OUT | IS_NO_RIP_IN)
32612115Sdyson#define IS_RIP_OUT_OFF(s) (((s) & IS_NO_RIP_OUT) == IS_NO_RIP_OUT)
32712115Sdyson#define IS_RIP_OFF(s)	(((s) & IS_NO_RIP) == IS_NO_RIP)
32812115Sdyson#define IS_NO_ADV_IN	    0x0100000
32912115Sdyson#define IS_NO_SOL_OUT	    0x0200000	/* no solicitations */
33012115Sdyson#define IS_SOL_OUT	    0x0400000	/* send solicitations */
33112115Sdyson#define GROUP_IS_SOL	(IS_NO_ADV_IN|IS_NO_SOL_OUT)
332202283Slulf#define IS_NO_ADV_OUT	    0x0800000	/* do not advertise rdisc */
333202283Slulf#define IS_ADV_OUT	    0x1000000	/* advertise rdisc */
33412115Sdyson#define GROUP_IS_ADV	(IS_NO_ADV_OUT|IS_ADV_OUT)
33512115Sdyson#define IS_BCAST_RDISC	    0x2000000	/* broadcast instead of multicast */
33612115Sdyson#define IS_NO_RDISC	(IS_NO_ADV_IN | IS_NO_SOL_OUT | IS_NO_ADV_OUT)
33712115Sdyson#define IS_PM_RDISC	    0x4000000	/* poor-man's router discovery */
33812115Sdyson
339111742Sdes#ifdef sgi
34012115Sdyson#define IFF_UP_RUNNING (IFF_RUNNING|IFF_UP)
34112115Sdyson#else
34212115Sdyson#define IFF_UP_RUNNING IFF_UP
34312115Sdyson#endif
34412115Sdyson#define iff_alive(f) (((f) & IFF_UP_RUNNING) == IFF_UP_RUNNING)
34512115Sdyson
34612115Sdyson
34712115Sdyson/* Information for aggregating routes */
34812115Sdyson#define NUM_AG_SLOTS	32
34912115Sdysonstruct ag_info {
35012115Sdyson	struct ag_info *ag_fine;	/* slot with finer netmask */
35112115Sdyson	struct ag_info *ag_cors;	/* more coarse netmask */
35212115Sdyson	naddr	ag_dst_h;		/* destination in host byte order */
35312115Sdyson	naddr	ag_mask;
35412115Sdyson	naddr	ag_gate;
35512115Sdyson	naddr	ag_nhop;
356202283Slulf	char	ag_metric;		/* metric to be advertised */
357202283Slulf	char	ag_pref;		/* aggregate based on this */
35812115Sdyson	u_int	ag_seqno;
359202283Slulf	u_short	ag_tag;
36012115Sdyson	u_short	ag_state;
36112115Sdyson#define	    AGS_SUPPRESS    0x001	/* combine with coaser mask */
362202283Slulf#define	    AGS_PROMOTE	    0x002	/* synthesize combined routes */
363202283Slulf#define	    AGS_REDUN0	    0x004	/* redundant, finer routes output */
364202283Slulf#define	    AGS_REDUN1	    0x008
36596749Siedowse#define	    AG_IS_REDUN(state) (((state) & (AGS_REDUN0 | AGS_REDUN1)) \
36612115Sdyson				== (AGS_REDUN0 | AGS_REDUN1))
36712115Sdyson#define	    AGS_GATEWAY	    0x010	/* tell kernel RTF_GATEWAY */
36812115Sdyson#define	    AGS_IF	    0x020	/* for an interface */
36912115Sdyson#define	    AGS_RIPV2	    0x040	/* send only as RIPv2 */
370202283Slulf#define	    AGS_FINE_GATE   0x080	/* ignore differing ag_gate when this
371202283Slulf					 * has the finer netmask */
37212115Sdyson#define	    AGS_CORS_GATE   0x100	/* ignore differing gate when this
37312115Sdyson					 * has the coarser netmaks */
37412115Sdyson#define	    AGS_SPLIT_HZ    0x200	/* suppress for split horizon */
375202283Slulf
37612115Sdyson	/* some bits are set if they are set on either route */
37712115Sdyson#define	    AGS_PROMOTE_EITHER (AGS_RIPV2 | AGS_GATEWAY |   \
37812115Sdyson				AGS_SUPPRESS | AGS_CORS_GATE)
379202283Slulf};
38012115Sdyson
38112115Sdyson
38243301Sdillon/* parameters for interfaces */
383202283Slulfextern struct parm {
38496749Siedowse	struct parm *parm_next;
38512115Sdyson	char	parm_name[IFNAMSIZ+1];
38612115Sdyson	naddr	parm_net;
38712115Sdyson	naddr	parm_mask;
38812115Sdyson
38912115Sdyson	char	parm_d_metric;
39012115Sdyson	u_int	parm_int_state;
39112115Sdyson	int	parm_rdisc_pref;
39212115Sdyson	int	parm_rdisc_int;
39312115Sdyson	struct auth parm_auth[MAX_AUTH_KEYS];
39412115Sdyson} *parms;
39512115Sdyson
39612115Sdyson/* authority for internal networks */
39712115Sdysonextern struct intnet {
39812115Sdyson	struct intnet *intnet_next;
39912115Sdyson	naddr	intnet_addr;
40012115Sdyson	naddr	intnet_mask;
40196753Siedowse	char	intnet_metric;
40296753Siedowse} *intnets;
40312115Sdyson
404202283Slulf/* trusted routers */
40512115Sdysonextern struct tgate {
406202283Slulf	struct tgate *tgate_next;
40712147Sdyson	naddr	tgate_addr;
40812115Sdyson} *tgates;
409202283Slulf
41012115Sdysonenum output_type {OUT_QUERY, OUT_UNICAST, OUT_BROADCAST, OUT_MULTICAST,
411202283Slulf	NO_OUT_MULTICAST, NO_OUT_RIPV2};
41212115Sdyson
41312115Sdyson/* common output buffers */
41412115Sdysonextern struct ws_buf {
41512115Sdyson	struct rip	*buf;
41612115Sdyson	struct netinfo	*n;
41712115Sdyson	struct netinfo	*base;
41812115Sdyson	struct netinfo	*lim;
41912115Sdyson	enum output_type type;
42012115Sdyson} v12buf, v2buf;
42112115Sdyson
42212115Sdysonextern pid_t	mypid;
423202283Slulfextern naddr	myaddr;			/* main address of this system */
42412115Sdyson
425202283Slulfextern int	stopint;		/* !=0 to stop */
426202283Slulf
42712115Sdysonextern int	sock_max;
42812115Sdysonextern int	rip_sock;		/* RIP socket */
42912115Sdysonextern struct interface *rip_sock_mcast;    /* current multicast interface */
430202283Slulfextern int	rt_sock;		/* routing socket */
431202283Slulfextern int	rt_sock_seqno;
43212115Sdysonextern int	rdisc_sock;		/* router-discovery raw socket */
43312115Sdyson
43412115Sdysonextern int	seqno;			/* sequence number for messages */
435202283Slulfextern int	supplier;		/* process should supply updates */
43612115Sdysonextern int	lookforinterfaces;	/* 1=probe for new up interfaces */
43712115Sdysonextern int	supplier_set;		/* -s or -q requested */
438202283Slulfextern int	ridhosts;		/* 1=reduce host routes */
439202283Slulfextern int	mhome;			/* 1=want multi-homed host route */
44012115Sdysonextern int	advertise_mhome;	/* 1=must continue adverising it */
44112115Sdysonextern int	auth_ok;		/* 1=ignore auth if we do not care */
44212115Sdyson
44312115Sdysonextern struct timeval clk;		/* system clock's idea of time */
44412115Sdysonextern struct timeval epoch;		/* system clock when started */
44512115Sdysonextern struct timeval now;		/* current idea of time */
44612115Sdysonextern time_t	now_stale;
44712115Sdysonextern time_t	now_expire;
448202283Slulfextern time_t	now_garbage;
449202283Slulf
45012115Sdysonextern struct timeval next_bcast;	/* next general broadcast */
451202283Slulfextern struct timeval age_timer;	/* next check of old routes */
45212115Sdysonextern struct timeval no_flash;		/* inhibit flash update until then */
45312115Sdysonextern struct timeval rdisc_timer;	/* next advert. or solicitation */
45412115Sdysonextern int rdisc_ok;			/* using solicited route */
45512115Sdyson
45612115Sdysonextern struct timeval ifinit_timer;	/* time to check interfaces */
45712115Sdyson
458202283Slulfextern naddr	loopaddr;		/* our address on loopback */
45912115Sdysonextern int	tot_interfaces;		/* # of remote and local interfaces */
46012115Sdysonextern int	rip_interfaces;		/* # of interfaces doing RIP */
46112115Sdysonextern struct interface *ifnet;		/* all interfaces */
462202283Slulfextern struct interface *remote_if;	/* remote interfaces */
463202283Slulfextern int	have_ripv1_out;		/* have a RIPv1 interface */
464202283Slulfextern int	have_ripv1_in;
465202283Slulfextern int	need_flash;		/* flash update needed */
466202283Slulfextern struct timeval need_kern;	/* need to update kernel table */
46712115Sdysonextern int	update_seqno;		/* a route has changed */
46812115Sdyson
46912115Sdysonextern int	tracelevel, new_tracelevel;
47012115Sdyson#define MAX_TRACELEVEL 4
47112115Sdyson#define TRACEKERNEL (tracelevel >= 4)	/* log kernel changes */
47212115Sdyson#define	TRACECONTENTS (tracelevel >= 3)	/* display packet contents */
47312115Sdyson#define TRACEPACKETS (tracelevel >= 2)	/* note packets */
47412115Sdyson#define	TRACEACTIONS (tracelevel != 0)
475202283Slulfextern FILE	*ftrace;		/* output trace file */
476202283Slulfextern char inittracename[MAXPATHLEN+1];
47712115Sdyson
47812115Sdysonextern struct radix_node_head *rhead;
47912115Sdyson
48012115Sdyson
48112115Sdyson#ifdef sgi
48212115Sdyson/* Fix conflicts */
48312115Sdyson#define	dup2(x,y)		BSDdup2(x,y)
48412115Sdyson#endif /* sgi */
48512115Sdyson
48612115Sdysonextern void fix_sock(int, char *);
48712115Sdysonextern void fix_select(void);
48812115Sdysonextern void rip_off(void);
48912115Sdysonextern void rip_on(struct interface *);
49012115Sdyson
49112115Sdysonextern void bufinit(void);
49283366Sjulianextern int  output(enum output_type, struct sockaddr_in *,
49312115Sdyson		   struct interface *, struct rip *, int);
49412115Sdysonextern void clr_ws_buf(struct ws_buf *, struct auth *);
49512115Sdysonextern void rip_query(void);
49612115Sdysonextern void rip_bcast(int);
49712115Sdysonextern void supply(struct sockaddr_in *, struct interface *,
49812115Sdyson		   enum output_type, int, int, int);
49912115Sdyson
50012115Sdysonextern void	msglog(char *, ...);
50112115Sdysonstruct msg_limit {
50212115Sdyson    time_t	reuse;
50312115Sdyson    struct msg_sub {
504202283Slulf	naddr	addr;
50512115Sdyson	time_t	until;
50612115Sdyson#   define MSG_SUBJECT_N 8
50712115Sdyson    } subs[MSG_SUBJECT_N];
50812115Sdyson};
50912115Sdysonextern void	msglim(struct msg_limit *, naddr, char *, ...);
51012115Sdyson#define	LOGERR(msg) msglog(msg ": %s", strerror(errno))
51112115Sdysonextern void	logbad(int, char *, ...);
51212115Sdyson#define	BADERR(dump,msg) logbad(dump,msg ": %s", strerror(errno))
513202283Slulf#ifdef DEBUG
51412115Sdyson#define	DBGERR(dump,msg) BADERR(dump,msg)
51512115Sdyson#else
51612115Sdyson#define	DBGERR(dump,msg) LOGERR(msg)
51712115Sdyson#endif
51812115Sdysonextern	char	*naddr_ntoa(naddr);
51912115Sdysonextern	char	*saddr_ntoa(struct sockaddr *);
52012115Sdyson
52112115Sdysonextern void	*rtmalloc(size_t, char *);
52212115Sdysonextern void	timevaladd(struct timeval *, struct timeval *);
52312115Sdysonextern void	intvl_random(struct timeval *, u_long, u_long);
52412115Sdysonextern int	getnet(char *, naddr *, naddr *);
52512115Sdysonextern int	gethost(char *, naddr *);
52612115Sdysonextern void	gwkludge(void);
52712115Sdysonextern char	*parse_parms(char *, int);
52812115Sdysonextern char	*check_parms(struct parm *);
52912115Sdysonextern void	get_parms(struct interface *);
53012115Sdyson
53112115Sdysonextern void	lastlog(void);
53212115Sdysonextern void	set_tracefile(char *, char *, int);
53312115Sdysonextern void	tracelevel_msg(char *, int);
534235820Spfgextern void	trace_off(char*, ...);
53512115Sdysonextern void	set_tracelevel(void);
53612115Sdysonextern void	trace_flush(void);
53712115Sdysonextern void	trace_kernel(char *, ...);
538235820Spfgextern void	trace_act(char *, ...);
539235820Spfgextern void	trace_pkt(char *, ...);
54012115Sdysonextern void	trace_add_del(char *, struct rt_entry *);
54112115Sdysonextern void	trace_change(struct rt_entry *, u_int, naddr, naddr, int,
54212115Sdyson			     u_short, struct interface *, time_t, char *);
54312115Sdysonextern void	trace_if(char *, struct interface *);
54412115Sdysonextern void	trace_upslot(struct rt_entry *, struct rt_spare *,
54512115Sdyson			     naddr, naddr,
546202283Slulf			     struct interface *, int, u_short, time_t);
54712115Sdysonextern void	trace_rip(char*, char*, struct sockaddr_in *,
548202283Slulf			  struct interface *, struct rip *, int);
549202283Slulfextern char	*addrname(naddr, naddr, int);
55012115Sdyson
55112115Sdysonextern void	rdisc_age(naddr);
552105420Sbdeextern void	set_rdisc_mg(struct interface *, int);
55312115Sdysonextern void	set_supplier(void);
55412115Sdysonextern void	if_bad_rdisc(struct interface *);
55512115Sdysonextern void	if_ok_rdisc(struct interface *);
55612115Sdysonextern void	read_rip(int, struct interface *);
55712115Sdysonextern void	read_rt(void);
55812115Sdysonextern void	read_d(void);
55912115Sdysonextern void	rdisc_adv(void);
560202283Slulfextern void	rdisc_sol(void);
56112115Sdyson
56212115Sdysonextern void	sigalrm(int);
56312115Sdysonextern void	sigterm(int);
56412115Sdyson
56512115Sdysonextern void	sigtrace_on(int);
566252677Spfgextern void	sigtrace_off(int);
567252677Spfg
56812115Sdysonextern void	flush_kern(void);
56912115Sdysonextern void	age(naddr);
57012115Sdyson
57183366Sjulianextern void	ag_flush(naddr, naddr, void (*)(struct ag_info *));
57212115Sdysonextern void	ag_check(naddr, naddr, naddr, naddr, char, char, u_int,
57312115Sdyson			 u_short, u_short, void (*)(struct ag_info *));
57412115Sdysonextern void	del_static(naddr, naddr, int);
57512115Sdysonextern void	del_redirects(naddr, time_t);
57612115Sdysonextern struct rt_entry *rtget(naddr, naddr);
57712115Sdysonextern struct rt_entry *rtfind(naddr);
578252677Spfgextern void	rtinit(void);
579252677Spfgextern void	rtadd(naddr, naddr, naddr, naddr,
580252677Spfg		      int, u_short, u_int, struct interface *);
581252677Spfgextern void	rtchange(struct rt_entry *, u_int, naddr,naddr, int, u_short,
582252677Spfg			 struct interface *ifp, time_t, char *);
58312115Sdysonextern void	rtdelete(struct rt_entry *);
584252677Spfgextern void	rtbad_sub(struct rt_entry *);
58512115Sdysonextern void	rtswitch(struct rt_entry *, struct rt_spare *);
58612115Sdysonextern void	rtbad(struct rt_entry *);
58712115Sdyson
58812115Sdyson
589235820Spfg#define S_ADDR(x)	(((struct sockaddr_in *)(x))->sin_addr.s_addr)
590235820Spfg#define INFO_DST(I)	((I)->rti_info[RTAX_DST])
591202283Slulf#define INFO_GATE(I)	((I)->rti_info[RTAX_GATEWAY])
59212115Sdyson#define INFO_MASK(I)	((I)->rti_info[RTAX_NETMASK])
59312115Sdyson#define INFO_IFA(I)	((I)->rti_info[RTAX_IFA])
59412115Sdyson#define INFO_IFP(I)	((I)->rti_info[RTAX_IFP])
59512115Sdyson#define INFO_AUTHOR(I)	((I)->rti_info[RTAX_AUTHOR])
596202283Slulf#define INFO_BRD(I)	((I)->rti_info[RTAX_BRD])
59792462Smckusickvoid rt_xaddrs(struct rt_addrinfo *, struct sockaddr *, struct sockaddr *,
59812115Sdyson	       int);
59912115Sdyson
60012115Sdysonextern naddr	std_mask(naddr);
60112115Sdysonextern naddr	ripv1_mask_net(naddr, struct interface *);
60212115Sdysonextern naddr	ripv1_mask_host(naddr,struct interface *);
60312115Sdyson#define		on_net(a,net,mask) (((ntohl(a) ^ (net)) & (mask)) == 0)
60412115Sdysonextern int	check_dst(naddr);
60512115Sdysonextern struct interface *check_dup(naddr, naddr, naddr, int);
60612115Sdysonextern int	check_remote(struct interface *);
60712115Sdysonextern int	addrouteforif(register struct interface *);
60812115Sdysonextern void	ifinit(void);
60912115Sdysonextern int	walk_bad(struct radix_node *, struct walkarg *);
61012115Sdysonextern int	if_ok(struct interface *, char *);
61112115Sdysonextern void	if_sick(struct interface *);
61212115Sdysonextern void	if_bad(struct interface *);
61312115Sdysonextern void	if_link(struct interface *);
61412115Sdysonextern struct interface *ifwithaddr(naddr, int, int);
61512115Sdysonextern struct interface *ifwithname(char *, naddr);
61612115Sdysonextern struct interface *ifwithindex(u_short);
61712115Sdysonextern struct interface *iflookup(naddr);
61812115Sdyson
61912115Sdysonextern struct auth *find_auth(struct interface *);
62012115Sdysonextern void end_md5_auth(struct ws_buf *, struct auth *);
62112115Sdyson
622144299Sjeff#include <md5.h>
62383366Sjulian