xref: /csrg-svn/sys/net/route.h (revision 24776)
123164Smckusick /*
223164Smckusick  * Copyright (c) 1980 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*24776Skarels  *	@(#)route.h	6.6 (Berkeley) 09/16/85
723164Smckusick  */
86332Ssam 
96332Ssam /*
106412Ssam  * Kernel resident routing tables.
116412Ssam  *
12*24776Skarels  * The routing tables are initialized when interface addresses
13*24776Skarels  * 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 */
42*24776Skarels #ifdef BBNNET
4324381Swalsh 	union {				/* domain specific info */
4424381Swalsh 	    struct {
4524381Swalsh 		int in_rt_pc;		/* count of pings not answered */
4624381Swalsh 	    } rt_in_data;
4724381Swalsh 
4824381Swalsh #define	irt_pings	rt_data.rt_in_data.in_rt_pc
4924381Swalsh #define irt_gdown	rt_data.rt_in_data.in_rt_pc
5024381Swalsh 
5124381Swalsh 	    char rt_dummy[32];
5224381Swalsh 	} rt_data;
53*24776Skarels #endif
547156Swnj };
557156Swnj 
566339Ssam #define	RTF_UP		0x1		/* route useable */
577156Swnj #define	RTF_GATEWAY	0x2		/* destination is a gateway */
586377Ssam #define	RTF_HOST	0x4		/* host entry (net otherwise) */
5924381Swalsh #define RTF_REINSTATE	0x8		/* re-instate route after timeout */
60*24776Skarels #define	RTF_DYNAMIC	0x10		/* created dynamically (by redirect) */
616332Ssam 
6212832Ssam /*
6312832Ssam  * Routing statistics.
6412832Ssam  */
6512832Ssam struct	rtstat {
6612832Ssam 	short	rts_badredirect;	/* bogus redirect calls */
6712832Ssam 	short	rts_dynamic;		/* routes created by redirects */
6812832Ssam 	short	rts_newgateway;		/* routes modified by redirects */
6912832Ssam 	short	rts_unreach;		/* lookups which failed */
7012832Ssam 	short	rts_wildcard;		/* lookups satisfied by a wildcard */
7112832Ssam };
7212832Ssam 
7312832Ssam #ifdef KERNEL
746412Ssam #define	RTFREE(rt) \
756412Ssam 	if ((rt)->rt_refcnt == 1) \
766412Ssam 		rtfree(rt); \
776412Ssam 	else \
786412Ssam 		(rt)->rt_refcnt--;
7912832Ssam 
8017067Skarels #ifdef	GATEWAY
8117067Skarels #define	RTHASHSIZ	64
8217067Skarels #else
8316554Skarels #define	RTHASHSIZ	8
8417067Skarels #endif
8516554Skarels #if	(RTHASHSIZ & (RTHASHSIZ - 1)) == 0
8616554Skarels #define RTHASHMOD(h)	((h) & (RTHASHSIZ - 1))
8716554Skarels #else
8816554Skarels #define RTHASHMOD(h)	((h) % RTHASHSIZ)
8916554Skarels #endif
9012832Ssam struct	mbuf *rthost[RTHASHSIZ];
9112832Ssam struct	mbuf *rtnet[RTHASHSIZ];
9212832Ssam struct	rtstat	rtstat;
9312832Ssam #endif
94