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