Commit | Line | Data |
---|---|---|
cb1c44c2 KM |
1 | /* |
2 | * Copyright (c) 1980 Regents of the University of California. | |
3 | * All rights reserved. The Berkeley software License Agreement | |
4 | * specifies the terms and conditions for redistribution. | |
5 | * | |
c43a1c83 | 6 | * @(#)route.h 6.7 (Berkeley) %G% |
cb1c44c2 | 7 | */ |
6c0a063b SL |
8 | |
9 | /* | |
a9f3e174 SL |
10 | * Kernel resident routing tables. |
11 | * | |
a839f328 MK |
12 | * The routing tables are initialized when interface addresses |
13 | * are set by making entries for all directly connected interfaces. | |
6c0a063b | 14 | */ |
6c0a063b | 15 | |
a13c006d BJ |
16 | /* |
17 | * A route consists of a destination address and a reference | |
18 | * to a routing entry. These are often held by protocols | |
19 | * in their control blocks, e.g. inpcb. | |
20 | */ | |
6c0a063b SL |
21 | struct route { |
22 | struct rtentry *ro_rt; | |
23 | struct sockaddr ro_dst; | |
6c0a063b SL |
24 | }; |
25 | ||
26 | /* | |
a13c006d BJ |
27 | * We distinguish between routes to hosts and routes to networks, |
28 | * preferring the former if available. For each route we infer | |
29 | * the interface to use from the gateway address supplied when | |
30 | * the route was entered. Routes that forward packets through | |
31 | * gateways are marked so that the output routines know to address the | |
32 | * gateway rather than the ultimate destination. | |
6c0a063b | 33 | */ |
a13c006d BJ |
34 | struct rtentry { |
35 | u_long rt_hash; /* to speed lookups */ | |
36 | struct sockaddr rt_dst; /* key */ | |
37 | struct sockaddr rt_gateway; /* value */ | |
38 | short rt_flags; /* up/down?, host/net */ | |
39 | short rt_refcnt; /* # held references */ | |
40 | u_long rt_use; /* raw # packets forwarded */ | |
41 | struct ifnet *rt_ifp; /* the answer: interface to use */ | |
42 | }; | |
a13c006d | 43 | |
ee787340 | 44 | #define RTF_UP 0x1 /* route useable */ |
a13c006d | 45 | #define RTF_GATEWAY 0x2 /* destination is a gateway */ |
fc74f0c9 | 46 | #define RTF_HOST 0x4 /* host entry (net otherwise) */ |
da2e2210 | 47 | #define RTF_REINSTATE 0x8 /* re-instate route after timeout */ |
a839f328 | 48 | #define RTF_DYNAMIC 0x10 /* created dynamically (by redirect) */ |
6c0a063b | 49 | |
a9ea8834 SL |
50 | /* |
51 | * Routing statistics. | |
52 | */ | |
53 | struct rtstat { | |
54 | short rts_badredirect; /* bogus redirect calls */ | |
55 | short rts_dynamic; /* routes created by redirects */ | |
56 | short rts_newgateway; /* routes modified by redirects */ | |
57 | short rts_unreach; /* lookups which failed */ | |
58 | short rts_wildcard; /* lookups satisfied by a wildcard */ | |
59 | }; | |
60 | ||
61 | #ifdef KERNEL | |
a9f3e174 SL |
62 | #define RTFREE(rt) \ |
63 | if ((rt)->rt_refcnt == 1) \ | |
64 | rtfree(rt); \ | |
65 | else \ | |
66 | (rt)->rt_refcnt--; | |
a9ea8834 | 67 | |
b4ad5b30 MK |
68 | #ifdef GATEWAY |
69 | #define RTHASHSIZ 64 | |
70 | #else | |
0ab3c88a | 71 | #define RTHASHSIZ 8 |
b4ad5b30 | 72 | #endif |
0ab3c88a MK |
73 | #if (RTHASHSIZ & (RTHASHSIZ - 1)) == 0 |
74 | #define RTHASHMOD(h) ((h) & (RTHASHSIZ - 1)) | |
75 | #else | |
76 | #define RTHASHMOD(h) ((h) % RTHASHSIZ) | |
77 | #endif | |
a9ea8834 SL |
78 | struct mbuf *rthost[RTHASHSIZ]; |
79 | struct mbuf *rtnet[RTHASHSIZ]; | |
80 | struct rtstat rtstat; | |
81 | #endif |