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