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