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