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 KB |
5 | * Redistribution and use in source and binary forms are permitted |
6 | * provided that this notice is preserved and that due credit is given | |
7 | * to the University of California at Berkeley. The name of the University | |
8 | * may not be used to endorse or promote products derived from this | |
9 | * software without specific prior written permission. This software | |
10 | * is provided ``as is'' without express or implied warranty. | |
11 | * | |
12 | * @(#)route.h 7.3 (Berkeley) %G% | |
cb1c44c2 | 13 | */ |
6c0a063b SL |
14 | |
15 | /* | |
a9f3e174 SL |
16 | * Kernel resident routing tables. |
17 | * | |
a839f328 MK |
18 | * The routing tables are initialized when interface addresses |
19 | * are set by making entries for all directly connected interfaces. | |
6c0a063b | 20 | */ |
6c0a063b | 21 | |
a13c006d BJ |
22 | /* |
23 | * A route consists of a destination address and a reference | |
24 | * to a routing entry. These are often held by protocols | |
25 | * in their control blocks, e.g. inpcb. | |
26 | */ | |
6c0a063b SL |
27 | struct route { |
28 | struct rtentry *ro_rt; | |
29 | struct sockaddr ro_dst; | |
6c0a063b SL |
30 | }; |
31 | ||
32 | /* | |
a13c006d BJ |
33 | * We distinguish between routes to hosts and routes to networks, |
34 | * preferring the former if available. For each route we infer | |
35 | * the interface to use from the gateway address supplied when | |
36 | * the route was entered. Routes that forward packets through | |
37 | * gateways are marked so that the output routines know to address the | |
38 | * gateway rather than the ultimate destination. | |
6c0a063b | 39 | */ |
a13c006d BJ |
40 | struct rtentry { |
41 | u_long rt_hash; /* to speed lookups */ | |
42 | struct sockaddr rt_dst; /* key */ | |
43 | struct sockaddr rt_gateway; /* value */ | |
44 | short rt_flags; /* up/down?, host/net */ | |
45 | short rt_refcnt; /* # held references */ | |
46 | u_long rt_use; /* raw # packets forwarded */ | |
47 | struct ifnet *rt_ifp; /* the answer: interface to use */ | |
48 | }; | |
a13c006d | 49 | |
ee787340 | 50 | #define RTF_UP 0x1 /* route useable */ |
a13c006d | 51 | #define RTF_GATEWAY 0x2 /* destination is a gateway */ |
fc74f0c9 | 52 | #define RTF_HOST 0x4 /* host entry (net otherwise) */ |
a839f328 | 53 | #define RTF_DYNAMIC 0x10 /* created dynamically (by redirect) */ |
31150b52 | 54 | #define RTF_MODIFIED 0x20 /* modified dynamically (by redirect) */ |
6c0a063b | 55 | |
a9ea8834 SL |
56 | /* |
57 | * Routing statistics. | |
58 | */ | |
59 | struct rtstat { | |
60 | short rts_badredirect; /* bogus redirect calls */ | |
61 | short rts_dynamic; /* routes created by redirects */ | |
62 | short rts_newgateway; /* routes modified by redirects */ | |
63 | short rts_unreach; /* lookups which failed */ | |
64 | short rts_wildcard; /* lookups satisfied by a wildcard */ | |
65 | }; | |
66 | ||
67 | #ifdef KERNEL | |
a9f3e174 SL |
68 | #define RTFREE(rt) \ |
69 | if ((rt)->rt_refcnt == 1) \ | |
70 | rtfree(rt); \ | |
71 | else \ | |
72 | (rt)->rt_refcnt--; | |
a9ea8834 | 73 | |
b4ad5b30 MK |
74 | #ifdef GATEWAY |
75 | #define RTHASHSIZ 64 | |
76 | #else | |
0ab3c88a | 77 | #define RTHASHSIZ 8 |
b4ad5b30 | 78 | #endif |
0ab3c88a MK |
79 | #if (RTHASHSIZ & (RTHASHSIZ - 1)) == 0 |
80 | #define RTHASHMOD(h) ((h) & (RTHASHSIZ - 1)) | |
81 | #else | |
82 | #define RTHASHMOD(h) ((h) % RTHASHSIZ) | |
83 | #endif | |
a9ea8834 SL |
84 | struct mbuf *rthost[RTHASHSIZ]; |
85 | struct mbuf *rtnet[RTHASHSIZ]; | |
86 | struct rtstat rtstat; | |
87 | #endif |