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