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