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