defs.h revision 190716
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 190716 2009-04-05 16:01:56Z phk $ 3218316Swollman */ 3318316Swollman 3446303Smarkm#ifdef sgi 3550969Speter#ident "$FreeBSD: head/sbin/routed/defs.h 190716 2009-04-05 16:01:56Z 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 MIN_PreferenceLevel 0x80000000 15418316Swollman 15518316Swollman#define MAX_INITIAL_ADVERT_INTERVAL 16 15618316Swollman#define MAX_INITIAL_ADVERTS 3 15718316Swollman 15818316Swollman#define MAX_SOLICITATION_DELAY 1 15918316Swollman#define SOLICITATION_INTERVAL 3 16018316Swollman#define MAX_SOLICITATIONS 3 16118316Swollman 16218316Swollman 16319885Swollman/* Bloated packet size for systems that simply add authentication to 16419885Swollman * full-sized packets 16519885Swollman */ 16619885Swollman#define OVER_MAXPACKETSIZE (MAXPACKETSIZE+sizeof(struct netinfo)*2) 16718316Swollman/* typical packet buffers */ 16818316Swollmanunion pkt_buf { 16919885Swollman char packet[OVER_MAXPACKETSIZE*2]; 17018316Swollman struct rip rip; 17118316Swollman}; 17218316Swollman 17346303Smarkm#define GNAME_LEN 64 /* assumed=64 in parms.c */ 17446303Smarkm/* bigger than IFNAMSIZ, with room for "external()" or "remote()" */ 17546303Smarkm#define IF_NAME_LEN (GNAME_LEN+15) 17618316Swollman 17719885Swollman/* No more routes than this, to protect ourself in case something goes 17819885Swollman * whacko and starts broadcasting zillions of bogus routes. 17918316Swollman */ 18018316Swollman#define MAX_ROUTES (128*1024) 18118316Swollmanextern int total_routes; 18218316Swollman 18318316Swollman/* Main, daemon routing table structure 18418316Swollman */ 18518316Swollmanstruct rt_entry { 18618316Swollman struct radix_node rt_nodes[2]; /* radix tree glue */ 18718316Swollman u_int rt_state; 18818316Swollman# define RS_IF 0x001 /* for network interface */ 18918316Swollman# define RS_NET_INT 0x002 /* authority route */ 19018316Swollman# define RS_NET_SYN 0x004 /* fake net route for subnet */ 19118316Swollman# define RS_NO_NET_SYN (RS_LOCAL | RS_LOCAL | RS_IF) 19218316Swollman# define RS_SUBNET 0x008 /* subnet route from any source */ 19318316Swollman# define RS_LOCAL 0x010 /* loopback for pt-to-pt */ 19418316Swollman# define RS_MHOME 0x020 /* from -m */ 19518316Swollman# define RS_STATIC 0x040 /* from the kernel */ 19618316Swollman# define RS_RDISC 0x080 /* from router discovery */ 19718316Swollman struct sockaddr_in rt_dst_sock; 19818316Swollman naddr rt_mask; 19918316Swollman struct rt_spare { 20018316Swollman struct interface *rts_ifp; 20118316Swollman naddr rts_gate; /* forward packets here */ 20218316Swollman naddr rts_router; /* on the authority of this router */ 20318316Swollman char rts_metric; 20418316Swollman u_short rts_tag; 20518316Swollman time_t rts_time; /* timer to junk stale routes */ 20646303Smarkm u_int rts_de_ag; /* de-aggregation level */ 20718316Swollman#define NUM_SPARES 4 20818316Swollman } rt_spares[NUM_SPARES]; 20918316Swollman u_int rt_seqno; /* when last changed */ 21018316Swollman char rt_poison_metric; /* to notice maximum recently */ 21118316Swollman time_t rt_poison_time; /* advertised metric */ 21218316Swollman}; 21346303Smarkm#define rt_dst rt_dst_sock.sin_addr.s_addr 21446303Smarkm#define rt_ifp rt_spares[0].rts_ifp 21546303Smarkm#define rt_gate rt_spares[0].rts_gate 21646303Smarkm#define rt_router rt_spares[0].rts_router 21746303Smarkm#define rt_metric rt_spares[0].rts_metric 21846303Smarkm#define rt_tag rt_spares[0].rts_tag 21946303Smarkm#define rt_time rt_spares[0].rts_time 22046303Smarkm#define rt_de_ag rt_spares[0].rts_de_ag 22118316Swollman 22218316Swollman#define HOST_MASK 0xffffffff 22318316Swollman#define RT_ISHOST(rt) ((rt)->rt_mask == HOST_MASK) 22418316Swollman 22518316Swollman/* age all routes that 22618316Swollman * are not from -g, -m, or static routes from the kernel 22718316Swollman * not unbroken interface routes 22818316Swollman * but not broken interfaces 22918316Swollman * nor non-passive, remote interfaces that are not aliases 23018316Swollman * (i.e. remote & metric=0) 23118316Swollman */ 23218316Swollman#define AGE_RT(rt_state,ifp) (0 == ((rt_state) & (RS_MHOME | RS_STATIC \ 23318316Swollman | RS_NET_SYN | RS_RDISC)) \ 23418316Swollman && (!((rt_state) & RS_IF) \ 23518316Swollman || (ifp) == 0 \ 23618316Swollman || (((ifp)->int_state & IS_REMOTE) \ 23718316Swollman && !((ifp)->int_state & IS_PASSIVE)))) 23818316Swollman 23918316Swollman/* true if A is better than B 24018316Swollman * Better if 24118316Swollman * - A is not a poisoned route 24218316Swollman * - and A is not stale 24318316Swollman * - and A has a shorter path 24418316Swollman * - or is the router speaking for itself 24518316Swollman * - or the current route is equal but stale 24618316Swollman * - or it is a host route advertised by a system for itself 24718316Swollman */ 24846303Smarkm#define BETTER_LINK(rt,A,B) ((A)->rts_metric < HOPCNT_INFINITY \ 24918316Swollman && now_stale <= (A)->rts_time \ 25018316Swollman && ((A)->rts_metric < (B)->rts_metric \ 25118316Swollman || ((A)->rts_gate == (A)->rts_router \ 25218316Swollman && (B)->rts_gate != (B)->rts_router) \ 25318316Swollman || ((A)->rts_metric == (B)->rts_metric \ 25418316Swollman && now_stale > (B)->rts_time) \ 25518316Swollman || (RT_ISHOST(rt) \ 25618316Swollman && (rt)->rt_dst == (A)->rts_router \ 25718316Swollman && (A)->rts_metric == (B)->rts_metric))) 25818316Swollman 25918316Swollman 26018316Swollman/* An "interface" is similar to a kernel ifnet structure, except it also 26118316Swollman * handles "logical" or "IS_REMOTE" interfaces (remote gateways). 26218316Swollman */ 26318316Swollmanstruct interface { 264190711Sphk LIST_ENTRY(interface) int_list; 265190713Sphk LIST_ENTRY(interface) remote_list; 26619885Swollman struct interface *int_ahash, **int_ahash_prev; 26719885Swollman struct interface *int_bhash, **int_bhash_prev; 26819885Swollman struct interface *int_nhash, **int_nhash_prev; 26946303Smarkm char int_name[IF_NAME_LEN+1]; 27018316Swollman u_short int_index; 27118316Swollman naddr int_addr; /* address on this host (net order) */ 27218316Swollman naddr int_brdaddr; /* broadcast address (n) */ 27318316Swollman naddr int_dstaddr; /* other end of pt-to-pt link (n) */ 27418316Swollman naddr int_net; /* working network # (host order)*/ 27518316Swollman naddr int_mask; /* working net mask (host order) */ 27618316Swollman naddr int_ripv1_mask; /* for inferring a mask (n) */ 27718316Swollman naddr int_std_addr; /* class A/B/C address (n) */ 27818316Swollman naddr int_std_net; /* class A/B/C network (h) */ 27918316Swollman naddr int_std_mask; /* class A/B/C netmask (h) */ 28018316Swollman int int_rip_sock; /* for queries */ 28118316Swollman int int_if_flags; /* some bits copied from kernel */ 28218316Swollman u_int int_state; 28318316Swollman time_t int_act_time; /* last thought healthy */ 28419885Swollman time_t int_query_time; 28518316Swollman u_short int_transitions; /* times gone up-down */ 28618316Swollman char int_metric; 287126250Sbms u_char int_d_metric; /* for faked default route */ 288126250Sbms u_char int_adj_inmetric; /* adjust advertised metrics */ 289126250Sbms u_char int_adj_outmetric; /* instead of interface metric */ 29018316Swollman struct int_data { 29118316Swollman u_int ipackets; /* previous network stats */ 29218316Swollman u_int ierrors; 29318316Swollman u_int opackets; 29418316Swollman u_int oerrors; 29518316Swollman#ifdef sgi 29618316Swollman u_int odrops; 29718316Swollman#endif 29818316Swollman time_t ts; /* timestamp on network stats */ 29918316Swollman } int_data; 30020342Swollman# define MAX_AUTH_KEYS 5 30119885Swollman struct auth { /* authentication info */ 30246303Smarkm u_int16_t type; 30346303Smarkm u_char key[RIP_AUTH_PW_LEN]; 30420342Swollman u_char keyid; 30520342Swollman time_t start, end; 30620342Swollman } int_auth[MAX_AUTH_KEYS]; 30746303Smarkm /* router discovery parameters */ 30846303Smarkm int int_rdisc_pref; /* signed preference to advertise */ 30918316Swollman int int_rdisc_int; /* MaxAdvertiseInterval */ 31018316Swollman int int_rdisc_cnt; 31118316Swollman struct timeval int_rdisc_timer; 31218316Swollman}; 31318316Swollman 31418316Swollman/* bits in int_state */ 31518316Swollman#define IS_ALIAS 0x0000001 /* interface alias */ 31618316Swollman#define IS_SUBNET 0x0000002 /* interface on subnetted network */ 31718316Swollman#define IS_REMOTE 0x0000004 /* interface is not on this machine */ 31818316Swollman#define IS_PASSIVE 0x0000008 /* remote and does not do RIP */ 31918316Swollman#define IS_EXTERNAL 0x0000010 /* handled by EGP or something */ 32018316Swollman#define IS_CHECKED 0x0000020 /* still exists */ 32118316Swollman#define IS_ALL_HOSTS 0x0000040 /* in INADDR_ALLHOSTS_GROUP */ 32218316Swollman#define IS_ALL_ROUTERS 0x0000080 /* in INADDR_ALLROUTERS_GROUP */ 32319885Swollman#define IS_DISTRUST 0x0000100 /* ignore untrusted routers */ 32420342Swollman#define IS_REDIRECT_OK 0x0000200 /* accept ICMP redirects */ 32520342Swollman#define IS_BROKE 0x0000400 /* seems to be broken */ 32620342Swollman#define IS_SICK 0x0000800 /* seems to be broken */ 32720342Swollman#define IS_DUP 0x0001000 /* has a duplicate address */ 32818316Swollman#define IS_NEED_NET_SYN 0x0002000 /* need RS_NET_SYN route */ 32918316Swollman#define IS_NO_AG 0x0004000 /* do not aggregate subnets */ 33018316Swollman#define IS_NO_SUPER_AG 0x0008000 /* do not aggregate networks */ 33118316Swollman#define IS_NO_RIPV1_IN 0x0010000 /* no RIPv1 input at all */ 33218316Swollman#define IS_NO_RIPV2_IN 0x0020000 /* no RIPv2 input at all */ 33318316Swollman#define IS_NO_RIP_IN (IS_NO_RIPV1_IN | IS_NO_RIPV2_IN) 33418316Swollman#define IS_RIP_IN_OFF(s) (((s) & IS_NO_RIP_IN) == IS_NO_RIP_IN) 33518316Swollman#define IS_NO_RIPV1_OUT 0x0040000 /* no RIPv1 output at all */ 33618316Swollman#define IS_NO_RIPV2_OUT 0x0080000 /* no RIPv2 output at all */ 33718316Swollman#define IS_NO_RIP_OUT (IS_NO_RIPV1_OUT | IS_NO_RIPV2_OUT) 33818316Swollman#define IS_NO_RIP (IS_NO_RIP_OUT | IS_NO_RIP_IN) 33918316Swollman#define IS_RIP_OUT_OFF(s) (((s) & IS_NO_RIP_OUT) == IS_NO_RIP_OUT) 34018316Swollman#define IS_RIP_OFF(s) (((s) & IS_NO_RIP) == IS_NO_RIP) 34146303Smarkm#define IS_NO_RIP_MCAST 0x0100000 /* broadcast RIPv2 */ 34246303Smarkm#define IS_NO_ADV_IN 0x0200000 /* do not listen to advertisements */ 34346303Smarkm#define IS_NO_SOL_OUT 0x0400000 /* send no solicitations */ 34446303Smarkm#define IS_SOL_OUT 0x0800000 /* send solicitations */ 34546303Smarkm#define GROUP_IS_SOL_OUT (IS_SOL_OUT | IS_NO_SOL_OUT) 34646303Smarkm#define IS_NO_ADV_OUT 0x1000000 /* do not advertise rdisc */ 34746303Smarkm#define IS_ADV_OUT 0x2000000 /* advertise rdisc */ 34846303Smarkm#define GROUP_IS_ADV_OUT (IS_NO_ADV_OUT | IS_ADV_OUT) 34946303Smarkm#define IS_BCAST_RDISC 0x4000000 /* broadcast instead of multicast */ 35018316Swollman#define IS_NO_RDISC (IS_NO_ADV_IN | IS_NO_SOL_OUT | IS_NO_ADV_OUT) 35146303Smarkm#define IS_PM_RDISC 0x8000000 /* poor-man's router discovery */ 35218316Swollman 35346303Smarkm#define iff_up(f) ((f) & IFF_UP) 35418316Swollman 355190711SphkLIST_HEAD(ifhead, interface); 35618316Swollman 35718316Swollman/* Information for aggregating routes */ 35818316Swollman#define NUM_AG_SLOTS 32 35918316Swollmanstruct ag_info { 36018316Swollman struct ag_info *ag_fine; /* slot with finer netmask */ 36118316Swollman struct ag_info *ag_cors; /* more coarse netmask */ 36218316Swollman naddr ag_dst_h; /* destination in host byte order */ 36318316Swollman naddr ag_mask; 36418316Swollman naddr ag_gate; 36518316Swollman naddr ag_nhop; 36618316Swollman char ag_metric; /* metric to be advertised */ 36718316Swollman char ag_pref; /* aggregate based on this */ 36818316Swollman u_int ag_seqno; 36918316Swollman u_short ag_tag; 37018316Swollman u_short ag_state; 37137908Scharnier#define AGS_SUPPRESS 0x001 /* combine with coarser mask */ 37246303Smarkm#define AGS_AGGREGATE 0x002 /* synthesize combined routes */ 37318316Swollman#define AGS_REDUN0 0x004 /* redundant, finer routes output */ 37418316Swollman#define AGS_REDUN1 0x008 37518316Swollman#define AG_IS_REDUN(state) (((state) & (AGS_REDUN0 | AGS_REDUN1)) \ 37618316Swollman == (AGS_REDUN0 | AGS_REDUN1)) 37718316Swollman#define AGS_GATEWAY 0x010 /* tell kernel RTF_GATEWAY */ 37818316Swollman#define AGS_IF 0x020 /* for an interface */ 37918316Swollman#define AGS_RIPV2 0x040 /* send only as RIPv2 */ 38018316Swollman#define AGS_FINE_GATE 0x080 /* ignore differing ag_gate when this 38118316Swollman * has the finer netmask */ 38218316Swollman#define AGS_CORS_GATE 0x100 /* ignore differing gate when this 38337908Scharnier * has the coarser netmasks */ 38418316Swollman#define AGS_SPLIT_HZ 0x200 /* suppress for split horizon */ 38518316Swollman 38618316Swollman /* some bits are set if they are set on either route */ 38746303Smarkm#define AGS_AGGREGATE_EITHER (AGS_RIPV2 | AGS_GATEWAY | \ 38846303Smarkm AGS_SUPPRESS | AGS_CORS_GATE) 38918316Swollman}; 39018316Swollman 39118316Swollman 39218316Swollman/* parameters for interfaces */ 393190715Sphkstruct parm { 39418316Swollman struct parm *parm_next; 39546303Smarkm char parm_name[IF_NAME_LEN+1]; 39619885Swollman naddr parm_net; 39718316Swollman naddr parm_mask; 39818316Swollman 399126250Sbms u_char parm_d_metric; 400126250Sbms u_char parm_adj_inmetric; 401126250Sbms char parm_adj_outmetric; 40218316Swollman u_int parm_int_state; 40346303Smarkm int parm_rdisc_pref; /* signed IRDP preference */ 40446303Smarkm int parm_rdisc_int; /* IRDP advertising interval */ 40520342Swollman struct auth parm_auth[MAX_AUTH_KEYS]; 406190715Sphk}; 40718316Swollman 40818316Swollman/* authority for internal networks */ 40918316Swollmanextern struct intnet { 41018316Swollman struct intnet *intnet_next; 41146303Smarkm naddr intnet_addr; /* network byte order */ 41218316Swollman naddr intnet_mask; 41318316Swollman char intnet_metric; 41418316Swollman} *intnets; 41518316Swollman 41646303Smarkm/* defined RIPv1 netmasks */ 41746303Smarkmextern struct r1net { 41846303Smarkm struct r1net *r1net_next; 41946303Smarkm naddr r1net_net; /* host order */ 42046303Smarkm naddr r1net_match; 42146303Smarkm naddr r1net_mask; 42246303Smarkm} *r1nets; 42346303Smarkm 42419885Swollman/* trusted routers */ 42519885Swollmanextern struct tgate { 42619885Swollman struct tgate *tgate_next; 42719885Swollman naddr tgate_addr; 42846303Smarkm#define MAX_TGATE_NETS 32 42946303Smarkm struct tgate_net { 43046303Smarkm naddr net; /* host order */ 43146303Smarkm naddr mask; 43246303Smarkm } tgate_nets[MAX_TGATE_NETS]; 43319885Swollman} *tgates; 43418316Swollman 43519885Swollmanenum output_type {OUT_QUERY, OUT_UNICAST, OUT_BROADCAST, OUT_MULTICAST, 43619885Swollman NO_OUT_MULTICAST, NO_OUT_RIPV2}; 43718316Swollman 43819885Swollman/* common output buffers */ 43919885Swollmanextern struct ws_buf { 44019885Swollman struct rip *buf; 44119885Swollman struct netinfo *n; 44219885Swollman struct netinfo *base; 44319885Swollman struct netinfo *lim; 44419885Swollman enum output_type type; 445190715Sphk} v12buf; 44619885Swollman 44718316Swollmanextern pid_t mypid; 44818316Swollmanextern naddr myaddr; /* main address of this system */ 44918316Swollman 45018316Swollmanextern int stopint; /* !=0 to stop */ 45118316Swollman 45218316Swollmanextern int rip_sock; /* RIP socket */ 453190716Sphkextern const struct interface *rip_sock_mcast; /* current multicast interface */ 45418316Swollmanextern int rt_sock; /* routing socket */ 45518316Swollmanextern int rt_sock_seqno; 45618316Swollmanextern int rdisc_sock; /* router-discovery raw socket */ 45718316Swollman 45818316Swollmanextern int supplier; /* process should supply updates */ 45946303Smarkmextern int supplier_set; /* -s or -q requested */ 46018316Swollmanextern int ridhosts; /* 1=reduce host routes */ 46118316Swollmanextern int mhome; /* 1=want multi-homed host route */ 46237908Scharnierextern int advertise_mhome; /* 1=must continue advertising it */ 46318316Swollmanextern int auth_ok; /* 1=ignore auth if we do not care */ 46418316Swollman 46519885Swollmanextern struct timeval clk; /* system clock's idea of time */ 46619885Swollmanextern struct timeval epoch; /* system clock when started */ 46718316Swollmanextern struct timeval now; /* current idea of time */ 46818316Swollmanextern time_t now_stale; 46918316Swollmanextern time_t now_expire; 47018316Swollmanextern time_t now_garbage; 47118316Swollman 47218316Swollmanextern struct timeval age_timer; /* next check of old routes */ 47318316Swollmanextern struct timeval no_flash; /* inhibit flash update until then */ 47418316Swollmanextern struct timeval rdisc_timer; /* next advert. or solicitation */ 47518316Swollmanextern int rdisc_ok; /* using solicited route */ 47618316Swollman 47718316Swollmanextern struct timeval ifinit_timer; /* time to check interfaces */ 47818316Swollman 47918316Swollmanextern naddr loopaddr; /* our address on loopback */ 48018316Swollmanextern int tot_interfaces; /* # of remote and local interfaces */ 48118316Swollmanextern int rip_interfaces; /* # of interfaces doing RIP */ 482190711Sphkextern struct ifhead ifnet; /* all interfaces */ 483190713Sphkextern struct ifhead remote_if; /* remote interfaces */ 48418316Swollmanextern int have_ripv1_out; /* have a RIPv1 interface */ 48518316Swollmanextern int need_flash; /* flash update needed */ 48618316Swollmanextern struct timeval need_kern; /* need to update kernel table */ 48746303Smarkmextern u_int update_seqno; /* a route has changed */ 48818316Swollman 48920342Swollmanextern int tracelevel, new_tracelevel; 49018316Swollman#define MAX_TRACELEVEL 4 49118316Swollman#define TRACEKERNEL (tracelevel >= 4) /* log kernel changes */ 49218316Swollman#define TRACECONTENTS (tracelevel >= 3) /* display packet contents */ 49318316Swollman#define TRACEPACKETS (tracelevel >= 2) /* note packets */ 49418316Swollman#define TRACEACTIONS (tracelevel != 0) 49518316Swollmanextern FILE *ftrace; /* output trace file */ 496118582Simpextern char inittracename[PATH_MAX]; 49718316Swollman 49818316Swollmanextern struct radix_node_head *rhead; 49918316Swollman 50018316Swollman 50118316Swollman#ifdef sgi 50218316Swollman/* Fix conflicts */ 50318316Swollman#define dup2(x,y) BSDdup2(x,y) 50418316Swollman#endif /* sgi */ 50518316Swollman 506190715Sphkvoid fix_sock(int, const char *); 507190715Sphkvoid fix_select(void); 508190715Sphkvoid rip_off(void); 509190715Sphkvoid rip_on(struct interface *); 51018316Swollman 511190715Sphkvoid bufinit(void); 512190715Sphkint output(enum output_type, struct sockaddr_in *, 51319885Swollman struct interface *, struct rip *, int); 514190715Sphkvoid clr_ws_buf(struct ws_buf *, struct auth *); 515190715Sphkvoid rip_query(void); 516190715Sphkvoid rip_bcast(int); 517190715Sphkvoid supply(struct sockaddr_in *, struct interface *, 51819885Swollman enum output_type, int, int, int); 51918316Swollman 520190715Sphkvoid msglog(const char *, ...) PATTRIB(1,2); 52119885Swollmanstruct msg_limit { 52220342Swollman time_t reuse; 52320342Swollman struct msg_sub { 52419885Swollman naddr addr; 52519885Swollman time_t until; 52620342Swollman# define MSG_SUBJECT_N 8 52720342Swollman } subs[MSG_SUBJECT_N]; 52819885Swollman}; 529190715Sphkvoid msglim(struct msg_limit *, naddr, 53046303Smarkm const char *, ...) PATTRIB(3,4); 53118316Swollman#define LOGERR(msg) msglog(msg ": %s", strerror(errno)) 532190715Sphkvoid logbad(int, const char *, ...) PATTRIB(2,3); 53318316Swollman#define BADERR(dump,msg) logbad(dump,msg ": %s", strerror(errno)) 53418316Swollman#ifdef DEBUG 53518316Swollman#define DBGERR(dump,msg) BADERR(dump,msg) 53618316Swollman#else 53718316Swollman#define DBGERR(dump,msg) LOGERR(msg) 53818316Swollman#endif 539190715Sphkchar *naddr_ntoa(naddr); 540190715Sphkconst char *saddr_ntoa(struct sockaddr *); 54118316Swollman 542190715Sphkvoid *rtmalloc(size_t, const char *); 543190715Sphkvoid timevaladd(struct timeval *, struct timeval *); 544190715Sphkvoid intvl_random(struct timeval *, u_long, u_long); 545190715Sphkint getnet(char *, naddr *, naddr *); 546190715Sphkint gethost(char *, naddr *); 547190715Sphkvoid gwkludge(void); 548190715Sphkconst char *parse_parms(char *, int); 549190715Sphkconst char *check_parms(struct parm *); 550190715Sphkvoid get_parms(struct interface *); 55118316Swollman 552190715Sphkvoid lastlog(void); 553190715Sphkvoid trace_close(int); 554190715Sphkvoid set_tracefile(const char *, const char *, int); 555190715Sphkvoid tracelevel_msg(const char *, int); 556190715Sphkvoid trace_off(const char*, ...) PATTRIB(1,2); 557190715Sphkvoid set_tracelevel(void); 558190715Sphkvoid trace_flush(void); 559190715Sphkvoid trace_misc(const char *, ...) PATTRIB(1,2); 560190715Sphkvoid trace_act(const char *, ...) PATTRIB(1,2); 561190715Sphkvoid trace_pkt(const char *, ...) PATTRIB(1,2); 562190715Sphkvoid trace_add_del(const char *, struct rt_entry *); 563190715Sphkvoid trace_change(struct rt_entry *, u_int, struct rt_spare *, 56446303Smarkm const char *); 565190715Sphkvoid trace_if(const char *, struct interface *); 566190715Sphkvoid trace_upslot(struct rt_entry *, struct rt_spare *, 56746303Smarkm struct rt_spare *); 568190715Sphkvoid trace_rip(const char*, const char*, struct sockaddr_in *, 56918316Swollman struct interface *, struct rip *, int); 570190715Sphkchar *addrname(naddr, naddr, int); 571190715Sphkchar *rtname(naddr, naddr, naddr); 57218316Swollman 573190715Sphkvoid rdisc_age(naddr); 574190715Sphkvoid set_rdisc_mg(struct interface *, int); 575190715Sphkvoid set_supplier(void); 576190715Sphkvoid if_bad_rdisc(struct interface *); 577190715Sphkvoid if_ok_rdisc(struct interface *); 578190715Sphkvoid read_rip(int, struct interface *); 579190715Sphkvoid read_rt(void); 580190715Sphkvoid read_d(void); 581190715Sphkvoid rdisc_adv(void); 582190715Sphkvoid rdisc_sol(void); 58318316Swollman 584190715Sphkvoid sigtrace_on(int); 585190715Sphkvoid sigtrace_off(int); 58618316Swollman 587190715Sphkvoid flush_kern(void); 588190715Sphkvoid age(naddr); 58918316Swollman 590190715Sphkvoid ag_flush(naddr, naddr, void (*)(struct ag_info *)); 591190715Sphkvoid ag_check(naddr, naddr, naddr, naddr, char, char, u_int, 59218316Swollman u_short, u_short, void (*)(struct ag_info *)); 593190715Sphkvoid del_static(naddr, naddr, naddr, int); 594190715Sphkvoid del_redirects(naddr, time_t); 595190715Sphkstruct rt_entry *rtget(naddr, naddr); 596190715Sphkstruct rt_entry *rtfind(naddr); 597190715Sphkvoid rtinit(void); 598190715Sphkvoid rtadd(naddr, naddr, u_int, struct rt_spare *); 599190715Sphkvoid rtchange(struct rt_entry *, u_int, struct rt_spare *, char *); 600190715Sphkvoid rtdelete(struct rt_entry *); 601190715Sphkvoid rts_delete(struct rt_entry *, struct rt_spare *); 602190715Sphkvoid rtbad_sub(struct rt_entry *); 603190715Sphkvoid rtswitch(struct rt_entry *, struct rt_spare *); 60418316Swollman 60518316Swollman#define S_ADDR(x) (((struct sockaddr_in *)(x))->sin_addr.s_addr) 60618316Swollman#define INFO_DST(I) ((I)->rti_info[RTAX_DST]) 60718316Swollman#define INFO_GATE(I) ((I)->rti_info[RTAX_GATEWAY]) 60818316Swollman#define INFO_MASK(I) ((I)->rti_info[RTAX_NETMASK]) 60918316Swollman#define INFO_IFA(I) ((I)->rti_info[RTAX_IFA]) 61018316Swollman#define INFO_AUTHOR(I) ((I)->rti_info[RTAX_AUTHOR]) 61118316Swollman#define INFO_BRD(I) ((I)->rti_info[RTAX_BRD]) 61218316Swollmanvoid rt_xaddrs(struct rt_addrinfo *, struct sockaddr *, struct sockaddr *, 61318316Swollman int); 61418316Swollman 615190715Sphknaddr std_mask(naddr); 616190715Sphknaddr ripv1_mask_net(naddr, struct interface *); 617190715Sphknaddr ripv1_mask_host(naddr,struct interface *); 61818316Swollman#define on_net(a,net,mask) (((ntohl(a) ^ (net)) & (mask)) == 0) 619190715Sphkint check_dst(naddr); 620190715Sphkstruct interface *check_dup(naddr, naddr, naddr, int); 621190715Sphkint check_remote(struct interface *); 622190715Sphkvoid ifinit(void); 623190715Sphkint walk_bad(struct radix_node *, struct walkarg *); 624190715Sphkint if_ok(struct interface *, const char *); 625190715Sphkvoid if_sick(struct interface *); 626190715Sphkvoid if_link(struct interface *); 627190715Sphkstruct interface *ifwithaddr(naddr addr, int bcast, int remote); 628190715Sphkstruct interface *ifwithindex(u_short, int); 629190715Sphkstruct interface *iflookup(naddr); 63019885Swollman 631190715Sphkstruct auth *find_auth(struct interface *); 632190715Sphkvoid end_md5_auth(struct ws_buf *, struct auth *); 63319885Swollman 634126250Sbms#if defined(__FreeBSD__) || defined(__NetBSD__) 635126250Sbms#include <md5.h> 636126250Sbms#else 63746303Smarkm#define MD5_DIGEST_LEN 16 63846303Smarkmtypedef struct { 63946303Smarkm u_int32_t state[4]; /* state (ABCD) */ 64046303Smarkm u_int32_t count[2]; /* # of bits, modulo 2^64 (LSB 1st) */ 64146303Smarkm unsigned char buffer[64]; /* input buffer */ 64246303Smarkm} MD5_CTX; 643190715Sphkvoid MD5Init(MD5_CTX*); 644190715Sphkvoid MD5Update(MD5_CTX*, u_char*, u_int); 645190715Sphkvoid MD5Final(u_char[MD5_DIGEST_LEN], MD5_CTX*); 646126250Sbms#endif 647