defs.h revision 20287
1/*
2 * Copyright (c) 1983, 1988, 1993
3 *	The Regents of the University of California.  All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 *    must display the following acknowledgement:
15 *	This product includes software developed by the University of
16 *	California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 *    may be used to endorse or promote products derived from this software
19 *    without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 *	@(#)defs.h	8.1 (Berkeley) 6/5/93
34 *	$Id: defs.h,v 1.3 1996/11/19 20:42:11 wollman Exp $
35 */
36
37/* Definitions for RIPv2 routing process.
38 *
39 * This code is based on the 4.4BSD `routed` daemon, with extensions to
40 * support:
41 *	RIPv2, including variable length subnet masks.
42 *	Router Discovery
43 *	aggregate routes in the kernel tables.
44 *	aggregate advertised routes.
45 *	maintain spare routes for faster selection of another gateway
46 *		when the current gateway dies.
47 *	timers on routes with second granularity so that selection
48 *		of a new route does not wait 30-60 seconds.
49 *	tolerance of static routes.
50 *	tell the kernel hop counts
51 *	do not advertise if ipforwarding=0
52 *
53 * The vestigual support for other protocols has been removed.  There
54 * is no likelihood that IETF RIPv1 or RIPv2 will ever be used with
55 * other protocols.  The result is far smaller, faster, cleaner, and
56 * perhaps understandable.
57 *
58 * The accumulation of special flags and kludges added over the many
59 * years have been simplified and integrated.
60 */
61
62#include <stdio.h>
63#include <netdb.h>
64#include <stdlib.h>
65#include <unistd.h>
66#include <errno.h>
67#include <string.h>
68#ifdef sgi
69#include <strings.h>
70#include <bstring.h>
71#endif
72#include <stdarg.h>
73#include <syslog.h>
74#include <time.h>
75#include <sys/types.h>
76#include <sys/param.h>
77#include <sys/ioctl.h>
78#include <sys/sysctl.h>
79#include <sys/socket.h>
80#include <sys/time.h>
81#ifdef sgi
82#include <net/radix.h>
83#else
84#include "radix.h"
85#endif
86#include <net/if.h>
87#include <net/route.h>
88#include <net/if_dl.h>
89#include <netinet/in.h>
90#include <arpa/inet.h>
91#define RIPVERSION RIPv2
92#include <protocols/routed.h>
93
94#ifdef sgi
95#define USE_PASSIFNAME
96#endif
97
98
99/* Type of an IP address.
100 *	Some systems do not like to pass structures, so do not use in_addr.
101 *	Some systems think a long has 64 bits, which would be a gross waste.
102 * So define it here so it can be changed for the target system.
103 * It should be defined somewhere netinet/in.h, but it is not.
104 */
105#ifdef sgi
106#define naddr __uint32_t
107#else
108#ifdef __NetBSD__
109#define naddr u_int32_t
110#else
111#define naddr u_long
112#endif
113#define _HAVE_SA_LEN
114#define _HAVE_SIN_LEN
115#endif
116
117/* Turn on if IP_DROP_MEMBERSHIP and IP_ADD_MEMBERSHIP do not look at
118 * the dstaddr of point-to-point interfaces.
119 */
120/* #define MCAST_PPP_BUG */
121
122#define NEVER (24*60*60)		/* a long time */
123#define EPOCH NEVER			/* bias time by this to avoid <0 */
124
125/* Scan the kernel regularly to see if any interfaces have appeared or been
126 * turned off.  These must be less than STALE_TIME.
127 */
128#define	CHECK_BAD_INTERVAL	5	/* when an interface is known bad */
129#define	CHECK_ACT_INTERVAL	30	/* when advertising */
130#define	CHECK_QUIET_INTERVAL	300	/* when not */
131
132#define LIM_SEC(s,l) ((s).tv_sec = MIN((s).tv_sec, (l)))
133
134/* Metric used for fake default routes.  It ought to be 15, but when
135 * processing advertised routes, previous versions of `routed` added
136 * to the received metric and discarded the route if the total was 16
137 * or larger.
138 */
139#define FAKE_METRIC (HOPCNT_INFINITY-2)
140
141
142/* Router Discovery parameters */
143#ifndef sgi
144#define INADDR_ALLROUTERS_GROUP		0xe0000002  /* 224.0.0.2 */
145#endif
146#define	MaxMaxAdvertiseInterval		1800
147#define	MinMaxAdvertiseInterval		4
148#define	DefMaxAdvertiseInterval		600
149#define DEF_PreferenceLevel		0
150#define MIN_PreferenceLevel		0x80000000
151
152#define	MAX_INITIAL_ADVERT_INTERVAL	16
153#define	MAX_INITIAL_ADVERTS		3
154#define	MAX_RESPONSE_DELAY		2
155
156#define	MAX_SOLICITATION_DELAY		1
157#define	SOLICITATION_INTERVAL		3
158#define	MAX_SOLICITATIONS		3
159
160
161/* Bloated packet size for systems that simply add authentication to
162 * full-sized packets
163 */
164#define OVER_MAXPACKETSIZE (MAXPACKETSIZE+sizeof(struct netinfo)*2)
165/* typical packet buffers */
166union pkt_buf {
167	char	packet[OVER_MAXPACKETSIZE*2];
168	struct	rip rip;
169};
170
171
172/* No more routes than this, to protect ourself in case something goes
173 * whacko and starts broadcasting zillions of bogus routes.
174 */
175#define MAX_ROUTES  (128*1024)
176extern int total_routes;
177
178/* Main, daemon routing table structure
179 */
180struct rt_entry {
181	struct	radix_node rt_nodes[2];	/* radix tree glue */
182	u_int	rt_state;
183#	    define RS_IF	0x001	/* for network interface */
184#	    define RS_NET_INT	0x002	/* authority route */
185#	    define RS_NET_SYN	0x004	/* fake net route for subnet */
186#	    define RS_NO_NET_SYN (RS_LOCAL | RS_LOCAL | RS_IF)
187#	    define RS_SUBNET	0x008	/* subnet route from any source */
188#	    define RS_LOCAL	0x010	/* loopback for pt-to-pt */
189#	    define RS_MHOME	0x020	/* from -m */
190#	    define RS_STATIC	0x040	/* from the kernel */
191#	    define RS_RDISC     0x080	/* from router discovery */
192	struct sockaddr_in rt_dst_sock;
193	naddr   rt_mask;
194	struct rt_spare {
195	    struct interface *rts_ifp;
196	    naddr   rts_gate;		/* forward packets here */
197	    naddr   rts_router;		/* on the authority of this router */
198	    char    rts_metric;
199	    u_short rts_tag;
200	    time_t  rts_time;		/* timer to junk stale routes */
201#define NUM_SPARES 4
202	} rt_spares[NUM_SPARES];
203	u_int	rt_seqno;		/* when last changed */
204	char	rt_poison_metric;	/* to notice maximum recently */
205	time_t	rt_poison_time;		/*	advertised metric */
206};
207#define rt_dst	rt_dst_sock.sin_addr.s_addr
208#define rt_ifp	rt_spares[0].rts_ifp
209#define rt_gate	rt_spares[0].rts_gate
210#define rt_router rt_spares[0].rts_router
211#define rt_metric rt_spares[0].rts_metric
212#define rt_tag	rt_spares[0].rts_tag
213#define rt_time	rt_spares[0].rts_time
214
215#define HOST_MASK	0xffffffff
216#define RT_ISHOST(rt)	((rt)->rt_mask == HOST_MASK)
217
218/* age all routes that
219 *	are not from -g, -m, or static routes from the kernel
220 *	not unbroken interface routes
221 *		but not broken interfaces
222 *	nor non-passive, remote interfaces that are not aliases
223 *		(i.e. remote & metric=0)
224 */
225#define AGE_RT(rt_state,ifp) (0 == ((rt_state) & (RS_MHOME | RS_STATIC	    \
226						  | RS_NET_SYN | RS_RDISC)) \
227			      && (!((rt_state) & RS_IF)			    \
228				  || (ifp) == 0				    \
229				  || (((ifp)->int_state & IS_REMOTE)	    \
230				      && !((ifp)->int_state & IS_PASSIVE))))
231
232/* true if A is better than B
233 * Better if
234 *	- A is not a poisoned route
235 *	- and A is not stale
236 *	- and A has a shorter path
237 *		- or is the router speaking for itself
238 *		- or the current route is equal but stale
239 *		- or it is a host route advertised by a system for itself
240 */
241#define BETTER_LINK(rt,A,B) ((A)->rts_metric < HOPCNT_INFINITY	\
242			     && now_stale <= (A)->rts_time		\
243			     && ((A)->rts_metric < (B)->rts_metric	\
244				 || ((A)->rts_gate == (A)->rts_router	\
245				     && (B)->rts_gate != (B)->rts_router) \
246				 || ((A)->rts_metric == (B)->rts_metric	\
247				     && now_stale > (B)->rts_time)	\
248				 || (RT_ISHOST(rt)			\
249				     && (rt)->rt_dst == (A)->rts_router	\
250				     && (A)->rts_metric == (B)->rts_metric)))
251
252
253/* An "interface" is similar to a kernel ifnet structure, except it also
254 * handles "logical" or "IS_REMOTE" interfaces (remote gateways).
255 */
256struct interface {
257	struct interface *int_next, **int_prev;
258	struct interface *int_ahash, **int_ahash_prev;
259	struct interface *int_bhash, **int_bhash_prev;
260	struct interface *int_rlink, **int_rlink_prev;
261	struct interface *int_nhash, **int_nhash_prev;
262	char	int_name[IFNAMSIZ+15+1];    /* big enough for IS_REMOTE */
263	u_short	int_index;
264	naddr	int_addr;		/* address on this host (net order) */
265	naddr	int_brdaddr;		/* broadcast address (n) */
266	naddr	int_dstaddr;		/* other end of pt-to-pt link (n) */
267	naddr	int_net;		/* working network # (host order)*/
268	naddr	int_mask;		/* working net mask (host order) */
269	naddr	int_ripv1_mask;		/* for inferring a mask (n) */
270	naddr	int_std_addr;		/* class A/B/C address (n) */
271	naddr	int_std_net;		/* class A/B/C network (h) */
272	naddr	int_std_mask;		/* class A/B/C netmask (h) */
273	int	int_rip_sock;		/* for queries */
274	int	int_if_flags;		/* some bits copied from kernel */
275	u_int	int_state;
276	time_t	int_act_time;		/* last thought healthy */
277	time_t	int_query_time;
278	u_short	int_transitions;	/* times gone up-down */
279	char	int_metric;
280	char	int_d_metric;		/* for faked default route */
281	struct int_data {
282		u_int	ipackets;	/* previous network stats */
283		u_int	ierrors;
284		u_int	opackets;
285		u_int	oerrors;
286#ifdef sgi
287		u_int	odrops;
288#endif
289		time_t	ts;		/* timestamp on network stats */
290	} int_data;
291	struct auth {			/* authentication info */
292	    u_char  type;
293#	    define MAX_AUTH_KEYS 3
294	    struct auth_key {
295		u_char	key[RIP_AUTH_PW_LEN];
296		u_char  keyid;
297		time_t  start, end;
298	    } keys[MAX_AUTH_KEYS];
299	} int_auth;
300	int	int_rdisc_pref;		/* advertised rdisc preference */
301	int	int_rdisc_int;		/* MaxAdvertiseInterval */
302	int	int_rdisc_cnt;
303	struct timeval int_rdisc_timer;
304};
305
306/* bits in int_state */
307#define IS_ALIAS	    0x0000001	/* interface alias */
308#define IS_SUBNET	    0x0000002	/* interface on subnetted network */
309#define	IS_REMOTE	    0x0000004	/* interface is not on this machine */
310#define	IS_PASSIVE	    0x0000008	/* remote and does not do RIP */
311#define IS_EXTERNAL	    0x0000010	/* handled by EGP or something */
312#define IS_CHECKED	    0x0000020	/* still exists */
313#define IS_ALL_HOSTS	    0x0000040	/* in INADDR_ALLHOSTS_GROUP */
314#define IS_ALL_ROUTERS	    0x0000080	/* in INADDR_ALLROUTERS_GROUP */
315#define IS_DISTRUST	    0x0000100	/* ignore untrusted routers */
316#define IS_BROKE	    0x0000200	/* seems to be broken */
317#define IS_SICK		    0x0000400	/* seems to be broken */
318#define IS_DUP		    0x0000800	/* has a duplicate address */
319/*			    0x0001000      spare */
320#define IS_NEED_NET_SYN	    0x0002000	/* need RS_NET_SYN route */
321#define IS_NO_AG	    0x0004000	/* do not aggregate subnets */
322#define IS_NO_SUPER_AG	    0x0008000	/* do not aggregate networks */
323#define IS_NO_RIPV1_IN	    0x0010000	/* no RIPv1 input at all */
324#define IS_NO_RIPV2_IN	    0x0020000	/* no RIPv2 input at all */
325#define IS_NO_RIP_IN	(IS_NO_RIPV1_IN | IS_NO_RIPV2_IN)
326#define IS_RIP_IN_OFF(s) (((s) & IS_NO_RIP_IN) == IS_NO_RIP_IN)
327#define IS_NO_RIPV1_OUT	    0x0040000	/* no RIPv1 output at all */
328#define IS_NO_RIPV2_OUT	    0x0080000	/* no RIPv2 output at all */
329#define IS_NO_RIP_OUT	(IS_NO_RIPV1_OUT | IS_NO_RIPV2_OUT)
330#define IS_NO_RIP	(IS_NO_RIP_OUT | IS_NO_RIP_IN)
331#define IS_RIP_OUT_OFF(s) (((s) & IS_NO_RIP_OUT) == IS_NO_RIP_OUT)
332#define IS_RIP_OFF(s)	(((s) & IS_NO_RIP) == IS_NO_RIP)
333#define IS_NO_ADV_IN	    0x0100000
334#define IS_NO_SOL_OUT	    0x0200000	/* no solicitations */
335#define IS_SOL_OUT	    0x0400000	/* send solicitations */
336#define GROUP_IS_SOL	(IS_NO_ADV_IN|IS_NO_SOL_OUT)
337#define IS_NO_ADV_OUT	    0x0800000	/* do not advertise rdisc */
338#define IS_ADV_OUT	    0x1000000	/* advertise rdisc */
339#define GROUP_IS_ADV	(IS_NO_ADV_OUT|IS_ADV_OUT)
340#define IS_BCAST_RDISC	    0x2000000	/* broadcast instead of multicast */
341#define IS_NO_RDISC	(IS_NO_ADV_IN | IS_NO_SOL_OUT | IS_NO_ADV_OUT)
342#define IS_PM_RDISC	    0x4000000	/* poor-man's router discovery */
343
344#ifdef sgi
345#define IFF_UP_RUNNING (IFF_RUNNING|IFF_UP)
346#else
347#define IFF_UP_RUNNING IFF_UP
348#endif
349#define iff_alive(f) (((f) & IFF_UP_RUNNING) == IFF_UP_RUNNING)
350
351
352/* Information for aggregating routes */
353#define NUM_AG_SLOTS	32
354struct ag_info {
355	struct ag_info *ag_fine;	/* slot with finer netmask */
356	struct ag_info *ag_cors;	/* more coarse netmask */
357	naddr	ag_dst_h;		/* destination in host byte order */
358	naddr	ag_mask;
359	naddr	ag_gate;
360	naddr	ag_nhop;
361	char	ag_metric;		/* metric to be advertised */
362	char	ag_pref;		/* aggregate based on this */
363	u_int	ag_seqno;
364	u_short	ag_tag;
365	u_short	ag_state;
366#define	    AGS_SUPPRESS    0x001	/* combine with coaser mask */
367#define	    AGS_PROMOTE	    0x002	/* synthesize combined routes */
368#define	    AGS_REDUN0	    0x004	/* redundant, finer routes output */
369#define	    AGS_REDUN1	    0x008
370#define	    AG_IS_REDUN(state) (((state) & (AGS_REDUN0 | AGS_REDUN1)) \
371				== (AGS_REDUN0 | AGS_REDUN1))
372#define	    AGS_GATEWAY	    0x010	/* tell kernel RTF_GATEWAY */
373#define	    AGS_IF	    0x020	/* for an interface */
374#define	    AGS_RIPV2	    0x040	/* send only as RIPv2 */
375#define	    AGS_FINE_GATE   0x080	/* ignore differing ag_gate when this
376					 * has the finer netmask */
377#define	    AGS_CORS_GATE   0x100	/* ignore differing gate when this
378					 * has the coarser netmaks */
379#define	    AGS_SPLIT_HZ    0x200	/* suppress for split horizon */
380
381	/* some bits are set if they are set on either route */
382#define	    AGS_PROMOTE_EITHER (AGS_RIPV2 | AGS_GATEWAY |   \
383				AGS_SUPPRESS | AGS_CORS_GATE)
384};
385
386
387/* parameters for interfaces */
388extern struct parm {
389	struct parm *parm_next;
390	char	parm_name[IFNAMSIZ+1];
391	naddr	parm_net;
392	naddr	parm_mask;
393
394	char	parm_d_metric;
395	u_int	parm_int_state;
396	int	parm_rdisc_pref;
397	int	parm_rdisc_int;
398	struct auth parm_auth;
399} *parms;
400
401/* authority for internal networks */
402extern struct intnet {
403	struct intnet *intnet_next;
404	naddr	intnet_addr;
405	naddr	intnet_mask;
406	char	intnet_metric;
407} *intnets;
408
409/* trusted routers */
410extern struct tgate {
411	struct tgate *tgate_next;
412	naddr	tgate_addr;
413} *tgates;
414
415enum output_type {OUT_QUERY, OUT_UNICAST, OUT_BROADCAST, OUT_MULTICAST,
416	NO_OUT_MULTICAST, NO_OUT_RIPV2};
417
418/* common output buffers */
419extern struct ws_buf {
420	struct rip	*buf;
421	struct netinfo	*n;
422	struct netinfo	*base;
423	struct netinfo	*lim;
424	enum output_type type;
425} v12buf, v2buf;
426
427extern pid_t	mypid;
428extern naddr	myaddr;			/* main address of this system */
429
430extern int	stopint;		/* !=0 to stop */
431
432extern int	sock_max;
433extern int	rip_sock;		/* RIP socket */
434extern struct interface *rip_sock_mcast;    /* current multicast interface */
435extern int	rt_sock;		/* routing socket */
436extern int	rt_sock_seqno;
437extern int	rdisc_sock;		/* router-discovery raw socket */
438
439extern int	seqno;			/* sequence number for messages */
440extern int	supplier;		/* process should supply updates */
441extern int	lookforinterfaces;	/* 1=probe for new up interfaces */
442extern int	supplier_set;		/* -s or -q requested */
443extern int	ridhosts;		/* 1=reduce host routes */
444extern int	mhome;			/* 1=want multi-homed host route */
445extern int	advertise_mhome;	/* 1=must continue adverising it */
446extern int	auth_ok;		/* 1=ignore auth if we do not care */
447
448extern struct timeval clk;		/* system clock's idea of time */
449extern struct timeval epoch;		/* system clock when started */
450extern struct timeval now;		/* current idea of time */
451extern time_t	now_stale;
452extern time_t	now_expire;
453extern time_t	now_garbage;
454
455extern struct timeval next_bcast;	/* next general broadcast */
456extern struct timeval age_timer;	/* next check of old routes */
457extern struct timeval no_flash;		/* inhibit flash update until then */
458extern struct timeval rdisc_timer;	/* next advert. or solicitation */
459extern int rdisc_ok;			/* using solicited route */
460
461extern struct timeval ifinit_timer;	/* time to check interfaces */
462
463extern naddr	loopaddr;		/* our address on loopback */
464extern int	tot_interfaces;		/* # of remote and local interfaces */
465extern int	rip_interfaces;		/* # of interfaces doing RIP */
466extern struct interface *ifnet;		/* all interfaces */
467extern struct interface *remote_if;	/* remote interfaces */
468extern int	have_ripv1_out;		/* have a RIPv1 interface */
469extern int	have_ripv1_in;
470extern int	need_flash;		/* flash update needed */
471extern struct timeval need_kern;	/* need to update kernel table */
472extern int	update_seqno;		/* a route has changed */
473
474extern u_int	tracelevel, new_tracelevel;
475#define MAX_TRACELEVEL 4
476#define TRACEKERNEL (tracelevel >= 4)	/* log kernel changes */
477#define	TRACECONTENTS (tracelevel >= 3)	/* display packet contents */
478#define TRACEPACKETS (tracelevel >= 2)	/* note packets */
479#define	TRACEACTIONS (tracelevel != 0)
480extern FILE	*ftrace;		/* output trace file */
481
482extern struct radix_node_head *rhead;
483
484
485#ifdef sgi
486/* Fix conflicts */
487#define	dup2(x,y)		BSDdup2(x,y)
488#endif /* sgi */
489
490extern void fix_sock(int, char *);
491extern void fix_select(void);
492extern void rip_off(void);
493extern void rip_on(struct interface *);
494
495extern void bufinit(void);
496extern int  output(enum output_type, struct sockaddr_in *,
497		   struct interface *, struct rip *, int);
498extern void clr_ws_buf(struct ws_buf *, struct auth_key *, struct interface *);
499extern void rip_query(void);
500extern void rip_bcast(int);
501extern void supply(struct sockaddr_in *, struct interface *,
502		   enum output_type, int, int, int);
503
504extern void	msglog(char *, ...);
505struct msg_limit {
506	naddr	addr;
507	time_t	until;
508};
509extern void	msglim(struct msg_limit *, naddr, char *, ...);
510#define	LOGERR(msg) msglog(msg ": %s", strerror(errno))
511extern void	logbad(int, char *, ...);
512#define	BADERR(dump,msg) logbad(dump,msg ": %s", strerror(errno))
513#ifdef DEBUG
514#define	DBGERR(dump,msg) BADERR(dump,msg)
515#else
516#define	DBGERR(dump,msg) LOGERR(msg)
517#endif
518extern	char	*naddr_ntoa(naddr);
519extern	char	*saddr_ntoa(struct sockaddr *);
520
521extern void	*rtmalloc(size_t, char *);
522extern void	timevaladd(struct timeval *, struct timeval *);
523extern void	intvl_random(struct timeval *, u_long, u_long);
524extern int	getnet(char *, naddr *, naddr *);
525extern int	gethost(char *, naddr *);
526extern void	gwkludge(void);
527extern char	*parse_parms(char *);
528extern char	*check_parms(struct parm *);
529extern void	get_parms(struct interface *);
530
531extern void	lastlog(void);
532extern void	trace_on(char *, int);
533extern void	trace_off(char*, ...);
534extern void	trace_flush(void);
535extern void	set_tracelevel(int);
536extern void	trace_kernel(char *, ...);
537extern void	trace_act(char *, ...);
538extern void	trace_pkt(char *, ...);
539extern void	trace_add_del(char *, struct rt_entry *);
540extern void	trace_change(struct rt_entry *, u_int, naddr, naddr, int,
541			     u_short, struct interface *, time_t, char *);
542extern void	trace_if(char *, struct interface *);
543extern void	trace_upslot(struct rt_entry *, struct rt_spare *,
544			     naddr, naddr,
545			     struct interface *, int, u_short, time_t);
546extern void	trace_rip(char*, char*, struct sockaddr_in *,
547			  struct interface *, struct rip *, int);
548extern char	*addrname(naddr, naddr, int);
549
550extern void	rdisc_age(naddr);
551extern void	set_rdisc_mg(struct interface *, int);
552extern void	set_supplier(void);
553extern void	if_bad_rdisc(struct interface *);
554extern void	if_ok_rdisc(struct interface *);
555extern void	read_rip(int, struct interface *);
556extern void	read_rt(void);
557extern void	read_d(void);
558extern void	rdisc_adv(void);
559extern void	rdisc_sol(void);
560
561extern void	sigalrm(int);
562extern void	sigterm(int);
563
564extern void	sigtrace_on(int);
565extern void	sigtrace_off(int);
566
567extern void	flush_kern(void);
568extern void	age(naddr);
569
570extern void	ag_flush(naddr, naddr, void (*)(struct ag_info *));
571extern void	ag_check(naddr, naddr, naddr, naddr, char, char, u_int,
572			 u_short, u_short, void (*)(struct ag_info *));
573extern void	del_static(naddr, naddr, int);
574extern void	del_redirects(naddr, time_t);
575extern struct rt_entry *rtget(naddr, naddr);
576extern struct rt_entry *rtfind(naddr);
577extern void	rtinit(void);
578extern void	rtadd(naddr, naddr, naddr, naddr,
579		      int, u_short, u_int, struct interface *);
580extern void	rtchange(struct rt_entry *, u_int, naddr,naddr, int, u_short,
581			 struct interface *ifp, time_t, char *);
582extern void	rtdelete(struct rt_entry *);
583extern void	rtbad_sub(struct rt_entry *);
584extern void	rtswitch(struct rt_entry *, struct rt_spare *);
585extern void	rtbad(struct rt_entry *);
586
587
588#define S_ADDR(x)	(((struct sockaddr_in *)(x))->sin_addr.s_addr)
589#define INFO_DST(I)	((I)->rti_info[RTAX_DST])
590#define INFO_GATE(I)	((I)->rti_info[RTAX_GATEWAY])
591#define INFO_MASK(I)	((I)->rti_info[RTAX_NETMASK])
592#define INFO_IFA(I)	((I)->rti_info[RTAX_IFA])
593#define INFO_IFP(I)	((I)->rti_info[RTAX_IFP])
594#define INFO_AUTHOR(I)	((I)->rti_info[RTAX_AUTHOR])
595#define INFO_BRD(I)	((I)->rti_info[RTAX_BRD])
596void rt_xaddrs(struct rt_addrinfo *, struct sockaddr *, struct sockaddr *,
597	       int);
598
599extern naddr	std_mask(naddr);
600extern naddr	ripv1_mask_net(naddr, struct interface *);
601extern naddr	ripv1_mask_host(naddr,struct interface *);
602#define		on_net(a,net,mask) (((ntohl(a) ^ (net)) & (mask)) == 0)
603extern int	check_dst(naddr);
604extern struct interface *check_dup(naddr, naddr, naddr, int);
605extern int	check_remote(struct interface *);
606extern int	addrouteforif(register struct interface *);
607extern void	ifinit(void);
608extern int	walk_bad(struct radix_node *, struct walkarg *);
609extern int	if_ok(struct interface *, char *);
610extern void	if_sick(struct interface *);
611extern void	if_bad(struct interface *);
612extern void	if_link(struct interface *);
613extern struct interface *ifwithaddr(naddr, int, int);
614extern struct interface *ifwithname(char *, naddr);
615extern struct interface *ifwithindex(u_short);
616extern struct interface *iflookup(naddr);
617
618extern struct auth_key *find_auth(struct interface *);
619extern void end_md5_auth(struct ws_buf *, struct auth_key *);
620
621#include <md5.h>
622