1 /* 2 * Copyright (c) 1980, 1986 Regents of the University of California. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms are permitted 6 * provided that the above copyright notice and this paragraph are 7 * duplicated in all such forms and that any documentation, 8 * advertising materials, and other materials related to such 9 * distribution and use acknowledge that the software was developed 10 * by the University of California, Berkeley. The name of the 11 * University may not be used to endorse or promote products derived 12 * from this software without specific prior written permission. 13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 16 * 17 * @(#)route.h 7.7 (Berkeley) 03/12/90 18 */ 19 20 /* 21 * Kernel resident routing tables. 22 * 23 * The routing tables are initialized when interface addresses 24 * are set by making entries for all directly connected interfaces. 25 */ 26 27 /* 28 * A route consists of a destination address and a reference 29 * to a routing entry. These are often held by protocols 30 * in their control blocks, e.g. inpcb. 31 */ 32 struct route { 33 struct rtentry *ro_rt; 34 struct sockaddr ro_dst; 35 }; 36 37 /* 38 * We distinguish between routes to hosts and routes to networks, 39 * preferring the former if available. For each route we infer 40 * the interface to use from the gateway address supplied when 41 * the route was entered. Routes that forward packets through 42 * gateways are marked so that the output routines know to address the 43 * gateway rather than the ultimate destination. 44 */ 45 #include "radix.h" 46 struct rtentry { 47 struct radix_node rt_nodes[2]; /* tree glue, and other values */ 48 #define rt_key(r) ((struct sockaddr *)((r)->rt_nodes->rn_key)) 49 #define rt_mask(r) ((struct sockaddr *)((r)->rt_nodes->rn_mask)) 50 struct sockaddr *rt_gateway; /* value */ 51 short rt_flags; /* up/down?, host/net */ 52 short rt_refcnt; /* # held references */ 53 u_long rt_use; /* raw # packets forwarded */ 54 struct ifnet *rt_ifp; /* the answer: interface to use */ 55 struct ifaddr *rt_ifa; /* the answer: interface to use */ 56 struct sockaddr *rt_genmask; /* for generation of cloned routes */ 57 caddr_t rt_llinfo; /* pointer to link level info cache */ 58 }; 59 60 /* 61 * Following structure necessary for 4.3 compatibility; 62 * We should eventually move it to a compat file. 63 */ 64 struct ortentry { 65 u_long rt_hash; /* to speed lookups */ 66 struct sockaddr rt_dst; /* key */ 67 struct sockaddr rt_gateway; /* value */ 68 short rt_flags; /* up/down?, host/net */ 69 short rt_refcnt; /* # held references */ 70 u_long rt_use; /* raw # packets forwarded */ 71 struct ifnet *rt_ifp; /* the answer: interface to use */ 72 }; 73 74 #define RTF_UP 0x1 /* route useable */ 75 #define RTF_GATEWAY 0x2 /* destination is a gateway */ 76 #define RTF_HOST 0x4 /* host entry (net otherwise) */ 77 #define RTF_DYNAMIC 0x10 /* created dynamically (by redirect) */ 78 #define RTF_MODIFIED 0x20 /* modified dynamically (by redirect) */ 79 #define RTF_DONE 0x40 /* message confirmed */ 80 #define RTF_MASK 0x80 /* subnet mask present */ 81 #define RTF_CLONING 0x100 /* generate new routes on use */ 82 #define RTF_XRESOLVE 0x200 /* external daemon resolves name */ 83 84 85 /* 86 * Routing statistics. 87 */ 88 struct rtstat { 89 short rts_badredirect; /* bogus redirect calls */ 90 short rts_dynamic; /* routes created by redirects */ 91 short rts_newgateway; /* routes modified by redirects */ 92 short rts_unreach; /* lookups which failed */ 93 short rts_wildcard; /* lookups satisfied by a wildcard */ 94 }; 95 /* 96 * Structures for routing messages. 97 */ 98 struct rt_metrics { 99 u_long rtm_mtu; /* MTU for this path */ 100 u_long rtm_hopcount; /* max hops expected */ 101 u_long rtm_expire; /* lifetime for route, e.g. redirect */ 102 u_long rtm_recvpipe; /* inbound delay-bandwith product */ 103 u_long rtm_sendpipe; /* outbound delay-bandwith product */ 104 u_long rtm_ssthresh; /* outbound gateway buffer limit */ 105 u_long rtm_rtt; /* estimated round trip time */ 106 u_long rtm_rttvar; /* estimated rtt variance */ 107 }; 108 109 struct rt_msghdr { 110 u_short rtm_msglen; /* to skip over non-understood messages */ 111 u_char rtm_version; /* future binary compatability */ 112 u_char rtm_type; /* message type */ 113 u_char rtm_count; /* number of sockaddrs */ 114 pid_t rtm_pid; /* identify sender */ 115 int rtm_seq; /* for sender to identify action */ 116 int rtm_errno; /* why failed */ 117 int rtm_flags; /* flags, incl. kern & message, e.g. DONE */ 118 int rtm_locks; /* which values kernel can alter */ 119 int rtm_inits; /* which values we are initializing */ 120 }; 121 122 struct rt_chgmsg { /* Good for RTM_ADD, RTM_CHANGE, RTM_GET */ 123 struct rt_msghdr cm_h; 124 struct rt_metrics cm_m; 125 }; 126 127 struct route_cb { 128 int ip_count; 129 int ns_count; 130 int iso_count; 131 int any_count; 132 }; 133 134 #define RTM_ADD 0x1 /* Add Route */ 135 #define RTM_DELETE 0x2 /* Delete Route */ 136 #define RTM_CHANGE 0x3 /* Change Metrics or flags */ 137 #define RTM_GET 0x4 /* Report Metrics */ 138 #define RTM_LOSING 0x5 /* Kernel Suspects Partitioning */ 139 #define RTM_REDIRECT 0x6 /* Told to use different route */ 140 #define RTM_MISS 0x7 /* Lookup failed on this address */ 141 #define RTM_LOCK 0x8 /* fix specified metrics */ 142 #define RTM_OLDADD 0x9 /* caused by SIOCADDRT */ 143 #define RTM_OLDDEL 0xa /* caused by SIOCDELRT */ 144 #define RTM_RESOLVE 0xb /* req to resolve dst to LL addr */ 145 146 #define RTV_MTU 0x1 /* init or lock _mtu */ 147 #define RTV_HOPCOUNT 0x2 /* init or lock _hopcount */ 148 #define RTV_EXPIRE 0x4 /* init or lock _hopcount */ 149 #define RTV_RPIPE 0x8 /* init or lock _recvpipe */ 150 #define RTV_SPIPE 0x10 /* init or lock _sendpipe */ 151 #define RTV_SSTHRESH 0x20 /* init or lock _ssthresh */ 152 #define RTV_RTT 0x40 /* init or lock _rtt */ 153 #define RTV_RTTVAR 0x80 /* init or lock _rttvar */ 154 155 #ifdef KERNEL 156 struct route_cb route_cb; 157 #endif 158 159 #ifdef KERNEL 160 #define RTFREE(rt) \ 161 if ((rt)->rt_refcnt <= 1) \ 162 rtfree(rt); \ 163 else \ 164 (rt)->rt_refcnt--; 165 166 #ifdef GATEWAY 167 #define RTHASHSIZ 64 168 #else 169 #define RTHASHSIZ 8 170 #endif 171 #if (RTHASHSIZ & (RTHASHSIZ - 1)) == 0 172 #define RTHASHMOD(h) ((h) & (RTHASHSIZ - 1)) 173 #else 174 #define RTHASHMOD(h) ((h) % RTHASHSIZ) 175 #endif 176 struct mbuf *rthost[RTHASHSIZ]; 177 struct mbuf *rtnet[RTHASHSIZ]; 178 struct rtstat rtstat; 179 struct rtentry *rtalloc1(); 180 #endif 181