xref: /csrg-svn/sys/net/route.h (revision 24776)
1 /*
2  * Copyright (c) 1980 Regents of the University of California.
3  * All rights reserved.  The Berkeley software License Agreement
4  * specifies the terms and conditions for redistribution.
5  *
6  *	@(#)route.h	6.6 (Berkeley) 09/16/85
7  */
8 
9 /*
10  * Kernel resident routing tables.
11  *
12  * The routing tables are initialized when interface addresses
13  * are set by making entries for all directly connected interfaces.
14  */
15 
16 /*
17  * A route consists of a destination address and a reference
18  * to a routing entry.  These are often held by protocols
19  * in their control blocks, e.g. inpcb.
20  */
21 struct route {
22 	struct	rtentry *ro_rt;
23 	struct	sockaddr ro_dst;
24 };
25 
26 /*
27  * We distinguish between routes to hosts and routes to networks,
28  * preferring the former if available.  For each route we infer
29  * the interface to use from the gateway address supplied when
30  * the route was entered.  Routes that forward packets through
31  * gateways are marked so that the output routines know to address the
32  * gateway rather than the ultimate destination.
33  */
34 struct rtentry {
35 	u_long	rt_hash;		/* to speed lookups */
36 	struct	sockaddr rt_dst;	/* key */
37 	struct	sockaddr rt_gateway;	/* value */
38 	short	rt_flags;		/* up/down?, host/net */
39 	short	rt_refcnt;		/* # held references */
40 	u_long	rt_use;			/* raw # packets forwarded */
41 	struct	ifnet *rt_ifp;		/* the answer: interface to use */
42 #ifdef BBNNET
43 	union {				/* domain specific info */
44 	    struct {
45 		int in_rt_pc;		/* count of pings not answered */
46 	    } rt_in_data;
47 
48 #define	irt_pings	rt_data.rt_in_data.in_rt_pc
49 #define irt_gdown	rt_data.rt_in_data.in_rt_pc
50 
51 	    char rt_dummy[32];
52 	} rt_data;
53 #endif
54 };
55 
56 #define	RTF_UP		0x1		/* route useable */
57 #define	RTF_GATEWAY	0x2		/* destination is a gateway */
58 #define	RTF_HOST	0x4		/* host entry (net otherwise) */
59 #define RTF_REINSTATE	0x8		/* re-instate route after timeout */
60 #define	RTF_DYNAMIC	0x10		/* created dynamically (by redirect) */
61 
62 /*
63  * Routing statistics.
64  */
65 struct	rtstat {
66 	short	rts_badredirect;	/* bogus redirect calls */
67 	short	rts_dynamic;		/* routes created by redirects */
68 	short	rts_newgateway;		/* routes modified by redirects */
69 	short	rts_unreach;		/* lookups which failed */
70 	short	rts_wildcard;		/* lookups satisfied by a wildcard */
71 };
72 
73 #ifdef KERNEL
74 #define	RTFREE(rt) \
75 	if ((rt)->rt_refcnt == 1) \
76 		rtfree(rt); \
77 	else \
78 		(rt)->rt_refcnt--;
79 
80 #ifdef	GATEWAY
81 #define	RTHASHSIZ	64
82 #else
83 #define	RTHASHSIZ	8
84 #endif
85 #if	(RTHASHSIZ & (RTHASHSIZ - 1)) == 0
86 #define RTHASHMOD(h)	((h) & (RTHASHSIZ - 1))
87 #else
88 #define RTHASHMOD(h)	((h) % RTHASHSIZ)
89 #endif
90 struct	mbuf *rthost[RTHASHSIZ];
91 struct	mbuf *rtnet[RTHASHSIZ];
92 struct	rtstat	rtstat;
93 #endif
94