xref: /csrg-svn/sys/net/route.h (revision 34844)
1 /*
2  * Copyright (c) 1980, 1986 Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are permitted
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.
16  *
17  *	@(#)route.h	7.4 (Berkeley) 06/27/88
18  */
19 
20 /*
21  * Kernel resident routing tables.
22  *
23  * The routing tables are initialized when interface addresses
24  * are set by making entries for all directly connected interfaces.
25  */
26 
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  */
32 struct route {
33 	struct	rtentry *ro_rt;
34 	struct	sockaddr ro_dst;
35 };
36 
37 /*
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.
44  */
45 struct 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 };
54 
55 #define	RTF_UP		0x1		/* route useable */
56 #define	RTF_GATEWAY	0x2		/* destination is a gateway */
57 #define	RTF_HOST	0x4		/* host entry (net otherwise) */
58 #define	RTF_DYNAMIC	0x10		/* created dynamically (by redirect) */
59 #define	RTF_MODIFIED	0x20		/* modified dynamically (by redirect) */
60 
61 /*
62  * Routing statistics.
63  */
64 struct	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
73 #define	RTFREE(rt) \
74 	if ((rt)->rt_refcnt == 1) \
75 		rtfree(rt); \
76 	else \
77 		(rt)->rt_refcnt--;
78 
79 #ifdef	GATEWAY
80 #define	RTHASHSIZ	64
81 #else
82 #define	RTHASHSIZ	8
83 #endif
84 #if	(RTHASHSIZ & (RTHASHSIZ - 1)) == 0
85 #define RTHASHMOD(h)	((h) & (RTHASHSIZ - 1))
86 #else
87 #define RTHASHMOD(h)	((h) % RTHASHSIZ)
88 #endif
89 struct	mbuf *rthost[RTHASHSIZ];
90 struct	mbuf *rtnet[RTHASHSIZ];
91 struct	rtstat	rtstat;
92 #endif
93