xref: /original-bsd/sbin/routed/defs.h (revision c7de680c)
1 /*	defs.h	4.10	82/06/10	*/
2 
3 /*
4  * Internal data structure definitions for
5  * user routing process.  Based on Xerox NS
6  * protocol specs with mods relevant to more
7  * general addressing scheme.
8  */
9 #include <net/route.h>
10 
11 /*
12  * An ``interface'' is similar to an ifnet structure,
13  * except it doesn't contain q'ing info, and it also
14  * handles ``logical'' interfaces (remote gateways
15  * that we want to keep polling even if they go down).
16  * The list of interfaces which we maintain is used
17  * in supplying the gratuitous routing table updates.
18  */
19 struct interface {
20 	struct	interface *int_next;
21 	struct	sockaddr int_addr;		/* address on this host */
22 	union {
23 		struct	sockaddr intu_broadaddr;
24 		struct	sockaddr intu_dstaddr;
25 	} int_intu;
26 #define	int_broadaddr	int_intu.intu_broadaddr	/* broadcast address */
27 #define	int_dstaddr	int_intu.intu_dstaddr	/* other end of p-to-p link */
28 	int	int_metric;			/* init's routing entry */
29 	int	int_flags;			/* see below */
30 	int	int_net;			/* network # */
31 };
32 
33 /*
34  * 0x1 to 0x10 are reused from the kernel's ifnet definitions,
35  * the others agree with the RTS_ flags defined below
36  */
37 #define	IFF_UP		0x1		/* interface is up */
38 #define	IFF_BROADCAST	0x2		/* broadcast address valid */
39 #define	IFF_DEBUG	0x4		/* turn on debugging */
40 #define	IFF_ROUTE	0x8		/* routing entry installed */
41 #define	IFF_POINTOPOINT	0x10		/* interface is point-to-point link */
42 #define	IFF_PASSIVE	0x20		/* can't tell if up/down */
43 #define	IFF_INTERFACE	0x40		/* hardware interface */
44 #define	IFF_REMOTE	0x80		/* interface isn't on this machine */
45 
46 /*
47  * Routing table structure; differs a bit from kernel tables.
48  *
49  * Note: the union below must agree in the first 4 members
50  * so the ioctl's will work.
51  */
52 struct rthash {
53 	struct	rt_entry *rt_forw;
54 	struct	rt_entry *rt_back;
55 };
56 
57 struct rt_entry {
58 	struct	rt_entry *rt_forw;
59 	struct	rt_entry *rt_back;
60 	union {
61 		struct	rtentry rtu_rt;
62 		struct {
63 			u_long	rtu_hash;
64 			struct	sockaddr rtu_dst;
65 			struct	sockaddr rtu_router;
66 			short	rtu_flags;
67 			short	rtu_state;
68 			int	rtu_timer;
69 			int	rtu_metric;
70 			struct	interface *rtu_ifp;
71 		} rtu_entry;
72 	} rt_rtu;
73 };
74 
75 #define	rt_rt		rt_rtu.rtu_rt			/* pass to ioctl */
76 #define	rt_hash		rt_rtu.rtu_entry.rtu_hash	/* for net or host */
77 #define	rt_dst		rt_rtu.rtu_entry.rtu_dst	/* match value */
78 #define	rt_router	rt_rtu.rtu_entry.rtu_router	/* who to forward to */
79 #define	rt_flags	rt_rtu.rtu_entry.rtu_flags	/* kernel flags */
80 #define	rt_timer	rt_rtu.rtu_entry.rtu_timer	/* for invalidation */
81 #define	rt_state	rt_rtu.rtu_entry.rtu_state	/* see below */
82 #define	rt_metric	rt_rtu.rtu_entry.rtu_metric	/* cost of route */
83 #define	rt_ifp		rt_rtu.rtu_entry.rtu_ifp	/* interface to take */
84 
85 #define	ROUTEHASHSIZ	19
86 
87 /*
88  * "State" of routing table entry.
89  */
90 #define	RTS_CHANGED	0x1		/* route has been altered recently */
91 #define	RTS_PASSIVE	0x20		/* don't time out route */
92 #define	RTS_INTERFACE	0x40		/* route is for network interface */
93 #define	RTS_REMOTE	0x80		/* route is for ``remote'' entity */
94 
95 struct	rthash nethash[ROUTEHASHSIZ], hosthash[ROUTEHASHSIZ];
96 struct	rt_entry *rtlookup(), *rtfind();
97 
98 /*
99  * Per address family routines.
100  */
101 struct afswitch {
102 	int	(*af_hash)();		/* returns keys based on address */
103 	int	(*af_netmatch)();	/* verifies net # matching */
104 	int	(*af_output)();		/* interprets address for sending */
105 	int	(*af_portmatch)();	/* packet from some other router? */
106 	int	(*af_portcheck)();	/* packet from priviledged peer? */
107 	int	(*af_checkhost)();	/* tells if address for host or net */
108 	int	(*af_canon)();		/* canonicalize address for compares */
109 };
110 
111 /*
112  * Structure returned by af_hash routines.
113  */
114 struct afhash {
115 	u_int	afh_hosthash;		/* host based hash */
116 	u_int	afh_nethash;		/* network based hash */
117 };
118 
119 struct	afswitch afswitch[AF_MAX];	/* table proper */
120 
121 /*
122  * When we find any interfaces marked down we rescan the
123  * kernel every CHECK_INTERVAL seconds to see if they've
124  * come up.
125  */
126 #define	CHECK_INTERVAL	(1*60)
127