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