]>
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_LICENSE_OSREFERENCE_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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
30 /* Copyright (c) 1988, 1989, 1997, 1998 Apple Computer, Inc.
32 * Modified for MP, 1996 by Tuyen Nguyen
33 * Modified, March 17, 1997 by Tuyen Nguyen for MacOSX.
36 /* at_aarp.c: 2.0, 1.17; 10/4/93; Apple Computer, Inc. */;
38 /* This file is at_aarp.c and it contains all the routines used by AARP. This
39 * is part of the LAP layer.
42 #include <sys/errno.h>
43 #include <sys/types.h>
44 #include <sys/param.h>
45 #include <machine/spl.h>
46 #include <sys/systm.h>
47 #include <sys/kernel.h>
49 #include <sys/filedesc.h>
50 #include <sys/fcntl.h>
52 #include <sys/ioctl.h>
53 #include <sys/malloc.h>
54 #include <sys/socket.h>
55 #include <sys/socketvar.h>
58 #include <net/if_types.h>
60 #include <netat/sysglue.h>
61 #include <netat/appletalk.h>
62 #include <netat/ddp.h>
63 #include <netat/at_snmp.h>
64 #include <netat/at_pcb.h>
65 #include <netat/at_var.h>
66 #include <netat/at_aarp.h>
67 #include <netat/debug.h>
69 #include <sys/kern_event.h>
72 /* Following two variables are used to keep track of how many dynamic addresses
73 * we have tried out at startup.
75 int no_of_nodes_tried
; /* no of node addresses we've tried
76 * so far, within a network number
78 int no_of_nets_tried
; /* no. of network numbers tried
81 struct etalk_addr et_zeroaddr
= {
85 aarp_amt_array
*aarp_table
[IF_TOTAL_MAX
];
87 int aarp_init1(), aarp_init2();
90 StaticProc
int aarp_req_cmd_in();
91 StaticProc
int aarp_resp_cmd_in();
92 StaticProc
int aarp_probe_cmd_in();
93 StaticProc
int aarp_send_resp();
94 StaticProc
int aarp_send_req();
95 StaticProc
int aarp_send_probe();
96 StaticProc aarp_amt_t
*aarp_lru_entry();
97 StaticProc
int aarp_glean_info();
98 StaticProc
int aarp_delete_amt_info();
99 StaticProc
void aarp_build_pkt();
100 StaticProc
void aarp_sched_req(void *);
101 StaticProc
int aarp_get_rand_node();
102 StaticProc
int aarp_get_next_node();
103 StaticProc
int aarp_get_rand_net();
105 extern void AARPwakeup(aarp_amt_t
*);
106 extern int pat_output(at_ifaddr_t
*, gbuf_t
*, unsigned char *, int);
108 /****************************************************************************
111 ****************************************************************************/
113 int aarp_init1(elapp
)
114 register at_ifaddr_t
*elapp
;
116 elapp
->ifThisNode
.s_net
= 0;
117 elapp
->ifThisNode
.s_node
= 0;
119 if (probing
!= PROBE_TENTATIVE
) /* How do I set the initial probe */
120 probing
= PROBE_IDLE
; /* state ???*/
122 dPrintf(D_M_AARP
,D_L_ERROR
,
123 ("aarp_init: error :probing == PROBE_TENTATIVE\n"));
127 /* pick a random addr or start with what we have from initial_node addr */
128 if (elapp
->initial_addr
.s_net
== 0 && elapp
->initial_addr
.s_node
== 0) {
129 dPrintf(D_M_AARP
, D_L_INFO
,
130 ("aarp_init: pick up a new node number\n"));
131 aarp_get_rand_node(elapp
);
132 aarp_get_rand_net(elapp
);
134 probe_cb
.elapp
= elapp
;
135 probe_cb
.no_of_retries
= 0;
138 no_of_nodes_tried
= 0; /* haven't tried any addresses yet */
139 no_of_nets_tried
= 0;
141 if (aarp_send_probe() == -1) {
142 probing
= PROBE_IDLE
; /* not probing any more */
143 dPrintf(D_M_AARP
, D_L_ERROR
,
144 ("aarp_init: aarp_send_probe returns error\n"));
150 int aarp_init2(elapp
)
151 register at_ifaddr_t
*elapp
;
153 if (probe_cb
.error
!= 0) {
154 probing
= PROBE_IDLE
; /* not probing any more */
155 dPrintf(D_M_AARP
, D_L_ERROR
,
156 ("aarp_init: probe_cb.error creates error =%d\n",
161 if (aarp_table
[elapp
->ifPort
])
162 bzero ((caddr_t
)&aarp_table
[elapp
->ifPort
]->et_aarp_amt
[0],
163 sizeof(aarp_amt_array
));
167 elapp
->ifThisNode
= elapp
->initial_addr
;
168 probing
= PROBE_DONE
;
170 /* AppleTalk was successfully started up. Send event with node and net. */
171 atalk_post_msg(elapp
->aa_ifp
, KEV_ATALK_ENABLED
, &(elapp
->ifThisNode
), 0);
173 /* Set global flag */
174 at_state
.flags
|= AT_ST_STARTED
;
179 /****************************************************************************
183 * (1) The caller must take care of freeing the real storage (gbuf)
184 * (2) The incoming packet is of the form {802.3, 802.2, aarp}.
186 ****************************************************************************/
187 int aarp_rcv_pkt(pkt
, elapp
)
191 switch (ntohs(pkt
->aarp_cmd
)) {
193 return (aarp_req_cmd_in (pkt
, elapp
));
195 return (aarp_resp_cmd_in (pkt
, elapp
));
197 return (aarp_probe_cmd_in (pkt
, elapp
));
203 /****************************************************************************
206 ****************************************************************************/
207 StaticProc
int aarp_req_cmd_in (pkt
, elapp
)
212 kprintf("aarp_req_cmd_in: ifThisNode=%d:%d srcNode=%d:%d dstNode=%d:%d\n",
213 elapp->ifThisNode.s_net,
214 elapp->ifThisNode.s_node,
215 NET_VALUE(pkt->src_at_addr.atalk_net),
216 pkt->src_at_addr.atalk_node,
217 NET_VALUE(pkt->dest_at_addr.atalk_net),
218 pkt->dest_at_addr.atalk_node);
220 if ((probing
== PROBE_DONE
) &&
221 (NET_VALUE(pkt
->dest_at_addr
.atalk_net
) == elapp
->ifThisNode
.s_net
) &&
222 (pkt
->dest_at_addr
.atalk_node
== elapp
->ifThisNode
.s_node
)) {
223 if (aarp_send_resp(elapp
, pkt
) == -1)
226 /* now to glean some info */
227 aarp_glean_info(pkt
, elapp
);
233 /****************************************************************************
236 ****************************************************************************/
237 StaticProc
int aarp_resp_cmd_in (pkt
, elapp
)
241 register aarp_amt_t
*amt_ptr
;
245 case PROBE_TENTATIVE
:
246 if ((NET_VALUE(pkt
->src_at_addr
.atalk_net
) ==
247 probe_cb
.elapp
->initial_addr
.s_net
) &&
248 (pkt
->src_at_addr
.atalk_node
==
249 probe_cb
.elapp
->initial_addr
.s_node
)) {
251 /* this is a response to AARP_PROBE_CMD. There's
252 * someone out there with the address we desire
255 untimeout(aarp_sched_probe
, 0);
256 probe_cb
.no_of_retries
= 0;
257 aarp_get_next_node(probe_cb
.elapp
);
260 if (no_of_nodes_tried
== AARP_MAX_NODES_TRIED
) {
261 aarp_get_rand_net(probe_cb
.elapp
);
262 aarp_get_rand_node(probe_cb
.elapp
);
263 no_of_nodes_tried
= 0;
266 if (no_of_nets_tried
== AARP_MAX_NETS_TRIED
) {
267 /* We have tried enough nodes and nets, give up.
269 probe_cb
.error
= EADDRNOTAVAIL
;
270 AARPwakeup(&probe_cb
);
273 if (aarp_send_probe() == -1) {
274 /* expecting aarp_send_probe to fill in
277 AARPwakeup(&probe_cb
);
281 /* hmmmm! got a response packet while still probing
282 * for AT address and the AT dest address doesn't
284 * What should I do here?? kkkkkkkkk
291 AMT_LOOK(amt_ptr
, pkt
->src_at_addr
, elapp
)
295 untimeout(aarp_sched_req
, amt_ptr
);
299 if (amt_ptr
->m
== NULL
) {
300 /* this may be because of a belated response to
301 * aarp reaquest. Based on an earlier response, we
302 * might have already sent the packet out, so
303 * there's nothing to send now. This is okay, no
308 amt_ptr
->dest_addr
= pkt
->src_addr
;
309 if (FDDI_OR_TOKENRING(elapp
->aa_ifp
->if_type
))
310 ddp_bit_reverse(&amt_ptr
->dest_addr
);
313 pat_output(amt_ptr
->elapp
, m
,
314 (unsigned char *)&amt_ptr
->dest_addr
, 0);
317 /* probing in a weird state?? */
325 /****************************************************************************
326 * aarp_probe_cmd_in()
328 ****************************************************************************/
329 StaticProc
int aarp_probe_cmd_in (pkt
, elapp
)
330 register aarp_pkt_t
*pkt
;
333 register aarp_amt_t
*amt_ptr
;
336 case PROBE_TENTATIVE
:
337 if ((elapp
== probe_cb
.elapp
) &&
338 (NET_VALUE(pkt
->src_at_addr
.atalk_net
) ==
339 probe_cb
.elapp
->initial_addr
.s_net
) &&
340 (pkt
->src_at_addr
.atalk_node
==
341 probe_cb
.elapp
->initial_addr
.s_node
)) {
342 /* some bozo is probing for address I want... and I
343 * can't tell him to shove off!
345 untimeout(aarp_sched_probe
, 0);
346 probe_cb
.no_of_retries
= 0;
347 aarp_get_next_node(probe_cb
.elapp
);
350 if (no_of_nodes_tried
== AARP_MAX_NODES_TRIED
) {
351 aarp_get_rand_net(probe_cb
.elapp
);
352 aarp_get_rand_node(probe_cb
.elapp
);
353 no_of_nodes_tried
= 0;
356 if (no_of_nets_tried
== AARP_MAX_NETS_TRIED
) {
357 /* We have tried enough nodes and nets, give up.
359 probe_cb
.error
= EADDRNOTAVAIL
;
360 AARPwakeup(&probe_cb
);
363 if (aarp_send_probe() == -1) {
364 /* expecting aarp_send_probe to fill in
367 AARPwakeup(&probe_cb
);
371 /* somebody's probing... none of my business yet, so
372 * just ignore the packet
379 if ((NET_VALUE(pkt
->src_at_addr
.atalk_net
) == elapp
->ifThisNode
.s_net
) &&
380 (pkt
->src_at_addr
.atalk_node
== elapp
->ifThisNode
.s_node
)) {
381 if (aarp_send_resp(elapp
, pkt
) == -1)
385 AMT_LOOK(amt_ptr
, pkt
->src_at_addr
, elapp
);
388 aarp_delete_amt_info(amt_ptr
);
391 /* probing in a weird state?? */
399 /****************************************************************************
401 ****************************************************************************/
402 int aarp_chk_addr(ddp_hdrp
, elapp
)
406 if ((ddp_hdrp
->dst_node
== elapp
->ifThisNode
.s_node
) &&
407 (NET_VALUE(ddp_hdrp
->dst_net
) == elapp
->ifThisNode
.s_net
)) {
408 return(0); /* exact match in address */
411 if (AARP_BROADCAST(ddp_hdrp
, elapp
)) {
412 return(0); /* some kind of broadcast address */
414 return (AARP_ERR_NOT_OURS
); /* not for us */
419 /****************************************************************************
423 * 1. The message coming in would be of the form {802.3, 802.2, ddp,...}
425 * 2. The message coming in would be freed here if transmission goes
426 * through okay. If an error is returned by aarp_send_data, the caller
427 * can assume that the message is not freed. The exception to
428 * this scenario is the prepended atalk_addr field. This field
429 * will ALWAYS be removed. If the message is dropped,
430 * it's not an "error".
432 * Parameter dest_at_addr must have the net # in network byte order
433 ****************************************************************************/
435 int aarp_send_data(m
, elapp
, dest_at_addr
, loop
)
437 register at_ifaddr_t
*elapp
;
438 struct atalk_addr
*dest_at_addr
; /* net# in network byte order */
439 int loop
; /* if true, loopback broadcasts */
441 register aarp_amt_t
*amt_ptr
;
442 register at_ddp_t
*ddp_hdrp
;
444 struct timeval timenow
;
445 getmicrouptime(&timenow
);
447 if (gbuf_len(m
) <= 0)
448 ddp_hdrp
= (at_ddp_t
*)gbuf_rptr(gbuf_cont(m
));
450 ddp_hdrp
= (at_ddp_t
*)gbuf_rptr(m
);
452 if ((ddp_hdrp
->dst_node
== ddp_hdrp
->src_node
) &&
453 (NET_VALUE(ddp_hdrp
->dst_net
) == NET_VALUE(ddp_hdrp
->src_net
))) {
455 * we're sending to ourselves
456 * so loop it back upstream
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
474 return (pat_output(elapp
, m
,
475 (unsigned char *)&amt_ptr
->dest_addr
, 0));
478 * either this is a packet to be broadcasted, or the address
479 * resolution needs to be done
481 if (AARP_BROADCAST(ddp_hdrp
, elapp
)) {
483 struct etalk_addr
*dest_addr
;
485 dest_addr
= &elapp
->cable_multicast_addr
;
487 newm
= (gbuf_t
*)gbuf_dupm(m
);
489 if ( !(error
= pat_output(elapp
, m
,
490 (unsigned char *)dest_addr
, 0))) {
492 * The message transmitted successfully;
493 * Also loop a copy back up since this
494 * is a broadcast message.
499 ddp_input(newm
, elapp
);
507 NEW_AMT(amt_ptr
, *dest_at_addr
, elapp
)
511 * no non-busy slots available in the cache, so
512 * drop this one and let the upper layer retransmit
518 amt_ptr
->dest_at_addr
= *dest_at_addr
;
519 amt_ptr
->dest_at_addr
.atalk_unused
= 0;
521 getmicrouptime(&timenow
);
522 amt_ptr
->last_time
= timenow
.tv_sec
;
524 amt_ptr
->elapp
= elapp
;
525 amt_ptr
->no_of_retries
= 0;
527 if ((error
= aarp_send_req(amt_ptr
))) {
528 aarp_delete_amt_info(amt_ptr
);
536 /****************************************************************************
540 * The pkt being passed here is only to "look at". It should neither
541 * be used for transmission, nor freed. Its contents also must not be
544 ****************************************************************************/
545 StaticProc
int aarp_send_resp(elapp
, pkt
)
546 register at_ifaddr_t
*elapp
;
549 register aarp_pkt_t
*new_pkt
;
552 if ((m
= gbuf_alloc(AT_WR_OFFSET
+sizeof(aarp_pkt_t
), PRI_MED
)) == NULL
) {
555 gbuf_rinc(m
,AT_WR_OFFSET
);
558 new_pkt
= (aarp_pkt_t
*)gbuf_rptr(m
);
559 aarp_build_pkt(new_pkt
, elapp
);
561 new_pkt
->aarp_cmd
= htons(AARP_RESP_CMD
);
562 new_pkt
->dest_addr
= pkt
->src_addr
;
564 new_pkt
->dest_at_addr
= pkt
->src_at_addr
;
565 new_pkt
->dest_at_addr
.atalk_unused
= 0;
567 ATALK_ASSIGN(new_pkt
->src_at_addr
, elapp
->ifThisNode
.s_net
,
568 elapp
->ifThisNode
.s_node
, 0);
570 gbuf_winc(m
,sizeof(aarp_pkt_t
));
571 if (FDDI_OR_TOKENRING(elapp
->aa_ifp
->if_type
))
572 ddp_bit_reverse(&new_pkt
->dest_addr
);
574 if (pat_output(elapp
, m
, (unsigned char *)&new_pkt
->dest_addr
,
582 /****************************************************************************
585 ****************************************************************************/
587 StaticProc
int aarp_send_req (amt_ptr
)
588 register aarp_amt_t
*amt_ptr
;
590 register aarp_pkt_t
*pkt
;
594 if ((m
= gbuf_alloc(AT_WR_OFFSET
+sizeof(aarp_pkt_t
), PRI_MED
)) == NULL
) {
597 gbuf_rinc(m
,AT_WR_OFFSET
);
600 pkt
= (aarp_pkt_t
*)gbuf_rptr(m
);
601 aarp_build_pkt(pkt
, amt_ptr
->elapp
);
603 pkt
->aarp_cmd
= htons(AARP_REQ_CMD
);
604 pkt
->dest_addr
= et_zeroaddr
;
605 pkt
->dest_at_addr
= amt_ptr
->dest_at_addr
;
606 pkt
->dest_at_addr
.atalk_unused
= 0;
607 ATALK_ASSIGN(pkt
->src_at_addr
, amt_ptr
->elapp
->ifThisNode
.s_net
,
608 amt_ptr
->elapp
->ifThisNode
.s_node
, 0);
609 gbuf_winc(m
,sizeof(aarp_pkt_t
));
611 amt_ptr
->no_of_retries
++;
612 timeout(aarp_sched_req
, amt_ptr
, AARP_REQ_TIMER_INT
);
614 error
= pat_output(amt_ptr
->elapp
, m
,
615 (unsigned char *)&amt_ptr
->elapp
->cable_multicast_addr
, AARP_AT_TYPE
);
618 untimeout(aarp_sched_req
, amt_ptr
);
628 /****************************************************************************
631 ****************************************************************************/
632 StaticProc
int aarp_send_probe()
634 register aarp_pkt_t
*pkt
;
637 if ((m
= gbuf_alloc(AT_WR_OFFSET
+sizeof(aarp_pkt_t
), PRI_MED
)) == NULL
) {
638 probe_cb
.error
= ENOBUFS
;
641 gbuf_rinc(m
,AT_WR_OFFSET
);
643 pkt
= (aarp_pkt_t
*)gbuf_rptr(m
);
644 aarp_build_pkt(pkt
, probe_cb
.elapp
);
646 pkt
->aarp_cmd
= htons(AARP_PROBE_CMD
);
647 pkt
->dest_addr
= et_zeroaddr
;
649 ATALK_ASSIGN(pkt
->src_at_addr
, probe_cb
.elapp
->initial_addr
.s_net
,
650 probe_cb
.elapp
->initial_addr
.s_node
, 0);
652 ATALK_ASSIGN(pkt
->dest_at_addr
, probe_cb
.elapp
->initial_addr
.s_net
,
653 probe_cb
.elapp
->initial_addr
.s_node
, 0);
655 gbuf_winc(m
,sizeof(aarp_pkt_t
));
657 probe_cb
.error
= pat_output(probe_cb
.elapp
, m
,
658 (unsigned char *)&probe_cb
.elapp
->cable_multicast_addr
, AARP_AT_TYPE
);
659 if (probe_cb
.error
) {
663 probing
= PROBE_TENTATIVE
;
664 probe_cb
.no_of_retries
++;
665 timeout(aarp_sched_probe
, 0, AARP_PROBE_TIMER_INT
);
672 /****************************************************************************
675 ****************************************************************************/
677 StaticProc aarp_amt_t
*aarp_lru_entry(at
)
678 register aarp_amt_t
*at
;
680 register aarp_amt_t
*at_ret
;
685 for (i
= 1, at
++; i
< AMT_BSIZ
; i
++, at
++) {
686 if (at
->last_time
< at_ret
->last_time
&& (at
->m
== NULL
))
694 /****************************************************************************
697 ****************************************************************************/
699 StaticProc
int aarp_glean_info(pkt
, elapp
)
700 register aarp_pkt_t
*pkt
;
703 register aarp_amt_t
*amt_ptr
;
705 AMT_LOOK(amt_ptr
, pkt
->src_at_addr
, elapp
);
707 if (amt_ptr
== NULL
) {
709 * amt entry for this address doesn't exist, add it to the cache
711 NEW_AMT(amt_ptr
, pkt
->src_at_addr
,elapp
);
714 return(0); /* no non-busy slots available in the cache */
715 amt_ptr
->dest_at_addr
= pkt
->src_at_addr
;
716 amt_ptr
->dest_at_addr
.atalk_unused
= 0;
718 amt_ptr
->last_time
= (int)random();
721 * update the ethernet address
724 amt_ptr
->dest_addr
= pkt
->src_addr
;
725 if (FDDI_OR_TOKENRING(elapp
->aa_ifp
->if_type
))
726 ddp_bit_reverse(&amt_ptr
->dest_addr
);
731 /****************************************************************************
732 * aarp_delete_amt_info()
734 ****************************************************************************/
736 StaticProc
int aarp_delete_amt_info(amt_ptr
)
737 register aarp_amt_t
*amt_ptr
;
740 amt_ptr
->last_time
= 0;
741 ATALK_ASSIGN(amt_ptr
->dest_at_addr
, 0, 0, 0);
742 amt_ptr
->no_of_retries
= 0;
754 /****************************************************************************
757 ****************************************************************************/
759 void aarp_sched_probe(void *arg
)
764 if (probe_cb
.elapp
->aa_ifp
!= 0 &&
765 probe_cb
.no_of_retries
!= AARP_MAX_PROBE_RETRIES
) {
766 if (aarp_send_probe() == -1)
767 AARPwakeup(&probe_cb
);
770 AARPwakeup(&probe_cb
);
778 /****************************************************************************
781 ****************************************************************************/
783 StaticProc
void aarp_build_pkt(pkt
, elapp
)
784 register aarp_pkt_t
*pkt
;
787 pkt
->hardware_type
= htons(AARP_ETHER_HW_TYPE
);
788 pkt
->stack_type
= htons(AARP_AT_PROTO
);
789 pkt
->hw_addr_len
= ETHERNET_ADDR_LEN
;
790 pkt
->stack_addr_len
= AARP_AT_ADDR_LEN
;
791 bcopy(elapp
->xaddr
, pkt
->src_addr
.etalk_addr_octet
, sizeof(elapp
->xaddr
));
792 if (FDDI_OR_TOKENRING(elapp
->aa_ifp
->if_type
))
793 ddp_bit_reverse(pkt
->src_addr
.etalk_addr_octet
);
796 /****************************************************************************
799 ****************************************************************************/
801 StaticProc
void aarp_sched_req(arg
)
805 aarp_amt_t
*amt_ptr
= (aarp_amt_t
*)arg
;
810 * make sure pointer still valid in case interface removed
811 * while trying to acquire the funnel. make sure it points
812 * into one of the amt arrays.
814 for (i
= 0; i
< IF_TOTAL_MAX
; i
++) {
815 if (aarp_table
[i
] == NULL
|| (void *)amt_ptr
< (void *)aarp_table
[i
] ||
816 (void *)amt_ptr
>= (void *)(aarp_table
[i
] + 1))
817 continue; /* no match - try next entry */
820 * found match - pointer is valid
822 if (amt_ptr
->tmo
== 0) {
826 if (amt_ptr
->no_of_retries
< AARP_MAX_REQ_RETRIES
) {
827 if (aarp_send_req(amt_ptr
) == 0) {
832 aarp_delete_amt_info(amt_ptr
);
842 /****************************************************************************
843 * aarp_get_rand_node()
845 ****************************************************************************/
846 StaticProc
int aarp_get_rand_node(elapp
)
849 register u_char node
;
852 * generate a starting node number in the range 1 thru 0xfd.
853 * we use this as the starting probe point for a given net
854 * To generate a different node number each time we call
857 node
= ((u_char
)(random() & 0xff)) % 0xfd + 2;
859 elapp
->initial_addr
.s_node
= node
;
865 StaticProc
int aarp_get_next_node(elapp
)
868 register u_char node
= elapp
->initial_addr
.s_node
;
871 * return the next node number in the range 1 thru 0xfd.
873 node
= (node
== 0xfd) ? (1) : (node
+1);
875 elapp
->initial_addr
.s_node
= node
;
883 /****************************************************************************
884 * aarp_get_rand_net()
886 ****************************************************************************/
887 StaticProc
int aarp_get_rand_net(elapp
)
888 register at_ifaddr_t
*elapp
;
890 register at_net_al last_net
, new_net
;
892 if (elapp
->ifThisCableStart
) {
893 last_net
= elapp
->initial_addr
.s_net
;
895 * the range of network numbers valid for this
896 * cable is known. Try to choose a number from
899 new_net
= ((at_net_al
)random() & 0xffff);
900 /* two-byte random number generated... now fit it in
901 * the prescribed range
903 new_net
= new_net
% (unsigned) (elapp
->ifThisCableEnd
-
904 elapp
->ifThisCableStart
+ 1)
905 + elapp
->ifThisCableStart
;
907 if (new_net
== last_net
) {
908 if (new_net
== elapp
->ifThisCableEnd
)
909 new_net
= elapp
->ifThisCableStart
;
913 elapp
->initial_addr
.s_net
= new_net
;
915 /* The range of valid network numbers for this cable
916 * is not known... choose a network number from
919 last_net
= (elapp
->initial_addr
.s_net
& 0x00ff);
920 new_net
= (at_net_al
)random() & 0x00ff;
922 if (new_net
== last_net
)
926 elapp
->initial_addr
.s_net
= (DDP_STARTUP_LOW
| new_net
);
932 int getAarpTableSize(elapId
)
933 int elapId
; /* elap_specifics array index (should be
934 * changed when we add a non-ethernet type
935 * of I/F to the mix. Unused for now.
941 int getPhysAddrSize(elapId
)
942 int elapId
; /* elap_specifics array index (should be
943 * changed when we add a non-ethernet type
944 * of I/F to the mix. Unused for now.
947 return(ETHERNET_ADDR_LEN
);
950 #define ENTRY_SIZE sizeof(struct atalk_addr) + sizeof(struct etalk_addr)
952 snmpAarpEnt_t
*getAarp(elapId
)
953 int *elapId
; /* I/F table to retrieve & table
954 size entries on return */
956 /* gets aarp table for specified interface and builds
957 a table in SNMP expected format. Returns pointer to said
958 table and sets elapId to byte size of used portion of table
963 static snmpAarpEnt_t snmp
[AMTSIZE
];
964 snmpAarpEnt_t
*snmpp
;
965 struct atalk_addr addr
;
969 if (*elapId
<0 || *elapId
>= IF_TOTAL_MAX
)
973 for (i
=0, amtp
= &(aarp_table
[*elapId
]->et_aarp_amt
[0]), snmpp
= snmp
;
974 i
< AMTSIZE
; i
++,amtp
++) {
976 /* last_time will be 0 if entry was never used */
977 if (amtp
->last_time
) {
978 /* copy just network & mac address.
979 * For speed, we assume that the atalk_addr
980 * & etalk_addr positions in the aarp_amt_t struct
981 * has not changed and copy both at once
983 addr
.atalk_unused
= 0;
984 tmp_net
= UAS_VALUE(amtp
->dest_at_addr
.atalk_net
);
985 NET_ASSIGN(addr
.atalk_net
, tmp_net
);
986 addr
.atalk_node
= amtp
->dest_at_addr
.atalk_node
;
987 bcopy(&addr
, &snmpp
->ap_ddpAddr
, ENTRY_SIZE
);
996 /*#endif *//* COMMENTED_OUT */