Commit | Line | Data |
---|---|---|
4a10c08d | 1 | /* |
3565c602 KB |
2 | * Copyright (c) 1985 The Regents of the University of California. |
3 | * All rights reserved. | |
4a10c08d | 4 | * |
3565c602 KB |
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 are permitted | |
9 | * provided that the above copyright notice and this paragraph are | |
10 | * duplicated in all such forms and that any documentation, | |
11 | * advertising materials, and other materials related to such | |
12 | * distribution and use acknowledge that the software was developed | |
13 | * by the University of California, Berkeley. The name of the | |
14 | * University may not be used to endorse or promote products derived | |
15 | * from this software without specific prior written permission. | |
16 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR | |
17 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED | |
18 | * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
4a10c08d KS |
19 | */ |
20 | ||
53eed0ef | 21 | #ifndef lint |
3565c602 KB |
22 | static char sccsid[] = "@(#)af.c 5.8 (Berkeley) %G%"; |
23 | #endif /* not lint */ | |
53eed0ef KS |
24 | |
25 | #include "defs.h" | |
26 | ||
27 | /* | |
28 | * Address family support routines | |
29 | */ | |
30 | int null_hash(), null_netmatch(), null_output(), | |
31 | null_portmatch(), null_portcheck(), | |
32 | null_checkhost(), null_ishost(), null_canon(); | |
33 | int xnnet_hash(), xnnet_netmatch(), xnnet_output(), | |
5a2fd09e | 34 | xnnet_portmatch(), |
53eed0ef KS |
35 | xnnet_checkhost(), xnnet_ishost(), xnnet_canon(); |
36 | #define NIL \ | |
37 | { null_hash, null_netmatch, null_output, \ | |
38 | null_portmatch, null_portcheck, null_checkhost, \ | |
39 | null_ishost, null_canon } | |
40 | #define XNSNET \ | |
41 | { xnnet_hash, xnnet_netmatch, xnnet_output, \ | |
42 | xnnet_portmatch, xnnet_portmatch, xnnet_checkhost, \ | |
43 | xnnet_ishost, xnnet_canon } | |
44 | ||
45 | struct afswitch afswitch[AF_MAX] = | |
46 | { NIL, NIL, NIL, NIL, NIL, NIL, XNSNET, NIL, NIL, NIL, NIL }; | |
47 | ||
48681466 | 48 | struct sockaddr_ns xnnet_default = { AF_NS }; |
53eed0ef | 49 | |
0a5735f6 KS |
50 | union ns_net ns_anynet; |
51 | union ns_net ns_zeronet; | |
52 | ||
48681466 KS |
53 | xnnet_hash(sns, hp) |
54 | register struct sockaddr_ns *sns; | |
53eed0ef KS |
55 | struct afhash *hp; |
56 | { | |
48681466 KS |
57 | register long hash = 0; |
58 | register u_short *s = sns->sns_addr.x_host.s_host; | |
0a5735f6 KS |
59 | union ns_net_u net; |
60 | ||
61 | net.net_e = sns->sns_addr.x_net; | |
62 | hp->afh_nethash = net.long_e; | |
48681466 KS |
63 | hash = *s++; hash <<= 8; hash += *s++; hash <<= 8; hash += *s; |
64 | hp->afh_hosthash = hash; | |
53eed0ef KS |
65 | } |
66 | ||
67 | xnnet_netmatch(sxn1, sxn2) | |
48681466 | 68 | struct sockaddr_ns *sxn1, *sxn2; |
53eed0ef | 69 | { |
0a5735f6 | 70 | return (ns_neteq(sxn1->sns_addr, sxn2->sns_addr)); |
53eed0ef KS |
71 | } |
72 | ||
73 | /* | |
74 | * Verify the message is from the right port. | |
75 | */ | |
48681466 KS |
76 | xnnet_portmatch(sns) |
77 | register struct sockaddr_ns *sns; | |
53eed0ef KS |
78 | { |
79 | ||
48681466 | 80 | return (ntohs(sns->sns_addr.x_port) == IDPPORT_RIF ); |
53eed0ef KS |
81 | } |
82 | ||
83 | ||
84 | /* | |
85 | * xns output routine. | |
86 | */ | |
87 | #ifdef DEBUG | |
88 | int do_output = 0; | |
89 | #endif | |
48681466 KS |
90 | xnnet_output(flags, sns, size) |
91 | int flags; | |
92 | struct sockaddr_ns *sns; | |
53eed0ef KS |
93 | int size; |
94 | { | |
48681466 | 95 | struct sockaddr_ns dst; |
53eed0ef | 96 | |
48681466 KS |
97 | dst = *sns; |
98 | sns = &dst; | |
99 | if (sns->sns_addr.x_port == 0) | |
100 | sns->sns_addr.x_port = htons(IDPPORT_RIF); | |
53eed0ef KS |
101 | #ifdef DEBUG |
102 | if(do_output || ntohs(msg->rip_cmd) == RIPCMD_REQUEST) | |
103 | #endif | |
610b111d KS |
104 | /* |
105 | * Kludge to allow us to get routes out to machines that | |
106 | * don't know their addresses yet; send to that address on | |
107 | * ALL connected nets | |
108 | */ | |
0a5735f6 | 109 | if (ns_neteqnn(sns->sns_addr.x_net, ns_zeronet)) { |
610b111d KS |
110 | extern struct interface *ifnet; |
111 | register struct interface *ifp; | |
112 | ||
113 | for (ifp = ifnet; ifp; ifp = ifp->int_next) { | |
0a5735f6 KS |
114 | sns->sns_addr.x_net = |
115 | satons_addr(ifp->int_addr).x_net; | |
9562f6c6 | 116 | (void) sendto(s, msg, size, flags, sns, sizeof (*sns)); |
610b111d KS |
117 | } |
118 | return; | |
119 | } | |
120 | ||
9562f6c6 | 121 | (void) sendto(s, msg, size, flags, sns, sizeof (*sns)); |
53eed0ef KS |
122 | } |
123 | ||
124 | /* | |
4a10c08d KS |
125 | * Return 1 if we want this route. |
126 | * We use this to disallow route net G entries for one for multiple | |
127 | * point to point links. | |
53eed0ef | 128 | */ |
48681466 KS |
129 | xnnet_checkhost(sns) |
130 | struct sockaddr_ns *sns; | |
53eed0ef | 131 | { |
4a10c08d KS |
132 | register struct interface *ifp = if_ifwithnet(sns); |
133 | /* | |
134 | * We want this route if there is no more than one | |
135 | * point to point interface with this network. | |
136 | */ | |
137 | if (ifp == 0 || (ifp->int_flags & IFF_POINTOPOINT)==0) return (1); | |
138 | return (ifp->int_sq.n == ifp->int_sq.p); | |
53eed0ef KS |
139 | } |
140 | ||
141 | /* | |
142 | * Return 1 if the address is | |
143 | * for a host, 0 for a network. | |
144 | */ | |
48681466 KS |
145 | xnnet_ishost(sns) |
146 | struct sockaddr_ns *sns; | |
53eed0ef | 147 | { |
48681466 | 148 | register u_short *s = sns->sns_addr.x_host.s_host; |
53eed0ef | 149 | |
48681466 KS |
150 | if ((s[0]==0xffff) && (s[1]==0xffff) && (s[2]==0xffff)) |
151 | return (0); | |
152 | else | |
153 | return (1); | |
53eed0ef KS |
154 | } |
155 | ||
48681466 KS |
156 | xnnet_canon(sns) |
157 | struct sockaddr_ns *sns; | |
53eed0ef KS |
158 | { |
159 | ||
48681466 | 160 | sns->sns_addr.x_port = 0; |
53eed0ef KS |
161 | } |
162 | ||
163 | /*ARGSUSED*/ | |
164 | null_hash(addr, hp) | |
165 | struct sockaddr *addr; | |
166 | struct afhash *hp; | |
167 | { | |
168 | ||
169 | hp->afh_nethash = hp->afh_hosthash = 0; | |
170 | } | |
171 | ||
172 | /*ARGSUSED*/ | |
173 | null_netmatch(a1, a2) | |
174 | struct sockaddr *a1, *a2; | |
175 | { | |
176 | ||
177 | return (0); | |
178 | } | |
179 | ||
180 | /*ARGSUSED*/ | |
181 | null_output(s, f, a1, n) | |
182 | int s, f; | |
183 | struct sockaddr *a1; | |
184 | int n; | |
185 | { | |
186 | ||
187 | ; | |
188 | } | |
189 | ||
190 | /*ARGSUSED*/ | |
191 | null_portmatch(a1) | |
192 | struct sockaddr *a1; | |
193 | { | |
194 | ||
195 | return (0); | |
196 | } | |
197 | ||
198 | /*ARGSUSED*/ | |
199 | null_portcheck(a1) | |
200 | struct sockaddr *a1; | |
201 | { | |
202 | ||
203 | return (0); | |
204 | } | |
205 | ||
206 | /*ARGSUSED*/ | |
207 | null_ishost(a1) | |
208 | struct sockaddr *a1; | |
209 | { | |
210 | ||
211 | return (0); | |
212 | } | |
213 | ||
214 | /*ARGSUSED*/ | |
215 | null_checkhost(a1) | |
216 | struct sockaddr *a1; | |
217 | { | |
218 | ||
219 | return (0); | |
220 | } | |
221 | ||
222 | /*ARGSUSED*/ | |
223 | null_canon(a1) | |
224 | struct sockaddr *a1; | |
225 | { | |
226 | ||
227 | ; | |
228 | } |