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