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.4 (Berkeley) 6/27/88 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 }; 57 58 /* 59 * Following structure necessary for 4.3 compatibility; 60 * We should eventually move it to a compat file. 61 */ 62 struct ortentry { 63 u_long rt_hash; /* to speed lookups */ 64 struct sockaddr rt_dst; /* key */ 65 struct sockaddr rt_gateway; /* value */ 66 short rt_flags; /* up/down?, host/net */ 67 short rt_refcnt; /* # held references */ 68 u_long rt_use; /* raw # packets forwarded */ 69 struct ifnet *rt_ifp; /* the answer: interface to use */ 70 }; 71 72 #define RTF_UP 0x1 /* route useable */ 73 #define RTF_GATEWAY 0x2 /* destination is a gateway */ 74 #define RTF_HOST 0x4 /* host entry (net otherwise) */ 75 #define RTF_DYNAMIC 0x10 /* created dynamically (by redirect) */ 76 #define RTF_MODIFIED 0x20 /* modified dynamically (by redirect) */ 77 #define RTF_DONE 0x40 /* message confirmed */ 78 #define RTF_MASK 0x80 /* subnet mask present */ 79 80 81 /* 82 * Routing statistics. 83 */ 84 struct rtstat { 85 short rts_badredirect; /* bogus redirect calls */ 86 short rts_dynamic; /* routes created by redirects */ 87 short rts_newgateway; /* routes modified by redirects */ 88 short rts_unreach; /* lookups which failed */ 89 short rts_wildcard; /* lookups satisfied by a wildcard */ 90 }; 91 /* 92 * Structures for routing messages. 93 */ 94 struct rt_metrics { 95 u_long rtm_mtu; /* MTU for this path */ 96 u_long rtm_hopcount; /* max hops expected */ 97 u_long rtm_expire; /* lifetime for route, e.g. redirect */ 98 u_long rtm_recvpipe; /* inbound delay-bandwith product */ 99 u_long rtm_sendpipe; /* outbound delay-bandwith product */ 100 u_long rtm_ssthresh; /* outbound gateway buffer limit */ 101 u_long rtm_rtt; /* estimated round trip time */ 102 u_long rtm_rttvar; /* estimated rtt variance */ 103 }; 104 105 struct rt_msghdr { 106 u_short rtm_msglen; /* to skip over non-understood messages */ 107 u_char rtm_version; /* future binary compatability */ 108 u_char rtm_type; /* message type */ 109 u_char rtm_count; /* number of sockaddrs */ 110 pid_t rtm_pid; /* identify sender */ 111 int rtm_seq; /* for sender to identify action */ 112 int rtm_errno; /* why failed */ 113 int rtm_flags; /* flags, incl. kern & message, e.g. DONE */ 114 int rtm_locks; /* which values kernel can alter */ 115 int rtm_inits; /* which values we are initializing */ 116 }; 117 118 struct rt_chgmsg { /* Good for RTM_ADD, RTM_CHANGE, RTM_GET */ 119 struct rt_msghdr cm_h; 120 struct rt_metrics cm_m; 121 }; 122 123 struct route_cb { 124 int ip_count; 125 int ns_count; 126 int iso_count; 127 int any_count; 128 }; 129 130 #define RTM_ADD 0x1 /* Add Route */ 131 #define RTM_DELETE 0x2 /* Delete Route */ 132 #define RTM_CHANGE 0x3 /* Change Metrics or flags */ 133 #define RTM_GET 0x4 /* Report Metrics */ 134 #define RTM_LOSING 0x5 /* Kernel Suspects Partitioning */ 135 #define RTM_REDIRECT 0x6 /* Told to use different route */ 136 #define RTM_MISS 0x7 /* Lookup failed on this address */ 137 #define RTM_LOCK 0x8 /* fix specified metrics */ 138 #define RTM_OLDADD 0x9 /* caused by SIOCADDRT */ 139 #define RTM_OLDDEL 0xa /* caused by SIOCDELRT */ 140 141 #define RTV_MTU 0x1 /* init or lock _mtu */ 142 #define RTV_HOPCOUNT 0x2 /* init or lock _hopcount */ 143 #define RTV_EXPIRE 0x4 /* init or lock _hopcount */ 144 #define RTV_RPIPE 0x8 /* init or lock _recvpipe */ 145 #define RTV_SPIPE 0x10 /* init or lock _sendpipe */ 146 #define RTV_SSTHRESH 0x20 /* init or lock _ssthresh */ 147 #define RTV_RTT 0x40 /* init or lock _rtt */ 148 #define RTV_RTTVAR 0x80 /* init or lock _rttvar */ 149 150 #ifdef KERNEL 151 struct route_cb route_cb; 152 #endif 153 154 #ifdef KERNEL 155 #define RTFREE(rt) \ 156 if ((rt)->rt_refcnt == 1) \ 157 rtfree(rt); \ 158 else \ 159 (rt)->rt_refcnt--; 160 161 #ifdef GATEWAY 162 #define RTHASHSIZ 64 163 #else 164 #define RTHASHSIZ 8 165 #endif 166 #if (RTHASHSIZ & (RTHASHSIZ - 1)) == 0 167 #define RTHASHMOD(h) ((h) & (RTHASHSIZ - 1)) 168 #else 169 #define RTHASHMOD(h) ((h) % RTHASHSIZ) 170 #endif 171 struct mbuf *rthost[RTHASHSIZ]; 172 struct mbuf *rtnet[RTHASHSIZ]; 173 struct rtstat rtstat; 174 struct rtentry *rtalloc1(); 175 #endif 176