route.h revision 17835
1178786Skmacy/* 2178786Skmacy * Copyright (c) 1980, 1986, 1993 3178786Skmacy * The Regents of the University of California. All rights reserved. 4178786Skmacy * 5178786Skmacy * Redistribution and use in source and binary forms, with or without 6178786Skmacy * modification, are permitted provided that the following conditions 7178786Skmacy * are met: 8178786Skmacy * 1. Redistributions of source code must retain the above copyright 9178786Skmacy * notice, this list of conditions and the following disclaimer. 10178786Skmacy * 2. Redistributions in binary form must reproduce the above copyright 11178786Skmacy * notice, this list of conditions and the following disclaimer in the 12178786Skmacy * documentation and/or other materials provided with the distribution. 13178786Skmacy * 3. All advertising materials mentioning features or use of this software 14178786Skmacy * must display the following acknowledgement: 15178786Skmacy * This product includes software developed by the University of 16178786Skmacy * California, Berkeley and its contributors. 17178786Skmacy * 4. Neither the name of the University nor the names of its contributors 18178786Skmacy * may be used to endorse or promote products derived from this software 19178786Skmacy * without specific prior written permission. 20178786Skmacy * 21178786Skmacy * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22178786Skmacy * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23178786Skmacy * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24178786Skmacy * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25178786Skmacy * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26178786Skmacy * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27178786Skmacy * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28178786Skmacy * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29178786Skmacy * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30178786Skmacy * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31178786Skmacy * SUCH DAMAGE. 32178786Skmacy * 33178786Skmacy * @(#)route.h 8.3 (Berkeley) 4/19/94 34237263Snp * $Id: route.h,v 1.21 1996/05/06 17:42:08 wollman Exp $ 35178786Skmacy */ 36178786Skmacy 37178786Skmacy#ifndef _NET_ROUTE_H_ 38178786Skmacy#define _NET_ROUTE_H_ 39178786Skmacy 40178786Skmacy/* 41178786Skmacy * Kernel resident routing tables. 42178786Skmacy * 43178786Skmacy * The routing tables are initialized when interface addresses 44178786Skmacy * are set by making entries for all directly connected interfaces. 45178786Skmacy */ 46178786Skmacy 47178786Skmacy/* 48178786Skmacy * A route consists of a destination address and a reference 49178786Skmacy * to a routing entry. These are often held by protocols 50178786Skmacy * in their control blocks, e.g. inpcb. 51178786Skmacy */ 52178786Skmacystruct route { 53178786Skmacy struct rtentry *ro_rt; 54178786Skmacy struct sockaddr ro_dst; 55178786Skmacy}; 56178786Skmacy 57178786Skmacy/* 58178786Skmacy * These numbers are used by reliable protocols for determining 59178786Skmacy * retransmission behavior and are included in the routing structure. 60178786Skmacy */ 61178786Skmacystruct rt_metrics { 62178786Skmacy u_long rmx_locks; /* Kernel must leave these values alone */ 63178786Skmacy u_long rmx_mtu; /* MTU for this path */ 64178786Skmacy u_long rmx_hopcount; /* max hops expected */ 65178786Skmacy u_long rmx_expire; /* lifetime for route, e.g. redirect */ 66178786Skmacy u_long rmx_recvpipe; /* inbound delay-bandwidth product */ 67178786Skmacy u_long rmx_sendpipe; /* outbound delay-bandwidth product */ 68178786Skmacy u_long rmx_ssthresh; /* outbound gateway buffer limit */ 69178786Skmacy u_long rmx_rtt; /* estimated round trip time */ 70178786Skmacy u_long rmx_rttvar; /* estimated rtt variance */ 71178786Skmacy u_long rmx_pksent; /* packets sent using this route */ 72178786Skmacy u_long rmx_filler[4]; /* will be used for T/TCP later */ 73178786Skmacy}; 74178786Skmacy 75178786Skmacy/* 76178786Skmacy * rmx_rtt and rmx_rttvar are stored as microseconds; 77178786Skmacy * RTTTOPRHZ(rtt) converts to a value suitable for use 78178786Skmacy * by a protocol slowtimo counter. 79178786Skmacy */ 80178786Skmacy#define RTM_RTTUNIT 1000000 /* units for rtt, rttvar, as units per sec */ 81178786Skmacy#define RTTTOPRHZ(r) ((r) / (RTM_RTTUNIT / PR_SLOWHZ)) 82178786Skmacy 83178786Skmacy/* 84178786Skmacy * XXX kernel function pointer `rt_output' is visible to applications. 85178786Skmacy */ 86178786Skmacystruct mbuf; 87178786Skmacy 88178786Skmacy/* 89178786Skmacy * We distinguish between routes to hosts and routes to networks, 90178786Skmacy * preferring the former if available. For each route we infer 91178786Skmacy * the interface to use from the gateway address supplied when 92178786Skmacy * the route was entered. Routes that forward packets through 93178786Skmacy * gateways are marked so that the output routines know to address the 94178786Skmacy * gateway rather than the ultimate destination. 95178786Skmacy */ 96178786Skmacy#ifndef RNF_NORMAL 97178786Skmacy#include <net/radix.h> 98178786Skmacy#endif 99178786Skmacystruct rtentry { 100178786Skmacy struct radix_node rt_nodes[2]; /* tree glue, and other values */ 101178786Skmacy#define rt_key(r) ((struct sockaddr *)((r)->rt_nodes->rn_key)) 102178786Skmacy#define rt_mask(r) ((struct sockaddr *)((r)->rt_nodes->rn_mask)) 103178786Skmacy struct sockaddr *rt_gateway; /* value */ 104178786Skmacy short rt_filler; /* was short flags field */ 105178786Skmacy short rt_refcnt; /* # held references */ 106178786Skmacy u_long rt_flags; /* up/down?, host/net */ 107178786Skmacy struct ifnet *rt_ifp; /* the answer: interface to use */ 108178786Skmacy struct ifaddr *rt_ifa; /* the answer: interface to use */ 109178786Skmacy struct sockaddr *rt_genmask; /* for generation of cloned routes */ 110178786Skmacy caddr_t rt_llinfo; /* pointer to link level info cache */ 111178786Skmacy struct rt_metrics rt_rmx; /* metrics used by rx'ing protocols */ 112178786Skmacy struct rtentry *rt_gwroute; /* implied entry for gatewayed routes */ 113178786Skmacy int (*rt_output) __P((struct ifnet *, struct mbuf *, 114178786Skmacy struct sockaddr *, struct rtentry *)); 115178786Skmacy /* output routine for this (rt,if) */ 116178786Skmacy struct rtentry *rt_parent; /* cloning parent of this route */ 117178786Skmacy void *rt_filler2; /* more filler */ 118178786Skmacy}; 119237263Snp 120178786Skmacy/* 121178786Skmacy * Following structure necessary for 4.3 compatibility; 122178786Skmacy * We should eventually move it to a compat file. 123178786Skmacy */ 124178786Skmacystruct ortentry { 125178786Skmacy u_long rt_hash; /* to speed lookups */ 126178786Skmacy struct sockaddr rt_dst; /* key */ 127178786Skmacy struct sockaddr rt_gateway; /* value */ 128178786Skmacy short rt_flags; /* up/down?, host/net */ 129178786Skmacy short rt_refcnt; /* # held references */ 130178786Skmacy u_long rt_use; /* raw # packets forwarded */ 131178786Skmacy struct ifnet *rt_ifp; /* the answer: interface to use */ 132178786Skmacy}; 133178786Skmacy 134178786Skmacy#define rt_use rt_rmx.rmx_pksent 135178786Skmacy 136178786Skmacy#define RTF_UP 0x1 /* route usable */ 137178786Skmacy#define RTF_GATEWAY 0x2 /* destination is a gateway */ 138178786Skmacy#define RTF_HOST 0x4 /* host entry (net otherwise) */ 139178786Skmacy#define RTF_REJECT 0x8 /* host or net unreachable */ 140178786Skmacy#define RTF_DYNAMIC 0x10 /* created dynamically (by redirect) */ 141178786Skmacy#define RTF_MODIFIED 0x20 /* modified dynamically (by redirect) */ 142178786Skmacy#define RTF_DONE 0x40 /* message confirmed */ 143178786Skmacy#define RTF_MASK 0x80 /* subnet mask present */ 144178786Skmacy#define RTF_CLONING 0x100 /* generate new routes on use */ 145178786Skmacy#define RTF_XRESOLVE 0x200 /* external daemon resolves name */ 146178786Skmacy#define RTF_LLINFO 0x400 /* generated by link layer (e.g. ARP) */ 147178786Skmacy#define RTF_STATIC 0x800 /* manually added */ 148178786Skmacy#define RTF_BLACKHOLE 0x1000 /* just discard pkts (during updates) */ 149178786Skmacy#define RTF_PROTO2 0x4000 /* protocol specific routing flag */ 150178786Skmacy#define RTF_PROTO1 0x8000 /* protocol specific routing flag */ 151178786Skmacy 152178786Skmacy#define RTF_PRCLONING 0x10000 /* protocol requires cloning */ 153178786Skmacy#define RTF_WASCLONED 0x20000 /* route generated through cloning */ 154178786Skmacy#define RTF_PROTO3 0x40000 /* protocol specific routing flag */ 155178786Skmacy#define RTF_CHAINDELETE 0x80000 /* chain is being deleted (internal) */ 156178786Skmacy#define RTF_PINNED 0x100000 /* future use */ 157178786Skmacy#define RTF_LOCAL 0x200000 /* route represents a local address */ 158178786Skmacy#define RTF_BROADCAST 0x400000 /* route represents a bcast address */ 159178786Skmacy#define RTF_MULTICAST 0x800000 /* route represents a mcast address */ 160178786Skmacy /* 0x1000000 and up unassigned */ 161178786Skmacy 162178786Skmacy/* 163178786Skmacy * Routing statistics. 164178786Skmacy */ 165178786Skmacystruct rtstat { 166178786Skmacy short rts_badredirect; /* bogus redirect calls */ 167178786Skmacy short rts_dynamic; /* routes created by redirects */ 168178786Skmacy short rts_newgateway; /* routes modified by redirects */ 169178786Skmacy short rts_unreach; /* lookups which failed */ 170178786Skmacy short rts_wildcard; /* lookups satisfied by a wildcard */ 171178786Skmacy}; 172178786Skmacy/* 173178786Skmacy * Structures for routing messages. 174178786Skmacy */ 175178786Skmacystruct rt_msghdr { 176178786Skmacy u_short rtm_msglen; /* to skip over non-understood messages */ 177178786Skmacy u_char rtm_version; /* future binary compatibility */ 178178786Skmacy u_char rtm_type; /* message type */ 179178786Skmacy u_short rtm_index; /* index for associated ifp */ 180178786Skmacy int rtm_flags; /* flags, incl. kern & message, e.g. DONE */ 181178786Skmacy int rtm_addrs; /* bitmask identifying sockaddrs in msg */ 182178786Skmacy pid_t rtm_pid; /* identify sender */ 183178786Skmacy int rtm_seq; /* for sender to identify action */ 184178786Skmacy int rtm_errno; /* why failed */ 185178786Skmacy int rtm_use; /* from rtentry */ 186178786Skmacy u_long rtm_inits; /* which metrics we are initializing */ 187178786Skmacy struct rt_metrics rtm_rmx; /* metrics themselves */ 188178786Skmacy}; 189178786Skmacy 190178786Skmacy#define RTM_VERSION 5 /* Up the ante and ignore older versions */ 191178786Skmacy 192178786Skmacy#define RTM_ADD 0x1 /* Add Route */ 193178786Skmacy#define RTM_DELETE 0x2 /* Delete Route */ 194178786Skmacy#define RTM_CHANGE 0x3 /* Change Metrics or flags */ 195178786Skmacy#define RTM_GET 0x4 /* Report Metrics */ 196178786Skmacy#define RTM_LOSING 0x5 /* Kernel Suspects Partitioning */ 197178786Skmacy#define RTM_REDIRECT 0x6 /* Told to use different route */ 198178786Skmacy#define RTM_MISS 0x7 /* Lookup failed on this address */ 199178786Skmacy#define RTM_LOCK 0x8 /* fix specified metrics */ 200178786Skmacy#define RTM_OLDADD 0x9 /* caused by SIOCADDRT */ 201178786Skmacy#define RTM_OLDDEL 0xa /* caused by SIOCDELRT */ 202178786Skmacy#define RTM_RESOLVE 0xb /* req to resolve dst to LL addr */ 203178786Skmacy#define RTM_NEWADDR 0xc /* address being added to iface */ 204178786Skmacy#define RTM_DELADDR 0xd /* address being removed from iface */ 205178786Skmacy#define RTM_IFINFO 0xe /* iface going up/down etc. */ 206178786Skmacy 207178786Skmacy#define RTV_MTU 0x1 /* init or lock _mtu */ 208178786Skmacy#define RTV_HOPCOUNT 0x2 /* init or lock _hopcount */ 209178786Skmacy#define RTV_EXPIRE 0x4 /* init or lock _hopcount */ 210178786Skmacy#define RTV_RPIPE 0x8 /* init or lock _recvpipe */ 211178786Skmacy#define RTV_SPIPE 0x10 /* init or lock _sendpipe */ 212178786Skmacy#define RTV_SSTHRESH 0x20 /* init or lock _ssthresh */ 213178786Skmacy#define RTV_RTT 0x40 /* init or lock _rtt */ 214178786Skmacy#define RTV_RTTVAR 0x80 /* init or lock _rttvar */ 215178786Skmacy 216178786Skmacy/* 217178786Skmacy * Bitmask values for rtm_addr. 218178786Skmacy */ 219178786Skmacy#define RTA_DST 0x1 /* destination sockaddr present */ 220178786Skmacy#define RTA_GATEWAY 0x2 /* gateway sockaddr present */ 221178786Skmacy#define RTA_NETMASK 0x4 /* netmask sockaddr present */ 222178786Skmacy#define RTA_GENMASK 0x8 /* cloning mask sockaddr present */ 223178786Skmacy#define RTA_IFP 0x10 /* interface name sockaddr present */ 224178786Skmacy#define RTA_IFA 0x20 /* interface addr sockaddr present */ 225178786Skmacy#define RTA_AUTHOR 0x40 /* sockaddr for author of redirect */ 226178786Skmacy#define RTA_BRD 0x80 /* for NEWADDR, broadcast or p-p dest addr */ 227178786Skmacy 228178786Skmacy/* 229178786Skmacy * Index offsets for sockaddr array for alternate internal encoding. 230178786Skmacy */ 231178786Skmacy#define RTAX_DST 0 /* destination sockaddr present */ 232178786Skmacy#define RTAX_GATEWAY 1 /* gateway sockaddr present */ 233178786Skmacy#define RTAX_NETMASK 2 /* netmask sockaddr present */ 234178786Skmacy#define RTAX_GENMASK 3 /* cloning mask sockaddr present */ 235178786Skmacy#define RTAX_IFP 4 /* interface name sockaddr present */ 236178786Skmacy#define RTAX_IFA 5 /* interface addr sockaddr present */ 237178786Skmacy#define RTAX_AUTHOR 6 /* sockaddr for author of redirect */ 238178786Skmacy#define RTAX_BRD 7 /* for NEWADDR, broadcast or p-p dest addr */ 239178786Skmacy#define RTAX_MAX 8 /* size of array to allocate */ 240178786Skmacy 241178786Skmacystruct rt_addrinfo { 242178786Skmacy int rti_addrs; 243178786Skmacy struct sockaddr *rti_info[RTAX_MAX]; 244178786Skmacy}; 245178786Skmacy 246178786Skmacystruct route_cb { 247178786Skmacy int ip_count; 248178786Skmacy int ipx_count; 249178786Skmacy int ns_count; 250178786Skmacy int iso_count; 251178786Skmacy int any_count; 252178786Skmacy}; 253178786Skmacy 254178786Skmacy#ifdef KERNEL 255178786Skmacy#define RTFREE(rt) \ 256178786Skmacy if ((rt)->rt_refcnt <= 1) \ 257178786Skmacy rtfree(rt); \ 258178786Skmacy else \ 259178786Skmacy (rt)->rt_refcnt--; 260178786Skmacy 261178786Skmacyextern struct route_cb route_cb; 262178786Skmacyextern struct rtstat rtstat; 263178786Skmacyextern struct radix_node_head *rt_tables[AF_MAX+1]; 264178786Skmacy 265178786Skmacyvoid route_init __P((void)); 266178786Skmacyvoid rt_ifmsg __P((struct ifnet *)); 267178786Skmacyvoid rt_missmsg __P((int, struct rt_addrinfo *, int, int)); 268178786Skmacyvoid rt_newaddrmsg __P((int, struct ifaddr *, int, struct rtentry *)); 269178786Skmacyint rt_setgate __P((struct rtentry *, 270178786Skmacy struct sockaddr *, struct sockaddr *)); 271178786Skmacyvoid rtalloc __P((struct route *)); 272178786Skmacyvoid rtalloc_ign __P((struct route *, unsigned long)); 273178786Skmacystruct rtentry * 274178786Skmacy rtalloc1 __P((struct sockaddr *, int, unsigned long)); 275178786Skmacyvoid rtfree __P((struct rtentry *)); 276178786Skmacyint rtinit __P((struct ifaddr *, int, int)); 277178786Skmacyint rtioctl __P((int, caddr_t, struct proc *)); 278178786Skmacyvoid rtredirect __P((struct sockaddr *, struct sockaddr *, 279178786Skmacy struct sockaddr *, int, struct sockaddr *, struct rtentry **)); 280178786Skmacyint rtrequest __P((int, struct sockaddr *, 281178786Skmacy struct sockaddr *, struct sockaddr *, int, struct rtentry **)); 282178786Skmacy#endif 283178786Skmacy 284178786Skmacy#endif 285178786Skmacy