]>
git.saurik.com Git - apple/xnu.git/blob - bsd/netat/ddp_aarp.c
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
28 /* Copyright (c) 1988, 1989, 1997, 1998 Apple Computer, Inc.
30 * Modified for MP, 1996 by Tuyen Nguyen
31 * Modified, March 17, 1997 by Tuyen Nguyen for MacOSX.
34 /* at_aarp.c: 2.0, 1.17; 10/4/93; Apple Computer, Inc. */;
36 /* This file is at_aarp.c and it contains all the routines used by AARP. This
37 * is part of the LAP layer.
40 #include <sys/errno.h>
41 #include <sys/types.h>
42 #include <sys/param.h>
43 #include <machine/spl.h>
44 #include <sys/systm.h>
45 #include <sys/kernel.h>
47 #include <sys/filedesc.h>
48 #include <sys/fcntl.h>
50 #include <sys/ioctl.h>
51 #include <sys/malloc.h>
52 #include <sys/socket.h>
53 #include <sys/socketvar.h>
56 #include <net/if_types.h>
58 #include <netat/sysglue.h>
59 #include <netat/appletalk.h>
60 #include <netat/ddp.h>
61 #include <netat/at_snmp.h>
62 #include <netat/at_pcb.h>
63 #include <netat/at_var.h>
64 #include <netat/at_aarp.h>
65 #include <netat/debug.h>
67 #include <sys/kern_event.h>
70 /* Following two variables are used to keep track of how many dynamic addresses
71 * we have tried out at startup.
73 int no_of_nodes_tried
; /* no of node addresses we've tried
74 * so far, within a network number
76 int no_of_nets_tried
; /* no. of network numbers tried
79 struct etalk_addr et_zeroaddr
= {
83 aarp_amt_array
*aarp_table
[IF_TOTAL_MAX
];
85 int aarp_init1(), aarp_init2();
88 StaticProc
int aarp_req_cmd_in();
89 StaticProc
int aarp_resp_cmd_in();
90 StaticProc
int aarp_probe_cmd_in();
91 StaticProc
int aarp_send_resp();
92 StaticProc
int aarp_send_req();
93 StaticProc
int aarp_send_probe();
94 StaticProc aarp_amt_t
*aarp_lru_entry();
95 StaticProc
int aarp_glean_info();
96 StaticProc
int aarp_delete_amt_info();
97 StaticProc
void aarp_build_pkt();
98 StaticProc
void aarp_sched_req(void *);
99 StaticProc
int aarp_get_rand_node();
100 StaticProc
int aarp_get_next_node();
101 StaticProc
int aarp_get_rand_net();
102 atlock_t arpinp_lock
;
104 extern void AARPwakeup(aarp_amt_t
*);
105 extern int pat_output(at_ifaddr_t
*, gbuf_t
*, unsigned char *, int);
107 /****************************************************************************
110 ****************************************************************************/
112 int aarp_init1(elapp
)
113 register at_ifaddr_t
*elapp
;
115 elapp
->ifThisNode
.s_net
= 0;
116 elapp
->ifThisNode
.s_node
= 0;
118 if (probing
!= PROBE_TENTATIVE
) /* How do I set the initial probe */
119 probing
= PROBE_IDLE
; /* state ???*/
121 dPrintf(D_M_AARP
,D_L_ERROR
,
122 ("aarp_init: error :probing == PROBE_TENTATIVE\n"));
126 /* pick a random addr or start with what we have from initial_node addr */
127 if (elapp
->initial_addr
.s_net
== 0 && elapp
->initial_addr
.s_node
== 0) {
128 dPrintf(D_M_AARP
, D_L_INFO
,
129 ("aarp_init: pick up a new node number\n"));
130 aarp_get_rand_node(elapp
);
131 aarp_get_rand_net(elapp
);
133 probe_cb
.elapp
= elapp
;
134 probe_cb
.no_of_retries
= 0;
137 no_of_nodes_tried
= 0; /* haven't tried any addresses yet */
138 no_of_nets_tried
= 0;
140 if (aarp_send_probe() == -1) {
141 probing
= PROBE_IDLE
; /* not probing any more */
142 dPrintf(D_M_AARP
, D_L_ERROR
,
143 ("aarp_init: aarp_send_probe returns error\n"));
149 int aarp_init2(elapp
)
150 register at_ifaddr_t
*elapp
;
152 if (probe_cb
.error
!= 0) {
153 probing
= PROBE_IDLE
; /* not probing any more */
154 dPrintf(D_M_AARP
, D_L_ERROR
,
155 ("aarp_init: probe_cb.error creates error =%d\n",
160 if (aarp_table
[elapp
->ifPort
])
161 bzero ((caddr_t
)&aarp_table
[elapp
->ifPort
]->et_aarp_amt
[0],
162 sizeof(aarp_amt_array
));
166 elapp
->ifThisNode
= elapp
->initial_addr
;
167 probing
= PROBE_DONE
;
169 /* AppleTalk was successfully started up. Send event with node and net. */
170 atalk_post_msg(elapp
->aa_ifp
, KEV_ATALK_ENABLED
, &(elapp
->ifThisNode
), 0);
172 /* Set global flag */
173 at_state
.flags
|= AT_ST_STARTED
;
178 /****************************************************************************
182 * (1) The caller must take care of freeing the real storage (gbuf)
183 * (2) The incoming packet is of the form {802.3, 802.2, aarp}.
185 ****************************************************************************/
186 int aarp_rcv_pkt(pkt
, elapp
)
190 switch (pkt
->aarp_cmd
) {
192 return (aarp_req_cmd_in (pkt
, elapp
));
194 return (aarp_resp_cmd_in (pkt
, elapp
));
196 return (aarp_probe_cmd_in (pkt
, elapp
));
202 /****************************************************************************
205 ****************************************************************************/
206 StaticProc
int aarp_req_cmd_in (pkt
, elapp
)
211 kprintf("aarp_req_cmd_in: ifThisNode=%d:%d srcNode=%d:%d dstNode=%d:%d\n",
212 elapp->ifThisNode.s_net,
213 elapp->ifThisNode.s_node,
214 NET_VALUE(pkt->src_at_addr.atalk_net),
215 pkt->src_at_addr.atalk_node,
216 NET_VALUE(pkt->dest_at_addr.atalk_net),
217 pkt->dest_at_addr.atalk_node);
219 if ((probing
== PROBE_DONE
) &&
220 (NET_VALUE(pkt
->dest_at_addr
.atalk_net
) == elapp
->ifThisNode
.s_net
) &&
221 (pkt
->dest_at_addr
.atalk_node
== elapp
->ifThisNode
.s_node
)) {
222 if (aarp_send_resp(elapp
, pkt
) == -1)
225 /* now to glean some info */
226 aarp_glean_info(pkt
, elapp
);
232 /****************************************************************************
235 ****************************************************************************/
236 StaticProc
int aarp_resp_cmd_in (pkt
, elapp
)
240 register aarp_amt_t
*amt_ptr
;
244 case PROBE_TENTATIVE
:
245 if ((NET_VALUE(pkt
->src_at_addr
.atalk_net
) ==
246 probe_cb
.elapp
->initial_addr
.s_net
) &&
247 (pkt
->src_at_addr
.atalk_node
==
248 probe_cb
.elapp
->initial_addr
.s_node
)) {
250 /* this is a response to AARP_PROBE_CMD. There's
251 * someone out there with the address we desire
254 untimeout(aarp_sched_probe
, 0);
255 probe_cb
.no_of_retries
= 0;
256 aarp_get_next_node(probe_cb
.elapp
);
259 if (no_of_nodes_tried
== AARP_MAX_NODES_TRIED
) {
260 aarp_get_rand_net(probe_cb
.elapp
);
261 aarp_get_rand_node(probe_cb
.elapp
);
262 no_of_nodes_tried
= 0;
265 if (no_of_nets_tried
== AARP_MAX_NETS_TRIED
) {
266 /* We have tried enough nodes and nets, give up.
268 probe_cb
.error
= EADDRNOTAVAIL
;
269 AARPwakeup(&probe_cb
);
272 if (aarp_send_probe() == -1) {
273 /* expecting aarp_send_probe to fill in
276 AARPwakeup(&probe_cb
);
280 /* hmmmm! got a response packet while still probing
281 * for AT address and the AT dest address doesn't
283 * What should I do here?? kkkkkkkkk
290 AMT_LOOK(amt_ptr
, pkt
->src_at_addr
, elapp
);
294 untimeout(aarp_sched_req
, amt_ptr
);
298 if (amt_ptr
->m
== NULL
) {
299 /* this may be because of a belated response to
300 * aarp reaquest. Based on an earlier response, we
301 * might have already sent the packet out, so
302 * there's nothing to send now. This is okay, no
307 amt_ptr
->dest_addr
= pkt
->src_addr
;
308 if (FDDI_OR_TOKENRING(elapp
->aa_ifp
->if_type
))
309 ddp_bit_reverse(&amt_ptr
->dest_addr
);
312 pat_output(amt_ptr
->elapp
, m
,
313 (unsigned char *)&amt_ptr
->dest_addr
, 0);
316 /* probing in a weird state?? */
324 /****************************************************************************
325 * aarp_probe_cmd_in()
327 ****************************************************************************/
328 StaticProc
int aarp_probe_cmd_in (pkt
, elapp
)
329 register aarp_pkt_t
*pkt
;
332 register aarp_amt_t
*amt_ptr
;
335 case PROBE_TENTATIVE
:
336 if ((elapp
== probe_cb
.elapp
) &&
337 (NET_VALUE(pkt
->src_at_addr
.atalk_net
) ==
338 probe_cb
.elapp
->initial_addr
.s_net
) &&
339 (pkt
->src_at_addr
.atalk_node
==
340 probe_cb
.elapp
->initial_addr
.s_node
)) {
341 /* some bozo is probing for address I want... and I
342 * can't tell him to shove off!
344 untimeout(aarp_sched_probe
, 0);
345 probe_cb
.no_of_retries
= 0;
346 aarp_get_next_node(probe_cb
.elapp
);
349 if (no_of_nodes_tried
== AARP_MAX_NODES_TRIED
) {
350 aarp_get_rand_net(probe_cb
.elapp
);
351 aarp_get_rand_node(probe_cb
.elapp
);
352 no_of_nodes_tried
= 0;
355 if (no_of_nets_tried
== AARP_MAX_NETS_TRIED
) {
356 /* We have tried enough nodes and nets, give up.
358 probe_cb
.error
= EADDRNOTAVAIL
;
359 AARPwakeup(&probe_cb
);
362 if (aarp_send_probe() == -1) {
363 /* expecting aarp_send_probe to fill in
366 AARPwakeup(&probe_cb
);
370 /* somebody's probing... none of my business yet, so
371 * just ignore the packet
378 if ((NET_VALUE(pkt
->src_at_addr
.atalk_net
) == elapp
->ifThisNode
.s_net
) &&
379 (pkt
->src_at_addr
.atalk_node
== elapp
->ifThisNode
.s_node
)) {
380 if (aarp_send_resp(elapp
, pkt
) == -1)
384 AMT_LOOK(amt_ptr
, pkt
->src_at_addr
, elapp
);
387 aarp_delete_amt_info(amt_ptr
);
390 /* probing in a weird state?? */
398 /****************************************************************************
400 ****************************************************************************/
401 int aarp_chk_addr(ddp_hdrp
, elapp
)
405 if ((ddp_hdrp
->dst_node
== elapp
->ifThisNode
.s_node
) &&
406 (NET_VALUE(ddp_hdrp
->dst_net
) == elapp
->ifThisNode
.s_net
)) {
407 return(0); /* exact match in address */
410 if (AARP_BROADCAST(ddp_hdrp
, elapp
)) {
411 return(0); /* some kind of broadcast address */
413 return (AARP_ERR_NOT_OURS
); /* not for us */
418 /****************************************************************************
422 * 1. The message coming in would be of the form {802.3, 802.2, ddp,...}
424 * 2. The message coming in would be freed here if transmission goes
425 * through okay. If an error is returned by aarp_send_data, the caller
426 * can assume that the message is not freed. The exception to
427 * this scenario is the prepended atalk_addr field. This field
428 * will ALWAYS be removed. If the message is dropped,
429 * it's not an "error".
431 ****************************************************************************/
433 int aarp_send_data(m
, elapp
, dest_at_addr
, loop
)
435 register at_ifaddr_t
*elapp
;
436 struct atalk_addr
*dest_at_addr
;
437 int loop
; /* if true, loopback broadcasts */
439 register aarp_amt_t
*amt_ptr
;
440 register at_ddp_t
*ddp_hdrp
;
443 struct timeval timenow
;
444 getmicrouptime(&timenow
);
446 if (gbuf_len(m
) <= 0)
447 ddp_hdrp
= (at_ddp_t
*)gbuf_rptr(gbuf_cont(m
));
449 ddp_hdrp
= (at_ddp_t
*)gbuf_rptr(m
);
451 if ((ddp_hdrp
->dst_node
== ddp_hdrp
->src_node
) &&
452 (NET_VALUE(ddp_hdrp
->dst_net
) == NET_VALUE(ddp_hdrp
->src_net
))) {
454 * we're sending to ourselves
455 * so loop it back upstream
460 ATDISABLE(s
, arpinp_lock
);
461 AMT_LOOK(amt_ptr
, *dest_at_addr
, elapp
);
467 * there's already a packet awaiting transmission, so
468 * drop this one and let the upper layer retransmit
471 ATENABLE(s
, arpinp_lock
);
475 ATENABLE(s
, arpinp_lock
);
476 return (pat_output(elapp
, m
,
477 (unsigned char *)&amt_ptr
->dest_addr
, 0));
480 * either this is a packet to be broadcasted, or the address
481 * resolution needs to be done
483 if (AARP_BROADCAST(ddp_hdrp
, elapp
)) {
485 struct etalk_addr
*dest_addr
;
487 ATENABLE(s
, arpinp_lock
);
488 dest_addr
= &elapp
->cable_multicast_addr
;
490 newm
= (gbuf_t
*)gbuf_dupm(m
);
492 if ( !(error
= pat_output(elapp
, m
,
493 (unsigned char *)dest_addr
, 0))) {
495 * The message transmitted successfully;
496 * Also loop a copy back up since this
497 * is a broadcast message.
502 ddp_input(newm
, elapp
);
510 NEW_AMT(amt_ptr
, *dest_at_addr
,elapp
);
514 * no non-busy slots available in the cache, so
515 * drop this one and let the upper layer retransmit
518 ATENABLE(s
, arpinp_lock
);
522 amt_ptr
->dest_at_addr
= *dest_at_addr
;
523 amt_ptr
->dest_at_addr
.atalk_unused
= 0;
525 getmicrouptime(&timenow
);
526 amt_ptr
->last_time
= timenow
.tv_sec
;
528 amt_ptr
->elapp
= elapp
;
529 amt_ptr
->no_of_retries
= 0;
530 ATENABLE(s
, arpinp_lock
);
532 if ((error
= aarp_send_req(amt_ptr
))) {
533 aarp_delete_amt_info(amt_ptr
);
541 /****************************************************************************
545 * The pkt being passed here is only to "look at". It should neither
546 * be used for transmission, nor freed. Its contents also must not be
549 ****************************************************************************/
550 StaticProc
int aarp_send_resp(elapp
, pkt
)
551 register at_ifaddr_t
*elapp
;
554 register aarp_pkt_t
*new_pkt
;
557 if ((m
= gbuf_alloc(AT_WR_OFFSET
+sizeof(aarp_pkt_t
), PRI_MED
)) == NULL
) {
560 gbuf_rinc(m
,AT_WR_OFFSET
);
563 new_pkt
= (aarp_pkt_t
*)gbuf_rptr(m
);
564 aarp_build_pkt(new_pkt
, elapp
);
566 new_pkt
->aarp_cmd
= AARP_RESP_CMD
;
567 new_pkt
->dest_addr
= pkt
->src_addr
;
569 new_pkt
->dest_at_addr
= pkt
->src_at_addr
;
570 new_pkt
->dest_at_addr
.atalk_unused
= 0;
572 ATALK_ASSIGN(new_pkt
->src_at_addr
, elapp
->ifThisNode
.s_net
,
573 elapp
->ifThisNode
.s_node
, 0);
575 gbuf_winc(m
,sizeof(aarp_pkt_t
));
576 if (FDDI_OR_TOKENRING(elapp
->aa_ifp
->if_type
))
577 ddp_bit_reverse(&new_pkt
->dest_addr
);
579 if (pat_output(elapp
, m
, (unsigned char *)&new_pkt
->dest_addr
,
587 /****************************************************************************
590 ****************************************************************************/
592 StaticProc
int aarp_send_req (amt_ptr
)
593 register aarp_amt_t
*amt_ptr
;
595 register aarp_pkt_t
*pkt
;
599 if ((m
= gbuf_alloc(AT_WR_OFFSET
+sizeof(aarp_pkt_t
), PRI_MED
)) == NULL
) {
602 gbuf_rinc(m
,AT_WR_OFFSET
);
605 pkt
= (aarp_pkt_t
*)gbuf_rptr(m
);
606 aarp_build_pkt(pkt
, amt_ptr
->elapp
);
608 pkt
->aarp_cmd
= AARP_REQ_CMD
;
609 pkt
->dest_addr
= et_zeroaddr
;
610 pkt
->dest_at_addr
= amt_ptr
->dest_at_addr
;
611 pkt
->dest_at_addr
.atalk_unused
= 0;
612 ATALK_ASSIGN(pkt
->src_at_addr
, amt_ptr
->elapp
->ifThisNode
.s_net
,
613 amt_ptr
->elapp
->ifThisNode
.s_node
, 0);
614 gbuf_winc(m
,sizeof(aarp_pkt_t
));
616 amt_ptr
->no_of_retries
++;
617 timeout(aarp_sched_req
, amt_ptr
, AARP_REQ_TIMER_INT
);
619 error
= pat_output(amt_ptr
->elapp
, m
,
620 (unsigned char *)&amt_ptr
->elapp
->cable_multicast_addr
, AARP_AT_TYPE
);
623 untimeout(aarp_sched_req
, amt_ptr
);
633 /****************************************************************************
636 ****************************************************************************/
637 StaticProc
int aarp_send_probe()
639 register aarp_pkt_t
*pkt
;
642 if ((m
= gbuf_alloc(AT_WR_OFFSET
+sizeof(aarp_pkt_t
), PRI_MED
)) == NULL
) {
643 probe_cb
.error
= ENOBUFS
;
646 gbuf_rinc(m
,AT_WR_OFFSET
);
648 pkt
= (aarp_pkt_t
*)gbuf_rptr(m
);
649 aarp_build_pkt(pkt
, probe_cb
.elapp
);
651 pkt
->aarp_cmd
= AARP_PROBE_CMD
;
652 pkt
->dest_addr
= et_zeroaddr
;
654 ATALK_ASSIGN(pkt
->src_at_addr
, probe_cb
.elapp
->initial_addr
.s_net
,
655 probe_cb
.elapp
->initial_addr
.s_node
, 0);
657 ATALK_ASSIGN(pkt
->dest_at_addr
, probe_cb
.elapp
->initial_addr
.s_net
,
658 probe_cb
.elapp
->initial_addr
.s_node
, 0);
660 gbuf_winc(m
,sizeof(aarp_pkt_t
));
662 probe_cb
.error
= pat_output(probe_cb
.elapp
, m
,
663 (unsigned char *)&probe_cb
.elapp
->cable_multicast_addr
, AARP_AT_TYPE
);
664 if (probe_cb
.error
) {
668 probing
= PROBE_TENTATIVE
;
669 probe_cb
.no_of_retries
++;
670 timeout(aarp_sched_probe
, 0, AARP_PROBE_TIMER_INT
);
677 /****************************************************************************
680 ****************************************************************************/
682 StaticProc aarp_amt_t
*aarp_lru_entry(at
)
683 register aarp_amt_t
*at
;
685 register aarp_amt_t
*at_ret
;
690 for (i
= 1, at
++; i
< AMT_BSIZ
; i
++, at
++) {
691 if (at
->last_time
< at_ret
->last_time
&& (at
->m
== NULL
))
699 /****************************************************************************
702 ****************************************************************************/
704 StaticProc
int aarp_glean_info(pkt
, elapp
)
705 register aarp_pkt_t
*pkt
;
708 register aarp_amt_t
*amt_ptr
;
711 ATDISABLE(s
, arpinp_lock
);
712 AMT_LOOK(amt_ptr
, pkt
->src_at_addr
, elapp
);
714 if (amt_ptr
== NULL
) {
716 * amt entry for this address doesn't exist, add it to the cache
718 NEW_AMT(amt_ptr
, pkt
->src_at_addr
,elapp
);
722 ATENABLE(s
, arpinp_lock
);
723 return(0); /* no non-busy slots available in the cache */
725 amt_ptr
->dest_at_addr
= pkt
->src_at_addr
;
726 amt_ptr
->dest_at_addr
.atalk_unused
= 0;
728 amt_ptr
->last_time
= (int)random();
731 * update the ethernet address
734 amt_ptr
->dest_addr
= pkt
->src_addr
;
735 if (FDDI_OR_TOKENRING(elapp
->aa_ifp
->if_type
))
736 ddp_bit_reverse(&amt_ptr
->dest_addr
);
737 ATENABLE(s
, arpinp_lock
);
742 /****************************************************************************
743 * aarp_delete_amt_info()
745 ****************************************************************************/
747 StaticProc
int aarp_delete_amt_info(amt_ptr
)
748 register aarp_amt_t
*amt_ptr
;
752 ATDISABLE(s
, arpinp_lock
);
753 amt_ptr
->last_time
= 0;
754 ATALK_ASSIGN(amt_ptr
->dest_at_addr
, 0, 0, 0);
755 amt_ptr
->no_of_retries
= 0;
760 ATENABLE(s
, arpinp_lock
);
764 ATENABLE(s
, arpinp_lock
);
770 /****************************************************************************
773 ****************************************************************************/
775 void aarp_sched_probe(void *arg
)
780 if (probe_cb
.elapp
->aa_ifp
!= 0 &&
781 probe_cb
.no_of_retries
!= AARP_MAX_PROBE_RETRIES
) {
782 if (aarp_send_probe() == -1)
783 AARPwakeup(&probe_cb
);
786 AARPwakeup(&probe_cb
);
794 /****************************************************************************
797 ****************************************************************************/
799 StaticProc
void aarp_build_pkt(pkt
, elapp
)
800 register aarp_pkt_t
*pkt
;
803 pkt
->hardware_type
= AARP_ETHER_HW_TYPE
;
804 pkt
->stack_type
= AARP_AT_PROTO
;
805 pkt
->hw_addr_len
= ETHERNET_ADDR_LEN
;
806 pkt
->stack_addr_len
= AARP_AT_ADDR_LEN
;
807 bcopy(elapp
->xaddr
, pkt
->src_addr
.etalk_addr_octet
, sizeof(elapp
->xaddr
));
808 if (FDDI_OR_TOKENRING(elapp
->aa_ifp
->if_type
))
809 ddp_bit_reverse(pkt
->src_addr
.etalk_addr_octet
);
812 /****************************************************************************
815 ****************************************************************************/
817 StaticProc
void aarp_sched_req(arg
)
821 aarp_amt_t
*amt_ptr
= (aarp_amt_t
*)arg
;
826 * make sure pointer still valid in case interface removed
827 * while trying to acquire the funnel. make sure it points
828 * into one of the amt arrays.
830 for (i
= 0; i
< IF_TOTAL_MAX
; i
++) {
831 if (aarp_table
[i
] == NULL
|| (void *)amt_ptr
< (void *)aarp_table
[i
] ||
832 (void *)amt_ptr
>= (void *)(aarp_table
[i
] + 1))
833 continue; /* no match - try next entry */
836 * found match - pointer is valid
838 ATDISABLE(s
, arpinp_lock
);
839 if (amt_ptr
->tmo
== 0) {
840 ATENABLE(s
, arpinp_lock
);
844 if (amt_ptr
->no_of_retries
< AARP_MAX_REQ_RETRIES
) {
845 ATENABLE(s
, arpinp_lock
);
846 if (aarp_send_req(amt_ptr
) == 0) {
850 ATDISABLE(s
, arpinp_lock
);
852 ATENABLE(s
, arpinp_lock
);
853 aarp_delete_amt_info(amt_ptr
);
863 /****************************************************************************
864 * aarp_get_rand_node()
866 ****************************************************************************/
867 StaticProc
int aarp_get_rand_node(elapp
)
870 register u_char node
;
873 * generate a starting node number in the range 1 thru 0xfd.
874 * we use this as the starting probe point for a given net
875 * To generate a different node number each time we call
878 node
= ((u_char
)(random() & 0xff)) % 0xfd + 2;
880 elapp
->initial_addr
.s_node
= node
;
886 StaticProc
int aarp_get_next_node(elapp
)
889 register u_char node
= elapp
->initial_addr
.s_node
;
892 * return the next node number in the range 1 thru 0xfd.
894 node
= (node
== 0xfd) ? (1) : (node
+1);
896 elapp
->initial_addr
.s_node
= node
;
904 /****************************************************************************
905 * aarp_get_rand_net()
907 ****************************************************************************/
908 StaticProc
int aarp_get_rand_net(elapp
)
909 register at_ifaddr_t
*elapp
;
911 register at_net_al last_net
, new_net
;
913 if (elapp
->ifThisCableStart
) {
914 last_net
= elapp
->initial_addr
.s_net
;
916 * the range of network numbers valid for this
917 * cable is known. Try to choose a number from
920 new_net
= ((at_net_al
)random() & 0xffff);
921 /* two-byte random number generated... now fit it in
922 * the prescribed range
924 new_net
= new_net
% (unsigned) (elapp
->ifThisCableEnd
-
925 elapp
->ifThisCableStart
+ 1)
926 + elapp
->ifThisCableStart
;
928 if (new_net
== last_net
) {
929 if (new_net
== elapp
->ifThisCableEnd
)
930 new_net
= elapp
->ifThisCableStart
;
934 elapp
->initial_addr
.s_net
= new_net
;
936 /* The range of valid network numbers for this cable
937 * is not known... choose a network number from
940 last_net
= (elapp
->initial_addr
.s_net
& 0x00ff);
941 new_net
= (at_net_al
)random() & 0x00ff;
943 if (new_net
== last_net
)
947 elapp
->initial_addr
.s_net
= (DDP_STARTUP_LOW
| new_net
);
953 int getAarpTableSize(elapId
)
954 int elapId
; /* elap_specifics array index (should be
955 * changed when we add a non-ethernet type
956 * of I/F to the mix. Unused for now.
962 int getPhysAddrSize(elapId
)
963 int elapId
; /* elap_specifics array index (should be
964 * changed when we add a non-ethernet type
965 * of I/F to the mix. Unused for now.
968 return(ETHERNET_ADDR_LEN
);
971 #define ENTRY_SIZE sizeof(struct atalk_addr) + sizeof(struct etalk_addr)
973 snmpAarpEnt_t
*getAarp(elapId
)
974 int *elapId
; /* I/F table to retrieve & table
975 size entries on return */
977 /* gets aarp table for specified interface and builds
978 a table in SNMP expected format. Returns pointer to said
979 table and sets elapId to byte size of used portion of table
984 static snmpAarpEnt_t snmp
[AMTSIZE
];
985 snmpAarpEnt_t
*snmpp
;
988 if (*elapId
<0 || *elapId
>= IF_TOTAL_MAX
)
992 for (i
=0, amtp
= &(aarp_table
[*elapId
]->et_aarp_amt
[0]), snmpp
= snmp
;
993 i
< AMTSIZE
; i
++,amtp
++) {
995 /* last_time will be 0 if entry was never used */
996 if (amtp
->last_time
) {
997 /* copy just network & mac address.
998 * For speed, we assume that the atalk_addr
999 * & etalk_addr positions in the aarp_amt_t struct
1000 * has not changed and copy both at once
1002 bcopy(&amtp
->dest_at_addr
, &snmpp
->ap_ddpAddr
, ENTRY_SIZE
);
1011 /*#endif *//* COMMENTED_OUT */