home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / amiga / os / bsdss4.tz / bsdss4 / bsdss / server / net / route.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-22  |  9.5 KB  |  260 lines

  1. /* 
  2.  * Mach Operating System
  3.  * Copyright (c) 1992 Carnegie Mellon University
  4.  * All Rights Reserved.
  5.  * 
  6.  * Permission to use, copy, modify and distribute this software and its
  7.  * documentation is hereby granted, provided that both the copyright
  8.  * notice and this permission notice appear in all copies of the
  9.  * software, derivative works or modified versions, and any portions
  10.  * thereof, and that both notices appear in supporting documentation.
  11.  * 
  12.  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
  13.  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
  14.  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  15.  * 
  16.  * Carnegie Mellon requests users of this software to return to
  17.  * 
  18.  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
  19.  *  School of Computer Science
  20.  *  Carnegie Mellon University
  21.  *  Pittsburgh PA 15213-3890
  22.  * 
  23.  * any improvements or extensions that they make and grant Carnegie Mellon 
  24.  * the rights to redistribute these changes.
  25.  */
  26. /*
  27.  * HISTORY
  28.  * $Log:    route.h,v $
  29.  * Revision 2.1  92/04/21  17:13:52  rwd
  30.  * BSDSS
  31.  * 
  32.  *
  33.  */
  34.  
  35. /*
  36.  * Copyright (c) 1980, 1986 Regents of the University of California.
  37.  * All rights reserved.
  38.  *
  39.  * Redistribution and use in source and binary forms, with or without
  40.  * modification, are permitted provided that the following conditions
  41.  * are met:
  42.  * 1. Redistributions of source code must retain the above copyright
  43.  *    notice, this list of conditions and the following disclaimer.
  44.  * 2. Redistributions in binary form must reproduce the above copyright
  45.  *    notice, this list of conditions and the following disclaimer in the
  46.  *    documentation and/or other materials provided with the distribution.
  47.  * 3. All advertising materials mentioning features or use of this software
  48.  *    must display the following acknowledgement:
  49.  *    This product includes software developed by the University of
  50.  *    California, Berkeley and its contributors.
  51.  * 4. Neither the name of the University nor the names of its contributors
  52.  *    may be used to endorse or promote products derived from this software
  53.  *    without specific prior written permission.
  54.  *
  55.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  56.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  57.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  58.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  59.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  60.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  61.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  62.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  63.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  64.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  65.  * SUCH DAMAGE.
  66.  *
  67.  *    @(#)route.h    7.13 (Berkeley) 4/25/91
  68.  */
  69.  
  70. #include <gateway.h>
  71.  
  72. /*
  73.  * Kernel resident routing tables.
  74.  * 
  75.  * The routing tables are initialized when interface addresses
  76.  * are set by making entries for all directly connected interfaces.
  77.  */
  78.  
  79. /*
  80.  * A route consists of a destination address and a reference
  81.  * to a routing entry.  These are often held by protocols
  82.  * in their control blocks, e.g. inpcb.
  83.  */
  84. struct route {
  85.     struct    rtentry *ro_rt;
  86.     struct    sockaddr ro_dst;
  87. };
  88.  
  89. /*
  90.  * These numbers are used by reliable protocols for determining
  91.  * retransmission behavior and are included in the routing structure.
  92.  */
  93. struct rt_metrics {
  94.     u_long    rmx_locks;    /* Kernel must leave these values alone */
  95.     u_long    rmx_mtu;    /* MTU for this path */
  96.     u_long    rmx_hopcount;    /* max hops expected */
  97.     u_long    rmx_expire;    /* lifetime for route, e.g. redirect */
  98.     u_long    rmx_recvpipe;    /* inbound delay-bandwith product */
  99.     u_long    rmx_sendpipe;    /* outbound delay-bandwith product */
  100.     u_long    rmx_ssthresh;    /* outbound gateway buffer limit */
  101.     u_long    rmx_rtt;    /* estimated round trip time */
  102.     u_long    rmx_rttvar;    /* estimated rtt variance */
  103. };
  104.  
  105. /*
  106.  * rmx_rtt and rmx_rttvar are stored as microseconds;
  107.  * RTTTOPRHZ(rtt) converts to a value suitable for use
  108.  * by a protocol slowtimo counter.
  109.  */
  110. #define    RTM_RTTUNIT    1000000    /* units for rtt, rttvar, as units per sec */
  111. #define    RTTTOPRHZ(r)    ((r) / (RTM_RTTUNIT / PR_SLOWHZ))
  112.  
  113. /*
  114.  * We distinguish between routes to hosts and routes to networks,
  115.  * preferring the former if available.  For each route we infer
  116.  * the interface to use from the gateway address supplied when
  117.  * the route was entered.  Routes that forward packets through
  118.  * gateways are marked so that the output routines know to address the
  119.  * gateway rather than the ultimate destination.
  120.  */
  121. #ifndef RNF_NORMAL
  122. #include <net/radix.h>
  123. #endif
  124. struct rtentry {
  125.     struct    radix_node rt_nodes[2];    /* tree glue, and other values */
  126. #define    rt_key(r)    ((struct sockaddr *)((r)->rt_nodes->rn_key))
  127. #define    rt_mask(r)    ((struct sockaddr *)((r)->rt_nodes->rn_mask))
  128.     struct    sockaddr *rt_gateway;    /* value */
  129.     short    rt_flags;        /* up/down?, host/net */
  130.     short    rt_refcnt;        /* # held references */
  131.     u_long    rt_use;            /* raw # packets forwarded */
  132.     struct    ifnet *rt_ifp;        /* the answer: interface to use */
  133.     struct    ifaddr *rt_ifa;        /* the answer: interface to use */
  134.     struct    sockaddr *rt_genmask;    /* for generation of cloned routes */
  135.     caddr_t    rt_llinfo;        /* pointer to link level info cache */
  136.     struct    rt_metrics rt_rmx;    /* metrics used by rx'ing protocols */
  137.     short    rt_idle;        /* easy to tell llayer still live */
  138. };
  139.  
  140. /*
  141.  * Following structure necessary for 4.3 compatibility;
  142.  * We should eventually move it to a compat file.
  143.  */
  144. struct ortentry {
  145.     u_long    rt_hash;        /* to speed lookups */
  146.     struct    sockaddr rt_dst;    /* key */
  147.     struct    sockaddr rt_gateway;    /* value */
  148.     short    rt_flags;        /* up/down?, host/net */
  149.     short    rt_refcnt;        /* # held references */
  150.     u_long    rt_use;            /* raw # packets forwarded */
  151.     struct    ifnet *rt_ifp;        /* the answer: interface to use */
  152. };
  153.  
  154. #define    RTF_UP        0x1        /* route useable */
  155. #define    RTF_GATEWAY    0x2        /* destination is a gateway */
  156. #define    RTF_HOST    0x4        /* host entry (net otherwise) */
  157. #define    RTF_REJECT    0x8        /* host or net unreachable */
  158. #define    RTF_DYNAMIC    0x10        /* created dynamically (by redirect) */
  159. #define    RTF_MODIFIED    0x20        /* modified dynamically (by redirect) */
  160. #define RTF_DONE    0x40        /* message confirmed */
  161. #define RTF_MASK    0x80        /* subnet mask present */
  162. #define RTF_CLONING    0x100        /* generate new routes on use */
  163. #define RTF_XRESOLVE    0x200        /* external daemon resolves name */
  164. #define RTF_LLINFO    0x400        /* generated by ARP or ESIS */
  165. #define RTF_PROTO2    0x4000        /* protocol specific routing flag */
  166. #define RTF_PROTO1    0x8000        /* protocol specific routing flag */
  167.  
  168.  
  169. /*
  170.  * Routing statistics.
  171.  */
  172. struct    rtstat {
  173.     short    rts_badredirect;    /* bogus redirect calls */
  174.     short    rts_dynamic;        /* routes created by redirects */
  175.     short    rts_newgateway;        /* routes modified by redirects */
  176.     short    rts_unreach;        /* lookups which failed */
  177.     short    rts_wildcard;        /* lookups satisfied by a wildcard */
  178. };
  179. /*
  180.  * Structures for routing messages.
  181.  */
  182. struct rt_msghdr {
  183.     u_short    rtm_msglen;    /* to skip over non-understood messages */
  184.     u_char    rtm_version;    /* future binary compatability */
  185.     u_char    rtm_type;    /* message type */
  186.     u_short    rtm_index;    /* index for associated ifp */
  187.     pid_t    rtm_pid;    /* identify sender */
  188.     int    rtm_addrs;    /* bitmask identifying sockaddrs in msg */
  189.     int    rtm_seq;    /* for sender to identify action */
  190.     int    rtm_errno;    /* why failed */
  191.     int    rtm_flags;    /* flags, incl. kern & message, e.g. DONE */
  192.     int    rtm_use;    /* from rtentry */
  193.     u_long    rtm_inits;    /* which metrics we are initializing */
  194.     struct    rt_metrics rtm_rmx; /* metrics themselves */
  195. };
  196.  
  197. struct route_cb {
  198.     int    ip_count;
  199.     int    ns_count;
  200.     int    iso_count;
  201.     int    any_count;
  202. };
  203. #define RTM_VERSION    2    /* Up the ante and ignore older versions */
  204.  
  205. #define RTM_ADD        0x1    /* Add Route */
  206. #define RTM_DELETE    0x2    /* Delete Route */
  207. #define RTM_CHANGE    0x3    /* Change Metrics or flags */
  208. #define RTM_GET        0x4    /* Report Metrics */
  209. #define RTM_LOSING    0x5    /* Kernel Suspects Partitioning */
  210. #define RTM_REDIRECT    0x6    /* Told to use different route */
  211. #define RTM_MISS    0x7    /* Lookup failed on this address */
  212. #define RTM_LOCK    0x8    /* fix specified metrics */
  213. #define RTM_OLDADD    0x9    /* caused by SIOCADDRT */
  214. #define RTM_OLDDEL    0xa    /* caused by SIOCDELRT */
  215. #define RTM_RESOLVE    0xb    /* req to resolve dst to LL addr */
  216.  
  217. #define RTV_MTU        0x1    /* init or lock _mtu */
  218. #define RTV_HOPCOUNT    0x2    /* init or lock _hopcount */
  219. #define RTV_EXPIRE    0x4    /* init or lock _hopcount */
  220. #define RTV_RPIPE    0x8    /* init or lock _recvpipe */
  221. #define RTV_SPIPE    0x10    /* init or lock _sendpipe */
  222. #define RTV_SSTHRESH    0x20    /* init or lock _ssthresh */
  223. #define RTV_RTT        0x40    /* init or lock _rtt */
  224. #define RTV_RTTVAR    0x80    /* init or lock _rttvar */
  225.  
  226. #define RTA_DST        0x1    /* destination sockaddr present */
  227. #define RTA_GATEWAY    0x2    /* gateway sockaddr present */
  228. #define RTA_NETMASK    0x4    /* netmask sockaddr present */
  229. #define RTA_GENMASK    0x8    /* cloning mask sockaddr present */
  230. #define RTA_IFP        0x10    /* interface name sockaddr present */
  231. #define RTA_IFA        0x20    /* interface addr sockaddr present */
  232. #define RTA_AUTHOR    0x40    /* sockaddr for author of redirect */
  233.  
  234. #ifdef KERNEL
  235. struct route_cb route_cb;
  236. #endif
  237.  
  238. #ifdef KERNEL
  239. #define    RTFREE(rt) \
  240.     if ((rt)->rt_refcnt <= 1) \
  241.         rtfree(rt); \
  242.     else \
  243.         (rt)->rt_refcnt--;
  244.  
  245. #if    GATEWAY
  246. #define    RTHASHSIZ    64
  247. #else
  248. #define    RTHASHSIZ    8
  249. #endif
  250. #if    (RTHASHSIZ & (RTHASHSIZ - 1)) == 0
  251. #define RTHASHMOD(h)    ((h) & (RTHASHSIZ - 1))
  252. #else
  253. #define RTHASHMOD(h)    ((h) % RTHASHSIZ)
  254. #endif
  255. struct    mbuf *rthost[RTHASHSIZ];
  256. struct    mbuf *rtnet[RTHASHSIZ];
  257. struct    rtstat    rtstat;
  258. struct    rtentry *rtalloc1();
  259. #endif
  260.