]>
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_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
22 /* Copyright (c) 1988, 1989, 1997, 1998 Apple Computer, Inc.
24 * Modified for MP, 1996 by Tuyen Nguyen
25 * Modified, March 17, 1997 by Tuyen Nguyen for MacOSX.
28 /* at_aarp.c: 2.0, 1.17; 10/4/93; Apple Computer, Inc. */;
30 /* This file is at_aarp.c and it contains all the routines used by AARP. This
31 * is part of the LAP layer.
34 #include <sys/errno.h>
35 #include <sys/types.h>
36 #include <sys/param.h>
37 #include <machine/spl.h>
38 #include <sys/systm.h>
39 #include <sys/kernel.h>
41 #include <sys/filedesc.h>
42 #include <sys/fcntl.h>
44 #include <sys/ioctl.h>
45 #include <sys/malloc.h>
46 #include <sys/socket.h>
47 #include <sys/socketvar.h>
50 #include <net/if_types.h>
52 #include <netat/sysglue.h>
53 #include <netat/appletalk.h>
54 #include <netat/ddp.h>
55 #include <netat/at_snmp.h>
56 #include <netat/at_pcb.h>
57 #include <netat/at_var.h>
58 #include <netat/at_aarp.h>
59 #include <netat/debug.h>
62 /* Following two variables are used to keep track of how many dynamic addresses
63 * we have tried out at startup.
65 int no_of_nodes_tried
; /* no of node addresses we've tried
66 * so far, within a network number
68 int no_of_nets_tried
; /* no. of network numbers tried
71 struct etalk_addr et_zeroaddr
= {
75 aarp_amt_array
*aarp_table
[IF_TOTAL_MAX
];
77 int aarp_init1(), aarp_init2();
79 int aarp_sched_probe();
81 StaticProc
int aarp_req_cmd_in();
82 StaticProc
int aarp_resp_cmd_in();
83 StaticProc
int aarp_probe_cmd_in();
84 StaticProc
int aarp_send_resp();
85 StaticProc
int aarp_send_req();
86 StaticProc
int aarp_send_probe();
87 StaticProc aarp_amt_t
*aarp_lru_entry();
88 StaticProc
int aarp_glean_info();
89 StaticProc
int aarp_delete_amt_info();
90 StaticProc
void aarp_build_pkt();
91 StaticProc
int aarp_sched_req();
92 StaticProc
int aarp_get_rand_node();
93 StaticProc
int aarp_get_next_node();
94 StaticProc
int aarp_get_rand_net();
97 extern void AARPwakeup(aarp_amt_t
*);
98 extern int pat_output(at_ifaddr_t
*, gbuf_t
*, unsigned char *, int);
100 /****************************************************************************
103 ****************************************************************************/
105 int aarp_init1(elapp
)
106 register at_ifaddr_t
*elapp
;
108 elapp
->ifThisNode
.s_net
= 0;
109 elapp
->ifThisNode
.s_node
= 0;
111 if (probing
!= PROBE_TENTATIVE
) /* How do I set the initial probe */
112 probing
= PROBE_IDLE
; /* state ???*/
114 dPrintf(D_M_AARP
,D_L_ERROR
,
115 ("aarp_init: error :probing == PROBE_TENTATIVE\n"));
119 /* pick a random addr or start with what we have from initial_node addr */
120 if (elapp
->initial_addr
.s_net
== 0 && elapp
->initial_addr
.s_node
== 0) {
121 dPrintf(D_M_AARP
, D_L_INFO
,
122 ("aarp_init: pick up a new node number\n"));
123 aarp_get_rand_node(elapp
);
124 aarp_get_rand_net(elapp
);
126 probe_cb
.elapp
= elapp
;
127 probe_cb
.no_of_retries
= 0;
130 no_of_nodes_tried
= 0; /* haven't tried any addresses yet */
131 no_of_nets_tried
= 0;
133 if (aarp_send_probe() == -1) {
134 probing
= PROBE_IDLE
; /* not probing any more */
135 dPrintf(D_M_AARP
, D_L_ERROR
,
136 ("aarp_init: aarp_send_probe returns error\n"));
142 int aarp_init2(elapp
)
143 register at_ifaddr_t
*elapp
;
145 if (probe_cb
.error
!= 0) {
146 probing
= PROBE_IDLE
; /* not probing any more */
147 dPrintf(D_M_AARP
, D_L_ERROR
,
148 ("aarp_init: probe_cb.error creates error =%d\n",
153 if (aarp_table
[elapp
->ifPort
])
154 bzero ((caddr_t
)&aarp_table
[elapp
->ifPort
]->et_aarp_amt
[0],
155 sizeof(aarp_amt_array
));
159 elapp
->ifThisNode
= elapp
->initial_addr
;
160 probing
= PROBE_DONE
;
165 /****************************************************************************
169 * (1) The caller must take care of freeing the real storage (gbuf)
170 * (2) The incoming packet is of the form {802.3, 802.2, aarp}.
172 ****************************************************************************/
173 int aarp_rcv_pkt(pkt
, elapp
)
177 switch (pkt
->aarp_cmd
) {
179 return (aarp_req_cmd_in (pkt
, elapp
));
181 return (aarp_resp_cmd_in (pkt
, elapp
));
183 return (aarp_probe_cmd_in (pkt
, elapp
));
189 /****************************************************************************
192 ****************************************************************************/
193 StaticProc
int aarp_req_cmd_in (pkt
, elapp
)
198 kprintf("aarp_req_cmd_in: ifThisNode=%d:%d srcNode=%d:%d dstNode=%d:%d\n",
199 elapp->ifThisNode.s_net,
200 elapp->ifThisNode.s_node,
201 NET_VALUE(pkt->src_at_addr.atalk_net),
202 pkt->src_at_addr.atalk_node,
203 NET_VALUE(pkt->dest_at_addr.atalk_net),
204 pkt->dest_at_addr.atalk_node);
206 if ((probing
== PROBE_DONE
) &&
207 (NET_VALUE(pkt
->dest_at_addr
.atalk_net
) == elapp
->ifThisNode
.s_net
) &&
208 (pkt
->dest_at_addr
.atalk_node
== elapp
->ifThisNode
.s_node
)) {
209 if (aarp_send_resp(elapp
, pkt
) == -1)
212 /* now to glean some info */
213 aarp_glean_info(pkt
, elapp
);
219 /****************************************************************************
222 ****************************************************************************/
223 StaticProc
int aarp_resp_cmd_in (pkt
, elapp
)
227 register aarp_amt_t
*amt_ptr
;
231 case PROBE_TENTATIVE
:
232 if ((NET_VALUE(pkt
->src_at_addr
.atalk_net
) ==
233 probe_cb
.elapp
->initial_addr
.s_net
) &&
234 (pkt
->src_at_addr
.atalk_node
==
235 probe_cb
.elapp
->initial_addr
.s_node
)) {
237 /* this is a response to AARP_PROBE_CMD. There's
238 * someone out there with the address we desire
241 untimeout(aarp_sched_probe
, 0);
242 probe_cb
.no_of_retries
= 0;
243 aarp_get_next_node(probe_cb
.elapp
);
246 if (no_of_nodes_tried
== AARP_MAX_NODES_TRIED
) {
247 aarp_get_rand_net(probe_cb
.elapp
);
248 aarp_get_rand_node(probe_cb
.elapp
);
249 no_of_nodes_tried
= 0;
252 if (no_of_nets_tried
== AARP_MAX_NETS_TRIED
) {
253 /* We have tried enough nodes and nets, give up.
255 probe_cb
.error
= EADDRNOTAVAIL
;
256 AARPwakeup(&probe_cb
);
259 if (aarp_send_probe() == -1) {
260 /* expecting aarp_send_probe to fill in
263 AARPwakeup(&probe_cb
);
267 /* hmmmm! got a response packet while still probing
268 * for AT address and the AT dest address doesn't
270 * What should I do here?? kkkkkkkkk
277 AMT_LOOK(amt_ptr
, pkt
->src_at_addr
, elapp
);
281 untimeout(aarp_sched_req
, amt_ptr
);
285 if (amt_ptr
->m
== NULL
) {
286 /* this may be because of a belated response to
287 * aarp reaquest. Based on an earlier response, we
288 * might have already sent the packet out, so
289 * there's nothing to send now. This is okay, no
294 amt_ptr
->dest_addr
= pkt
->src_addr
;
295 if (FDDI_OR_TOKENRING(elapp
->aa_ifp
->if_type
))
296 ddp_bit_reverse(&amt_ptr
->dest_addr
);
299 pat_output(amt_ptr
->elapp
, m
,
300 (unsigned char *)&amt_ptr
->dest_addr
, 0);
303 /* probing in a weird state?? */
311 /****************************************************************************
312 * aarp_probe_cmd_in()
314 ****************************************************************************/
315 StaticProc
int aarp_probe_cmd_in (pkt
, elapp
)
316 register aarp_pkt_t
*pkt
;
319 register aarp_amt_t
*amt_ptr
;
322 case PROBE_TENTATIVE
:
323 if ((elapp
== probe_cb
.elapp
) &&
324 (NET_VALUE(pkt
->src_at_addr
.atalk_net
) ==
325 probe_cb
.elapp
->initial_addr
.s_net
) &&
326 (pkt
->src_at_addr
.atalk_node
==
327 probe_cb
.elapp
->initial_addr
.s_node
)) {
328 /* some bozo is probing for address I want... and I
329 * can't tell him to shove off!
331 untimeout(aarp_sched_probe
, 0);
332 probe_cb
.no_of_retries
= 0;
333 aarp_get_next_node(probe_cb
.elapp
);
336 if (no_of_nodes_tried
== AARP_MAX_NODES_TRIED
) {
337 aarp_get_rand_net(probe_cb
.elapp
);
338 aarp_get_rand_node(probe_cb
.elapp
);
339 no_of_nodes_tried
= 0;
342 if (no_of_nets_tried
== AARP_MAX_NETS_TRIED
) {
343 /* We have tried enough nodes and nets, give up.
345 probe_cb
.error
= EADDRNOTAVAIL
;
346 AARPwakeup(&probe_cb
);
349 if (aarp_send_probe() == -1) {
350 /* expecting aarp_send_probe to fill in
353 AARPwakeup(&probe_cb
);
357 /* somebody's probing... none of my business yet, so
358 * just ignore the packet
365 if ((NET_VALUE(pkt
->src_at_addr
.atalk_net
) == elapp
->ifThisNode
.s_net
) &&
366 (pkt
->src_at_addr
.atalk_node
== elapp
->ifThisNode
.s_node
)) {
367 if (aarp_send_resp(elapp
, pkt
) == -1)
371 AMT_LOOK(amt_ptr
, pkt
->src_at_addr
, elapp
);
374 aarp_delete_amt_info(amt_ptr
);
377 /* probing in a weird state?? */
385 /****************************************************************************
387 ****************************************************************************/
388 int aarp_chk_addr(ddp_hdrp
, elapp
)
392 if ((ddp_hdrp
->dst_node
== elapp
->ifThisNode
.s_node
) &&
393 (NET_VALUE(ddp_hdrp
->dst_net
) == elapp
->ifThisNode
.s_net
)) {
394 return(0); /* exact match in address */
397 if (AARP_BROADCAST(ddp_hdrp
, elapp
)) {
398 return(0); /* some kind of broadcast address */
400 return (AARP_ERR_NOT_OURS
); /* not for us */
405 /****************************************************************************
409 * 1. The message coming in would be of the form {802.3, 802.2, ddp,...}
411 * 2. The message coming in would be freed here if transmission goes
412 * through okay. If an error is returned by aarp_send_data, the caller
413 * can assume that the message is not freed. The exception to
414 * this scenario is the prepended atalk_addr field. This field
415 * will ALWAYS be removed. If the message is dropped,
416 * it's not an "error".
418 ****************************************************************************/
420 int aarp_send_data(m
, elapp
, dest_at_addr
, loop
)
422 register at_ifaddr_t
*elapp
;
423 struct atalk_addr
*dest_at_addr
;
424 int loop
; /* if true, loopback broadcasts */
426 register aarp_amt_t
*amt_ptr
;
427 register at_ddp_t
*ddp_hdrp
;
431 if (gbuf_len(m
) <= 0)
432 ddp_hdrp
= (at_ddp_t
*)gbuf_rptr(gbuf_cont(m
));
434 ddp_hdrp
= (at_ddp_t
*)gbuf_rptr(m
);
436 if ((ddp_hdrp
->dst_node
== ddp_hdrp
->src_node
) &&
437 (NET_VALUE(ddp_hdrp
->dst_net
) == NET_VALUE(ddp_hdrp
->src_net
))) {
439 * we're sending to ourselves
440 * so loop it back upstream
445 ATDISABLE(s
, arpinp_lock
);
446 AMT_LOOK(amt_ptr
, *dest_at_addr
, elapp
);
452 * there's already a packet awaiting transmission, so
453 * drop this one and let the upper layer retransmit
456 ATENABLE(s
, arpinp_lock
);
460 ATENABLE(s
, arpinp_lock
);
461 return (pat_output(elapp
, m
,
462 (unsigned char *)&amt_ptr
->dest_addr
, 0));
465 * either this is a packet to be broadcasted, or the address
466 * resolution needs to be done
468 if (AARP_BROADCAST(ddp_hdrp
, elapp
)) {
470 struct etalk_addr
*dest_addr
;
472 ATENABLE(s
, arpinp_lock
);
473 dest_addr
= &elapp
->cable_multicast_addr
;
475 newm
= (gbuf_t
*)gbuf_dupm(m
);
477 if ( !(error
= pat_output(elapp
, m
,
478 (unsigned char *)dest_addr
, 0))) {
480 * The message transmitted successfully;
481 * Also loop a copy back up since this
482 * is a broadcast message.
487 ddp_input(newm
, elapp
);
495 NEW_AMT(amt_ptr
, *dest_at_addr
,elapp
);
499 * no non-busy slots available in the cache, so
500 * drop this one and let the upper layer retransmit
503 ATENABLE(s
, arpinp_lock
);
507 amt_ptr
->dest_at_addr
= *dest_at_addr
;
508 amt_ptr
->dest_at_addr
.atalk_unused
= 0;
510 amt_ptr
->last_time
= time
.tv_sec
;
512 amt_ptr
->elapp
= elapp
;
513 amt_ptr
->no_of_retries
= 0;
514 ATENABLE(s
, arpinp_lock
);
516 if ((error
= aarp_send_req(amt_ptr
))) {
517 aarp_delete_amt_info(amt_ptr
);
525 /****************************************************************************
529 * The pkt being passed here is only to "look at". It should neither
530 * be used for transmission, nor freed. Its contents also must not be
533 ****************************************************************************/
534 StaticProc
int aarp_send_resp(elapp
, pkt
)
535 register at_ifaddr_t
*elapp
;
538 register aarp_pkt_t
*new_pkt
;
541 if ((m
= gbuf_alloc(AT_WR_OFFSET
+sizeof(aarp_pkt_t
), PRI_MED
)) == NULL
) {
544 gbuf_rinc(m
,AT_WR_OFFSET
);
547 new_pkt
= (aarp_pkt_t
*)gbuf_rptr(m
);
548 aarp_build_pkt(new_pkt
, elapp
);
550 new_pkt
->aarp_cmd
= AARP_RESP_CMD
;
551 new_pkt
->dest_addr
= pkt
->src_addr
;
553 new_pkt
->dest_at_addr
= pkt
->src_at_addr
;
554 new_pkt
->dest_at_addr
.atalk_unused
= 0;
556 ATALK_ASSIGN(new_pkt
->src_at_addr
, elapp
->ifThisNode
.s_net
,
557 elapp
->ifThisNode
.s_node
, 0);
559 gbuf_winc(m
,sizeof(aarp_pkt_t
));
560 if (FDDI_OR_TOKENRING(elapp
->aa_ifp
->if_type
))
561 ddp_bit_reverse(&new_pkt
->dest_addr
);
563 if (pat_output(elapp
, m
, (unsigned char *)&new_pkt
->dest_addr
,
571 /****************************************************************************
574 ****************************************************************************/
576 StaticProc
int aarp_send_req (amt_ptr
)
577 register aarp_amt_t
*amt_ptr
;
579 register aarp_pkt_t
*pkt
;
583 if ((m
= gbuf_alloc(AT_WR_OFFSET
+sizeof(aarp_pkt_t
), PRI_MED
)) == NULL
) {
586 gbuf_rinc(m
,AT_WR_OFFSET
);
589 pkt
= (aarp_pkt_t
*)gbuf_rptr(m
);
590 aarp_build_pkt(pkt
, amt_ptr
->elapp
);
592 pkt
->aarp_cmd
= AARP_REQ_CMD
;
593 pkt
->dest_addr
= et_zeroaddr
;
594 pkt
->dest_at_addr
= amt_ptr
->dest_at_addr
;
595 pkt
->dest_at_addr
.atalk_unused
= 0;
596 ATALK_ASSIGN(pkt
->src_at_addr
, amt_ptr
->elapp
->ifThisNode
.s_net
,
597 amt_ptr
->elapp
->ifThisNode
.s_node
, 0);
598 gbuf_winc(m
,sizeof(aarp_pkt_t
));
600 amt_ptr
->no_of_retries
++;
601 timeout(aarp_sched_req
, amt_ptr
, AARP_REQ_TIMER_INT
);
603 error
= pat_output(amt_ptr
->elapp
, m
,
604 (unsigned char *)&amt_ptr
->elapp
->cable_multicast_addr
, AARP_AT_TYPE
);
607 untimeout(aarp_sched_req
, amt_ptr
);
617 /****************************************************************************
620 ****************************************************************************/
621 StaticProc
int aarp_send_probe()
623 register aarp_pkt_t
*pkt
;
626 if ((m
= gbuf_alloc(AT_WR_OFFSET
+sizeof(aarp_pkt_t
), PRI_MED
)) == NULL
) {
627 probe_cb
.error
= ENOBUFS
;
630 gbuf_rinc(m
,AT_WR_OFFSET
);
632 pkt
= (aarp_pkt_t
*)gbuf_rptr(m
);
633 aarp_build_pkt(pkt
, probe_cb
.elapp
);
635 pkt
->aarp_cmd
= AARP_PROBE_CMD
;
636 pkt
->dest_addr
= et_zeroaddr
;
638 ATALK_ASSIGN(pkt
->src_at_addr
, probe_cb
.elapp
->initial_addr
.s_net
,
639 probe_cb
.elapp
->initial_addr
.s_node
, 0);
641 ATALK_ASSIGN(pkt
->dest_at_addr
, probe_cb
.elapp
->initial_addr
.s_net
,
642 probe_cb
.elapp
->initial_addr
.s_node
, 0);
644 gbuf_winc(m
,sizeof(aarp_pkt_t
));
646 probe_cb
.error
= pat_output(probe_cb
.elapp
, m
,
647 (unsigned char *)&probe_cb
.elapp
->cable_multicast_addr
, AARP_AT_TYPE
);
648 if (probe_cb
.error
) {
652 probing
= PROBE_TENTATIVE
;
653 probe_cb
.no_of_retries
++;
654 timeout(aarp_sched_probe
, 0, AARP_PROBE_TIMER_INT
);
661 /****************************************************************************
664 ****************************************************************************/
666 StaticProc aarp_amt_t
*aarp_lru_entry(at
)
667 register aarp_amt_t
*at
;
669 register aarp_amt_t
*at_ret
;
674 for (i
= 1, at
++; i
< AMT_BSIZ
; i
++, at
++) {
675 if (at
->last_time
< at_ret
->last_time
&& (at
->m
== NULL
))
683 /****************************************************************************
686 ****************************************************************************/
688 StaticProc
int aarp_glean_info(pkt
, elapp
)
689 register aarp_pkt_t
*pkt
;
692 register aarp_amt_t
*amt_ptr
;
695 ATDISABLE(s
, arpinp_lock
);
696 AMT_LOOK(amt_ptr
, pkt
->src_at_addr
, elapp
);
698 if (amt_ptr
== NULL
) {
700 * amt entry for this address doesn't exist, add it to the cache
702 NEW_AMT(amt_ptr
, pkt
->src_at_addr
,elapp
);
706 ATENABLE(s
, arpinp_lock
);
707 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(&amt_ptr
->dest_addr
);
721 ATENABLE(s
, arpinp_lock
);
726 /****************************************************************************
727 * aarp_delete_amt_info()
729 ****************************************************************************/
731 StaticProc
int aarp_delete_amt_info(amt_ptr
)
732 register aarp_amt_t
*amt_ptr
;
736 ATDISABLE(s
, arpinp_lock
);
737 amt_ptr
->last_time
= 0;
738 ATALK_ASSIGN(amt_ptr
->dest_at_addr
, 0, 0, 0);
739 amt_ptr
->no_of_retries
= 0;
744 ATENABLE(s
, arpinp_lock
);
748 ATENABLE(s
, arpinp_lock
);
754 /****************************************************************************
757 ****************************************************************************/
759 int aarp_sched_probe()
761 boolean_t funnel_state
;
763 funnel_state
= thread_funnel_set(network_flock
, TRUE
);
765 if (probe_cb
.no_of_retries
!= AARP_MAX_PROBE_RETRIES
) {
766 if (aarp_send_probe() == -1)
767 AARPwakeup(&probe_cb
);
770 AARPwakeup(&probe_cb
);
773 (void) thread_funnel_set(network_flock
, FALSE
);
779 /****************************************************************************
782 ****************************************************************************/
784 StaticProc
void aarp_build_pkt(pkt
, elapp
)
785 register aarp_pkt_t
*pkt
;
788 pkt
->hardware_type
= AARP_ETHER_HW_TYPE
;
789 pkt
->stack_type
= AARP_AT_PROTO
;
790 pkt
->hw_addr_len
= ETHERNET_ADDR_LEN
;
791 pkt
->stack_addr_len
= AARP_AT_ADDR_LEN
;
792 bcopy(elapp
->xaddr
, pkt
->src_addr
.etalk_addr_octet
, sizeof(elapp
->xaddr
));
793 if (FDDI_OR_TOKENRING(elapp
->aa_ifp
->if_type
))
794 ddp_bit_reverse(pkt
->src_addr
.etalk_addr_octet
);
797 /****************************************************************************
800 ****************************************************************************/
802 StaticProc
int aarp_sched_req(amt_ptr
)
803 register aarp_amt_t
*amt_ptr
;
806 boolean_t funnel_state
;
808 funnel_state
= thread_funnel_set(network_flock
, TRUE
);
810 ATDISABLE(s
, arpinp_lock
);
811 if (amt_ptr
->tmo
== 0)
813 ATENABLE(s
, arpinp_lock
);
814 (void) thread_funnel_set(network_flock
, FALSE
);
817 if (amt_ptr
->no_of_retries
< AARP_MAX_REQ_RETRIES
) {
818 ATENABLE(s
, arpinp_lock
);
819 if (aarp_send_req(amt_ptr
) == 0) {
820 (void) thread_funnel_set(network_flock
, FALSE
);
823 ATDISABLE(s
, arpinp_lock
);
825 ATENABLE(s
, arpinp_lock
);
826 aarp_delete_amt_info(amt_ptr
);
828 (void) thread_funnel_set(network_flock
, FALSE
);
835 /****************************************************************************
836 * aarp_get_rand_node()
838 ****************************************************************************/
839 StaticProc
int aarp_get_rand_node(elapp
)
842 register u_char node
;
845 * generate a starting node number in the range 1 thru 0xfd.
846 * we use this as the starting probe point for a given net
847 * To generate a different node number each time we call
850 node
= ((u_char
)(random() & 0xff)) % 0xfd + 2;
852 elapp
->initial_addr
.s_node
= node
;
858 StaticProc
int aarp_get_next_node(elapp
)
861 register u_char node
= elapp
->initial_addr
.s_node
;
864 * return the next node number in the range 1 thru 0xfd.
866 node
= (node
== 0xfd) ? (1) : (node
+1);
868 elapp
->initial_addr
.s_node
= node
;
876 /****************************************************************************
877 * aarp_get_rand_net()
879 ****************************************************************************/
880 StaticProc
int aarp_get_rand_net(elapp
)
881 register at_ifaddr_t
*elapp
;
883 register at_net_al last_net
, new_net
;
885 if (elapp
->ifThisCableStart
) {
886 last_net
= elapp
->initial_addr
.s_net
;
888 * the range of network numbers valid for this
889 * cable is known. Try to choose a number from
892 new_net
= ((at_net_al
)random() & 0xffff);
893 /* two-byte random number generated... now fit it in
894 * the prescribed range
896 new_net
= new_net
% (unsigned) (elapp
->ifThisCableEnd
-
897 elapp
->ifThisCableStart
+ 1)
898 + elapp
->ifThisCableStart
;
900 if (new_net
== last_net
) {
901 if (new_net
== elapp
->ifThisCableEnd
)
902 new_net
= elapp
->ifThisCableStart
;
906 elapp
->initial_addr
.s_net
= new_net
;
908 /* The range of valid network numbers for this cable
909 * is not known... choose a network number from
912 last_net
= (elapp
->initial_addr
.s_net
& 0x00ff);
913 new_net
= (at_net_al
)random() & 0x00ff;
915 if (new_net
== last_net
)
919 elapp
->initial_addr
.s_net
= (DDP_STARTUP_LOW
| new_net
);
925 int getAarpTableSize(elapId
)
926 int elapId
; /* elap_specifics array index (should be
927 * changed when we add a non-ethernet type
928 * of I/F to the mix. Unused for now.
934 int getPhysAddrSize(elapId
)
935 int elapId
; /* elap_specifics array index (should be
936 * changed when we add a non-ethernet type
937 * of I/F to the mix. Unused for now.
940 return(ETHERNET_ADDR_LEN
);
943 #define ENTRY_SIZE sizeof(struct atalk_addr) + sizeof(struct etalk_addr)
945 snmpAarpEnt_t
*getAarp(elapId
)
946 int *elapId
; /* I/F table to retrieve & table
947 size entries on return */
949 /* gets aarp table for specified interface and builds
950 a table in SNMP expected format. Returns pointer to said
951 table and sets elapId to byte size of used portion of table
956 static snmpAarpEnt_t snmp
[AMTSIZE
];
957 snmpAarpEnt_t
*snmpp
;
960 if (*elapId
<0 || *elapId
>= IF_TOTAL_MAX
)
964 for (i
=0, amtp
= &(aarp_table
[*elapId
]->et_aarp_amt
[0]), snmpp
= snmp
;
965 i
< AMTSIZE
; i
++,amtp
++) {
967 /* last_time will be 0 if entry was never used */
968 if (amtp
->last_time
) {
969 /* copy just network & mac address.
970 * For speed, we assume that the atalk_addr
971 * & etalk_addr positions in the aarp_amt_t struct
972 * has not changed and copy both at once
974 bcopy(&amtp
->dest_at_addr
, &snmpp
->ap_ddpAddr
, ENTRY_SIZE
);
983 /*#endif *//* COMMENTED_OUT */