xref: /original-bsd/sbin/routed/defs.h (revision f0fd5f8a)
1 /*	defs.h	4.12	82/11/14	*/
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 <sys/types.h>
10 #include <sys/socket.h>
11 
12 #include <net/route.h>
13 #include <netinet/in.h>
14 
15 #include <stdio.h>
16 #include <netdb.h>
17 
18 #include "rip.h"
19 
20 /*
21  * Trace record format.
22  */
23 struct	iftrace {
24 	time_t	ift_stamp;		/* time stamp */
25 	struct	sockaddr ift_who;	/* from/to */
26 	char	*ift_packet;		/* pointer to packet */
27 	short	ift_size;		/* size of packet */
28 	short	ift_metric;		/* metric on associated metric */
29 };
30 
31 /*
32  * Per interface packet tracing buffers.  An incoming and
33  * outgoing circular buffer of packets is maintained, per
34  * interface, for debugging.  Buffers are dumped whenever
35  * an interface is marked down.
36  */
37 struct	ifdebug {
38 	struct	iftrace *ifd_records;	/* array of trace records */
39 	struct	iftrace *ifd_front;	/* next empty trace record */
40 	struct	interface *ifd_if;	/* for locating stuff */
41 };
42 
43 /*
44  * An ``interface'' is similar to an ifnet structure,
45  * except it doesn't contain q'ing info, and it also
46  * handles ``logical'' interfaces (remote gateways
47  * that we want to keep polling even if they go down).
48  * The list of interfaces which we maintain is used
49  * in supplying the gratuitous routing table updates.
50  */
51 struct interface {
52 	struct	interface *int_next;
53 	struct	sockaddr int_addr;		/* address on this host */
54 	union {
55 		struct	sockaddr intu_broadaddr;
56 		struct	sockaddr intu_dstaddr;
57 	} int_intu;
58 #define	int_broadaddr	int_intu.intu_broadaddr	/* broadcast address */
59 #define	int_dstaddr	int_intu.intu_dstaddr	/* other end of p-to-p link */
60 	int	int_metric;			/* init's routing entry */
61 	int	int_flags;			/* see below */
62 	int	int_net;			/* network # */
63 	struct	ifdebug int_input, int_output;	/* packet tracing stuff */
64 	int	int_ipackets;			/* input packets received */
65 	int	int_opackets;			/* output packets sent */
66 	char	*int_name;			/* from kernel if structure */
67 	u_short	int_transitions;		/* times gone up-down */
68 };
69 
70 /*
71  * 0x1 to 0x10 are reused from the kernel's ifnet definitions,
72  * the others agree with the RTS_ flags defined below
73  */
74 #define	IFF_UP		0x1		/* interface is up */
75 #define	IFF_BROADCAST	0x2		/* broadcast address valid */
76 #define	IFF_DEBUG	0x4		/* turn on debugging */
77 #define	IFF_ROUTE	0x8		/* routing entry installed */
78 #define	IFF_POINTOPOINT	0x10		/* interface is point-to-point link */
79 #define	IFF_PASSIVE	0x20		/* can't tell if up/down */
80 #define	IFF_INTERFACE	0x40		/* hardware interface */
81 #define	IFF_REMOTE	0x80		/* interface isn't on this machine */
82 
83 /*
84  * Routing table structure; differs a bit from kernel tables.
85  *
86  * Note: the union below must agree in the first 4 members
87  * so the ioctl's will work.
88  */
89 struct rthash {
90 	struct	rt_entry *rt_forw;
91 	struct	rt_entry *rt_back;
92 };
93 
94 struct rt_entry {
95 	struct	rt_entry *rt_forw;
96 	struct	rt_entry *rt_back;
97 	union {
98 		struct	rtentry rtu_rt;
99 		struct {
100 			u_long	rtu_hash;
101 			struct	sockaddr rtu_dst;
102 			struct	sockaddr rtu_router;
103 			short	rtu_flags;
104 			short	rtu_state;
105 			int	rtu_timer;
106 			int	rtu_metric;
107 			struct	interface *rtu_ifp;
108 		} rtu_entry;
109 	} rt_rtu;
110 };
111 
112 #define	rt_rt		rt_rtu.rtu_rt			/* pass to ioctl */
113 #define	rt_hash		rt_rtu.rtu_entry.rtu_hash	/* for net or host */
114 #define	rt_dst		rt_rtu.rtu_entry.rtu_dst	/* match value */
115 #define	rt_router	rt_rtu.rtu_entry.rtu_router	/* who to forward to */
116 #define	rt_flags	rt_rtu.rtu_entry.rtu_flags	/* kernel flags */
117 #define	rt_timer	rt_rtu.rtu_entry.rtu_timer	/* for invalidation */
118 #define	rt_state	rt_rtu.rtu_entry.rtu_state	/* see below */
119 #define	rt_metric	rt_rtu.rtu_entry.rtu_metric	/* cost of route */
120 #define	rt_ifp		rt_rtu.rtu_entry.rtu_ifp	/* interface to take */
121 
122 #define	ROUTEHASHSIZ	19
123 
124 /*
125  * "State" of routing table entry.
126  */
127 #define	RTS_CHANGED	0x1		/* route has been altered recently */
128 #define	RTS_PASSIVE	0x20		/* don't time out route */
129 #define	RTS_INTERFACE	0x40		/* route is for network interface */
130 #define	RTS_REMOTE	0x80		/* route is for ``remote'' entity */
131 
132 struct	rthash nethash[ROUTEHASHSIZ], hosthash[ROUTEHASHSIZ];
133 struct	rt_entry *rtlookup(), *rtfind();
134 
135 /*
136  * Per address family routines.
137  */
138 struct afswitch {
139 	int	(*af_hash)();		/* returns keys based on address */
140 	int	(*af_netmatch)();	/* verifies net # matching */
141 	int	(*af_output)();		/* interprets address for sending */
142 	int	(*af_portmatch)();	/* packet from some other router? */
143 	int	(*af_portcheck)();	/* packet from priviledged peer? */
144 	int	(*af_checkhost)();	/* tells if address for host or net */
145 	int	(*af_canon)();		/* canonicalize address for compares */
146 };
147 
148 /*
149  * Structure returned by af_hash routines.
150  */
151 struct afhash {
152 	u_int	afh_hosthash;		/* host based hash */
153 	u_int	afh_nethash;		/* network based hash */
154 };
155 
156 struct	afswitch afswitch[AF_MAX];	/* table proper */
157 
158 /*
159  * When we find any interfaces marked down we rescan the
160  * kernel every CHECK_INTERVAL seconds to see if they've
161  * come up.
162  */
163 #define	CHECK_INTERVAL	(1*60)
164 
165 #define	LOOPBACKNET	0177
166 /* casts to keep lint happy */
167 #define	insque(q,p)	_insque((caddr_t)q,(caddr_t)p)
168 #define	remque(q)	_remque((caddr_t)q)
169 #define equal(a1, a2) \
170 	(bcmp((caddr_t)(a1), (caddr_t)(a2), sizeof (struct sockaddr)) == 0)
171 #define	min(a,b)	((a)>(b)?(b):(a))
172 
173 struct	sockaddr_in routingaddr;
174 struct	sockaddr_in noroutingaddr;
175 
176 int	s;
177 int	snoroute;		/* socket with no routing */
178 int	kmem;
179 int	supplier;		/* process should supply updates */
180 int	install;		/* if 1 call kernel */
181 int	lookforinterfaces;
182 int	performnlist;
183 int	externalinterfaces;	/* # of remote and local interfaces */
184 int	timeval;
185 
186 /*
187  * Packet tracing stuff.
188  */
189 int	tracing;		/* on/off */
190 FILE	*ftrace;		/* output trace file */
191 #define	TRACE_ACTION(action, route) \
192 	{ if (tracing) \
193 		traceaction(ftrace, "action", route); \
194 	}
195 #define	TRACE_INPUT(ifp, from, size) \
196 	{ if (tracing) { \
197 		ifp = if_iflookup(from); \
198 		if (ifp) \
199 			trace(&ifp->int_input, from, packet, size, \
200 				ifp->int_metric); \
201 	  } \
202 	}
203 #define	TRACE_OUTPUT(ifp, to, size) \
204 	{ if (tracing) \
205 		trace(&ifp->int_output, to, packet, size, ifp->int_metric); \
206 	}
207 
208 char	packet[MAXPACKETSIZE+1];
209 struct	rip *msg;
210 
211 char	**argv0;
212 struct	servent *sp;
213 
214 struct	in_addr inet_makeaddr();
215 struct	interface *if_ifwithaddr(), *if_ifwithnet(), *if_iflookup();
216 extern	char *malloc(), *sys_errlist[];
217 extern	int errno, exit();
218 
219 int	sendmsg(), supply();
220 int	timer(), cleanup();
221