xref: /csrg-svn/sys/net/route.h (revision 12414)
1 /*	route.h	4.9	83/05/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 
27 /*
28  * We distinguish between routes to hosts and routes to networks,
29  * preferring the former if available.  For each route we infer
30  * the interface to use from the gateway address supplied when
31  * the route was entered.  Routes that forward packets through
32  * gateways are marked so that the output routines know to address the
33  * gateway rather than the ultimate destination.
34  */
35 struct rtentry {
36 	u_long	rt_hash;		/* to speed lookups */
37 	struct	sockaddr rt_dst;	/* key */
38 	struct	sockaddr rt_gateway;	/* value */
39 	short	rt_flags;		/* up/down?, host/net */
40 	short	rt_refcnt;		/* # held references */
41 	u_long	rt_use;			/* raw # packets forwarded */
42 	struct	ifnet *rt_ifp;		/* the answer: interface to use */
43 };
44 #ifdef KERNEL
45 #define	RTHASHSIZ	7
46 struct	mbuf *rthost[RTHASHSIZ];
47 struct	mbuf *rtnet[RTHASHSIZ];
48 #endif
49 
50 #define	RTF_UP		0x1		/* route useable */
51 #define	RTF_GATEWAY	0x2		/* destination is a gateway */
52 #define	RTF_HOST	0x4		/* host entry (net otherwise) */
53 
54 #define	RTFREE(rt) \
55 	if ((rt)->rt_refcnt == 1) \
56 		rtfree(rt); \
57 	else \
58 		(rt)->rt_refcnt--;
59