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