up version from 4 to 5
[unix-history] / usr / src / sys / net / route.h
CommitLineData
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 *
50c7758a 17 * @(#)route.h 7.4 (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
32struct route {
33 struct rtentry *ro_rt;
34 struct sockaddr ro_dst;
6c0a063b
SL
35};
36
37/*
a13c006d
BJ
38 * We distinguish between routes to hosts and routes to networks,
39 * preferring the former if available. For each route we infer
40 * the interface to use from the gateway address supplied when
41 * the route was entered. Routes that forward packets through
42 * gateways are marked so that the output routines know to address the
43 * gateway rather than the ultimate destination.
6c0a063b 44 */
a13c006d
BJ
45struct rtentry {
46 u_long rt_hash; /* to speed lookups */
47 struct sockaddr rt_dst; /* key */
48 struct sockaddr rt_gateway; /* value */
49 short rt_flags; /* up/down?, host/net */
50 short rt_refcnt; /* # held references */
51 u_long rt_use; /* raw # packets forwarded */
52 struct ifnet *rt_ifp; /* the answer: interface to use */
53};
a13c006d 54
ee787340 55#define RTF_UP 0x1 /* route useable */
a13c006d 56#define RTF_GATEWAY 0x2 /* destination is a gateway */
fc74f0c9 57#define RTF_HOST 0x4 /* host entry (net otherwise) */
a839f328 58#define RTF_DYNAMIC 0x10 /* created dynamically (by redirect) */
31150b52 59#define RTF_MODIFIED 0x20 /* modified dynamically (by redirect) */
6c0a063b 60
a9ea8834
SL
61/*
62 * Routing statistics.
63 */
64struct rtstat {
65 short rts_badredirect; /* bogus redirect calls */
66 short rts_dynamic; /* routes created by redirects */
67 short rts_newgateway; /* routes modified by redirects */
68 short rts_unreach; /* lookups which failed */
69 short rts_wildcard; /* lookups satisfied by a wildcard */
70};
71
72#ifdef KERNEL
a9f3e174
SL
73#define RTFREE(rt) \
74 if ((rt)->rt_refcnt == 1) \
75 rtfree(rt); \
76 else \
77 (rt)->rt_refcnt--;
a9ea8834 78
b4ad5b30
MK
79#ifdef GATEWAY
80#define RTHASHSIZ 64
81#else
0ab3c88a 82#define RTHASHSIZ 8
b4ad5b30 83#endif
0ab3c88a
MK
84#if (RTHASHSIZ & (RTHASHSIZ - 1)) == 0
85#define RTHASHMOD(h) ((h) & (RTHASHSIZ - 1))
86#else
87#define RTHASHMOD(h) ((h) % RTHASHSIZ)
88#endif
a9ea8834
SL
89struct mbuf *rthost[RTHASHSIZ];
90struct mbuf *rtnet[RTHASHSIZ];
91struct rtstat rtstat;
92#endif