Commit | Line | Data |
---|---|---|
18916298 RG |
1 | /* |
2 | * Copyright (c) 1985 The Regents of the University of California. | |
3 | * All rights reserved. | |
4 | * | |
5 | * This file includes significant work done at Cornell University by | |
6 | * Bill Nesheim. That work included by permission. | |
7 | * | |
8 | * Redistribution and use in source and binary forms, with or without | |
9 | * modification, are permitted provided that the following conditions | |
10 | * are met: | |
11 | * 1. Redistributions of source code must retain the above copyright | |
12 | * notice, this list of conditions and the following disclaimer. | |
13 | * 2. Redistributions in binary form must reproduce the above copyright | |
14 | * notice, this list of conditions and the following disclaimer in the | |
15 | * documentation and/or other materials provided with the distribution. | |
16 | * 3. All advertising materials mentioning features or use of this software | |
17 | * must display the following acknowledgement: | |
18 | * This product includes software developed by the University of | |
19 | * California, Berkeley and its contributors. | |
20 | * 4. Neither the name of the University nor the names of its contributors | |
21 | * may be used to endorse or promote products derived from this software | |
22 | * without specific prior written permission. | |
23 | * | |
24 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
25 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
27 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
30 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
31 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
32 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
33 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
34 | * SUCH DAMAGE. | |
35 | */ | |
36 | ||
37 | #ifndef lint | |
38 | static char sccsid[] = "@(#)af.c 5.11 (Berkeley) 2/26/91"; | |
39 | #endif /* not lint */ | |
40 | ||
41 | #include "defs.h" | |
42 | ||
43 | /* | |
44 | * Address family support routines | |
45 | */ | |
46 | int null_hash(), null_netmatch(), null_output(), | |
47 | null_portmatch(), null_portcheck(), | |
48 | null_checkhost(), null_ishost(), null_canon(); | |
49 | int xnnet_hash(), xnnet_netmatch(), xnnet_output(), | |
50 | xnnet_portmatch(), | |
51 | xnnet_checkhost(), xnnet_ishost(), xnnet_canon(); | |
52 | #define NIL \ | |
53 | { null_hash, null_netmatch, null_output, \ | |
54 | null_portmatch, null_portcheck, null_checkhost, \ | |
55 | null_ishost, null_canon } | |
56 | #define XNSNET \ | |
57 | { xnnet_hash, xnnet_netmatch, xnnet_output, \ | |
58 | xnnet_portmatch, xnnet_portmatch, xnnet_checkhost, \ | |
59 | xnnet_ishost, xnnet_canon } | |
60 | ||
61 | struct afswitch afswitch[AF_MAX] = | |
62 | { NIL, NIL, NIL, NIL, NIL, NIL, XNSNET, NIL, NIL, NIL, NIL }; | |
63 | ||
64 | struct sockaddr_ns xnnet_default = { sizeof(struct sockaddr_ns), AF_NS }; | |
65 | ||
66 | union ns_net ns_anynet; | |
67 | union ns_net ns_zeronet; | |
68 | ||
69 | xnnet_hash(sns, hp) | |
70 | register struct sockaddr_ns *sns; | |
71 | struct afhash *hp; | |
72 | { | |
73 | register long hash = 0; | |
74 | register u_short *s = sns->sns_addr.x_host.s_host; | |
75 | union ns_net_u net; | |
76 | ||
77 | net.net_e = sns->sns_addr.x_net; | |
78 | hp->afh_nethash = net.long_e; | |
79 | hash = *s++; hash <<= 8; hash += *s++; hash <<= 8; hash += *s; | |
80 | hp->afh_hosthash = hash; | |
81 | } | |
82 | ||
83 | xnnet_netmatch(sxn1, sxn2) | |
84 | struct sockaddr_ns *sxn1, *sxn2; | |
85 | { | |
86 | return (ns_neteq(sxn1->sns_addr, sxn2->sns_addr)); | |
87 | } | |
88 | ||
89 | /* | |
90 | * Verify the message is from the right port. | |
91 | */ | |
92 | xnnet_portmatch(sns) | |
93 | register struct sockaddr_ns *sns; | |
94 | { | |
95 | ||
96 | return (ntohs(sns->sns_addr.x_port) == IDPPORT_RIF ); | |
97 | } | |
98 | ||
99 | ||
100 | /* | |
101 | * xns output routine. | |
102 | */ | |
103 | #ifdef DEBUG | |
104 | int do_output = 0; | |
105 | #endif | |
106 | xnnet_output(flags, sns, size) | |
107 | int flags; | |
108 | struct sockaddr_ns *sns; | |
109 | int size; | |
110 | { | |
111 | struct sockaddr_ns dst; | |
112 | ||
113 | dst = *sns; | |
114 | sns = &dst; | |
115 | if (sns->sns_addr.x_port == 0) | |
116 | sns->sns_addr.x_port = htons(IDPPORT_RIF); | |
117 | #ifdef DEBUG | |
118 | if(do_output || ntohs(msg->rip_cmd) == RIPCMD_REQUEST) | |
119 | #endif | |
120 | /* | |
121 | * Kludge to allow us to get routes out to machines that | |
122 | * don't know their addresses yet; send to that address on | |
123 | * ALL connected nets | |
124 | */ | |
125 | if (ns_neteqnn(sns->sns_addr.x_net, ns_zeronet)) { | |
126 | extern struct interface *ifnet; | |
127 | register struct interface *ifp; | |
128 | ||
129 | for (ifp = ifnet; ifp; ifp = ifp->int_next) { | |
130 | sns->sns_addr.x_net = | |
131 | satons_addr(ifp->int_addr).x_net; | |
132 | (void) sendto(s, msg, size, flags, | |
133 | (struct sockaddr *)sns, sizeof (*sns)); | |
134 | } | |
135 | return; | |
136 | } | |
137 | ||
138 | (void) sendto(s, msg, size, flags, | |
139 | (struct sockaddr *)sns, sizeof (*sns)); | |
140 | } | |
141 | ||
142 | /* | |
143 | * Return 1 if we want this route. | |
144 | * We use this to disallow route net G entries for one for multiple | |
145 | * point to point links. | |
146 | */ | |
147 | xnnet_checkhost(sns) | |
148 | struct sockaddr_ns *sns; | |
149 | { | |
150 | register struct interface *ifp = if_ifwithnet(sns); | |
151 | /* | |
152 | * We want this route if there is no more than one | |
153 | * point to point interface with this network. | |
154 | */ | |
155 | if (ifp == 0 || (ifp->int_flags & IFF_POINTOPOINT)==0) return (1); | |
156 | return (ifp->int_sq.n == ifp->int_sq.p); | |
157 | } | |
158 | ||
159 | /* | |
160 | * Return 1 if the address is | |
161 | * for a host, 0 for a network. | |
162 | */ | |
163 | xnnet_ishost(sns) | |
164 | struct sockaddr_ns *sns; | |
165 | { | |
166 | register u_short *s = sns->sns_addr.x_host.s_host; | |
167 | ||
168 | if ((s[0]==0xffff) && (s[1]==0xffff) && (s[2]==0xffff)) | |
169 | return (0); | |
170 | else | |
171 | return (1); | |
172 | } | |
173 | ||
174 | xnnet_canon(sns) | |
175 | struct sockaddr_ns *sns; | |
176 | { | |
177 | ||
178 | sns->sns_addr.x_port = 0; | |
179 | } | |
180 | ||
181 | /*ARGSUSED*/ | |
182 | null_hash(addr, hp) | |
183 | struct sockaddr *addr; | |
184 | struct afhash *hp; | |
185 | { | |
186 | ||
187 | hp->afh_nethash = hp->afh_hosthash = 0; | |
188 | } | |
189 | ||
190 | /*ARGSUSED*/ | |
191 | null_netmatch(a1, a2) | |
192 | struct sockaddr *a1, *a2; | |
193 | { | |
194 | ||
195 | return (0); | |
196 | } | |
197 | ||
198 | /*ARGSUSED*/ | |
199 | null_output(s, f, a1, n) | |
200 | int s, f; | |
201 | struct sockaddr *a1; | |
202 | int n; | |
203 | { | |
204 | ||
205 | ; | |
206 | } | |
207 | ||
208 | /*ARGSUSED*/ | |
209 | null_portmatch(a1) | |
210 | struct sockaddr *a1; | |
211 | { | |
212 | ||
213 | return (0); | |
214 | } | |
215 | ||
216 | /*ARGSUSED*/ | |
217 | null_portcheck(a1) | |
218 | struct sockaddr *a1; | |
219 | { | |
220 | ||
221 | return (0); | |
222 | } | |
223 | ||
224 | /*ARGSUSED*/ | |
225 | null_ishost(a1) | |
226 | struct sockaddr *a1; | |
227 | { | |
228 | ||
229 | return (0); | |
230 | } | |
231 | ||
232 | /*ARGSUSED*/ | |
233 | null_checkhost(a1) | |
234 | struct sockaddr *a1; | |
235 | { | |
236 | ||
237 | return (0); | |
238 | } | |
239 | ||
240 | /*ARGSUSED*/ | |
241 | null_canon(a1) | |
242 | struct sockaddr *a1; | |
243 | { | |
244 | ||
245 | ; | |
246 | } |