]>
git.saurik.com Git - apple/xnu.git/blob - bsd/netat/ddp_rtmptable.c
933c07649ca45ecb75b7a570d77d930f13ae8c31
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 /*----------------------------------------------------------------------------
24 * RTMP & ZIP routing tables access routines
26 * This code implement b-tree search and manipulation of
27 * of the RTMP routing table and ZIP zone table.
29 * The RTMP routing table is a data block divided in several routing
30 * entries sorted during insertion in a b-tree form. We use a table and
31 * not dynamically allocated entries because it allow us to scan the whole
32 * table when RTMP packets are generated. The routing table entries are sorted
33 * by there NetStop value (because non extended nets have a NetStart value of
34 * zero. From any point in the tree, the left side contains Network ranges
35 * smaller or equal to the current Node, and the right tree points to higher
36 * values network ranges.
39 * 0.01 3/16/94 LD Creation
40 * Modified for MP, 1996 by Tuyen Nguyen
41 * Modified, March 17, 1997 by Tuyen Nguyen for MacOSX.
43 *----------------------------------------------------------------------------
45 * Copyright (c) 1994, 1996, 1997, 1998 Apple Computer, Inc.
48 #include <sys/errno.h>
49 #include <sys/types.h>
50 #include <sys/param.h>
51 #include <machine/spl.h>
52 #include <sys/systm.h>
53 #include <sys/kernel.h>
55 #include <sys/filedesc.h>
56 #include <sys/fcntl.h>
58 #include <sys/ioctl.h>
59 #include <sys/malloc.h>
60 #include <sys/socket.h>
61 #include <sys/socketvar.h>
64 #include <net/if_types.h>
66 #include <netat/sysglue.h>
67 #include <netat/appletalk.h>
68 #include <netat/at_var.h>
69 #include <netat/ddp.h>
70 #include <netat/rtmp.h>
71 #include <netat/at_pcb.h>
72 #include <netat/zip.h>
73 #include <netat/routing_tables.h>
74 #include <netat/at_snmp.h>
75 #include <netat/debug.h>
77 RT_entry
*RT_table_freelist
; /* start of free entry list */
78 RT_entry RT_table_start
; /* start of the actual entry table */
79 RT_entry
*RT_table
; /* the routing table */
80 ZT_entry
*ZT_table
; /* the Zone Information Protocol table */
81 short RT_maxentry
; /* Number of entry in RTMP table */
82 short ZT_maxentry
; /* Number of entry in ZIP table */
84 char errstr
[512]; /* used to display meaningfull router errors*/
86 extern at_ifaddr_t
*ifID_table
[];
87 extern at_ifaddr_t
*ifID_home
;
88 extern snmpStats_t snmpStats
;
90 short ErrorRTMPoverflow
= 0; /* flag if RTMP table is too small for this net */
91 short ErrorZIPoverflow
= 0; /* flag if ZIP table is too small for this net */
94 void getIfUsage( int, at_ifnames_t
*);
97 * This a temporary function : just to display the router error
100 void RouterError(port
, err_number
)
101 short port
, err_number
;
104 switch (err_number
) {
106 case ERTR_SEED_CONFLICT
:
107 dPrintf(D_M_RTMP
, D_L_ERROR
,
108 ("**** RTR Error on port# %d SEED_CONFLICT\n", port
));
111 case ERTR_CABLE_CONFLICT
:
112 dPrintf(D_M_RTMP
, D_L_ERROR
,
113 ("**** RTR Error on port# %d CABLE_CONFLICT\n", port
));
116 case ERTR_RTMP_BAD_VERSION
:
117 dPrintf(D_M_RTMP
, D_L_ERROR
,
118 ("**** RTR Error on port# %d RTMP_BAD_VERSION\n", port
));
121 case ERTR_CABLE_STARTUP
:
122 dPrintf(D_M_RTMP
, D_L_ERROR
,
123 ("**** RTR Error on port# %d RTMP_CABLE_STARTUP\n",
128 dPrintf(D_M_RTMP
, D_L_ERROR
,
129 ("**** RTR Error on port# %d WHAT IN THE WORLD IS THIS ONE? code=%d\n",
133 dPrintf(D_M_RTMP
, D_L_ERROR
, ("Explanation: %s\n", errstr
));
138 * this function just look for a NetNumber in the routing table,
139 * no check is done for the validity of the entry
142 RT_entry
*rt_blookup (NetNumber
)
146 RT_entry
*ptree
= &RT_table_start
;
149 dPrintf(D_M_RTMP_LOW, D_L_ROUTING, ("%s : Lookup for Net=%d\n",
150 "rt_blookup", NetNumber));
154 if (NetNumber
> ptree
->NetStop
) {
156 dPrintf(D_M_RTMP_LOW, D_L_ROUTING, ("%s : Go Right from #%d\n",
157 "rt_blookup", ptree->NextIRNet));
159 ptree
= ptree
->right
;
164 LowEnd
= ptree
->NetStart
;
166 LowEnd
= ptree
->NetStop
;
168 if (NetNumber
< LowEnd
) {
170 dPrintf(D_M_RTMP_LOW, D_L_ROUTING, ("%s : Go Left from #%d\n",
171 "rt_blookup", ptree->NextIRNet));
177 /* we're in the range (either extended or not)
178 * return the entry found.
181 /* dPrintf(D_M_RTMP_LOW, D_L_ROUTING, ("%s : found %04d-%04d Port=%d State=0x%x\n",
182 "rt_blookup", ptree->NetStart, ptree->NetStop, ptree->NetPort,
190 dPrintf(D_M_RTMP_LOW
, D_L_ROUTING
, ("%s : %04d : NOT FOUND\n",
191 "rt_blookup", NetNumber
));
192 return ((RT_entry
*)NULL
);
196 /* Routing table btree insert routine
197 * Uses a RT_entry parameter as the input, the insert is sorted in
198 * the tree on the NetStop field. Provision is made for non extented
199 * net (ie NetStart = 0).
200 * The function returns the element where the new entry was inserted, or
201 * NULL if the insert didn't work. (In this cas there is a problem with
202 * the tree coherency...
207 RT_entry
*rt_binsert (NewEntry
)
210 RT_entry
*ptree
= &RT_table_start
;
212 register at_net_al NetStart
= NewEntry
->NetStart
;
213 register at_net_al NetStop
= NewEntry
->NetStop
;
215 dPrintf(D_M_RTMP_LOW
, D_L_ROUTING
, ("rt_binsert: for Net %d-%d state=x%x NextIR %d:%d\n",
216 NetStart
, NetStop
, NewEntry
->EntryState
,NewEntry
->NextIRNet
, NewEntry
->NextIRNode
));
218 if (ptree
== (RT_entry
*)NULL
) {
220 at_state
.flags
|= AT_ST_RT_CHANGED
;
227 if (NetStop
> ptree
->NetStop
) { /* walk the right sub-tree */
229 ptree
= ptree
->right
;
231 ptree
->right
= NewEntry
;
232 at_state
.flags
|= AT_ST_RT_CHANGED
;
236 else { /* walk the left sub-tree */
240 ptree
->left
= NewEntry
;
241 at_state
.flags
|= AT_ST_RT_CHANGED
;
248 dPrintf(D_M_RTMP
, D_L_WARNING
, ("%s : ERROR NOT INSERTED Net %d-%d\n",
249 "rt_binsert", NetStart
, NetStop
));
250 return ((RT_entry
*)NULL
);
253 RT_entry
*rt_insert(NStop
, NStart
, NxNet
, NxNode
, NtDist
, NtPort
, EntS
)
254 at_net_al NStop
, NStart
, NxNet
;
256 u_char NtDist
, NtPort
, EntS
;
259 if ((New
= RT_table_freelist
)) {
260 RT_table_freelist
= RT_table_freelist
->right
;
262 return ((RT_entry
*)NULL
);
264 New
->NetStop
= NStop
;
265 New
->NetStart
= NStart
;
266 New
->NextIRNet
= NxNet
;
267 New
->NextIRNode
= NxNode
;
268 New
->NetDist
= NtDist
;
269 New
->NetPort
= NtPort
;
270 New
->EntryState
= EntS
;
271 bzero(New
->ZoneBitMap
, sizeof(New
->ZoneBitMap
));
272 at_state
.flags
|= AT_ST_RT_CHANGED
;
273 return(rt_binsert(New
));
277 dPrintf(D_M_RTMP_LOW, D_L_ROUTING, ("%s : %04d : NOT FOUND\n",
278 "rt_blookup", NetNumber));
279 * Routing table btree deletion routine
283 RT_entry
*rt_bdelete (NetStop
, NetStart
)
284 at_net_al NetStop
, NetStart
;
287 RT_entry
*rt_found
, *pprevious
, *pnext
, *pnextl
, *psub
;
290 rt_found
= &RT_table_start
;
292 dPrintf(D_M_RTMP_LOW
, D_L_ROUTING
, ("%s : Delete %d-%d\n",
293 "rt_bdelete", NetStart
, NetStop
));
297 if (NetStop
> rt_found
->NetStop
) {
298 pprevious
= rt_found
;
299 rt_found
= rt_found
->right
;
304 /* non extended nets cases */
306 if (rt_found
->NetStart
)
307 LowEnd
= rt_found
->NetStart
;
309 LowEnd
= rt_found
->NetStop
;
311 if (NetStop
< LowEnd
) {
312 pprevious
= rt_found
;
313 rt_found
= rt_found
->left
;
317 /* we're in the range (either extended or not)
318 * return the entry found.
325 dPrintf(D_M_RTMP
, D_L_ROUTING
, ("%s : Delete %d-%d found to delete %d-%d\n",
326 "rt_bdelete", NetStart
, NetStop
, rt_found
->NetStart
,rt_found
->NetStop
));
332 /* we found the entry, now reorg the sub-trees
333 * spanning from our node.
336 if ((pnext
= rt_found
->right
)) {
338 /* Tree pruning: take the left branch of the current
339 * node and place it at the lowest left branch
340 * of the current right branch
345 /* walk the Right/Left sub tree from current node */
347 while ((pnextl
= psub
->left
))
350 /* plug the old left tree to the new ->Right leftmost node */
352 psub
->left
= rt_found
->left
;
355 } else { /* only left sub-tree, simple case */
357 pnext
= rt_found
->left
;
360 /* Now, plug the current node sub tree to the good pointer of
365 if (pprevious
->left
== rt_found
)
366 pprevious
->left
= pnext
;
368 pprevious
->right
= pnext
;
370 /* clean-up entry and add to the free-list */
372 at_state
.flags
|= AT_ST_RT_CHANGED
;
376 else { /* Trying to delete something that doesn't exist? */
378 dPrintf(D_M_RTMP
, D_L_WARNING
, ("%s : %d NOT Removed\n",
379 "rt_bdelete", NetStop
));
381 return ((RT_entry
*)NULL
);
388 RT_entry
*rt_sortedshow(parent
)
395 if (parent
== NULL
) {
396 me
= &RT_table_start
;
402 /* parent = parent->parent; */
408 * debug only: display the contents of the routing table
416 ptree
= &RT_table
[0];
418 while (ptree
&& i
< 600 ) {
419 if (ptree
->NetStop
) {
420 dPrintf(D_M_RTMP_LOW
, D_L_VERBOSE
,
421 ("%4d-%4d IR=%d:%d Dist=%d\n",
422 ptree
->NetStop
, ptree
->NetStart
, ptree
->NextIRNet
,
423 ptree
->NextIRNode
, (short)ptree
->NetDist
));
425 dPrintf(D_M_RTMP_LOW
, D_L_VERBOSE
,
426 ("%04d : * FREE ENTRY\n", i
));
434 * prepare the indexing of the free entries in the RTMP table
441 if ((RT_table
= (RT_entry
*)_MALLOC(sizeof(RT_entry
)*RT_maxentry
,
442 M_RTABLE
, M_WAITOK
)) == NULL
) {
443 dPrintf(D_M_RTMP
, D_L_WARNING
,
444 ("rtmptable: Can't allocate RT_table\n"));
447 if ((ZT_table
= (ZT_entry
*)_MALLOC(sizeof(ZT_entry
)*ZT_maxentry
,
448 M_RTABLE
, M_WAITOK
)) == NULL
) {
449 dPrintf(D_M_RTMP
, D_L_WARNING
,
450 ("rtmptable: Can't allocate ZT_table\n"));
453 dPrintf(D_M_RTMP
, D_L_STARTUP
, ("rt_table_init called\n"));
454 bzero(&RT_table
[0], sizeof(RT_entry
)* RT_maxentry
);
455 for (i
= 1 ; i
< RT_maxentry
; i
++) {
456 (&RT_table
[i
-1])->right
= &RT_table
[i
];
458 RT_table_freelist
= &RT_table
[0];
460 at_state
.flags
|= AT_ST_RT_CHANGED
;
461 at_state
.flags
|= AT_ST_ZT_CHANGED
;
462 bzero(&RT_table_start
, sizeof(RT_entry
));
464 /* also clean up the ZIP table */
466 bzero(&ZT_table
[0], sizeof(ZT_entry
)* ZT_maxentry
);
467 ErrorRTMPoverflow
= 0;
468 ErrorZIPoverflow
= 0;
473 * zt_add_zone: add a zone name in the zone table.
476 zt_add_zone(name
, length
)
481 bcopy(name
, &zname
.str
, length
);
483 return (zt_add_zonename(&zname
));
487 * zt_add_zonename: add a zone name in the zone table.
490 int zt_add_zonename(zname
)
493 register short res
,i
;
495 if (res
= zt_find_zname(zname
))
498 for (i
= 0; i
< ZT_maxentry
; i
++) {
499 if (ZT_table
[i
].ZoneCount
== 0 && ZT_table
[i
].Zone
.len
== 0) {/* free entry */
500 ZT_table
[i
].Zone
= *zname
;
501 dPrintf(D_M_RTMP
, D_L_VERBOSE
, ("zt_add_zonename: zone #%d %s len=%d\n",
502 i
, ZT_table
[i
].Zone
.str
, ZT_table
[i
].Zone
.len
));
503 at_state
.flags
|= AT_ST_ZT_CHANGED
;
508 return (ZT_MAXEDOUT
);
511 /* Adjust zone counts for a removed network entry.
512 * If the ZoneCount of a zone reaches zero, delete the zone from the zone table
514 void zt_remove_zones(zmap
)
518 register u_short i
,j
, Index
;
520 for (i
=0; i
< ZT_BYTES
; i
++) {
523 for (j
=0; j
< 8 ; j
++)
524 if ((zmap
[i
] << j
) & 0x80) {
525 Index
= i
*8 + j
; /* get the index in ZT */
526 /* 1-23-97 this routine caused a crash once, presumably
527 zmap bits beyond ZT_table size got set somehow.
530 if (Index
>= ZT_maxentry
) {
531 dPrintf(D_M_RTMP
, D_L_ERROR
,
532 ("zt_remove_zones: index (%d) GT ZT_maxentry (%d) (zmap:%d)\n",
533 Index
,ZT_maxentry
,i
));
536 dPrintf(D_M_RTMP
, D_L_VERBOSE
,
537 ("zt_remove_zones: zone #%d %s was=%d\n", Index
,
538 ZT_table
[Index
].Zone
.str
, ZT_table
[Index
].ZoneCount
));
539 if (ZT_table
[Index
].ZoneCount
> 0)
540 ZT_table
[Index
].ZoneCount
--;
541 if (ZT_table
[Index
].ZoneCount
== 0)
542 ZT_table
[Index
].Zone
.len
= 0;
543 at_state
.flags
|= AT_ST_ZT_CHANGED
;
552 * zt_compute_hash: compute hash index from the zone name string
555 short zt_compute_hash(zname
)
558 register u_short checksum
=0, i
;
561 /* apply the upper name + DDP checksum algorithm */
563 for (i
= 0 ; i
< zname
->len
; i
++) {
565 /* upperize the character */
568 if (c1
>= 'a' && c1
<= 'z')
576 checksum
= ((checksum
& 0x8000) ?
577 (checksum
<< 1 | 1) : (checksum
<< 1));
580 dPrintf(D_M_RTMP_LOW
, D_L_ROUTING
, ("zt_comphash: value computed for zone=%s h=%d\n",
581 zname
->str
, checksum
));
591 * zt_upper_zname: translate the name string into uppercase
594 void zt_upper_zname(zname
)
600 for (i
= 0 ; i
< zname
->len
; i
++) {
603 if (c1
>= 'a' && c1
<= 'z')
613 * zt_get_zmcast: calcularte the zone multicast address for a
615 * Returns the result in "buffer"
618 zt_get_zmcast(ifID
, zname
, buffer
)
619 at_ifaddr_t
*ifID
; /* we want to know the media type */
620 at_nvestr_t
*zname
; /* source name for multicast address */
621 char *buffer
; /* resulting Zone Multicast address */
625 h
= zt_compute_hash(zname
);
628 * Find a nice way to decide if it is TokenRing or Ethernet for
629 * the Multicast address computation....
632 if (ifID
->aa_ifp
->if_type
!= IFT_ISO88025
) { /* token ring */
639 /* no router, use cable multicast */
640 if (MULTIHOME_MODE
&& ifID
->ifRouterState
== NO_ROUTER
) {
641 buffer
[3] = buffer
[4] = buffer
[5] = 0xff;
646 buffer
[5] = h
% 0xFD;
648 dPrintf(D_M_RTMP_LOW
, D_L_ROUTING
, ("zt_get_multi: computed for h=%d %x %x\n",
649 h
, *(u_int
*)&buffer
[0], *(u_short
*)&buffer
[4]));
651 return(6); /* returns Multicast address length */
655 /* assume it is token ring: note for the magic number computation,
656 * first see Inside Mac Page 3-10, there is 20 multicast addresses
657 * for TLAP, and they are from 0xC000 0000 0008 00 to 0xC000 0200 0000 00
661 *(u_int
*)&buffer
[2] = 1 << ((h
% 19) + 11);
662 dPrintf(D_M_RTMP
, D_L_WARNING
,("zt_get_multi: BROAD not found forr h=%d \n",
672 * zt_ent_zindex: return the first zone index found in the zone map
673 * return the entry number+1 in the Zone Table, or zero if not found
676 int zt_ent_zindex(zmap
)
682 for (i
= 0 ; i
< ZT_BYTES
; i
++)
685 for (j
= 0 ; j
< 8 ; j
++)
686 if ((zmap
[i
] << j
) & 0x80)
692 * zt_ent_zcount: count the number of actives zone for a routing entry
698 register u_char
*zmap
;
699 register u_short i
,j
;
700 register int zone_count
= 0 ;
703 if (!RT_ALL_ZONES_KNOWN(ent
))
705 zmap
= ent
->ZoneBitMap
;
707 for (i
= 0 ; i
< ZT_BYTES
; i
++) {
711 for (j
= 0 ; j
< 8 ; j
++)
712 if ((*zmap
<< j
) & 0x80)
721 * zt_find_zname: match a zone name in the zone table and return the entry if found
726 register short i
, j
, found
;
727 register char c1
, c2
;
733 for (i
= 0 ; i
< ZT_maxentry
; i
++) {
734 if (!ZT_table
[i
].ZoneCount
|| zname
->len
!= ZT_table
[i
].Zone
.len
)
737 found
= 1; /* did we get the right one? */
739 for (j
= 0 ; j
< zname
->len
; j
++) {
741 c2
= ZT_table
[i
].Zone
.str
[j
];
742 if (c1
>= 'a' && c1
<= 'z')
744 if (c2
>= 'a' && c2
<= 'z')
765 * zt_set_zmap: set a bit for the corresponding zone map in an entry bitmap
767 void zt_set_zmap(znum
, zmap
)
771 register u_short num
= znum
-1;
773 if (!(zmap
[num
>> 3] & 0x80 >> (num
% 8))) {
774 zmap
[num
>> 3] |= 0x80 >> (num
% 8);
775 ZT_table
[num
].ZoneCount
++;
781 * zt_clr_zmap: clear a bit for the corresponding zone map in an entry bitmap
783 void zt_clr_zmap(znum
, zmap
)
787 register u_short num
= znum
-1;
789 if (zmap
[num
>> 3] & 0x80 >> (num
% 8)) {
790 zmap
[num
>> 3] ^= 0x80 >> (num
% 8);
791 ZT_table
[num
].ZoneCount
--;
798 * This function performs the actual lookup and forward of packets
799 * send to the box for routing.
801 * The destination network is looked up in our tables, and if we
802 * know the next IR to send the packet to, we forward the packet
805 * If the destination is unknown, we simply dump the packet.
808 void routing_needed(mp
, ifID
, bypass
)
811 char bypass
; /* set by special socket handlers */
814 register at_ddp_t
*ddp
;
815 register int msgsize
;
816 register RT_entry
*Entry
;
817 register gbuf_t
*tmp_m
;
819 /* first check the interface is up and forwarding */
822 dPrintf(D_M_RTMP
, D_L_WARNING
,
823 ("routing_needed: non valid IFID!\n"));
827 if ((ifID
->ifRoutingState
< PORT_ONLINE
)) {
828 dPrintf(D_M_RTMP
, D_L_WARNING
,
829 ("routing_needed: port %d not online yet\n",
835 ddp
= (at_ddp_t
*)gbuf_rptr(mp
);
836 msgsize
= DDPLEN_VALUE(ddp
);
837 for (tmp_m
= gbuf_next(mp
); tmp_m
; tmp_m
= gbuf_next(tmp_m
))
838 msgsize
+= DDPLEN_VALUE(((at_ddp_t
*)gbuf_rptr(tmp_m
)));
840 if (ddp
->hopcount
++ > 15) {
841 dPrintf(D_M_RTMP
, D_L_WARNING
,
842 ("routing_needed: drop packet for %d:%d, hopcount too high\n",
843 NET_VALUE(ddp
->dst_net
), ddp
->dst_node
));
845 snmpStats
.dd_hopCount
++;
846 return; /* was return(1); */
849 if ((Entry
= rt_blookup(NET_VALUE(ddp
->dst_net
)))) {
851 dPrintf(D_M_RTMP_LOW
, D_L_ROUTING
,
852 ("routing_needed: FOUND for %d.%d p=%d to %d.%d \n",
853 NET_VALUE(ddp
->dst_net
), ddp
->dst_node
, ifID
->ifPort
,
854 Entry
->NextIRNet
, Entry
->NextIRNode
));
856 /* somehow, come to that point... */
858 /* if multihomed - need to set source address to the interface
859 * the packet is being sent from.
861 if (MULTIHOME_MODE
) {
862 NET_ASSIGN(ddp
->src_net
, ifID_table
[Entry
->NetPort
]->ifThisNode
.s_net
);
863 ddp
->src_node
= ifID_table
[Entry
->NetPort
]->ifThisNode
.s_node
;
866 ifID
->ifStatistics
.fwdPkts
++;
867 ifID
->ifStatistics
.fwdBytes
+= msgsize
;
869 if (Entry
->NetDist
) /* net not directly connected */
870 ddp_router_output(mp
, ifID_table
[Entry
->NetPort
], AT_ADDR
,
871 Entry
->NextIRNet
, Entry
->NextIRNode
, 0);
872 else {/* we are directly on this net */
874 /* we want to avoid duplicating broadcast packet on the same net,
875 * but special sockets handlers are ok to do that (mainly for
876 * for loopback purpose). So, if the "bypass" flag is set, we don't
877 * check for that test... [Problem was "movietalk"].
880 if (bypass
|| ifID_table
[Entry
->NetPort
] != ifID
)
881 ddp_router_output(mp
, ifID_table
[Entry
->NetPort
], AT_ADDR
,
882 NET_VALUE(ddp
->dst_net
), ddp
->dst_node
, 0);
884 dPrintf(D_M_RTMP
, D_L_ROUTING
,
885 ("routing_needed: bad loopback for add %d.%d from port %d (%d.%d)\n",
886 NET_VALUE(ddp
->dst_net
), ddp
->dst_node
, ifID
->ifPort
,
887 NET_VALUE(ddp
->src_net
), ddp
->src_node
));
888 ifID
->ifStatistics
.droppedPkts
++;
889 ifID
->ifStatistics
.droppedBytes
+= msgsize
;
892 return; /* was return (2); */
899 dPrintf(D_M_RTMP
, D_L_ROUTING
,
900 ("routing_needed: NOT FOUND for add %d.%d from port %d our %d.%d\n",
901 NET_VALUE(ddp
->dst_net
), ddp
->dst_node
, ifID
->ifPort
,
902 ifID_home
->ifThisNode
.s_net
,
903 ifID_home
->ifThisNode
.s_node
));
905 ifID
->ifStatistics
.droppedPkts
++;
906 ifID
->ifStatistics
.droppedBytes
+= msgsize
;
907 snmpStats
.dd_noRoutes
++;
910 return; /* was return (2); */
914 } /* routing_needed */
916 ZT_entryno
*zt_getNextZone(first
)
918 /* a call made with first = TRUE returns the first valid entry in
919 the ZT_table, if first != TRUE, then then each call returns the
920 next valid entry in the table. The next call after the last
921 valid entry was read returns NULL
926 static ZT_entryno zte
;
934 for (i
=idx
; i
<ZT_maxentry
; i
++) {
935 if (ZT_table
[i
].ZoneCount
)
940 zte
.zt
= ZT_table
[i
];
948 RT_entry
*rt_getNextRoute(first
)
951 /* a call made with first = TRUE returns the first valid entry in
952 the RT_table, if first != TRUE, then then each call returns the
953 next valid entry in the table. The next call after the last
954 valid entry was read returns NULL
967 for (i
=idx
; i
<RT_maxentry
; i
++) {
968 if (RT_table
[i
].EntryState
!= RTE_STATE_UNUSED
)
973 return(&RT_table
[i
]);
983 register RT_entry
*rt
;
986 if(!(at_state
.flags
&AT_ST_RT_CHANGED
))
989 for (i
=RT_maxentry
,rt
= &RT_table
[RT_maxentry
-1]; i
; i
--,rt
--)
990 if (rt
->EntryState
!= RTE_STATE_UNUSED
) {
1000 register ZT_entry
*zt
;
1003 if (!(at_state
.flags
& AT_ST_ZT_CHANGED
))
1006 for (i
=ZT_maxentry
,zt
= &ZT_table
[ZT_maxentry
-1]; i
; i
--,zt
--)
1007 if (zt
->ZoneCount
) {
1015 RT_entry
*d
; /* destination */
1016 int s
; /* starting entry */
1017 int c
; /* # entries to copy */
1020 register RT_entry
*rt
;
1022 for(i
=s
,rt
=&RT_table
[s
]; i
<RT_maxentry
&& n
<c
; rt
++,i
++)
1023 if (rt
->EntryState
!= RTE_STATE_UNUSED
) {
1030 ZT_entry
*d
; /* destination */
1031 int s
; /* starting entry */
1032 int c
; /* # entries to copy */
1035 bcopy(&ZT_table
[s
], d
, c
*sizeof(ZT_entry
));
1038 at_nvestr_t
*getRTRLocalZone(ifz
)
1044 int zcnt
=0; /* zone we're pointing to in the list */
1045 char zonesChecked
[ZT_BYTES
];
1048 if (ifz
->zone_index
< 0) {
1049 return((at_nvestr_t
*)NULL
);
1051 bzero(zonesChecked
,sizeof(zonesChecked
));
1052 TAILQ_FOREACH(ifID
, &at_ifQueueHd
, aa_link
) {
1053 if (!(route
= rt_blookup(ifID
->ifThisNode
.s_net
))) {
1054 return((at_nvestr_t
*)NULL
);
1056 zmap
=route
->ZoneBitMap
;
1057 dPrintf(D_M_RTMP_LOW
, D_L_USR1
,
1058 ("getRTRLocal: i/f %s, net:%d\n",ifID
->ifName
,
1059 ifID
->ifThisNode
.s_net
));
1060 for (i
= 0 ; i
< ZT_BYTES
; i
++) {
1062 for (j
= 0; j
< 8 ; j
++)
1063 if ( (zmap
[i
] & (0x80 >> j
)) &&
1064 !(zonesChecked
[i
] & (0x80 >> j
))
1066 zonesChecked
[i
] |= (0x80 >> j
);
1067 if (ifz
->zone_index
== zcnt
) {
1069 getIfUsage(index
, &ifz
->zone_iflist
);
1070 ifz
->zone_name
= ZT_table
[index
].Zone
;
1071 dPrintf(D_M_RTMP_LOW
, D_L_USR1
,
1072 ("getRTRLocal:zmap:%8x zcnt:%d\n",
1073 *(int*)zmap
, zcnt
));
1074 ifz
->zone_index
= index
+1;
1075 return(&ZT_table
[index
].Zone
);
1082 dPrintf(D_M_RTMP_LOW
, D_L_USR1
,
1083 ("getRTRLocal: returning NULL last ent:%d net:%d zmap:%08x\n",
1084 (ifID
? ifID
->ifPort
: 0),
1085 (ifID
? ifID
->ifThisNode
.s_net
: 0),*(int*)zmap
));
1086 ifz
->zone_name
.len
= 0;
1087 return((at_nvestr_t
*)NULL
);
1088 } /* getRTRLocalZone */
1090 void getIfUsage(zone
, ifs_in_zone
)
1092 at_ifnames_t
*ifs_in_zone
;
1094 /* sets the interface name in each element of the array for each I/F in the
1095 requested zone. The array has a 1:1 correspondence with the
1096 ifID_table. Zone is assumed to be valid and local, so if we're in
1097 single port mode, we'll set the home port and thats it.
1100 u_int zmi
; /* zone map index for zone */
1101 u_char zmb
; /* zone map bit mask for zone */
1106 if (!MULTIPORT_MODE
) {
1107 strncpy(ifs_in_zone
->at_if
[cnt
], ifID_home
->ifName
,
1111 bzero(ifs_in_zone
, sizeof(at_ifnames_t
));
1113 zmb
= 0x80>>(zone
% 8);
1114 dPrintf(D_M_NBP_LOW
, D_L_USR3
, ("get_ifs znum:%d zmi%d zmb:%x\n",
1116 TAILQ_FOREACH(ifID
, &at_ifQueueHd
, aa_link
) {
1117 if (!(route
= rt_blookup(ifID
->ifThisNode
.s_net
)))
1119 if (route
->ZoneBitMap
[zmi
] & zmb
) {
1120 dPrintf(D_M_NBP_LOW
, D_L_USR3
, ("zone in port %d \n",
1122 strncpy(ifs_in_zone
->at_if
[cnt
],
1123 ifID_table
[route
->NetPort
]->ifName
, IFNAMESIZ
);