xref: /csrg-svn/sys/net/route.h (revision 33183)
123164Smckusick /*
229070Smckusick  * Copyright (c) 1980, 1986 Regents of the University of California.
3*33183Sbostic  * All rights reserved.
423164Smckusick  *
5*33183Sbostic  * Redistribution and use in source and binary forms are permitted
6*33183Sbostic  * provided that this notice is preserved and that due credit is given
7*33183Sbostic  * to the University of California at Berkeley. The name of the University
8*33183Sbostic  * may not be used to endorse or promote products derived from this
9*33183Sbostic  * software without specific prior written permission. This software
10*33183Sbostic  * is provided ``as is'' without express or implied warranty.
11*33183Sbostic  *
12*33183Sbostic  *	@(#)route.h	7.3 (Berkeley) 12/30/87
1323164Smckusick  */
146332Ssam 
156332Ssam /*
166412Ssam  * Kernel resident routing tables.
176412Ssam  *
1824776Skarels  * The routing tables are initialized when interface addresses
1924776Skarels  * are set by making entries for all directly connected interfaces.
206332Ssam  */
216332Ssam 
227156Swnj /*
237156Swnj  * A route consists of a destination address and a reference
247156Swnj  * to a routing entry.  These are often held by protocols
257156Swnj  * in their control blocks, e.g. inpcb.
267156Swnj  */
276332Ssam struct route {
286332Ssam 	struct	rtentry *ro_rt;
296332Ssam 	struct	sockaddr ro_dst;
306332Ssam };
316332Ssam 
326332Ssam /*
337156Swnj  * We distinguish between routes to hosts and routes to networks,
347156Swnj  * preferring the former if available.  For each route we infer
357156Swnj  * the interface to use from the gateway address supplied when
367156Swnj  * the route was entered.  Routes that forward packets through
377156Swnj  * gateways are marked so that the output routines know to address the
387156Swnj  * gateway rather than the ultimate destination.
396332Ssam  */
407156Swnj struct rtentry {
417156Swnj 	u_long	rt_hash;		/* to speed lookups */
427156Swnj 	struct	sockaddr rt_dst;	/* key */
437156Swnj 	struct	sockaddr rt_gateway;	/* value */
447156Swnj 	short	rt_flags;		/* up/down?, host/net */
457156Swnj 	short	rt_refcnt;		/* # held references */
467156Swnj 	u_long	rt_use;			/* raw # packets forwarded */
477156Swnj 	struct	ifnet *rt_ifp;		/* the answer: interface to use */
487156Swnj };
497156Swnj 
506339Ssam #define	RTF_UP		0x1		/* route useable */
517156Swnj #define	RTF_GATEWAY	0x2		/* destination is a gateway */
526377Ssam #define	RTF_HOST	0x4		/* host entry (net otherwise) */
5324776Skarels #define	RTF_DYNAMIC	0x10		/* created dynamically (by redirect) */
5430396Skarels #define	RTF_MODIFIED	0x20		/* modified dynamically (by redirect) */
556332Ssam 
5612832Ssam /*
5712832Ssam  * Routing statistics.
5812832Ssam  */
5912832Ssam struct	rtstat {
6012832Ssam 	short	rts_badredirect;	/* bogus redirect calls */
6112832Ssam 	short	rts_dynamic;		/* routes created by redirects */
6212832Ssam 	short	rts_newgateway;		/* routes modified by redirects */
6312832Ssam 	short	rts_unreach;		/* lookups which failed */
6412832Ssam 	short	rts_wildcard;		/* lookups satisfied by a wildcard */
6512832Ssam };
6612832Ssam 
6712832Ssam #ifdef KERNEL
686412Ssam #define	RTFREE(rt) \
696412Ssam 	if ((rt)->rt_refcnt == 1) \
706412Ssam 		rtfree(rt); \
716412Ssam 	else \
726412Ssam 		(rt)->rt_refcnt--;
7312832Ssam 
7417067Skarels #ifdef	GATEWAY
7517067Skarels #define	RTHASHSIZ	64
7617067Skarels #else
7716554Skarels #define	RTHASHSIZ	8
7817067Skarels #endif
7916554Skarels #if	(RTHASHSIZ & (RTHASHSIZ - 1)) == 0
8016554Skarels #define RTHASHMOD(h)	((h) & (RTHASHSIZ - 1))
8116554Skarels #else
8216554Skarels #define RTHASHMOD(h)	((h) % RTHASHSIZ)
8316554Skarels #endif
8412832Ssam struct	mbuf *rthost[RTHASHSIZ];
8512832Ssam struct	mbuf *rtnet[RTHASHSIZ];
8612832Ssam struct	rtstat	rtstat;
8712832Ssam #endif
88