1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 3*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 4*7c478bd9Sstevel@tonic-gate * 5*7c478bd9Sstevel@tonic-gate * Copyright (c) 1983, 1988, 1993 6*7c478bd9Sstevel@tonic-gate * The Regents of the University of California. All rights reserved. 7*7c478bd9Sstevel@tonic-gate * 8*7c478bd9Sstevel@tonic-gate * Redistribution and use in source and binary forms, with or without 9*7c478bd9Sstevel@tonic-gate * modification, are permitted provided that the following conditions 10*7c478bd9Sstevel@tonic-gate * are met: 11*7c478bd9Sstevel@tonic-gate * 1. Redistributions of source code must retain the above copyright 12*7c478bd9Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer. 13*7c478bd9Sstevel@tonic-gate * 2. Redistributions in binary form must reproduce the above copyright 14*7c478bd9Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer in the 15*7c478bd9Sstevel@tonic-gate * documentation and/or other materials provided with the distribution. 16*7c478bd9Sstevel@tonic-gate * 3. All advertising materials mentioning features or use of this software 17*7c478bd9Sstevel@tonic-gate * must display the following acknowledgment: 18*7c478bd9Sstevel@tonic-gate * This product includes software developed by the University of 19*7c478bd9Sstevel@tonic-gate * California, Berkeley and its contributors. 20*7c478bd9Sstevel@tonic-gate * 4. Neither the name of the University nor the names of its contributors 21*7c478bd9Sstevel@tonic-gate * may be used to endorse or promote products derived from this software 22*7c478bd9Sstevel@tonic-gate * without specific prior written permission. 23*7c478bd9Sstevel@tonic-gate * 24*7c478bd9Sstevel@tonic-gate * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25*7c478bd9Sstevel@tonic-gate * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26*7c478bd9Sstevel@tonic-gate * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27*7c478bd9Sstevel@tonic-gate * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28*7c478bd9Sstevel@tonic-gate * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29*7c478bd9Sstevel@tonic-gate * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30*7c478bd9Sstevel@tonic-gate * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31*7c478bd9Sstevel@tonic-gate * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32*7c478bd9Sstevel@tonic-gate * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33*7c478bd9Sstevel@tonic-gate * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34*7c478bd9Sstevel@tonic-gate * SUCH DAMAGE. 35*7c478bd9Sstevel@tonic-gate * 36*7c478bd9Sstevel@tonic-gate * @(#)defs.h 8.1 (Berkeley) 6/5/93 37*7c478bd9Sstevel@tonic-gate * 38*7c478bd9Sstevel@tonic-gate * $FreeBSD: src/sbin/routed/defs.h,v 1.14 2000/08/11 08:24:38 sheldonh Exp $ 39*7c478bd9Sstevel@tonic-gate */ 40*7c478bd9Sstevel@tonic-gate 41*7c478bd9Sstevel@tonic-gate #ifndef _DEFS_H 42*7c478bd9Sstevel@tonic-gate #define _DEFS_H 43*7c478bd9Sstevel@tonic-gate 44*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 45*7c478bd9Sstevel@tonic-gate 46*7c478bd9Sstevel@tonic-gate /* 47*7c478bd9Sstevel@tonic-gate * Definitions for RIPv2 routing process. 48*7c478bd9Sstevel@tonic-gate * 49*7c478bd9Sstevel@tonic-gate * This code is based on the 4.4BSD `routed` daemon, with extensions to 50*7c478bd9Sstevel@tonic-gate * support: 51*7c478bd9Sstevel@tonic-gate * RIPv2, including variable length subnet masks. 52*7c478bd9Sstevel@tonic-gate * Router Discovery 53*7c478bd9Sstevel@tonic-gate * aggregate routes in the kernel tables. 54*7c478bd9Sstevel@tonic-gate * aggregate advertised routes. 55*7c478bd9Sstevel@tonic-gate * maintain spare routes for faster selection of another gateway 56*7c478bd9Sstevel@tonic-gate * when the current gateway dies. 57*7c478bd9Sstevel@tonic-gate * timers on routes with second granularity so that selection 58*7c478bd9Sstevel@tonic-gate * of a new route does not wait 30-60 seconds. 59*7c478bd9Sstevel@tonic-gate * tolerance of static routes. 60*7c478bd9Sstevel@tonic-gate * tell the kernel hop counts. 61*7c478bd9Sstevel@tonic-gate * use of per-interface ip_forwarding state. 62*7c478bd9Sstevel@tonic-gate * 63*7c478bd9Sstevel@tonic-gate * The vestigial support for other protocols has been removed. There 64*7c478bd9Sstevel@tonic-gate * is no likelihood that IETF RIPv1 or RIPv2 will ever be used with 65*7c478bd9Sstevel@tonic-gate * other protocols. The result is far smaller, faster, cleaner, and 66*7c478bd9Sstevel@tonic-gate * perhaps understandable. 67*7c478bd9Sstevel@tonic-gate * 68*7c478bd9Sstevel@tonic-gate * The accumulation of special flags and kludges added over the many 69*7c478bd9Sstevel@tonic-gate * years have been simplified and integrated. 70*7c478bd9Sstevel@tonic-gate */ 71*7c478bd9Sstevel@tonic-gate 72*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 73*7c478bd9Sstevel@tonic-gate extern "C" { 74*7c478bd9Sstevel@tonic-gate #endif 75*7c478bd9Sstevel@tonic-gate 76*7c478bd9Sstevel@tonic-gate #include <stdio.h> 77*7c478bd9Sstevel@tonic-gate #include <netdb.h> 78*7c478bd9Sstevel@tonic-gate #include <stdlib.h> 79*7c478bd9Sstevel@tonic-gate #include <unistd.h> 80*7c478bd9Sstevel@tonic-gate #include <errno.h> 81*7c478bd9Sstevel@tonic-gate #include <string.h> 82*7c478bd9Sstevel@tonic-gate #include <stdarg.h> 83*7c478bd9Sstevel@tonic-gate #include <syslog.h> 84*7c478bd9Sstevel@tonic-gate #include <time.h> 85*7c478bd9Sstevel@tonic-gate #include <md5.h> 86*7c478bd9Sstevel@tonic-gate #include <libintl.h> 87*7c478bd9Sstevel@tonic-gate #include <locale.h> 88*7c478bd9Sstevel@tonic-gate #include "radix.h" 89*7c478bd9Sstevel@tonic-gate 90*7c478bd9Sstevel@tonic-gate #include <sys/time.h> 91*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 92*7c478bd9Sstevel@tonic-gate #include <sys/param.h> 93*7c478bd9Sstevel@tonic-gate #include <sys/ioctl.h> 94*7c478bd9Sstevel@tonic-gate #include <sys/socket.h> 95*7c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h> 96*7c478bd9Sstevel@tonic-gate 97*7c478bd9Sstevel@tonic-gate #include <net/if.h> 98*7c478bd9Sstevel@tonic-gate #include <net/route.h> 99*7c478bd9Sstevel@tonic-gate #include <net/if_dl.h> 100*7c478bd9Sstevel@tonic-gate #include <netinet/in.h> 101*7c478bd9Sstevel@tonic-gate #include <arpa/inet.h> 102*7c478bd9Sstevel@tonic-gate #define RIPVERSION RIPv2 103*7c478bd9Sstevel@tonic-gate #include <protocols/routed.h> 104*7c478bd9Sstevel@tonic-gate 105*7c478bd9Sstevel@tonic-gate 106*7c478bd9Sstevel@tonic-gate #define DAY (24*60*60) 107*7c478bd9Sstevel@tonic-gate #define NEVER DAY /* a long time */ 108*7c478bd9Sstevel@tonic-gate #define EPOCH NEVER /* bias time by this to avoid <0 */ 109*7c478bd9Sstevel@tonic-gate 110*7c478bd9Sstevel@tonic-gate /* 111*7c478bd9Sstevel@tonic-gate * Scan the kernel regularly to see if any interfaces have appeared or been 112*7c478bd9Sstevel@tonic-gate * turned off. 113*7c478bd9Sstevel@tonic-gate */ 114*7c478bd9Sstevel@tonic-gate #define CHECK_BAD_INTERVAL 5 /* when an interface is known bad */ 115*7c478bd9Sstevel@tonic-gate #define CHECK_ACT_INTERVAL 30 /* when advertising */ 116*7c478bd9Sstevel@tonic-gate #define CHECK_QUIET_INTERVAL 300 /* when not */ 117*7c478bd9Sstevel@tonic-gate 118*7c478bd9Sstevel@tonic-gate /* 119*7c478bd9Sstevel@tonic-gate * Limit the seconds in the timeval structure "s" to "l" seconds, but only 120*7c478bd9Sstevel@tonic-gate * if l is less than the current seconds in s. This is used to shorten 121*7c478bd9Sstevel@tonic-gate * certain timers to ensure that scheduled events occur sooner than 122*7c478bd9Sstevel@tonic-gate * originally scheduled. 123*7c478bd9Sstevel@tonic-gate */ 124*7c478bd9Sstevel@tonic-gate #define LIM_SEC(s, l) ((s).tv_sec = MIN((s).tv_sec, (l))) 125*7c478bd9Sstevel@tonic-gate 126*7c478bd9Sstevel@tonic-gate /* 127*7c478bd9Sstevel@tonic-gate * Metric used for fake default routes. It ought to be 15, but when 128*7c478bd9Sstevel@tonic-gate * processing advertised routes, previous versions of `routed` added 129*7c478bd9Sstevel@tonic-gate * to the received metric and discarded the route if the total was 16 130*7c478bd9Sstevel@tonic-gate * or larger. 131*7c478bd9Sstevel@tonic-gate */ 132*7c478bd9Sstevel@tonic-gate #define FAKE_METRIC (HOPCNT_INFINITY-2) 133*7c478bd9Sstevel@tonic-gate 134*7c478bd9Sstevel@tonic-gate 135*7c478bd9Sstevel@tonic-gate /* Router Discovery parameters */ 136*7c478bd9Sstevel@tonic-gate #define MAX_MAXADVERTISEINTERVAL 1800 137*7c478bd9Sstevel@tonic-gate #define MIN_MAXADVERTISEINTERVAL 4 138*7c478bd9Sstevel@tonic-gate #define DEF_MAXADVERTISEINTERVAL 600 139*7c478bd9Sstevel@tonic-gate #define DEF_PREFERENCELEVEL 0 140*7c478bd9Sstevel@tonic-gate #define MIN_PREFERENCELEVEL 0x80000000 141*7c478bd9Sstevel@tonic-gate 142*7c478bd9Sstevel@tonic-gate #define MAX_INITIAL_ADVERT_INTERVAL 16 143*7c478bd9Sstevel@tonic-gate #define MAX_INITIAL_ADVERTS 3 144*7c478bd9Sstevel@tonic-gate #define MAX_RESPONSE_DELAY 2 145*7c478bd9Sstevel@tonic-gate 146*7c478bd9Sstevel@tonic-gate #define MAX_SOLICITATION_DELAY 1 147*7c478bd9Sstevel@tonic-gate #define SOLICITATION_INTERVAL 3 148*7c478bd9Sstevel@tonic-gate #define MAX_SOLICITATIONS 3 149*7c478bd9Sstevel@tonic-gate 150*7c478bd9Sstevel@tonic-gate /* 151*7c478bd9Sstevel@tonic-gate * convert between signed, balanced around zero, 152*7c478bd9Sstevel@tonic-gate * and unsigned zero-based preferences 153*7c478bd9Sstevel@tonic-gate */ 154*7c478bd9Sstevel@tonic-gate #define SIGN_PREF(p) ((p) ^ MIN_PREFERENCELEVEL) 155*7c478bd9Sstevel@tonic-gate #define UNSIGN_PREF(p) SIGN_PREF(p) 156*7c478bd9Sstevel@tonic-gate 157*7c478bd9Sstevel@tonic-gate /* 158*7c478bd9Sstevel@tonic-gate * Bloated packet size for systems that simply add authentication to 159*7c478bd9Sstevel@tonic-gate * full-sized packets 160*7c478bd9Sstevel@tonic-gate */ 161*7c478bd9Sstevel@tonic-gate #define OVER_MAXPACKETSIZE (MAXPACKETSIZE+sizeof (struct netinfo)*2) 162*7c478bd9Sstevel@tonic-gate /* typical packet buffers */ 163*7c478bd9Sstevel@tonic-gate union pkt_buf { 164*7c478bd9Sstevel@tonic-gate uint8_t packet[OVER_MAXPACKETSIZE*2]; 165*7c478bd9Sstevel@tonic-gate struct rip rip; 166*7c478bd9Sstevel@tonic-gate }; 167*7c478bd9Sstevel@tonic-gate 168*7c478bd9Sstevel@tonic-gate /* 169*7c478bd9Sstevel@tonic-gate * IF_NAME_LEN is the maximum size of interface names represented within 170*7c478bd9Sstevel@tonic-gate * in.routed. Regular Solaris interfaces have names of at most LIFNAMESIZ 171*7c478bd9Sstevel@tonic-gate * characters, but in.routed has remote interfaces represented internally 172*7c478bd9Sstevel@tonic-gate * as "remote(<gatewayname>)", where <gatewayname> is a hostname or IP 173*7c478bd9Sstevel@tonic-gate * address. IF_NAME_LEN needs to be large enough to also hold such 174*7c478bd9Sstevel@tonic-gate * interface names as well. 175*7c478bd9Sstevel@tonic-gate */ 176*7c478bd9Sstevel@tonic-gate #define IF_NAME_LEN (MAXHOSTNAMELEN + sizeof ("remote()") + 1) 177*7c478bd9Sstevel@tonic-gate 178*7c478bd9Sstevel@tonic-gate /* 179*7c478bd9Sstevel@tonic-gate * No more routes than this, to protect ourself in case something goes 180*7c478bd9Sstevel@tonic-gate * whacko and starts broadcasting zillions of bogus routes. 181*7c478bd9Sstevel@tonic-gate */ 182*7c478bd9Sstevel@tonic-gate #define MAX_ROUTES (128*1024) 183*7c478bd9Sstevel@tonic-gate 184*7c478bd9Sstevel@tonic-gate enum origin { 185*7c478bd9Sstevel@tonic-gate RO_NONE, /* empty slot */ 186*7c478bd9Sstevel@tonic-gate RO_RIP, /* learnt from RIP */ 187*7c478bd9Sstevel@tonic-gate RO_RDISC, /* learnt from RDISC */ 188*7c478bd9Sstevel@tonic-gate RO_STATIC, /* learnt from kernel */ 189*7c478bd9Sstevel@tonic-gate RO_LOOPBCK, /* loopback route */ 190*7c478bd9Sstevel@tonic-gate RO_PTOPT, /* point-to-point route */ 191*7c478bd9Sstevel@tonic-gate RO_NET_SYN, /* fake net route for subnet */ 192*7c478bd9Sstevel@tonic-gate RO_IF, /* interface route */ 193*7c478bd9Sstevel@tonic-gate RO_FILE /* from /etc/gateways */ 194*7c478bd9Sstevel@tonic-gate }; 195*7c478bd9Sstevel@tonic-gate 196*7c478bd9Sstevel@tonic-gate /* 197*7c478bd9Sstevel@tonic-gate * Main, daemon routing table structure 198*7c478bd9Sstevel@tonic-gate */ 199*7c478bd9Sstevel@tonic-gate struct rt_spare { 200*7c478bd9Sstevel@tonic-gate struct interface *rts_ifp; 201*7c478bd9Sstevel@tonic-gate uint32_t rts_gate; /* forward packets here */ 202*7c478bd9Sstevel@tonic-gate uint32_t rts_router; /* on this router's authority */ 203*7c478bd9Sstevel@tonic-gate uint8_t rts_metric; 204*7c478bd9Sstevel@tonic-gate enum origin rts_origin; 205*7c478bd9Sstevel@tonic-gate uint16_t rts_tag; 206*7c478bd9Sstevel@tonic-gate time_t rts_time; /* timer to junk stale routes */ 207*7c478bd9Sstevel@tonic-gate uint32_t rts_de_ag; /* de-aggregation level */ 208*7c478bd9Sstevel@tonic-gate uint16_t rts_flags; 209*7c478bd9Sstevel@tonic-gate }; 210*7c478bd9Sstevel@tonic-gate 211*7c478bd9Sstevel@tonic-gate #define RTS_EXTERNAL 0x0001 /* handled by other routing protocol e.g. EGP */ 212*7c478bd9Sstevel@tonic-gate #define SPARE_INC 2 213*7c478bd9Sstevel@tonic-gate #define EMPTY_RT_SPARE { NULL, 0, 0, HOPCNT_INFINITY, RO_NONE, 0, 0, 0, 0 } 214*7c478bd9Sstevel@tonic-gate 215*7c478bd9Sstevel@tonic-gate struct rt_entry { 216*7c478bd9Sstevel@tonic-gate struct radix_node rt_nodes[2]; /* radix tree glue */ 217*7c478bd9Sstevel@tonic-gate struct sockaddr_in rt_dst_sock; 218*7c478bd9Sstevel@tonic-gate time_t rt_poison_time; /* advertised metric */ 219*7c478bd9Sstevel@tonic-gate in_addr_t rt_mask; 220*7c478bd9Sstevel@tonic-gate uint32_t rt_seqno; /* when last changed */ 221*7c478bd9Sstevel@tonic-gate uint16_t rt_state; 222*7c478bd9Sstevel@tonic-gate #define RS_IF 0x0001 /* for network interface */ 223*7c478bd9Sstevel@tonic-gate #define RS_NET_INT 0x0002 /* authority route */ 224*7c478bd9Sstevel@tonic-gate #define RS_NET_SYN 0x0004 /* fake net route for subnet */ 225*7c478bd9Sstevel@tonic-gate #define RS_NO_NET_SYN (RS_LOCAL | RS_IF) 226*7c478bd9Sstevel@tonic-gate #define RS_SUBNET 0x0008 /* subnet route from any source */ 227*7c478bd9Sstevel@tonic-gate #define RS_LOCAL 0x0010 /* loopback for pt-to-pt */ 228*7c478bd9Sstevel@tonic-gate #define RS_MHOME 0x0020 /* from -m */ 229*7c478bd9Sstevel@tonic-gate #define RS_STATIC 0x0040 /* from the kernel */ 230*7c478bd9Sstevel@tonic-gate #define RS_NOPROPAGATE 0x0080 /* route which must not be propagated */ 231*7c478bd9Sstevel@tonic-gate #define RS_BADIF 0x0100 /* route through dead ifp */ 232*7c478bd9Sstevel@tonic-gate 233*7c478bd9Sstevel@tonic-gate uint8_t rt_poison_metric; /* to notice maximum recently */ 234*7c478bd9Sstevel@tonic-gate uint_t rt_num_spares; 235*7c478bd9Sstevel@tonic-gate struct rt_spare *rt_spares; 236*7c478bd9Sstevel@tonic-gate }; 237*7c478bd9Sstevel@tonic-gate #define rt_dst rt_dst_sock.sin_addr.s_addr 238*7c478bd9Sstevel@tonic-gate #define rt_ifp rt_spares[0].rts_ifp 239*7c478bd9Sstevel@tonic-gate #define rt_gate rt_spares[0].rts_gate 240*7c478bd9Sstevel@tonic-gate #define rt_router rt_spares[0].rts_router 241*7c478bd9Sstevel@tonic-gate #define rt_metric rt_spares[0].rts_metric 242*7c478bd9Sstevel@tonic-gate #define rt_tag rt_spares[0].rts_tag 243*7c478bd9Sstevel@tonic-gate #define rt_time rt_spares[0].rts_time 244*7c478bd9Sstevel@tonic-gate #define rt_de_ag rt_spares[0].rts_de_ag 245*7c478bd9Sstevel@tonic-gate 246*7c478bd9Sstevel@tonic-gate #define HOST_MASK 0xffffffffU 247*7c478bd9Sstevel@tonic-gate #define RT_ISHOST(rt) ((rt)->rt_mask == HOST_MASK) 248*7c478bd9Sstevel@tonic-gate 249*7c478bd9Sstevel@tonic-gate /* 250*7c478bd9Sstevel@tonic-gate * Determine if a route should be aged. Age all routes that are: 251*7c478bd9Sstevel@tonic-gate * Not from -g, -m, nor static routes from the kernel 252*7c478bd9Sstevel@tonic-gate * not unbroken interface routes but not broken interfaces 253*7c478bd9Sstevel@tonic-gate * not learnt from RDISC or from /etc/gateways 254*7c478bd9Sstevel@tonic-gate * nor non-passive, remote interfaces that are not aliases 255*7c478bd9Sstevel@tonic-gate * (i.e. remote & metric=0) 256*7c478bd9Sstevel@tonic-gate */ 257*7c478bd9Sstevel@tonic-gate #define AGE_RT(rt_state, rts_origin, ifp) \ 258*7c478bd9Sstevel@tonic-gate ((!((rt_state) & (RS_MHOME | RS_STATIC | RS_NET_SYN)) && \ 259*7c478bd9Sstevel@tonic-gate (rts_origin != RO_RDISC) && \ 260*7c478bd9Sstevel@tonic-gate (rts_origin != RO_FILE)) && \ 261*7c478bd9Sstevel@tonic-gate (!((rt_state) & RS_IF) || \ 262*7c478bd9Sstevel@tonic-gate (ifp) == NULL || \ 263*7c478bd9Sstevel@tonic-gate (((ifp)->int_state & IS_REMOTE) && \ 264*7c478bd9Sstevel@tonic-gate !((ifp)->int_state & IS_PASSIVE)))) 265*7c478bd9Sstevel@tonic-gate 266*7c478bd9Sstevel@tonic-gate /* 267*7c478bd9Sstevel@tonic-gate * true if A is better than B 268*7c478bd9Sstevel@tonic-gate * Better if 269*7c478bd9Sstevel@tonic-gate * - A is not a poisoned route 270*7c478bd9Sstevel@tonic-gate * - and A is not stale 271*7c478bd9Sstevel@tonic-gate * - and either: 272*7c478bd9Sstevel@tonic-gate * - A has a shorter path 273*7c478bd9Sstevel@tonic-gate * - or the router is speaking for itself 274*7c478bd9Sstevel@tonic-gate * - or B has the same metric and isn't stale 275*7c478bd9Sstevel@tonic-gate * - or A is a host route advertised by a system for itself 276*7c478bd9Sstevel@tonic-gate */ 277*7c478bd9Sstevel@tonic-gate #define BETTER_LINK(rt, A, B) ((A)->rts_metric < HOPCNT_INFINITY && \ 278*7c478bd9Sstevel@tonic-gate now_stale <= (A)->rts_time && \ 279*7c478bd9Sstevel@tonic-gate ((A)->rts_metric < (B)->rts_metric || \ 280*7c478bd9Sstevel@tonic-gate ((A)->rts_gate == (A)->rts_router && \ 281*7c478bd9Sstevel@tonic-gate (B)->rts_gate != (B)->rts_router) || \ 282*7c478bd9Sstevel@tonic-gate ((A)->rts_metric == (B)->rts_metric && \ 283*7c478bd9Sstevel@tonic-gate now_stale > (B)->rts_time) || \ 284*7c478bd9Sstevel@tonic-gate (RT_ISHOST(rt) && \ 285*7c478bd9Sstevel@tonic-gate (rt)->rt_dst == (A)->rts_router && \ 286*7c478bd9Sstevel@tonic-gate (A)->rts_metric == (B)->rts_metric))) 287*7c478bd9Sstevel@tonic-gate 288*7c478bd9Sstevel@tonic-gate struct hlinkage { 289*7c478bd9Sstevel@tonic-gate void *hl_next; 290*7c478bd9Sstevel@tonic-gate void **hl_prev; 291*7c478bd9Sstevel@tonic-gate }; 292*7c478bd9Sstevel@tonic-gate 293*7c478bd9Sstevel@tonic-gate /* 294*7c478bd9Sstevel@tonic-gate * A "physical_interface" represents the actual hardware. It is also 295*7c478bd9Sstevel@tonic-gate * a container for a list of the interfaces that have the same ifIndex 296*7c478bd9Sstevel@tonic-gate * number. This will consist of zero or one "main" interface plus 297*7c478bd9Sstevel@tonic-gate * zero or more IS_ALIAS interfaces. 298*7c478bd9Sstevel@tonic-gate */ 299*7c478bd9Sstevel@tonic-gate struct physical_interface { 300*7c478bd9Sstevel@tonic-gate struct hlinkage phyi_link; 301*7c478bd9Sstevel@tonic-gate uint32_t phyi_index; 302*7c478bd9Sstevel@tonic-gate struct interface *phyi_interface; 303*7c478bd9Sstevel@tonic-gate struct phyi_data { 304*7c478bd9Sstevel@tonic-gate uint32_t ipackets; /* previous network stats */ 305*7c478bd9Sstevel@tonic-gate uint32_t ierrors; 306*7c478bd9Sstevel@tonic-gate uint32_t opackets; 307*7c478bd9Sstevel@tonic-gate uint32_t oerrors; 308*7c478bd9Sstevel@tonic-gate time_t ts; /* timestamp on network stats */ 309*7c478bd9Sstevel@tonic-gate } phyi_data; 310*7c478bd9Sstevel@tonic-gate char phyi_name[IF_NAME_LEN+1]; 311*7c478bd9Sstevel@tonic-gate }; 312*7c478bd9Sstevel@tonic-gate 313*7c478bd9Sstevel@tonic-gate /* 314*7c478bd9Sstevel@tonic-gate * An "interface" is similar to a kernel ifnet structure, except it also 315*7c478bd9Sstevel@tonic-gate * handles "logical" or "IS_REMOTE" interfaces (remote gateways). 316*7c478bd9Sstevel@tonic-gate */ 317*7c478bd9Sstevel@tonic-gate struct interface { 318*7c478bd9Sstevel@tonic-gate /* 319*7c478bd9Sstevel@tonic-gate * We keep interfaces in a variety of data structures to 320*7c478bd9Sstevel@tonic-gate * optimize for different types of searches. 321*7c478bd9Sstevel@tonic-gate */ 322*7c478bd9Sstevel@tonic-gate struct hlinkage int_link; 323*7c478bd9Sstevel@tonic-gate #define int_next int_link.hl_next 324*7c478bd9Sstevel@tonic-gate struct hlinkage int_ahash; /* by address */ 325*7c478bd9Sstevel@tonic-gate struct hlinkage int_bhash; /* by broadcast address */ 326*7c478bd9Sstevel@tonic-gate struct hlinkage int_nhash; /* by name */ 327*7c478bd9Sstevel@tonic-gate struct hlinkage int_ilist; /* ifIndex list */ 328*7c478bd9Sstevel@tonic-gate struct physical_interface *int_phys; /* backpointer */ 329*7c478bd9Sstevel@tonic-gate char int_name[IF_NAME_LEN+1]; 330*7c478bd9Sstevel@tonic-gate in_addr_t int_addr; /* address on this host (net order) */ 331*7c478bd9Sstevel@tonic-gate in_addr_t int_brdaddr; /* broadcast address (n) */ 332*7c478bd9Sstevel@tonic-gate in_addr_t int_dstaddr; /* other end of pt-to-pt link (n) */ 333*7c478bd9Sstevel@tonic-gate in_addr_t int_net; /* working network # (host order) */ 334*7c478bd9Sstevel@tonic-gate in_addr_t int_mask; /* working net mask (host order) */ 335*7c478bd9Sstevel@tonic-gate in_addr_t int_ripv1_mask; /* for inferring a mask (n) */ 336*7c478bd9Sstevel@tonic-gate in_addr_t int_std_addr; /* class A/B/C address (n) */ 337*7c478bd9Sstevel@tonic-gate in_addr_t int_std_net; /* class A/B/C network (h) */ 338*7c478bd9Sstevel@tonic-gate in_addr_t int_std_mask; /* class A/B/C netmask (h) */ 339*7c478bd9Sstevel@tonic-gate in_addr_t int_ripout_addr; /* RIP pkts sent to this addr */ 340*7c478bd9Sstevel@tonic-gate int int_if_flags; /* some bits copied from kernel */ 341*7c478bd9Sstevel@tonic-gate uint32_t int_state; 342*7c478bd9Sstevel@tonic-gate time_t int_act_time; /* last thought healthy (IS_REMOTE) */ 343*7c478bd9Sstevel@tonic-gate time_t int_query_time; /* last query (IS_REMOTE) */ 344*7c478bd9Sstevel@tonic-gate uint32_t int_transitions; /* times gone up-down */ 345*7c478bd9Sstevel@tonic-gate uint8_t int_metric; 346*7c478bd9Sstevel@tonic-gate uint8_t int_d_metric; /* for faked default route */ 347*7c478bd9Sstevel@tonic-gate #define MAX_AUTH_KEYS 5 348*7c478bd9Sstevel@tonic-gate struct auth { /* authentication info */ 349*7c478bd9Sstevel@tonic-gate time_t start, end; 350*7c478bd9Sstevel@tonic-gate uint16_t type; 351*7c478bd9Sstevel@tonic-gate /* 352*7c478bd9Sstevel@tonic-gate * Although the following key is just an array of bytes, 353*7c478bd9Sstevel@tonic-gate * in.routed is currently limited to ascii characters 354*7c478bd9Sstevel@tonic-gate * because of its configuration syntax and parsing. 355*7c478bd9Sstevel@tonic-gate */ 356*7c478bd9Sstevel@tonic-gate uint8_t key[RIP_AUTH_PW_LEN +1]; 357*7c478bd9Sstevel@tonic-gate uint8_t keyid; 358*7c478bd9Sstevel@tonic-gate uint8_t warnedflag; 359*7c478bd9Sstevel@tonic-gate } int_auth[MAX_AUTH_KEYS]; 360*7c478bd9Sstevel@tonic-gate /* router discovery parameters */ 361*7c478bd9Sstevel@tonic-gate int int_rdisc_pref; /* signed preference to advertise */ 362*7c478bd9Sstevel@tonic-gate uint32_t int_rdisc_int; /* MaxAdvertiseInterval */ 363*7c478bd9Sstevel@tonic-gate uint32_t int_rdisc_cnt; 364*7c478bd9Sstevel@tonic-gate struct timeval int_rdisc_timer; 365*7c478bd9Sstevel@tonic-gate }; 366*7c478bd9Sstevel@tonic-gate 367*7c478bd9Sstevel@tonic-gate /* bits in int_state */ 368*7c478bd9Sstevel@tonic-gate #define IS_ALIAS 0x00000001 /* interface alias */ 369*7c478bd9Sstevel@tonic-gate #define IS_SUBNET 0x00000002 /* interface on subnetted network */ 370*7c478bd9Sstevel@tonic-gate #define IS_REMOTE 0x00000004 /* interface is not on this machine */ 371*7c478bd9Sstevel@tonic-gate #define IS_PASSIVE 0x00000008 /* remote and does not do RIP */ 372*7c478bd9Sstevel@tonic-gate #define IS_EXTERNAL 0x00000010 /* handled by EGP or something */ 373*7c478bd9Sstevel@tonic-gate #define IS_CHECKED 0x00000020 /* still exists */ 374*7c478bd9Sstevel@tonic-gate #define IS_ALL_HOSTS 0x00000040 /* in INADDR_ALLHOSTS_GROUP */ 375*7c478bd9Sstevel@tonic-gate #define IS_ALL_ROUTERS 0x00000080 /* in INADDR_ALLROUTERS_GROUP */ 376*7c478bd9Sstevel@tonic-gate #define IS_DISTRUST 0x00000100 /* ignore untrusted routers */ 377*7c478bd9Sstevel@tonic-gate #define IS_REDIRECT_OK 0x00000200 /* accept ICMP redirects */ 378*7c478bd9Sstevel@tonic-gate #define IS_BROKE 0x00000400 /* seems to be broken */ 379*7c478bd9Sstevel@tonic-gate #define IS_SICK 0x00000800 /* seems to be broken */ 380*7c478bd9Sstevel@tonic-gate #define IS_DUP 0x00001000 /* duplicates another interface */ 381*7c478bd9Sstevel@tonic-gate #define IS_NEED_NET_SYN 0x00002000 /* need RS_NET_SYN route */ 382*7c478bd9Sstevel@tonic-gate #define IS_NO_AG 0x00004000 /* do not aggregate subnets */ 383*7c478bd9Sstevel@tonic-gate #define IS_NO_SUPER_AG 0x00008000 /* do not aggregate networks */ 384*7c478bd9Sstevel@tonic-gate #define IS_NO_RIPV1_IN 0x00010000 /* no RIPv1 input at all */ 385*7c478bd9Sstevel@tonic-gate #define IS_NO_RIPV2_IN 0x00020000 /* no RIPv2 input at all */ 386*7c478bd9Sstevel@tonic-gate #define IS_NO_RIP_IN (IS_NO_RIPV1_IN | IS_NO_RIPV2_IN) 387*7c478bd9Sstevel@tonic-gate #define IS_RIP_IN_OFF(s) (((s) & IS_NO_RIP_IN) == IS_NO_RIP_IN) 388*7c478bd9Sstevel@tonic-gate #define IS_NO_RIPV1_OUT 0x00040000 /* no RIPv1 output at all */ 389*7c478bd9Sstevel@tonic-gate #define IS_NO_RIPV2_OUT 0x00080000 /* no RIPv2 output at all */ 390*7c478bd9Sstevel@tonic-gate #define IS_NO_RIP_OUT (IS_NO_RIPV1_OUT | IS_NO_RIPV2_OUT) 391*7c478bd9Sstevel@tonic-gate #define IS_NO_RIP (IS_NO_RIP_OUT | IS_NO_RIP_IN) 392*7c478bd9Sstevel@tonic-gate #define IS_RIP_OUT_OFF(s) (((s) & IS_NO_RIP_OUT) == IS_NO_RIP_OUT) 393*7c478bd9Sstevel@tonic-gate #define IS_RIP_OFF(s) (((s) & IS_NO_RIP) == IS_NO_RIP) 394*7c478bd9Sstevel@tonic-gate #define IS_NO_RIP_MCAST 0x00100000 /* broadcast RIPv2 */ 395*7c478bd9Sstevel@tonic-gate #define IS_NO_ADV_IN 0x00200000 /* do not listen to advertisements */ 396*7c478bd9Sstevel@tonic-gate #define IS_NO_SOL_OUT 0x00400000 /* send no solicitations */ 397*7c478bd9Sstevel@tonic-gate #define IS_SOL_OUT 0x00800000 /* send solicitations */ 398*7c478bd9Sstevel@tonic-gate #define GROUP_IS_SOL_OUT (IS_SOL_OUT | IS_NO_SOL_OUT) 399*7c478bd9Sstevel@tonic-gate #define IS_NO_ADV_OUT 0x01000000 /* do not advertise rdisc */ 400*7c478bd9Sstevel@tonic-gate #define IS_ADV_OUT 0x02000000 /* advertise rdisc */ 401*7c478bd9Sstevel@tonic-gate #define GROUP_IS_ADV_OUT (IS_NO_ADV_OUT | IS_ADV_OUT) 402*7c478bd9Sstevel@tonic-gate #define IS_BCAST_RDISC 0x04000000 /* broadcast instead of multicast */ 403*7c478bd9Sstevel@tonic-gate #define IS_NO_RDISC (IS_NO_ADV_IN | IS_NO_SOL_OUT | IS_NO_ADV_OUT) 404*7c478bd9Sstevel@tonic-gate #define IS_PM_RDISC 0x08000000 /* poor-man's router discovery */ 405*7c478bd9Sstevel@tonic-gate #define IS_NO_HOST 0x10000000 /* disallow host routes */ 406*7c478bd9Sstevel@tonic-gate #define IS_SUPPRESS_RDISC 0x20000000 /* don't send rdisc advs */ 407*7c478bd9Sstevel@tonic-gate #define IS_FLUSH_RDISC 0x40000000 /* flush client rdisc caches */ 408*7c478bd9Sstevel@tonic-gate 409*7c478bd9Sstevel@tonic-gate /* 410*7c478bd9Sstevel@tonic-gate * passive interfaces are added through gwkludge 411*7c478bd9Sstevel@tonic-gate */ 412*7c478bd9Sstevel@tonic-gate #define IS_PASSIVE_IFP(ifp) \ 413*7c478bd9Sstevel@tonic-gate (((ifp)->int_state & (IS_REMOTE|IS_PASSIVE|IS_EXTERNAL|IS_ALIAS)) == \ 414*7c478bd9Sstevel@tonic-gate (IS_REMOTE|IS_PASSIVE)) 415*7c478bd9Sstevel@tonic-gate 416*7c478bd9Sstevel@tonic-gate /* 417*7c478bd9Sstevel@tonic-gate * Is an IP interface up? Because of the way IPMP uses deprecated 418*7c478bd9Sstevel@tonic-gate * interfaces, we need to check more than the IFF_UP and IFF_RUNNING 419*7c478bd9Sstevel@tonic-gate * interface flags here. Basically, we do not want to use IFF_DEPRECATED 420*7c478bd9Sstevel@tonic-gate * interfaces unless they are also IFF_STANDBY and not IFF_INACTIVE. 421*7c478bd9Sstevel@tonic-gate */ 422*7c478bd9Sstevel@tonic-gate #define IFF_GOOD (IFF_UP|IFF_RUNNING) 423*7c478bd9Sstevel@tonic-gate #define IS_IFF_UP(f) \ 424*7c478bd9Sstevel@tonic-gate ((((f) & (IFF_GOOD|IFF_DEPRECATED)) == IFF_GOOD) || \ 425*7c478bd9Sstevel@tonic-gate (((f) & (IFF_GOOD|IFF_INACTIVE|IFF_STANDBY)) == \ 426*7c478bd9Sstevel@tonic-gate (IFF_GOOD|IFF_STANDBY))) 427*7c478bd9Sstevel@tonic-gate 428*7c478bd9Sstevel@tonic-gate /* 429*7c478bd9Sstevel@tonic-gate * This defines interfaces that we should not use for advertising or 430*7c478bd9Sstevel@tonic-gate * soliciting routes by way of RIP and rdisc. Interfaces marked this 431*7c478bd9Sstevel@tonic-gate * way do not count for purposes of determining how many interfaces 432*7c478bd9Sstevel@tonic-gate * this router has. 433*7c478bd9Sstevel@tonic-gate */ 434*7c478bd9Sstevel@tonic-gate #define IS_IFF_QUIET(f) ((f) & (IFF_LOOPBACK|IFF_NORTEXCH|IFF_NOXMIT)) 435*7c478bd9Sstevel@tonic-gate 436*7c478bd9Sstevel@tonic-gate /* 437*7c478bd9Sstevel@tonic-gate * This defines interfaces that we can use for advertising routes by way of 438*7c478bd9Sstevel@tonic-gate * RIP and rdisc. 439*7c478bd9Sstevel@tonic-gate */ 440*7c478bd9Sstevel@tonic-gate #define IS_IFF_ROUTING(f) \ 441*7c478bd9Sstevel@tonic-gate (((f) & IFF_ROUTER) && !((f) & (IFF_NORTEXCH|IFF_NOXMIT))) 442*7c478bd9Sstevel@tonic-gate 443*7c478bd9Sstevel@tonic-gate /* Information for aggregating routes */ 444*7c478bd9Sstevel@tonic-gate #define NUM_AG_SLOTS 32 445*7c478bd9Sstevel@tonic-gate struct ag_info { 446*7c478bd9Sstevel@tonic-gate struct ag_info *ag_fine; /* slot with finer netmask */ 447*7c478bd9Sstevel@tonic-gate struct ag_info *ag_cors; /* more coarse netmask */ 448*7c478bd9Sstevel@tonic-gate in_addr_t ag_dst_h; /* destination in host byte order */ 449*7c478bd9Sstevel@tonic-gate in_addr_t ag_mask; 450*7c478bd9Sstevel@tonic-gate in_addr_t ag_gate; 451*7c478bd9Sstevel@tonic-gate struct interface *ag_ifp; 452*7c478bd9Sstevel@tonic-gate in_addr_t ag_nhop; 453*7c478bd9Sstevel@tonic-gate uint8_t ag_metric; /* metric to be advertised */ 454*7c478bd9Sstevel@tonic-gate uint8_t ag_pref; /* aggregate based on this */ 455*7c478bd9Sstevel@tonic-gate uint32_t ag_seqno; 456*7c478bd9Sstevel@tonic-gate uint16_t ag_tag; 457*7c478bd9Sstevel@tonic-gate uint16_t ag_state; 458*7c478bd9Sstevel@tonic-gate #define AGS_SUPPRESS 0x001 /* combine with coarser mask */ 459*7c478bd9Sstevel@tonic-gate #define AGS_AGGREGATE 0x002 /* synthesize combined routes */ 460*7c478bd9Sstevel@tonic-gate #define AGS_REDUN0 0x004 /* redundant, finer routes output */ 461*7c478bd9Sstevel@tonic-gate #define AGS_REDUN1 0x008 462*7c478bd9Sstevel@tonic-gate #define AG_IS_REDUN(state) (((state) & (AGS_REDUN0 | AGS_REDUN1)) \ 463*7c478bd9Sstevel@tonic-gate == (AGS_REDUN0 | AGS_REDUN1)) 464*7c478bd9Sstevel@tonic-gate #define AGS_GATEWAY 0x010 /* tell kernel RTF_GATEWAY */ 465*7c478bd9Sstevel@tonic-gate #define AGS_IF 0x020 /* for an interface */ 466*7c478bd9Sstevel@tonic-gate #define AGS_RIPV2 0x040 /* send only as RIPv2 */ 467*7c478bd9Sstevel@tonic-gate #define AGS_FINE_GATE 0x080 /* ignore differing ag_gate when */ 468*7c478bd9Sstevel@tonic-gate /* this has the finer netmask */ 469*7c478bd9Sstevel@tonic-gate #define AGS_CORS_GATE 0x100 /* ignore differing gate when this */ 470*7c478bd9Sstevel@tonic-gate /* has the coarser netmasks */ 471*7c478bd9Sstevel@tonic-gate #define AGS_SPLIT_HZ 0x200 /* suppress for split horizon */ 472*7c478bd9Sstevel@tonic-gate #define AGS_PASSIVE 0x400 /* passive "remote" interface route */ 473*7c478bd9Sstevel@tonic-gate #define AGS_FILE 0x800 /* from /etc/gateways */ 474*7c478bd9Sstevel@tonic-gate 475*7c478bd9Sstevel@tonic-gate /* some bits are set if they are set on either route */ 476*7c478bd9Sstevel@tonic-gate #define AGS_AGGREGATE_EITHER (AGS_RIPV2 | AGS_GATEWAY | \ 477*7c478bd9Sstevel@tonic-gate AGS_SUPPRESS | AGS_CORS_GATE) 478*7c478bd9Sstevel@tonic-gate }; 479*7c478bd9Sstevel@tonic-gate 480*7c478bd9Sstevel@tonic-gate struct khash { 481*7c478bd9Sstevel@tonic-gate struct khash *k_next; 482*7c478bd9Sstevel@tonic-gate in_addr_t k_dst; 483*7c478bd9Sstevel@tonic-gate in_addr_t k_mask; 484*7c478bd9Sstevel@tonic-gate in_addr_t k_gate; 485*7c478bd9Sstevel@tonic-gate struct interface *k_ifp; 486*7c478bd9Sstevel@tonic-gate short k_metric; 487*7c478bd9Sstevel@tonic-gate ushort_t k_state; /* KS_* */ 488*7c478bd9Sstevel@tonic-gate time_t k_keep; 489*7c478bd9Sstevel@tonic-gate time_t k_redirect_time; /* when redirected route 1st seen */ 490*7c478bd9Sstevel@tonic-gate }; 491*7c478bd9Sstevel@tonic-gate 492*7c478bd9Sstevel@tonic-gate /* bit flags for k_state; shared between table.c and trace.c */ 493*7c478bd9Sstevel@tonic-gate #define KS_NEW 0x0001 494*7c478bd9Sstevel@tonic-gate #define KS_DELETE 0x0002 /* need to delete the route */ 495*7c478bd9Sstevel@tonic-gate #define KS_ADD 0x0004 /* add to the kernel */ 496*7c478bd9Sstevel@tonic-gate #define KS_CHANGE 0x0008 /* tell kernel to change the route */ 497*7c478bd9Sstevel@tonic-gate #define KS_DEL_ADD 0x0010 /* delete & add to change the kernel */ 498*7c478bd9Sstevel@tonic-gate #define KS_STATIC 0x0020 /* Static flag in kernel */ 499*7c478bd9Sstevel@tonic-gate #define KS_GATEWAY 0x0040 /* G flag in kernel */ 500*7c478bd9Sstevel@tonic-gate #define KS_DYNAMIC 0x0080 /* result of redirect */ 501*7c478bd9Sstevel@tonic-gate #define KS_DELETED 0x0100 /* already deleted from kernel */ 502*7c478bd9Sstevel@tonic-gate #define KS_PRIVATE 0x0200 /* Private flag in kernel */ 503*7c478bd9Sstevel@tonic-gate #define KS_CHECK 0x0400 504*7c478bd9Sstevel@tonic-gate #define KS_IF 0x0800 /* interface route */ 505*7c478bd9Sstevel@tonic-gate #define KS_PASSIVE 0x1000 /* passive remote interface route */ 506*7c478bd9Sstevel@tonic-gate #define KS_DEPRE_IF 0x2000 /* IPMP deprecated interface route */ 507*7c478bd9Sstevel@tonic-gate #define KS_FILE 0x4000 /* from /etc/gateways */ 508*7c478bd9Sstevel@tonic-gate 509*7c478bd9Sstevel@tonic-gate /* default router structure */ 510*7c478bd9Sstevel@tonic-gate struct dr { /* accumulated advertisements */ 511*7c478bd9Sstevel@tonic-gate struct interface *dr_ifp; 512*7c478bd9Sstevel@tonic-gate in_addr_t dr_gate; /* gateway */ 513*7c478bd9Sstevel@tonic-gate time_t dr_ts; /* when received */ 514*7c478bd9Sstevel@tonic-gate time_t dr_life; /* lifetime in host byte order */ 515*7c478bd9Sstevel@tonic-gate uint32_t dr_recv_pref; /* received but biased preference */ 516*7c478bd9Sstevel@tonic-gate uint32_t dr_pref; /* preference adjusted by metric */ 517*7c478bd9Sstevel@tonic-gate uint32_t dr_flags; 518*7c478bd9Sstevel@tonic-gate #define DR_CHANGED 1 /* received new info for known dr */ 519*7c478bd9Sstevel@tonic-gate }; 520*7c478bd9Sstevel@tonic-gate 521*7c478bd9Sstevel@tonic-gate /* parameters for interfaces */ 522*7c478bd9Sstevel@tonic-gate struct parm { 523*7c478bd9Sstevel@tonic-gate struct parm *parm_next; 524*7c478bd9Sstevel@tonic-gate in_addr_t parm_net; 525*7c478bd9Sstevel@tonic-gate in_addr_t parm_mask; 526*7c478bd9Sstevel@tonic-gate in_addr_t parm_ripout_addr; 527*7c478bd9Sstevel@tonic-gate uint32_t parm_int_state; 528*7c478bd9Sstevel@tonic-gate int32_t parm_rdisc_pref; /* signed IRDP preference */ 529*7c478bd9Sstevel@tonic-gate uint32_t parm_rdisc_int; /* IRDP advertising interval */ 530*7c478bd9Sstevel@tonic-gate struct auth parm_auth[MAX_AUTH_KEYS]; 531*7c478bd9Sstevel@tonic-gate char parm_name[IF_NAME_LEN+1]; 532*7c478bd9Sstevel@tonic-gate uint8_t parm_d_metric; 533*7c478bd9Sstevel@tonic-gate }; 534*7c478bd9Sstevel@tonic-gate 535*7c478bd9Sstevel@tonic-gate /* authority for internal networks */ 536*7c478bd9Sstevel@tonic-gate extern struct intnet { 537*7c478bd9Sstevel@tonic-gate struct intnet *intnet_next; 538*7c478bd9Sstevel@tonic-gate in_addr_t intnet_addr; /* network byte order */ 539*7c478bd9Sstevel@tonic-gate in_addr_t intnet_mask; 540*7c478bd9Sstevel@tonic-gate int8_t intnet_metric; 541*7c478bd9Sstevel@tonic-gate } *intnets; 542*7c478bd9Sstevel@tonic-gate 543*7c478bd9Sstevel@tonic-gate /* 544*7c478bd9Sstevel@tonic-gate * Defined RIPv1 netmasks. These come from ripv1_mask entries in 545*7c478bd9Sstevel@tonic-gate * /etc/gateways of the form: 546*7c478bd9Sstevel@tonic-gate * 547*7c478bd9Sstevel@tonic-gate * ripv1_mask=<net>/<match>,<mask> 548*7c478bd9Sstevel@tonic-gate * 549*7c478bd9Sstevel@tonic-gate * The intended use of these structures is to give RIPv1 destinations which 550*7c478bd9Sstevel@tonic-gate * are in <net>/<match> a netmask of <mask>, where <mask> > <match>. 551*7c478bd9Sstevel@tonic-gate */ 552*7c478bd9Sstevel@tonic-gate extern struct r1net { 553*7c478bd9Sstevel@tonic-gate struct r1net *r1net_next; 554*7c478bd9Sstevel@tonic-gate in_addr_t r1net_net; /* host order */ 555*7c478bd9Sstevel@tonic-gate in_addr_t r1net_match; 556*7c478bd9Sstevel@tonic-gate in_addr_t r1net_mask; 557*7c478bd9Sstevel@tonic-gate } *r1nets; 558*7c478bd9Sstevel@tonic-gate 559*7c478bd9Sstevel@tonic-gate /* trusted routers */ 560*7c478bd9Sstevel@tonic-gate extern struct tgate { 561*7c478bd9Sstevel@tonic-gate struct tgate *tgate_next; 562*7c478bd9Sstevel@tonic-gate in_addr_t tgate_addr; 563*7c478bd9Sstevel@tonic-gate #define MAX_TGATE_NETS 32 564*7c478bd9Sstevel@tonic-gate struct tgate_net { 565*7c478bd9Sstevel@tonic-gate in_addr_t net; /* host order */ 566*7c478bd9Sstevel@tonic-gate in_addr_t mask; 567*7c478bd9Sstevel@tonic-gate } tgate_nets[MAX_TGATE_NETS]; 568*7c478bd9Sstevel@tonic-gate } *tgates; 569*7c478bd9Sstevel@tonic-gate 570*7c478bd9Sstevel@tonic-gate enum output_type {OUT_QUERY, OUT_UNICAST, OUT_BROADCAST, OUT_MULTICAST, 571*7c478bd9Sstevel@tonic-gate NO_OUT_MULTICAST, NO_OUT_RIPV2}; 572*7c478bd9Sstevel@tonic-gate 573*7c478bd9Sstevel@tonic-gate /* common output buffers */ 574*7c478bd9Sstevel@tonic-gate extern struct ws_buf { 575*7c478bd9Sstevel@tonic-gate struct rip *buf; 576*7c478bd9Sstevel@tonic-gate struct netinfo *n; 577*7c478bd9Sstevel@tonic-gate struct netinfo *base; 578*7c478bd9Sstevel@tonic-gate struct netinfo *lim; 579*7c478bd9Sstevel@tonic-gate enum output_type type; 580*7c478bd9Sstevel@tonic-gate } v12buf; 581*7c478bd9Sstevel@tonic-gate 582*7c478bd9Sstevel@tonic-gate extern int stopint; /* !=0 to stop in.routed */ 583*7c478bd9Sstevel@tonic-gate 584*7c478bd9Sstevel@tonic-gate extern int rip_sock; /* RIP socket */ 585*7c478bd9Sstevel@tonic-gate extern struct interface *rip_sock_interface; /* current output interface */ 586*7c478bd9Sstevel@tonic-gate extern int rt_sock; /* routing socket */ 587*7c478bd9Sstevel@tonic-gate extern int rdisc_sock; /* router-discovery raw socket */ 588*7c478bd9Sstevel@tonic-gate 589*7c478bd9Sstevel@tonic-gate extern boolean_t rip_enabled; /* is rip on? */ 590*7c478bd9Sstevel@tonic-gate extern boolean_t supplier; /* process should supply updates */ 591*7c478bd9Sstevel@tonic-gate extern boolean_t supplier_set; /* -s or -q requested */ 592*7c478bd9Sstevel@tonic-gate extern boolean_t save_space; /* -S option 1=treat all RIP speakers */ 593*7c478bd9Sstevel@tonic-gate extern boolean_t ridhosts; /* 1=reduce host routes */ 594*7c478bd9Sstevel@tonic-gate extern boolean_t mhome; /* 1=want multi-homed host route */ 595*7c478bd9Sstevel@tonic-gate extern boolean_t advertise_mhome; /* 1=must continue advertising it */ 596*7c478bd9Sstevel@tonic-gate extern boolean_t auth_ok; /* 1=ignore auth if we do not care */ 597*7c478bd9Sstevel@tonic-gate extern boolean_t no_install; /* 1=don't install in kernel */ 598*7c478bd9Sstevel@tonic-gate 599*7c478bd9Sstevel@tonic-gate extern struct timeval clk; /* system clock's idea of time */ 600*7c478bd9Sstevel@tonic-gate extern struct timeval epoch; /* system clock when started */ 601*7c478bd9Sstevel@tonic-gate extern struct timeval now; /* current idea of time */ 602*7c478bd9Sstevel@tonic-gate extern time_t now_stale; 603*7c478bd9Sstevel@tonic-gate extern time_t now_expire; 604*7c478bd9Sstevel@tonic-gate extern time_t now_garbage; 605*7c478bd9Sstevel@tonic-gate 606*7c478bd9Sstevel@tonic-gate extern struct timeval age_timer; /* next check of old routes */ 607*7c478bd9Sstevel@tonic-gate extern struct timeval no_flash; /* inhibit flash update until then */ 608*7c478bd9Sstevel@tonic-gate extern struct timeval rdisc_timer; /* next advert. or solicitation */ 609*7c478bd9Sstevel@tonic-gate extern boolean_t rdisc_ok; /* using solicited route */ 610*7c478bd9Sstevel@tonic-gate 611*7c478bd9Sstevel@tonic-gate extern struct timeval ifscan_timer; /* time to check interfaces */ 612*7c478bd9Sstevel@tonic-gate 613*7c478bd9Sstevel@tonic-gate extern in_addr_t loopaddr; /* our address on loopback */ 614*7c478bd9Sstevel@tonic-gate extern uint_t tot_interfaces; /* # of remote and local interfaces */ 615*7c478bd9Sstevel@tonic-gate extern uint_t rip_interfaces; /* # of interfaces doing RIP */ 616*7c478bd9Sstevel@tonic-gate extern uint_t ripout_interfaces; /* # of interfaces advertising RIP */ 617*7c478bd9Sstevel@tonic-gate extern uint_t fwd_interfaces; /* # of interfaces ip_forwarding=1 */ 618*7c478bd9Sstevel@tonic-gate extern struct interface *ifnet; /* all interfaces */ 619*7c478bd9Sstevel@tonic-gate extern size_t hash_table_sizes[]; /* list of primes for hash tables */ 620*7c478bd9Sstevel@tonic-gate extern boolean_t have_ripv1_out; /* have a RIPv1 interface */ 621*7c478bd9Sstevel@tonic-gate extern boolean_t need_flash; /* flash update needed */ 622*7c478bd9Sstevel@tonic-gate extern struct timeval need_kern; /* need to update kernel table */ 623*7c478bd9Sstevel@tonic-gate extern uint32_t update_seqno; /* a route has changed */ 624*7c478bd9Sstevel@tonic-gate extern struct interface dummy_ifp; /* wildcard interface */ 625*7c478bd9Sstevel@tonic-gate 626*7c478bd9Sstevel@tonic-gate extern int tracelevel, new_tracelevel; 627*7c478bd9Sstevel@tonic-gate #define MAX_TRACELEVEL 5 628*7c478bd9Sstevel@tonic-gate #define TRACERTS (tracelevel >= 5) /* log routing socket contents */ 629*7c478bd9Sstevel@tonic-gate #define TRACEKERNEL (tracelevel >= 4) /* log kernel changes */ 630*7c478bd9Sstevel@tonic-gate #define TRACECONTENTS (tracelevel >= 3) /* display packet contents */ 631*7c478bd9Sstevel@tonic-gate #define TRACEPACKETS (tracelevel >= 2) /* note packets */ 632*7c478bd9Sstevel@tonic-gate #define TRACEACTIONS (tracelevel != 0) 633*7c478bd9Sstevel@tonic-gate extern FILE *ftrace; /* output trace file */ 634*7c478bd9Sstevel@tonic-gate extern char inittracename[MAXPATHLEN+1]; 635*7c478bd9Sstevel@tonic-gate 636*7c478bd9Sstevel@tonic-gate extern struct radix_node_head *rhead; 637*7c478bd9Sstevel@tonic-gate 638*7c478bd9Sstevel@tonic-gate extern void fix_sock(int, const char *); 639*7c478bd9Sstevel@tonic-gate extern void fix_select(void); 640*7c478bd9Sstevel@tonic-gate extern void rip_off(void); 641*7c478bd9Sstevel@tonic-gate extern void rip_on(struct interface *); 642*7c478bd9Sstevel@tonic-gate 643*7c478bd9Sstevel@tonic-gate extern void bufinit(void); 644*7c478bd9Sstevel@tonic-gate extern int output(enum output_type, struct sockaddr_in *, 645*7c478bd9Sstevel@tonic-gate struct interface *, struct rip *, int); 646*7c478bd9Sstevel@tonic-gate extern void clr_ws_buf(struct ws_buf *, struct auth *); 647*7c478bd9Sstevel@tonic-gate extern void rip_query(void); 648*7c478bd9Sstevel@tonic-gate extern void rip_bcast(int); 649*7c478bd9Sstevel@tonic-gate extern void supply(struct sockaddr_in *, struct interface *, 650*7c478bd9Sstevel@tonic-gate enum output_type, int, int, boolean_t); 651*7c478bd9Sstevel@tonic-gate 652*7c478bd9Sstevel@tonic-gate extern void msglog(const char *, ...); 653*7c478bd9Sstevel@tonic-gate extern void writelog(int, const char *, ...); 654*7c478bd9Sstevel@tonic-gate struct msg_limit { 655*7c478bd9Sstevel@tonic-gate time_t reuse; 656*7c478bd9Sstevel@tonic-gate struct msg_sub { 657*7c478bd9Sstevel@tonic-gate in_addr_t addr; 658*7c478bd9Sstevel@tonic-gate time_t until; 659*7c478bd9Sstevel@tonic-gate #define MSG_SUBJECT_N 8 660*7c478bd9Sstevel@tonic-gate } subs[MSG_SUBJECT_N]; 661*7c478bd9Sstevel@tonic-gate }; 662*7c478bd9Sstevel@tonic-gate extern void msglim(struct msg_limit *, in_addr_t, const char *, ...); 663*7c478bd9Sstevel@tonic-gate #define LOGERR(msg) msglog(msg ": %s", rip_strerror(errno)) 664*7c478bd9Sstevel@tonic-gate extern void logbad(boolean_t, const char *, ...); 665*7c478bd9Sstevel@tonic-gate #define BADERR(dump, msg) logbad(dump, msg ": %s", rip_strerror(errno)) 666*7c478bd9Sstevel@tonic-gate #ifdef DEBUG 667*7c478bd9Sstevel@tonic-gate #define DBGERR(dump, msg) BADERR(dump, msg) 668*7c478bd9Sstevel@tonic-gate #else 669*7c478bd9Sstevel@tonic-gate #define DBGERR(dump, msg) LOGERR(msg) 670*7c478bd9Sstevel@tonic-gate #endif 671*7c478bd9Sstevel@tonic-gate extern char *naddr_ntoa(in_addr_t); 672*7c478bd9Sstevel@tonic-gate extern const char *saddr_ntoa(struct sockaddr_storage *); 673*7c478bd9Sstevel@tonic-gate extern const char *rip_strerror(int errnum); 674*7c478bd9Sstevel@tonic-gate extern char *if_bit_string(uint_t, boolean_t); 675*7c478bd9Sstevel@tonic-gate 676*7c478bd9Sstevel@tonic-gate extern void *rtmalloc(size_t, const char *); 677*7c478bd9Sstevel@tonic-gate extern void timevaladd(struct timeval *, struct timeval *); 678*7c478bd9Sstevel@tonic-gate extern void intvl_random(struct timeval *, ulong_t, ulong_t); 679*7c478bd9Sstevel@tonic-gate extern boolean_t getnet(const char *, in_addr_t *, in_addr_t *); 680*7c478bd9Sstevel@tonic-gate extern int gethost(char *, in_addr_t *); 681*7c478bd9Sstevel@tonic-gate extern void gwkludge(void); 682*7c478bd9Sstevel@tonic-gate extern const char *parse_parms(char *, boolean_t); 683*7c478bd9Sstevel@tonic-gate extern const char *insert_parm(struct parm *); 684*7c478bd9Sstevel@tonic-gate extern void get_parms(struct interface *); 685*7c478bd9Sstevel@tonic-gate 686*7c478bd9Sstevel@tonic-gate extern void lastlog(void); 687*7c478bd9Sstevel@tonic-gate extern void trace_close(int); 688*7c478bd9Sstevel@tonic-gate extern void set_tracefile(const char *, const char *, int); 689*7c478bd9Sstevel@tonic-gate extern void tracelevel_msg(const char *, int); 690*7c478bd9Sstevel@tonic-gate extern void trace_off(const char *, ...); 691*7c478bd9Sstevel@tonic-gate extern void set_tracelevel(void); 692*7c478bd9Sstevel@tonic-gate extern void trace_flush(void); 693*7c478bd9Sstevel@tonic-gate extern void trace_misc(const char *, ...); 694*7c478bd9Sstevel@tonic-gate extern void trace_act(const char *, ...); 695*7c478bd9Sstevel@tonic-gate extern void trace_pkt(const char *, ...); 696*7c478bd9Sstevel@tonic-gate extern void trace_add_del(const char *, struct rt_entry *); 697*7c478bd9Sstevel@tonic-gate extern void trace_change(struct rt_entry *, uint16_t, struct rt_spare *, 698*7c478bd9Sstevel@tonic-gate const char *); 699*7c478bd9Sstevel@tonic-gate extern void trace_if(const char *, struct interface *); 700*7c478bd9Sstevel@tonic-gate extern void trace_khash(const struct khash *); 701*7c478bd9Sstevel@tonic-gate extern void trace_dr(const struct dr *); 702*7c478bd9Sstevel@tonic-gate extern void trace_upslot(struct rt_entry *, struct rt_spare *, 703*7c478bd9Sstevel@tonic-gate struct rt_spare *); 704*7c478bd9Sstevel@tonic-gate extern void trace_rip(const char *, const char *, struct sockaddr_in *, 705*7c478bd9Sstevel@tonic-gate struct interface *, struct rip *, int); 706*7c478bd9Sstevel@tonic-gate extern char *addrname(in_addr_t, in_addr_t, int); 707*7c478bd9Sstevel@tonic-gate extern char *rtname(in_addr_t, in_addr_t, in_addr_t); 708*7c478bd9Sstevel@tonic-gate 709*7c478bd9Sstevel@tonic-gate extern void rdisc_age(in_addr_t); 710*7c478bd9Sstevel@tonic-gate extern void set_rdisc_mg(struct interface *, int); 711*7c478bd9Sstevel@tonic-gate extern void set_supplier(void); 712*7c478bd9Sstevel@tonic-gate extern void if_bad_rdisc(struct interface *); 713*7c478bd9Sstevel@tonic-gate extern void if_rewire_rdisc(struct interface *, struct interface *); 714*7c478bd9Sstevel@tonic-gate extern void if_ok_rdisc(struct interface *); 715*7c478bd9Sstevel@tonic-gate extern int read_rip(void); 716*7c478bd9Sstevel@tonic-gate extern void input_route(in_addr_t, in_addr_t, struct rt_spare *, 717*7c478bd9Sstevel@tonic-gate struct netinfo *, uint16_t); 718*7c478bd9Sstevel@tonic-gate extern void read_rt(void); 719*7c478bd9Sstevel@tonic-gate extern void read_d(void); 720*7c478bd9Sstevel@tonic-gate extern void rdisc_adv(boolean_t); 721*7c478bd9Sstevel@tonic-gate extern void rdisc_sol(void); 722*7c478bd9Sstevel@tonic-gate extern struct interface *receiving_interface(struct msghdr *, boolean_t); 723*7c478bd9Sstevel@tonic-gate extern void *find_ancillary(struct msghdr *, int); 724*7c478bd9Sstevel@tonic-gate extern boolean_t should_supply(struct interface *); 725*7c478bd9Sstevel@tonic-gate extern void rdisc_dump(void); 726*7c478bd9Sstevel@tonic-gate extern void rdisc_suppress(struct interface *); 727*7c478bd9Sstevel@tonic-gate extern void rdisc_restore(struct interface *); 728*7c478bd9Sstevel@tonic-gate 729*7c478bd9Sstevel@tonic-gate extern void age_peer_info(void); 730*7c478bd9Sstevel@tonic-gate 731*7c478bd9Sstevel@tonic-gate extern void sigtrace_more(int); 732*7c478bd9Sstevel@tonic-gate extern void sigtrace_less(int); 733*7c478bd9Sstevel@tonic-gate extern void sigtrace_dump(int); 734*7c478bd9Sstevel@tonic-gate 735*7c478bd9Sstevel@tonic-gate extern void sync_kern(void); 736*7c478bd9Sstevel@tonic-gate extern void age(in_addr_t); 737*7c478bd9Sstevel@tonic-gate extern void kern_dump(void); 738*7c478bd9Sstevel@tonic-gate extern void kern_flush_ifp(struct interface *); 739*7c478bd9Sstevel@tonic-gate extern void kern_rewire_ifp(struct interface *, struct interface *); 740*7c478bd9Sstevel@tonic-gate 741*7c478bd9Sstevel@tonic-gate extern void ag_flush(in_addr_t, in_addr_t, void (*)(struct ag_info *)); 742*7c478bd9Sstevel@tonic-gate extern void ag_check(in_addr_t, in_addr_t, in_addr_t, struct interface *, 743*7c478bd9Sstevel@tonic-gate in_addr_t, uint8_t, uint8_t, uint32_t, uint16_t, uint16_t, 744*7c478bd9Sstevel@tonic-gate void (*)(struct ag_info *)); 745*7c478bd9Sstevel@tonic-gate extern void del_static(in_addr_t, in_addr_t, in_addr_t, 746*7c478bd9Sstevel@tonic-gate struct interface *, int); 747*7c478bd9Sstevel@tonic-gate extern void del_redirects(in_addr_t, time_t); 748*7c478bd9Sstevel@tonic-gate extern struct rt_entry *rtget(in_addr_t, in_addr_t); 749*7c478bd9Sstevel@tonic-gate extern struct rt_entry *rtfind(in_addr_t); 750*7c478bd9Sstevel@tonic-gate extern void rtinit(void); 751*7c478bd9Sstevel@tonic-gate extern void rtadd(in_addr_t, in_addr_t, uint16_t, struct rt_spare *); 752*7c478bd9Sstevel@tonic-gate extern void rtchange(struct rt_entry *, uint16_t, struct rt_spare *, 753*7c478bd9Sstevel@tonic-gate char *); 754*7c478bd9Sstevel@tonic-gate extern void rtdelete(struct rt_entry *); 755*7c478bd9Sstevel@tonic-gate extern void rts_delete(struct rt_entry *, struct rt_spare *); 756*7c478bd9Sstevel@tonic-gate extern void rtbad_sub(struct rt_entry *, struct interface *); 757*7c478bd9Sstevel@tonic-gate extern void rtswitch(struct rt_entry *, struct rt_spare *); 758*7c478bd9Sstevel@tonic-gate 759*7c478bd9Sstevel@tonic-gate #define S_ADDR(x) (((struct sockaddr_in *)(x))->sin_addr.s_addr) 760*7c478bd9Sstevel@tonic-gate #define INFO_DST(I) ((I)->rti_info[RTAX_DST]) 761*7c478bd9Sstevel@tonic-gate #define INFO_GATE(I) ((I)->rti_info[RTAX_GATEWAY]) 762*7c478bd9Sstevel@tonic-gate #define INFO_MASK(I) ((I)->rti_info[RTAX_NETMASK]) 763*7c478bd9Sstevel@tonic-gate #define INFO_AUTHOR(I) ((I)->rti_info[RTAX_AUTHOR]) 764*7c478bd9Sstevel@tonic-gate 765*7c478bd9Sstevel@tonic-gate struct rewire_data { 766*7c478bd9Sstevel@tonic-gate struct interface *if_old; 767*7c478bd9Sstevel@tonic-gate struct interface *if_new; 768*7c478bd9Sstevel@tonic-gate int metric_delta; 769*7c478bd9Sstevel@tonic-gate }; 770*7c478bd9Sstevel@tonic-gate 771*7c478bd9Sstevel@tonic-gate extern char *qstring(const uchar_t *, int); 772*7c478bd9Sstevel@tonic-gate extern in_addr_t std_mask(in_addr_t); 773*7c478bd9Sstevel@tonic-gate extern int parse_quote(char **, const char *, char *, char *, int); 774*7c478bd9Sstevel@tonic-gate extern in_addr_t ripv1_mask_net(in_addr_t, const struct interface *); 775*7c478bd9Sstevel@tonic-gate extern in_addr_t ripv1_mask_host(in_addr_t, const struct interface *); 776*7c478bd9Sstevel@tonic-gate #define on_net(a, net, mask) (((ntohl(a) ^ (net)) & (mask)) == 0) 777*7c478bd9Sstevel@tonic-gate extern boolean_t check_dst(in_addr_t); 778*7c478bd9Sstevel@tonic-gate extern boolean_t remote_address_ok(struct interface *, in_addr_t); 779*7c478bd9Sstevel@tonic-gate extern struct interface *check_dup(const char *, in_addr_t, in_addr_t, 780*7c478bd9Sstevel@tonic-gate in_addr_t, int, boolean_t); 781*7c478bd9Sstevel@tonic-gate extern boolean_t check_remote(struct interface *); 782*7c478bd9Sstevel@tonic-gate extern void iftbl_alloc(void); 783*7c478bd9Sstevel@tonic-gate extern void ifscan(void); 784*7c478bd9Sstevel@tonic-gate extern int walk_bad(struct radix_node *, void *); 785*7c478bd9Sstevel@tonic-gate extern int walk_rewire(struct radix_node *, void *); 786*7c478bd9Sstevel@tonic-gate extern void if_ok(struct interface *, const char *, boolean_t); 787*7c478bd9Sstevel@tonic-gate extern void if_sick(struct interface *, boolean_t); 788*7c478bd9Sstevel@tonic-gate extern void if_link(struct interface *, uint32_t); 789*7c478bd9Sstevel@tonic-gate extern struct interface *ifwithaddr(in_addr_t, boolean_t, boolean_t); 790*7c478bd9Sstevel@tonic-gate extern struct interface *ifwithindex(ulong_t, boolean_t); 791*7c478bd9Sstevel@tonic-gate extern struct interface *ifwithname(const char *); 792*7c478bd9Sstevel@tonic-gate extern struct interface *findremoteif(in_addr_t); 793*7c478bd9Sstevel@tonic-gate extern struct interface *findifaddr(in_addr_t); 794*7c478bd9Sstevel@tonic-gate extern struct interface *iflookup(in_addr_t); 795*7c478bd9Sstevel@tonic-gate extern struct auth *find_auth(struct interface *); 796*7c478bd9Sstevel@tonic-gate extern void end_md5_auth(struct ws_buf *, struct auth *); 797*7c478bd9Sstevel@tonic-gate extern void rip_mcast_on(struct interface *); 798*7c478bd9Sstevel@tonic-gate extern void rip_mcast_off(struct interface *); 799*7c478bd9Sstevel@tonic-gate extern void trace_dump(); 800*7c478bd9Sstevel@tonic-gate 801*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 802*7c478bd9Sstevel@tonic-gate } 803*7c478bd9Sstevel@tonic-gate #endif 804*7c478bd9Sstevel@tonic-gate 805*7c478bd9Sstevel@tonic-gate #endif /* _DEFS_H */ 806