Commit | Line | Data |
---|---|---|
cb1c44c2 | 1 | /* |
1810611d | 2 | * Copyright (c) 1980, 1986 Regents of the University of California. |
5b519e94 | 3 | * All rights reserved. |
cb1c44c2 | 4 | * |
dbf0c423 | 5 | * %sccs.include.redist.c% |
5b519e94 | 6 | * |
1cc2aa92 | 7 | * @(#)route.h 7.15 (Berkeley) %G% |
cb1c44c2 | 8 | */ |
6c0a063b SL |
9 | |
10 | /* | |
a9f3e174 SL |
11 | * Kernel resident routing tables. |
12 | * | |
a839f328 MK |
13 | * The routing tables are initialized when interface addresses |
14 | * are set by making entries for all directly connected interfaces. | |
6c0a063b | 15 | */ |
6c0a063b | 16 | |
a13c006d BJ |
17 | /* |
18 | * A route consists of a destination address and a reference | |
19 | * to a routing entry. These are often held by protocols | |
20 | * in their control blocks, e.g. inpcb. | |
21 | */ | |
6c0a063b SL |
22 | struct route { |
23 | struct rtentry *ro_rt; | |
24 | struct sockaddr ro_dst; | |
6c0a063b SL |
25 | }; |
26 | ||
d281dcc1 KS |
27 | /* |
28 | * These numbers are used by reliable protocols for determining | |
29 | * retransmission behavior and are included in the routing structure. | |
30 | */ | |
31 | struct rt_metrics { | |
32 | u_long rmx_locks; /* Kernel must leave these values alone */ | |
33 | u_long rmx_mtu; /* MTU for this path */ | |
34 | u_long rmx_hopcount; /* max hops expected */ | |
35 | u_long rmx_expire; /* lifetime for route, e.g. redirect */ | |
36 | u_long rmx_recvpipe; /* inbound delay-bandwith product */ | |
37 | u_long rmx_sendpipe; /* outbound delay-bandwith product */ | |
38 | u_long rmx_ssthresh; /* outbound gateway buffer limit */ | |
39 | u_long rmx_rtt; /* estimated round trip time */ | |
40 | u_long rmx_rttvar; /* estimated rtt variance */ | |
41 | }; | |
42 | ||
ae5e8a71 MK |
43 | /* |
44 | * rmx_rtt and rmx_rttvar are stored as microseconds; | |
45 | * RTTTOPRHZ(rtt) converts to a value suitable for use | |
46 | * by a protocol slowtimo counter. | |
47 | */ | |
48 | #define RTM_RTTUNIT 1000000 /* units for rtt, rttvar, as units per sec */ | |
49 | #define RTTTOPRHZ(r) ((r) / (RTM_RTTUNIT / PR_SLOWHZ)) | |
50 | ||
6c0a063b | 51 | /* |
a13c006d BJ |
52 | * We distinguish between routes to hosts and routes to networks, |
53 | * preferring the former if available. For each route we infer | |
54 | * the interface to use from the gateway address supplied when | |
55 | * the route was entered. Routes that forward packets through | |
56 | * gateways are marked so that the output routines know to address the | |
57 | * gateway rather than the ultimate destination. | |
6c0a063b | 58 | */ |
aaf06fbd | 59 | #ifndef RNF_NORMAL |
573d82c4 | 60 | #include "radix.h" |
aaf06fbd | 61 | #endif |
a13c006d | 62 | struct rtentry { |
573d82c4 KS |
63 | struct radix_node rt_nodes[2]; /* tree glue, and other values */ |
64 | #define rt_key(r) ((struct sockaddr *)((r)->rt_nodes->rn_key)) | |
65 | #define rt_mask(r) ((struct sockaddr *)((r)->rt_nodes->rn_mask)) | |
66 | struct sockaddr *rt_gateway; /* value */ | |
67 | short rt_flags; /* up/down?, host/net */ | |
68 | short rt_refcnt; /* # held references */ | |
69 | u_long rt_use; /* raw # packets forwarded */ | |
70 | struct ifnet *rt_ifp; /* the answer: interface to use */ | |
b72a6efb | 71 | struct ifaddr *rt_ifa; /* the answer: interface to use */ |
c050ffea KS |
72 | struct sockaddr *rt_genmask; /* for generation of cloned routes */ |
73 | caddr_t rt_llinfo; /* pointer to link level info cache */ | |
d281dcc1 | 74 | struct rt_metrics rt_rmx; /* metrics used by rx'ing protocols */ |
92e18d47 | 75 | struct rtentry *rt_gwroute; /* implied entry for gatewayed routes */ |
573d82c4 KS |
76 | }; |
77 | ||
78 | /* | |
79 | * Following structure necessary for 4.3 compatibility; | |
80 | * We should eventually move it to a compat file. | |
81 | */ | |
82 | struct ortentry { | |
a13c006d BJ |
83 | u_long rt_hash; /* to speed lookups */ |
84 | struct sockaddr rt_dst; /* key */ | |
85 | struct sockaddr rt_gateway; /* value */ | |
86 | short rt_flags; /* up/down?, host/net */ | |
87 | short rt_refcnt; /* # held references */ | |
88 | u_long rt_use; /* raw # packets forwarded */ | |
89 | struct ifnet *rt_ifp; /* the answer: interface to use */ | |
90 | }; | |
a13c006d | 91 | |
ee787340 | 92 | #define RTF_UP 0x1 /* route useable */ |
a13c006d | 93 | #define RTF_GATEWAY 0x2 /* destination is a gateway */ |
fc74f0c9 | 94 | #define RTF_HOST 0x4 /* host entry (net otherwise) */ |
b4cd1ddd | 95 | #define RTF_REJECT 0x8 /* host or net unreachable */ |
a839f328 | 96 | #define RTF_DYNAMIC 0x10 /* created dynamically (by redirect) */ |
31150b52 | 97 | #define RTF_MODIFIED 0x20 /* modified dynamically (by redirect) */ |
573d82c4 KS |
98 | #define RTF_DONE 0x40 /* message confirmed */ |
99 | #define RTF_MASK 0x80 /* subnet mask present */ | |
c050ffea KS |
100 | #define RTF_CLONING 0x100 /* generate new routes on use */ |
101 | #define RTF_XRESOLVE 0x200 /* external daemon resolves name */ | |
0492b696 | 102 | #define RTF_LLINFO 0x400 /* generated by ARP or ESIS */ |
1cc2aa92 | 103 | #define RTF_STATIC 0x800 /* manually added */ |
aaf06fbd KS |
104 | #define RTF_PROTO2 0x4000 /* protocol specific routing flag */ |
105 | #define RTF_PROTO1 0x8000 /* protocol specific routing flag */ | |
573d82c4 | 106 | |
6c0a063b | 107 | |
a9ea8834 SL |
108 | /* |
109 | * Routing statistics. | |
110 | */ | |
111 | struct rtstat { | |
112 | short rts_badredirect; /* bogus redirect calls */ | |
113 | short rts_dynamic; /* routes created by redirects */ | |
114 | short rts_newgateway; /* routes modified by redirects */ | |
115 | short rts_unreach; /* lookups which failed */ | |
116 | short rts_wildcard; /* lookups satisfied by a wildcard */ | |
117 | }; | |
573d82c4 KS |
118 | /* |
119 | * Structures for routing messages. | |
120 | */ | |
573d82c4 KS |
121 | struct rt_msghdr { |
122 | u_short rtm_msglen; /* to skip over non-understood messages */ | |
123 | u_char rtm_version; /* future binary compatability */ | |
124 | u_char rtm_type; /* message type */ | |
d281dcc1 | 125 | u_short rtm_index; /* index for associated ifp */ |
573d82c4 | 126 | pid_t rtm_pid; /* identify sender */ |
d281dcc1 | 127 | int rtm_addrs; /* bitmask identifying sockaddrs in msg */ |
573d82c4 KS |
128 | int rtm_seq; /* for sender to identify action */ |
129 | int rtm_errno; /* why failed */ | |
130 | int rtm_flags; /* flags, incl. kern & message, e.g. DONE */ | |
d281dcc1 KS |
131 | int rtm_use; /* from rtentry */ |
132 | u_long rtm_inits; /* which metrics we are initializing */ | |
133 | struct rt_metrics rtm_rmx; /* metrics themselves */ | |
573d82c4 KS |
134 | }; |
135 | ||
136 | struct route_cb { | |
137 | int ip_count; | |
138 | int ns_count; | |
139 | int iso_count; | |
140 | int any_count; | |
141 | }; | |
d281dcc1 | 142 | #define RTM_VERSION 2 /* Up the ante and ignore older versions */ |
573d82c4 KS |
143 | |
144 | #define RTM_ADD 0x1 /* Add Route */ | |
145 | #define RTM_DELETE 0x2 /* Delete Route */ | |
146 | #define RTM_CHANGE 0x3 /* Change Metrics or flags */ | |
147 | #define RTM_GET 0x4 /* Report Metrics */ | |
148 | #define RTM_LOSING 0x5 /* Kernel Suspects Partitioning */ | |
149 | #define RTM_REDIRECT 0x6 /* Told to use different route */ | |
150 | #define RTM_MISS 0x7 /* Lookup failed on this address */ | |
151 | #define RTM_LOCK 0x8 /* fix specified metrics */ | |
152 | #define RTM_OLDADD 0x9 /* caused by SIOCADDRT */ | |
153 | #define RTM_OLDDEL 0xa /* caused by SIOCDELRT */ | |
c050ffea | 154 | #define RTM_RESOLVE 0xb /* req to resolve dst to LL addr */ |
573d82c4 KS |
155 | |
156 | #define RTV_MTU 0x1 /* init or lock _mtu */ | |
157 | #define RTV_HOPCOUNT 0x2 /* init or lock _hopcount */ | |
158 | #define RTV_EXPIRE 0x4 /* init or lock _hopcount */ | |
159 | #define RTV_RPIPE 0x8 /* init or lock _recvpipe */ | |
160 | #define RTV_SPIPE 0x10 /* init or lock _sendpipe */ | |
161 | #define RTV_SSTHRESH 0x20 /* init or lock _ssthresh */ | |
162 | #define RTV_RTT 0x40 /* init or lock _rtt */ | |
163 | #define RTV_RTTVAR 0x80 /* init or lock _rttvar */ | |
164 | ||
d281dcc1 KS |
165 | #define RTA_DST 0x1 /* destination sockaddr present */ |
166 | #define RTA_GATEWAY 0x2 /* gateway sockaddr present */ | |
167 | #define RTA_NETMASK 0x4 /* netmask sockaddr present */ | |
168 | #define RTA_GENMASK 0x8 /* cloning mask sockaddr present */ | |
169 | #define RTA_IFP 0x10 /* interface name sockaddr present */ | |
170 | #define RTA_IFA 0x20 /* interface addr sockaddr present */ | |
171 | #define RTA_AUTHOR 0x40 /* sockaddr for author of redirect */ | |
172 | ||
573d82c4 KS |
173 | #ifdef KERNEL |
174 | struct route_cb route_cb; | |
175 | #endif | |
a9ea8834 SL |
176 | |
177 | #ifdef KERNEL | |
a9f3e174 | 178 | #define RTFREE(rt) \ |
c050ffea | 179 | if ((rt)->rt_refcnt <= 1) \ |
a9f3e174 SL |
180 | rtfree(rt); \ |
181 | else \ | |
182 | (rt)->rt_refcnt--; | |
a9ea8834 | 183 | |
b4ad5b30 MK |
184 | #ifdef GATEWAY |
185 | #define RTHASHSIZ 64 | |
186 | #else | |
0ab3c88a | 187 | #define RTHASHSIZ 8 |
b4ad5b30 | 188 | #endif |
0ab3c88a MK |
189 | #if (RTHASHSIZ & (RTHASHSIZ - 1)) == 0 |
190 | #define RTHASHMOD(h) ((h) & (RTHASHSIZ - 1)) | |
191 | #else | |
192 | #define RTHASHMOD(h) ((h) % RTHASHSIZ) | |
193 | #endif | |
a9ea8834 SL |
194 | struct mbuf *rthost[RTHASHSIZ]; |
195 | struct mbuf *rtnet[RTHASHSIZ]; | |
196 | struct rtstat rtstat; | |
573d82c4 | 197 | struct rtentry *rtalloc1(); |
1cc2aa92 | 198 | struct radix_node_head *rt_tables[AF_MAX+1]; |
a9ea8834 | 199 | #endif |