Deleted Added
full compact
aarp.c (15885) aarp.c (17254)
1/*
2 * Copyright (c) 1990,1991 Regents of The University of Michigan.
3 * All Rights Reserved.
4 */
5
6#include <sys/types.h>
7#include <sys/cdefs.h>
8#include <sys/socket.h>
9#include <sys/syslog.h>
10#include <sys/param.h>
1/*
2 * Copyright (c) 1990,1991 Regents of The University of Michigan.
3 * All Rights Reserved.
4 */
5
6#include <sys/types.h>
7#include <sys/cdefs.h>
8#include <sys/socket.h>
9#include <sys/syslog.h>
10#include <sys/param.h>
11#if defined( __FreeBSD__ )
12#include <machine/endian.h>
13#include <sys/systm.h>
14#include <sys/proc.h>
11#include <machine/endian.h>
12#include <sys/systm.h>
13#include <sys/proc.h>
15#endif
16#include <sys/mbuf.h>
17#include <sys/time.h>
14#include <sys/mbuf.h>
15#include <sys/time.h>
18#ifndef _IBMR2
19#include <sys/kernel.h>
16#include <sys/kernel.h>
20#endif _IBMR2
21#include <net/if.h>
22#include <net/route.h>
17#include <net/if.h>
18#include <net/route.h>
23#if !defined( __FreeBSD__ )
24#include <net/af.h>
25#endif
26#include <netinet/in.h>
27#undef s_net
28#include <netinet/if_ether.h>
19#include <netinet/in.h>
20#undef s_net
21#include <netinet/if_ether.h>
29#ifdef _IBMR2
30#include <netinet/in_netarp.h>
31#include <net/spl.h>
32#include <sys/errno.h>
33#include <sys/err_rec.h>
34#endif _IBMR2
35
36#include <netatalk/at.h>
37#include <netatalk/at_var.h>
38#include <netatalk/aarp.h>
39#include <netatalk/ddp_var.h>
40#include <netatalk/phase2.h>
41#include <netatalk/at_extern.h>
42
43static void aarptfree( struct aarptab *aat);
44static void at_aarpinput( struct arpcom *ac, struct mbuf *m);
45
22
23#include <netatalk/at.h>
24#include <netatalk/at_var.h>
25#include <netatalk/aarp.h>
26#include <netatalk/ddp_var.h>
27#include <netatalk/phase2.h>
28#include <netatalk/at_extern.h>
29
30static void aarptfree( struct aarptab *aat);
31static void at_aarpinput( struct arpcom *ac, struct mbuf *m);
32
46#ifdef GATEWAY
47#define AARPTAB_BSIZ 16
48#define AARPTAB_NB 37
49#else
50#define AARPTAB_BSIZ 9
51#define AARPTAB_NB 19
33#define AARPTAB_BSIZ 9
34#define AARPTAB_NB 19
52#endif GATEWAY
53#define AARPTAB_SIZE (AARPTAB_BSIZ * AARPTAB_NB)
54struct aarptab aarptab[AARPTAB_SIZE];
55int aarptab_size = AARPTAB_SIZE;
56
57#define AARPTAB_HASH(a) \
58 ((((a).s_net << 8 ) + (a).s_node ) % AARPTAB_NB )
59
60#define AARPTAB_LOOK(aat,addr) { \

--- 6 unchanged lines hidden (view full) ---

67 if ( n >= AARPTAB_BSIZ ) \
68 aat = 0; \
69}
70
71#define AARPT_AGE (60 * 1)
72#define AARPT_KILLC 20
73#define AARPT_KILLI 3
74
35#define AARPTAB_SIZE (AARPTAB_BSIZ * AARPTAB_NB)
36struct aarptab aarptab[AARPTAB_SIZE];
37int aarptab_size = AARPTAB_SIZE;
38
39#define AARPTAB_HASH(a) \
40 ((((a).s_net << 8 ) + (a).s_node ) % AARPTAB_NB )
41
42#define AARPTAB_LOOK(aat,addr) { \

--- 6 unchanged lines hidden (view full) ---

49 if ( n >= AARPTAB_BSIZ ) \
50 aat = 0; \
51}
52
53#define AARPT_AGE (60 * 1)
54#define AARPT_KILLC 20
55#define AARPT_KILLI 3
56
75#ifdef sun
76extern struct ether_addr etherbroadcastaddr;
77#else sun
78# if !defined( __FreeBSD__ )
79extern u_char etherbroadcastaddr[6];
80# endif __FreeBSD__
57# if !defined( __FreeBSD__ )
58extern u_char etherbroadcastaddr[6];
59# endif __FreeBSD__
81#endif sun
82
83u_char atmulticastaddr[ 6 ] = {
84 0x09, 0x00, 0x07, 0xff, 0xff, 0xff,
85};
86
87u_char at_org_code[ 3 ] = {
88 0x08, 0x00, 0x07,
89};

--- 21 unchanged lines hidden (view full) ---

111 }
112}
113
114struct ifaddr *
115at_ifawithnet( sat, ifa )
116 struct sockaddr_at *sat;
117 struct ifaddr *ifa;
118{
60
61u_char atmulticastaddr[ 6 ] = {
62 0x09, 0x00, 0x07, 0xff, 0xff, 0xff,
63};
64
65u_char at_org_code[ 3 ] = {
66 0x08, 0x00, 0x07,
67};

--- 21 unchanged lines hidden (view full) ---

89 }
90}
91
92struct ifaddr *
93at_ifawithnet( sat, ifa )
94 struct sockaddr_at *sat;
95 struct ifaddr *ifa;
96{
119 struct at_ifaddr *aa;
120
121 for (; ifa; ifa = ifa->ifa_next ) {
97
98 for (; ifa; ifa = ifa->ifa_next ) {
122#ifdef BSD4_4
123 if ( ifa->ifa_addr->sa_family != AF_APPLETALK ) {
124 continue;
125 }
126 if ( satosat( ifa->ifa_addr )->sat_addr.s_net ==
127 sat->sat_addr.s_net ) {
128 break;
129 }
99 if ( ifa->ifa_addr->sa_family != AF_APPLETALK ) {
100 continue;
101 }
102 if ( satosat( ifa->ifa_addr )->sat_addr.s_net ==
103 sat->sat_addr.s_net ) {
104 break;
105 }
130#else BSD4_4
131 if ( ifa->ifa_addr.sa_family != AF_APPLETALK ) {
132 continue;
133 }
134 aa = (struct at_ifaddr *)ifa;
135 if ( ntohs( sat->sat_addr.s_net ) >= ntohs( aa->aa_firstnet ) &&
136 ntohs( sat->sat_addr.s_net ) <= ntohs( aa->aa_lastnet )) {
137 break;
138 }
139#endif BSD4_4
140 }
141 return( ifa );
142}
143
144static void
145aarpwhohas( struct arpcom *ac, struct sockaddr_at *sat )
146{
147 struct mbuf *m;
148 struct ether_header *eh;
149 struct ether_aarp *ea;
150 struct at_ifaddr *aa;
151 struct llc *llc;
152 struct sockaddr sa;
153
106 }
107 return( ifa );
108}
109
110static void
111aarpwhohas( struct arpcom *ac, struct sockaddr_at *sat )
112{
113 struct mbuf *m;
114 struct ether_header *eh;
115 struct ether_aarp *ea;
116 struct at_ifaddr *aa;
117 struct llc *llc;
118 struct sockaddr sa;
119
154#ifdef BSD4_4
155 if (( m = m_gethdr( M_DONTWAIT, MT_DATA )) == NULL ) {
156 return;
157 }
158 m->m_len = sizeof( *ea );
159 m->m_pkthdr.len = sizeof( *ea );
160 MH_ALIGN( m, sizeof( *ea ));
120 if (( m = m_gethdr( M_DONTWAIT, MT_DATA )) == NULL ) {
121 return;
122 }
123 m->m_len = sizeof( *ea );
124 m->m_pkthdr.len = sizeof( *ea );
125 MH_ALIGN( m, sizeof( *ea ));
161#else BSD4_4
162 if (( m = m_get( M_DONTWAIT, MT_DATA )) == NULL ) {
163 return;
164 }
165 m->m_len = sizeof( *ea );
166 m->m_off = MMAXOFF - sizeof( *ea );
167#endif BSD4_4
168
169 ea = mtod( m, struct ether_aarp *);
170 bzero((caddr_t)ea, sizeof( *ea ));
171
172 ea->aarp_hrd = htons( AARPHRD_ETHER );
173 ea->aarp_pro = htons( ETHERTYPE_AT );
174 ea->aarp_hln = sizeof( ea->aarp_sha );
175 ea->aarp_pln = sizeof( ea->aarp_spu );
176 ea->aarp_op = htons( AARPOP_REQUEST );
126
127 ea = mtod( m, struct ether_aarp *);
128 bzero((caddr_t)ea, sizeof( *ea ));
129
130 ea->aarp_hrd = htons( AARPHRD_ETHER );
131 ea->aarp_pro = htons( ETHERTYPE_AT );
132 ea->aarp_hln = sizeof( ea->aarp_sha );
133 ea->aarp_pln = sizeof( ea->aarp_spu );
134 ea->aarp_op = htons( AARPOP_REQUEST );
177#ifdef sun
178 bcopy((caddr_t)&ac->ac_enaddr, (caddr_t)ea->aarp_sha,
179 sizeof( ea->aarp_sha ));
180#else sun
181 bcopy((caddr_t)ac->ac_enaddr, (caddr_t)ea->aarp_sha,
182 sizeof( ea->aarp_sha ));
135 bcopy((caddr_t)ac->ac_enaddr, (caddr_t)ea->aarp_sha,
136 sizeof( ea->aarp_sha ));
183#endif sun
184
185 /*
186 * We need to check whether the output ethernet type should
187 * be phase 1 or 2. We have the interface that we'll be sending
188 * the aarp out. We need to find an AppleTalk network on that
189 * interface with the same address as we're looking for. If the
190 * net is phase 2, generate an 802.2 and SNAP header.
191 */
192 if (( aa = (struct at_ifaddr *)at_ifawithnet( sat, ac->ac_if.if_addrlist ))
193 == NULL ) {
194 m_freem( m );
195 return;
196 }
197
198 eh = (struct ether_header *)sa.sa_data;
199
200 if ( aa->aa_flags & AFA_PHASE2 ) {
137
138 /*
139 * We need to check whether the output ethernet type should
140 * be phase 1 or 2. We have the interface that we'll be sending
141 * the aarp out. We need to find an AppleTalk network on that
142 * interface with the same address as we're looking for. If the
143 * net is phase 2, generate an 802.2 and SNAP header.
144 */
145 if (( aa = (struct at_ifaddr *)at_ifawithnet( sat, ac->ac_if.if_addrlist ))
146 == NULL ) {
147 m_freem( m );
148 return;
149 }
150
151 eh = (struct ether_header *)sa.sa_data;
152
153 if ( aa->aa_flags & AFA_PHASE2 ) {
201#ifdef sun
202 bcopy((caddr_t)atmulticastaddr, (caddr_t)&eh->ether_dhost,
203 sizeof( eh->ether_dhost ));
204#else sun
205 bcopy((caddr_t)atmulticastaddr, (caddr_t)eh->ether_dhost,
206 sizeof( eh->ether_dhost ));
154 bcopy((caddr_t)atmulticastaddr, (caddr_t)eh->ether_dhost,
155 sizeof( eh->ether_dhost ));
207#endif sun
208#if defined(sun) && defined(i386)
209 eh->ether_type = htons(sizeof(struct llc) + sizeof(struct ether_aarp));
156 eh->ether_type = htons(sizeof(struct llc) + sizeof(struct ether_aarp));
210#else
211 eh->ether_type = sizeof(struct llc) + sizeof(struct ether_aarp);
212#endif
213#ifdef BSD4_4
214 M_PREPEND( m, sizeof( struct llc ), M_WAIT );
157 M_PREPEND( m, sizeof( struct llc ), M_WAIT );
215#else BSD4_4
216 m->m_len += sizeof( struct llc );
217 m->m_off -= sizeof( struct llc );
218#endif BSD4_4
219 llc = mtod( m, struct llc *);
220 llc->llc_dsap = llc->llc_ssap = LLC_SNAP_LSAP;
221 llc->llc_control = LLC_UI;
222 bcopy( aarp_org_code, llc->llc_org_code, sizeof( aarp_org_code ));
223 llc->llc_ether_type = htons( ETHERTYPE_AARP );
224
225 bcopy( &AA_SAT( aa )->sat_addr.s_net, ea->aarp_spnet,
226 sizeof( ea->aarp_spnet ));
227 bcopy( &sat->sat_addr.s_net, ea->aarp_tpnet,
228 sizeof( ea->aarp_tpnet ));
229 ea->aarp_spnode = AA_SAT( aa )->sat_addr.s_node;
230 ea->aarp_tpnode = sat->sat_addr.s_node;
231 } else {
158 llc = mtod( m, struct llc *);
159 llc->llc_dsap = llc->llc_ssap = LLC_SNAP_LSAP;
160 llc->llc_control = LLC_UI;
161 bcopy( aarp_org_code, llc->llc_org_code, sizeof( aarp_org_code ));
162 llc->llc_ether_type = htons( ETHERTYPE_AARP );
163
164 bcopy( &AA_SAT( aa )->sat_addr.s_net, ea->aarp_spnet,
165 sizeof( ea->aarp_spnet ));
166 bcopy( &sat->sat_addr.s_net, ea->aarp_tpnet,
167 sizeof( ea->aarp_tpnet ));
168 ea->aarp_spnode = AA_SAT( aa )->sat_addr.s_node;
169 ea->aarp_tpnode = sat->sat_addr.s_node;
170 } else {
232#ifdef sun
233 bcopy((caddr_t)&etherbroadcastaddr, (caddr_t)&eh->ether_dhost,
234 sizeof( eh->ether_dhost ));
235#else sun
236 bcopy((caddr_t)etherbroadcastaddr, (caddr_t)eh->ether_dhost,
237 sizeof( eh->ether_dhost ));
171 bcopy((caddr_t)etherbroadcastaddr, (caddr_t)eh->ether_dhost,
172 sizeof( eh->ether_dhost ));
238#endif sun
239#if defined(sun) && defined(i386)
240 eh->ether_type = htons( ETHERTYPE_AARP );
173 eh->ether_type = htons( ETHERTYPE_AARP );
241#else
242 eh->ether_type = ETHERTYPE_AARP;
243#endif
244
245 ea->aarp_spa = AA_SAT( aa )->sat_addr.s_node;
246 ea->aarp_tpa = sat->sat_addr.s_node;
247 }
248
249#ifdef NETATALKDEBUG
250 printf("aarp: sending request for %u.%u\n",
251 ntohs(AA_SAT( aa )->sat_addr.s_net),
252 AA_SAT( aa )->sat_addr.s_node);
253#endif NETATALKDEBUG
254
174
175 ea->aarp_spa = AA_SAT( aa )->sat_addr.s_node;
176 ea->aarp_tpa = sat->sat_addr.s_node;
177 }
178
179#ifdef NETATALKDEBUG
180 printf("aarp: sending request for %u.%u\n",
181 ntohs(AA_SAT( aa )->sat_addr.s_net),
182 AA_SAT( aa )->sat_addr.s_node);
183#endif NETATALKDEBUG
184
255#ifdef BSD4_4
256 sa.sa_len = sizeof( struct sockaddr );
185 sa.sa_len = sizeof( struct sockaddr );
257#endif BSD4_4
258 sa.sa_family = AF_UNSPEC;
186 sa.sa_family = AF_UNSPEC;
259 (*ac->ac_if.if_output)(&ac->ac_if, m, &sa
260#if defined( __FreeBSD__ )
261 , NULL /* XXX should be routing information */
262#endif __FreeBSD__
263 );
187 (*ac->ac_if.if_output)(&ac->ac_if,
188 m, &sa, NULL); /* XXX NULL should be routing information */
264}
265
266int
267aarpresolve( ac, m, destsat, desten )
268 struct arpcom *ac;
269 struct mbuf *m;
270 struct sockaddr_at *destsat;
189}
190
191int
192aarpresolve( ac, m, destsat, desten )
193 struct arpcom *ac;
194 struct mbuf *m;
195 struct sockaddr_at *destsat;
271#ifdef sun
272 struct ether_addr *desten;
273#else sun
274 u_char *desten;
196 u_char *desten;
275#endif sun
276{
277 struct at_ifaddr *aa;
197{
198 struct at_ifaddr *aa;
278 struct ifaddr ifa;
279 struct aarptab *aat;
280 int s;
281
282 if ( at_broadcast( destsat )) {
283 if (( aa = (struct at_ifaddr *)at_ifawithnet( destsat,
284 ((struct ifnet *)ac)->if_addrlist )) == NULL ) {
285 m_freem( m );
286 return( 0 );
287 }
288 if ( aa->aa_flags & AFA_PHASE2 ) {
289 bcopy( (caddr_t)atmulticastaddr, (caddr_t)desten,
290 sizeof( atmulticastaddr ));
291 } else {
199 struct aarptab *aat;
200 int s;
201
202 if ( at_broadcast( destsat )) {
203 if (( aa = (struct at_ifaddr *)at_ifawithnet( destsat,
204 ((struct ifnet *)ac)->if_addrlist )) == NULL ) {
205 m_freem( m );
206 return( 0 );
207 }
208 if ( aa->aa_flags & AFA_PHASE2 ) {
209 bcopy( (caddr_t)atmulticastaddr, (caddr_t)desten,
210 sizeof( atmulticastaddr ));
211 } else {
292#ifdef sun
293 bcopy( (caddr_t)&etherbroadcastaddr, (caddr_t)desten,
294 sizeof( etherbroadcastaddr ));
295#else sun
296 bcopy( (caddr_t)etherbroadcastaddr, (caddr_t)desten,
297 sizeof( etherbroadcastaddr ));
212 bcopy( (caddr_t)etherbroadcastaddr, (caddr_t)desten,
213 sizeof( etherbroadcastaddr ));
298#endif sun
299 }
300 return( 1 );
301 }
302
303 s = splimp();
304 AARPTAB_LOOK( aat, destsat->sat_addr );
305 if ( aat == 0 ) { /* No entry */
306 aat = aarptnew( &destsat->sat_addr );

--- 28 unchanged lines hidden (view full) ---

335 struct arpcom *ac;
336 struct mbuf *m;
337{
338 struct arphdr *ar;
339
340 if ( ac->ac_if.if_flags & IFF_NOARP )
341 goto out;
342
214 }
215 return( 1 );
216 }
217
218 s = splimp();
219 AARPTAB_LOOK( aat, destsat->sat_addr );
220 if ( aat == 0 ) { /* No entry */
221 aat = aarptnew( &destsat->sat_addr );

--- 28 unchanged lines hidden (view full) ---

250 struct arpcom *ac;
251 struct mbuf *m;
252{
253 struct arphdr *ar;
254
255 if ( ac->ac_if.if_flags & IFF_NOARP )
256 goto out;
257
343#ifndef BSD4_4
344 IF_ADJ( m );
345#endif BSD4_4
346
347 if ( m->m_len < sizeof( struct arphdr )) {
348 goto out;
349 }
350
351 ar = mtod( m, struct arphdr *);
352 if ( ntohs( ar->ar_hrd ) != AARPHRD_ETHER ) {
353 goto out;
354 }

--- 14 unchanged lines hidden (view full) ---

369
370out:
371 m_freem( m );
372}
373
374static void
375at_aarpinput( struct arpcom *ac, struct mbuf *m)
376{
258 if ( m->m_len < sizeof( struct arphdr )) {
259 goto out;
260 }
261
262 ar = mtod( m, struct arphdr *);
263 if ( ntohs( ar->ar_hrd ) != AARPHRD_ETHER ) {
264 goto out;
265 }

--- 14 unchanged lines hidden (view full) ---

280
281out:
282 m_freem( m );
283}
284
285static void
286at_aarpinput( struct arpcom *ac, struct mbuf *m)
287{
377 struct mbuf *m0;
378 struct ether_aarp *ea;
379 struct at_ifaddr *aa;
380 struct aarptab *aat;
381 struct ether_header *eh;
382 struct llc *llc;
383 struct sockaddr_at sat;
384 struct sockaddr sa;
385 struct at_addr spa, tpa, ma;
288 struct ether_aarp *ea;
289 struct at_ifaddr *aa;
290 struct aarptab *aat;
291 struct ether_header *eh;
292 struct llc *llc;
293 struct sockaddr_at sat;
294 struct sockaddr sa;
295 struct at_addr spa, tpa, ma;
386 int op, s;
296 int op;
387 u_short net;
388
389 ea = mtod( m, struct ether_aarp *);
390
391 /* Check to see if from my hardware address */
297 u_short net;
298
299 ea = mtod( m, struct ether_aarp *);
300
301 /* Check to see if from my hardware address */
392#ifdef sun
393 if ( !bcmp(( caddr_t )ea->aarp_sha, ( caddr_t )&ac->ac_enaddr,
394 sizeof( ac->ac_enaddr ))) {
395 m_freem( m );
396 return;
397 }
398#else sun
399 if ( !bcmp(( caddr_t )ea->aarp_sha, ( caddr_t )ac->ac_enaddr,
400 sizeof( ac->ac_enaddr ))) {
401 m_freem( m );
402 return;
403 }
302 if ( !bcmp(( caddr_t )ea->aarp_sha, ( caddr_t )ac->ac_enaddr,
303 sizeof( ac->ac_enaddr ))) {
304 m_freem( m );
305 return;
306 }
404#endif sun
405
406 op = ntohs( ea->aarp_op );
407 bcopy( ea->aarp_tpnet, &net, sizeof( net ));
408
409 if ( net != 0 ) { /* should be ATADDR_ANYNET? */
307
308 op = ntohs( ea->aarp_op );
309 bcopy( ea->aarp_tpnet, &net, sizeof( net ));
310
311 if ( net != 0 ) { /* should be ATADDR_ANYNET? */
410#ifdef BSD4_4
411 sat.sat_len = sizeof(struct sockaddr_at);
312 sat.sat_len = sizeof(struct sockaddr_at);
412#endif BSD4_4
413 sat.sat_family = AF_APPLETALK;
414 sat.sat_addr.s_net = net;
415 if (( aa = (struct at_ifaddr *)at_ifawithnet( &sat,
416 ac->ac_if.if_addrlist )) == NULL ) {
417 m_freem( m );
418 return;
419 }
420 bcopy( ea->aarp_spnet, &spa.s_net, sizeof( spa.s_net ));

--- 37 unchanged lines hidden (view full) ---

458 m_freem( m );
459 return;
460 } else if ( op != AARPOP_PROBE ) {
461 /*
462 * This is not a probe, and we're not probing. This means
463 * that someone's saying they have the same source address
464 * as the one we're using. Get upset...
465 */
313 sat.sat_family = AF_APPLETALK;
314 sat.sat_addr.s_net = net;
315 if (( aa = (struct at_ifaddr *)at_ifawithnet( &sat,
316 ac->ac_if.if_addrlist )) == NULL ) {
317 m_freem( m );
318 return;
319 }
320 bcopy( ea->aarp_spnet, &spa.s_net, sizeof( spa.s_net ));

--- 37 unchanged lines hidden (view full) ---

358 m_freem( m );
359 return;
360 } else if ( op != AARPOP_PROBE ) {
361 /*
362 * This is not a probe, and we're not probing. This means
363 * that someone's saying they have the same source address
364 * as the one we're using. Get upset...
365 */
466#ifndef _IBMR2
467#ifdef ultrix
468 mprintf( LOG_ERR,
469#else ultrix
470 log( LOG_ERR,
366 log( LOG_ERR,
471#endif ultrix
472 "aarp: duplicate AT address!! %x:%x:%x:%x:%x:%x\n",
473 ea->aarp_sha[ 0 ], ea->aarp_sha[ 1 ], ea->aarp_sha[ 2 ],
474 ea->aarp_sha[ 3 ], ea->aarp_sha[ 4 ], ea->aarp_sha[ 5 ]);
367 "aarp: duplicate AT address!! %x:%x:%x:%x:%x:%x\n",
368 ea->aarp_sha[ 0 ], ea->aarp_sha[ 1 ], ea->aarp_sha[ 2 ],
369 ea->aarp_sha[ 3 ], ea->aarp_sha[ 4 ], ea->aarp_sha[ 5 ]);
475#endif _IBMR2
476 m_freem( m );
477 return;
478 }
479 }
480
481 AARPTAB_LOOK( aat, spa );
482 if ( aat ) {
483 if ( op == AARPOP_PROBE ) {

--- 6 unchanged lines hidden (view full) ---

490 m_freem( m );
491 return;
492 }
493
494 bcopy(( caddr_t )ea->aarp_sha, ( caddr_t )aat->aat_enaddr,
495 sizeof( ea->aarp_sha ));
496 aat->aat_flags |= ATF_COM;
497 if ( aat->aat_hold ) {
370 m_freem( m );
371 return;
372 }
373 }
374
375 AARPTAB_LOOK( aat, spa );
376 if ( aat ) {
377 if ( op == AARPOP_PROBE ) {

--- 6 unchanged lines hidden (view full) ---

384 m_freem( m );
385 return;
386 }
387
388 bcopy(( caddr_t )ea->aarp_sha, ( caddr_t )aat->aat_enaddr,
389 sizeof( ea->aarp_sha ));
390 aat->aat_flags |= ATF_COM;
391 if ( aat->aat_hold ) {
498#ifdef _IBMR2
499 /*
500 * Like in ddp_output(), we can't rely on the if_output
501 * routine to resolve AF_APPLETALK addresses, on the rs6k.
502 * So, we fill the destination ethernet address here.
503 *
504 * This should really be replaced with something like
505 * rsif_output(). XXX Will have to be for phase 2.
506 */
507 /* XXX maybe fill in the rest of the frame header */
508 sat.sat_family = AF_UNSPEC;
509 bcopy( aat->aat_enaddr, (*(struct sockaddr *)&sat).sa_data,
510 sizeof( aat->aat_enaddr ));
511#else _IBMR2
512#ifdef BSD4_4
513 sat.sat_len = sizeof(struct sockaddr_at);
392 sat.sat_len = sizeof(struct sockaddr_at);
514#endif BSD4_4
515 sat.sat_family = AF_APPLETALK;
516 sat.sat_addr = spa;
393 sat.sat_family = AF_APPLETALK;
394 sat.sat_addr = spa;
517#endif _IBMR2
518 (*ac->ac_if.if_output)( &ac->ac_if, aat->aat_hold,
395 (*ac->ac_if.if_output)( &ac->ac_if, aat->aat_hold,
519 (struct sockaddr *)&sat
520#if defined( __FreeBSD__ )
521 , NULL /* XXX */
522#endif __FreeBSD__
523 );
396 (struct sockaddr *)&sat, NULL); /* XXX */
524 aat->aat_hold = 0;
525 }
526 }
527
528 if ( aat == 0 && tpa.s_net == ma.s_net && tpa.s_node == ma.s_node
529 && op != AARPOP_PROBE ) {
530 if ( aat = aarptnew( &spa )) {
531 bcopy(( caddr_t )ea->aarp_sha, ( caddr_t )aat->aat_enaddr,

--- 9 unchanged lines hidden (view full) ---

541 if ( tpa.s_net != ma.s_net || tpa.s_node != ma.s_node ||
542 op == AARPOP_RESPONSE || ( aa->aa_flags & AFA_PROBING )) {
543 m_freem( m );
544 return;
545 }
546
547 bcopy(( caddr_t )ea->aarp_sha, ( caddr_t )ea->aarp_tha,
548 sizeof( ea->aarp_sha ));
397 aat->aat_hold = 0;
398 }
399 }
400
401 if ( aat == 0 && tpa.s_net == ma.s_net && tpa.s_node == ma.s_node
402 && op != AARPOP_PROBE ) {
403 if ( aat = aarptnew( &spa )) {
404 bcopy(( caddr_t )ea->aarp_sha, ( caddr_t )aat->aat_enaddr,

--- 9 unchanged lines hidden (view full) ---

414 if ( tpa.s_net != ma.s_net || tpa.s_node != ma.s_node ||
415 op == AARPOP_RESPONSE || ( aa->aa_flags & AFA_PROBING )) {
416 m_freem( m );
417 return;
418 }
419
420 bcopy(( caddr_t )ea->aarp_sha, ( caddr_t )ea->aarp_tha,
421 sizeof( ea->aarp_sha ));
549#ifdef sun
550 bcopy(( caddr_t )&ac->ac_enaddr, ( caddr_t )ea->aarp_sha,
551 sizeof( ea->aarp_sha ));
552#else sun
553 bcopy(( caddr_t )ac->ac_enaddr, ( caddr_t )ea->aarp_sha,
554 sizeof( ea->aarp_sha ));
422 bcopy(( caddr_t )ac->ac_enaddr, ( caddr_t )ea->aarp_sha,
423 sizeof( ea->aarp_sha ));
555#endif sun
556
557 /* XXX */
558 eh = (struct ether_header *)sa.sa_data;
424
425 /* XXX */
426 eh = (struct ether_header *)sa.sa_data;
559#ifdef sun
560 bcopy(( caddr_t )ea->aarp_tha, ( caddr_t )&eh->ether_dhost,
561 sizeof( eh->ether_dhost ));
562#else sun
563 bcopy(( caddr_t )ea->aarp_tha, ( caddr_t )eh->ether_dhost,
564 sizeof( eh->ether_dhost ));
427 bcopy(( caddr_t )ea->aarp_tha, ( caddr_t )eh->ether_dhost,
428 sizeof( eh->ether_dhost ));
565#endif sun
566
567 if ( aa->aa_flags & AFA_PHASE2 ) {
429
430 if ( aa->aa_flags & AFA_PHASE2 ) {
568#if defined(sun) && defined(i386)
569 eh->ether_type = htons( sizeof( struct llc ) +
570 sizeof( struct ether_aarp ));
431 eh->ether_type = htons( sizeof( struct llc ) +
432 sizeof( struct ether_aarp ));
571#else
572 eh->ether_type = sizeof( struct llc ) + sizeof( struct ether_aarp );
573#endif
574#ifdef BSD4_4
575 M_PREPEND( m, sizeof( struct llc ), M_DONTWAIT );
576 if ( m == NULL ) {
577 return;
578 }
433 M_PREPEND( m, sizeof( struct llc ), M_DONTWAIT );
434 if ( m == NULL ) {
435 return;
436 }
579#else BSD4_4
580 MGET( m0, M_DONTWAIT, MT_HEADER );
581 if ( m0 == NULL ) {
582 m_freem( m );
583 return;
584 }
585 m0->m_next = m;
586 m = m0;
587 m->m_off = MMAXOFF - sizeof( struct llc );
588 m->m_len = sizeof ( struct llc );
589#endif BSD4_4
590 llc = mtod( m, struct llc *);
591 llc->llc_dsap = llc->llc_ssap = LLC_SNAP_LSAP;
592 llc->llc_control = LLC_UI;
593 bcopy( aarp_org_code, llc->llc_org_code, sizeof( aarp_org_code ));
594 llc->llc_ether_type = htons( ETHERTYPE_AARP );
595
596 bcopy( ea->aarp_spnet, ea->aarp_tpnet, sizeof( ea->aarp_tpnet ));
597 bcopy( &ma.s_net, ea->aarp_spnet, sizeof( ea->aarp_spnet ));
598 } else {
437 llc = mtod( m, struct llc *);
438 llc->llc_dsap = llc->llc_ssap = LLC_SNAP_LSAP;
439 llc->llc_control = LLC_UI;
440 bcopy( aarp_org_code, llc->llc_org_code, sizeof( aarp_org_code ));
441 llc->llc_ether_type = htons( ETHERTYPE_AARP );
442
443 bcopy( ea->aarp_spnet, ea->aarp_tpnet, sizeof( ea->aarp_tpnet ));
444 bcopy( &ma.s_net, ea->aarp_spnet, sizeof( ea->aarp_spnet ));
445 } else {
599#if defined(sun) && defined(i386)
600 eh->ether_type = htons( ETHERTYPE_AARP );
446 eh->ether_type = htons( ETHERTYPE_AARP );
601#else
602 eh->ether_type = ETHERTYPE_AARP;
603#endif
604 }
605
606 ea->aarp_tpnode = ea->aarp_spnode;
607 ea->aarp_spnode = ma.s_node;
608 ea->aarp_op = htons( AARPOP_RESPONSE );
609
447 }
448
449 ea->aarp_tpnode = ea->aarp_spnode;
450 ea->aarp_spnode = ma.s_node;
451 ea->aarp_op = htons( AARPOP_RESPONSE );
452
610#ifdef BSD4_4
611 sa.sa_len = sizeof( struct sockaddr );
453 sa.sa_len = sizeof( struct sockaddr );
612#endif BSD4_4
613 sa.sa_family = AF_UNSPEC;
454 sa.sa_family = AF_UNSPEC;
614 (*ac->ac_if.if_output)( &ac->ac_if, m, &sa
615#if defined( __FreeBSD__ )
616 , NULL /* XXX */
617#endif
618 );
455 (*ac->ac_if.if_output)( &ac->ac_if, m, &sa, NULL); /* XXX */
619 return;
620}
621
622static void
623aarptfree( struct aarptab *aat)
624{
625
626 if ( aat->aat_hold )

--- 71 unchanged lines hidden (view full) ---

698 if ( aa->aa_probcnt <= 0 ) {
699 aa->aa_flags &= ~AFA_PROBING;
700 wakeup( aa );
701 return;
702 } else {
703 timeout( (timeout_func_t)aarpprobe, (caddr_t)ac, hz / 5 );
704 }
705
456 return;
457}
458
459static void
460aarptfree( struct aarptab *aat)
461{
462
463 if ( aat->aat_hold )

--- 71 unchanged lines hidden (view full) ---

535 if ( aa->aa_probcnt <= 0 ) {
536 aa->aa_flags &= ~AFA_PROBING;
537 wakeup( aa );
538 return;
539 } else {
540 timeout( (timeout_func_t)aarpprobe, (caddr_t)ac, hz / 5 );
541 }
542
706#ifdef BSD4_4
707 if (( m = m_gethdr( M_DONTWAIT, MT_DATA )) == NULL ) {
708 return;
709 }
710 m->m_len = sizeof( *ea );
711 m->m_pkthdr.len = sizeof( *ea );
712 MH_ALIGN( m, sizeof( *ea ));
543 if (( m = m_gethdr( M_DONTWAIT, MT_DATA )) == NULL ) {
544 return;
545 }
546 m->m_len = sizeof( *ea );
547 m->m_pkthdr.len = sizeof( *ea );
548 MH_ALIGN( m, sizeof( *ea ));
713#else BSD4_4
714 if (( m = m_get( M_DONTWAIT, MT_DATA )) == NULL ) {
715 return;
716 }
717 m->m_len = sizeof( *ea );
718 m->m_off = MMAXOFF - sizeof( *ea );
719#endif BSD4_4
720
721 ea = mtod( m, struct ether_aarp *);
722 bzero((caddr_t)ea, sizeof( *ea ));
723
724 ea->aarp_hrd = htons( AARPHRD_ETHER );
725 ea->aarp_pro = htons( ETHERTYPE_AT );
726 ea->aarp_hln = sizeof( ea->aarp_sha );
727 ea->aarp_pln = sizeof( ea->aarp_spu );
728 ea->aarp_op = htons( AARPOP_PROBE );
549
550 ea = mtod( m, struct ether_aarp *);
551 bzero((caddr_t)ea, sizeof( *ea ));
552
553 ea->aarp_hrd = htons( AARPHRD_ETHER );
554 ea->aarp_pro = htons( ETHERTYPE_AT );
555 ea->aarp_hln = sizeof( ea->aarp_sha );
556 ea->aarp_pln = sizeof( ea->aarp_spu );
557 ea->aarp_op = htons( AARPOP_PROBE );
729#ifdef sun
730 bcopy((caddr_t)&ac->ac_enaddr, (caddr_t)ea->aarp_sha,
731 sizeof( ea->aarp_sha ));
732#else sun
733 bcopy((caddr_t)ac->ac_enaddr, (caddr_t)ea->aarp_sha,
734 sizeof( ea->aarp_sha ));
558 bcopy((caddr_t)ac->ac_enaddr, (caddr_t)ea->aarp_sha,
559 sizeof( ea->aarp_sha ));
735#endif sun
736
737 eh = (struct ether_header *)sa.sa_data;
738
739 if ( aa->aa_flags & AFA_PHASE2 ) {
560
561 eh = (struct ether_header *)sa.sa_data;
562
563 if ( aa->aa_flags & AFA_PHASE2 ) {
740#ifdef sun
741 bcopy((caddr_t)atmulticastaddr, (caddr_t)&eh->ether_dhost,
742 sizeof( eh->ether_dhost ));
743#else sun
744 bcopy((caddr_t)atmulticastaddr, (caddr_t)eh->ether_dhost,
745 sizeof( eh->ether_dhost ));
564 bcopy((caddr_t)atmulticastaddr, (caddr_t)eh->ether_dhost,
565 sizeof( eh->ether_dhost ));
746#endif sun
747#if defined(sun) && defined(i386)
748 eh->ether_type = htons( sizeof( struct llc ) +
749 sizeof( struct ether_aarp ));
566 eh->ether_type = htons( sizeof( struct llc ) +
567 sizeof( struct ether_aarp ));
750#else
751 eh->ether_type = sizeof( struct llc ) + sizeof( struct ether_aarp );
752#endif
753#ifdef BSD4_4
754 M_PREPEND( m, sizeof( struct llc ), M_WAIT );
568 M_PREPEND( m, sizeof( struct llc ), M_WAIT );
755#else BSD4_4
756 m->m_len += sizeof( struct llc );
757 m->m_off -= sizeof( struct llc );
758#endif BSD4_4
759 llc = mtod( m, struct llc *);
760 llc->llc_dsap = llc->llc_ssap = LLC_SNAP_LSAP;
761 llc->llc_control = LLC_UI;
762 bcopy( aarp_org_code, llc->llc_org_code, sizeof( aarp_org_code ));
763 llc->llc_ether_type = htons( ETHERTYPE_AARP );
764
765 bcopy( &AA_SAT( aa )->sat_addr.s_net, ea->aarp_spnet,
766 sizeof( ea->aarp_spnet ));
767 bcopy( &AA_SAT( aa )->sat_addr.s_net, ea->aarp_tpnet,
768 sizeof( ea->aarp_tpnet ));
769 ea->aarp_spnode = ea->aarp_tpnode = AA_SAT( aa )->sat_addr.s_node;
770 } else {
569 llc = mtod( m, struct llc *);
570 llc->llc_dsap = llc->llc_ssap = LLC_SNAP_LSAP;
571 llc->llc_control = LLC_UI;
572 bcopy( aarp_org_code, llc->llc_org_code, sizeof( aarp_org_code ));
573 llc->llc_ether_type = htons( ETHERTYPE_AARP );
574
575 bcopy( &AA_SAT( aa )->sat_addr.s_net, ea->aarp_spnet,
576 sizeof( ea->aarp_spnet ));
577 bcopy( &AA_SAT( aa )->sat_addr.s_net, ea->aarp_tpnet,
578 sizeof( ea->aarp_tpnet ));
579 ea->aarp_spnode = ea->aarp_tpnode = AA_SAT( aa )->sat_addr.s_node;
580 } else {
771#ifdef sun
772 bcopy((caddr_t)&etherbroadcastaddr, (caddr_t)&eh->ether_dhost,
773 sizeof( eh->ether_dhost ));
774#else sun
775 bcopy((caddr_t)etherbroadcastaddr, (caddr_t)eh->ether_dhost,
776 sizeof( eh->ether_dhost ));
581 bcopy((caddr_t)etherbroadcastaddr, (caddr_t)eh->ether_dhost,
582 sizeof( eh->ether_dhost ));
777#endif sun
778#if defined(sun) && defined(i386)
779 eh->ether_type = htons( ETHERTYPE_AARP );
583 eh->ether_type = htons( ETHERTYPE_AARP );
780#else
781 eh->ether_type = ETHERTYPE_AARP;
782#endif
783 ea->aarp_spa = ea->aarp_tpa = AA_SAT( aa )->sat_addr.s_node;
784 }
785
786#ifdef NETATALKDEBUG
787 printf("aarp: sending probe for %u.%u\n",
788 ntohs(AA_SAT( aa )->sat_addr.s_net),
789 AA_SAT( aa )->sat_addr.s_node);
790#endif NETATALKDEBUG
791
584 ea->aarp_spa = ea->aarp_tpa = AA_SAT( aa )->sat_addr.s_node;
585 }
586
587#ifdef NETATALKDEBUG
588 printf("aarp: sending probe for %u.%u\n",
589 ntohs(AA_SAT( aa )->sat_addr.s_net),
590 AA_SAT( aa )->sat_addr.s_node);
591#endif NETATALKDEBUG
592
792#ifdef BSD4_4
793 sa.sa_len = sizeof( struct sockaddr );
593 sa.sa_len = sizeof( struct sockaddr );
794#endif BSD4_4
795 sa.sa_family = AF_UNSPEC;
594 sa.sa_family = AF_UNSPEC;
796 (*ac->ac_if.if_output)(&ac->ac_if, m, &sa
797#if defined( __FreeBSD__ )
798 , NULL /* XXX */
799#endif __FreeBSD__
800 );
595 (*ac->ac_if.if_output)(&ac->ac_if, m, &sa, NULL); /* XXX */
801 aa->aa_probcnt--;
802}
803
804void
805aarp_clean(void)
806{
807 struct aarptab *aat;
808 int i;
809
810 untimeout( aarptimer, 0 );
811 for ( i = 0, aat = aarptab; i < AARPTAB_SIZE; i++, aat++ ) {
812 if ( aat->aat_hold ) {
813 m_freem( aat->aat_hold );
814 }
815 }
816}
596 aa->aa_probcnt--;
597}
598
599void
600aarp_clean(void)
601{
602 struct aarptab *aat;
603 int i;
604
605 untimeout( aarptimer, 0 );
606 for ( i = 0, aat = aarptab; i < AARPTAB_SIZE; i++, aat++ ) {
607 if ( aat->aat_hold ) {
608 m_freem( aat->aat_hold );
609 }
610 }
611}