xref: /csrg-svn/sys/net/route.h (revision 7156)
1 /*	route.h	4.8	82/06/12	*/
2 
3 /*
4  * Kernel resident routing tables.
5  *
6  * The routing tables are initialized at boot time by
7  * making entries for all directly connected interfaces.
8  * Routing daemons can thereafter update the routing tables.
9  *
10  * TODO:
11  *	keep statistics
12  */
13 
14 /*
15  * A route consists of a destination address and a reference
16  * to a routing entry.  These are often held by protocols
17  * in their control blocks, e.g. inpcb.
18  */
19 struct route {
20 	struct	rtentry *ro_rt;
21 	struct	sockaddr ro_dst;
22 #ifdef notdef
23 	caddr_t	ro_pcb;			/* not used yet */
24 #endif
25 };
26 #ifdef KERNEL
27 /*
28  * The route ``routetoif'' is a special atom passed to the output routines
29  * to implement the SO_DONTROUTE option.
30  */
31 struct	route routetoif;
32 #endif
33 
34 /*
35  * We distinguish between routes to hosts and routes to networks,
36  * preferring the former if available.  For each route we infer
37  * the interface to use from the gateway address supplied when
38  * the route was entered.  Routes that forward packets through
39  * gateways are marked so that the output routines know to address the
40  * gateway rather than the ultimate destination.
41  */
42 struct rtentry {
43 	u_long	rt_hash;		/* to speed lookups */
44 	struct	sockaddr rt_dst;	/* key */
45 	struct	sockaddr rt_gateway;	/* value */
46 	short	rt_flags;		/* up/down?, host/net */
47 	short	rt_refcnt;		/* # held references */
48 	u_long	rt_use;			/* raw # packets forwarded */
49 	struct	ifnet *rt_ifp;		/* the answer: interface to use */
50 };
51 #ifdef KERNEL
52 #define	RTHASHSIZ	7
53 struct	mbuf *rthost[RTHASHSIZ];
54 struct	mbuf *rtnet[RTHASHSIZ];
55 #endif
56 
57 #define	RTF_UP		0x1		/* route useable */
58 #define	RTF_GATEWAY	0x2		/* destination is a gateway */
59 #define	RTF_HOST	0x4		/* host entry (net otherwise) */
60 
61 #define	RTFREE(rt) \
62 	if ((rt)->rt_refcnt == 1) \
63 		rtfree(rt); \
64 	else \
65 		(rt)->rt_refcnt--;
66