]>
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/at_pat.h>
66 #include <netat/debug.h>
68 #include <sys/kern_event.h>
71 /* Following two variables are used to keep track of how many dynamic addresses
72 * we have tried out at startup.
74 int no_of_nodes_tried
; /* no of node addresses we've tried
75 * so far, within a network number
77 int no_of_nets_tried
; /* no. of network numbers tried
80 struct etalk_addr et_zeroaddr
= {
84 aarp_amt_array
*aarp_table
[IF_TOTAL_MAX
];
87 StaticProc
int aarp_req_cmd_in(aarp_pkt_t
*, at_ifaddr_t
*);
88 StaticProc
int aarp_resp_cmd_in(aarp_pkt_t
*, at_ifaddr_t
*);
89 StaticProc
int aarp_probe_cmd_in(aarp_pkt_t
*, at_ifaddr_t
*);
90 StaticProc
int aarp_send_resp(at_ifaddr_t
*, aarp_pkt_t
*);
91 StaticProc
int aarp_send_req(aarp_amt_t
*);
92 StaticProc
int aarp_send_probe(void);
93 StaticProc aarp_amt_t
*aarp_lru_entry(aarp_amt_t
*);
94 StaticProc
int aarp_glean_info(aarp_pkt_t
*, at_ifaddr_t
*);
95 StaticProc
int aarp_delete_amt_info(aarp_amt_t
*);
96 StaticProc
void aarp_build_pkt(aarp_pkt_t
*, at_ifaddr_t
*);
97 StaticProc
void aarp_sched_req(void *);
98 StaticProc
int aarp_get_rand_node(at_ifaddr_t
*);
99 StaticProc
int aarp_get_next_node(at_ifaddr_t
*);
100 StaticProc
int aarp_get_rand_net(at_ifaddr_t
*);
102 /****************************************************************************
105 ****************************************************************************/
107 int aarp_init1(elapp
)
108 register at_ifaddr_t
*elapp
;
110 elapp
->ifThisNode
.s_net
= 0;
111 elapp
->ifThisNode
.s_node
= 0;
113 if (probing
!= PROBE_TENTATIVE
) /* How do I set the initial probe */
114 probing
= PROBE_IDLE
; /* state ???*/
116 dPrintf(D_M_AARP
,D_L_ERROR
,
117 ("aarp_init: error :probing == PROBE_TENTATIVE\n"));
121 /* pick a random addr or start with what we have from initial_node addr */
122 if (elapp
->initial_addr
.s_net
== 0 && elapp
->initial_addr
.s_node
== 0) {
123 dPrintf(D_M_AARP
, D_L_INFO
,
124 ("aarp_init: pick up a new node number\n"));
125 aarp_get_rand_node(elapp
);
126 aarp_get_rand_net(elapp
);
128 probe_cb
.elapp
= elapp
;
129 probe_cb
.no_of_retries
= 0;
132 no_of_nodes_tried
= 0; /* haven't tried any addresses yet */
133 no_of_nets_tried
= 0;
135 if (aarp_send_probe() == -1) {
136 probing
= PROBE_IDLE
; /* not probing any more */
137 dPrintf(D_M_AARP
, D_L_ERROR
,
138 ("aarp_init: aarp_send_probe returns error\n"));
144 int aarp_init2(elapp
)
145 register at_ifaddr_t
*elapp
;
147 if (probe_cb
.error
!= 0) {
148 probing
= PROBE_IDLE
; /* not probing any more */
149 dPrintf(D_M_AARP
, D_L_ERROR
,
150 ("aarp_init: probe_cb.error creates error =%d\n",
155 if (aarp_table
[elapp
->ifPort
])
156 bzero ((caddr_t
)&aarp_table
[elapp
->ifPort
]->et_aarp_amt
[0],
157 sizeof(aarp_amt_array
));
161 elapp
->ifThisNode
= elapp
->initial_addr
;
162 probing
= PROBE_DONE
;
164 /* AppleTalk was successfully started up. Send event with node and net. */
165 atalk_post_msg(elapp
->aa_ifp
, KEV_ATALK_ENABLED
, &(elapp
->ifThisNode
), 0);
167 /* Set global flag */
168 at_state
.flags
|= AT_ST_STARTED
;
173 /****************************************************************************
177 * (1) The caller must take care of freeing the real storage (gbuf)
178 * (2) The incoming packet is of the form {802.3, 802.2, aarp}.
180 ****************************************************************************/
181 int aarp_rcv_pkt(pkt
, elapp
)
185 switch (ntohs(pkt
->aarp_cmd
)) {
187 return (aarp_req_cmd_in (pkt
, elapp
));
189 return (aarp_resp_cmd_in (pkt
, elapp
));
191 return (aarp_probe_cmd_in (pkt
, elapp
));
197 /****************************************************************************
200 ****************************************************************************/
201 StaticProc
int aarp_req_cmd_in (pkt
, elapp
)
206 kprintf("aarp_req_cmd_in: ifThisNode=%d:%d srcNode=%d:%d dstNode=%d:%d\n",
207 elapp->ifThisNode.s_net,
208 elapp->ifThisNode.s_node,
209 NET_VALUE(pkt->src_at_addr.atalk_net),
210 pkt->src_at_addr.atalk_node,
211 NET_VALUE(pkt->dest_at_addr.atalk_net),
212 pkt->dest_at_addr.atalk_node);
214 if ((probing
== PROBE_DONE
) &&
215 (NET_VALUE(pkt
->dest_at_addr
.atalk_net
) == elapp
->ifThisNode
.s_net
) &&
216 (pkt
->dest_at_addr
.atalk_node
== elapp
->ifThisNode
.s_node
)) {
217 if (aarp_send_resp(elapp
, pkt
) == -1)
220 /* now to glean some info */
221 aarp_glean_info(pkt
, elapp
);
227 /****************************************************************************
230 ****************************************************************************/
231 StaticProc
int aarp_resp_cmd_in (pkt
, elapp
)
235 register aarp_amt_t
*amt_ptr
;
239 case PROBE_TENTATIVE
:
240 if ((NET_VALUE(pkt
->src_at_addr
.atalk_net
) ==
241 probe_cb
.elapp
->initial_addr
.s_net
) &&
242 (pkt
->src_at_addr
.atalk_node
==
243 probe_cb
.elapp
->initial_addr
.s_node
)) {
245 /* this is a response to AARP_PROBE_CMD. There's
246 * someone out there with the address we desire
249 untimeout(aarp_sched_probe
, 0);
250 probe_cb
.no_of_retries
= 0;
251 aarp_get_next_node(probe_cb
.elapp
);
254 if (no_of_nodes_tried
== AARP_MAX_NODES_TRIED
) {
255 aarp_get_rand_net(probe_cb
.elapp
);
256 aarp_get_rand_node(probe_cb
.elapp
);
257 no_of_nodes_tried
= 0;
260 if (no_of_nets_tried
== AARP_MAX_NETS_TRIED
) {
261 /* We have tried enough nodes and nets, give up.
263 probe_cb
.error
= EADDRNOTAVAIL
;
264 AARPwakeup(&probe_cb
);
267 if (aarp_send_probe() == -1) {
268 /* expecting aarp_send_probe to fill in
271 AARPwakeup(&probe_cb
);
275 /* hmmmm! got a response packet while still probing
276 * for AT address and the AT dest address doesn't
278 * What should I do here?? kkkkkkkkk
285 AMT_LOOK(amt_ptr
, pkt
->src_at_addr
, elapp
)
289 untimeout(aarp_sched_req
, amt_ptr
);
293 if (amt_ptr
->m
== NULL
) {
294 /* this may be because of a belated response to
295 * aarp reaquest. Based on an earlier response, we
296 * might have already sent the packet out, so
297 * there's nothing to send now. This is okay, no
302 amt_ptr
->dest_addr
= pkt
->src_addr
;
303 if (FDDI_OR_TOKENRING(elapp
->aa_ifp
->if_type
))
304 ddp_bit_reverse((unsigned char *)&amt_ptr
->dest_addr
);
307 pat_output(amt_ptr
->elapp
, m
,
308 (unsigned char *)&amt_ptr
->dest_addr
, 0);
311 /* probing in a weird state?? */
319 /****************************************************************************
320 * aarp_probe_cmd_in()
322 ****************************************************************************/
323 StaticProc
int aarp_probe_cmd_in (pkt
, elapp
)
324 register aarp_pkt_t
*pkt
;
327 register aarp_amt_t
*amt_ptr
;
330 case PROBE_TENTATIVE
:
331 if ((elapp
== probe_cb
.elapp
) &&
332 (NET_VALUE(pkt
->src_at_addr
.atalk_net
) ==
333 probe_cb
.elapp
->initial_addr
.s_net
) &&
334 (pkt
->src_at_addr
.atalk_node
==
335 probe_cb
.elapp
->initial_addr
.s_node
)) {
336 /* some bozo is probing for address I want... and I
337 * can't tell him to shove off!
339 untimeout(aarp_sched_probe
, 0);
340 probe_cb
.no_of_retries
= 0;
341 aarp_get_next_node(probe_cb
.elapp
);
344 if (no_of_nodes_tried
== AARP_MAX_NODES_TRIED
) {
345 aarp_get_rand_net(probe_cb
.elapp
);
346 aarp_get_rand_node(probe_cb
.elapp
);
347 no_of_nodes_tried
= 0;
350 if (no_of_nets_tried
== AARP_MAX_NETS_TRIED
) {
351 /* We have tried enough nodes and nets, give up.
353 probe_cb
.error
= EADDRNOTAVAIL
;
354 AARPwakeup(&probe_cb
);
357 if (aarp_send_probe() == -1) {
358 /* expecting aarp_send_probe to fill in
361 AARPwakeup(&probe_cb
);
365 /* somebody's probing... none of my business yet, so
366 * just ignore the packet
373 if ((NET_VALUE(pkt
->src_at_addr
.atalk_net
) == elapp
->ifThisNode
.s_net
) &&
374 (pkt
->src_at_addr
.atalk_node
== elapp
->ifThisNode
.s_node
)) {
375 if (aarp_send_resp(elapp
, pkt
) == -1)
379 AMT_LOOK(amt_ptr
, pkt
->src_at_addr
, elapp
);
382 aarp_delete_amt_info(amt_ptr
);
385 /* probing in a weird state?? */
393 /****************************************************************************
395 ****************************************************************************/
396 int aarp_chk_addr(ddp_hdrp
, elapp
)
400 if ((ddp_hdrp
->dst_node
== elapp
->ifThisNode
.s_node
) &&
401 (NET_VALUE(ddp_hdrp
->dst_net
) == elapp
->ifThisNode
.s_net
)) {
402 return(0); /* exact match in address */
405 if (AARP_BROADCAST(ddp_hdrp
, elapp
)) {
406 return(0); /* some kind of broadcast address */
408 return (AARP_ERR_NOT_OURS
); /* not for us */
413 /****************************************************************************
417 * 1. The message coming in would be of the form {802.3, 802.2, ddp,...}
419 * 2. The message coming in would be freed here if transmission goes
420 * through okay. If an error is returned by aarp_send_data, the caller
421 * can assume that the message is not freed. The exception to
422 * this scenario is the prepended atalk_addr field. This field
423 * will ALWAYS be removed. If the message is dropped,
424 * it's not an "error".
426 * Parameter dest_at_addr must have the net # in network byte order
427 ****************************************************************************/
429 int aarp_send_data(m
, elapp
, dest_at_addr
, loop
)
431 register at_ifaddr_t
*elapp
;
432 struct atalk_addr
*dest_at_addr
; /* net# in network byte order */
433 int loop
; /* if true, loopback broadcasts */
435 register aarp_amt_t
*amt_ptr
;
436 register at_ddp_t
*ddp_hdrp
;
438 struct timeval timenow
;
439 getmicrouptime(&timenow
);
441 if (gbuf_len(m
) <= 0)
442 ddp_hdrp
= (at_ddp_t
*)gbuf_rptr(gbuf_cont(m
));
444 ddp_hdrp
= (at_ddp_t
*)gbuf_rptr(m
);
446 if ((ddp_hdrp
->dst_node
== ddp_hdrp
->src_node
) &&
447 (NET_VALUE(ddp_hdrp
->dst_net
) == NET_VALUE(ddp_hdrp
->src_net
))) {
449 * we're sending to ourselves
450 * so loop it back upstream
455 AMT_LOOK(amt_ptr
, *dest_at_addr
, elapp
);
461 * there's already a packet awaiting transmission, so
462 * drop this one and let the upper layer retransmit
468 return (pat_output(elapp
, m
,
469 (unsigned char *)&amt_ptr
->dest_addr
, 0));
472 * either this is a packet to be broadcasted, or the address
473 * resolution needs to be done
475 if (AARP_BROADCAST(ddp_hdrp
, elapp
)) {
477 struct etalk_addr
*dest_addr
;
479 dest_addr
= &elapp
->cable_multicast_addr
;
481 newm
= (gbuf_t
*)gbuf_dupm(m
);
483 if ( !(error
= pat_output(elapp
, m
,
484 (unsigned char *)dest_addr
, 0))) {
486 * The message transmitted successfully;
487 * Also loop a copy back up since this
488 * is a broadcast message.
493 ddp_input(newm
, elapp
);
501 NEW_AMT(amt_ptr
, *dest_at_addr
, elapp
)
505 * no non-busy slots available in the cache, so
506 * drop this one and let the upper layer retransmit
512 amt_ptr
->dest_at_addr
= *dest_at_addr
;
513 amt_ptr
->dest_at_addr
.atalk_unused
= 0;
515 getmicrouptime(&timenow
);
516 amt_ptr
->last_time
= timenow
.tv_sec
;
518 amt_ptr
->elapp
= elapp
;
519 amt_ptr
->no_of_retries
= 0;
521 if ((error
= aarp_send_req(amt_ptr
))) {
522 aarp_delete_amt_info(amt_ptr
);
530 /****************************************************************************
534 * The pkt being passed here is only to "look at". It should neither
535 * be used for transmission, nor freed. Its contents also must not be
538 ****************************************************************************/
539 StaticProc
int aarp_send_resp(elapp
, pkt
)
540 register at_ifaddr_t
*elapp
;
543 register aarp_pkt_t
*new_pkt
;
546 if ((m
= gbuf_alloc(AT_WR_OFFSET
+sizeof(aarp_pkt_t
), PRI_MED
)) == NULL
) {
549 gbuf_rinc(m
,AT_WR_OFFSET
);
552 new_pkt
= (aarp_pkt_t
*)gbuf_rptr(m
);
553 aarp_build_pkt(new_pkt
, elapp
);
555 new_pkt
->aarp_cmd
= htons(AARP_RESP_CMD
);
556 new_pkt
->dest_addr
= pkt
->src_addr
;
558 new_pkt
->dest_at_addr
= pkt
->src_at_addr
;
559 new_pkt
->dest_at_addr
.atalk_unused
= 0;
561 ATALK_ASSIGN(new_pkt
->src_at_addr
, elapp
->ifThisNode
.s_net
,
562 elapp
->ifThisNode
.s_node
, 0);
564 gbuf_winc(m
,sizeof(aarp_pkt_t
));
565 if (FDDI_OR_TOKENRING(elapp
->aa_ifp
->if_type
))
566 ddp_bit_reverse((unsigned char *)&new_pkt
->dest_addr
);
568 if (pat_output(elapp
, m
, (unsigned char *)&new_pkt
->dest_addr
,
576 /****************************************************************************
579 ****************************************************************************/
581 StaticProc
int aarp_send_req (amt_ptr
)
582 register aarp_amt_t
*amt_ptr
;
584 register aarp_pkt_t
*pkt
;
588 if ((m
= gbuf_alloc(AT_WR_OFFSET
+sizeof(aarp_pkt_t
), PRI_MED
)) == NULL
) {
591 gbuf_rinc(m
,AT_WR_OFFSET
);
594 pkt
= (aarp_pkt_t
*)gbuf_rptr(m
);
595 aarp_build_pkt(pkt
, amt_ptr
->elapp
);
597 pkt
->aarp_cmd
= htons(AARP_REQ_CMD
);
598 pkt
->dest_addr
= et_zeroaddr
;
599 pkt
->dest_at_addr
= amt_ptr
->dest_at_addr
;
600 pkt
->dest_at_addr
.atalk_unused
= 0;
601 ATALK_ASSIGN(pkt
->src_at_addr
, amt_ptr
->elapp
->ifThisNode
.s_net
,
602 amt_ptr
->elapp
->ifThisNode
.s_node
, 0);
603 gbuf_winc(m
,sizeof(aarp_pkt_t
));
605 amt_ptr
->no_of_retries
++;
606 timeout(aarp_sched_req
, amt_ptr
, AARP_REQ_TIMER_INT
);
608 error
= pat_output(amt_ptr
->elapp
, m
,
609 (unsigned char *)&amt_ptr
->elapp
->cable_multicast_addr
, AARP_AT_TYPE
);
612 untimeout(aarp_sched_req
, amt_ptr
);
622 /****************************************************************************
625 ****************************************************************************/
626 StaticProc
int aarp_send_probe(void)
628 register aarp_pkt_t
*pkt
;
631 if ((m
= gbuf_alloc(AT_WR_OFFSET
+sizeof(aarp_pkt_t
), PRI_MED
)) == NULL
) {
632 probe_cb
.error
= ENOBUFS
;
635 gbuf_rinc(m
,AT_WR_OFFSET
);
637 pkt
= (aarp_pkt_t
*)gbuf_rptr(m
);
638 aarp_build_pkt(pkt
, probe_cb
.elapp
);
640 pkt
->aarp_cmd
= htons(AARP_PROBE_CMD
);
641 pkt
->dest_addr
= et_zeroaddr
;
643 ATALK_ASSIGN(pkt
->src_at_addr
, probe_cb
.elapp
->initial_addr
.s_net
,
644 probe_cb
.elapp
->initial_addr
.s_node
, 0);
646 ATALK_ASSIGN(pkt
->dest_at_addr
, probe_cb
.elapp
->initial_addr
.s_net
,
647 probe_cb
.elapp
->initial_addr
.s_node
, 0);
649 gbuf_winc(m
,sizeof(aarp_pkt_t
));
651 probe_cb
.error
= pat_output(probe_cb
.elapp
, m
,
652 (unsigned char *)&probe_cb
.elapp
->cable_multicast_addr
, AARP_AT_TYPE
);
653 if (probe_cb
.error
) {
657 probing
= PROBE_TENTATIVE
;
658 probe_cb
.no_of_retries
++;
659 timeout(aarp_sched_probe
, 0, AARP_PROBE_TIMER_INT
);
666 /****************************************************************************
669 ****************************************************************************/
671 StaticProc aarp_amt_t
*aarp_lru_entry(at
)
672 register aarp_amt_t
*at
;
674 register aarp_amt_t
*at_ret
;
679 for (i
= 1, at
++; i
< AMT_BSIZ
; i
++, at
++) {
680 if (at
->last_time
< at_ret
->last_time
&& (at
->m
== NULL
))
688 /****************************************************************************
691 ****************************************************************************/
693 StaticProc
int aarp_glean_info(pkt
, elapp
)
694 register aarp_pkt_t
*pkt
;
697 register aarp_amt_t
*amt_ptr
;
699 AMT_LOOK(amt_ptr
, pkt
->src_at_addr
, elapp
);
701 if (amt_ptr
== NULL
) {
703 * amt entry for this address doesn't exist, add it to the cache
705 NEW_AMT(amt_ptr
, pkt
->src_at_addr
,elapp
);
708 return(0); /* no non-busy slots available in the cache */
709 amt_ptr
->dest_at_addr
= pkt
->src_at_addr
;
710 amt_ptr
->dest_at_addr
.atalk_unused
= 0;
712 amt_ptr
->last_time
= (int)random();
715 * update the ethernet address
718 amt_ptr
->dest_addr
= pkt
->src_addr
;
719 if (FDDI_OR_TOKENRING(elapp
->aa_ifp
->if_type
))
720 ddp_bit_reverse((unsigned char *)&amt_ptr
->dest_addr
);
725 /****************************************************************************
726 * aarp_delete_amt_info()
728 ****************************************************************************/
730 StaticProc
int aarp_delete_amt_info(amt_ptr
)
731 register aarp_amt_t
*amt_ptr
;
734 amt_ptr
->last_time
= 0;
735 ATALK_ASSIGN(amt_ptr
->dest_at_addr
, 0, 0, 0);
736 amt_ptr
->no_of_retries
= 0;
748 /****************************************************************************
751 ****************************************************************************/
753 void aarp_sched_probe(__unused
void *arg
)
758 if (probe_cb
.elapp
->aa_ifp
!= 0 &&
759 probe_cb
.no_of_retries
!= AARP_MAX_PROBE_RETRIES
) {
760 if (aarp_send_probe() == -1)
761 AARPwakeup(&probe_cb
);
764 AARPwakeup(&probe_cb
);
772 /****************************************************************************
775 ****************************************************************************/
777 StaticProc
void aarp_build_pkt(pkt
, elapp
)
778 register aarp_pkt_t
*pkt
;
781 pkt
->hardware_type
= htons(AARP_ETHER_HW_TYPE
);
782 pkt
->stack_type
= htons(AARP_AT_PROTO
);
783 pkt
->hw_addr_len
= ETHERNET_ADDR_LEN
;
784 pkt
->stack_addr_len
= AARP_AT_ADDR_LEN
;
785 bcopy(elapp
->xaddr
, pkt
->src_addr
.etalk_addr_octet
, sizeof(elapp
->xaddr
));
786 if (FDDI_OR_TOKENRING(elapp
->aa_ifp
->if_type
))
787 ddp_bit_reverse(pkt
->src_addr
.etalk_addr_octet
);
790 /****************************************************************************
793 ****************************************************************************/
795 StaticProc
void aarp_sched_req(arg
)
799 aarp_amt_t
*amt_ptr
= (aarp_amt_t
*)arg
;
804 * make sure pointer still valid in case interface removed
805 * while trying to acquire the funnel. make sure it points
806 * into one of the amt arrays.
808 for (i
= 0; i
< IF_TOTAL_MAX
; i
++) {
809 if (aarp_table
[i
] == NULL
|| (void *)amt_ptr
< (void *)aarp_table
[i
] ||
810 (void *)amt_ptr
>= (void *)(aarp_table
[i
] + 1))
811 continue; /* no match - try next entry */
814 * found match - pointer is valid
816 if (amt_ptr
->tmo
== 0) {
820 if (amt_ptr
->no_of_retries
< AARP_MAX_REQ_RETRIES
) {
821 if (aarp_send_req(amt_ptr
) == 0) {
826 aarp_delete_amt_info(amt_ptr
);
836 /****************************************************************************
837 * aarp_get_rand_node()
839 ****************************************************************************/
840 StaticProc
int aarp_get_rand_node(elapp
)
843 register u_char node
;
846 * generate a starting node number in the range 1 thru 0xfd.
847 * we use this as the starting probe point for a given net
848 * To generate a different node number each time we call
851 node
= ((u_char
)(random() & 0xff)) % 0xfd + 2;
853 elapp
->initial_addr
.s_node
= node
;
859 StaticProc
int aarp_get_next_node(elapp
)
862 register u_char node
= elapp
->initial_addr
.s_node
;
865 * return the next node number in the range 1 thru 0xfd.
867 node
= (node
== 0xfd) ? (1) : (node
+1);
869 elapp
->initial_addr
.s_node
= node
;
877 /****************************************************************************
878 * aarp_get_rand_net()
880 ****************************************************************************/
881 StaticProc
int aarp_get_rand_net(elapp
)
882 register at_ifaddr_t
*elapp
;
884 register at_net_al last_net
, new_net
;
886 if (elapp
->ifThisCableStart
) {
887 last_net
= elapp
->initial_addr
.s_net
;
889 * the range of network numbers valid for this
890 * cable is known. Try to choose a number from
893 new_net
= ((at_net_al
)random() & 0xffff);
894 /* two-byte random number generated... now fit it in
895 * the prescribed range
897 new_net
= new_net
% (unsigned) (elapp
->ifThisCableEnd
-
898 elapp
->ifThisCableStart
+ 1)
899 + elapp
->ifThisCableStart
;
901 if (new_net
== last_net
) {
902 if (new_net
== elapp
->ifThisCableEnd
)
903 new_net
= elapp
->ifThisCableStart
;
907 elapp
->initial_addr
.s_net
= new_net
;
909 /* The range of valid network numbers for this cable
910 * is not known... choose a network number from
913 last_net
= (elapp
->initial_addr
.s_net
& 0x00ff);
914 new_net
= (at_net_al
)random() & 0x00ff;
916 if (new_net
== last_net
)
920 elapp
->initial_addr
.s_net
= (DDP_STARTUP_LOW
| new_net
);
926 int getAarpTableSize(__unused
int elapId
)
927 /* elap_specifics array index (should be
928 * changed when we add a non-ethernet type
929 * of I/F to the mix. Unused for now.
935 int getPhysAddrSize(__unused
int elapId
)
936 /* elap_specifics array index (should be
937 * changed when we add a non-ethernet type
938 * of I/F to the mix. Unused for now.
941 return(ETHERNET_ADDR_LEN
);
944 #define ENTRY_SIZE sizeof(struct atalk_addr) + sizeof(struct etalk_addr)
946 snmpAarpEnt_t
*getAarp(elapId
)
947 int *elapId
; /* I/F table to retrieve & table
948 size entries on return */
950 /* gets aarp table for specified interface and builds
951 a table in SNMP expected format. Returns pointer to said
952 table and sets elapId to byte size of used portion of table
957 static snmpAarpEnt_t snmp
[AMTSIZE
];
958 snmpAarpEnt_t
*snmpp
;
959 struct atalk_addr addr
;
963 if (*elapId
<0 || *elapId
>= IF_TOTAL_MAX
)
967 for (i
=0, amtp
= &(aarp_table
[*elapId
]->et_aarp_amt
[0]), snmpp
= snmp
;
968 i
< AMTSIZE
; i
++,amtp
++) {
970 /* last_time will be 0 if entry was never used */
971 if (amtp
->last_time
) {
972 /* copy just network & mac address.
973 * For speed, we assume that the atalk_addr
974 * & etalk_addr positions in the aarp_amt_t struct
975 * has not changed and copy both at once
977 addr
.atalk_unused
= 0;
978 tmp_net
= UAS_VALUE(amtp
->dest_at_addr
.atalk_net
);
979 NET_ASSIGN(addr
.atalk_net
, tmp_net
);
980 addr
.atalk_node
= amtp
->dest_at_addr
.atalk_node
;
981 bcopy(&addr
, &snmpp
->ap_ddpAddr
, ENTRY_SIZE
);
990 /*#endif *//* COMMENTED_OUT */