defs.h revision 20610
1105573Simp/* 2105573Simp * Copyright (c) 1983, 1988, 1993 3105573Simp * The Regents of the University of California. All rights reserved. 4105573Simp * 5105573Simp * Redistribution and use in source and binary forms, with or without 6105573Simp * modification, are permitted provided that the following conditions 7105573Simp * are met: 8105573Simp * 1. Redistributions of source code must retain the above copyright 9105573Simp * notice, this list of conditions and the following disclaimer. 10105573Simp * 2. Redistributions in binary form must reproduce the above copyright 11105573Simp * notice, this list of conditions and the following disclaimer in the 12105573Simp * documentation and/or other materials provided with the distribution. 13105573Simp * 3. All advertising materials mentioning features or use of this software 14105573Simp * must display the following acknowledgement: 15105573Simp * This product includes software developed by the University of 16105573Simp * California, Berkeley and its contributors. 17105573Simp * 4. Neither the name of the University nor the names of its contributors 18105573Simp * may be used to endorse or promote products derived from this software 19105573Simp * without specific prior written permission. 20105573Simp * 21105573Simp * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22105573Simp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23105573Simp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24105573Simp * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25111813Sru * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26105573Simp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27105573Simp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28105573Simp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29105573Simp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30105573Simp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31105573Simp * SUCH DAMAGE. 32105573Simp * 33105573Simp * @(#)defs.h 8.1 (Berkeley) 6/5/93 34105573Simp * $Id: defs.h,v 1.6 1996/12/17 21:11:51 wollman Exp $ 35105573Simp */ 36105573Simp 37105573Simp/* Definitions for RIPv2 routing process. 38105573Simp * 39105573Simp * This code is based on the 4.4BSD `routed` daemon, with extensions to 40105573Simp * support: 41105573Simp * RIPv2, including variable length subnet masks. 42105573Simp * Router Discovery 43111813Sru * aggregate routes in the kernel tables. 44307446Ssevan * aggregate advertised routes. 45105573Simp * maintain spare routes for faster selection of another gateway 46105573Simp * when the current gateway dies. 47105573Simp * timers on routes with second granularity so that selection 48105573Simp * of a new route does not wait 30-60 seconds. 49105573Simp * tolerance of static routes. 50108781Simp * tell the kernel hop counts 51111813Sru * do not advertise if ipforwarding=0 52105573Simp * 53105573Simp * The vestigual support for other protocols has been removed. There 54108317Sschweikh * is no likelihood that IETF RIPv1 or RIPv2 will ever be used with 55105573Simp * other protocols. The result is far smaller, faster, cleaner, and 56105573Simp * perhaps understandable. 57105573Simp * 58111813Sru * The accumulation of special flags and kludges added over the many 59105573Simp * years have been simplified and integrated. 60105573Simp */ 61105573Simp 62111813Sru#include <stdio.h> 63105573Simp#include <netdb.h> 64163106Sjmg#include <stdlib.h> 65105573Simp#include <unistd.h> 66105573Simp#include <errno.h> 67163106Sjmg#include <string.h> 68111813Sru#ifdef sgi 69105573Simp#include <strings.h> 70163106Sjmg#include <bstring.h> 71105573Simp#endif 72105573Simp#include <stdarg.h> 73163106Sjmg#include <syslog.h> 74163106Sjmg#include <time.h> 75163106Sjmg#include <sys/types.h> 76163106Sjmg#include <sys/param.h> 77163106Sjmg#include <sys/ioctl.h> 78163106Sjmg#include <sys/sysctl.h> 79105573Simp#include <sys/socket.h> 80105573Simp#include <sys/time.h> 81111813Sru#ifdef sgi 82111813Sru#include <net/radix.h> 83111813Sru#else 84111813Sru#include "radix.h" 85105573Simp#endif 86163106Sjmg#include <net/if.h> 87163581Sru#include <net/route.h> 88163106Sjmg#include <net/if_dl.h> 89163106Sjmg#include <netinet/in.h> 90163106Sjmg#include <arpa/inet.h> 91163106Sjmg#define RIPVERSION RIPv2 92163106Sjmg#include <protocols/routed.h> 93163106Sjmg 94163106Sjmg 95163106Sjmg/* Type of an IP address. 96163106Sjmg * Some systems do not like to pass structures, so do not use in_addr. 97163106Sjmg * Some systems think a long has 64 bits, which would be a gross waste. 98163106Sjmg * So define it here so it can be changed for the target system. 99163106Sjmg * It should be defined somewhere netinet/in.h, but it is not. 100163106Sjmg */ 101163106Sjmg#ifdef sgi 102163106Sjmg#define naddr __uint32_t 103163106Sjmg#else 104163106Sjmg#ifdef __NetBSD__ 105163106Sjmg#define naddr u_int32_t 106163581Sru#else 107163106Sjmg#define naddr u_long 108163106Sjmg#endif 109163581Sru#define _HAVE_SA_LEN 110163106Sjmg#define _HAVE_SIN_LEN 111163106Sjmg#endif 112186077Sphk 113163581Sru/* Turn on if IP_DROP_MEMBERSHIP and IP_ADD_MEMBERSHIP do not look at 114163581Sru * the dstaddr of point-to-point interfaces. 115163581Sru */ 116163106Sjmg/* #define MCAST_PPP_BUG */ 117163581Sru 118163581Sru#define DAY (24*60*60) 119163581Sru#define NEVER DAY /* a long time */ 120163106Sjmg#define EPOCH NEVER /* bias time by this to avoid <0 */ 121163581Sru 122189538Smaxim/* Scan the kernel regularly to see if any interfaces have appeared or been 123163106Sjmg * turned off. These must be less than STALE_TIME. 124226775Shrs */ 125226775Shrs#define CHECK_BAD_INTERVAL 5 /* when an interface is known bad */ 126226775Shrs#define CHECK_ACT_INTERVAL 30 /* when advertising */ 127226775Shrs#define CHECK_QUIET_INTERVAL 300 /* when not */ 128163106Sjmg 129163581Sru#define LIM_SEC(s,l) ((s).tv_sec = MIN((s).tv_sec, (l))) 130163106Sjmg 131163106Sjmg/* Metric used for fake default routes. It ought to be 15, but when 132163106Sjmg * processing advertised routes, previous versions of `routed` added 133163106Sjmg * to the received metric and discarded the route if the total was 16 134163581Sru * or larger. 135163106Sjmg */ 136163581Sru#define FAKE_METRIC (HOPCNT_INFINITY-2) 137163106Sjmg 138163106Sjmg 139163581Sru/* Router Discovery parameters */ 140163106Sjmg#ifndef sgi 141163106Sjmg#define INADDR_ALLROUTERS_GROUP 0xe0000002 /* 224.0.0.2 */ 142163581Sru#endif 143163581Sru#define MaxMaxAdvertiseInterval 1800 144163106Sjmg#define MinMaxAdvertiseInterval 4 145163581Sru#define DefMaxAdvertiseInterval 600 146163581Sru#define DEF_PreferenceLevel 0 147163106Sjmg#define MIN_PreferenceLevel 0x80000000 148163581Sru 149163106Sjmg#define MAX_INITIAL_ADVERT_INTERVAL 16 150163581Sru#define MAX_INITIAL_ADVERTS 3 151163106Sjmg#define MAX_RESPONSE_DELAY 2 152163106Sjmg 153163106Sjmg#define MAX_SOLICITATION_DELAY 1 154163581Sru#define SOLICITATION_INTERVAL 3 155163106Sjmg#define MAX_SOLICITATIONS 3 156163581Sru 157163581Sru 158163581Sru/* Bloated packet size for systems that simply add authentication to 159163581Sru * full-sized packets 160163106Sjmg */ 161163581Sru#define OVER_MAXPACKETSIZE (MAXPACKETSIZE+sizeof(struct netinfo)*2) 162163106Sjmg/* typical packet buffers */ 163163581Sruunion pkt_buf { 164163106Sjmg char packet[OVER_MAXPACKETSIZE*2]; 165163581Sru struct rip rip; 166163106Sjmg}; 167163106Sjmg 168163581Sru 169163106Sjmg/* No more routes than this, to protect ourself in case something goes 170163581Sru * whacko and starts broadcasting zillions of bogus routes. 171163106Sjmg */ 172163581Sru#define MAX_ROUTES (128*1024) 173163106Sjmgextern int total_routes; 174163106Sjmg 175163581Sru/* Main, daemon routing table structure 176163667Sru */ 177163667Srustruct rt_entry { 178163667Sru struct radix_node rt_nodes[2]; /* radix tree glue */ 179163667Sru u_int rt_state; 180163667Sru# define RS_IF 0x001 /* for network interface */ 181163667Sru# define RS_NET_INT 0x002 /* authority route */ 182163667Sru# define RS_NET_SYN 0x004 /* fake net route for subnet */ 183163667Sru# define RS_NO_NET_SYN (RS_LOCAL | RS_LOCAL | RS_IF) 184163667Sru# define RS_SUBNET 0x008 /* subnet route from any source */ 185247134Spluknet# define RS_LOCAL 0x010 /* loopback for pt-to-pt */ 186163581Sru# define RS_MHOME 0x020 /* from -m */ 187163106Sjmg# define RS_STATIC 0x040 /* from the kernel */ 188163581Sru# define RS_RDISC 0x080 /* from router discovery */ 189163106Sjmg struct sockaddr_in rt_dst_sock; 190163106Sjmg naddr rt_mask; 191163106Sjmg struct rt_spare { 192163581Sru struct interface *rts_ifp; 193163106Sjmg naddr rts_gate; /* forward packets here */ 194163106Sjmg naddr rts_router; /* on the authority of this router */ 195163581Sru char rts_metric; 196163106Sjmg u_short rts_tag; 197163581Sru time_t rts_time; /* timer to junk stale routes */ 198163106Sjmg#define NUM_SPARES 4 199163581Sru } rt_spares[NUM_SPARES]; 200163106Sjmg u_int rt_seqno; /* when last changed */ 201163581Sru char rt_poison_metric; /* to notice maximum recently */ 202163106Sjmg time_t rt_poison_time; /* advertised metric */ 203163581Sru}; 204163106Sjmg#define rt_dst rt_dst_sock.sin_addr.s_addr 205163106Sjmg#define rt_ifp rt_spares[0].rts_ifp 206163106Sjmg#define rt_gate rt_spares[0].rts_gate 207163106Sjmg#define rt_router rt_spares[0].rts_router 208163106Sjmg#define rt_metric rt_spares[0].rts_metric 209163581Sru#define rt_tag rt_spares[0].rts_tag 210163106Sjmg#define rt_time rt_spares[0].rts_time 211163106Sjmg 212163106Sjmg#define HOST_MASK 0xffffffff 213189538Smaxim#define RT_ISHOST(rt) ((rt)->rt_mask == HOST_MASK) 214163106Sjmg 215163106Sjmg/* age all routes that 216163581Sru * are not from -g, -m, or static routes from the kernel 217163581Sru * not unbroken interface routes 218163581Sru * but not broken interfaces 219163581Sru * nor non-passive, remote interfaces that are not aliases 220163581Sru * (i.e. remote & metric=0) 221163106Sjmg */ 222163581Sru#define AGE_RT(rt_state,ifp) (0 == ((rt_state) & (RS_MHOME | RS_STATIC \ 223163581Sru | RS_NET_SYN | RS_RDISC)) \ 224163581Sru && (!((rt_state) & RS_IF) \ 225163581Sru || (ifp) == 0 \ 226163581Sru || (((ifp)->int_state & IS_REMOTE) \ 227163106Sjmg && !((ifp)->int_state & IS_PASSIVE)))) 228189538Smaxim 229163667Sru/* true if A is better than B 230163667Sru * Better if 231163106Sjmg * - A is not a poisoned route 232163106Sjmg * - and A is not stale 233163106Sjmg * - and A has a shorter path 234163106Sjmg * - or is the router speaking for itself 235163581Sru * - or the current route is equal but stale 236163106Sjmg * - or it is a host route advertised by a system for itself 237163106Sjmg */ 238163581Sru#define BETTER_LINK(rt,A,B) ((A)->rts_metric < HOPCNT_INFINITY \ 239163106Sjmg && now_stale <= (A)->rts_time \ 240163106Sjmg && ((A)->rts_metric < (B)->rts_metric \ 241163581Sru || ((A)->rts_gate == (A)->rts_router \ 242163581Sru && (B)->rts_gate != (B)->rts_router) \ 243189534Skib || ((A)->rts_metric == (B)->rts_metric \ 244189534Skib && now_stale > (B)->rts_time) \ 245189534Skib || (RT_ISHOST(rt) \ 246189534Skib && (rt)->rt_dst == (A)->rts_router \ 247163581Sru && (A)->rts_metric == (B)->rts_metric))) 248163581Sru 249163581Sru 250163581Sru/* An "interface" is similar to a kernel ifnet structure, except it also 251163581Sru * handles "logical" or "IS_REMOTE" interfaces (remote gateways). 252163581Sru */ 253163581Srustruct interface { 254163581Sru struct interface *int_next, **int_prev; 255207072Sthompsa struct interface *int_ahash, **int_ahash_prev; 256207072Sthompsa struct interface *int_bhash, **int_bhash_prev; 257207072Sthompsa struct interface *int_rlink, **int_rlink_prev; 258207072Sthompsa struct interface *int_nhash, **int_nhash_prev; 259163581Sru char int_name[IFNAMSIZ+15+1]; /* big enough for IS_REMOTE */ 260163581Sru u_short int_index; 261207072Sthompsa naddr int_addr; /* address on this host (net order) */ 262207072Sthompsa naddr int_brdaddr; /* broadcast address (n) */ 263163581Sru naddr int_dstaddr; /* other end of pt-to-pt link (n) */ 264163581Sru naddr int_net; /* working network # (host order)*/ 265207072Sthompsa naddr int_mask; /* working net mask (host order) */ 266207072Sthompsa naddr int_ripv1_mask; /* for inferring a mask (n) */ 267207072Sthompsa naddr int_std_addr; /* class A/B/C address (n) */ 268207072Sthompsa naddr int_std_net; /* class A/B/C network (h) */ 269207072Sthompsa naddr int_std_mask; /* class A/B/C netmask (h) */ 270207072Sthompsa int int_rip_sock; /* for queries */ 271207072Sthompsa int int_if_flags; /* some bits copied from kernel */ 272207072Sthompsa u_int int_state; 273284666Strasz time_t int_act_time; /* last thought healthy */ 274284666Strasz time_t int_query_time; 275163581Sru u_short int_transitions; /* times gone up-down */ 276163581Sru char int_metric; 277207072Sthompsa char int_d_metric; /* for faked default route */ 278207072Sthompsa struct int_data { 279163581Sru u_int ipackets; /* previous network stats */ 280163106Sjmg u_int ierrors; 281163106Sjmg u_int opackets; 282163106Sjmg u_int oerrors; 283207072Sthompsa#ifdef sgi 284207072Sthompsa u_int odrops; 285284666Strasz#endif 286284666Strasz time_t ts; /* timestamp on network stats */ 287207072Sthompsa } int_data; 288207072Sthompsa# define MAX_AUTH_KEYS 5 289163581Sru struct auth { /* authentication info */ 290207072Sthompsa u_char type; 291207072Sthompsa u_char key[RIP_AUTH_PW_LEN]; 292207072Sthompsa u_char keyid; 293284666Strasz time_t start, end; 294284666Strasz } int_auth[MAX_AUTH_KEYS]; 295284666Strasz int int_rdisc_pref; /* advertised rdisc preference */ 296284666Strasz int int_rdisc_int; /* MaxAdvertiseInterval */ 297221719Sbms int int_rdisc_cnt; 298163581Sru struct timeval int_rdisc_timer; 299163581Sru}; 300163581Sru 301163581Sru/* bits in int_state */ 302163581Sru#define IS_ALIAS 0x0000001 /* interface alias */ 303163581Sru#define IS_SUBNET 0x0000002 /* interface on subnetted network */ 304163581Sru#define IS_REMOTE 0x0000004 /* interface is not on this machine */ 305163581Sru#define IS_PASSIVE 0x0000008 /* remote and does not do RIP */ 306163581Sru#define IS_EXTERNAL 0x0000010 /* handled by EGP or something */ 307163581Sru#define IS_CHECKED 0x0000020 /* still exists */ 308163581Sru#define IS_ALL_HOSTS 0x0000040 /* in INADDR_ALLHOSTS_GROUP */ 309163581Sru#define IS_ALL_ROUTERS 0x0000080 /* in INADDR_ALLROUTERS_GROUP */ 310163581Sru#define IS_DISTRUST 0x0000100 /* ignore untrusted routers */ 311163581Sru#define IS_REDIRECT_OK 0x0000200 /* accept ICMP redirects */ 312163581Sru#define IS_BROKE 0x0000400 /* seems to be broken */ 313163106Sjmg#define IS_SICK 0x0000800 /* seems to be broken */ 314163106Sjmg#define IS_DUP 0x0001000 /* has a duplicate address */ 315163581Sru#define IS_NEED_NET_SYN 0x0002000 /* need RS_NET_SYN route */ 316163581Sru#define IS_NO_AG 0x0004000 /* do not aggregate subnets */ 317163106Sjmg#define IS_NO_SUPER_AG 0x0008000 /* do not aggregate networks */ 318163106Sjmg#define IS_NO_RIPV1_IN 0x0010000 /* no RIPv1 input at all */ 319189534Skib#define IS_NO_RIPV2_IN 0x0020000 /* no RIPv2 input at all */ 320163581Sru#define IS_NO_RIP_IN (IS_NO_RIPV1_IN | IS_NO_RIPV2_IN) 321163581Sru#define IS_RIP_IN_OFF(s) (((s) & IS_NO_RIP_IN) == IS_NO_RIP_IN) 322163106Sjmg#define IS_NO_RIPV1_OUT 0x0040000 /* no RIPv1 output at all */ 323163581Sru#define IS_NO_RIPV2_OUT 0x0080000 /* no RIPv2 output at all */ 324163581Sru#define IS_NO_RIP_OUT (IS_NO_RIPV1_OUT | IS_NO_RIPV2_OUT) 325163581Sru#define IS_NO_RIP (IS_NO_RIP_OUT | IS_NO_RIP_IN) 326163581Sru#define IS_RIP_OUT_OFF(s) (((s) & IS_NO_RIP_OUT) == IS_NO_RIP_OUT) 327163581Sru#define IS_RIP_OFF(s) (((s) & IS_NO_RIP) == IS_NO_RIP) 328163106Sjmg#define IS_NO_ADV_IN 0x0100000 329163581Sru#define IS_NO_SOL_OUT 0x0200000 /* no solicitations */ 330163106Sjmg#define IS_SOL_OUT 0x0400000 /* send solicitations */ 331163581Sru#define GROUP_IS_SOL (IS_NO_ADV_IN|IS_NO_SOL_OUT) 332163106Sjmg#define IS_NO_ADV_OUT 0x0800000 /* do not advertise rdisc */ 333241772Savg#define IS_ADV_OUT 0x1000000 /* advertise rdisc */ 334241772Savg#define GROUP_IS_ADV (IS_NO_ADV_OUT|IS_ADV_OUT) 335286191Strasz#define IS_BCAST_RDISC 0x2000000 /* broadcast instead of multicast */ 336286191Strasz#define IS_NO_RDISC (IS_NO_ADV_IN | IS_NO_SOL_OUT | IS_NO_ADV_OUT) 337286191Strasz#define IS_PM_RDISC 0x4000000 /* poor-man's router discovery */ 338286191Strasz 339163581Sru#ifdef sgi 340163106Sjmg#define IFF_UP_RUNNING (IFF_RUNNING|IFF_UP) 341163106Sjmg#else 342163106Sjmg#define IFF_UP_RUNNING IFF_UP 343286190Strasz#endif 344286190Strasz#define iff_alive(f) (((f) & IFF_UP_RUNNING) == IFF_UP_RUNNING) 345286190Strasz 346286190Strasz 347286190Strasz/* Information for aggregating routes */ 348286190Strasz#define NUM_AG_SLOTS 32 349286190Straszstruct ag_info { 350286190Strasz struct ag_info *ag_fine; /* slot with finer netmask */ 351286190Strasz struct ag_info *ag_cors; /* more coarse netmask */ 352286190Strasz naddr ag_dst_h; /* destination in host byte order */ 353286190Strasz naddr ag_mask; 354286190Strasz naddr ag_gate; 355286190Strasz naddr ag_nhop; 356286190Strasz char ag_metric; /* metric to be advertised */ 357286190Strasz char ag_pref; /* aggregate based on this */ 358286190Strasz u_int ag_seqno; 359286190Strasz u_short ag_tag; 360286190Strasz u_short ag_state; 361286190Strasz#define AGS_SUPPRESS 0x001 /* combine with coaser mask */ 362286190Strasz#define AGS_PROMOTE 0x002 /* synthesize combined routes */ 363163581Sru#define AGS_REDUN0 0x004 /* redundant, finer routes output */ 364163106Sjmg#define AGS_REDUN1 0x008 365163581Sru#define AG_IS_REDUN(state) (((state) & (AGS_REDUN0 | AGS_REDUN1)) \ 366163581Sru == (AGS_REDUN0 | AGS_REDUN1)) 367163581Sru#define AGS_GATEWAY 0x010 /* tell kernel RTF_GATEWAY */ 368163106Sjmg#define AGS_IF 0x020 /* for an interface */ 369163106Sjmg#define AGS_RIPV2 0x040 /* send only as RIPv2 */ 370163106Sjmg#define AGS_FINE_GATE 0x080 /* ignore differing ag_gate when this 371163106Sjmg * has the finer netmask */ 372163581Sru#define AGS_CORS_GATE 0x100 /* ignore differing gate when this 373163581Sru * has the coarser netmaks */ 374163581Sru#define AGS_SPLIT_HZ 0x200 /* suppress for split horizon */ 375163106Sjmg 376163581Sru /* some bits are set if they are set on either route */ 377163106Sjmg#define AGS_PROMOTE_EITHER (AGS_RIPV2 | AGS_GATEWAY | \ 378189534Skib AGS_SUPPRESS | AGS_CORS_GATE) 379189538Smaxim}; 380189534Skib 381189538Smaxim 382163106Sjmg/* parameters for interfaces */ 383163106Sjmgextern struct parm { 384247129Spluknet struct parm *parm_next; 385189534Skib char parm_name[IFNAMSIZ+1]; 386189534Skib naddr parm_net; 387189534Skib naddr parm_mask; 388189534Skib 389189534Skib char parm_d_metric; 390189534Skib u_int parm_int_state; 391189534Skib int parm_rdisc_pref; 392189534Skib int parm_rdisc_int; 393189534Skib struct auth parm_auth[MAX_AUTH_KEYS]; 394189534Skib} *parms; 395189534Skib 396189534Skib/* authority for internal networks */ 397189534Skibextern struct intnet { 398189534Skib struct intnet *intnet_next; 399189534Skib naddr intnet_addr; 400189534Skib naddr intnet_mask; 401189534Skib char intnet_metric; 402163106Sjmg} *intnets; 403189534Skib 404247129Spluknet/* trusted routers */ 405282953Straszextern struct tgate { 406282953Strasz struct tgate *tgate_next; 407282953Strasz naddr tgate_addr; 408282953Strasz} *tgates; 409282953Strasz 410282953Straszenum output_type {OUT_QUERY, OUT_UNICAST, OUT_BROADCAST, OUT_MULTICAST, 411282953Strasz NO_OUT_MULTICAST, NO_OUT_RIPV2}; 412282953Strasz 413282953Strasz/* common output buffers */ 414282953Straszextern struct ws_buf { 415282953Strasz struct rip *buf; 416282953Strasz struct netinfo *n; 417282953Strasz struct netinfo *base; 418282953Strasz struct netinfo *lim; 419282953Strasz enum output_type type; 420282953Strasz} v12buf, v2buf; 421282953Strasz 422282953Straszextern pid_t mypid; 423282953Straszextern naddr myaddr; /* main address of this system */ 424282953Strasz 425282953Straszextern int stopint; /* !=0 to stop */ 426282953Strasz 427300214Sasomersextern int sock_max; 428300214Sasomersextern int rip_sock; /* RIP socket */ 429282953Straszextern struct interface *rip_sock_mcast; /* current multicast interface */ 430282953Straszextern int rt_sock; /* routing socket */ 431282953Straszextern int rt_sock_seqno; 432282953Straszextern int rdisc_sock; /* router-discovery raw socket */ 433282953Strasz 434284666Straszextern int seqno; /* sequence number for messages */ 435284666Straszextern int supplier; /* process should supply updates */ 436284666Straszextern int lookforinterfaces; /* 1=probe for new up interfaces */ 437284666Straszextern int supplier_set; /* -s or -q requested */ 438284666Straszextern int ridhosts; /* 1=reduce host routes */ 439284666Straszextern int mhome; /* 1=want multi-homed host route */ 440284666Straszextern int advertise_mhome; /* 1=must continue adverising it */ 441284666Straszextern int auth_ok; /* 1=ignore auth if we do not care */ 442284666Strasz 443284666Straszextern struct timeval clk; /* system clock's idea of time */ 444284666Straszextern struct timeval epoch; /* system clock when started */ 445284666Straszextern struct timeval now; /* current idea of time */ 446284666Straszextern time_t now_stale; 447284666Straszextern time_t now_expire; 448207072Sthompsaextern time_t now_garbage; 449207072Sthompsa 450207072Sthompsaextern struct timeval next_bcast; /* next general broadcast */ 451207072Sthompsaextern struct timeval age_timer; /* next check of old routes */ 452207072Sthompsaextern struct timeval no_flash; /* inhibit flash update until then */ 453207072Sthompsaextern struct timeval rdisc_timer; /* next advert. or solicitation */ 454207072Sthompsaextern int rdisc_ok; /* using solicited route */ 455207072Sthompsa 456207072Sthompsaextern struct timeval ifinit_timer; /* time to check interfaces */ 457207072Sthompsa 458207072Sthompsaextern naddr loopaddr; /* our address on loopback */ 459207072Sthompsaextern int tot_interfaces; /* # of remote and local interfaces */ 460207072Sthompsaextern int rip_interfaces; /* # of interfaces doing RIP */ 461207072Sthompsaextern struct interface *ifnet; /* all interfaces */ 462207072Sthompsaextern struct interface *remote_if; /* remote interfaces */ 463207072Sthompsaextern int have_ripv1_out; /* have a RIPv1 interface */ 464211397Sjoelextern int have_ripv1_in; 465207072Sthompsaextern int need_flash; /* flash update needed */ 466207072Sthompsaextern struct timeval need_kern; /* need to update kernel table */ 467207072Sthompsaextern int update_seqno; /* a route has changed */ 468207072Sthompsa 469247129Spluknetextern int tracelevel, new_tracelevel; 470189534Skib#define MAX_TRACELEVEL 4 471189534Skib#define TRACEKERNEL (tracelevel >= 4) /* log kernel changes */ 472189534Skib#define TRACECONTENTS (tracelevel >= 3) /* display packet contents */ 473189534Skib#define TRACEPACKETS (tracelevel >= 2) /* note packets */ 474189534Skib#define TRACEACTIONS (tracelevel != 0) 475189534Skibextern FILE *ftrace; /* output trace file */ 476189534Skibextern char inittracename[MAXPATHLEN+1]; 477189534Skib 478189534Skibextern struct radix_node_head *rhead; 479189534Skib 480189534Skib 481189534Skib#ifdef sgi 482189534Skib/* Fix conflicts */ 483189534Skib#define dup2(x,y) BSDdup2(x,y) 484247129Spluknet#endif /* sgi */ 485189534Skib 486189534Skibextern void fix_sock(int, char *); 487189534Skibextern void fix_select(void); 488189534Skibextern void rip_off(void); 489189534Skibextern void rip_on(struct interface *); 490189534Skib 491189534Skibextern void bufinit(void); 492189534Skibextern int output(enum output_type, struct sockaddr_in *, 493189534Skib struct interface *, struct rip *, int); 494189534Skibextern void clr_ws_buf(struct ws_buf *, struct auth *); 495189534Skibextern void rip_query(void); 496189534Skibextern void rip_bcast(int); 497298135Sscottlextern void supply(struct sockaddr_in *, struct interface *, 498298135Sscottl enum output_type, int, int, int); 499298135Sscottl 500298135Sscottlextern void msglog(char *, ...); 501298135Sscottlstruct msg_limit { 502298135Sscottl time_t reuse; 503298135Sscottl struct msg_sub { 504298135Sscottl naddr addr; 505298135Sscottl time_t until; 506298135Sscottl# define MSG_SUBJECT_N 8 507298135Sscottl } subs[MSG_SUBJECT_N]; 508298135Sscottl}; 509298135Sscottlextern void msglim(struct msg_limit *, naddr, char *, ...); 510298135Sscottl#define LOGERR(msg) msglog(msg ": %s", strerror(errno)) 511298135Sscottlextern void logbad(int, char *, ...); 512189534Skib#define BADERR(dump,msg) logbad(dump,msg ": %s", strerror(errno)) 513298135Sscottl#ifdef DEBUG 514298135Sscottl#define DBGERR(dump,msg) BADERR(dump,msg) 515163106Sjmg#else 516163106Sjmg#define DBGERR(dump,msg) LOGERR(msg) 517163581Sru#endif 518163106Sjmgextern char *naddr_ntoa(naddr); 519163106Sjmgextern char *saddr_ntoa(struct sockaddr *); 520163106Sjmg 521163106Sjmgextern void *rtmalloc(size_t, char *); 522163106Sjmgextern void timevaladd(struct timeval *, struct timeval *); 523163106Sjmgextern void intvl_random(struct timeval *, u_long, u_long); 524163106Sjmgextern int getnet(char *, naddr *, naddr *); 525163106Sjmgextern int gethost(char *, naddr *); 526163106Sjmgextern void gwkludge(void); 527163106Sjmgextern char *parse_parms(char *, int); 528163106Sjmgextern char *check_parms(struct parm *); 529163106Sjmgextern void get_parms(struct interface *); 530107665Simp 531111813Sruextern void lastlog(void); 532111813Sruextern void set_tracefile(char *, char *, int); 533111813Sruextern void tracelevel_msg(char *, int); 534105573Simpextern void trace_off(char*, ...); 535105573Simpextern void set_tracelevel(void); 536111813Sruextern void trace_flush(void); 537105573Simpextern void trace_kernel(char *, ...); 538111813Sruextern void trace_act(char *, ...); 539105573Simpextern void trace_pkt(char *, ...); 540105573Simpextern void trace_add_del(char *, struct rt_entry *); 541105573Simpextern void trace_change(struct rt_entry *, u_int, naddr, naddr, int, 542105573Simp u_short, struct interface *, time_t, char *); 543105573Simpextern void trace_if(char *, struct interface *); 544111813Sruextern void trace_upslot(struct rt_entry *, struct rt_spare *, 545111813Sru naddr, naddr, 546105573Simp struct interface *, int, u_short, time_t); 547111813Sruextern void trace_rip(char*, char*, struct sockaddr_in *, 548105573Simp struct interface *, struct rip *, int); 549105573Simpextern char *addrname(naddr, naddr, int); 550105573Simp 551105573Simpextern void rdisc_age(naddr); 552105573Simpextern void set_rdisc_mg(struct interface *, int); 553105573Simpextern void set_supplier(void); 554105573Simpextern void if_bad_rdisc(struct interface *); 555105573Simpextern void if_ok_rdisc(struct interface *); 556111813Sruextern void read_rip(int, struct interface *); 557105573Simpextern void read_rt(void); 558105573Simpextern void read_d(void); 559105573Simpextern void rdisc_adv(void); 560163581Sruextern void rdisc_sol(void); 561111813Sru 562111813Sruextern void sigalrm(int); 563105573Simpextern void sigterm(int); 564105573Simp 565105573Simpextern void sigtrace_on(int); 566105573Simpextern void sigtrace_off(int); 567105573Simp 568163581Sruextern void flush_kern(void); 569163581Sruextern void age(naddr); 570163581Sru 571163581Sruextern void ag_flush(naddr, naddr, void (*)(struct ag_info *)); 572163581Sruextern void ag_check(naddr, naddr, naddr, naddr, char, char, u_int, 573163581Sru u_short, u_short, void (*)(struct ag_info *)); 574163581Sruextern void del_static(naddr, naddr, int); 575163106Sjmgextern void del_redirects(naddr, time_t); 576163106Sjmgextern struct rt_entry *rtget(naddr, naddr); 577163106Sjmgextern struct rt_entry *rtfind(naddr); 578163106Sjmgextern void rtinit(void); 579163106Sjmgextern void rtadd(naddr, naddr, naddr, naddr, 580163106Sjmg int, u_short, u_int, struct interface *); 581163106Sjmgextern void rtchange(struct rt_entry *, u_int, naddr,naddr, int, u_short, 582163106Sjmg struct interface *ifp, time_t, char *); 583163106Sjmgextern void rtdelete(struct rt_entry *); 584163106Sjmgextern void rtbad_sub(struct rt_entry *); 585163106Sjmgextern void rtswitch(struct rt_entry *, struct rt_spare *); 586163106Sjmgextern void rtbad(struct rt_entry *); 587163106Sjmg 588163106Sjmg 589163106Sjmg#define S_ADDR(x) (((struct sockaddr_in *)(x))->sin_addr.s_addr) 590163106Sjmg#define INFO_DST(I) ((I)->rti_info[RTAX_DST]) 591163106Sjmg#define INFO_GATE(I) ((I)->rti_info[RTAX_GATEWAY]) 592163106Sjmg#define INFO_MASK(I) ((I)->rti_info[RTAX_NETMASK]) 593163106Sjmg#define INFO_IFA(I) ((I)->rti_info[RTAX_IFA]) 594163106Sjmg#define INFO_IFP(I) ((I)->rti_info[RTAX_IFP]) 595163106Sjmg#define INFO_AUTHOR(I) ((I)->rti_info[RTAX_AUTHOR]) 596163106Sjmg#define INFO_BRD(I) ((I)->rti_info[RTAX_BRD]) 597163106Sjmgvoid rt_xaddrs(struct rt_addrinfo *, struct sockaddr *, struct sockaddr *, 598163106Sjmg int); 599163106Sjmg 600163106Sjmgextern naddr std_mask(naddr); 601163106Sjmgextern naddr ripv1_mask_net(naddr, struct interface *); 602163106Sjmgextern naddr ripv1_mask_host(naddr,struct interface *); 603163106Sjmg#define on_net(a,net,mask) (((ntohl(a) ^ (net)) & (mask)) == 0) 604163106Sjmgextern int check_dst(naddr); 605163106Sjmgextern struct interface *check_dup(naddr, naddr, naddr, int); 606163106Sjmgextern int check_remote(struct interface *); 607207072Sthompsaextern int addrouteforif(register struct interface *); 608207072Sthompsaextern void ifinit(void); 609207072Sthompsaextern int walk_bad(struct radix_node *, struct walkarg *); 610207072Sthompsaextern int if_ok(struct interface *, char *); 611207072Sthompsaextern void if_sick(struct interface *); 612207072Sthompsaextern void if_bad(struct interface *); 613207072Sthompsaextern void if_link(struct interface *); 614207072Sthompsaextern struct interface *ifwithaddr(naddr, int, int); 615207072Sthompsaextern struct interface *ifwithname(char *, naddr); 616207072Sthompsaextern struct interface *ifwithindex(u_short); 617207072Sthompsaextern struct interface *iflookup(naddr); 618163106Sjmg 619163106Sjmgextern struct auth *find_auth(struct interface *); 620163106Sjmgextern void end_md5_auth(struct ws_buf *, struct auth *); 621163106Sjmg 622163106Sjmg#include <md5.h> 623163106Sjmg