10Sstevel@tonic-gate /* 2*8485SPeter.Memishian@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 30Sstevel@tonic-gate * Use is subject to license terms. 40Sstevel@tonic-gate * 50Sstevel@tonic-gate * Copyright (c) 1983, 1988, 1993 60Sstevel@tonic-gate * The Regents of the University of California. All rights reserved. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * Redistribution and use in source and binary forms, with or without 90Sstevel@tonic-gate * modification, are permitted provided that the following conditions 100Sstevel@tonic-gate * are met: 110Sstevel@tonic-gate * 1. Redistributions of source code must retain the above copyright 120Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer. 130Sstevel@tonic-gate * 2. Redistributions in binary form must reproduce the above copyright 140Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer in the 150Sstevel@tonic-gate * documentation and/or other materials provided with the distribution. 160Sstevel@tonic-gate * 3. All advertising materials mentioning features or use of this software 170Sstevel@tonic-gate * must display the following acknowledgment: 180Sstevel@tonic-gate * This product includes software developed by the University of 190Sstevel@tonic-gate * California, Berkeley and its contributors. 200Sstevel@tonic-gate * 4. Neither the name of the University nor the names of its contributors 210Sstevel@tonic-gate * may be used to endorse or promote products derived from this software 220Sstevel@tonic-gate * without specific prior written permission. 230Sstevel@tonic-gate * 240Sstevel@tonic-gate * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 250Sstevel@tonic-gate * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 260Sstevel@tonic-gate * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 270Sstevel@tonic-gate * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 280Sstevel@tonic-gate * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 290Sstevel@tonic-gate * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 300Sstevel@tonic-gate * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 310Sstevel@tonic-gate * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 320Sstevel@tonic-gate * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 330Sstevel@tonic-gate * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 340Sstevel@tonic-gate * SUCH DAMAGE. 350Sstevel@tonic-gate * 360Sstevel@tonic-gate * @(#)defs.h 8.1 (Berkeley) 6/5/93 370Sstevel@tonic-gate * 380Sstevel@tonic-gate * $FreeBSD: src/sbin/routed/defs.h,v 1.14 2000/08/11 08:24:38 sheldonh Exp $ 390Sstevel@tonic-gate */ 400Sstevel@tonic-gate 410Sstevel@tonic-gate #ifndef _DEFS_H 420Sstevel@tonic-gate #define _DEFS_H 430Sstevel@tonic-gate 440Sstevel@tonic-gate /* 450Sstevel@tonic-gate * Definitions for RIPv2 routing process. 460Sstevel@tonic-gate * 470Sstevel@tonic-gate * This code is based on the 4.4BSD `routed` daemon, with extensions to 480Sstevel@tonic-gate * support: 490Sstevel@tonic-gate * RIPv2, including variable length subnet masks. 500Sstevel@tonic-gate * Router Discovery 510Sstevel@tonic-gate * aggregate routes in the kernel tables. 520Sstevel@tonic-gate * aggregate advertised routes. 530Sstevel@tonic-gate * maintain spare routes for faster selection of another gateway 540Sstevel@tonic-gate * when the current gateway dies. 550Sstevel@tonic-gate * timers on routes with second granularity so that selection 560Sstevel@tonic-gate * of a new route does not wait 30-60 seconds. 570Sstevel@tonic-gate * tolerance of static routes. 580Sstevel@tonic-gate * tell the kernel hop counts. 590Sstevel@tonic-gate * use of per-interface ip_forwarding state. 600Sstevel@tonic-gate * 610Sstevel@tonic-gate * The vestigial support for other protocols has been removed. There 620Sstevel@tonic-gate * is no likelihood that IETF RIPv1 or RIPv2 will ever be used with 630Sstevel@tonic-gate * other protocols. The result is far smaller, faster, cleaner, and 640Sstevel@tonic-gate * perhaps understandable. 650Sstevel@tonic-gate * 660Sstevel@tonic-gate * The accumulation of special flags and kludges added over the many 670Sstevel@tonic-gate * years have been simplified and integrated. 680Sstevel@tonic-gate */ 690Sstevel@tonic-gate 700Sstevel@tonic-gate #ifdef __cplusplus 710Sstevel@tonic-gate extern "C" { 720Sstevel@tonic-gate #endif 730Sstevel@tonic-gate 740Sstevel@tonic-gate #include <stdio.h> 750Sstevel@tonic-gate #include <netdb.h> 760Sstevel@tonic-gate #include <stdlib.h> 770Sstevel@tonic-gate #include <unistd.h> 780Sstevel@tonic-gate #include <errno.h> 790Sstevel@tonic-gate #include <string.h> 800Sstevel@tonic-gate #include <stdarg.h> 810Sstevel@tonic-gate #include <syslog.h> 820Sstevel@tonic-gate #include <time.h> 830Sstevel@tonic-gate #include <md5.h> 840Sstevel@tonic-gate #include <libintl.h> 850Sstevel@tonic-gate #include <locale.h> 860Sstevel@tonic-gate #include "radix.h" 870Sstevel@tonic-gate 880Sstevel@tonic-gate #include <sys/time.h> 890Sstevel@tonic-gate #include <sys/types.h> 900Sstevel@tonic-gate #include <sys/param.h> 910Sstevel@tonic-gate #include <sys/ioctl.h> 920Sstevel@tonic-gate #include <sys/socket.h> 930Sstevel@tonic-gate #include <sys/sysmacros.h> 940Sstevel@tonic-gate 950Sstevel@tonic-gate #include <net/if.h> 960Sstevel@tonic-gate #include <net/route.h> 970Sstevel@tonic-gate #include <net/if_dl.h> 980Sstevel@tonic-gate #include <netinet/in.h> 990Sstevel@tonic-gate #include <arpa/inet.h> 1000Sstevel@tonic-gate #define RIPVERSION RIPv2 1010Sstevel@tonic-gate #include <protocols/routed.h> 1020Sstevel@tonic-gate 1030Sstevel@tonic-gate 1040Sstevel@tonic-gate #define DAY (24*60*60) 1050Sstevel@tonic-gate #define NEVER DAY /* a long time */ 1060Sstevel@tonic-gate #define EPOCH NEVER /* bias time by this to avoid <0 */ 1070Sstevel@tonic-gate 1080Sstevel@tonic-gate /* 1090Sstevel@tonic-gate * Scan the kernel regularly to see if any interfaces have appeared or been 1100Sstevel@tonic-gate * turned off. 1110Sstevel@tonic-gate */ 1120Sstevel@tonic-gate #define CHECK_BAD_INTERVAL 5 /* when an interface is known bad */ 1130Sstevel@tonic-gate #define CHECK_ACT_INTERVAL 30 /* when advertising */ 1140Sstevel@tonic-gate #define CHECK_QUIET_INTERVAL 300 /* when not */ 1150Sstevel@tonic-gate 1160Sstevel@tonic-gate /* 1170Sstevel@tonic-gate * Limit the seconds in the timeval structure "s" to "l" seconds, but only 1180Sstevel@tonic-gate * if l is less than the current seconds in s. This is used to shorten 1190Sstevel@tonic-gate * certain timers to ensure that scheduled events occur sooner than 1200Sstevel@tonic-gate * originally scheduled. 1210Sstevel@tonic-gate */ 1220Sstevel@tonic-gate #define LIM_SEC(s, l) ((s).tv_sec = MIN((s).tv_sec, (l))) 1230Sstevel@tonic-gate 1240Sstevel@tonic-gate /* 1250Sstevel@tonic-gate * Metric used for fake default routes. It ought to be 15, but when 1260Sstevel@tonic-gate * processing advertised routes, previous versions of `routed` added 1270Sstevel@tonic-gate * to the received metric and discarded the route if the total was 16 1280Sstevel@tonic-gate * or larger. 1290Sstevel@tonic-gate */ 1300Sstevel@tonic-gate #define FAKE_METRIC (HOPCNT_INFINITY-2) 1310Sstevel@tonic-gate 1320Sstevel@tonic-gate 1330Sstevel@tonic-gate /* Router Discovery parameters */ 1340Sstevel@tonic-gate #define MAX_MAXADVERTISEINTERVAL 1800 1350Sstevel@tonic-gate #define MIN_MAXADVERTISEINTERVAL 4 1360Sstevel@tonic-gate #define DEF_MAXADVERTISEINTERVAL 600 1370Sstevel@tonic-gate #define DEF_PREFERENCELEVEL 0 1380Sstevel@tonic-gate #define MIN_PREFERENCELEVEL 0x80000000 1390Sstevel@tonic-gate 1400Sstevel@tonic-gate #define MAX_INITIAL_ADVERT_INTERVAL 16 1410Sstevel@tonic-gate #define MAX_INITIAL_ADVERTS 3 1420Sstevel@tonic-gate #define MAX_RESPONSE_DELAY 2 1430Sstevel@tonic-gate 1440Sstevel@tonic-gate #define MAX_SOLICITATION_DELAY 1 1450Sstevel@tonic-gate #define SOLICITATION_INTERVAL 3 1460Sstevel@tonic-gate #define MAX_SOLICITATIONS 3 1470Sstevel@tonic-gate 1480Sstevel@tonic-gate /* 1490Sstevel@tonic-gate * convert between signed, balanced around zero, 1500Sstevel@tonic-gate * and unsigned zero-based preferences 1510Sstevel@tonic-gate */ 1520Sstevel@tonic-gate #define SIGN_PREF(p) ((p) ^ MIN_PREFERENCELEVEL) 1530Sstevel@tonic-gate #define UNSIGN_PREF(p) SIGN_PREF(p) 1540Sstevel@tonic-gate 1550Sstevel@tonic-gate /* 1560Sstevel@tonic-gate * Bloated packet size for systems that simply add authentication to 1570Sstevel@tonic-gate * full-sized packets 1580Sstevel@tonic-gate */ 1590Sstevel@tonic-gate #define OVER_MAXPACKETSIZE (MAXPACKETSIZE+sizeof (struct netinfo)*2) 1600Sstevel@tonic-gate /* typical packet buffers */ 1610Sstevel@tonic-gate union pkt_buf { 1620Sstevel@tonic-gate uint8_t packet[OVER_MAXPACKETSIZE*2]; 1630Sstevel@tonic-gate struct rip rip; 1640Sstevel@tonic-gate }; 1650Sstevel@tonic-gate 1663284Sapersson extern struct dr *drs; 1673284Sapersson 1680Sstevel@tonic-gate /* 1690Sstevel@tonic-gate * IF_NAME_LEN is the maximum size of interface names represented within 1700Sstevel@tonic-gate * in.routed. Regular Solaris interfaces have names of at most LIFNAMESIZ 1710Sstevel@tonic-gate * characters, but in.routed has remote interfaces represented internally 1720Sstevel@tonic-gate * as "remote(<gatewayname>)", where <gatewayname> is a hostname or IP 1730Sstevel@tonic-gate * address. IF_NAME_LEN needs to be large enough to also hold such 1740Sstevel@tonic-gate * interface names as well. 1750Sstevel@tonic-gate */ 1760Sstevel@tonic-gate #define IF_NAME_LEN (MAXHOSTNAMELEN + sizeof ("remote()") + 1) 1770Sstevel@tonic-gate 1780Sstevel@tonic-gate /* 1790Sstevel@tonic-gate * No more routes than this, to protect ourself in case something goes 1800Sstevel@tonic-gate * whacko and starts broadcasting zillions of bogus routes. 1810Sstevel@tonic-gate */ 1820Sstevel@tonic-gate #define MAX_ROUTES (128*1024) 1830Sstevel@tonic-gate 1840Sstevel@tonic-gate enum origin { 1850Sstevel@tonic-gate RO_NONE, /* empty slot */ 1860Sstevel@tonic-gate RO_RIP, /* learnt from RIP */ 1870Sstevel@tonic-gate RO_RDISC, /* learnt from RDISC */ 1880Sstevel@tonic-gate RO_STATIC, /* learnt from kernel */ 1890Sstevel@tonic-gate RO_LOOPBCK, /* loopback route */ 1900Sstevel@tonic-gate RO_PTOPT, /* point-to-point route */ 1910Sstevel@tonic-gate RO_NET_SYN, /* fake net route for subnet */ 1920Sstevel@tonic-gate RO_IF, /* interface route */ 1930Sstevel@tonic-gate RO_FILE /* from /etc/gateways */ 1940Sstevel@tonic-gate }; 1950Sstevel@tonic-gate 1960Sstevel@tonic-gate /* 1970Sstevel@tonic-gate * Main, daemon routing table structure 1980Sstevel@tonic-gate */ 1990Sstevel@tonic-gate struct rt_spare { 2000Sstevel@tonic-gate struct interface *rts_ifp; 2010Sstevel@tonic-gate uint32_t rts_gate; /* forward packets here */ 2020Sstevel@tonic-gate uint32_t rts_router; /* on this router's authority */ 2030Sstevel@tonic-gate uint8_t rts_metric; 2040Sstevel@tonic-gate enum origin rts_origin; 2050Sstevel@tonic-gate uint16_t rts_tag; 2060Sstevel@tonic-gate time_t rts_time; /* timer to junk stale routes */ 2070Sstevel@tonic-gate uint32_t rts_de_ag; /* de-aggregation level */ 2080Sstevel@tonic-gate uint16_t rts_flags; 2090Sstevel@tonic-gate }; 2100Sstevel@tonic-gate 2110Sstevel@tonic-gate #define RTS_EXTERNAL 0x0001 /* handled by other routing protocol e.g. EGP */ 2120Sstevel@tonic-gate #define SPARE_INC 2 2130Sstevel@tonic-gate #define EMPTY_RT_SPARE { NULL, 0, 0, HOPCNT_INFINITY, RO_NONE, 0, 0, 0, 0 } 2140Sstevel@tonic-gate 2150Sstevel@tonic-gate struct rt_entry { 2160Sstevel@tonic-gate struct radix_node rt_nodes[2]; /* radix tree glue */ 2170Sstevel@tonic-gate struct sockaddr_in rt_dst_sock; 2180Sstevel@tonic-gate time_t rt_poison_time; /* advertised metric */ 2190Sstevel@tonic-gate in_addr_t rt_mask; 2200Sstevel@tonic-gate uint32_t rt_seqno; /* when last changed */ 2210Sstevel@tonic-gate uint16_t rt_state; 2220Sstevel@tonic-gate #define RS_IF 0x0001 /* for network interface */ 2230Sstevel@tonic-gate #define RS_NET_INT 0x0002 /* authority route */ 2240Sstevel@tonic-gate #define RS_NET_SYN 0x0004 /* fake net route for subnet */ 2250Sstevel@tonic-gate #define RS_NO_NET_SYN (RS_LOCAL | RS_IF) 2260Sstevel@tonic-gate #define RS_SUBNET 0x0008 /* subnet route from any source */ 2270Sstevel@tonic-gate #define RS_LOCAL 0x0010 /* loopback for pt-to-pt */ 2280Sstevel@tonic-gate #define RS_MHOME 0x0020 /* from -m */ 2290Sstevel@tonic-gate #define RS_STATIC 0x0040 /* from the kernel */ 2300Sstevel@tonic-gate #define RS_NOPROPAGATE 0x0080 /* route which must not be propagated */ 2310Sstevel@tonic-gate #define RS_BADIF 0x0100 /* route through dead ifp */ 2320Sstevel@tonic-gate 2330Sstevel@tonic-gate uint8_t rt_poison_metric; /* to notice maximum recently */ 2340Sstevel@tonic-gate uint_t rt_num_spares; 2350Sstevel@tonic-gate struct rt_spare *rt_spares; 2360Sstevel@tonic-gate }; 2370Sstevel@tonic-gate #define rt_dst rt_dst_sock.sin_addr.s_addr 2380Sstevel@tonic-gate #define rt_ifp rt_spares[0].rts_ifp 2390Sstevel@tonic-gate #define rt_gate rt_spares[0].rts_gate 2400Sstevel@tonic-gate #define rt_router rt_spares[0].rts_router 2410Sstevel@tonic-gate #define rt_metric rt_spares[0].rts_metric 2420Sstevel@tonic-gate #define rt_tag rt_spares[0].rts_tag 2430Sstevel@tonic-gate #define rt_time rt_spares[0].rts_time 2440Sstevel@tonic-gate #define rt_de_ag rt_spares[0].rts_de_ag 2450Sstevel@tonic-gate 2460Sstevel@tonic-gate #define HOST_MASK 0xffffffffU 2470Sstevel@tonic-gate #define RT_ISHOST(rt) ((rt)->rt_mask == HOST_MASK) 2480Sstevel@tonic-gate 2490Sstevel@tonic-gate /* 2500Sstevel@tonic-gate * Determine if a route should be aged. Age all routes that are: 2510Sstevel@tonic-gate * Not from -g, -m, nor static routes from the kernel 2520Sstevel@tonic-gate * not unbroken interface routes but not broken interfaces 2530Sstevel@tonic-gate * not learnt from RDISC or from /etc/gateways 2540Sstevel@tonic-gate * nor non-passive, remote interfaces that are not aliases 2550Sstevel@tonic-gate * (i.e. remote & metric=0) 2560Sstevel@tonic-gate */ 2570Sstevel@tonic-gate #define AGE_RT(rt_state, rts_origin, ifp) \ 2580Sstevel@tonic-gate ((!((rt_state) & (RS_MHOME | RS_STATIC | RS_NET_SYN)) && \ 2590Sstevel@tonic-gate (rts_origin != RO_RDISC) && \ 2600Sstevel@tonic-gate (rts_origin != RO_FILE)) && \ 2610Sstevel@tonic-gate (!((rt_state) & RS_IF) || \ 2620Sstevel@tonic-gate (ifp) == NULL || \ 2630Sstevel@tonic-gate (((ifp)->int_state & IS_REMOTE) && \ 2640Sstevel@tonic-gate !((ifp)->int_state & IS_PASSIVE)))) 2650Sstevel@tonic-gate 2660Sstevel@tonic-gate /* 2670Sstevel@tonic-gate * true if A is better than B 2680Sstevel@tonic-gate * Better if 2690Sstevel@tonic-gate * - A is not a poisoned route 2700Sstevel@tonic-gate * - and A is not stale 2710Sstevel@tonic-gate * - and either: 2720Sstevel@tonic-gate * - A has a shorter path 2730Sstevel@tonic-gate * - or the router is speaking for itself 2740Sstevel@tonic-gate * - or B has the same metric and isn't stale 2750Sstevel@tonic-gate * - or A is a host route advertised by a system for itself 2760Sstevel@tonic-gate */ 2770Sstevel@tonic-gate #define BETTER_LINK(rt, A, B) ((A)->rts_metric < HOPCNT_INFINITY && \ 2780Sstevel@tonic-gate now_stale <= (A)->rts_time && \ 2790Sstevel@tonic-gate ((A)->rts_metric < (B)->rts_metric || \ 2800Sstevel@tonic-gate ((A)->rts_gate == (A)->rts_router && \ 2810Sstevel@tonic-gate (B)->rts_gate != (B)->rts_router) || \ 2820Sstevel@tonic-gate ((A)->rts_metric == (B)->rts_metric && \ 2830Sstevel@tonic-gate now_stale > (B)->rts_time) || \ 2840Sstevel@tonic-gate (RT_ISHOST(rt) && \ 2850Sstevel@tonic-gate (rt)->rt_dst == (A)->rts_router && \ 2860Sstevel@tonic-gate (A)->rts_metric == (B)->rts_metric))) 2870Sstevel@tonic-gate 2880Sstevel@tonic-gate struct hlinkage { 2890Sstevel@tonic-gate void *hl_next; 2900Sstevel@tonic-gate void **hl_prev; 2910Sstevel@tonic-gate }; 2920Sstevel@tonic-gate 2930Sstevel@tonic-gate /* 2940Sstevel@tonic-gate * A "physical_interface" represents the actual hardware. It is also 2950Sstevel@tonic-gate * a container for a list of the interfaces that have the same ifIndex 2960Sstevel@tonic-gate * number. This will consist of zero or one "main" interface plus 2970Sstevel@tonic-gate * zero or more IS_ALIAS interfaces. 2980Sstevel@tonic-gate */ 2990Sstevel@tonic-gate struct physical_interface { 3000Sstevel@tonic-gate struct hlinkage phyi_link; 3010Sstevel@tonic-gate uint32_t phyi_index; 3020Sstevel@tonic-gate struct interface *phyi_interface; 3030Sstevel@tonic-gate struct phyi_data { 3040Sstevel@tonic-gate uint32_t ipackets; /* previous network stats */ 3050Sstevel@tonic-gate uint32_t ierrors; 3060Sstevel@tonic-gate uint32_t opackets; 3070Sstevel@tonic-gate uint32_t oerrors; 3080Sstevel@tonic-gate time_t ts; /* timestamp on network stats */ 3090Sstevel@tonic-gate } phyi_data; 3100Sstevel@tonic-gate char phyi_name[IF_NAME_LEN+1]; 3110Sstevel@tonic-gate }; 3120Sstevel@tonic-gate 3130Sstevel@tonic-gate /* 3140Sstevel@tonic-gate * An "interface" is similar to a kernel ifnet structure, except it also 3150Sstevel@tonic-gate * handles "logical" or "IS_REMOTE" interfaces (remote gateways). 3160Sstevel@tonic-gate */ 3170Sstevel@tonic-gate struct interface { 3180Sstevel@tonic-gate /* 3190Sstevel@tonic-gate * We keep interfaces in a variety of data structures to 3200Sstevel@tonic-gate * optimize for different types of searches. 3210Sstevel@tonic-gate */ 3220Sstevel@tonic-gate struct hlinkage int_link; 3230Sstevel@tonic-gate #define int_next int_link.hl_next 3240Sstevel@tonic-gate struct hlinkage int_ahash; /* by address */ 3250Sstevel@tonic-gate struct hlinkage int_bhash; /* by broadcast address */ 3260Sstevel@tonic-gate struct hlinkage int_nhash; /* by name */ 3270Sstevel@tonic-gate struct hlinkage int_ilist; /* ifIndex list */ 3280Sstevel@tonic-gate struct physical_interface *int_phys; /* backpointer */ 3290Sstevel@tonic-gate char int_name[IF_NAME_LEN+1]; 3300Sstevel@tonic-gate in_addr_t int_addr; /* address on this host (net order) */ 3310Sstevel@tonic-gate in_addr_t int_brdaddr; /* broadcast address (n) */ 3320Sstevel@tonic-gate in_addr_t int_dstaddr; /* other end of pt-to-pt link (n) */ 3330Sstevel@tonic-gate in_addr_t int_net; /* working network # (host order) */ 3340Sstevel@tonic-gate in_addr_t int_mask; /* working net mask (host order) */ 3350Sstevel@tonic-gate in_addr_t int_ripv1_mask; /* for inferring a mask (n) */ 3360Sstevel@tonic-gate in_addr_t int_std_addr; /* class A/B/C address (n) */ 3370Sstevel@tonic-gate in_addr_t int_std_net; /* class A/B/C network (h) */ 3380Sstevel@tonic-gate in_addr_t int_std_mask; /* class A/B/C netmask (h) */ 3390Sstevel@tonic-gate in_addr_t int_ripout_addr; /* RIP pkts sent to this addr */ 340192Scarlsonj uint64_t int_if_flags; /* some bits copied from kernel */ 3410Sstevel@tonic-gate uint32_t int_state; 3420Sstevel@tonic-gate time_t int_act_time; /* last thought healthy (IS_REMOTE) */ 3430Sstevel@tonic-gate time_t int_query_time; /* last query (IS_REMOTE) */ 3440Sstevel@tonic-gate uint32_t int_transitions; /* times gone up-down */ 3450Sstevel@tonic-gate uint8_t int_metric; 3460Sstevel@tonic-gate uint8_t int_d_metric; /* for faked default route */ 3470Sstevel@tonic-gate #define MAX_AUTH_KEYS 5 3480Sstevel@tonic-gate struct auth { /* authentication info */ 3490Sstevel@tonic-gate time_t start, end; 3500Sstevel@tonic-gate uint16_t type; 3510Sstevel@tonic-gate /* 3520Sstevel@tonic-gate * Although the following key is just an array of bytes, 3530Sstevel@tonic-gate * in.routed is currently limited to ascii characters 3540Sstevel@tonic-gate * because of its configuration syntax and parsing. 3550Sstevel@tonic-gate */ 3560Sstevel@tonic-gate uint8_t key[RIP_AUTH_PW_LEN +1]; 3570Sstevel@tonic-gate uint8_t keyid; 3580Sstevel@tonic-gate uint8_t warnedflag; 3590Sstevel@tonic-gate } int_auth[MAX_AUTH_KEYS]; 3600Sstevel@tonic-gate /* router discovery parameters */ 3610Sstevel@tonic-gate int int_rdisc_pref; /* signed preference to advertise */ 3620Sstevel@tonic-gate uint32_t int_rdisc_int; /* MaxAdvertiseInterval */ 3630Sstevel@tonic-gate uint32_t int_rdisc_cnt; 3640Sstevel@tonic-gate struct timeval int_rdisc_timer; 3650Sstevel@tonic-gate }; 3660Sstevel@tonic-gate 3670Sstevel@tonic-gate /* bits in int_state */ 3680Sstevel@tonic-gate #define IS_ALIAS 0x00000001 /* interface alias */ 3690Sstevel@tonic-gate #define IS_SUBNET 0x00000002 /* interface on subnetted network */ 3700Sstevel@tonic-gate #define IS_REMOTE 0x00000004 /* interface is not on this machine */ 3710Sstevel@tonic-gate #define IS_PASSIVE 0x00000008 /* remote and does not do RIP */ 3720Sstevel@tonic-gate #define IS_EXTERNAL 0x00000010 /* handled by EGP or something */ 3730Sstevel@tonic-gate #define IS_CHECKED 0x00000020 /* still exists */ 3740Sstevel@tonic-gate #define IS_ALL_HOSTS 0x00000040 /* in INADDR_ALLHOSTS_GROUP */ 3750Sstevel@tonic-gate #define IS_ALL_ROUTERS 0x00000080 /* in INADDR_ALLROUTERS_GROUP */ 3760Sstevel@tonic-gate #define IS_DISTRUST 0x00000100 /* ignore untrusted routers */ 3770Sstevel@tonic-gate #define IS_REDIRECT_OK 0x00000200 /* accept ICMP redirects */ 3780Sstevel@tonic-gate #define IS_BROKE 0x00000400 /* seems to be broken */ 3790Sstevel@tonic-gate #define IS_SICK 0x00000800 /* seems to be broken */ 3800Sstevel@tonic-gate #define IS_DUP 0x00001000 /* duplicates another interface */ 3810Sstevel@tonic-gate #define IS_NEED_NET_SYN 0x00002000 /* need RS_NET_SYN route */ 3820Sstevel@tonic-gate #define IS_NO_AG 0x00004000 /* do not aggregate subnets */ 3830Sstevel@tonic-gate #define IS_NO_SUPER_AG 0x00008000 /* do not aggregate networks */ 3840Sstevel@tonic-gate #define IS_NO_RIPV1_IN 0x00010000 /* no RIPv1 input at all */ 3850Sstevel@tonic-gate #define IS_NO_RIPV2_IN 0x00020000 /* no RIPv2 input at all */ 3860Sstevel@tonic-gate #define IS_NO_RIP_IN (IS_NO_RIPV1_IN | IS_NO_RIPV2_IN) 3870Sstevel@tonic-gate #define IS_RIP_IN_OFF(s) (((s) & IS_NO_RIP_IN) == IS_NO_RIP_IN) 3880Sstevel@tonic-gate #define IS_NO_RIPV1_OUT 0x00040000 /* no RIPv1 output at all */ 3890Sstevel@tonic-gate #define IS_NO_RIPV2_OUT 0x00080000 /* no RIPv2 output at all */ 3900Sstevel@tonic-gate #define IS_NO_RIP_OUT (IS_NO_RIPV1_OUT | IS_NO_RIPV2_OUT) 3910Sstevel@tonic-gate #define IS_NO_RIP (IS_NO_RIP_OUT | IS_NO_RIP_IN) 3920Sstevel@tonic-gate #define IS_RIP_OUT_OFF(s) (((s) & IS_NO_RIP_OUT) == IS_NO_RIP_OUT) 3930Sstevel@tonic-gate #define IS_RIP_OFF(s) (((s) & IS_NO_RIP) == IS_NO_RIP) 3940Sstevel@tonic-gate #define IS_NO_RIP_MCAST 0x00100000 /* broadcast RIPv2 */ 3950Sstevel@tonic-gate #define IS_NO_ADV_IN 0x00200000 /* do not listen to advertisements */ 3960Sstevel@tonic-gate #define IS_NO_SOL_OUT 0x00400000 /* send no solicitations */ 3970Sstevel@tonic-gate #define IS_SOL_OUT 0x00800000 /* send solicitations */ 3980Sstevel@tonic-gate #define GROUP_IS_SOL_OUT (IS_SOL_OUT | IS_NO_SOL_OUT) 3990Sstevel@tonic-gate #define IS_NO_ADV_OUT 0x01000000 /* do not advertise rdisc */ 4000Sstevel@tonic-gate #define IS_ADV_OUT 0x02000000 /* advertise rdisc */ 4010Sstevel@tonic-gate #define GROUP_IS_ADV_OUT (IS_NO_ADV_OUT | IS_ADV_OUT) 4020Sstevel@tonic-gate #define IS_BCAST_RDISC 0x04000000 /* broadcast instead of multicast */ 4030Sstevel@tonic-gate #define IS_NO_RDISC (IS_NO_ADV_IN | IS_NO_SOL_OUT | IS_NO_ADV_OUT) 4040Sstevel@tonic-gate #define IS_PM_RDISC 0x08000000 /* poor-man's router discovery */ 4050Sstevel@tonic-gate #define IS_NO_HOST 0x10000000 /* disallow host routes */ 4060Sstevel@tonic-gate #define IS_SUPPRESS_RDISC 0x20000000 /* don't send rdisc advs */ 4070Sstevel@tonic-gate #define IS_FLUSH_RDISC 0x40000000 /* flush client rdisc caches */ 4080Sstevel@tonic-gate 4090Sstevel@tonic-gate /* 4100Sstevel@tonic-gate * passive interfaces are added through gwkludge 4110Sstevel@tonic-gate */ 4120Sstevel@tonic-gate #define IS_PASSIVE_IFP(ifp) \ 4130Sstevel@tonic-gate (((ifp)->int_state & (IS_REMOTE|IS_PASSIVE|IS_EXTERNAL|IS_ALIAS)) == \ 4140Sstevel@tonic-gate (IS_REMOTE|IS_PASSIVE)) 4150Sstevel@tonic-gate 4160Sstevel@tonic-gate /* 417*8485SPeter.Memishian@Sun.COM * Is an IP interface up? 4180Sstevel@tonic-gate */ 419*8485SPeter.Memishian@Sun.COM #define IS_IFF_UP(f) (((f) & (IFF_UP|IFF_RUNNING)) == (IFF_UP|IFF_RUNNING)) 4200Sstevel@tonic-gate 4210Sstevel@tonic-gate /* 4220Sstevel@tonic-gate * This defines interfaces that we should not use for advertising or 4230Sstevel@tonic-gate * soliciting routes by way of RIP and rdisc. Interfaces marked this 4240Sstevel@tonic-gate * way do not count for purposes of determining how many interfaces 4250Sstevel@tonic-gate * this router has. 4260Sstevel@tonic-gate */ 4270Sstevel@tonic-gate #define IS_IFF_QUIET(f) ((f) & (IFF_LOOPBACK|IFF_NORTEXCH|IFF_NOXMIT)) 4280Sstevel@tonic-gate 4290Sstevel@tonic-gate /* 4300Sstevel@tonic-gate * This defines interfaces that we can use for advertising routes by way of 4310Sstevel@tonic-gate * RIP and rdisc. 4320Sstevel@tonic-gate */ 4330Sstevel@tonic-gate #define IS_IFF_ROUTING(f) \ 4340Sstevel@tonic-gate (((f) & IFF_ROUTER) && !((f) & (IFF_NORTEXCH|IFF_NOXMIT))) 4350Sstevel@tonic-gate 4360Sstevel@tonic-gate /* Information for aggregating routes */ 4370Sstevel@tonic-gate #define NUM_AG_SLOTS 32 4380Sstevel@tonic-gate struct ag_info { 4390Sstevel@tonic-gate struct ag_info *ag_fine; /* slot with finer netmask */ 4400Sstevel@tonic-gate struct ag_info *ag_cors; /* more coarse netmask */ 4410Sstevel@tonic-gate in_addr_t ag_dst_h; /* destination in host byte order */ 4420Sstevel@tonic-gate in_addr_t ag_mask; 4430Sstevel@tonic-gate in_addr_t ag_gate; 4440Sstevel@tonic-gate struct interface *ag_ifp; 4450Sstevel@tonic-gate in_addr_t ag_nhop; 4460Sstevel@tonic-gate uint8_t ag_metric; /* metric to be advertised */ 4470Sstevel@tonic-gate uint8_t ag_pref; /* aggregate based on this */ 4480Sstevel@tonic-gate uint32_t ag_seqno; 4490Sstevel@tonic-gate uint16_t ag_tag; 4500Sstevel@tonic-gate uint16_t ag_state; 4510Sstevel@tonic-gate #define AGS_SUPPRESS 0x001 /* combine with coarser mask */ 4520Sstevel@tonic-gate #define AGS_AGGREGATE 0x002 /* synthesize combined routes */ 4530Sstevel@tonic-gate #define AGS_REDUN0 0x004 /* redundant, finer routes output */ 4540Sstevel@tonic-gate #define AGS_REDUN1 0x008 4550Sstevel@tonic-gate #define AG_IS_REDUN(state) (((state) & (AGS_REDUN0 | AGS_REDUN1)) \ 4560Sstevel@tonic-gate == (AGS_REDUN0 | AGS_REDUN1)) 4570Sstevel@tonic-gate #define AGS_GATEWAY 0x010 /* tell kernel RTF_GATEWAY */ 4580Sstevel@tonic-gate #define AGS_IF 0x020 /* for an interface */ 4590Sstevel@tonic-gate #define AGS_RIPV2 0x040 /* send only as RIPv2 */ 4600Sstevel@tonic-gate #define AGS_FINE_GATE 0x080 /* ignore differing ag_gate when */ 4610Sstevel@tonic-gate /* this has the finer netmask */ 4620Sstevel@tonic-gate #define AGS_CORS_GATE 0x100 /* ignore differing gate when this */ 4630Sstevel@tonic-gate /* has the coarser netmasks */ 4640Sstevel@tonic-gate #define AGS_SPLIT_HZ 0x200 /* suppress for split horizon */ 4650Sstevel@tonic-gate #define AGS_PASSIVE 0x400 /* passive "remote" interface route */ 4660Sstevel@tonic-gate #define AGS_FILE 0x800 /* from /etc/gateways */ 4670Sstevel@tonic-gate 4680Sstevel@tonic-gate /* some bits are set if they are set on either route */ 4690Sstevel@tonic-gate #define AGS_AGGREGATE_EITHER (AGS_RIPV2 | AGS_GATEWAY | \ 4700Sstevel@tonic-gate AGS_SUPPRESS | AGS_CORS_GATE) 4710Sstevel@tonic-gate }; 4720Sstevel@tonic-gate 4730Sstevel@tonic-gate struct khash { 4740Sstevel@tonic-gate struct khash *k_next; 4750Sstevel@tonic-gate in_addr_t k_dst; 4760Sstevel@tonic-gate in_addr_t k_mask; 4770Sstevel@tonic-gate in_addr_t k_gate; 4780Sstevel@tonic-gate struct interface *k_ifp; 4790Sstevel@tonic-gate short k_metric; 4800Sstevel@tonic-gate ushort_t k_state; /* KS_* */ 4810Sstevel@tonic-gate time_t k_keep; 4820Sstevel@tonic-gate time_t k_redirect_time; /* when redirected route 1st seen */ 4830Sstevel@tonic-gate }; 4840Sstevel@tonic-gate 4850Sstevel@tonic-gate /* bit flags for k_state; shared between table.c and trace.c */ 4860Sstevel@tonic-gate #define KS_NEW 0x0001 4870Sstevel@tonic-gate #define KS_DELETE 0x0002 /* need to delete the route */ 4880Sstevel@tonic-gate #define KS_ADD 0x0004 /* add to the kernel */ 4890Sstevel@tonic-gate #define KS_CHANGE 0x0008 /* tell kernel to change the route */ 4900Sstevel@tonic-gate #define KS_DEL_ADD 0x0010 /* delete & add to change the kernel */ 4910Sstevel@tonic-gate #define KS_STATIC 0x0020 /* Static flag in kernel */ 4920Sstevel@tonic-gate #define KS_GATEWAY 0x0040 /* G flag in kernel */ 4930Sstevel@tonic-gate #define KS_DYNAMIC 0x0080 /* result of redirect */ 4940Sstevel@tonic-gate #define KS_DELETED 0x0100 /* already deleted from kernel */ 4950Sstevel@tonic-gate #define KS_PRIVATE 0x0200 /* Private flag in kernel */ 4960Sstevel@tonic-gate #define KS_CHECK 0x0400 4970Sstevel@tonic-gate #define KS_IF 0x0800 /* interface route */ 4980Sstevel@tonic-gate #define KS_PASSIVE 0x1000 /* passive remote interface route */ 4990Sstevel@tonic-gate #define KS_DEPRE_IF 0x2000 /* IPMP deprecated interface route */ 5000Sstevel@tonic-gate #define KS_FILE 0x4000 /* from /etc/gateways */ 5010Sstevel@tonic-gate 5020Sstevel@tonic-gate /* default router structure */ 5030Sstevel@tonic-gate struct dr { /* accumulated advertisements */ 5040Sstevel@tonic-gate struct interface *dr_ifp; 5050Sstevel@tonic-gate in_addr_t dr_gate; /* gateway */ 5060Sstevel@tonic-gate time_t dr_ts; /* when received */ 5070Sstevel@tonic-gate time_t dr_life; /* lifetime in host byte order */ 5080Sstevel@tonic-gate uint32_t dr_recv_pref; /* received but biased preference */ 5090Sstevel@tonic-gate uint32_t dr_pref; /* preference adjusted by metric */ 5100Sstevel@tonic-gate uint32_t dr_flags; 5110Sstevel@tonic-gate #define DR_CHANGED 1 /* received new info for known dr */ 5120Sstevel@tonic-gate }; 5130Sstevel@tonic-gate 5140Sstevel@tonic-gate /* parameters for interfaces */ 5150Sstevel@tonic-gate struct parm { 5160Sstevel@tonic-gate struct parm *parm_next; 5170Sstevel@tonic-gate in_addr_t parm_net; 5180Sstevel@tonic-gate in_addr_t parm_mask; 5190Sstevel@tonic-gate in_addr_t parm_ripout_addr; 5200Sstevel@tonic-gate uint32_t parm_int_state; 5210Sstevel@tonic-gate int32_t parm_rdisc_pref; /* signed IRDP preference */ 5220Sstevel@tonic-gate uint32_t parm_rdisc_int; /* IRDP advertising interval */ 5230Sstevel@tonic-gate struct auth parm_auth[MAX_AUTH_KEYS]; 5240Sstevel@tonic-gate char parm_name[IF_NAME_LEN+1]; 5250Sstevel@tonic-gate uint8_t parm_d_metric; 5260Sstevel@tonic-gate }; 5270Sstevel@tonic-gate 5280Sstevel@tonic-gate /* authority for internal networks */ 5290Sstevel@tonic-gate extern struct intnet { 5300Sstevel@tonic-gate struct intnet *intnet_next; 5310Sstevel@tonic-gate in_addr_t intnet_addr; /* network byte order */ 5320Sstevel@tonic-gate in_addr_t intnet_mask; 5330Sstevel@tonic-gate int8_t intnet_metric; 5340Sstevel@tonic-gate } *intnets; 5350Sstevel@tonic-gate 5360Sstevel@tonic-gate /* 5370Sstevel@tonic-gate * Defined RIPv1 netmasks. These come from ripv1_mask entries in 5380Sstevel@tonic-gate * /etc/gateways of the form: 5390Sstevel@tonic-gate * 5400Sstevel@tonic-gate * ripv1_mask=<net>/<match>,<mask> 5410Sstevel@tonic-gate * 5420Sstevel@tonic-gate * The intended use of these structures is to give RIPv1 destinations which 5430Sstevel@tonic-gate * are in <net>/<match> a netmask of <mask>, where <mask> > <match>. 5440Sstevel@tonic-gate */ 5450Sstevel@tonic-gate extern struct r1net { 5460Sstevel@tonic-gate struct r1net *r1net_next; 5470Sstevel@tonic-gate in_addr_t r1net_net; /* host order */ 5480Sstevel@tonic-gate in_addr_t r1net_match; 5490Sstevel@tonic-gate in_addr_t r1net_mask; 5500Sstevel@tonic-gate } *r1nets; 5510Sstevel@tonic-gate 5520Sstevel@tonic-gate /* trusted routers */ 5530Sstevel@tonic-gate extern struct tgate { 5540Sstevel@tonic-gate struct tgate *tgate_next; 5550Sstevel@tonic-gate in_addr_t tgate_addr; 5560Sstevel@tonic-gate #define MAX_TGATE_NETS 32 5570Sstevel@tonic-gate struct tgate_net { 5580Sstevel@tonic-gate in_addr_t net; /* host order */ 5590Sstevel@tonic-gate in_addr_t mask; 5600Sstevel@tonic-gate } tgate_nets[MAX_TGATE_NETS]; 5610Sstevel@tonic-gate } *tgates; 5620Sstevel@tonic-gate 5630Sstevel@tonic-gate enum output_type {OUT_QUERY, OUT_UNICAST, OUT_BROADCAST, OUT_MULTICAST, 5640Sstevel@tonic-gate NO_OUT_MULTICAST, NO_OUT_RIPV2}; 5650Sstevel@tonic-gate 5660Sstevel@tonic-gate /* common output buffers */ 5670Sstevel@tonic-gate extern struct ws_buf { 5680Sstevel@tonic-gate struct rip *buf; 5690Sstevel@tonic-gate struct netinfo *n; 5700Sstevel@tonic-gate struct netinfo *base; 5710Sstevel@tonic-gate struct netinfo *lim; 5720Sstevel@tonic-gate enum output_type type; 5730Sstevel@tonic-gate } v12buf; 5740Sstevel@tonic-gate 5750Sstevel@tonic-gate extern int stopint; /* !=0 to stop in.routed */ 5760Sstevel@tonic-gate 5770Sstevel@tonic-gate extern int rip_sock; /* RIP socket */ 5780Sstevel@tonic-gate extern struct interface *rip_sock_interface; /* current output interface */ 5790Sstevel@tonic-gate extern int rt_sock; /* routing socket */ 5800Sstevel@tonic-gate extern int rdisc_sock; /* router-discovery raw socket */ 5813284Sapersson extern int rdisc_mib_sock; /* AF_UNIX mib info socket */ 5820Sstevel@tonic-gate 5830Sstevel@tonic-gate extern boolean_t rip_enabled; /* is rip on? */ 5840Sstevel@tonic-gate extern boolean_t supplier; /* process should supply updates */ 5850Sstevel@tonic-gate extern boolean_t supplier_set; /* -s or -q requested */ 5860Sstevel@tonic-gate extern boolean_t save_space; /* -S option 1=treat all RIP speakers */ 5870Sstevel@tonic-gate extern boolean_t ridhosts; /* 1=reduce host routes */ 5880Sstevel@tonic-gate extern boolean_t mhome; /* 1=want multi-homed host route */ 5890Sstevel@tonic-gate extern boolean_t advertise_mhome; /* 1=must continue advertising it */ 5900Sstevel@tonic-gate extern boolean_t auth_ok; /* 1=ignore auth if we do not care */ 5910Sstevel@tonic-gate extern boolean_t no_install; /* 1=don't install in kernel */ 5920Sstevel@tonic-gate 5930Sstevel@tonic-gate extern struct timeval clk; /* system clock's idea of time */ 5940Sstevel@tonic-gate extern struct timeval epoch; /* system clock when started */ 5950Sstevel@tonic-gate extern struct timeval now; /* current idea of time */ 5960Sstevel@tonic-gate extern time_t now_stale; 5970Sstevel@tonic-gate extern time_t now_expire; 5980Sstevel@tonic-gate extern time_t now_garbage; 5990Sstevel@tonic-gate 6000Sstevel@tonic-gate extern struct timeval age_timer; /* next check of old routes */ 6010Sstevel@tonic-gate extern struct timeval no_flash; /* inhibit flash update until then */ 6020Sstevel@tonic-gate extern struct timeval rdisc_timer; /* next advert. or solicitation */ 6030Sstevel@tonic-gate extern boolean_t rdisc_ok; /* using solicited route */ 6040Sstevel@tonic-gate 6050Sstevel@tonic-gate extern struct timeval ifscan_timer; /* time to check interfaces */ 6060Sstevel@tonic-gate 6070Sstevel@tonic-gate extern in_addr_t loopaddr; /* our address on loopback */ 6080Sstevel@tonic-gate extern uint_t tot_interfaces; /* # of remote and local interfaces */ 6090Sstevel@tonic-gate extern uint_t rip_interfaces; /* # of interfaces doing RIP */ 6100Sstevel@tonic-gate extern uint_t ripout_interfaces; /* # of interfaces advertising RIP */ 6110Sstevel@tonic-gate extern uint_t fwd_interfaces; /* # of interfaces ip_forwarding=1 */ 6120Sstevel@tonic-gate extern struct interface *ifnet; /* all interfaces */ 6130Sstevel@tonic-gate extern size_t hash_table_sizes[]; /* list of primes for hash tables */ 6140Sstevel@tonic-gate extern boolean_t have_ripv1_out; /* have a RIPv1 interface */ 6150Sstevel@tonic-gate extern boolean_t need_flash; /* flash update needed */ 6160Sstevel@tonic-gate extern struct timeval need_kern; /* need to update kernel table */ 6170Sstevel@tonic-gate extern uint32_t update_seqno; /* a route has changed */ 6180Sstevel@tonic-gate extern struct interface dummy_ifp; /* wildcard interface */ 6190Sstevel@tonic-gate 6200Sstevel@tonic-gate extern int tracelevel, new_tracelevel; 6210Sstevel@tonic-gate #define MAX_TRACELEVEL 5 6220Sstevel@tonic-gate #define TRACERTS (tracelevel >= 5) /* log routing socket contents */ 6230Sstevel@tonic-gate #define TRACEKERNEL (tracelevel >= 4) /* log kernel changes */ 6240Sstevel@tonic-gate #define TRACECONTENTS (tracelevel >= 3) /* display packet contents */ 6250Sstevel@tonic-gate #define TRACEPACKETS (tracelevel >= 2) /* note packets */ 6260Sstevel@tonic-gate #define TRACEACTIONS (tracelevel != 0) 6270Sstevel@tonic-gate extern FILE *ftrace; /* output trace file */ 6280Sstevel@tonic-gate extern char inittracename[MAXPATHLEN+1]; 6290Sstevel@tonic-gate 6300Sstevel@tonic-gate extern struct radix_node_head *rhead; 6310Sstevel@tonic-gate 6320Sstevel@tonic-gate extern void fix_sock(int, const char *); 6330Sstevel@tonic-gate extern void fix_select(void); 6340Sstevel@tonic-gate extern void rip_off(void); 6350Sstevel@tonic-gate extern void rip_on(struct interface *); 6360Sstevel@tonic-gate 6370Sstevel@tonic-gate extern void bufinit(void); 6380Sstevel@tonic-gate extern int output(enum output_type, struct sockaddr_in *, 6390Sstevel@tonic-gate struct interface *, struct rip *, int); 6400Sstevel@tonic-gate extern void clr_ws_buf(struct ws_buf *, struct auth *); 6410Sstevel@tonic-gate extern void rip_query(void); 6420Sstevel@tonic-gate extern void rip_bcast(int); 6430Sstevel@tonic-gate extern void supply(struct sockaddr_in *, struct interface *, 6440Sstevel@tonic-gate enum output_type, int, int, boolean_t); 6450Sstevel@tonic-gate 6460Sstevel@tonic-gate extern void msglog(const char *, ...); 6470Sstevel@tonic-gate extern void writelog(int, const char *, ...); 6480Sstevel@tonic-gate struct msg_limit { 6490Sstevel@tonic-gate time_t reuse; 6500Sstevel@tonic-gate struct msg_sub { 6510Sstevel@tonic-gate in_addr_t addr; 6520Sstevel@tonic-gate time_t until; 6530Sstevel@tonic-gate #define MSG_SUBJECT_N 8 6540Sstevel@tonic-gate } subs[MSG_SUBJECT_N]; 6550Sstevel@tonic-gate }; 6560Sstevel@tonic-gate extern void msglim(struct msg_limit *, in_addr_t, const char *, ...); 6570Sstevel@tonic-gate #define LOGERR(msg) msglog(msg ": %s", rip_strerror(errno)) 6580Sstevel@tonic-gate extern void logbad(boolean_t, const char *, ...); 6590Sstevel@tonic-gate #define BADERR(dump, msg) logbad(dump, msg ": %s", rip_strerror(errno)) 6600Sstevel@tonic-gate #ifdef DEBUG 6610Sstevel@tonic-gate #define DBGERR(dump, msg) BADERR(dump, msg) 6620Sstevel@tonic-gate #else 6630Sstevel@tonic-gate #define DBGERR(dump, msg) LOGERR(msg) 6640Sstevel@tonic-gate #endif 6650Sstevel@tonic-gate extern char *naddr_ntoa(in_addr_t); 6660Sstevel@tonic-gate extern const char *saddr_ntoa(struct sockaddr_storage *); 6670Sstevel@tonic-gate extern const char *rip_strerror(int errnum); 6680Sstevel@tonic-gate extern char *if_bit_string(uint_t, boolean_t); 6690Sstevel@tonic-gate 6700Sstevel@tonic-gate extern void *rtmalloc(size_t, const char *); 6710Sstevel@tonic-gate extern void timevaladd(struct timeval *, struct timeval *); 6720Sstevel@tonic-gate extern void intvl_random(struct timeval *, ulong_t, ulong_t); 6730Sstevel@tonic-gate extern boolean_t getnet(const char *, in_addr_t *, in_addr_t *); 6740Sstevel@tonic-gate extern int gethost(char *, in_addr_t *); 6750Sstevel@tonic-gate extern void gwkludge(void); 6760Sstevel@tonic-gate extern const char *parse_parms(char *, boolean_t); 6770Sstevel@tonic-gate extern const char *insert_parm(struct parm *); 6780Sstevel@tonic-gate extern void get_parms(struct interface *); 6790Sstevel@tonic-gate 6800Sstevel@tonic-gate extern void lastlog(void); 6810Sstevel@tonic-gate extern void trace_close(int); 6820Sstevel@tonic-gate extern void set_tracefile(const char *, const char *, int); 6830Sstevel@tonic-gate extern void tracelevel_msg(const char *, int); 6840Sstevel@tonic-gate extern void trace_off(const char *, ...); 6850Sstevel@tonic-gate extern void set_tracelevel(void); 6860Sstevel@tonic-gate extern void trace_flush(void); 6870Sstevel@tonic-gate extern void trace_misc(const char *, ...); 6880Sstevel@tonic-gate extern void trace_act(const char *, ...); 6890Sstevel@tonic-gate extern void trace_pkt(const char *, ...); 6900Sstevel@tonic-gate extern void trace_add_del(const char *, struct rt_entry *); 6910Sstevel@tonic-gate extern void trace_change(struct rt_entry *, uint16_t, struct rt_spare *, 6920Sstevel@tonic-gate const char *); 6930Sstevel@tonic-gate extern void trace_if(const char *, struct interface *); 6940Sstevel@tonic-gate extern void trace_khash(const struct khash *); 6950Sstevel@tonic-gate extern void trace_dr(const struct dr *); 6960Sstevel@tonic-gate extern void trace_upslot(struct rt_entry *, struct rt_spare *, 6970Sstevel@tonic-gate struct rt_spare *); 6980Sstevel@tonic-gate extern void trace_rip(const char *, const char *, struct sockaddr_in *, 6990Sstevel@tonic-gate struct interface *, struct rip *, int); 7000Sstevel@tonic-gate extern char *addrname(in_addr_t, in_addr_t, int); 7010Sstevel@tonic-gate extern char *rtname(in_addr_t, in_addr_t, in_addr_t); 7020Sstevel@tonic-gate 7030Sstevel@tonic-gate extern void rdisc_age(in_addr_t); 7040Sstevel@tonic-gate extern void set_rdisc_mg(struct interface *, int); 7050Sstevel@tonic-gate extern void set_supplier(void); 7060Sstevel@tonic-gate extern void if_bad_rdisc(struct interface *); 7070Sstevel@tonic-gate extern void if_rewire_rdisc(struct interface *, struct interface *); 7080Sstevel@tonic-gate extern void if_ok_rdisc(struct interface *); 7090Sstevel@tonic-gate extern int read_rip(void); 7100Sstevel@tonic-gate extern void input_route(in_addr_t, in_addr_t, struct rt_spare *, 7110Sstevel@tonic-gate struct netinfo *, uint16_t); 7120Sstevel@tonic-gate extern void read_rt(void); 7130Sstevel@tonic-gate extern void read_d(void); 7143284Sapersson extern void process_d_mib_sock(void); 7150Sstevel@tonic-gate extern void rdisc_adv(boolean_t); 7160Sstevel@tonic-gate extern void rdisc_sol(void); 7170Sstevel@tonic-gate extern struct interface *receiving_interface(struct msghdr *, boolean_t); 7180Sstevel@tonic-gate extern void *find_ancillary(struct msghdr *, int); 7190Sstevel@tonic-gate extern boolean_t should_supply(struct interface *); 7200Sstevel@tonic-gate extern void rdisc_dump(void); 7210Sstevel@tonic-gate extern void rdisc_suppress(struct interface *); 7220Sstevel@tonic-gate extern void rdisc_restore(struct interface *); 7230Sstevel@tonic-gate 7240Sstevel@tonic-gate extern void age_peer_info(void); 7250Sstevel@tonic-gate 7260Sstevel@tonic-gate extern void sigtrace_more(int); 7270Sstevel@tonic-gate extern void sigtrace_less(int); 7280Sstevel@tonic-gate extern void sigtrace_dump(int); 7290Sstevel@tonic-gate 7300Sstevel@tonic-gate extern void sync_kern(void); 7310Sstevel@tonic-gate extern void age(in_addr_t); 7320Sstevel@tonic-gate extern void kern_dump(void); 7330Sstevel@tonic-gate extern void kern_flush_ifp(struct interface *); 7340Sstevel@tonic-gate extern void kern_rewire_ifp(struct interface *, struct interface *); 7350Sstevel@tonic-gate 7360Sstevel@tonic-gate extern void ag_flush(in_addr_t, in_addr_t, void (*)(struct ag_info *)); 7370Sstevel@tonic-gate extern void ag_check(in_addr_t, in_addr_t, in_addr_t, struct interface *, 7380Sstevel@tonic-gate in_addr_t, uint8_t, uint8_t, uint32_t, uint16_t, uint16_t, 7390Sstevel@tonic-gate void (*)(struct ag_info *)); 7400Sstevel@tonic-gate extern void del_static(in_addr_t, in_addr_t, in_addr_t, 7410Sstevel@tonic-gate struct interface *, int); 7420Sstevel@tonic-gate extern void del_redirects(in_addr_t, time_t); 7430Sstevel@tonic-gate extern struct rt_entry *rtget(in_addr_t, in_addr_t); 7440Sstevel@tonic-gate extern struct rt_entry *rtfind(in_addr_t); 7450Sstevel@tonic-gate extern void rtinit(void); 7460Sstevel@tonic-gate extern void rtadd(in_addr_t, in_addr_t, uint16_t, struct rt_spare *); 7470Sstevel@tonic-gate extern void rtchange(struct rt_entry *, uint16_t, struct rt_spare *, 7480Sstevel@tonic-gate char *); 7490Sstevel@tonic-gate extern void rtdelete(struct rt_entry *); 7500Sstevel@tonic-gate extern void rts_delete(struct rt_entry *, struct rt_spare *); 7510Sstevel@tonic-gate extern void rtbad_sub(struct rt_entry *, struct interface *); 7520Sstevel@tonic-gate extern void rtswitch(struct rt_entry *, struct rt_spare *); 7530Sstevel@tonic-gate 7540Sstevel@tonic-gate #define S_ADDR(x) (((struct sockaddr_in *)(x))->sin_addr.s_addr) 7550Sstevel@tonic-gate #define INFO_DST(I) ((I)->rti_info[RTAX_DST]) 7560Sstevel@tonic-gate #define INFO_GATE(I) ((I)->rti_info[RTAX_GATEWAY]) 7570Sstevel@tonic-gate #define INFO_MASK(I) ((I)->rti_info[RTAX_NETMASK]) 7580Sstevel@tonic-gate #define INFO_AUTHOR(I) ((I)->rti_info[RTAX_AUTHOR]) 7590Sstevel@tonic-gate 7600Sstevel@tonic-gate struct rewire_data { 7610Sstevel@tonic-gate struct interface *if_old; 7620Sstevel@tonic-gate struct interface *if_new; 7630Sstevel@tonic-gate int metric_delta; 7640Sstevel@tonic-gate }; 7650Sstevel@tonic-gate 7660Sstevel@tonic-gate extern char *qstring(const uchar_t *, int); 7670Sstevel@tonic-gate extern in_addr_t std_mask(in_addr_t); 7680Sstevel@tonic-gate extern int parse_quote(char **, const char *, char *, char *, int); 7690Sstevel@tonic-gate extern in_addr_t ripv1_mask_net(in_addr_t, const struct interface *); 7700Sstevel@tonic-gate extern in_addr_t ripv1_mask_host(in_addr_t, const struct interface *); 7710Sstevel@tonic-gate #define on_net(a, net, mask) (((ntohl(a) ^ (net)) & (mask)) == 0) 7720Sstevel@tonic-gate extern boolean_t check_dst(in_addr_t); 7730Sstevel@tonic-gate extern boolean_t remote_address_ok(struct interface *, in_addr_t); 7740Sstevel@tonic-gate extern struct interface *check_dup(const char *, in_addr_t, in_addr_t, 775192Scarlsonj in_addr_t, uint64_t, boolean_t); 7760Sstevel@tonic-gate extern boolean_t check_remote(struct interface *); 7770Sstevel@tonic-gate extern void iftbl_alloc(void); 7780Sstevel@tonic-gate extern void ifscan(void); 7790Sstevel@tonic-gate extern int walk_bad(struct radix_node *, void *); 7800Sstevel@tonic-gate extern int walk_rewire(struct radix_node *, void *); 7810Sstevel@tonic-gate extern void if_ok(struct interface *, const char *, boolean_t); 7820Sstevel@tonic-gate extern void if_sick(struct interface *, boolean_t); 7830Sstevel@tonic-gate extern void if_link(struct interface *, uint32_t); 7840Sstevel@tonic-gate extern struct interface *ifwithaddr(in_addr_t, boolean_t, boolean_t); 7850Sstevel@tonic-gate extern struct interface *ifwithindex(ulong_t, boolean_t); 7860Sstevel@tonic-gate extern struct interface *ifwithname(const char *); 7877738SRishi.Srivatsavai@Sun.COM extern struct physical_interface *phys_byname(const char *); 7887738SRishi.Srivatsavai@Sun.COM extern boolean_t addr_on_ifp(in_addr_t, struct interface *, 7897738SRishi.Srivatsavai@Sun.COM struct interface **); 7900Sstevel@tonic-gate extern struct interface *findremoteif(in_addr_t); 7910Sstevel@tonic-gate extern struct interface *findifaddr(in_addr_t); 7920Sstevel@tonic-gate extern struct interface *iflookup(in_addr_t); 7930Sstevel@tonic-gate extern struct auth *find_auth(struct interface *); 7940Sstevel@tonic-gate extern void end_md5_auth(struct ws_buf *, struct auth *); 7950Sstevel@tonic-gate extern void rip_mcast_on(struct interface *); 7960Sstevel@tonic-gate extern void rip_mcast_off(struct interface *); 7970Sstevel@tonic-gate extern void trace_dump(); 7985381Smeem extern int sendtoif(int, const void *, uint_t, uint_t, struct sockaddr_in *, 7995381Smeem uint_t); 8000Sstevel@tonic-gate 8010Sstevel@tonic-gate #ifdef __cplusplus 8020Sstevel@tonic-gate } 8030Sstevel@tonic-gate #endif 8040Sstevel@tonic-gate 8050Sstevel@tonic-gate #endif /* _DEFS_H */ 806