xref: /csrg-svn/sys/net/route.h (revision 29070)
123164Smckusick /*
2*29070Smckusick  * Copyright (c) 1980, 1986 Regents of the University of California.
323164Smckusick  * All rights reserved.  The Berkeley software License Agreement
423164Smckusick  * specifies the terms and conditions for redistribution.
523164Smckusick  *
6*29070Smckusick  *	@(#)route.h	7.1 (Berkeley) 06/04/86
723164Smckusick  */
86332Ssam 
96332Ssam /*
106412Ssam  * Kernel resident routing tables.
116412Ssam  *
1224776Skarels  * The routing tables are initialized when interface addresses
1324776Skarels  * are set by making entries for all directly connected interfaces.
146332Ssam  */
156332Ssam 
167156Swnj /*
177156Swnj  * A route consists of a destination address and a reference
187156Swnj  * to a routing entry.  These are often held by protocols
197156Swnj  * in their control blocks, e.g. inpcb.
207156Swnj  */
216332Ssam struct route {
226332Ssam 	struct	rtentry *ro_rt;
236332Ssam 	struct	sockaddr ro_dst;
246332Ssam };
256332Ssam 
266332Ssam /*
277156Swnj  * We distinguish between routes to hosts and routes to networks,
287156Swnj  * preferring the former if available.  For each route we infer
297156Swnj  * the interface to use from the gateway address supplied when
307156Swnj  * the route was entered.  Routes that forward packets through
317156Swnj  * gateways are marked so that the output routines know to address the
327156Swnj  * gateway rather than the ultimate destination.
336332Ssam  */
347156Swnj struct rtentry {
357156Swnj 	u_long	rt_hash;		/* to speed lookups */
367156Swnj 	struct	sockaddr rt_dst;	/* key */
377156Swnj 	struct	sockaddr rt_gateway;	/* value */
387156Swnj 	short	rt_flags;		/* up/down?, host/net */
397156Swnj 	short	rt_refcnt;		/* # held references */
407156Swnj 	u_long	rt_use;			/* raw # packets forwarded */
417156Swnj 	struct	ifnet *rt_ifp;		/* the answer: interface to use */
427156Swnj };
437156Swnj 
446339Ssam #define	RTF_UP		0x1		/* route useable */
457156Swnj #define	RTF_GATEWAY	0x2		/* destination is a gateway */
466377Ssam #define	RTF_HOST	0x4		/* host entry (net otherwise) */
4724776Skarels #define	RTF_DYNAMIC	0x10		/* created dynamically (by redirect) */
486332Ssam 
4912832Ssam /*
5012832Ssam  * Routing statistics.
5112832Ssam  */
5212832Ssam struct	rtstat {
5312832Ssam 	short	rts_badredirect;	/* bogus redirect calls */
5412832Ssam 	short	rts_dynamic;		/* routes created by redirects */
5512832Ssam 	short	rts_newgateway;		/* routes modified by redirects */
5612832Ssam 	short	rts_unreach;		/* lookups which failed */
5712832Ssam 	short	rts_wildcard;		/* lookups satisfied by a wildcard */
5812832Ssam };
5912832Ssam 
6012832Ssam #ifdef KERNEL
616412Ssam #define	RTFREE(rt) \
626412Ssam 	if ((rt)->rt_refcnt == 1) \
636412Ssam 		rtfree(rt); \
646412Ssam 	else \
656412Ssam 		(rt)->rt_refcnt--;
6612832Ssam 
6717067Skarels #ifdef	GATEWAY
6817067Skarels #define	RTHASHSIZ	64
6917067Skarels #else
7016554Skarels #define	RTHASHSIZ	8
7117067Skarels #endif
7216554Skarels #if	(RTHASHSIZ & (RTHASHSIZ - 1)) == 0
7316554Skarels #define RTHASHMOD(h)	((h) & (RTHASHSIZ - 1))
7416554Skarels #else
7516554Skarels #define RTHASHMOD(h)	((h) % RTHASHSIZ)
7616554Skarels #endif
7712832Ssam struct	mbuf *rthost[RTHASHSIZ];
7812832Ssam struct	mbuf *rtnet[RTHASHSIZ];
7912832Ssam struct	rtstat	rtstat;
8012832Ssam #endif
81