defs.h revision 118582
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 * 3. All advertising materials mentioning features or use of this software 1446303Smarkm * must display the following acknowledgment: 1518316Swollman * This product includes software developed by the University of 1618316Swollman * California, Berkeley and its contributors. 1718316Swollman * 4. Neither the name of the University nor the names of its contributors 1818316Swollman * may be used to endorse or promote products derived from this software 1918316Swollman * without specific prior written permission. 2018316Swollman * 2118316Swollman * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2218316Swollman * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2318316Swollman * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2418316Swollman * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2518316Swollman * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2618316Swollman * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2718316Swollman * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2818316Swollman * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2918316Swollman * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3018316Swollman * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3118316Swollman * SUCH DAMAGE. 3218316Swollman * 3318316Swollman * @(#)defs.h 8.1 (Berkeley) 6/5/93 3446303Smarkm * 3550476Speter * $FreeBSD: head/sbin/routed/defs.h 118582 2003-08-07 05:38:56Z imp $ 3618316Swollman */ 3718316Swollman 3846303Smarkm#ifdef sgi 3950969Speter#ident "$FreeBSD: head/sbin/routed/defs.h 118582 2003-08-07 05:38:56Z imp $" 4046303Smarkm#endif 4146303Smarkm 4218316Swollman/* Definitions for RIPv2 routing process. 4318316Swollman * 4418316Swollman * This code is based on the 4.4BSD `routed` daemon, with extensions to 4518316Swollman * support: 4618316Swollman * RIPv2, including variable length subnet masks. 4718316Swollman * Router Discovery 4818316Swollman * aggregate routes in the kernel tables. 4918316Swollman * aggregate advertised routes. 5018316Swollman * maintain spare routes for faster selection of another gateway 5118316Swollman * when the current gateway dies. 5218316Swollman * timers on routes with second granularity so that selection 5318316Swollman * of a new route does not wait 30-60 seconds. 5418316Swollman * tolerance of static routes. 5518316Swollman * tell the kernel hop counts 5618316Swollman * do not advertise if ipforwarding=0 5718316Swollman * 5837908Scharnier * The vestigial support for other protocols has been removed. There 5918316Swollman * is no likelihood that IETF RIPv1 or RIPv2 will ever be used with 6018316Swollman * other protocols. The result is far smaller, faster, cleaner, and 6118316Swollman * perhaps understandable. 6218316Swollman * 6318316Swollman * The accumulation of special flags and kludges added over the many 6418316Swollman * years have been simplified and integrated. 6518316Swollman */ 6618316Swollman 6718316Swollman#include <stdio.h> 6818316Swollman#include <netdb.h> 6918316Swollman#include <stdlib.h> 7018316Swollman#include <unistd.h> 7118316Swollman#include <errno.h> 7218316Swollman#include <string.h> 7318316Swollman#ifdef sgi 7418316Swollman#include <strings.h> 7518316Swollman#include <bstring.h> 7618316Swollman#endif 7718316Swollman#include <stdarg.h> 7818316Swollman#include <syslog.h> 7918316Swollman#include <time.h> 8046303Smarkm#include <sys/cdefs.h> 8146303Smarkm#include <sys/time.h> 8218316Swollman#include <sys/types.h> 8318316Swollman#include <sys/param.h> 8418316Swollman#include <sys/ioctl.h> 8518316Swollman#include <sys/sysctl.h> 8618316Swollman#include <sys/socket.h> 8718316Swollman#ifdef sgi 8846303Smarkm#define _USER_ROUTE_TREE 8918316Swollman#include <net/radix.h> 9018316Swollman#else 9118316Swollman#include "radix.h" 9246303Smarkm#define UNUSED __attribute__((unused)) 9346303Smarkm#define PATTRIB(f,l) __attribute__((format (printf,f,l))) 9418316Swollman#endif 9518316Swollman#include <net/if.h> 9618316Swollman#include <net/route.h> 9718316Swollman#include <net/if_dl.h> 9818316Swollman#include <netinet/in.h> 9918316Swollman#include <arpa/inet.h> 10018316Swollman#define RIPVERSION RIPv2 10118316Swollman#include <protocols/routed.h> 10218316Swollman 10318316Swollman 10418316Swollman/* Type of an IP address. 10518316Swollman * Some systems do not like to pass structures, so do not use in_addr. 10618316Swollman * Some systems think a long has 64 bits, which would be a gross waste. 10718316Swollman * So define it here so it can be changed for the target system. 10818316Swollman * It should be defined somewhere netinet/in.h, but it is not. 10918316Swollman */ 11018316Swollman#ifdef sgi 11118316Swollman#define naddr u_int32_t 11246303Smarkm#elif defined (__NetBSD__) 11346303Smarkm#define naddr u_int32_t 11446303Smarkm#define _HAVE_SA_LEN 11546303Smarkm#define _HAVE_SIN_LEN 11618316Swollman#else 11718316Swollman#define naddr u_long 11818316Swollman#define _HAVE_SA_LEN 11918316Swollman#define _HAVE_SIN_LEN 12018316Swollman#endif 12118316Swollman 12218316Swollman/* Turn on if IP_DROP_MEMBERSHIP and IP_ADD_MEMBERSHIP do not look at 12318316Swollman * the dstaddr of point-to-point interfaces. 12418316Swollman */ 12546303Smarkm#ifdef __NetBSD__ 12646303Smarkm#define MCAST_PPP_BUG 12746303Smarkm#endif 12818316Swollman 12920342Swollman#define DAY (24*60*60) 13020342Swollman#define NEVER DAY /* a long time */ 13118316Swollman#define EPOCH NEVER /* bias time by this to avoid <0 */ 13218316Swollman 13318316Swollman/* Scan the kernel regularly to see if any interfaces have appeared or been 13418316Swollman * turned off. These must be less than STALE_TIME. 13518316Swollman */ 13618316Swollman#define CHECK_BAD_INTERVAL 5 /* when an interface is known bad */ 13718316Swollman#define CHECK_ACT_INTERVAL 30 /* when advertising */ 13818316Swollman#define CHECK_QUIET_INTERVAL 300 /* when not */ 13918316Swollman 14018316Swollman#define LIM_SEC(s,l) ((s).tv_sec = MIN((s).tv_sec, (l))) 14118316Swollman 14219885Swollman/* Metric used for fake default routes. It ought to be 15, but when 14319885Swollman * processing advertised routes, previous versions of `routed` added 14419885Swollman * to the received metric and discarded the route if the total was 16 14519885Swollman * or larger. 14619885Swollman */ 14719885Swollman#define FAKE_METRIC (HOPCNT_INFINITY-2) 14818316Swollman 14919885Swollman 15018316Swollman/* Router Discovery parameters */ 15118316Swollman#ifndef sgi 15218316Swollman#define INADDR_ALLROUTERS_GROUP 0xe0000002 /* 224.0.0.2 */ 15318316Swollman#endif 15418316Swollman#define MaxMaxAdvertiseInterval 1800 15518316Swollman#define MinMaxAdvertiseInterval 4 15618316Swollman#define DefMaxAdvertiseInterval 600 15718316Swollman#define DEF_PreferenceLevel 0 15818316Swollman#define MIN_PreferenceLevel 0x80000000 15918316Swollman 16018316Swollman#define MAX_INITIAL_ADVERT_INTERVAL 16 16118316Swollman#define MAX_INITIAL_ADVERTS 3 16218316Swollman#define MAX_RESPONSE_DELAY 2 16318316Swollman 16418316Swollman#define MAX_SOLICITATION_DELAY 1 16518316Swollman#define SOLICITATION_INTERVAL 3 16618316Swollman#define MAX_SOLICITATIONS 3 16718316Swollman 16818316Swollman 16919885Swollman/* Bloated packet size for systems that simply add authentication to 17019885Swollman * full-sized packets 17119885Swollman */ 17219885Swollman#define OVER_MAXPACKETSIZE (MAXPACKETSIZE+sizeof(struct netinfo)*2) 17318316Swollman/* typical packet buffers */ 17418316Swollmanunion pkt_buf { 17519885Swollman char packet[OVER_MAXPACKETSIZE*2]; 17618316Swollman struct rip rip; 17718316Swollman}; 17818316Swollman 17946303Smarkm#define GNAME_LEN 64 /* assumed=64 in parms.c */ 18046303Smarkm/* bigger than IFNAMSIZ, with room for "external()" or "remote()" */ 18146303Smarkm#define IF_NAME_LEN (GNAME_LEN+15) 18218316Swollman 18319885Swollman/* No more routes than this, to protect ourself in case something goes 18419885Swollman * whacko and starts broadcasting zillions of bogus routes. 18518316Swollman */ 18618316Swollman#define MAX_ROUTES (128*1024) 18718316Swollmanextern int total_routes; 18818316Swollman 18918316Swollman/* Main, daemon routing table structure 19018316Swollman */ 19118316Swollmanstruct rt_entry { 19218316Swollman struct radix_node rt_nodes[2]; /* radix tree glue */ 19318316Swollman u_int rt_state; 19418316Swollman# define RS_IF 0x001 /* for network interface */ 19518316Swollman# define RS_NET_INT 0x002 /* authority route */ 19618316Swollman# define RS_NET_SYN 0x004 /* fake net route for subnet */ 19718316Swollman# define RS_NO_NET_SYN (RS_LOCAL | RS_LOCAL | RS_IF) 19818316Swollman# define RS_SUBNET 0x008 /* subnet route from any source */ 19918316Swollman# define RS_LOCAL 0x010 /* loopback for pt-to-pt */ 20018316Swollman# define RS_MHOME 0x020 /* from -m */ 20118316Swollman# define RS_STATIC 0x040 /* from the kernel */ 20218316Swollman# define RS_RDISC 0x080 /* from router discovery */ 20318316Swollman struct sockaddr_in rt_dst_sock; 20418316Swollman naddr rt_mask; 20518316Swollman struct rt_spare { 20618316Swollman struct interface *rts_ifp; 20718316Swollman naddr rts_gate; /* forward packets here */ 20818316Swollman naddr rts_router; /* on the authority of this router */ 20918316Swollman char rts_metric; 21018316Swollman u_short rts_tag; 21118316Swollman time_t rts_time; /* timer to junk stale routes */ 21246303Smarkm u_int rts_de_ag; /* de-aggregation level */ 21318316Swollman#define NUM_SPARES 4 21418316Swollman } rt_spares[NUM_SPARES]; 21518316Swollman u_int rt_seqno; /* when last changed */ 21618316Swollman char rt_poison_metric; /* to notice maximum recently */ 21718316Swollman time_t rt_poison_time; /* advertised metric */ 21818316Swollman}; 21946303Smarkm#define rt_dst rt_dst_sock.sin_addr.s_addr 22046303Smarkm#define rt_ifp rt_spares[0].rts_ifp 22146303Smarkm#define rt_gate rt_spares[0].rts_gate 22246303Smarkm#define rt_router rt_spares[0].rts_router 22346303Smarkm#define rt_metric rt_spares[0].rts_metric 22446303Smarkm#define rt_tag rt_spares[0].rts_tag 22546303Smarkm#define rt_time rt_spares[0].rts_time 22646303Smarkm#define rt_de_ag rt_spares[0].rts_de_ag 22718316Swollman 22818316Swollman#define HOST_MASK 0xffffffff 22918316Swollman#define RT_ISHOST(rt) ((rt)->rt_mask == HOST_MASK) 23018316Swollman 23118316Swollman/* age all routes that 23218316Swollman * are not from -g, -m, or static routes from the kernel 23318316Swollman * not unbroken interface routes 23418316Swollman * but not broken interfaces 23518316Swollman * nor non-passive, remote interfaces that are not aliases 23618316Swollman * (i.e. remote & metric=0) 23718316Swollman */ 23818316Swollman#define AGE_RT(rt_state,ifp) (0 == ((rt_state) & (RS_MHOME | RS_STATIC \ 23918316Swollman | RS_NET_SYN | RS_RDISC)) \ 24018316Swollman && (!((rt_state) & RS_IF) \ 24118316Swollman || (ifp) == 0 \ 24218316Swollman || (((ifp)->int_state & IS_REMOTE) \ 24318316Swollman && !((ifp)->int_state & IS_PASSIVE)))) 24418316Swollman 24518316Swollman/* true if A is better than B 24618316Swollman * Better if 24718316Swollman * - A is not a poisoned route 24818316Swollman * - and A is not stale 24918316Swollman * - and A has a shorter path 25018316Swollman * - or is the router speaking for itself 25118316Swollman * - or the current route is equal but stale 25218316Swollman * - or it is a host route advertised by a system for itself 25318316Swollman */ 25446303Smarkm#define BETTER_LINK(rt,A,B) ((A)->rts_metric < HOPCNT_INFINITY \ 25518316Swollman && now_stale <= (A)->rts_time \ 25618316Swollman && ((A)->rts_metric < (B)->rts_metric \ 25718316Swollman || ((A)->rts_gate == (A)->rts_router \ 25818316Swollman && (B)->rts_gate != (B)->rts_router) \ 25918316Swollman || ((A)->rts_metric == (B)->rts_metric \ 26018316Swollman && now_stale > (B)->rts_time) \ 26118316Swollman || (RT_ISHOST(rt) \ 26218316Swollman && (rt)->rt_dst == (A)->rts_router \ 26318316Swollman && (A)->rts_metric == (B)->rts_metric))) 26418316Swollman 26518316Swollman 26618316Swollman/* An "interface" is similar to a kernel ifnet structure, except it also 26718316Swollman * handles "logical" or "IS_REMOTE" interfaces (remote gateways). 26818316Swollman */ 26918316Swollmanstruct interface { 27019885Swollman struct interface *int_next, **int_prev; 27119885Swollman struct interface *int_ahash, **int_ahash_prev; 27219885Swollman struct interface *int_bhash, **int_bhash_prev; 27319885Swollman struct interface *int_rlink, **int_rlink_prev; 27419885Swollman struct interface *int_nhash, **int_nhash_prev; 27546303Smarkm char int_name[IF_NAME_LEN+1]; 27618316Swollman u_short int_index; 27718316Swollman naddr int_addr; /* address on this host (net order) */ 27818316Swollman naddr int_brdaddr; /* broadcast address (n) */ 27918316Swollman naddr int_dstaddr; /* other end of pt-to-pt link (n) */ 28018316Swollman naddr int_net; /* working network # (host order)*/ 28118316Swollman naddr int_mask; /* working net mask (host order) */ 28218316Swollman naddr int_ripv1_mask; /* for inferring a mask (n) */ 28318316Swollman naddr int_std_addr; /* class A/B/C address (n) */ 28418316Swollman naddr int_std_net; /* class A/B/C network (h) */ 28518316Swollman naddr int_std_mask; /* class A/B/C netmask (h) */ 28618316Swollman int int_rip_sock; /* for queries */ 28718316Swollman int int_if_flags; /* some bits copied from kernel */ 28818316Swollman u_int int_state; 28918316Swollman time_t int_act_time; /* last thought healthy */ 29019885Swollman time_t int_query_time; 29118316Swollman u_short int_transitions; /* times gone up-down */ 29218316Swollman char int_metric; 29318316Swollman char int_d_metric; /* for faked default route */ 29418316Swollman struct int_data { 29518316Swollman u_int ipackets; /* previous network stats */ 29618316Swollman u_int ierrors; 29718316Swollman u_int opackets; 29818316Swollman u_int oerrors; 29918316Swollman#ifdef sgi 30018316Swollman u_int odrops; 30118316Swollman#endif 30218316Swollman time_t ts; /* timestamp on network stats */ 30318316Swollman } int_data; 30420342Swollman# define MAX_AUTH_KEYS 5 30519885Swollman struct auth { /* authentication info */ 30646303Smarkm u_int16_t type; 30746303Smarkm u_char key[RIP_AUTH_PW_LEN]; 30820342Swollman u_char keyid; 30920342Swollman time_t start, end; 31020342Swollman } int_auth[MAX_AUTH_KEYS]; 31146303Smarkm /* router discovery parameters */ 31246303Smarkm int int_rdisc_pref; /* signed preference to advertise */ 31318316Swollman int int_rdisc_int; /* MaxAdvertiseInterval */ 31418316Swollman int int_rdisc_cnt; 31518316Swollman struct timeval int_rdisc_timer; 31618316Swollman}; 31718316Swollman 31818316Swollman/* bits in int_state */ 31918316Swollman#define IS_ALIAS 0x0000001 /* interface alias */ 32018316Swollman#define IS_SUBNET 0x0000002 /* interface on subnetted network */ 32118316Swollman#define IS_REMOTE 0x0000004 /* interface is not on this machine */ 32218316Swollman#define IS_PASSIVE 0x0000008 /* remote and does not do RIP */ 32318316Swollman#define IS_EXTERNAL 0x0000010 /* handled by EGP or something */ 32418316Swollman#define IS_CHECKED 0x0000020 /* still exists */ 32518316Swollman#define IS_ALL_HOSTS 0x0000040 /* in INADDR_ALLHOSTS_GROUP */ 32618316Swollman#define IS_ALL_ROUTERS 0x0000080 /* in INADDR_ALLROUTERS_GROUP */ 32719885Swollman#define IS_DISTRUST 0x0000100 /* ignore untrusted routers */ 32820342Swollman#define IS_REDIRECT_OK 0x0000200 /* accept ICMP redirects */ 32920342Swollman#define IS_BROKE 0x0000400 /* seems to be broken */ 33020342Swollman#define IS_SICK 0x0000800 /* seems to be broken */ 33120342Swollman#define IS_DUP 0x0001000 /* has a duplicate address */ 33218316Swollman#define IS_NEED_NET_SYN 0x0002000 /* need RS_NET_SYN route */ 33318316Swollman#define IS_NO_AG 0x0004000 /* do not aggregate subnets */ 33418316Swollman#define IS_NO_SUPER_AG 0x0008000 /* do not aggregate networks */ 33518316Swollman#define IS_NO_RIPV1_IN 0x0010000 /* no RIPv1 input at all */ 33618316Swollman#define IS_NO_RIPV2_IN 0x0020000 /* no RIPv2 input at all */ 33718316Swollman#define IS_NO_RIP_IN (IS_NO_RIPV1_IN | IS_NO_RIPV2_IN) 33818316Swollman#define IS_RIP_IN_OFF(s) (((s) & IS_NO_RIP_IN) == IS_NO_RIP_IN) 33918316Swollman#define IS_NO_RIPV1_OUT 0x0040000 /* no RIPv1 output at all */ 34018316Swollman#define IS_NO_RIPV2_OUT 0x0080000 /* no RIPv2 output at all */ 34118316Swollman#define IS_NO_RIP_OUT (IS_NO_RIPV1_OUT | IS_NO_RIPV2_OUT) 34218316Swollman#define IS_NO_RIP (IS_NO_RIP_OUT | IS_NO_RIP_IN) 34318316Swollman#define IS_RIP_OUT_OFF(s) (((s) & IS_NO_RIP_OUT) == IS_NO_RIP_OUT) 34418316Swollman#define IS_RIP_OFF(s) (((s) & IS_NO_RIP) == IS_NO_RIP) 34546303Smarkm#define IS_NO_RIP_MCAST 0x0100000 /* broadcast RIPv2 */ 34646303Smarkm#define IS_NO_ADV_IN 0x0200000 /* do not listen to advertisements */ 34746303Smarkm#define IS_NO_SOL_OUT 0x0400000 /* send no solicitations */ 34846303Smarkm#define IS_SOL_OUT 0x0800000 /* send solicitations */ 34946303Smarkm#define GROUP_IS_SOL_OUT (IS_SOL_OUT | IS_NO_SOL_OUT) 35046303Smarkm#define IS_NO_ADV_OUT 0x1000000 /* do not advertise rdisc */ 35146303Smarkm#define IS_ADV_OUT 0x2000000 /* advertise rdisc */ 35246303Smarkm#define GROUP_IS_ADV_OUT (IS_NO_ADV_OUT | IS_ADV_OUT) 35346303Smarkm#define IS_BCAST_RDISC 0x4000000 /* broadcast instead of multicast */ 35418316Swollman#define IS_NO_RDISC (IS_NO_ADV_IN | IS_NO_SOL_OUT | IS_NO_ADV_OUT) 35546303Smarkm#define IS_PM_RDISC 0x8000000 /* poor-man's router discovery */ 35618316Swollman 35746303Smarkm#define iff_up(f) ((f) & IFF_UP) 35818316Swollman 35918316Swollman 36018316Swollman/* Information for aggregating routes */ 36118316Swollman#define NUM_AG_SLOTS 32 36218316Swollmanstruct ag_info { 36318316Swollman struct ag_info *ag_fine; /* slot with finer netmask */ 36418316Swollman struct ag_info *ag_cors; /* more coarse netmask */ 36518316Swollman naddr ag_dst_h; /* destination in host byte order */ 36618316Swollman naddr ag_mask; 36718316Swollman naddr ag_gate; 36818316Swollman naddr ag_nhop; 36918316Swollman char ag_metric; /* metric to be advertised */ 37018316Swollman char ag_pref; /* aggregate based on this */ 37118316Swollman u_int ag_seqno; 37218316Swollman u_short ag_tag; 37318316Swollman u_short ag_state; 37437908Scharnier#define AGS_SUPPRESS 0x001 /* combine with coarser mask */ 37546303Smarkm#define AGS_AGGREGATE 0x002 /* synthesize combined routes */ 37618316Swollman#define AGS_REDUN0 0x004 /* redundant, finer routes output */ 37718316Swollman#define AGS_REDUN1 0x008 37818316Swollman#define AG_IS_REDUN(state) (((state) & (AGS_REDUN0 | AGS_REDUN1)) \ 37918316Swollman == (AGS_REDUN0 | AGS_REDUN1)) 38018316Swollman#define AGS_GATEWAY 0x010 /* tell kernel RTF_GATEWAY */ 38118316Swollman#define AGS_IF 0x020 /* for an interface */ 38218316Swollman#define AGS_RIPV2 0x040 /* send only as RIPv2 */ 38318316Swollman#define AGS_FINE_GATE 0x080 /* ignore differing ag_gate when this 38418316Swollman * has the finer netmask */ 38518316Swollman#define AGS_CORS_GATE 0x100 /* ignore differing gate when this 38637908Scharnier * has the coarser netmasks */ 38718316Swollman#define AGS_SPLIT_HZ 0x200 /* suppress for split horizon */ 38818316Swollman 38918316Swollman /* some bits are set if they are set on either route */ 39046303Smarkm#define AGS_AGGREGATE_EITHER (AGS_RIPV2 | AGS_GATEWAY | \ 39146303Smarkm AGS_SUPPRESS | AGS_CORS_GATE) 39218316Swollman}; 39318316Swollman 39418316Swollman 39518316Swollman/* parameters for interfaces */ 39618316Swollmanextern struct parm { 39718316Swollman struct parm *parm_next; 39846303Smarkm char parm_name[IF_NAME_LEN+1]; 39919885Swollman naddr parm_net; 40018316Swollman naddr parm_mask; 40118316Swollman 40218316Swollman char parm_d_metric; 40318316Swollman u_int parm_int_state; 40446303Smarkm int parm_rdisc_pref; /* signed IRDP preference */ 40546303Smarkm int parm_rdisc_int; /* IRDP advertising interval */ 40620342Swollman struct auth parm_auth[MAX_AUTH_KEYS]; 40718316Swollman} *parms; 40818316Swollman 40918316Swollman/* authority for internal networks */ 41018316Swollmanextern struct intnet { 41118316Swollman struct intnet *intnet_next; 41246303Smarkm naddr intnet_addr; /* network byte order */ 41318316Swollman naddr intnet_mask; 41418316Swollman char intnet_metric; 41518316Swollman} *intnets; 41618316Swollman 41746303Smarkm/* defined RIPv1 netmasks */ 41846303Smarkmextern struct r1net { 41946303Smarkm struct r1net *r1net_next; 42046303Smarkm naddr r1net_net; /* host order */ 42146303Smarkm naddr r1net_match; 42246303Smarkm naddr r1net_mask; 42346303Smarkm} *r1nets; 42446303Smarkm 42519885Swollman/* trusted routers */ 42619885Swollmanextern struct tgate { 42719885Swollman struct tgate *tgate_next; 42819885Swollman naddr tgate_addr; 42946303Smarkm#define MAX_TGATE_NETS 32 43046303Smarkm struct tgate_net { 43146303Smarkm naddr net; /* host order */ 43246303Smarkm naddr mask; 43346303Smarkm } tgate_nets[MAX_TGATE_NETS]; 43419885Swollman} *tgates; 43518316Swollman 43619885Swollmanenum output_type {OUT_QUERY, OUT_UNICAST, OUT_BROADCAST, OUT_MULTICAST, 43719885Swollman NO_OUT_MULTICAST, NO_OUT_RIPV2}; 43818316Swollman 43919885Swollman/* common output buffers */ 44019885Swollmanextern struct ws_buf { 44119885Swollman struct rip *buf; 44219885Swollman struct netinfo *n; 44319885Swollman struct netinfo *base; 44419885Swollman struct netinfo *lim; 44519885Swollman enum output_type type; 44619885Swollman} v12buf, v2buf; 44719885Swollman 44818316Swollmanextern pid_t mypid; 44918316Swollmanextern naddr myaddr; /* main address of this system */ 45018316Swollman 45118316Swollmanextern int stopint; /* !=0 to stop */ 45218316Swollman 45318316Swollmanextern int sock_max; 45418316Swollmanextern int rip_sock; /* RIP socket */ 45518316Swollmanextern struct interface *rip_sock_mcast; /* current multicast interface */ 45618316Swollmanextern int rt_sock; /* routing socket */ 45718316Swollmanextern int rt_sock_seqno; 45818316Swollmanextern int rdisc_sock; /* router-discovery raw socket */ 45918316Swollman 46018316Swollmanextern int seqno; /* sequence number for messages */ 46118316Swollmanextern int supplier; /* process should supply updates */ 46246303Smarkmextern int supplier_set; /* -s or -q requested */ 46318316Swollmanextern int lookforinterfaces; /* 1=probe for new up interfaces */ 46418316Swollmanextern int ridhosts; /* 1=reduce host routes */ 46518316Swollmanextern int mhome; /* 1=want multi-homed host route */ 46637908Scharnierextern int advertise_mhome; /* 1=must continue advertising it */ 46718316Swollmanextern int auth_ok; /* 1=ignore auth if we do not care */ 46818316Swollman 46919885Swollmanextern struct timeval clk; /* system clock's idea of time */ 47019885Swollmanextern struct timeval epoch; /* system clock when started */ 47118316Swollmanextern struct timeval now; /* current idea of time */ 47218316Swollmanextern time_t now_stale; 47318316Swollmanextern time_t now_expire; 47418316Swollmanextern time_t now_garbage; 47518316Swollman 47618316Swollmanextern struct timeval next_bcast; /* next general broadcast */ 47718316Swollmanextern struct timeval age_timer; /* next check of old routes */ 47818316Swollmanextern struct timeval no_flash; /* inhibit flash update until then */ 47918316Swollmanextern struct timeval rdisc_timer; /* next advert. or solicitation */ 48018316Swollmanextern int rdisc_ok; /* using solicited route */ 48118316Swollman 48218316Swollmanextern struct timeval ifinit_timer; /* time to check interfaces */ 48318316Swollman 48418316Swollmanextern naddr loopaddr; /* our address on loopback */ 48518316Swollmanextern int tot_interfaces; /* # of remote and local interfaces */ 48618316Swollmanextern int rip_interfaces; /* # of interfaces doing RIP */ 48718316Swollmanextern struct interface *ifnet; /* all interfaces */ 48819885Swollmanextern struct interface *remote_if; /* remote interfaces */ 48918316Swollmanextern int have_ripv1_out; /* have a RIPv1 interface */ 49018316Swollmanextern int have_ripv1_in; 49118316Swollmanextern int need_flash; /* flash update needed */ 49218316Swollmanextern struct timeval need_kern; /* need to update kernel table */ 49346303Smarkmextern u_int update_seqno; /* a route has changed */ 49418316Swollman 49520342Swollmanextern int tracelevel, new_tracelevel; 49618316Swollman#define MAX_TRACELEVEL 4 49718316Swollman#define TRACEKERNEL (tracelevel >= 4) /* log kernel changes */ 49818316Swollman#define TRACECONTENTS (tracelevel >= 3) /* display packet contents */ 49918316Swollman#define TRACEPACKETS (tracelevel >= 2) /* note packets */ 50018316Swollman#define TRACEACTIONS (tracelevel != 0) 50118316Swollmanextern FILE *ftrace; /* output trace file */ 502118582Simpextern char inittracename[PATH_MAX]; 50318316Swollman 50418316Swollmanextern struct radix_node_head *rhead; 50518316Swollman 50618316Swollman 50718316Swollman#ifdef sgi 50818316Swollman/* Fix conflicts */ 50918316Swollman#define dup2(x,y) BSDdup2(x,y) 51018316Swollman#endif /* sgi */ 51118316Swollman 51246303Smarkmextern void fix_sock(int, const char *); 51318316Swollmanextern void fix_select(void); 51418316Swollmanextern void rip_off(void); 51518316Swollmanextern void rip_on(struct interface *); 51618316Swollman 51719885Swollmanextern void bufinit(void); 51819885Swollmanextern int output(enum output_type, struct sockaddr_in *, 51919885Swollman struct interface *, struct rip *, int); 52020342Swollmanextern void clr_ws_buf(struct ws_buf *, struct auth *); 52118316Swollmanextern void rip_query(void); 52218316Swollmanextern void rip_bcast(int); 52318316Swollmanextern void supply(struct sockaddr_in *, struct interface *, 52419885Swollman enum output_type, int, int, int); 52518316Swollman 52646303Smarkmextern void msglog(const char *, ...) PATTRIB(1,2); 52719885Swollmanstruct msg_limit { 52820342Swollman time_t reuse; 52920342Swollman struct msg_sub { 53019885Swollman naddr addr; 53119885Swollman time_t until; 53220342Swollman# define MSG_SUBJECT_N 8 53320342Swollman } subs[MSG_SUBJECT_N]; 53419885Swollman}; 53546303Smarkmextern void msglim(struct msg_limit *, naddr, 53646303Smarkm const char *, ...) PATTRIB(3,4); 53718316Swollman#define LOGERR(msg) msglog(msg ": %s", strerror(errno)) 53846303Smarkmextern void logbad(int, const char *, ...) PATTRIB(2,3); 53918316Swollman#define BADERR(dump,msg) logbad(dump,msg ": %s", strerror(errno)) 54018316Swollman#ifdef DEBUG 54118316Swollman#define DBGERR(dump,msg) BADERR(dump,msg) 54218316Swollman#else 54318316Swollman#define DBGERR(dump,msg) LOGERR(msg) 54418316Swollman#endif 54518316Swollmanextern char *naddr_ntoa(naddr); 54646303Smarkmextern const char *saddr_ntoa(struct sockaddr *); 54718316Swollman 54846303Smarkmextern void *rtmalloc(size_t, const char *); 54918316Swollmanextern void timevaladd(struct timeval *, struct timeval *); 55018316Swollmanextern void intvl_random(struct timeval *, u_long, u_long); 55118316Swollmanextern int getnet(char *, naddr *, naddr *); 55218316Swollmanextern int gethost(char *, naddr *); 55318316Swollmanextern void gwkludge(void); 55446303Smarkmextern const char *parse_parms(char *, int); 55546303Smarkmextern const char *check_parms(struct parm *); 55618316Swollmanextern void get_parms(struct interface *); 55718316Swollman 55818316Swollmanextern void lastlog(void); 55946303Smarkmextern void trace_close(int); 56046303Smarkmextern void set_tracefile(const char *, const char *, int); 56146303Smarkmextern void tracelevel_msg(const char *, int); 56246303Smarkmextern void trace_off(const char*, ...) PATTRIB(1,2); 56320342Swollmanextern void set_tracelevel(void); 56418316Swollmanextern void trace_flush(void); 56546303Smarkmextern void trace_misc(const char *, ...) PATTRIB(1,2); 56646303Smarkmextern void trace_act(const char *, ...) PATTRIB(1,2); 56746303Smarkmextern void trace_pkt(const char *, ...) PATTRIB(1,2); 56846303Smarkmextern void trace_add_del(const char *, struct rt_entry *); 56946303Smarkmextern void trace_change(struct rt_entry *, u_int, struct rt_spare *, 57046303Smarkm const char *); 57146303Smarkmextern void trace_if(const char *, struct interface *); 57218316Swollmanextern void trace_upslot(struct rt_entry *, struct rt_spare *, 57346303Smarkm struct rt_spare *); 57446303Smarkmextern void trace_rip(const char*, const char*, struct sockaddr_in *, 57518316Swollman struct interface *, struct rip *, int); 57618316Swollmanextern char *addrname(naddr, naddr, int); 57746303Smarkmextern char *rtname(naddr, naddr, naddr); 57818316Swollman 57918316Swollmanextern void rdisc_age(naddr); 58018316Swollmanextern void set_rdisc_mg(struct interface *, int); 58118316Swollmanextern void set_supplier(void); 58218316Swollmanextern void if_bad_rdisc(struct interface *); 58318316Swollmanextern void if_ok_rdisc(struct interface *); 58418316Swollmanextern void read_rip(int, struct interface *); 58518316Swollmanextern void read_rt(void); 58618316Swollmanextern void read_d(void); 58718316Swollmanextern void rdisc_adv(void); 58818316Swollmanextern void rdisc_sol(void); 58918316Swollman 59018316Swollmanextern void sigalrm(int); 59118316Swollmanextern void sigterm(int); 59218316Swollman 59318316Swollmanextern void sigtrace_on(int); 59418316Swollmanextern void sigtrace_off(int); 59518316Swollman 59618316Swollmanextern void flush_kern(void); 59718316Swollmanextern void age(naddr); 59818316Swollman 59918316Swollmanextern void ag_flush(naddr, naddr, void (*)(struct ag_info *)); 60018316Swollmanextern void ag_check(naddr, naddr, naddr, naddr, char, char, u_int, 60118316Swollman u_short, u_short, void (*)(struct ag_info *)); 60246303Smarkmextern void del_static(naddr, naddr, naddr, int); 60318316Swollmanextern void del_redirects(naddr, time_t); 60418316Swollmanextern struct rt_entry *rtget(naddr, naddr); 60518316Swollmanextern struct rt_entry *rtfind(naddr); 60618316Swollmanextern void rtinit(void); 60746303Smarkmextern void rtadd(naddr, naddr, u_int, struct rt_spare *); 60846303Smarkmextern void rtchange(struct rt_entry *, u_int, struct rt_spare *, char *); 60918316Swollmanextern void rtdelete(struct rt_entry *); 61046303Smarkmextern void rts_delete(struct rt_entry *, struct rt_spare *); 61118316Swollmanextern void rtbad_sub(struct rt_entry *); 61218316Swollmanextern void rtswitch(struct rt_entry *, struct rt_spare *); 61318316Swollmanextern void rtbad(struct rt_entry *); 61418316Swollman 61518316Swollman#define S_ADDR(x) (((struct sockaddr_in *)(x))->sin_addr.s_addr) 61618316Swollman#define INFO_DST(I) ((I)->rti_info[RTAX_DST]) 61718316Swollman#define INFO_GATE(I) ((I)->rti_info[RTAX_GATEWAY]) 61818316Swollman#define INFO_MASK(I) ((I)->rti_info[RTAX_NETMASK]) 61918316Swollman#define INFO_IFA(I) ((I)->rti_info[RTAX_IFA]) 62018316Swollman#define INFO_IFP(I) ((I)->rti_info[RTAX_IFP]) 62118316Swollman#define INFO_AUTHOR(I) ((I)->rti_info[RTAX_AUTHOR]) 62218316Swollman#define INFO_BRD(I) ((I)->rti_info[RTAX_BRD]) 62318316Swollmanvoid rt_xaddrs(struct rt_addrinfo *, struct sockaddr *, struct sockaddr *, 62418316Swollman int); 62518316Swollman 62618316Swollmanextern naddr std_mask(naddr); 62718316Swollmanextern naddr ripv1_mask_net(naddr, struct interface *); 62818316Swollmanextern naddr ripv1_mask_host(naddr,struct interface *); 62918316Swollman#define on_net(a,net,mask) (((ntohl(a) ^ (net)) & (mask)) == 0) 63018316Swollmanextern int check_dst(naddr); 63119885Swollmanextern struct interface *check_dup(naddr, naddr, naddr, int); 63219885Swollmanextern int check_remote(struct interface *); 63346303Smarkmextern int addrouteforif(struct interface *); 63418316Swollmanextern void ifinit(void); 63518316Swollmanextern int walk_bad(struct radix_node *, struct walkarg *); 63646303Smarkmextern int if_ok(struct interface *, const char *); 63718316Swollmanextern void if_sick(struct interface *); 63818316Swollmanextern void if_bad(struct interface *); 63919885Swollmanextern void if_link(struct interface *); 64018316Swollmanextern struct interface *ifwithaddr(naddr, int, int); 64118316Swollmanextern struct interface *ifwithname(char *, naddr); 64246303Smarkmextern struct interface *ifwithindex(u_short, int); 64318316Swollmanextern struct interface *iflookup(naddr); 64419885Swollman 64520342Swollmanextern struct auth *find_auth(struct interface *); 64620342Swollmanextern void end_md5_auth(struct ws_buf *, struct auth *); 64719885Swollman 64846303Smarkm#define MD5_DIGEST_LEN 16 64946303Smarkmtypedef struct { 65046303Smarkm u_int32_t state[4]; /* state (ABCD) */ 65146303Smarkm u_int32_t count[2]; /* # of bits, modulo 2^64 (LSB 1st) */ 65246303Smarkm unsigned char buffer[64]; /* input buffer */ 65346303Smarkm} MD5_CTX; 65446303Smarkmextern void MD5Init(MD5_CTX*); 65546303Smarkmextern void MD5Update(MD5_CTX*, u_char*, u_int); 65646303Smarkmextern void MD5Final(u_char[MD5_DIGEST_LEN], MD5_CTX*); 657