defs.h revision 190713
118316Swollman/* 218316Swollman * Copyright (c) 1983, 1988, 1993 318316Swollman * The Regents of the University of California. All rights reserved. 418316Swollman * 518316Swollman * Redistribution and use in source and binary forms, with or without 618316Swollman * modification, are permitted provided that the following conditions 718316Swollman * are met: 818316Swollman * 1. Redistributions of source code must retain the above copyright 918316Swollman * notice, this list of conditions and the following disclaimer. 1018316Swollman * 2. Redistributions in binary form must reproduce the above copyright 1118316Swollman * notice, this list of conditions and the following disclaimer in the 1218316Swollman * documentation and/or other materials provided with the distribution. 1318316Swollman * 4. Neither the name of the University nor the names of its contributors 1418316Swollman * may be used to endorse or promote products derived from this software 1518316Swollman * without specific prior written permission. 1618316Swollman * 1718316Swollman * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 1818316Swollman * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1918316Swollman * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2018316Swollman * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2118316Swollman * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2218316Swollman * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2318316Swollman * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2418316Swollman * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2518316Swollman * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2618316Swollman * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2718316Swollman * SUCH DAMAGE. 2818316Swollman * 2918316Swollman * @(#)defs.h 8.1 (Berkeley) 6/5/93 3046303Smarkm * 3150476Speter * $FreeBSD: head/sbin/routed/defs.h 190713 2009-04-05 15:06:02Z phk $ 3218316Swollman */ 3318316Swollman 3446303Smarkm#ifdef sgi 3550969Speter#ident "$FreeBSD: head/sbin/routed/defs.h 190713 2009-04-05 15:06:02Z phk $" 3646303Smarkm#endif 3746303Smarkm 3818316Swollman/* Definitions for RIPv2 routing process. 3918316Swollman * 4018316Swollman * This code is based on the 4.4BSD `routed` daemon, with extensions to 4118316Swollman * support: 4218316Swollman * RIPv2, including variable length subnet masks. 4318316Swollman * Router Discovery 4418316Swollman * aggregate routes in the kernel tables. 4518316Swollman * aggregate advertised routes. 4618316Swollman * maintain spare routes for faster selection of another gateway 4718316Swollman * when the current gateway dies. 4818316Swollman * timers on routes with second granularity so that selection 4918316Swollman * of a new route does not wait 30-60 seconds. 5018316Swollman * tolerance of static routes. 5118316Swollman * tell the kernel hop counts 5218316Swollman * do not advertise if ipforwarding=0 5318316Swollman * 5437908Scharnier * The vestigial support for other protocols has been removed. There 5518316Swollman * is no likelihood that IETF RIPv1 or RIPv2 will ever be used with 5618316Swollman * other protocols. The result is far smaller, faster, cleaner, and 5718316Swollman * perhaps understandable. 5818316Swollman * 5918316Swollman * The accumulation of special flags and kludges added over the many 6018316Swollman * years have been simplified and integrated. 6118316Swollman */ 6218316Swollman 6318316Swollman#include <stdio.h> 6418316Swollman#include <netdb.h> 6518316Swollman#include <stdlib.h> 6618316Swollman#include <unistd.h> 6718316Swollman#include <errno.h> 6818316Swollman#include <string.h> 6918316Swollman#ifdef sgi 7018316Swollman#include <strings.h> 7118316Swollman#include <bstring.h> 7218316Swollman#endif 7318316Swollman#include <stdarg.h> 7418316Swollman#include <syslog.h> 7518316Swollman#include <time.h> 7646303Smarkm#include <sys/cdefs.h> 7746303Smarkm#include <sys/time.h> 7818316Swollman#include <sys/types.h> 7918316Swollman#include <sys/param.h> 8018316Swollman#include <sys/ioctl.h> 8118316Swollman#include <sys/sysctl.h> 8218316Swollman#include <sys/socket.h> 83190711Sphk#include <sys/queue.h> 8418316Swollman#ifdef sgi 8546303Smarkm#define _USER_ROUTE_TREE 8618316Swollman#include <net/radix.h> 8718316Swollman#else 8818316Swollman#include "radix.h" 8946303Smarkm#define UNUSED __attribute__((unused)) 9046303Smarkm#define PATTRIB(f,l) __attribute__((format (printf,f,l))) 9118316Swollman#endif 9218316Swollman#include <net/if.h> 9318316Swollman#include <net/route.h> 9418316Swollman#include <net/if_dl.h> 9518316Swollman#include <netinet/in.h> 9618316Swollman#include <arpa/inet.h> 9718316Swollman#define RIPVERSION RIPv2 9818316Swollman#include <protocols/routed.h> 9918316Swollman 100126250Sbms#ifndef __RCSID 101126250Sbms#define __RCSID(_s) static const char rcsid[] UNUSED = _s 102126250Sbms#endif 103126250Sbms#ifndef __COPYRIGHT 104126250Sbms#define __COPYRIGHT(_s) static const char copyright[] UNUSED = _s 105126250Sbms#endif 10618316Swollman 10718316Swollman/* Type of an IP address. 10818316Swollman * Some systems do not like to pass structures, so do not use in_addr. 10918316Swollman * Some systems think a long has 64 bits, which would be a gross waste. 11018316Swollman * So define it here so it can be changed for the target system. 11118316Swollman * It should be defined somewhere netinet/in.h, but it is not. 11218316Swollman */ 11318316Swollman#ifdef sgi 11418316Swollman#define naddr u_int32_t 11546303Smarkm#elif defined (__NetBSD__) 11646303Smarkm#define naddr u_int32_t 11746303Smarkm#define _HAVE_SA_LEN 11846303Smarkm#define _HAVE_SIN_LEN 11918316Swollman#else 12018316Swollman#define naddr u_long 12118316Swollman#define _HAVE_SA_LEN 12218316Swollman#define _HAVE_SIN_LEN 12318316Swollman#endif 12418316Swollman 12520342Swollman#define DAY (24*60*60) 12620342Swollman#define NEVER DAY /* a long time */ 12718316Swollman#define EPOCH NEVER /* bias time by this to avoid <0 */ 12818316Swollman 12918316Swollman/* Scan the kernel regularly to see if any interfaces have appeared or been 13018316Swollman * turned off. These must be less than STALE_TIME. 13118316Swollman */ 13218316Swollman#define CHECK_BAD_INTERVAL 5 /* when an interface is known bad */ 13318316Swollman#define CHECK_ACT_INTERVAL 30 /* when advertising */ 13418316Swollman#define CHECK_QUIET_INTERVAL 300 /* when not */ 13518316Swollman 13618316Swollman#define LIM_SEC(s,l) ((s).tv_sec = MIN((s).tv_sec, (l))) 13718316Swollman 13819885Swollman/* Metric used for fake default routes. It ought to be 15, but when 13919885Swollman * processing advertised routes, previous versions of `routed` added 14019885Swollman * to the received metric and discarded the route if the total was 16 14119885Swollman * or larger. 14219885Swollman */ 14319885Swollman#define FAKE_METRIC (HOPCNT_INFINITY-2) 14418316Swollman 14519885Swollman 14618316Swollman/* Router Discovery parameters */ 14718316Swollman#ifndef sgi 14818316Swollman#define INADDR_ALLROUTERS_GROUP 0xe0000002 /* 224.0.0.2 */ 14918316Swollman#endif 15018316Swollman#define MaxMaxAdvertiseInterval 1800 15118316Swollman#define MinMaxAdvertiseInterval 4 15218316Swollman#define DefMaxAdvertiseInterval 600 15318316Swollman#define DEF_PreferenceLevel 0 15418316Swollman#define MIN_PreferenceLevel 0x80000000 15518316Swollman 15618316Swollman#define MAX_INITIAL_ADVERT_INTERVAL 16 15718316Swollman#define MAX_INITIAL_ADVERTS 3 15818316Swollman#define MAX_RESPONSE_DELAY 2 15918316Swollman 16018316Swollman#define MAX_SOLICITATION_DELAY 1 16118316Swollman#define SOLICITATION_INTERVAL 3 16218316Swollman#define MAX_SOLICITATIONS 3 16318316Swollman 16418316Swollman 16519885Swollman/* Bloated packet size for systems that simply add authentication to 16619885Swollman * full-sized packets 16719885Swollman */ 16819885Swollman#define OVER_MAXPACKETSIZE (MAXPACKETSIZE+sizeof(struct netinfo)*2) 16918316Swollman/* typical packet buffers */ 17018316Swollmanunion pkt_buf { 17119885Swollman char packet[OVER_MAXPACKETSIZE*2]; 17218316Swollman struct rip rip; 17318316Swollman}; 17418316Swollman 17546303Smarkm#define GNAME_LEN 64 /* assumed=64 in parms.c */ 17646303Smarkm/* bigger than IFNAMSIZ, with room for "external()" or "remote()" */ 17746303Smarkm#define IF_NAME_LEN (GNAME_LEN+15) 17818316Swollman 17919885Swollman/* No more routes than this, to protect ourself in case something goes 18019885Swollman * whacko and starts broadcasting zillions of bogus routes. 18118316Swollman */ 18218316Swollman#define MAX_ROUTES (128*1024) 18318316Swollmanextern int total_routes; 18418316Swollman 18518316Swollman/* Main, daemon routing table structure 18618316Swollman */ 18718316Swollmanstruct rt_entry { 18818316Swollman struct radix_node rt_nodes[2]; /* radix tree glue */ 18918316Swollman u_int rt_state; 19018316Swollman# define RS_IF 0x001 /* for network interface */ 19118316Swollman# define RS_NET_INT 0x002 /* authority route */ 19218316Swollman# define RS_NET_SYN 0x004 /* fake net route for subnet */ 19318316Swollman# define RS_NO_NET_SYN (RS_LOCAL | RS_LOCAL | RS_IF) 19418316Swollman# define RS_SUBNET 0x008 /* subnet route from any source */ 19518316Swollman# define RS_LOCAL 0x010 /* loopback for pt-to-pt */ 19618316Swollman# define RS_MHOME 0x020 /* from -m */ 19718316Swollman# define RS_STATIC 0x040 /* from the kernel */ 19818316Swollman# define RS_RDISC 0x080 /* from router discovery */ 19918316Swollman struct sockaddr_in rt_dst_sock; 20018316Swollman naddr rt_mask; 20118316Swollman struct rt_spare { 20218316Swollman struct interface *rts_ifp; 20318316Swollman naddr rts_gate; /* forward packets here */ 20418316Swollman naddr rts_router; /* on the authority of this router */ 20518316Swollman char rts_metric; 20618316Swollman u_short rts_tag; 20718316Swollman time_t rts_time; /* timer to junk stale routes */ 20846303Smarkm u_int rts_de_ag; /* de-aggregation level */ 20918316Swollman#define NUM_SPARES 4 21018316Swollman } rt_spares[NUM_SPARES]; 21118316Swollman u_int rt_seqno; /* when last changed */ 21218316Swollman char rt_poison_metric; /* to notice maximum recently */ 21318316Swollman time_t rt_poison_time; /* advertised metric */ 21418316Swollman}; 21546303Smarkm#define rt_dst rt_dst_sock.sin_addr.s_addr 21646303Smarkm#define rt_ifp rt_spares[0].rts_ifp 21746303Smarkm#define rt_gate rt_spares[0].rts_gate 21846303Smarkm#define rt_router rt_spares[0].rts_router 21946303Smarkm#define rt_metric rt_spares[0].rts_metric 22046303Smarkm#define rt_tag rt_spares[0].rts_tag 22146303Smarkm#define rt_time rt_spares[0].rts_time 22246303Smarkm#define rt_de_ag rt_spares[0].rts_de_ag 22318316Swollman 22418316Swollman#define HOST_MASK 0xffffffff 22518316Swollman#define RT_ISHOST(rt) ((rt)->rt_mask == HOST_MASK) 22618316Swollman 22718316Swollman/* age all routes that 22818316Swollman * are not from -g, -m, or static routes from the kernel 22918316Swollman * not unbroken interface routes 23018316Swollman * but not broken interfaces 23118316Swollman * nor non-passive, remote interfaces that are not aliases 23218316Swollman * (i.e. remote & metric=0) 23318316Swollman */ 23418316Swollman#define AGE_RT(rt_state,ifp) (0 == ((rt_state) & (RS_MHOME | RS_STATIC \ 23518316Swollman | RS_NET_SYN | RS_RDISC)) \ 23618316Swollman && (!((rt_state) & RS_IF) \ 23718316Swollman || (ifp) == 0 \ 23818316Swollman || (((ifp)->int_state & IS_REMOTE) \ 23918316Swollman && !((ifp)->int_state & IS_PASSIVE)))) 24018316Swollman 24118316Swollman/* true if A is better than B 24218316Swollman * Better if 24318316Swollman * - A is not a poisoned route 24418316Swollman * - and A is not stale 24518316Swollman * - and A has a shorter path 24618316Swollman * - or is the router speaking for itself 24718316Swollman * - or the current route is equal but stale 24818316Swollman * - or it is a host route advertised by a system for itself 24918316Swollman */ 25046303Smarkm#define BETTER_LINK(rt,A,B) ((A)->rts_metric < HOPCNT_INFINITY \ 25118316Swollman && now_stale <= (A)->rts_time \ 25218316Swollman && ((A)->rts_metric < (B)->rts_metric \ 25318316Swollman || ((A)->rts_gate == (A)->rts_router \ 25418316Swollman && (B)->rts_gate != (B)->rts_router) \ 25518316Swollman || ((A)->rts_metric == (B)->rts_metric \ 25618316Swollman && now_stale > (B)->rts_time) \ 25718316Swollman || (RT_ISHOST(rt) \ 25818316Swollman && (rt)->rt_dst == (A)->rts_router \ 25918316Swollman && (A)->rts_metric == (B)->rts_metric))) 26018316Swollman 26118316Swollman 26218316Swollman/* An "interface" is similar to a kernel ifnet structure, except it also 26318316Swollman * handles "logical" or "IS_REMOTE" interfaces (remote gateways). 26418316Swollman */ 26518316Swollmanstruct interface { 266190711Sphk LIST_ENTRY(interface) int_list; 267190713Sphk LIST_ENTRY(interface) remote_list; 26819885Swollman struct interface *int_ahash, **int_ahash_prev; 26919885Swollman struct interface *int_bhash, **int_bhash_prev; 27019885Swollman struct interface *int_nhash, **int_nhash_prev; 27146303Smarkm char int_name[IF_NAME_LEN+1]; 27218316Swollman u_short int_index; 27318316Swollman naddr int_addr; /* address on this host (net order) */ 27418316Swollman naddr int_brdaddr; /* broadcast address (n) */ 27518316Swollman naddr int_dstaddr; /* other end of pt-to-pt link (n) */ 27618316Swollman naddr int_net; /* working network # (host order)*/ 27718316Swollman naddr int_mask; /* working net mask (host order) */ 27818316Swollman naddr int_ripv1_mask; /* for inferring a mask (n) */ 27918316Swollman naddr int_std_addr; /* class A/B/C address (n) */ 28018316Swollman naddr int_std_net; /* class A/B/C network (h) */ 28118316Swollman naddr int_std_mask; /* class A/B/C netmask (h) */ 28218316Swollman int int_rip_sock; /* for queries */ 28318316Swollman int int_if_flags; /* some bits copied from kernel */ 28418316Swollman u_int int_state; 28518316Swollman time_t int_act_time; /* last thought healthy */ 28619885Swollman time_t int_query_time; 28718316Swollman u_short int_transitions; /* times gone up-down */ 28818316Swollman char int_metric; 289126250Sbms u_char int_d_metric; /* for faked default route */ 290126250Sbms u_char int_adj_inmetric; /* adjust advertised metrics */ 291126250Sbms u_char int_adj_outmetric; /* instead of interface metric */ 29218316Swollman struct int_data { 29318316Swollman u_int ipackets; /* previous network stats */ 29418316Swollman u_int ierrors; 29518316Swollman u_int opackets; 29618316Swollman u_int oerrors; 29718316Swollman#ifdef sgi 29818316Swollman u_int odrops; 29918316Swollman#endif 30018316Swollman time_t ts; /* timestamp on network stats */ 30118316Swollman } int_data; 30220342Swollman# define MAX_AUTH_KEYS 5 30319885Swollman struct auth { /* authentication info */ 30446303Smarkm u_int16_t type; 30546303Smarkm u_char key[RIP_AUTH_PW_LEN]; 30620342Swollman u_char keyid; 30720342Swollman time_t start, end; 30820342Swollman } int_auth[MAX_AUTH_KEYS]; 30946303Smarkm /* router discovery parameters */ 31046303Smarkm int int_rdisc_pref; /* signed preference to advertise */ 31118316Swollman int int_rdisc_int; /* MaxAdvertiseInterval */ 31218316Swollman int int_rdisc_cnt; 31318316Swollman struct timeval int_rdisc_timer; 31418316Swollman}; 31518316Swollman 31618316Swollman/* bits in int_state */ 31718316Swollman#define IS_ALIAS 0x0000001 /* interface alias */ 31818316Swollman#define IS_SUBNET 0x0000002 /* interface on subnetted network */ 31918316Swollman#define IS_REMOTE 0x0000004 /* interface is not on this machine */ 32018316Swollman#define IS_PASSIVE 0x0000008 /* remote and does not do RIP */ 32118316Swollman#define IS_EXTERNAL 0x0000010 /* handled by EGP or something */ 32218316Swollman#define IS_CHECKED 0x0000020 /* still exists */ 32318316Swollman#define IS_ALL_HOSTS 0x0000040 /* in INADDR_ALLHOSTS_GROUP */ 32418316Swollman#define IS_ALL_ROUTERS 0x0000080 /* in INADDR_ALLROUTERS_GROUP */ 32519885Swollman#define IS_DISTRUST 0x0000100 /* ignore untrusted routers */ 32620342Swollman#define IS_REDIRECT_OK 0x0000200 /* accept ICMP redirects */ 32720342Swollman#define IS_BROKE 0x0000400 /* seems to be broken */ 32820342Swollman#define IS_SICK 0x0000800 /* seems to be broken */ 32920342Swollman#define IS_DUP 0x0001000 /* has a duplicate address */ 33018316Swollman#define IS_NEED_NET_SYN 0x0002000 /* need RS_NET_SYN route */ 33118316Swollman#define IS_NO_AG 0x0004000 /* do not aggregate subnets */ 33218316Swollman#define IS_NO_SUPER_AG 0x0008000 /* do not aggregate networks */ 33318316Swollman#define IS_NO_RIPV1_IN 0x0010000 /* no RIPv1 input at all */ 33418316Swollman#define IS_NO_RIPV2_IN 0x0020000 /* no RIPv2 input at all */ 33518316Swollman#define IS_NO_RIP_IN (IS_NO_RIPV1_IN | IS_NO_RIPV2_IN) 33618316Swollman#define IS_RIP_IN_OFF(s) (((s) & IS_NO_RIP_IN) == IS_NO_RIP_IN) 33718316Swollman#define IS_NO_RIPV1_OUT 0x0040000 /* no RIPv1 output at all */ 33818316Swollman#define IS_NO_RIPV2_OUT 0x0080000 /* no RIPv2 output at all */ 33918316Swollman#define IS_NO_RIP_OUT (IS_NO_RIPV1_OUT | IS_NO_RIPV2_OUT) 34018316Swollman#define IS_NO_RIP (IS_NO_RIP_OUT | IS_NO_RIP_IN) 34118316Swollman#define IS_RIP_OUT_OFF(s) (((s) & IS_NO_RIP_OUT) == IS_NO_RIP_OUT) 34218316Swollman#define IS_RIP_OFF(s) (((s) & IS_NO_RIP) == IS_NO_RIP) 34346303Smarkm#define IS_NO_RIP_MCAST 0x0100000 /* broadcast RIPv2 */ 34446303Smarkm#define IS_NO_ADV_IN 0x0200000 /* do not listen to advertisements */ 34546303Smarkm#define IS_NO_SOL_OUT 0x0400000 /* send no solicitations */ 34646303Smarkm#define IS_SOL_OUT 0x0800000 /* send solicitations */ 34746303Smarkm#define GROUP_IS_SOL_OUT (IS_SOL_OUT | IS_NO_SOL_OUT) 34846303Smarkm#define IS_NO_ADV_OUT 0x1000000 /* do not advertise rdisc */ 34946303Smarkm#define IS_ADV_OUT 0x2000000 /* advertise rdisc */ 35046303Smarkm#define GROUP_IS_ADV_OUT (IS_NO_ADV_OUT | IS_ADV_OUT) 35146303Smarkm#define IS_BCAST_RDISC 0x4000000 /* broadcast instead of multicast */ 35218316Swollman#define IS_NO_RDISC (IS_NO_ADV_IN | IS_NO_SOL_OUT | IS_NO_ADV_OUT) 35346303Smarkm#define IS_PM_RDISC 0x8000000 /* poor-man's router discovery */ 35418316Swollman 35546303Smarkm#define iff_up(f) ((f) & IFF_UP) 35618316Swollman 357190711SphkLIST_HEAD(ifhead, interface); 35818316Swollman 35918316Swollman/* Information for aggregating routes */ 36018316Swollman#define NUM_AG_SLOTS 32 36118316Swollmanstruct ag_info { 36218316Swollman struct ag_info *ag_fine; /* slot with finer netmask */ 36318316Swollman struct ag_info *ag_cors; /* more coarse netmask */ 36418316Swollman naddr ag_dst_h; /* destination in host byte order */ 36518316Swollman naddr ag_mask; 36618316Swollman naddr ag_gate; 36718316Swollman naddr ag_nhop; 36818316Swollman char ag_metric; /* metric to be advertised */ 36918316Swollman char ag_pref; /* aggregate based on this */ 37018316Swollman u_int ag_seqno; 37118316Swollman u_short ag_tag; 37218316Swollman u_short ag_state; 37337908Scharnier#define AGS_SUPPRESS 0x001 /* combine with coarser mask */ 37446303Smarkm#define AGS_AGGREGATE 0x002 /* synthesize combined routes */ 37518316Swollman#define AGS_REDUN0 0x004 /* redundant, finer routes output */ 37618316Swollman#define AGS_REDUN1 0x008 37718316Swollman#define AG_IS_REDUN(state) (((state) & (AGS_REDUN0 | AGS_REDUN1)) \ 37818316Swollman == (AGS_REDUN0 | AGS_REDUN1)) 37918316Swollman#define AGS_GATEWAY 0x010 /* tell kernel RTF_GATEWAY */ 38018316Swollman#define AGS_IF 0x020 /* for an interface */ 38118316Swollman#define AGS_RIPV2 0x040 /* send only as RIPv2 */ 38218316Swollman#define AGS_FINE_GATE 0x080 /* ignore differing ag_gate when this 38318316Swollman * has the finer netmask */ 38418316Swollman#define AGS_CORS_GATE 0x100 /* ignore differing gate when this 38537908Scharnier * has the coarser netmasks */ 38618316Swollman#define AGS_SPLIT_HZ 0x200 /* suppress for split horizon */ 38718316Swollman 38818316Swollman /* some bits are set if they are set on either route */ 38946303Smarkm#define AGS_AGGREGATE_EITHER (AGS_RIPV2 | AGS_GATEWAY | \ 39046303Smarkm AGS_SUPPRESS | AGS_CORS_GATE) 39118316Swollman}; 39218316Swollman 39318316Swollman 39418316Swollman/* parameters for interfaces */ 39518316Swollmanextern struct parm { 39618316Swollman struct parm *parm_next; 39746303Smarkm char parm_name[IF_NAME_LEN+1]; 39819885Swollman naddr parm_net; 39918316Swollman naddr parm_mask; 40018316Swollman 401126250Sbms u_char parm_d_metric; 402126250Sbms u_char parm_adj_inmetric; 403126250Sbms char parm_adj_outmetric; 40418316Swollman u_int parm_int_state; 40546303Smarkm int parm_rdisc_pref; /* signed IRDP preference */ 40646303Smarkm int parm_rdisc_int; /* IRDP advertising interval */ 40720342Swollman struct auth parm_auth[MAX_AUTH_KEYS]; 40818316Swollman} *parms; 40918316Swollman 41018316Swollman/* authority for internal networks */ 41118316Swollmanextern struct intnet { 41218316Swollman struct intnet *intnet_next; 41346303Smarkm naddr intnet_addr; /* network byte order */ 41418316Swollman naddr intnet_mask; 41518316Swollman char intnet_metric; 41618316Swollman} *intnets; 41718316Swollman 41846303Smarkm/* defined RIPv1 netmasks */ 41946303Smarkmextern struct r1net { 42046303Smarkm struct r1net *r1net_next; 42146303Smarkm naddr r1net_net; /* host order */ 42246303Smarkm naddr r1net_match; 42346303Smarkm naddr r1net_mask; 42446303Smarkm} *r1nets; 42546303Smarkm 42619885Swollman/* trusted routers */ 42719885Swollmanextern struct tgate { 42819885Swollman struct tgate *tgate_next; 42919885Swollman naddr tgate_addr; 43046303Smarkm#define MAX_TGATE_NETS 32 43146303Smarkm struct tgate_net { 43246303Smarkm naddr net; /* host order */ 43346303Smarkm naddr mask; 43446303Smarkm } tgate_nets[MAX_TGATE_NETS]; 43519885Swollman} *tgates; 43618316Swollman 43719885Swollmanenum output_type {OUT_QUERY, OUT_UNICAST, OUT_BROADCAST, OUT_MULTICAST, 43819885Swollman NO_OUT_MULTICAST, NO_OUT_RIPV2}; 43918316Swollman 44019885Swollman/* common output buffers */ 44119885Swollmanextern struct ws_buf { 44219885Swollman struct rip *buf; 44319885Swollman struct netinfo *n; 44419885Swollman struct netinfo *base; 44519885Swollman struct netinfo *lim; 44619885Swollman enum output_type type; 44719885Swollman} v12buf, v2buf; 44819885Swollman 44918316Swollmanextern pid_t mypid; 45018316Swollmanextern naddr myaddr; /* main address of this system */ 45118316Swollman 45218316Swollmanextern int stopint; /* !=0 to stop */ 45318316Swollman 45418316Swollmanextern int sock_max; 45518316Swollmanextern int rip_sock; /* RIP socket */ 45618316Swollmanextern struct interface *rip_sock_mcast; /* current multicast interface */ 45718316Swollmanextern int rt_sock; /* routing socket */ 45818316Swollmanextern int rt_sock_seqno; 45918316Swollmanextern int rdisc_sock; /* router-discovery raw socket */ 46018316Swollman 46118316Swollmanextern int seqno; /* sequence number for messages */ 46218316Swollmanextern int supplier; /* process should supply updates */ 46346303Smarkmextern int supplier_set; /* -s or -q requested */ 46418316Swollmanextern int lookforinterfaces; /* 1=probe for new up interfaces */ 46518316Swollmanextern int ridhosts; /* 1=reduce host routes */ 46618316Swollmanextern int mhome; /* 1=want multi-homed host route */ 46737908Scharnierextern int advertise_mhome; /* 1=must continue advertising it */ 46818316Swollmanextern int auth_ok; /* 1=ignore auth if we do not care */ 46918316Swollman 47019885Swollmanextern struct timeval clk; /* system clock's idea of time */ 47119885Swollmanextern struct timeval epoch; /* system clock when started */ 47218316Swollmanextern struct timeval now; /* current idea of time */ 47318316Swollmanextern time_t now_stale; 47418316Swollmanextern time_t now_expire; 47518316Swollmanextern time_t now_garbage; 47618316Swollman 47718316Swollmanextern struct timeval next_bcast; /* next general broadcast */ 47818316Swollmanextern struct timeval age_timer; /* next check of old routes */ 47918316Swollmanextern struct timeval no_flash; /* inhibit flash update until then */ 48018316Swollmanextern struct timeval rdisc_timer; /* next advert. or solicitation */ 48118316Swollmanextern int rdisc_ok; /* using solicited route */ 48218316Swollman 48318316Swollmanextern struct timeval ifinit_timer; /* time to check interfaces */ 48418316Swollman 48518316Swollmanextern naddr loopaddr; /* our address on loopback */ 48618316Swollmanextern int tot_interfaces; /* # of remote and local interfaces */ 48718316Swollmanextern int rip_interfaces; /* # of interfaces doing RIP */ 488190711Sphkextern struct ifhead ifnet; /* all interfaces */ 489190713Sphkextern struct ifhead remote_if; /* remote interfaces */ 49018316Swollmanextern int have_ripv1_out; /* have a RIPv1 interface */ 49118316Swollmanextern int have_ripv1_in; 49218316Swollmanextern int need_flash; /* flash update needed */ 49318316Swollmanextern struct timeval need_kern; /* need to update kernel table */ 49446303Smarkmextern u_int update_seqno; /* a route has changed */ 49518316Swollman 49620342Swollmanextern int tracelevel, new_tracelevel; 49718316Swollman#define MAX_TRACELEVEL 4 49818316Swollman#define TRACEKERNEL (tracelevel >= 4) /* log kernel changes */ 49918316Swollman#define TRACECONTENTS (tracelevel >= 3) /* display packet contents */ 50018316Swollman#define TRACEPACKETS (tracelevel >= 2) /* note packets */ 50118316Swollman#define TRACEACTIONS (tracelevel != 0) 50218316Swollmanextern FILE *ftrace; /* output trace file */ 503118582Simpextern char inittracename[PATH_MAX]; 50418316Swollman 50518316Swollmanextern struct radix_node_head *rhead; 50618316Swollman 50718316Swollman 50818316Swollman#ifdef sgi 50918316Swollman/* Fix conflicts */ 51018316Swollman#define dup2(x,y) BSDdup2(x,y) 51118316Swollman#endif /* sgi */ 51218316Swollman 51346303Smarkmextern void fix_sock(int, const char *); 51418316Swollmanextern void fix_select(void); 51518316Swollmanextern void rip_off(void); 51618316Swollmanextern void rip_on(struct interface *); 51718316Swollman 51819885Swollmanextern void bufinit(void); 51919885Swollmanextern int output(enum output_type, struct sockaddr_in *, 52019885Swollman struct interface *, struct rip *, int); 52120342Swollmanextern void clr_ws_buf(struct ws_buf *, struct auth *); 52218316Swollmanextern void rip_query(void); 52318316Swollmanextern void rip_bcast(int); 52418316Swollmanextern void supply(struct sockaddr_in *, struct interface *, 52519885Swollman enum output_type, int, int, int); 52618316Swollman 52746303Smarkmextern void msglog(const char *, ...) PATTRIB(1,2); 52819885Swollmanstruct msg_limit { 52920342Swollman time_t reuse; 53020342Swollman struct msg_sub { 53119885Swollman naddr addr; 53219885Swollman time_t until; 53320342Swollman# define MSG_SUBJECT_N 8 53420342Swollman } subs[MSG_SUBJECT_N]; 53519885Swollman}; 53646303Smarkmextern void msglim(struct msg_limit *, naddr, 53746303Smarkm const char *, ...) PATTRIB(3,4); 53818316Swollman#define LOGERR(msg) msglog(msg ": %s", strerror(errno)) 53946303Smarkmextern void logbad(int, const char *, ...) PATTRIB(2,3); 54018316Swollman#define BADERR(dump,msg) logbad(dump,msg ": %s", strerror(errno)) 54118316Swollman#ifdef DEBUG 54218316Swollman#define DBGERR(dump,msg) BADERR(dump,msg) 54318316Swollman#else 54418316Swollman#define DBGERR(dump,msg) LOGERR(msg) 54518316Swollman#endif 54618316Swollmanextern char *naddr_ntoa(naddr); 54746303Smarkmextern const char *saddr_ntoa(struct sockaddr *); 54818316Swollman 54946303Smarkmextern void *rtmalloc(size_t, const char *); 55018316Swollmanextern void timevaladd(struct timeval *, struct timeval *); 55118316Swollmanextern void intvl_random(struct timeval *, u_long, u_long); 55218316Swollmanextern int getnet(char *, naddr *, naddr *); 55318316Swollmanextern int gethost(char *, naddr *); 55418316Swollmanextern void gwkludge(void); 55546303Smarkmextern const char *parse_parms(char *, int); 55646303Smarkmextern const char *check_parms(struct parm *); 55718316Swollmanextern void get_parms(struct interface *); 55818316Swollman 55918316Swollmanextern void lastlog(void); 56046303Smarkmextern void trace_close(int); 56146303Smarkmextern void set_tracefile(const char *, const char *, int); 56246303Smarkmextern void tracelevel_msg(const char *, int); 56346303Smarkmextern void trace_off(const char*, ...) PATTRIB(1,2); 56420342Swollmanextern void set_tracelevel(void); 56518316Swollmanextern void trace_flush(void); 56646303Smarkmextern void trace_misc(const char *, ...) PATTRIB(1,2); 56746303Smarkmextern void trace_act(const char *, ...) PATTRIB(1,2); 56846303Smarkmextern void trace_pkt(const char *, ...) PATTRIB(1,2); 56946303Smarkmextern void trace_add_del(const char *, struct rt_entry *); 57046303Smarkmextern void trace_change(struct rt_entry *, u_int, struct rt_spare *, 57146303Smarkm const char *); 57246303Smarkmextern void trace_if(const char *, struct interface *); 57318316Swollmanextern void trace_upslot(struct rt_entry *, struct rt_spare *, 57446303Smarkm struct rt_spare *); 57546303Smarkmextern void trace_rip(const char*, const char*, struct sockaddr_in *, 57618316Swollman struct interface *, struct rip *, int); 57718316Swollmanextern char *addrname(naddr, naddr, int); 57846303Smarkmextern char *rtname(naddr, naddr, naddr); 57918316Swollman 58018316Swollmanextern void rdisc_age(naddr); 58118316Swollmanextern void set_rdisc_mg(struct interface *, int); 58218316Swollmanextern void set_supplier(void); 58318316Swollmanextern void if_bad_rdisc(struct interface *); 58418316Swollmanextern void if_ok_rdisc(struct interface *); 58518316Swollmanextern void read_rip(int, struct interface *); 58618316Swollmanextern void read_rt(void); 58718316Swollmanextern void read_d(void); 58818316Swollmanextern void rdisc_adv(void); 58918316Swollmanextern void rdisc_sol(void); 59018316Swollman 59118316Swollmanextern void sigalrm(int); 59218316Swollmanextern void sigterm(int); 59318316Swollman 59418316Swollmanextern void sigtrace_on(int); 59518316Swollmanextern void sigtrace_off(int); 59618316Swollman 59718316Swollmanextern void flush_kern(void); 59818316Swollmanextern void age(naddr); 59918316Swollman 60018316Swollmanextern void ag_flush(naddr, naddr, void (*)(struct ag_info *)); 60118316Swollmanextern void ag_check(naddr, naddr, naddr, naddr, char, char, u_int, 60218316Swollman u_short, u_short, void (*)(struct ag_info *)); 60346303Smarkmextern void del_static(naddr, naddr, naddr, int); 60418316Swollmanextern void del_redirects(naddr, time_t); 60518316Swollmanextern struct rt_entry *rtget(naddr, naddr); 60618316Swollmanextern struct rt_entry *rtfind(naddr); 60718316Swollmanextern void rtinit(void); 60846303Smarkmextern void rtadd(naddr, naddr, u_int, struct rt_spare *); 60946303Smarkmextern void rtchange(struct rt_entry *, u_int, struct rt_spare *, char *); 61018316Swollmanextern void rtdelete(struct rt_entry *); 61146303Smarkmextern void rts_delete(struct rt_entry *, struct rt_spare *); 61218316Swollmanextern void rtbad_sub(struct rt_entry *); 61318316Swollmanextern void rtswitch(struct rt_entry *, struct rt_spare *); 61418316Swollmanextern void rtbad(struct rt_entry *); 61518316Swollman 61618316Swollman#define S_ADDR(x) (((struct sockaddr_in *)(x))->sin_addr.s_addr) 61718316Swollman#define INFO_DST(I) ((I)->rti_info[RTAX_DST]) 61818316Swollman#define INFO_GATE(I) ((I)->rti_info[RTAX_GATEWAY]) 61918316Swollman#define INFO_MASK(I) ((I)->rti_info[RTAX_NETMASK]) 62018316Swollman#define INFO_IFA(I) ((I)->rti_info[RTAX_IFA]) 62118316Swollman#define INFO_IFP(I) ((I)->rti_info[RTAX_IFP]) 62218316Swollman#define INFO_AUTHOR(I) ((I)->rti_info[RTAX_AUTHOR]) 62318316Swollman#define INFO_BRD(I) ((I)->rti_info[RTAX_BRD]) 62418316Swollmanvoid rt_xaddrs(struct rt_addrinfo *, struct sockaddr *, struct sockaddr *, 62518316Swollman int); 62618316Swollman 62718316Swollmanextern naddr std_mask(naddr); 62818316Swollmanextern naddr ripv1_mask_net(naddr, struct interface *); 62918316Swollmanextern naddr ripv1_mask_host(naddr,struct interface *); 63018316Swollman#define on_net(a,net,mask) (((ntohl(a) ^ (net)) & (mask)) == 0) 63118316Swollmanextern int check_dst(naddr); 63219885Swollmanextern struct interface *check_dup(naddr, naddr, naddr, int); 63319885Swollmanextern int check_remote(struct interface *); 63446303Smarkmextern int addrouteforif(struct interface *); 63518316Swollmanextern void ifinit(void); 63618316Swollmanextern int walk_bad(struct radix_node *, struct walkarg *); 63746303Smarkmextern int if_ok(struct interface *, const char *); 63818316Swollmanextern void if_sick(struct interface *); 63918316Swollmanextern void if_bad(struct interface *); 64019885Swollmanextern void if_link(struct interface *); 64118316Swollmanextern struct interface *ifwithaddr(naddr, int, int); 64218316Swollmanextern struct interface *ifwithname(char *, naddr); 64346303Smarkmextern struct interface *ifwithindex(u_short, int); 64418316Swollmanextern struct interface *iflookup(naddr); 64519885Swollman 64620342Swollmanextern struct auth *find_auth(struct interface *); 64720342Swollmanextern void end_md5_auth(struct ws_buf *, struct auth *); 64819885Swollman 649126250Sbms#if defined(__FreeBSD__) || defined(__NetBSD__) 650126250Sbms#include <md5.h> 651126250Sbms#else 65246303Smarkm#define MD5_DIGEST_LEN 16 65346303Smarkmtypedef struct { 65446303Smarkm u_int32_t state[4]; /* state (ABCD) */ 65546303Smarkm u_int32_t count[2]; /* # of bits, modulo 2^64 (LSB 1st) */ 65646303Smarkm unsigned char buffer[64]; /* input buffer */ 65746303Smarkm} MD5_CTX; 65846303Smarkmextern void MD5Init(MD5_CTX*); 65946303Smarkmextern void MD5Update(MD5_CTX*, u_char*, u_int); 66046303Smarkmextern void MD5Final(u_char[MD5_DIGEST_LEN], MD5_CTX*); 661126250Sbms#endif 662