route.h revision 4104
11195Srgrimes/* 21371Srgrimes * Copyright (c) 1980, 1986, 1993 337Srgrimes * The Regents of the University of California. All rights reserved. 4358Srgrimes * 537Srgrimes * Redistribution and use in source and binary forms, with or without 637Srgrimes * modification, are permitted provided that the following conditions 737Srgrimes * are met: 8147Srgrimes * 1. Redistributions of source code must retain the above copyright 9147Srgrimes * notice, this list of conditions and the following disclaimer. 10147Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 11207Snate * notice, this list of conditions and the following disclaimer in the 12377Srgrimes * documentation and/or other materials provided with the distribution. 13147Srgrimes * 3. All advertising materials mentioning features or use of this software 14147Srgrimes * must display the following acknowledgement: 1537Srgrimes * This product includes software developed by the University of 1637Srgrimes * California, Berkeley and its contributors. 1737Srgrimes * 4. Neither the name of the University nor the names of its contributors 1837Srgrimes * may be used to endorse or promote products derived from this software 19147Srgrimes * without specific prior written permission. 20147Srgrimes * 21147Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22491Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2337Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2437Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2537Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2637Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2737Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28263Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 291130Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30993Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 311126Srgrimes * SUCH DAMAGE. 32993Srgrimes * 33277Srgrimes * @(#)route.h 8.3 (Berkeley) 4/19/94 34277Srgrimes * $Id: route.h,v 1.4 1994/08/21 05:11:46 paul Exp $ 35284Srgrimes */ 36463Srgrimes 371205Srgrimes#ifndef _NET_ROUTE_H_ 38284Srgrimes#define _NET_ROUTE_H_ 39284Srgrimes 40284Srgrimes/* 41284Srgrimes * Kernel resident routing tables. 42284Srgrimes * 431285Srgrimes * The routing tables are initialized when interface addresses 44284Srgrimes * are set by making entries for all directly connected interfaces. 451194Srgrimes */ 461285Srgrimes 471194Srgrimes/* 481285Srgrimes * A route consists of a destination address and a reference 491285Srgrimes * to a routing entry. These are often held by protocols 50284Srgrimes * in their control blocks, e.g. inpcb. 511371Srgrimes */ 521371Srgrimesstruct route { 531194Srgrimes struct rtentry *ro_rt; 54358Srgrimes struct sockaddr ro_dst; 55358Srgrimes}; 561194Srgrimes 57412Salm/* 58358Srgrimes * These numbers are used by reliable protocols for determining 59452Srgrimes * retransmission behavior and are included in the routing structure. 60358Srgrimes */ 611194Srgrimesstruct rt_metrics { 621194Srgrimes u_long rmx_locks; /* Kernel must leave these values alone */ 631194Srgrimes u_long rmx_mtu; /* MTU for this path */ 641194Srgrimes u_long rmx_hopcount; /* max hops expected */ 651194Srgrimes u_long rmx_expire; /* lifetime for route, e.g. redirect */ 661194Srgrimes u_long rmx_recvpipe; /* inbound delay-bandwith product */ 671194Srgrimes u_long rmx_sendpipe; /* outbound delay-bandwith product */ 681194Srgrimes u_long rmx_ssthresh; /* outbound gateway buffer limit */ 691194Srgrimes u_long rmx_rtt; /* estimated round trip time */ 701194Srgrimes u_long rmx_rttvar; /* estimated rtt variance */ 711194Srgrimes u_long rmx_pksent; /* packets sent using this route */ 721194Srgrimes}; 731194Srgrimes 741194Srgrimes/* 751194Srgrimes * rmx_rtt and rmx_rttvar are stored as microseconds; 761194Srgrimes * RTTTOPRHZ(rtt) converts to a value suitable for use 771194Srgrimes * by a protocol slowtimo counter. 781194Srgrimes */ 791194Srgrimes#define RTM_RTTUNIT 1000000 /* units for rtt, rttvar, as units per sec */ 801194Srgrimes#define RTTTOPRHZ(r) ((r) / (RTM_RTTUNIT / PR_SLOWHZ)) 811243Srgrimes 82263Srgrimes/* 83358Srgrimes * We distinguish between routes to hosts and routes to networks, 841194Srgrimes * preferring the former if available. For each route we infer 851194Srgrimes * the interface to use from the gateway address supplied when 861194Srgrimes * the route was entered. Routes that forward packets through 871194Srgrimes * gateways are marked so that the output routines know to address the 88452Srgrimes * gateway rather than the ultimate destination. 891194Srgrimes */ 90452Srgrimes#ifndef RNF_NORMAL 911194Srgrimes#include <net/radix.h> 921194Srgrimes#endif 93358Srgrimesstruct rtentry { 941194Srgrimes struct radix_node rt_nodes[2]; /* tree glue, and other values */ 951194Srgrimes#define rt_key(r) ((struct sockaddr *)((r)->rt_nodes->rn_key)) 961194Srgrimes#define rt_mask(r) ((struct sockaddr *)((r)->rt_nodes->rn_mask)) 971194Srgrimes struct sockaddr *rt_gateway; /* value */ 981194Srgrimes /* XXX - rt_flags should be unified with rt_prflags */ 991194Srgrimes short rt_flags; /* up/down?, host/net */ 1001194Srgrimes short rt_refcnt; /* # held references */ 1011194Srgrimes u_long rt_prflags; /* protocol-specific flags */ 1021243Srgrimes struct ifnet *rt_ifp; /* the answer: interface to use */ 1031194Srgrimes struct ifaddr *rt_ifa; /* the answer: interface to use */ 1041194Srgrimes struct sockaddr *rt_genmask; /* for generation of cloned routes */ 1051243Srgrimes caddr_t rt_llinfo; /* pointer to link level info cache */ 1061243Srgrimes struct rt_metrics rt_rmx; /* metrics used by rx'ing protocols */ 107284Srgrimes struct rtentry *rt_gwroute; /* implied entry for gatewayed routes */ 108347Srgrimes}; 109372Srgrimes 110372Srgrimes/* 111372Srgrimes * Following structure necessary for 4.3 compatibility; 1121126Srgrimes * We should eventually move it to a compat file. 113372Srgrimes */ 114372Srgrimesstruct ortentry { 1151126Srgrimes u_long rt_hash; /* to speed lookups */ 116347Srgrimes struct sockaddr rt_dst; /* key */ 11737Srgrimes struct sockaddr rt_gateway; /* value */ 11837Srgrimes short rt_flags; /* up/down?, host/net */ 119347Srgrimes short rt_refcnt; /* # held references */ 120347Srgrimes u_long rt_use; /* raw # packets forwarded */ 121347Srgrimes struct ifnet *rt_ifp; /* the answer: interface to use */ 122355Srgrimes}; 123372Srgrimes 124347Srgrimes#define rt_use rt_rmx.rmx_pksent 125355Srgrimes 126347Srgrimes#define RTF_UP 0x1 /* route usable */ 127347Srgrimes#define RTF_GATEWAY 0x2 /* destination is a gateway */ 128347Srgrimes#define RTF_HOST 0x4 /* host entry (net otherwise) */ 129347Srgrimes#define RTF_REJECT 0x8 /* host or net unreachable */ 130372Srgrimes#define RTF_DYNAMIC 0x10 /* created dynamically (by redirect) */ 131347Srgrimes#define RTF_MODIFIED 0x20 /* modified dynamically (by redirect) */ 132355Srgrimes#define RTF_DONE 0x40 /* message confirmed */ 133347Srgrimes#define RTF_MASK 0x80 /* subnet mask present */ 134347Srgrimes#define RTF_CLONING 0x100 /* generate new routes on use */ 135147Srgrimes#define RTF_XRESOLVE 0x200 /* external daemon resolves name */ 13637Srgrimes#define RTF_LLINFO 0x400 /* generated by ARP or ESIS */ 13737Srgrimes#define RTF_STATIC 0x800 /* manually added */ 138147Srgrimes#define RTF_BLACKHOLE 0x1000 /* just discard pkts (during updates) */ 1391014Snate#define RTF_PROTO2 0x4000 /* protocol specific routing flag */ 140238Sroot#define RTF_PROTO1 0x8000 /* protocol specific routing flag */ 14137Srgrimes 142358Srgrimes#define RTPRF_WASCLONED 0x1 /* route generated through cloning */ 14337Srgrimes 14437Srgrimes/* 145347Srgrimes * Routing statistics. 146147Srgrimes */ 147347Srgrimesstruct rtstat { 14837Srgrimes short rts_badredirect; /* bogus redirect calls */ 14937Srgrimes short rts_dynamic; /* routes created by redirects */ 15037Srgrimes short rts_newgateway; /* routes modified by redirects */ 15137Srgrimes short rts_unreach; /* lookups which failed */ 15237Srgrimes short rts_wildcard; /* lookups satisfied by a wildcard */ 15337Srgrimes}; 15437Srgrimes/* 15537Srgrimes * Structures for routing messages. 15637Srgrimes */ 15737Srgrimesstruct rt_msghdr { 15837Srgrimes u_short rtm_msglen; /* to skip over non-understood messages */ 15937Srgrimes u_char rtm_version; /* future binary compatibility */ 16037Srgrimes u_char rtm_type; /* message type */ 16137Srgrimes u_short rtm_index; /* index for associated ifp */ 16237Srgrimes int rtm_flags; /* flags, incl. kern & message, e.g. DONE */ 16337Srgrimes int rtm_addrs; /* bitmask identifying sockaddrs in msg */ 16437Srgrimes pid_t rtm_pid; /* identify sender */ 16537Srgrimes int rtm_seq; /* for sender to identify action */ 166147Srgrimes int rtm_errno; /* why failed */ 167147Srgrimes int rtm_use; /* from rtentry */ 16837Srgrimes u_long rtm_inits; /* which metrics we are initializing */ 169147Srgrimes struct rt_metrics rtm_rmx; /* metrics themselves */ 17037Srgrimes}; 17137Srgrimes 17237Srgrimes#define RTM_VERSION 3 /* Up the ante and ignore older versions */ 173288Srgrimes 174288Srgrimes#define RTM_ADD 0x1 /* Add Route */ 175147Srgrimes#define RTM_DELETE 0x2 /* Delete Route */ 17637Srgrimes#define RTM_CHANGE 0x3 /* Change Metrics or flags */ 177147Srgrimes#define RTM_GET 0x4 /* Report Metrics */ 178147Srgrimes#define RTM_LOSING 0x5 /* Kernel Suspects Partitioning */ 17937Srgrimes#define RTM_REDIRECT 0x6 /* Told to use different route */ 18037Srgrimes#define RTM_MISS 0x7 /* Lookup failed on this address */ 181147Srgrimes#define RTM_LOCK 0x8 /* fix specified metrics */ 182347Srgrimes#define RTM_OLDADD 0x9 /* caused by SIOCADDRT */ 183355Srgrimes#define RTM_OLDDEL 0xa /* caused by SIOCDELRT */ 184355Srgrimes#define RTM_RESOLVE 0xb /* req to resolve dst to LL addr */ 185347Srgrimes#define RTM_NEWADDR 0xc /* address being added to iface */ 186355Srgrimes#define RTM_DELADDR 0xd /* address being removed from iface */ 187355Srgrimes#define RTM_IFINFO 0xe /* iface going up/down etc. */ 188347Srgrimes 189277Srgrimes#define RTV_MTU 0x1 /* init or lock _mtu */ 190355Srgrimes#define RTV_HOPCOUNT 0x2 /* init or lock _hopcount */ 191277Srgrimes#define RTV_EXPIRE 0x4 /* init or lock _hopcount */ 1921126Srgrimes#define RTV_RPIPE 0x8 /* init or lock _recvpipe */ 1931126Srgrimes#define RTV_SPIPE 0x10 /* init or lock _sendpipe */ 1941133Srgrimes#define RTV_SSTHRESH 0x20 /* init or lock _ssthresh */ 195238Sroot#define RTV_RTT 0x40 /* init or lock _rtt */ 196277Srgrimes#define RTV_RTTVAR 0x80 /* init or lock _rttvar */ 197277Srgrimes 198355Srgrimes/* 199644Srgrimes * Bitmask values for rtm_addr. 200333Srgrimes */ 201333Srgrimes#define RTA_DST 0x1 /* destination sockaddr present */ 202333Srgrimes#define RTA_GATEWAY 0x2 /* gateway sockaddr present */ 203168Srgrimes#define RTA_NETMASK 0x4 /* netmask sockaddr present */ 204333Srgrimes#define RTA_GENMASK 0x8 /* cloning mask sockaddr present */ 205333Srgrimes#define RTA_IFP 0x10 /* interface name sockaddr present */ 206333Srgrimes#define RTA_IFA 0x20 /* interface addr sockaddr present */ 207333Srgrimes#define RTA_AUTHOR 0x40 /* sockaddr for author of redirect */ 20837Srgrimes#define RTA_BRD 0x80 /* for NEWADDR, broadcast or p-p dest addr */ 20937Srgrimes 21037Srgrimes/* 21137Srgrimes * Index offsets for sockaddr array for alternate internal encoding. 21237Srgrimes */ 213358Srgrimes#define RTAX_DST 0 /* destination sockaddr present */ 214320Srgrimes#define RTAX_GATEWAY 1 /* gateway sockaddr present */ 215320Srgrimes#define RTAX_NETMASK 2 /* netmask sockaddr present */ 216355Srgrimes#define RTAX_GENMASK 3 /* cloning mask sockaddr present */ 217320Srgrimes#define RTAX_IFP 4 /* interface name sockaddr present */ 218320Srgrimes#define RTAX_IFA 5 /* interface addr sockaddr present */ 219355Srgrimes#define RTAX_AUTHOR 6 /* sockaddr for author of redirect */ 220320Srgrimes#define RTAX_BRD 7 /* for NEWADDR, broadcast or p-p dest addr */ 221320Srgrimes#define RTAX_MAX 8 /* size of array to allocate */ 222320Srgrimes 223358Srgrimesstruct rt_addrinfo { 224568Srgrimes int rti_addrs; 225568Srgrimes struct sockaddr *rti_info[RTAX_MAX]; 2261285Srgrimes}; 2271027Sache 2281027Sachestruct route_cb { 229333Srgrimes int ip_count; 230333Srgrimes int ns_count; 231284Srgrimes int iso_count; 232320Srgrimes int any_count; 233277Srgrimes}; 234277Srgrimes 235277Srgrimes#ifdef KERNEL 2361371Srgrimes#define RTFREE(rt) \ 2371371Srgrimes if ((rt)->rt_refcnt <= 1) \ 2381371Srgrimes rtfree(rt); \ 2391371Srgrimes else \ 240284Srgrimes (rt)->rt_refcnt--; 241320Srgrimes 242277Srgrimesstruct route_cb route_cb; 243277Srgrimesstruct rtstat rtstat; 2441194Srgrimesstruct radix_node_head *rt_tables[AF_MAX+1]; 2451194Srgrimes 2461194Srgrimesvoid route_init __P((void)); 2471194Srgrimesint route_output __P((struct mbuf *, struct socket *)); 2481194Srgrimesint route_usrreq __P((struct socket *, 2491194Srgrimes int, struct mbuf *, struct mbuf *, struct mbuf *)); 250320Srgrimesvoid rt_ifmsg __P((struct ifnet *)); 2511205Srgrimesvoid rt_maskedcopy __P((struct sockaddr *, 252372Srgrimes struct sockaddr *, struct sockaddr *)); 253320Srgrimesvoid rt_missmsg __P((int, struct rt_addrinfo *, int, int)); 254277Srgrimesvoid rt_newaddrmsg __P((int, struct ifaddr *, int, struct rtentry *)); 255277Srgrimesint rt_setgate __P((struct rtentry *, 2561027Sache struct sockaddr *, struct sockaddr *)); 2571027Sachevoid rt_setmetrics __P((u_long, struct rt_metrics *, struct rt_metrics *)); 2581205Srgrimesvoid rtable_init __P((void **)); 259358Srgrimesvoid rtalloc __P((struct route *)); 2601205Srgrimesstruct rtentry * 2611205Srgrimes rtalloc1 __P((struct sockaddr *, int)); 262277Srgrimesvoid rtfree __P((struct rtentry *)); 2631205Srgrimesint rtinit __P((struct ifaddr *, int, int)); 264372Srgrimesint rtioctl __P((int, caddr_t, struct proc *)); 265320Srgrimesvoid rtredirect __P((struct sockaddr *, struct sockaddr *, 266320Srgrimes struct sockaddr *, int, struct sockaddr *, struct rtentry **)); 267320Srgrimesint rtrequest __P((int, struct sockaddr *, 2681027Sache struct sockaddr *, struct sockaddr *, int, struct rtentry **)); 2691027Sache#endif 2701205Srgrimes 271358Srgrimes#endif 2721205Srgrimes