Add copyright
[unix-history] / usr / src / sys / net / route.h
CommitLineData
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 *
6 * @(#)route.h 6.4 (Berkeley) %G%
7 */
6c0a063b
SL
8
9/*
a9f3e174
SL
10 * Kernel resident routing tables.
11 *
a13c006d
BJ
12 * The routing tables are initialized at boot time by
13 * 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
21struct route {
22 struct rtentry *ro_rt;
23 struct sockaddr ro_dst;
a13c006d
BJ
24#ifdef notdef
25 caddr_t ro_pcb; /* not used yet */
26#endif
6c0a063b
SL
27};
28
29/*
a13c006d
BJ
30 * We distinguish between routes to hosts and routes to networks,
31 * preferring the former if available. For each route we infer
32 * the interface to use from the gateway address supplied when
33 * the route was entered. Routes that forward packets through
34 * gateways are marked so that the output routines know to address the
35 * gateway rather than the ultimate destination.
6c0a063b 36 */
a13c006d
BJ
37struct rtentry {
38 u_long rt_hash; /* to speed lookups */
39 struct sockaddr rt_dst; /* key */
40 struct sockaddr rt_gateway; /* value */
41 short rt_flags; /* up/down?, host/net */
42 short rt_refcnt; /* # held references */
43 u_long rt_use; /* raw # packets forwarded */
44 struct ifnet *rt_ifp; /* the answer: interface to use */
45};
a13c006d 46
ee787340 47#define RTF_UP 0x1 /* route useable */
a13c006d 48#define RTF_GATEWAY 0x2 /* destination is a gateway */
fc74f0c9 49#define RTF_HOST 0x4 /* host entry (net otherwise) */
6c0a063b 50
a9ea8834
SL
51/*
52 * Routing statistics.
53 */
54struct rtstat {
55 short rts_badredirect; /* bogus redirect calls */
56 short rts_dynamic; /* routes created by redirects */
57 short rts_newgateway; /* routes modified by redirects */
58 short rts_unreach; /* lookups which failed */
59 short rts_wildcard; /* lookups satisfied by a wildcard */
60};
61
62#ifdef KERNEL
a9f3e174
SL
63#define RTFREE(rt) \
64 if ((rt)->rt_refcnt == 1) \
65 rtfree(rt); \
66 else \
67 (rt)->rt_refcnt--;
a9ea8834 68
b4ad5b30
MK
69#ifdef GATEWAY
70#define RTHASHSIZ 64
71#else
0ab3c88a 72#define RTHASHSIZ 8
b4ad5b30 73#endif
0ab3c88a
MK
74#if (RTHASHSIZ & (RTHASHSIZ - 1)) == 0
75#define RTHASHMOD(h) ((h) & (RTHASHSIZ - 1))
76#else
77#define RTHASHMOD(h) ((h) % RTHASHSIZ)
78#endif
a9ea8834
SL
79struct mbuf *rthost[RTHASHSIZ];
80struct mbuf *rtnet[RTHASHSIZ];
81struct rtstat rtstat;
82#endif