date and time created 83/01/11 14:35:38 by sam
[unix-history] / usr / src / sbin / routed / defs.h
CommitLineData
28d85f83 1/* defs.h 4.13 82/12/24 */
b242391c
SL
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 */
c8c4156e
SL
9#include <sys/types.h>
10#include <sys/socket.h>
4f306a0d 11
3cec0c76 12#include <net/route.h>
4f306a0d
SL
13#include <netinet/in.h>
14
c8c4156e
SL
15#include <stdio.h>
16#include <netdb.h>
4f306a0d 17
c8c4156e
SL
18#include "rip.h"
19
20/*
21 * Trace record format.
22 */
23struct 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 */
37struct 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};
b242391c 42
e0a3d4f9
SL
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 */
51struct 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 # */
c8c4156e
SL
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 */
e0a3d4f9
SL
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
b242391c 83/*
e6b5ed24
SL
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.
b242391c 88 */
3cec0c76 89struct rthash {
b242391c
SL
90 struct rt_entry *rt_forw;
91 struct rt_entry *rt_back;
92};
93
94struct rt_entry {
95 struct rt_entry *rt_forw;
96 struct rt_entry *rt_back;
3cec0c76
SL
97 union {
98 struct rtentry rtu_rt;
99 struct {
100 u_long rtu_hash;
101 struct sockaddr rtu_dst;
6a8616d4 102 struct sockaddr rtu_router;
3cec0c76 103 short rtu_flags;
e6b5ed24 104 short rtu_state;
6a8616d4 105 int rtu_timer;
3cec0c76 106 int rtu_metric;
e0a3d4f9 107 struct interface *rtu_ifp;
3cec0c76
SL
108 } rtu_entry;
109 } rt_rtu;
b242391c
SL
110};
111
3cec0c76
SL
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 */
6a8616d4 115#define rt_router rt_rtu.rtu_entry.rtu_router /* who to forward to */
e6b5ed24 116#define rt_flags rt_rtu.rtu_entry.rtu_flags /* kernel flags */
3cec0c76 117#define rt_timer rt_rtu.rtu_entry.rtu_timer /* for invalidation */
e6b5ed24 118#define rt_state rt_rtu.rtu_entry.rtu_state /* see below */
3cec0c76
SL
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
b242391c
SL
122#define ROUTEHASHSIZ 19
123
124/*
e6b5ed24 125 * "State" of routing table entry.
b242391c 126 */
e0a3d4f9
SL
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 */
b242391c 131
3cec0c76 132struct rthash nethash[ROUTEHASHSIZ], hosthash[ROUTEHASHSIZ];
eae14a37 133struct rt_entry *rtlookup(), *rtfind();
b242391c
SL
134
135/*
e6b5ed24 136 * Per address family routines.
b242391c
SL
137 */
138struct afswitch {
e6b5ed24
SL
139 int (*af_hash)(); /* returns keys based on address */
140 int (*af_netmatch)(); /* verifies net # matching */
141 int (*af_output)(); /* interprets address for sending */
75659c93
SL
142 int (*af_portmatch)(); /* packet from some other router? */
143 int (*af_portcheck)(); /* packet from priviledged peer? */
e6b5ed24 144 int (*af_checkhost)(); /* tells if address for host or net */
75659c93 145 int (*af_canon)(); /* canonicalize address for compares */
b242391c
SL
146};
147
e6b5ed24
SL
148/*
149 * Structure returned by af_hash routines.
150 */
b242391c 151struct afhash {
e6b5ed24
SL
152 u_int afh_hosthash; /* host based hash */
153 u_int afh_nethash; /* network based hash */
b242391c
SL
154};
155
e6b5ed24 156struct afswitch afswitch[AF_MAX]; /* table proper */
e0a3d4f9
SL
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)
c8c4156e
SL
164
165#define LOOPBACKNET 0177
c8c4156e
SL
166#define equal(a1, a2) \
167 (bcmp((caddr_t)(a1), (caddr_t)(a2), sizeof (struct sockaddr)) == 0)
168#define min(a,b) ((a)>(b)?(b):(a))
169
170struct sockaddr_in routingaddr;
171struct sockaddr_in noroutingaddr;
172
173int s;
174int snoroute; /* socket with no routing */
175int kmem;
176int supplier; /* process should supply updates */
177int install; /* if 1 call kernel */
178int lookforinterfaces;
179int performnlist;
180int externalinterfaces; /* # of remote and local interfaces */
181int timeval;
182
183/*
184 * Packet tracing stuff.
185 */
186int tracing; /* on/off */
187FILE *ftrace; /* output trace file */
188#define TRACE_ACTION(action, route) \
189 { if (tracing) \
190 traceaction(ftrace, "action", route); \
191 }
192#define TRACE_INPUT(ifp, from, size) \
193 { if (tracing) { \
194 ifp = if_iflookup(from); \
195 if (ifp) \
196 trace(&ifp->int_input, from, packet, size, \
197 ifp->int_metric); \
198 } \
199 }
200#define TRACE_OUTPUT(ifp, to, size) \
201 { if (tracing) \
202 trace(&ifp->int_output, to, packet, size, ifp->int_metric); \
203 }
204
205char packet[MAXPACKETSIZE+1];
206struct rip *msg;
207
208char **argv0;
209struct servent *sp;
210
211struct in_addr inet_makeaddr();
212struct interface *if_ifwithaddr(), *if_ifwithnet(), *if_iflookup();
213extern char *malloc(), *sys_errlist[];
214extern int errno, exit();
215
216int sendmsg(), supply();
217int timer(), cleanup();